<?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; } }