InformAdminClass.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. namespace biz\message\classes;
  3. use biz\admin\classes\AdminClass;
  4. use biz\user\classes\UserClass;
  5. use common\components\httpUtil;
  6. use common\components\wxUtil;
  7. use common\services\xhTMessageService;
  8. use Yii;
  9. use biz\base\classes\BaseClass;
  10. class InformAdminClass extends BaseClass
  11. {
  12. public static $baseFile = '\biz\message\models\InformAdmin';
  13. //增加通知员工 shish
  14. public static function addInform($params, $admin, $type, $TMList)
  15. {
  16. switch ($type) {
  17. case 'goodsSold':
  18. //宝贝售出
  19. $respond = self::goodsSoldInform($params, $admin, $TMList);
  20. break;
  21. case 'income':
  22. //收入提醒
  23. $respond = self::incomeInform($params, $admin, $TMList);
  24. break;
  25. case 'send':
  26. $respond = self::sendInform($params, $admin, $TMList);
  27. break;
  28. default:
  29. }
  30. $data = ['messageType' => 'inform', 'informWay' => 'wx', 'userType' => 'admin', 'id' => 6, 'mobile' => '15280215347'];
  31. $data = array_merge($data, $respond);
  32. $producer = Yii::$app->rabbitmq->getProducer('informProducer');
  33. $msg = serialize($data);
  34. Yii::info('消息通知:' . $msg);
  35. $producer->publish($msg, 'informExchange', 'informRoute');
  36. }
  37. //送到通知 shish 2020.1.31
  38. public static function sendInform($params, $admin, $TMList)
  39. {
  40. $totalFee = 199;
  41. $userName = '石头';
  42. $data['briefContent'] = "客户" . $userName . "付款" . $totalFee . '元';
  43. $openId = $admin['openId'];
  44. $shortTempId = 'OPENTM201205968';
  45. $tempId = isset($TMList[$shortTempId]) ? $TMList[$shortTempId] : '';
  46. $tMessage = ["touser" => $openId, "template_id" => $tempId,
  47. "url" => Yii::$app->params['frontUrl'] . "/center/order-detail?id=1225&account=12362",
  48. "data" => [
  49. "first" => ["value" => '您的订单已送达', "color" => "#173177"],
  50. "keyword1" => ["value" => (string)1525, "color" => "#173177"],
  51. "keyword2" => ["value" => '石头', "color" => "#173177"],
  52. "keyword3" => ["value" => '已送达', "color" => "#173177"],
  53. "remark" => ["value" => '感谢您惠顾,祝你生活愉快!', "color" => "#173177"]]
  54. ];
  55. $data['tMessage'] = json_encode($tMessage);
  56. $msg = "客户" . $userName . "付款" . $totalFee . '元';
  57. $data['content'] = $msg;
  58. return $data;
  59. }
  60. public static function incomeInform($params, $admin, $TMList)
  61. {
  62. $totalFee = 199;
  63. $orderSn = '2051229823132466';
  64. $orderName = '商品';
  65. $userName = '石头';
  66. $data['briefContent'] = "客户" . $userName . "付款" . $totalFee . '元';
  67. //收入提醒
  68. $openId = $admin['openId'];
  69. $shortTempId = 'OPENTM207422813';
  70. $tempId = isset($TMList[$shortTempId]) ? $TMList[$shortTempId] : '';
  71. $tMessage = ["touser" => $openId, "template_id" => $tempId, "url" => Yii::$app->params['adminUrl'] . '/order/detail?id=' . $orderSn, "data" => [
  72. "first" => ["value" => '您有宝贝售出哦!', "color" => "#173177"],
  73. "keyword1" => ["value" => (string)$orderSn, "color" => "#173177"],
  74. "keyword2" => ["value" => $orderName, "color" => "#173177"],
  75. "keyword3" => ["value" => number_format($totalFee, 2) . '元', "color" => "#173177"],
  76. "keyword4" => ["value" => number_format($totalFee, 2) . '元', "color" => "#173177"],
  77. "keyword5" => ["value" => $userName, "color" => "#173177"],
  78. "remark" => ["value" => '点此查看详细、编辑收花人信息。', "color" => "#173177"]]];
  79. $data['tMessage'] = json_encode($tMessage);
  80. $msg = "客户" . $userName . "付款" . $totalFee . '元';
  81. $data['content'] = $msg;
  82. return $data;
  83. }
  84. //添加通知内容 shish 2020.1.8
  85. public static function addData($data)
  86. {
  87. self::add($data);
  88. }
  89. //订单完成通知店长 shish 2020.3.19
  90. public static function sendComplete($order, $merchant)
  91. {
  92. $merchantId = $merchant['id'];
  93. $adminList = AdminClass::getAdminList($merchantId);
  94. if (empty($adminList)) {
  95. return false;
  96. }
  97. $remindUserIds = [];
  98. foreach ($adminList as $admin) {
  99. $remind = $admin['remind'];
  100. if ($remind == 1) {
  101. $remindUserIds[] = $admin['userId'];
  102. }
  103. }
  104. if(empty($remindUserIds)){
  105. return false;
  106. }
  107. $remindUserIds = array_filter(array_unique($remindUserIds));
  108. if (empty($remindUserIds)) {
  109. return false;
  110. }
  111. $userList = UserClass::getByIds($remindUserIds);
  112. $allTM = xhTMessageService::getList($merchantId);
  113. $shortTempId = 'OPENTM201205968';//订单送达通知
  114. $tempId = $allTM[$shortTempId];
  115. foreach ($userList as $user) {
  116. if (isset($user['subscribe']) && $user['subscribe'] == 1) {
  117. $openId = $user['openId'];
  118. $url = Yii::$app->params['shopDomain'] . "/#/admin/order/detail?id=" . $order['id'];
  119. $url = httpUtil::becomeHttps($url);
  120. $data = [
  121. "touser" => $openId,
  122. "template_id" => $tempId,
  123. "url" => $url,
  124. "data" => [
  125. "first" => ["value" => '客户订单已送达', "color" => "#173177"],
  126. "keyword1" => ["value" => (string)$order['orderSn'], "color" => "#173177"],
  127. "keyword2" => ["value" => $order['bookName'], "color" => "#173177"],
  128. "keyword3" => ["value" => '已送达', "color" => "#173177"],
  129. "remark" => ["value" => '', "color" => "#173177"]]];
  130. wxUtil::sendTaskInform($data, $merchant);
  131. }
  132. }
  133. }
  134. }