SmsLog.php
3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
* 模型层:系统-短信 模型类
+-----------------------------------------------------------------------------------------------------------------------
*
* PHP version 7
*
* @category App\Models\System
* @package App\Models\System
* @author Richer <yangzi1028@163.com>
* @date 2021年1月26日17:53:22
* @copyright 2020-2022 Richer (http://www.Richer.com/)
* @license http://www.Richer.com/ License
* @link http://www.Richer.com/
*/
namespace App\Models\System;
use App\Models\BaseModel;
use App\Models\Traits\MorphMapTrait;
use Illuminate\Database\Eloquent\Relations\MorphTo;
/**
* Class SmsLog
*
* @category App\Models\System
* @package App\Models\System
* @author Richer <yangzi1028@163.com>
* @date 2021年1月26日17:53:22
* @copyright 2020-2022 Richer (http://www.Richer.com/)
* @license http://www.Richer.com/ License
* @link http://www.Richer.com/
*/
class SmsLog extends BaseModel
{
use MorphMapTrait;
// 指定数据库表
const TABLE = 'system_sms_logs';
protected $table = self::TABLE ;
const REGISTER_SMS = 1;// 注册短信
const LOGIN_SMS = 2;// 登录短信
const RETRIEVE_PASSWORD_SMS = 3;// 找回密码短信
const RESET_PASSWORD_SMS = 4;// 重置密码短信
const UPDATE_LOCK_PASSWORD_SMS = 5;// 修改智能门锁密码
const AUTHORIZATION_BIND = 6;// 授权绑定
const WARNING_USER = 'warning_user';// 火警短信
const TYPE_OPTIONS = [
self::REGISTER_SMS => '注册短信',
self::LOGIN_SMS => '登录短信',
self::RETRIEVE_PASSWORD_SMS => '找回密码短信',
self::RESET_PASSWORD_SMS => '重置密码短信',
self::UPDATE_LOCK_PASSWORD_SMS => '修改智能门锁密码',
self::AUTHORIZATION_BIND => '授权绑定',
self::WARNING_USER => '火警短信',
];
const INTERVALS = 60 ;// 短信发送间隔时间
const INVALID_TIME = 60 * 10 ;// 短信失效时间
const SENDING = 1;
const SEND_SUCCESS = 2;
const SEND_FAIL = 3;
const SEND_UNKNOWN = 4;
const STATUS_OPTIONS = [
self::SENDING => '发送中',
self::SEND_SUCCESS => '发送成功',
self::SEND_FAIL => '发送失败',
self::SEND_UNKNOWN => '未知',
];
/**
* 可以批量赋值的属性
*
* @var array
*/
protected $fillable = [
'loggable_id', 'loggable_type', 'mobile','sent_at','sent_body','received_body','received_at',
'noticed_body','noticed_at','out_id','type','status','result'
];
/**
* 多态关联
*
* @return MorphTo
*/
public function loggable(): MorphTo
{
return $this->morphTo()->withTrashed();
}
public function getSentBodyAttribute($value)
{
return json_decode($value, true) ?: null;
}
public function setSentBodyAttribute($value)
{
$this->attributes['sent_body'] = my_json_encode($value);
}
public function getReceivedBodyAttribute($value)
{
return json_decode($value, true) ?: null;
}
public function setReceivedBodyAttribute($value)
{
$this->attributes['received_body'] = my_json_encode($value);
}
public function getNoticedBodyAttribute($value)
{
return json_decode($value, true) ?: null;
}
public function setNoticedBodyAttribute($value)
{
$this->attributes['noticed_body'] = my_json_encode($value);
}
// public function getResultAttribute($value)
// {
// return json_decode($value, true) ?: null;
// }
//
// public function setResultAttribute($value)
// {
// $this->attributes['result'] = my_json_encode($value);
// }
}