InformAdminClass.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. namespace biz\message\classes;
  3. use biz\admin\classes\AdminClass;
  4. use biz\admin\services\ShopAdminService;
  5. use biz\user\classes\UserClass;
  6. use common\components\httpUtil;
  7. use common\components\wxUtil;
  8. use common\services\xhTMessageService;
  9. use Yii;
  10. use biz\base\classes\BaseClass;
  11. class InformAdminClass extends BaseClass
  12. {
  13. public static $baseFile = '\biz\message\models\InformAdmin';
  14. //增加通知员工 shish
  15. public static function addInform($params, $shopAdmin, $type, $TMList)
  16. {
  17. //没有关注公众号暂时不进行通知
  18. $subscribe = isset($shopAdmin['adminBaseInfo']['subscribe']) ? $shopAdmin['adminBaseInfo']['subscribe'] : 0;
  19. if ($subscribe == 0) {
  20. return false;
  21. }
  22. //没有小程序id暂时不进行通知,目前只有小程序商家版,没有h5
  23. $miniOpenId = isset($shopAdmin['adminBaseInfo']['miniOpenId']) ? $shopAdmin['adminBaseInfo']['miniOpenId'] : '';
  24. if (empty($miniOpenId)) {
  25. return false;
  26. }
  27. switch ($type) {
  28. case 'goodsSold':
  29. //宝贝售出
  30. $respond = self::goodsSoldInform($params, $shopAdmin, $TMList);
  31. break;
  32. case 'income':
  33. //收入提醒
  34. $respond = self::incomeInform($params, $shopAdmin, $TMList);
  35. break;
  36. case 'send':
  37. $respond = self::sendInform($params, $shopAdmin, $TMList);
  38. break;
  39. default:
  40. }
  41. $shopAdminId = $shopAdmin['id'];
  42. $shopId = $shopAdmin['shopId'];
  43. $mobile = isset($shopAdmin['adminBaseInfo']['mobile']) ? $shopAdmin['adminBaseInfo']['mobile'] : '';
  44. //通知管理员的都是平台通知
  45. $isOpen = 1;
  46. $data = [
  47. 'messageType' => 'inform',
  48. 'informWay' => 'miniProgram',
  49. 'userType' => 'admin',
  50. 'mobile' => $mobile,
  51. 'shopAdminId' => $shopAdminId,
  52. 'userId' => 0,
  53. 'shopId' => $shopId,
  54. 'isOpen' => $isOpen,
  55. ];
  56. $data = array_merge($data, $respond);
  57. $producer = Yii::$app->rabbitmq->getProducer('informProducer');
  58. $msg = serialize($data);
  59. Yii::info('消息通知:' . $msg);
  60. $producer->publish($msg, 'informExchange', 'informRoute');
  61. }
  62. //宝贝售出提醒 shish 2020.5.31
  63. public static function goodsSoldInform($params, $admin, $TMList)
  64. {
  65. }
  66. //送到通知 shish 2020.1.31
  67. public static function sendInform($params, $admin, $TMList)
  68. {
  69. $totalFee = 199;
  70. $userName = '石头';
  71. $orderId = $params['orderId'];
  72. $data['briefContent'] = "客户" . $userName . "付款" . $totalFee . '元';
  73. $openId = isset($admin['openId']) && !empty($admin['openId']) ? $admin['openId'] : '';
  74. $miniOpenId = isset($admin['miniOpenId']) && !empty($admin['miniOpenId']) ? $admin['miniOpenId'] : '';
  75. $shortTempId = 'OPENTM201205968';
  76. $tempId = isset($TMList[$shortTempId]) ? $TMList[$shortTempId] : '';
  77. $tMessage = [
  78. "touser" => $openId,
  79. "template_id" => $tempId,
  80. "url" => Yii::$app->params['frontUrl'] . "/center/order-detail?id=1225&account=12362",
  81. "data" => [
  82. "first" => ["value" => '客户订单已送达', "color" => "#173177"],
  83. "keyword1" => ["value" => (string)1525, "color" => "#173177"],
  84. "keyword2" => ["value" => '石头', "color" => "#173177"],
  85. "keyword3" => ["value" => '已送达', "color" => "#173177"],
  86. "remark" => ["value" => '。。。。。。。', "color" => "#173177"]
  87. ]
  88. ];
  89. if (!empty($miniOpenId)) {
  90. $tMessage['miniprogram']['appid'] = $params['miniAppId'];
  91. $tMessage['miniprogram']['pagepath'] = 'admin/order/detail?id=' . $orderId;
  92. }
  93. $data['tMessage'] = json_encode($tMessage);
  94. $msg = "客户" . $userName . "付款" . $totalFee . '元';
  95. $data['content'] = $msg;
  96. return $data;
  97. }
  98. public static function incomeInform($params, $admin, $TMList)
  99. {
  100. $totalFee = isset($params['totalFee']) ? $params['totalFee'] : 0;
  101. $orderId = isset($params['orderId']) ? $params['orderId'] : '';
  102. $orderSn = isset($params['orderSn']) ? $params['orderSn'] : '';
  103. $orderName = '商品';
  104. $userName = '石头';
  105. $data['briefContent'] = "客户" . $userName . "付款" . $totalFee . '元';
  106. //收入提醒
  107. $openId = isset($admin['adminBaseInfo']['openId']) ? $admin['adminBaseInfo']['openId'] : '';
  108. $miniOpenId = isset($admin['adminBaseInfo']['miniOpenId']) ? $admin['adminBaseInfo']['miniOpenId'] : '';
  109. $shortTempId = 'OPENTM207422813';
  110. $tempId = isset($TMList[$shortTempId]) ? $TMList[$shortTempId] : '';
  111. $tMessage = [
  112. "touser" => $openId,
  113. "template_id" => $tempId,
  114. "url" => Yii::$app->params['adminUrl'] . '/order/detail',
  115. "data" => [
  116. "first" => ["value" => '您有宝贝售出哦!', "color" => "#173177"],
  117. "keyword1" => ["value" => (string)$orderSn, "color" => "#173177"],
  118. "keyword2" => ["value" => $orderName, "color" => "#173177"],
  119. "keyword3" => ["value" => number_format($totalFee, 2) . '元', "color" => "#173177"],
  120. "keyword4" => ["value" => number_format($totalFee, 2) . '元', "color" => "#173177"],
  121. "keyword5" => ["value" => $userName, "color" => "#173177"],
  122. "remark" => ["value" => '点此查看详细、编辑收花人信息。', "color" => "#173177"]
  123. ]
  124. ];
  125. if (!empty($miniOpenId)) {
  126. $tMessage['miniprogram']['appid'] = $params['miniAppId'];
  127. $tMessage['miniprogram']['pagepath'] = 'admin/order/detail?id=' . $orderId;
  128. }
  129. $data['tMessage'] = json_encode($tMessage);
  130. $msg = "客户" . $userName . "付款" . $totalFee . '元';
  131. $data['content'] = $msg;
  132. return $data;
  133. }
  134. //添加通知内容 shish 2020.1.8
  135. public static function addData($data)
  136. {
  137. self::add($data);
  138. }
  139. //订单完成通知店长 shish 2020.3.19
  140. public static function sendComplete($order, $merchant)
  141. {
  142. $merchantId = $merchant['id'];
  143. $orderId = $order['id'];
  144. $shopId = $order['shopId'];
  145. $adminList = ShopAdminService::getNoticeAdminList($shopId);
  146. $tm = xhTMessageService::getList($merchantId);
  147. $shortTempId = 'OPENTM201205968';//订单送达通知
  148. $tempId = $tm[$shortTempId];
  149. if (!empty($adminList)) {
  150. foreach ($adminList as $admin) {
  151. if (isset($admin['subscribe']) && $admin['subscribe'] == 1) {
  152. $openId = $admin['openId'];
  153. $miniOpenId = $admin['miniOpenId'];
  154. $url = Yii::$app->params['shopDomain'] . "/#/admin/order/detail?id=" . $order['id'];
  155. $url = httpUtil::becomeHttps($url);
  156. $data = [
  157. "touser" => $openId,
  158. "template_id" => $tempId,
  159. "url" => $url,
  160. "data" => [
  161. "first" => ["value" => '客户订单已送达', "color" => "#173177"],
  162. "keyword1" => ["value" => (string)$order['orderSn'], "color" => "#173177"],
  163. "keyword2" => ["value" => $order['bookName'], "color" => "#173177"],
  164. "keyword3" => ["value" => '已送达', "color" => "#173177"],
  165. "remark" => ["value" => '', "color" => "#173177"]
  166. ]
  167. ];
  168. if (!empty($miniOpenId)) {
  169. $data['miniprogram']['appid'] = $merchant['miniAppId'];
  170. $data['miniprogram']['pagepath'] = 'admin/order/detail?id=' . $orderId;
  171. }
  172. wxUtil::sendTaskInform($data, $merchant);
  173. }
  174. }
  175. }
  176. }
  177. }