123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace addons\csmadmin\library;
- use app\common\library\Sms;
- class Csmadmin extends ACsmadmin
- {
-
- /**
- * 给部门推送消息
- */
- public static function sendMessageToDepart($param)
- {
- // 输入参数
- $depart_id = $param['depart_id'];
- $msgtplcode = $param['msgtplcode'];
- $msgdata = $param['msgdata'];
- $url = $param['url'];
- $admin_ids = static::getAdminsByDepartId($depart_id);
- foreach ($admin_ids as $admin_id) {
- static::sendMessage([
- 'admin_id' => $admin_id,
- 'msgtplcode' => $msgtplcode,
- 'msgdata' => $msgdata,
- 'url' => $url
- ]);
- }
- }
- /**
- * 给人员推送消息
- */
- public static function sendMessage($param)
- {
- // 输入参数
- $admin_id = $param['admin_id'];
- $msgtplcode = $param['msgtplcode'];
- $msgdata = $param['msgdata'];
- $url = $param['url'];
- // 检查帐号是否存在
- $adminrow = static::getAdminById($admin_id);
- if ($adminrow == null) {
- return static::error("管理员帐号不存在:{$admin_id}");
- }
- $email = $adminrow->email;
- $csmadminrow = static::getCsmAdminById($adminrow->id);
- $mobile = ($csmadminrow == null) ? null : $csmadminrow->mobile;
- // 检查模板是否存在
- $tplrow = static::getMsgtpl($msgtplcode);
- if ($tplrow == null) {
- return static::error("消息模板不存在:{$msgtplcode}");
- }
- $tplchannelrows = static::getMsgtplchannels($tplrow->id);
- if ($tplchannelrows == null) {
- return static::error("消息模板渠道不存在:{$msgtplcode}");
- }
- // 推送消息
- $logdao = new \app\admin\model\csmadmin\Msgtplchannellog();
- foreach ($tplchannelrows as $channelrow) {
- $msgtitle = static::_evalstring($channelrow->msgtitle, $msgdata);
- $msgcontent = static::_evalstring($channelrow->msgcontent, $msgdata);
- $logid = static::_insertChannellog($logdao, $tplrow, $channelrow, $msgtitle, $msgcontent);
- // 按渠道推送
- $errmsg = null;
- switch ($channelrow->channel) {
- case "web":
- $dao = new \app\admin\model\csmadmin\Adminmessage();
- $msgparam = [
- 'faadmin_id' => $admin_id,
- 'msgurl' => $url,
- 'msgtitle' => $msgtitle,
- 'msgcontent' => $msgcontent,
- 'createtime' => time()
- ];
- $dao->create($msgparam);
- break;
- case "email":
- if ($email == null || $email == '') {
- continue;
- }
- // 推送邮件
- $obj = \app\common\library\Email::instance();
- $ret = $obj->to($email)
- ->subject($msgtitle)
- ->message($msgcontent)
- ->send();
- if ($ret === false) {
- $errmsg = "邮件发送失败:{$errmsg};";
- }
- break;
- case "sms":
- if ($mobile == null || $mobile == '') {
- continue;
- }
- // 推送短信
- $ret = Sms::notice($mobile, $msgdata, $channelrow->msgcontent);
- if ($ret === false) {
- $errmsg = "短信发送失败:{$errmsg};";
- }
- break;
- case "dingtalk":
- // TODO csmding
- break;
- }
- static::_updateChannellogResult($logdao, $logid, $errmsg);
- }
- return static::success();
- }
- }
|