| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- <?php
- namespace bizHd\message\classes;
- use bizHd\admin\classes\AdminClass;
- use bizHd\admin\classes\ShopAdminClass;
- use bizHd\admin\services\ShopAdminService;
- use biz\sj\classes\MerchantClass;
- use bizHd\user\classes\UserClass;
- use bizHd\wx\classes\WxOpenClass;
- use common\components\httpUtil;
- use common\components\sms;
- use common\components\wxUtil;
- use common\services\xhTMessageService;
- use Yii;
- use bizHd\base\classes\BaseClass;
- class InformAdminClass extends BaseClass
- {
- public static $baseFile = '\bizHd\message\models\InformAdmin';
- //增加通知员工 ssh
- public static function addInform($params, $shopAdmin, $type, $TMList)
- {
- //没有关注公众号暂时不进行通知
- $subscribe = isset($shopAdmin['adminBaseInfo']['subscribe']) ? $shopAdmin['adminBaseInfo']['subscribe'] : 0;
- if ($subscribe == 0) {
- return false;
- }
- //没有小程序id暂时不进行通知,目前只有小程序商家版,没有h5
- $miniOpenId = isset($shopAdmin['adminBaseInfo']['miniOpenId']) ? $shopAdmin['adminBaseInfo']['miniOpenId'] : '';
- if (empty($miniOpenId)) {
- return false;
- }
- $openMerchant = WxOpenClass::getWxInfo();
- $params['miniAppId'] = $openMerchant['miniAppId'];
- switch ($type) {
- case 'goodsSold':
- //宝贝售出
- $respond = self::goodsSoldInform($params, $shopAdmin, $TMList);
- break;
- case 'income':
- //收入提醒
- $respond = self::incomeInform($params, $shopAdmin, $TMList);
- break;
- case 'reach':
- $respond = self::reachInform($params, $shopAdmin, $TMList);
- break;
- default:
- }
- $shopAdminId = $shopAdmin['id'];
- $shopId = $shopAdmin['shopId'];
- $mobile = isset($shopAdmin['adminBaseInfo']['mobile']) ? $shopAdmin['adminBaseInfo']['mobile'] : '';
- //通知管理员的都是平台通知
- $isOpen = 1;
- $data = [
- 'messageType' => 'inform',
- 'informWay' => 'miniProgram',
- 'userType' => 'admin',
- 'mobile' => $mobile,
- 'shopAdminId' => $shopAdminId,
- 'userId' => 0,
- 'shopId' => $shopId,
- 'isOpen' => $isOpen,
- ];
- $data = array_merge($data, $respond);
- self::consumeInformQueue($data);
- return true;
- }
- //宝贝售出提醒 ssh 2020.5.31
- public static function goodsSoldInform($params, $admin, $TMList)
- {
- $totalFee = isset($params['totalFee']) ? $params['totalFee'] : 0;
- $orderId = isset($params['orderId']) ? $params['orderId'] : '';
- $orderSn = isset($params['orderSn']) ? $params['orderSn'] : '';
- $orderName = '商品';
- $userName = '石头';
- $data['briefContent'] = "客户" . $userName . "付款" . $totalFee . '元';
- //收入提醒
- $openId = isset($admin['adminBaseInfo']['openId']) ? $admin['adminBaseInfo']['openId'] : '';
- $miniOpenId = isset($admin['adminBaseInfo']['miniOpenId']) ? $admin['adminBaseInfo']['miniOpenId'] : '';
- $shortTempId = 'OPENTM207422813';
- $tempId = isset($TMList[$shortTempId]) ? $TMList[$shortTempId] : '';
- $tMessage = [
- "touser" => $openId,
- "template_id" => $tempId,
- "url" => Yii::$app->params['adminUrl'] . '/order/detail',
- "data" => [
- "first" => ["value" => '您有新的收入!', "color" => "#173177"],
- "keyword1" => ["value" => (string)$orderSn, "color" => "#173177"],
- "keyword2" => ["value" => $orderName, "color" => "#173177"],
- "keyword3" => ["value" => number_format($totalFee, 2) . '元', "color" => "#173177"],
- "keyword4" => ["value" => number_format($totalFee, 2) . '元', "color" => "#173177"],
- "keyword5" => ["value" => $userName, "color" => "#173177"],
- "remark" => ["value" => '点此查看详细', "color" => "#173177"]
- ]
- ];
- if (!empty($miniOpenId)) {
- $tMessage['miniprogram']['appid'] = $params['miniAppId'];
- $tMessage['miniprogram']['pagepath'] = 'admin/order/detail?id=' . $orderId;
- }
- $data['tMessage'] = json_encode($tMessage);
- $msg = "客户" . $userName . "付款" . $totalFee . '元';
- $data['content'] = $msg;
- return $data;
- }
- //送到通知 ssh 2020.1.31
- public static function reachInform($params, $admin, $TMList)
- {
- $totalFee = 199;
- $userName = '石头';
- $orderId = $params['orderId'];
- $data['briefContent'] = "客户" . $userName . "付款" . $totalFee . '元';
- $openId = isset($admin['openId']) && !empty($admin['openId']) ? $admin['openId'] : '';
- $miniOpenId = isset($admin['miniOpenId']) && !empty($admin['miniOpenId']) ? $admin['miniOpenId'] : '';
- $shortTempId = 'OPENTM201205968';
- $tempId = isset($TMList[$shortTempId]) ? $TMList[$shortTempId] : '';
- $tMessage = [
- "touser" => $openId,
- "template_id" => $tempId,
- "url" => Yii::$app->params['frontUrl'] . "/center/order-detail?id=1225&account=12362",
- "data" => [
- "first" => ["value" => '客户订单已送达', "color" => "#173177"],
- "keyword1" => ["value" => (string)1525, "color" => "#173177"],
- "keyword2" => ["value" => '石头', "color" => "#173177"],
- "keyword3" => ["value" => '已送达', "color" => "#173177"],
- "remark" => ["value" => '。。。。。。。', "color" => "#173177"]
- ]
- ];
- if (!empty($miniOpenId)) {
- $tMessage['miniprogram']['appid'] = $params['miniAppId'];
- $tMessage['miniprogram']['pagepath'] = 'admin/order/detail?id=' . $orderId;
- }
- $data['tMessage'] = json_encode($tMessage);
- $msg = "客户" . $userName . "付款" . $totalFee . '元';
- $data['content'] = $msg;
- return $data;
- }
- //收入提醒 ssh 2020.5.31
- public static function incomeInform($params, $admin, $TMList)
- {
- $order = $params['order'];
- $totalFee = isset($order['actPrice']) ? $order['actPrice'] : 0;
- $orderId = isset($order['id']) ? $order['id'] : '';
- $payTime = isset($order['payTime']) && !empty($order['payTime']) ? date("Y-m-d H:i", $order['payTime']) : '未知';
- $store = isset($order['store']) ? $order['store'] : 0;
- $sourceTypeId = $order['sourceType'];
- if ($store == 1) {
- $incomeStyle = '门店收入';
- } else {
- $sourceTypeList = [0 => '微信', 1 => '支付宝', 2 => '小程序', 3 => '朋友圈', 4 => '美团', 5 => '系统'];
- $incomeStyle = isset($sourceTypeList[$sourceTypeId]) ? $sourceTypeList[$sourceTypeId] . '收入' : '未知';
- }
- $data = [];
- $data['briefContent'] = "客户付款" . $totalFee . '元';
- $openId = isset($admin['adminBaseInfo']['openId']) ? $admin['adminBaseInfo']['openId'] : '';
- $miniOpenId = isset($admin['adminBaseInfo']['miniOpenId']) ? $admin['adminBaseInfo']['miniOpenId'] : '';
- $shortTempId = 'OPENTM207422813';
- $tempId = isset($TMList[$shortTempId]) ? $TMList[$shortTempId] : '';
- $tMessage = [
- "touser" => $openId,
- "template_id" => $tempId,
- "url" => Yii::$app->params['adminUrl'] . '/order/detail',
- "data" => [
- "first" => ["value" => '恭喜,您有新收入。', "color" => "#173177"],
- "keyword1" => ["value" => number_format($totalFee, 2) . '元', "color" => "#173177"],
- "keyword2" => ["value" => $incomeStyle, "color" => "#173177"],
- "keyword3" => ["value" => $payTime, "color" => "#173177"],
- "remark" => ["value" => '点此查看详情', "color" => "#173177"]
- ]
- ];
- if (!empty($miniOpenId)) {
- $tMessage['miniprogram']['appid'] = $params['miniAppId'];
- $tMessage['miniprogram']['pagepath'] = 'admin/order/detail?id=' . $orderId;
- }
- $data['tMessage'] = json_encode($tMessage);
- $msg = "客户付款" . $totalFee . '元';
- $data['content'] = $msg;
- return $data;
- }
- //添加通知内容 ssh 2020.1.8
- public static function addData($data)
- {
- self::add($data);
- }
- //订单完成通知店长 ssh 2020.3.19
- public static function sendComplete($order)
- {
- $open = WxOpenClass::getWxInfo();
- $sjId = $order['sjId'];
- $orderId = $order['id'];
- $shopId = $order['shopId'];
- $merchant = MerchantClass::getMerchantById($sjId);
- if (empty($shopId)) {
- $shopId = MerchantClass::getDefaultShopId($merchant);
- }
- $adminList = ShopAdminService::getNoticeAdminList($shopId);
- $tm = xhTMessageService::getList(0);
- $shortTempId = 'OPENTM201205968';//订单送达通知
- $tempId = $tm[$shortTempId];
- if (!empty($adminList)) {
- foreach ($adminList as $admin) {
- if (isset($admin['adminBaseInfo']['subscribe']) && $admin['adminBaseInfo']['subscribe'] == 1) {
- $openId = isset($admin['adminBaseInfo']['openId']) ? $admin['adminBaseInfo']['openId'] : '';
- $miniOpenId = isset($admin['adminBaseInfo']['miniOpenId']) ? $admin['adminBaseInfo']['miniOpenId'] : '';
- $url = Yii::$app->params['hdDomain'] . "/#/admin/order/detail?id=" . $order['id'];
- $url = httpUtil::becomeHttps($url);
- $data = [
- "touser" => $openId,
- "template_id" => $tempId,
- "url" => $url,
- "data" => [
- "first" => ["value" => '客户订单已送达', "color" => "#173177"],
- "keyword1" => ["value" => (string)$order['orderSn'], "color" => "#173177"],
- "keyword2" => ["value" => $order['bookName'], "color" => "#173177"],
- "keyword3" => ["value" => '已送达', "color" => "#173177"],
- "remark" => ["value" => '', "color" => "#173177"]
- ]
- ];
- if (!empty($miniOpenId)) {
- $data['miniprogram']['appid'] = $open['miniAppId'];
- $data['miniprogram']['pagepath'] = 'admin/order/detail?id=' . $orderId;
- }
- wxUtil::sendTaskInform($data, $open);
- }
- }
- }
- }
- //消费通知内容 ssh 2020.1.1
- //['messageType'=>'inform','informWay'=>'miniProgram','userType'=>'admin','shopAdminId'=>913,'mobile'=>'15280215347','tMessage'=>'','content'=>'','briefContent'=>'','isOpen'=>1]
- public static function consumeInformQueue($data)
- {
- $informWay = $data['informWay'];
- $shopAdminId = isset($data['shopAdminId']) ? $data['shopAdminId'] : 0;
- if (empty($shopAdminId)) {
- echo "\n 没有找到门店管理员 \n";
- util::end();
- }
- $shopAdmin = ShopAdminClass::getById($shopAdminId);
- $sjId = $shopAdmin['sjId'];
- $adminId = $shopAdmin['adminId'];
- $mobile = $data['mobile'];
- $isOpen = isset($data['isOpen']) ? $data['isOpen'] : 0;
- $merchant = WxOpenClass::getWxInfo();
- $hasSend = 0;
- $noticeWay = 0;
- if ($informWay == 'wx') {
- $tMessage = json_decode($data['tMessage'], true);
- wxUtil::sendTaskInform($tMessage, $merchant, $isOpen);
- $hasSend = 1;
- $noticeWay = 0;
- } elseif ($informWay == 'sms') {
- $msg = $data['content'];
- sms::merchantSend($mobile, $msg, $merchant);
- $hasSend = 1;
- $noticeWay = 1;
- } elseif ($informWay == 'miniProgram') {
- $tMessage = json_decode($data['tMessage'], true);
- wxUtil::sendTaskInform($tMessage, $merchant);
- $hasSend = 1;
- $noticeWay = 0;
- } else {
- }
- //存入数据库
- $informData = [
- 'adminId' => $adminId,
- 'sjId' => $sjId,
- 'noticeType' => 0,
- 'content' => $data['briefContent'],
- 'noticeWay' => $noticeWay,
- 'status' => $hasSend,
- 'sourceType' => 0,
- 'sourceId' => 0,
- 'addTime' => time(),
- 'createTime' => date("Y-m-d H:i:s"),
- ];
- InformAdminClass::addData($informData);
- return true;
- }
- }
|