Apply.php
5.5 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
namespace addons\groupon\notifications\store;
use addons\groupon\notifications\Notification;
use think\queue\ShouldQueue;
use addons\groupon\model\Config;
use addons\groupon\model\DispatchAutosend;
use addons\groupon\model\Store;
use addons\groupon\model\User;
use addons\groupon\model\UserOauth;
/**
* 自提点审核结果通知
*/
class Apply extends Notification implements ShouldQueue
{
// 队列延迟时间,必须继承 ShouldQueue 接口
public $delay = 0;
// 发送类型 复合型消息类动态传值 当前类支持的发送类型: store_apply: 自提点审核结果通知
public $event = '';
// 额外数据
public $data = [];
// 返回的字段列表
public static $returnField = [
'store_apply' => [
'name' => '自提点审核结果通知',
'fields' => [
['name' => '申请用户', 'field' => 'nickname'],
['name' => '自提点名称', 'field' => 'store_name'],
['name' => '联系人', 'field' => 'realname'],
['name' => '手机号', 'field' => 'phone'],
['name' => '所属区域', 'field' => 'region'],
['name' => '自提点地址', 'field' => 'address'],
['name' => '审核状态', 'field' => 'status'],
['name' => '拒绝原因', 'field' => 'status_msg'],
['name' => '申请时间', 'field' => 'create_date'],
['name' => '处理时间', 'field' => 'update_date'],
]
]
];
public function __construct($data = [])
{
$this->data = $data;
$this->event = $data['event'] ?? '';
$this->initConfig();
}
public function toDatabase($notifiable) {
$data = $this->data;
$apply = $data['apply'] ?? [];
$store = $data['store'] ?? null;
$params = [];
$params['apply'] = $apply;
$params['store'] = $store;
// 获取消息data
$this->paramsData($params, $notifiable);
return $params;
}
public function toSms($notifiable) {
$event = $this->event;
$data = $this->data;
$phone = $notifiable['mobile'] ? $notifiable['mobile'] : '';
$params = [];
$params['phone'] = $phone;
// 获取消息data
$this->paramsData($params, $notifiable);
return $this->formatParams($params, 'sms');
}
public function toEmail($notifiable)
{
$event = $this->event;
$data = $this->data;
$params = [];
// 获取消息data
$this->paramsData($params, $notifiable);
return $this->formatParams($params, 'email');
}
public function toWxOfficeAccount($notifiable) {
$event = $this->event;
$data = $this->data;
$apply = $data['apply'] ?? [];
$store = $data['store'] ?? null;
$params = [];
if ($oauth = $this->getWxOauth($notifiable, 'wxOfficialAccount')) {
// 自提点入口
$path = "/pages/app/merchant/apply"; // 自提点申请地址
// 获取 h5 域名
$url = $this->getH5DomainUrl($path);
$params['openid'] = $oauth->openid;
$params['url'] = $url;
// 获取消息data
$this->paramsData($params, $notifiable);
}
return $this->formatParams($params, 'wxOfficialAccount');
}
public function toWxMiniProgram($notifiable) {
$event = $this->event;
$data = $this->data;
$apply = $data['apply'] ?? [];
$store = $data['store'] ?? null;
$params = [];
if ($oauth = $this->getWxOauth($notifiable, 'wxMiniProgram')) {
// 钱包记录
$path = "/pages/app/merchant/apply"; // 自提点申请地址
// 获取小程序完整路径
$path = $this->getMiniDomainUrl($path);
$params['openid'] = $oauth->openid;
$params['page'] = $path;
// 获取消息data
$this->paramsData($params, $notifiable);
}
return $this->formatParams($params, 'wxMiniProgram');
}
// 组合消息参数
private function paramsData(&$params, $notifiable) {
$params['data'] = [];
switch ($this->event) {
case 'store_apply': // 自提点审核结果通知
$params['data'] = array_merge($params['data'], $this->storeApplyData($notifiable));
break;
default:
$params = [];
}
}
/**
* 申请提现消息参数
*/
private function storeApplyData($notifiable) {
$currentData = $this->data;
$apply = $currentData['apply'] ?? [];
$store = $currentData['store'] ?? null;
$data['template'] = self::$returnField[$this->event]['name']; // 模板名称
$data['nickname'] = $notifiable['nickname'];
$data['store_name'] = $apply['name'];
$data['realname'] = $apply['realname'];
$data['phone'] = $apply['phone'];
$data['region'] = $apply['province_name'] . '-' . $apply['city_name'] . '-' . $apply['area_name'];
$data['address'] = $apply['address'];
$data['status'] = $apply['status_text'];
$data['status_msg'] = $apply['status_msg'] ? : '审核已通过';
$data['create_date'] = date('Y-m-d H:i:s', $apply['createtime']);
$data['update_date'] = date('Y-m-d H:i:s', $apply['updatetime']);
return $data;
}
}