Template.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
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
* 短信模板类:各种业务发送短信的模板
+-----------------------------------------------------------------------------------------------------------------------
* PHP version 7
*
* @category App\Sms
* @package App\Sms
* @author Richer <yangzi1028@163.com>
* @date 2020年6月15日,16:08:39
* @copyright 2021-2022 Richer (http://www.Richer.com/)
* @license http://www.Richer.com/ License
* @link http://www.Richer.com/
*/
namespace App\Sms;
use App\Models\Lock\Lock;
use App\Models\Lock\LockPassword;
use App\Models\Warning;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
/**
* Class Template
*
* @category App\Sms
* @package App\Sms
* @author Richer <yangzi1028@163.com>
* @date 2020年6月15日,16:08:39
* @copyright 2021-2022 Richer (http://www.Richer.com/)
* @license http://www.Richer.com/ License
* @link http://www.Richer.com/
*/
class Template
{
const SIGN = "云旅馆";
const MESSAGE_OPTIONS = [
// 开锁密码
LockPassword::OBJ_NAME => [
// 租客开锁密码(长期)
'tenant' => [
'content' => '【' . self::SIGN . '】' . '尊敬的租客,您所租的{s50}开锁密码是:{s12},有效期为{s20}至{s20},请妥善保管好您的密码!',
],
],
// 火警提醒
Warning::OBJ_NAME => [
// 火警报警
'warning' => [
'content' => '【' . self::SIGN . '】' . '{s50}发生火灾,火警等级{s8},设备编号:{s10},临时开锁密码:{s12},请立即处理!',
],
],
];
/**
* 获取消息发送的模板
*
* @param string $module 模块
* @param Model $model 对象模型
* @param string $target 发送目标
* @param string $operate 操作
*
* @return array
*/
public static function getTemplate($module, $model, $target = 'user', $operate = 'warning')
{
$options = Arr::get(self::MESSAGE_OPTIONS, $module. '.'. $operate);
$params = [];
switch ($module) {
case Warning::OBJ_NAME:
$params = app(WarningTemplate::class)->getParams($model, $target);
break;
case LockPassword::OBJ_NAME:
$params = LockPasswordTemplate::getParams($model, $target);
break;
default:
}
return [
// 'mobile' => $model->$target->mobile,
'content' => Arr::get($options, 'content'),
'params' => Arr::get($params, 'params'),
'template' => Arr::get($params, 'template'),
'type' => $module . '_' . $target . '_' . $operate,
];
}
/**
* 获取消息发送的内容
*
* @param string $module 模块
* @param Model $model 对象模型
* @param string $target
* @param string $operate 操作
*
* @return array
*/
public static function getContent($module, $model, $target = 'users', $operate = 'warning')
{
$options = Arr::get(self::MESSAGE_OPTIONS, $module. '.'. $operate);
$mobiles = $model->$target->map(function ($item) {
return $item->mobile;
})->all();
$params = [];
switch ($module) {
case Warning::OBJ_NAME:
$params = WarningTemplate::getParams($model, $target);
break;
case Lock::OBJ_NAME:
//
break;
default:
}
return [
'mobiles' => $mobiles,
'content' => Arr::get($options, 'content'),
'params' => $params,
'type' => $module . '_' . $target . '_' . $operate,
];
}
}