InformAdminClass.php 6.1 KB

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