InformAdminClass.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <?php
  2. namespace bizHd\message\classes;
  3. use bizHd\admin\classes\AdminClass;
  4. use bizHd\admin\classes\ShopAdminClass;
  5. use bizHd\admin\services\ShopAdminService;
  6. use biz\sj\classes\MerchantClass;
  7. use bizHd\user\classes\UserClass;
  8. use bizHd\wx\classes\WxOpenClass;
  9. use common\components\httpUtil;
  10. use common\components\sms;
  11. use common\components\wxUtil;
  12. use common\services\xhTMessageService;
  13. use Yii;
  14. use bizHd\base\classes\BaseClass;
  15. class InformAdminClass extends BaseClass
  16. {
  17. public static $baseFile = '\bizHd\message\models\InformAdmin';
  18. //增加通知员工 ssh
  19. public static function addInform($params, $shopAdmin, $type, $TMList)
  20. {
  21. //没有关注公众号暂时不进行通知
  22. $subscribe = isset($shopAdmin['adminBaseInfo']['subscribe']) ? $shopAdmin['adminBaseInfo']['subscribe'] : 0;
  23. if ($subscribe == 0) {
  24. return false;
  25. }
  26. //没有小程序id暂时不进行通知,目前只有小程序商家版,没有h5
  27. $miniOpenId = isset($shopAdmin['adminBaseInfo']['miniOpenId']) ? $shopAdmin['adminBaseInfo']['miniOpenId'] : '';
  28. if (empty($miniOpenId)) {
  29. return false;
  30. }
  31. $openMerchant = WxOpenClass::getWxInfo();
  32. $params['miniAppId'] = $openMerchant['miniAppId'];
  33. switch ($type) {
  34. case 'goodsSold':
  35. //宝贝售出
  36. $respond = self::goodsSoldInform($params, $shopAdmin, $TMList);
  37. break;
  38. case 'income':
  39. //收入提醒
  40. $respond = self::incomeInform($params, $shopAdmin, $TMList);
  41. break;
  42. case 'reach':
  43. $respond = self::reachInform($params, $shopAdmin, $TMList);
  44. break;
  45. default:
  46. }
  47. $shopAdminId = $shopAdmin['id'];
  48. $shopId = $shopAdmin['shopId'];
  49. $mobile = isset($shopAdmin['adminBaseInfo']['mobile']) ? $shopAdmin['adminBaseInfo']['mobile'] : '';
  50. //通知管理员的都是平台通知
  51. $isOpen = 1;
  52. $data = [
  53. 'messageType' => 'inform',
  54. 'informWay' => 'miniProgram',
  55. 'userType' => 'admin',
  56. 'mobile' => $mobile,
  57. 'shopAdminId' => $shopAdminId,
  58. 'userId' => 0,
  59. 'shopId' => $shopId,
  60. 'isOpen' => $isOpen,
  61. ];
  62. $data = array_merge($data, $respond);
  63. self::consumeInformQueue($data);
  64. return true;
  65. }
  66. //宝贝售出提醒 ssh 2020.5.31
  67. public static function goodsSoldInform($params, $admin, $TMList)
  68. {
  69. $totalFee = isset($params['totalFee']) ? $params['totalFee'] : 0;
  70. $orderId = isset($params['orderId']) ? $params['orderId'] : '';
  71. $orderSn = isset($params['orderSn']) ? $params['orderSn'] : '';
  72. $orderName = '商品';
  73. $userName = '石头';
  74. $data['briefContent'] = "客户" . $userName . "付款" . $totalFee . '元';
  75. //收入提醒
  76. $openId = isset($admin['adminBaseInfo']['openId']) ? $admin['adminBaseInfo']['openId'] : '';
  77. $miniOpenId = isset($admin['adminBaseInfo']['miniOpenId']) ? $admin['adminBaseInfo']['miniOpenId'] : '';
  78. $shortTempId = 'OPENTM207422813';
  79. $tempId = isset($TMList[$shortTempId]) ? $TMList[$shortTempId] : '';
  80. $tMessage = [
  81. "touser" => $openId,
  82. "template_id" => $tempId,
  83. "url" => Yii::$app->params['adminUrl'] . '/order/detail',
  84. "data" => [
  85. "first" => ["value" => '您有新的收入!', "color" => "#173177"],
  86. "keyword1" => ["value" => (string)$orderSn, "color" => "#173177"],
  87. "keyword2" => ["value" => $orderName, "color" => "#173177"],
  88. "keyword3" => ["value" => number_format($totalFee, 2) . '元', "color" => "#173177"],
  89. "keyword4" => ["value" => number_format($totalFee, 2) . '元', "color" => "#173177"],
  90. "keyword5" => ["value" => $userName, "color" => "#173177"],
  91. "remark" => ["value" => '点此查看详细', "color" => "#173177"]
  92. ]
  93. ];
  94. if (!empty($miniOpenId)) {
  95. $tMessage['miniprogram']['appid'] = $params['miniAppId'];
  96. $tMessage['miniprogram']['pagepath'] = 'admin/order/detail?id=' . $orderId;
  97. }
  98. $data['tMessage'] = json_encode($tMessage);
  99. $msg = "客户" . $userName . "付款" . $totalFee . '元';
  100. $data['content'] = $msg;
  101. return $data;
  102. }
  103. //送到通知 ssh 2020.1.31
  104. public static function reachInform($params, $admin, $TMList)
  105. {
  106. $totalFee = 199;
  107. $userName = '石头';
  108. $orderId = $params['orderId'];
  109. $data['briefContent'] = "客户" . $userName . "付款" . $totalFee . '元';
  110. $openId = isset($admin['openId']) && !empty($admin['openId']) ? $admin['openId'] : '';
  111. $miniOpenId = isset($admin['miniOpenId']) && !empty($admin['miniOpenId']) ? $admin['miniOpenId'] : '';
  112. $shortTempId = 'OPENTM201205968';
  113. $tempId = isset($TMList[$shortTempId]) ? $TMList[$shortTempId] : '';
  114. $tMessage = [
  115. "touser" => $openId,
  116. "template_id" => $tempId,
  117. "url" => Yii::$app->params['frontUrl'] . "/center/order-detail?id=1225&account=12362",
  118. "data" => [
  119. "first" => ["value" => '客户订单已送达', "color" => "#173177"],
  120. "keyword1" => ["value" => (string)1525, "color" => "#173177"],
  121. "keyword2" => ["value" => '石头', "color" => "#173177"],
  122. "keyword3" => ["value" => '已送达', "color" => "#173177"],
  123. "remark" => ["value" => '。。。。。。。', "color" => "#173177"]
  124. ]
  125. ];
  126. if (!empty($miniOpenId)) {
  127. $tMessage['miniprogram']['appid'] = $params['miniAppId'];
  128. $tMessage['miniprogram']['pagepath'] = 'admin/order/detail?id=' . $orderId;
  129. }
  130. $data['tMessage'] = json_encode($tMessage);
  131. $msg = "客户" . $userName . "付款" . $totalFee . '元';
  132. $data['content'] = $msg;
  133. return $data;
  134. }
  135. //收入提醒 ssh 2020.5.31
  136. public static function incomeInform($params, $admin, $TMList)
  137. {
  138. $order = $params['order'];
  139. $totalFee = isset($order['actPrice']) ? $order['actPrice'] : 0;
  140. $orderId = isset($order['id']) ? $order['id'] : '';
  141. $payTime = isset($order['payTime']) && !empty($order['payTime']) ? date("Y-m-d H:i", $order['payTime']) : '未知';
  142. $store = isset($order['store']) ? $order['store'] : 0;
  143. $sourceTypeId = $order['sourceType'];
  144. if ($store == 1) {
  145. $incomeStyle = '门店收入';
  146. } else {
  147. $sourceTypeList = [0 => '微信', 1 => '支付宝', 2 => '小程序', 3 => '朋友圈', 4 => '美团', 5 => '系统'];
  148. $incomeStyle = isset($sourceTypeList[$sourceTypeId]) ? $sourceTypeList[$sourceTypeId] . '收入' : '未知';
  149. }
  150. $data = [];
  151. $data['briefContent'] = "客户付款" . $totalFee . '元';
  152. $openId = isset($admin['adminBaseInfo']['openId']) ? $admin['adminBaseInfo']['openId'] : '';
  153. $miniOpenId = isset($admin['adminBaseInfo']['miniOpenId']) ? $admin['adminBaseInfo']['miniOpenId'] : '';
  154. $shortTempId = 'OPENTM207422813';
  155. $tempId = isset($TMList[$shortTempId]) ? $TMList[$shortTempId] : '';
  156. $tMessage = [
  157. "touser" => $openId,
  158. "template_id" => $tempId,
  159. "url" => Yii::$app->params['adminUrl'] . '/order/detail',
  160. "data" => [
  161. "first" => ["value" => '恭喜,您有新收入。', "color" => "#173177"],
  162. "keyword1" => ["value" => number_format($totalFee, 2) . '元', "color" => "#173177"],
  163. "keyword2" => ["value" => $incomeStyle, "color" => "#173177"],
  164. "keyword3" => ["value" => $payTime, "color" => "#173177"],
  165. "remark" => ["value" => '点此查看详情', "color" => "#173177"]
  166. ]
  167. ];
  168. if (!empty($miniOpenId)) {
  169. $tMessage['miniprogram']['appid'] = $params['miniAppId'];
  170. $tMessage['miniprogram']['pagepath'] = 'admin/order/detail?id=' . $orderId;
  171. }
  172. $data['tMessage'] = json_encode($tMessage);
  173. $msg = "客户付款" . $totalFee . '元';
  174. $data['content'] = $msg;
  175. return $data;
  176. }
  177. //添加通知内容 ssh 2020.1.8
  178. public static function addData($data)
  179. {
  180. self::add($data);
  181. }
  182. //订单完成通知店长 ssh 2020.3.19
  183. public static function sendComplete($order)
  184. {
  185. $open = WxOpenClass::getWxInfo();
  186. $sjId = $order['sjId'];
  187. $orderId = $order['id'];
  188. $shopId = $order['shopId'];
  189. $merchant = MerchantClass::getMerchantById($sjId);
  190. if (empty($shopId)) {
  191. $shopId = MerchantClass::getDefaultShopId($merchant);
  192. }
  193. $adminList = ShopAdminService::getNoticeAdminList($shopId);
  194. $tm = xhTMessageService::getList(0);
  195. $shortTempId = 'OPENTM201205968';//订单送达通知
  196. $tempId = $tm[$shortTempId];
  197. if (!empty($adminList)) {
  198. foreach ($adminList as $admin) {
  199. if (isset($admin['adminBaseInfo']['subscribe']) && $admin['adminBaseInfo']['subscribe'] == 1) {
  200. $openId = isset($admin['adminBaseInfo']['openId']) ? $admin['adminBaseInfo']['openId'] : '';
  201. $miniOpenId = isset($admin['adminBaseInfo']['miniOpenId']) ? $admin['adminBaseInfo']['miniOpenId'] : '';
  202. $url = Yii::$app->params['hdDomain'] . "/#/admin/order/detail?id=" . $order['id'];
  203. $url = httpUtil::becomeHttps($url);
  204. $data = [
  205. "touser" => $openId,
  206. "template_id" => $tempId,
  207. "url" => $url,
  208. "data" => [
  209. "first" => ["value" => '客户订单已送达', "color" => "#173177"],
  210. "keyword1" => ["value" => (string)$order['orderSn'], "color" => "#173177"],
  211. "keyword2" => ["value" => $order['bookName'], "color" => "#173177"],
  212. "keyword3" => ["value" => '已送达', "color" => "#173177"],
  213. "remark" => ["value" => '', "color" => "#173177"]
  214. ]
  215. ];
  216. if (!empty($miniOpenId)) {
  217. $data['miniprogram']['appid'] = $open['miniAppId'];
  218. $data['miniprogram']['pagepath'] = 'admin/order/detail?id=' . $orderId;
  219. }
  220. wxUtil::sendTaskInform($data, $open);
  221. }
  222. }
  223. }
  224. }
  225. //消费通知内容 ssh 2020.1.1
  226. //['messageType'=>'inform','informWay'=>'miniProgram','userType'=>'admin','shopAdminId'=>913,'mobile'=>'15280215347','tMessage'=>'','content'=>'','briefContent'=>'','isOpen'=>1]
  227. public static function consumeInformQueue($data)
  228. {
  229. $informWay = $data['informWay'];
  230. $shopAdminId = isset($data['shopAdminId']) ? $data['shopAdminId'] : 0;
  231. if (empty($shopAdminId)) {
  232. echo "\n 没有找到门店管理员 \n";
  233. util::end();
  234. }
  235. $shopAdmin = ShopAdminClass::getById($shopAdminId);
  236. $sjId = $shopAdmin['sjId'];
  237. $adminId = $shopAdmin['adminId'];
  238. $mobile = $data['mobile'];
  239. $isOpen = isset($data['isOpen']) ? $data['isOpen'] : 0;
  240. $merchant = WxOpenClass::getWxInfo();
  241. $hasSend = 0;
  242. $noticeWay = 0;
  243. if ($informWay == 'wx') {
  244. $tMessage = json_decode($data['tMessage'], true);
  245. wxUtil::sendTaskInform($tMessage, $merchant, $isOpen);
  246. $hasSend = 1;
  247. $noticeWay = 0;
  248. } elseif ($informWay == 'sms') {
  249. $msg = $data['content'];
  250. sms::merchantSend($mobile, $msg, $merchant);
  251. $hasSend = 1;
  252. $noticeWay = 1;
  253. } elseif ($informWay == 'miniProgram') {
  254. $tMessage = json_decode($data['tMessage'], true);
  255. wxUtil::sendTaskInform($tMessage, $merchant);
  256. $hasSend = 1;
  257. $noticeWay = 0;
  258. } else {
  259. }
  260. //存入数据库
  261. $informData = [
  262. 'adminId' => $adminId,
  263. 'sjId' => $sjId,
  264. 'noticeType' => 0,
  265. 'content' => $data['briefContent'],
  266. 'noticeWay' => $noticeWay,
  267. 'status' => $hasSend,
  268. 'sourceType' => 0,
  269. 'sourceId' => 0,
  270. 'addTime' => time(),
  271. 'createTime' => date("Y-m-d H:i:s"),
  272. ];
  273. InformAdminClass::addData($informData);
  274. return true;
  275. }
  276. }