This repository has been archived by the owner on Apr 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Account.php
116 lines (105 loc) · 2.55 KB
/
Account.php
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
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Account extends Model
{
use SoftDeletes;
//完成图片同步
const SYNC_STATUS_FINSHED_IMAGE = 1;
//完成图文同步
const SYNC_STATUS_FINSHED_NEWS = 2;
//完成视频同步
const SYNC_STATUS_FINSHED_VIDEO = 3;
//完成声音同步
const SYNC_STATUS_FINSHED_VOICE = 4;
//完成菜单同步
const SYNC_STATUS_FINSHED_MENU = 5;
/**
* 字段白名单.
*
* @var array
*/
protected $fillable = [
'name',
'token',
'user_id',
'app_id',
'app_secret',
'aes_key',
'merchant_id',
'merchant_key',
'cert_path',
'key_path',
'type',
];
/**
* 用于表单验证时的字段名称提示.
*
* @var array
*/
public static $aliases = [
'name' => '公众号名称',
'original_id' => '原始ID',
'wechat_account' => '微信账号',
'app_id' => '应用ID',
'app_secret' => '应用secret',
'aes_key' => '应用secret',
'merchant_id' => '商户号',
'key' => '商户密钥',
'cert_path' => '商户证书路径',
'key_path' => '密钥证书路径',
'type' => '账户类型',
];
/**
* 重载 setAttrivute,保存时去除多余空格
*
* @param string $key
* @param mixed $value
*
* @return $this
*/
public function setAttribute($key, $value)
{
$value = trim($value);
return parent::setAttribute($key, $value);
}
/**
* @param $type
*
* @return string
*/
public function getTypeAttribute($type)
{
switch ($type) {
case 1:
return '订阅号';
case 2:
return '认证订阅号';
case 3:
return '服务号';
case 4:
return '认证服务号';
default:
return '未知类型';
}
}
/**
* 粉丝.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function fans()
{
return $this->hasMany(\App\Fan::class, 'account_id', 'id');
}
/**
* 所属用户.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
return $this->belongsTo(\App\User::class, 'user_id', 'id');
}
}