NoticeController.class.php
4.3 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
<?php
/**
* Created by PhpStorm.
* User: tony
* Date: 2016-11-24 16:57:03
*/
namespace Apicp\Controller\User;
use Common\Common\Cache;
use Common\Common\ShortUrl;
use Common\Common\Sms;
use Common\Common\User;
use Common\Service\NoticeService;
use Common\Service\UserService;
use VcySDK\Mail;
use VcySDK\Service;
class NoticeController extends AbstractController
{
/**
* Notice
* @author tangxingguo
* @desc 提醒未关注人员关注,发送短信和邮件
* @param Array uids 需要发送提醒的人员
* @param Int is_all 是否发送给所有未加入的人员(1=否,2=是)
* @return bool
*/
public function Index_post()
{
$uids = I('post.uids');
$is_all = I('post.is_all', 1, 'intval');
// 通知所有未加入的人员
if ($is_all == UserService::NOTICE_TO_ALL_UNFOLLOW) {
$conds = [
// 人员状态,4=未加入
'memSubscribeStatus' => UserService::USER_STATUS_UNFOLLOW,
];
$newUser = &User::instance();
$result = $newUser->listAll($conds);
if (!empty($result)) {
$uids = array_column($result, 'memUid');
}
}
if (empty($uids)) {
E('_ERR_PARAM_IS_NULL');
}
$this->sendNotice($uids);
return true;
}
/**
* 发送审核通知
* @author tony
* @param array $uids 需要发送提醒的用户uid
* @return bool
*/
private function sendNotice($uids)
{
// 获取企业信息
$ep = Cache::instance()->get(
'Common.EnterpriseDetail',
'',
['expire' => cfg('ENTERPRISE_DETAIL_CACHE_EXPIRE')]
);
$userServ = new User();
$sms = &Sms::instance();
$mailSdk = new Mail(Service::instance());
$noticeServ = new NoticeService();
$tplname = 'yq_subscribe_mail';
$subject = "管理员{$this->_login->user['eaRealname']}邀请加入{$ep['epName']}企业";
foreach ($uids as $k => $uid) {
$userInfo = $userServ->getByUid($uid);
$gender = ['', '先生', '女士'];
// 写入提醒关注表
$data = [
'eaid' => $this->_login->user['eaId'],
'adminer_mobile' => $this->_login->user['eaMobile'],
'uid' => $uid,
'user_name' => $userInfo['memUsername'],
'user_mobile' => $userInfo['memMobile'],
'email' => $userInfo['memEmail'],
];
$result = $noticeServ->insert($data);
if ($result === false) {
E('_ERR_INSERT_ERROR');
}
// 发送短信
if (!empty($userInfo['memMobile'])) {
$longUrl = oaUrl('Frontend/Index/NoticeFollow/Index', ['notice_id' => $result]);
$url = ShortUrl::create($longUrl);
// 最新修改,姓名可以为50个字符串,所以先拼装成一个完整的字符串,然后按照长度进行截断。
$sms->send(
$userInfo['memMobile'],
json_encode([
'adminer_name' => $this->_login->user['eaRealname'],
'enterprise_name' => $ep['epName'],
'url' => $url,
]),
'',
'',
Sms::CHANNEL_SENDCLOUD,
Sms::SMS_TMP_ID_ADMINER_INVITE
);
}
// 发送邮件
if (!empty($userInfo['memEmail'])) {
$params = [
'%qy_name%' => $ep['epName'],
'%user_name%' => $userInfo['memUsername'],
'%adminer_mobile%' => $this->_login->user['eaMobile'],
'%adminer_name%' => $this->_login->user['eaRealname'],
'%qrcode%' => $ep['corpWxqrcode'],
'%date%' => rgmdate(NOW_TIME, 'Y-m-d'),
];
$mailSdk->sendTemplateMail([
'mcTplName' => $tplname,
'mcEmails' => [$userInfo['memEmail']],
'mcSubject' => $subject,
'mcVars' => $params,
]);
}
}
return true;
}
}