$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(); } }