InformAdminClass.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. //没有关注公众号暂时不进行通知
  17. if (isset($admin['subscribe']) == false && $admin['subscribe'] == 0) {
  18. return false;
  19. }
  20. //没有小程序id暂时不进行通知,目前只有小程序商家版,没有h5
  21. if (isset($admin['miniOpenId']) == false || empty($admin['miniOpenId'])) {
  22. return false;
  23. }
  24. switch ($type) {
  25. case 'goodsSold':
  26. //宝贝售出
  27. $respond = self::goodsSoldInform($params, $admin, $TMList);
  28. break;
  29. case 'income':
  30. //收入提醒
  31. $respond = self::incomeInform($params, $admin, $TMList);
  32. break;
  33. case 'send':
  34. $respond = self::sendInform($params, $admin, $TMList);
  35. break;
  36. default:
  37. }
  38. $data = ['messageType' => 'inform', 'informWay' => 'miniProgram', 'userType' => 'admin', 'id' => 6, 'mobile' => '15280215347'];
  39. $data = array_merge($data, $respond);
  40. $producer = Yii::$app->rabbitmq->getProducer('informProducer');
  41. $msg = serialize($data);
  42. Yii::info('消息通知:' . $msg);
  43. $producer->publish($msg, 'informExchange', 'informRoute');
  44. }
  45. //送到通知 shish 2020.1.31
  46. public static function sendInform($params, $admin, $TMList)
  47. {
  48. $totalFee = 199;
  49. $userName = '石头';
  50. $data['briefContent'] = "客户" . $userName . "付款" . $totalFee . '元';
  51. $openId = isset($admin['openId']) && !empty($admin['openId']) ? $admin['openId'] : '';
  52. $miniOpenId = isset($admin['miniOpenId']) && !empty($admin['miniOpenId']) ? $admin['miniOpenId'] : '';
  53. $shortTempId = 'OPENTM201205968';
  54. $tempId = isset($TMList[$shortTempId]) ? $TMList[$shortTempId] : '';
  55. $tMessage = [
  56. "touser" => $openId,
  57. "template_id" => $tempId,
  58. "url" => Yii::$app->params['frontUrl'] . "/center/order-detail?id=1225&account=12362",
  59. "data" => [
  60. "first" => ["value" => '您的订单已送达', "color" => "#173177"],
  61. "keyword1" => ["value" => (string)1525, "color" => "#173177"],
  62. "keyword2" => ["value" => '石头', "color" => "#173177"],
  63. "keyword3" => ["value" => '已送达', "color" => "#173177"],
  64. "remark" => ["value" => '感谢您惠顾,祝你生活愉快!', "color" => "#173177"]
  65. ]
  66. ];
  67. $data['tMessage'] = json_encode($tMessage);
  68. $msg = "客户" . $userName . "付款" . $totalFee . '元';
  69. $data['content'] = $msg;
  70. return $data;
  71. }
  72. public static function incomeInform($params, $admin, $TMList)
  73. {
  74. $totalFee = 199;
  75. $orderSn = '2051229823132466';
  76. $orderId = $params['orderId'];
  77. $orderName = '商品';
  78. $userName = '石头';
  79. $data['briefContent'] = "客户" . $userName . "付款" . $totalFee . '元';
  80. //收入提醒
  81. $openId = isset($admin['openId']) && !empty($admin['openId']) ? $admin['openId'] : '';
  82. $miniOpenId = isset($admin['miniOpenId']) && !empty($admin['miniOpenId']) ? $admin['miniOpenId'] : '';
  83. $shortTempId = 'OPENTM207422813';
  84. $tempId = isset($TMList[$shortTempId]) ? $TMList[$shortTempId] : '';
  85. $tMessage = [
  86. "touser" => $openId,
  87. "template_id" => $tempId,
  88. "url" => Yii::$app->params['adminUrl'] . '/order/detail?id=' . $orderSn,
  89. "data" => [
  90. "first" => ["value" => '您有宝贝售出哦!', "color" => "#173177"],
  91. "keyword1" => ["value" => (string)$orderSn, "color" => "#173177"],
  92. "keyword2" => ["value" => $orderName, "color" => "#173177"],
  93. "keyword3" => ["value" => number_format($totalFee, 2) . '元', "color" => "#173177"],
  94. "keyword4" => ["value" => number_format($totalFee, 2) . '元', "color" => "#173177"],
  95. "keyword5" => ["value" => $userName, "color" => "#173177"],
  96. "remark" => ["value" => '点此查看详细、编辑收花人信息。', "color" => "#173177"]
  97. ]
  98. ];
  99. if (!empty($miniOpenId)) {
  100. $tMessage['miniprogram']['appid'] = $params['miniAppId'];
  101. $tMessage['miniprogram']['pagepath'] = 'admin/order/detail?id=' . $orderId;
  102. }
  103. $data['tMessage'] = json_encode($tMessage);
  104. $msg = "客户" . $userName . "付款" . $totalFee . '元';
  105. $data['content'] = $msg;
  106. return $data;
  107. }
  108. //添加通知内容 shish 2020.1.8
  109. public static function addData($data)
  110. {
  111. self::add($data);
  112. }
  113. //订单完成通知店长 shish 2020.3.19
  114. public static function sendComplete($order, $merchant)
  115. {
  116. $merchantId = $merchant['id'];
  117. $adminList = AdminClass::getAdminList($merchantId);
  118. if (empty($adminList)) {
  119. return false;
  120. }
  121. $remindUserIds = [];
  122. foreach ($adminList as $admin) {
  123. $remind = $admin['remind'];
  124. if ($remind == 1) {
  125. $remindUserIds[] = $admin['userId'];
  126. }
  127. }
  128. if (empty($remindUserIds)) {
  129. return false;
  130. }
  131. $remindUserIds = array_filter(array_unique($remindUserIds));
  132. if (empty($remindUserIds)) {
  133. return false;
  134. }
  135. // $userList = UserClass::getByIds($remindUserIds);
  136. //
  137. // $allTM = xhTMessageService::getList($merchantId);
  138. // $shortTempId = 'OPENTM201205968';//订单送达通知
  139. // $tempId = $allTM[$shortTempId];
  140. //
  141. // foreach ($userList as $user) {
  142. // if (isset($user['subscribe']) && $user['subscribe'] == 1) {
  143. // $openId = $user['openId'];
  144. // $url = Yii::$app->params['shopDomain'] . "/#/admin/order/detail?id=" . $order['id'];
  145. // $url = httpUtil::becomeHttps($url);
  146. // $data = [
  147. // "touser" => $openId,
  148. // "template_id" => $tempId,
  149. // "url" => $url,
  150. // "data" => [
  151. // "first" => ["value" => '客户订单已送达', "color" => "#173177"],
  152. // "keyword1" => ["value" => (string)$order['orderSn'], "color" => "#173177"],
  153. // "keyword2" => ["value" => $order['bookName'], "color" => "#173177"],
  154. // "keyword3" => ["value" => '已送达', "color" => "#173177"],
  155. // "remark" => ["value" => '', "color" => "#173177"]
  156. // ]
  157. // ];
  158. // wxUtil::sendTaskInform($data, $merchant);
  159. // }
  160. // }
  161. }
  162. }