NoticeListener.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\listener\notice;
  12. use app\jobs\notice\PrintJob;
  13. use app\services\message\NoticeService;
  14. use app\services\message\notice\{
  15. EnterpriseWechatService,
  16. RoutineTemplateListService,
  17. SmsService,
  18. SystemMsgService,
  19. WechatTemplateListService
  20. };
  21. use app\services\order\StoreOrderCartInfoServices;
  22. use app\services\user\UserServices;
  23. use crmeb\interfaces\ListenerInterface;
  24. use crmeb\utils\Str;
  25. /**
  26. * 消息类
  27. * @author: 吴汐
  28. * @email: 442384644@qq.com
  29. * @date: 2023/8/29
  30. */
  31. class NoticeListener implements ListenerInterface
  32. {
  33. /**
  34. * @var array
  35. */
  36. protected $services = [];
  37. /**
  38. * 方法
  39. * @var string[]
  40. */
  41. protected $eventMethods = [
  42. 'bind_spread_uid' => 'handleBindSpreadUid',
  43. 'order_pay_success' => 'handleOrderPaySuccess',
  44. 'order_deliver_success' => 'handleOrderDeliverSuccess',
  45. 'order_postage_success' => 'handleOrderPostageSuccess',
  46. 'order_take' => 'handleOrderTake',
  47. 'price_revision' => 'handlePriceRevision',
  48. 'order_refund' => 'handleOrderRefund',
  49. 'send_order_refund_no_status' => 'handleSendOrderRefundNoStatus',
  50. 'recharge_success' => 'handleRechargeSuccess',
  51. 'recharge_order_refund_status' => 'handleRechargeOrderRefundStatus',
  52. 'integral_accout' => 'handleIntegralAccout',
  53. 'order_brokerage' => 'handleOrderBrokerage',
  54. 'bargain_success' => 'handleBargainSuccess',
  55. 'can_pink_success' => 'handlePinkSuccess',
  56. 'open_pink_success' => 'handlePinkSuccess',
  57. 'order_user_groups_success' => 'handleGroupsSuccess',
  58. 'send_order_pink_fial' => 'handlePinkFail',
  59. 'send_order_pink_clone' => 'handlePinkFail',
  60. 'user_extract' => 'handleUserExtract',
  61. 'user_balance_change' => 'handleUserBalanceChange',
  62. 'order_pay_false' => 'handleOrderPayFalse',
  63. 'admin_pay_success_code' => 'handleAdminPaySuccessCode',
  64. 'send_admin_confirm_take_over' => 'handleSendAdminConfirmTakeOver',
  65. 'send_order_apply_refund' => 'handleSendOrderApplyRefund',
  66. 'kefu_send_extract_application' => 'handleKefuSendExtractApplication',
  67. // add more event-method mappings here...
  68. ];
  69. /**
  70. * 启动加载
  71. */
  72. public function __construct()
  73. {
  74. $this->services = [
  75. 'Wechat' => app()->make(WechatTemplateListService::class),
  76. 'Routine' => app()->make(RoutineTemplateListService::class),
  77. 'SysMsg' => app()->make(SystemMsgService::class),
  78. 'WeWork' => app()->make(EnterpriseWechatService::class),
  79. 'Sms' => app()->make(SmsService::class)
  80. ];
  81. }
  82. /**
  83. * 获取对象
  84. * @param $mark
  85. * @return NoticeService
  86. * @author: 吴汐
  87. * @email: 442384644@qq.com
  88. * @date: 2023/8/29
  89. */
  90. private function getNoticeService($mark)
  91. {
  92. return $this->services[$mark];
  93. }
  94. /**
  95. * 执行方法
  96. * @param $event
  97. * @author: 吴汐
  98. * @email: 442384644@qq.com
  99. * @date: 2023/8/29
  100. */
  101. public function handle($event): void
  102. {
  103. try {
  104. [$data, $mark] = $event;
  105. if ($mark) {
  106. $this->getNoticeService('SysMsg')->setEvent($mark); //站内信
  107. $this->getNoticeService('Sms')->setEvent($mark); //短信
  108. $this->getNoticeService('Wechat')->setEvent($mark); //模版消息
  109. $this->getNoticeService('Routine')->setEvent($mark); //订阅消息
  110. $this->getNoticeService('WeWork')->setEvent($mark); //企业微信消息
  111. if (isset($this->eventMethods[$mark])) {
  112. $method = $this->eventMethods[$mark];
  113. call_user_func([$this, $method], $data);
  114. }
  115. }
  116. } catch (\Throwable $e) {
  117. }
  118. }
  119. /**
  120. * 推广新用户给上级发送消息
  121. * @param $data
  122. * @return bool
  123. * @author: 吴汐
  124. * @email: 442384644@qq.com
  125. * @date: 2023/8/29
  126. */
  127. protected function handleBindSpreadUid($data)
  128. {
  129. if (isset($data['spreadUid']) && $data['spreadUid']) {
  130. $name = $data['nickname'] ?? '';
  131. //站内信
  132. $this->getNoticeService('SysMsg')->sendMsg($data['spreadUid'], ['nickname' => $name]);
  133. }
  134. return true;
  135. }
  136. /**
  137. * 支付成功给用户发送消息
  138. * @param $data
  139. * @return bool
  140. * @author: 吴汐
  141. * @email: 442384644@qq.com
  142. * @date: 2023/8/29
  143. */
  144. protected function handleOrderPaySuccess($data)
  145. {
  146. $pay_price = $data['pay_price'];
  147. $order_id = $data['order_id'];
  148. $data['is_channel'] = $data['is_channel'] ?? 2;
  149. $data['total_num'] = $data['total_num'] ?? 1;
  150. $data['storeName'] = Str::substrUTf8($data['storeName'], 20, 'UTF-8', '');
  151. //站内信
  152. $this->getNoticeService('SysMsg')->sendMsg($data['uid'], ['order_id' => $data['order_id'], 'total_num' => $data['total_num'], 'pay_price' => $data['pay_price']]);
  153. //短信
  154. $this->getNoticeService('Sms')->sendSms($data['user_phone'], compact('order_id', 'pay_price'));
  155. //模板消息公众号模版消息
  156. $this->getNoticeService('Wechat')->sendOrderPaySuccess($data['uid'], $data);
  157. //模板消息小程序订阅消息
  158. $this->getNoticeService('Routine')->sendOrderSuccess($data['uid'], $data['pay_price'], $data['order_id']);
  159. //小票打印
  160. if (isset($data['cart_id']) && $data['cart_id']) PrintJob::dispatch([$data['id']]);
  161. return true;
  162. }
  163. /**
  164. * 送货给用户发送消息
  165. * @param $data
  166. * @return bool
  167. * @author: 吴汐
  168. * @email: 442384644@qq.com
  169. * @date: 2023/8/29
  170. */
  171. protected function handleOrderDeliverSuccess($data)
  172. {
  173. $orderInfo = $data['orderInfo'];
  174. $storeTitle = $data['storeName'];
  175. $order_id = $orderInfo->order_id;
  176. $store_name = $storeTitle;
  177. $storeTitle = Str::substrUTf8($storeTitle, 20, 'UTF-8', '');
  178. $nickname = app()->make(UserServices::class)->value(['uid' => $orderInfo->uid], 'nickname');
  179. //站内信
  180. $this->getNoticeService('SysMsg')->sendMsg($orderInfo['uid'], ['nickname' => $nickname, 'store_name' => $storeTitle, 'order_id' => $orderInfo['order_id'], 'delivery_name' => $orderInfo['delivery_name'], 'delivery_id' => $orderInfo['delivery_id'], 'user_address' => $orderInfo['user_address']]);
  181. //短信
  182. $this->getNoticeService('Sms')->sendSms($orderInfo->user_phone, compact('order_id', 'store_name', 'nickname'));
  183. //模板消息公众号模版消息
  184. $this->getNoticeService('Wechat')->sendOrderDeliver($orderInfo['uid'], $storeTitle, $orderInfo->toArray());
  185. //模板消息小程序订阅消息
  186. $this->getNoticeService('Routine')->sendOrderPostage($orderInfo['uid'], $orderInfo->toArray(), $storeTitle, 0);
  187. return true;
  188. }
  189. /**
  190. * 发快递给用户发送消息
  191. * @param $data
  192. * @return bool
  193. * @author: 吴汐
  194. * @email: 442384644@qq.com
  195. * @date: 2023/8/29
  196. */
  197. protected function handleOrderPostageSuccess($data)
  198. {
  199. $orderInfo = $data['orderInfo'];
  200. $storeTitle = $data['storeName'];
  201. $order_id = $orderInfo->order_id;
  202. $store_name = $storeTitle;
  203. $storeTitle = Str::substrUTf8($storeTitle, 20, 'UTF-8', '');
  204. $nickname = app()->make(UserServices::class)->value(['uid' => $orderInfo->uid], 'nickname');
  205. //站内信
  206. $this->getNoticeService('SysMsg')->sendMsg($orderInfo['uid'], ['nickname' => $nickname, 'store_name' => $storeTitle, 'order_id' => $orderInfo['order_id'], 'delivery_name' => $orderInfo['delivery_name'], 'delivery_id' => $orderInfo['delivery_id'], 'user_address' => $orderInfo['user_address']]);
  207. //短信
  208. $this->getNoticeService('Sms')->sendSms($orderInfo->user_phone, compact('order_id', 'store_name', 'nickname'));
  209. //模板消息公众号模版消息
  210. $this->getNoticeService('Wechat')->sendOrderPostage($orderInfo['uid'], $orderInfo->toArray(), $storeTitle);
  211. //模板消息小程序订阅消息
  212. $this->getNoticeService('Routine')->sendOrderPostage($orderInfo['uid'], $orderInfo->toArray(), $storeTitle, 1);
  213. return true;
  214. }
  215. /**
  216. * 确认收货给用户发送消息
  217. * @param $data
  218. * @return bool
  219. * @author: 吴汐
  220. * @email: 442384644@qq.com
  221. * @date: 2023/8/29
  222. */
  223. protected function handleOrderTake($data)
  224. {
  225. $order = is_object($data['order']) ? $data['order']->toArray() : $data['order'];
  226. $store_name = Str::substrUTf8($data['storeTitle'], 20, 'UTF-8', '');
  227. $order_id = $order['order_id'];
  228. //站内信
  229. $this->getNoticeService('SysMsg')->sendMsg($order['uid'], ['order_id' => $order['order_id'], 'store_name' => $store_name]);
  230. //短信
  231. $this->getNoticeService('Sms')->sendSms($order['user_phone'], compact('store_name', 'order_id'));
  232. //模板消息公众号模版消息
  233. $this->getNoticeService('Wechat')->sendOrderTakeSuccess($order['uid'], $order, $store_name);
  234. //模板消息小程序订阅消息
  235. $this->getNoticeService('Routine')->sendOrderTakeOver($order['uid'], $order, $store_name);
  236. return true;
  237. }
  238. /**
  239. * 改价给用户发送消息
  240. * @param $data
  241. * @return bool
  242. * @throws \think\db\exception\DataNotFoundException
  243. * @throws \think\db\exception\DbException
  244. * @throws \think\db\exception\ModelNotFoundException
  245. * @author: 吴汐
  246. * @email: 442384644@qq.com
  247. * @date: 2023/8/29
  248. */
  249. protected function handlePriceRevision($data)
  250. {
  251. $order = $data['order'];
  252. $pay_price = $data['pay_price'];
  253. $order['storeName'] = app()->make(StoreOrderCartInfoServices::class)->getCarIdByProductTitle((int)$order['id']);
  254. //站内信
  255. $this->getNoticeService('SysMsg')->sendMsg($order['uid'], ['order_id' => $order['order_id'], 'pay_price' => $pay_price]);
  256. //短信
  257. $this->getNoticeService('Sms')->sendSms($order['user_phone'], ['order_id' => $order['order_id'], 'pay_price' => $pay_price]);
  258. return true;
  259. }
  260. /**
  261. * 退款成功给用户发送消息
  262. * @param $data
  263. * @return bool
  264. * @throws \think\db\exception\DataNotFoundException
  265. * @throws \think\db\exception\DbException
  266. * @throws \think\db\exception\ModelNotFoundException
  267. * @author: 吴汐
  268. * @email: 442384644@qq.com
  269. * @date: 2023/8/29
  270. */
  271. protected function handleOrderRefund($data)
  272. {
  273. $datas = $data['data'];
  274. $order = $data['order'];
  275. $order['refund_price'] = $datas['refund_price'];
  276. $order['refund_no'] = $datas['refund_no'];
  277. $storeName = app()->make(StoreOrderCartInfoServices::class)->getCarIdByProductTitle((int)$order['id']);
  278. $storeTitle = Str::substrUTf8($storeName, 20, 'UTF-8', '');
  279. //站内信
  280. $this->getNoticeService('SysMsg')->sendMsg($order['uid'], ['order_id' => $order['order_id'], 'pay_price' => $order['pay_price'], 'refund_price' => $datas['refund_price']]);
  281. //短信
  282. $this->getNoticeService('Sms')->sendSms($order['user_phone'], ['order_id' => $order['order_id'], 'refund_price' => $order['refund_price']]);
  283. //模板消息公众号模版消息
  284. $this->getNoticeService('Wechat')->sendOrderRefund($order['uid'], $order, $storeTitle);
  285. //模板消息小程序订阅消息
  286. $this->getNoticeService('Routine')->sendOrderRefundSuccess($order['uid'], $order, $storeTitle, $datas);
  287. return true;
  288. }
  289. /**
  290. * 退款未通过给用户发送消息
  291. * @param $data
  292. * @return bool
  293. * @author: 吴汐
  294. * @email: 442384644@qq.com
  295. * @date: 2023/8/29
  296. */
  297. protected function handleSendOrderRefundNoStatus($data)
  298. {
  299. $order = $data['orderInfo'];
  300. $order['pay_price'] = $order['refund_price'];
  301. $order['refund_no'] = $order['order_id'];
  302. $storeTitle = Str::substrUTf8($order['cart_info'][0]['productInfo']['store_name'], 20, 'UTF-8', '');
  303. //站内信
  304. $this->getNoticeService('SysMsg')->sendMsg($order['uid'], ['order_id' => $order['order_id'], 'pay_price' => $order['refund_price'], 'store_name' => $storeTitle]);
  305. //模板消息
  306. $this->getNoticeService('Wechat')->sendOrderNoRefund($order['uid'], $order, $storeTitle);
  307. //小程序订阅消息
  308. $this->getNoticeService('Routine')->sendOrderRefundFail($order['uid'], $order, $storeTitle);
  309. return true;
  310. }
  311. /**
  312. * 充值成功给用户发消息
  313. * @param $data
  314. * @return bool
  315. * @author: 吴汐
  316. * @email: 442384644@qq.com
  317. * @date: 2023/8/29
  318. */
  319. protected function handleRechargeSuccess($data)
  320. {
  321. $order = $data['order'];
  322. $order['now_money'] = $data['now_money'];
  323. //站内信
  324. $this->getNoticeService('SysMsg')->sendMsg($order['uid'], ['order_id' => $order['order_id'], 'price' => $order['price'], 'now_money' => $order['now_money']]);
  325. //模板消息公众号模版消息
  326. $this->getNoticeService('Wechat')->sendRechargeSuccess($order['uid'], $order);
  327. //模板消息小程序订阅消息
  328. $this->getNoticeService('Routine')->sendRechargeSuccess($order['uid'], $order, $order['now_money']);
  329. return true;
  330. }
  331. /**
  332. * 充值退款给用户发消息
  333. * @param $data
  334. * @return bool
  335. * @author: 吴汐
  336. * @email: 442384644@qq.com
  337. * @date: 2023/8/29
  338. */
  339. protected function handleRechargeOrderRefundStatus($data)
  340. {
  341. $datas = $data['data'];
  342. $UserRecharge = $data['UserRecharge'];
  343. $now_money = $data['now_money'];
  344. //站内信
  345. $this->getNoticeService('SysMsg')->sendMsg($UserRecharge['uid'], ['refund_price' => $datas['refund_price'], 'order_id' => $UserRecharge['order_id'], 'price' => $UserRecharge['price']]);
  346. //模板消息公众号模版消息
  347. $this->getNoticeService('Wechat')->sendOrderRefund($UserRecharge['uid'], ['refund_no' => $UserRecharge['order_id'], 'refund_price' => $UserRecharge['price']], '充值退款');
  348. //模板消息小程序订阅消息
  349. $this->getNoticeService('Routine')->sendRechargeSuccess($UserRecharge['uid'], $UserRecharge, $now_money);
  350. return true;
  351. }
  352. /**
  353. * 积分到账给用户发信息
  354. * @param $data
  355. * @return bool
  356. * @author: 吴汐
  357. * @email: 442384644@qq.com
  358. * @date: 2023/8/29
  359. */
  360. protected function handleIntegralAccout($data)
  361. {
  362. $order = $data['order'];
  363. //站内信
  364. $this->getNoticeService('SysMsg')->sendMsg($order['uid'], ['order_id' => $order['order_id'], 'store_name' => $data['storeTitle'], 'pay_price' => $order['pay_price'], 'gain_integral' => $data['give_integral'], 'integral' => $data['integral']]);
  365. //模板消息小程序订阅消息
  366. $this->getNoticeService('Routine')->sendUserIntegral($order['uid'], $data['order'], $data['storeTitle'], $data['give_integral'], $data['integral']);
  367. return true;
  368. }
  369. /**
  370. * 佣金到账给用户发消息
  371. * @param $data
  372. * @return bool
  373. * @author: 吴汐
  374. * @email: 442384644@qq.com
  375. * @date: 2023/8/29
  376. */
  377. protected function handleOrderBrokerage($data)
  378. {
  379. $brokeragePrice = $data['brokeragePrice'];
  380. $goodsName = $data['goodsName'];
  381. $goodsPrice = $data['goodsPrice'];
  382. $spread_uid = $data['spread_uid'];
  383. //站内信
  384. $this->getNoticeService('SysMsg')->sendMsg($spread_uid, ['goods_name' => $goodsName, 'goods_price' => $goodsPrice, 'brokerage_price' => $brokeragePrice]);
  385. return true;
  386. }
  387. /**
  388. * 砍价成功给用户发消息
  389. * @param $data
  390. * @return bool
  391. * @author: 吴汐
  392. * @email: 442384644@qq.com
  393. * @date: 2023/8/29
  394. */
  395. protected function handleBargainSuccess($data)
  396. {
  397. $uid = $data['uid'];
  398. $bargainInfo = $data['bargainInfo'];
  399. $bargainUserInfo = $data['bargainUserInfo'];
  400. $bargainInfo['title'] = Str::substrUTf8($bargainInfo['title'], 20, 'UTF-8', '');
  401. //站内信
  402. $this->getNoticeService('SysMsg')->sendMsg($uid, ['title' => $bargainInfo['title'], 'min_price' => $bargainInfo['min_price']]);
  403. //模板消息小程序订阅消息
  404. $this->getNoticeService('Routine')->sendBargainSuccess($uid, $bargainInfo, $bargainUserInfo, $uid);
  405. return true;
  406. }
  407. /**
  408. * 开团成功,参团成功给用户发消息
  409. * @param $data
  410. * @return bool
  411. * @author: 吴汐
  412. * @email: 442384644@qq.com
  413. * @date: 2023/8/29
  414. */
  415. protected function handlePinkSuccess($data)
  416. {
  417. $orderInfo = $data['orderInfo'];
  418. $title = $data['title'];
  419. $pink = $data['pink'];
  420. $nickname = app()->make(UserServices::class)->value(['uid' => $orderInfo['uid']], 'nickname');
  421. //站内信
  422. $this->getNoticeService('SysMsg')->sendMsg($orderInfo['uid'], ['title' => $title, 'nickname' => $nickname, 'count' => $pink['people'], 'pink_time' => date('Y-m-d H:i:s', $pink['add_time'])]);
  423. return true;
  424. }
  425. /**
  426. * 拼团成功给用户发消息
  427. * @param $data
  428. * @return bool
  429. * @author: 吴汐
  430. * @email: 442384644@qq.com
  431. * @date: 2023/8/29
  432. */
  433. protected function handleGroupsSuccess($data)
  434. {
  435. $list = $data['list'];
  436. $title = $data['title'];
  437. $url = '/pages/users/order_details/index?order_id=' . $list['order_id'];
  438. $title = Str::substrUTf8($title, 20, 'UTF-8', '');
  439. //站内信
  440. $this->getNoticeService('SysMsg')->sendMsg($list['uid'], ['title' => $title, 'nickname' => $list['nickname'], 'count' => $list['people'], 'pink_time' => date('Y-m-d H:i:s', $list['add_time'])]);
  441. //模板消息小程序订阅消息
  442. $this->getNoticeService('Routine')->sendPinkSuccess($list['uid'], $title, $list['nickname'], $list['add_time'], $list['people'], $url);
  443. return true;
  444. }
  445. /**
  446. * 拼团失败,拼团取消给用户发消息
  447. * @param $data
  448. * @return bool
  449. * @author: 吴汐
  450. * @email: 442384644@qq.com
  451. * @date: 2023/8/29
  452. */
  453. protected function handlePinkFail($data)
  454. {
  455. $uid = $data['uid'];
  456. $pink = $data['pink'];
  457. //站内信
  458. $this->getNoticeService('SysMsg')->sendMsg($uid, ['title' => $pink->title, 'count' => $pink->people]);
  459. return true;
  460. }
  461. /**
  462. * 提现成功给用户发消息
  463. * @param $data
  464. * @return bool
  465. * @author: 吴汐
  466. * @email: 442384644@qq.com
  467. * @date: 2023/8/29
  468. */
  469. protected function handleUserExtract($data)
  470. {
  471. $extractNumber = $data['extractNumber'];
  472. $nickname = $data['nickname'];
  473. $uid = $data['uid'];
  474. //站内信
  475. $this->getNoticeService('SysMsg')->sendMsg($uid, ['extract_number' => $extractNumber, 'nickname' => $nickname, 'date' => date('Y-m-d H:i:s', time())]);
  476. //模板消息公众号模版消息
  477. $this->getNoticeService('Wechat')->sendUserExtract($uid, $extractNumber);
  478. //模板消息小程序订阅消息
  479. $this->getNoticeService('Routine')->sendExtractSuccess($uid, $extractNumber, $nickname);
  480. return true;
  481. }
  482. /**
  483. * 提现失败给用户发消息
  484. * @param $data
  485. * @return bool
  486. * @author: 吴汐
  487. * @email: 442384644@qq.com
  488. * @date: 2023/8/29
  489. */
  490. protected function handleUserBalanceChange($data)
  491. {
  492. $extract_number = $data['extract_number'];
  493. $message = $data['message'];
  494. $uid = $data['uid'];
  495. $nickname = $data['nickname'];
  496. //站内信
  497. $this->getNoticeService('SysMsg')->sendMsg($uid, ['extract_number' => $extract_number, 'nickname' => $nickname, 'date' => date('Y-m-d H:i:s', time()), 'message' => $message]);
  498. //模板消息小程序订阅消息
  499. $this->getNoticeService('Routine')->sendExtractFail($uid, $message, $extract_number, $nickname);
  500. return true;
  501. }
  502. /**
  503. * 提醒付款给用户发消息
  504. * @param $data
  505. * @return bool
  506. * @throws \think\db\exception\DataNotFoundException
  507. * @throws \think\db\exception\DbException
  508. * @throws \think\db\exception\ModelNotFoundException
  509. * @author: 吴汐
  510. * @email: 442384644@qq.com
  511. * @date: 2023/8/29
  512. */
  513. protected function handleOrderPayFalse($data)
  514. {
  515. $order = $data['order'];
  516. $order_id = $order['order_id'];
  517. $order['storeName'] = app()->make(StoreOrderCartInfoServices::class)->getCarIdByProductTitle((int)$order['id']);
  518. //站内信
  519. $this->getNoticeService('SysMsg')->sendMsg($order['uid'], ['order_id' => $order_id]);
  520. //短信
  521. $this->getNoticeService('Sms')->sendSms($order['user_phone'], compact('order_id'));
  522. return true;
  523. }
  524. /**
  525. * 新订单给客服发消息
  526. * @param $data
  527. * @return bool
  528. * @throws \think\db\exception\DataNotFoundException
  529. * @throws \think\db\exception\DbException
  530. * @throws \think\db\exception\ModelNotFoundException
  531. * @author: 吴汐
  532. * @email: 442384644@qq.com
  533. * @date: 2023/8/29
  534. */
  535. protected function handleAdminPaySuccessCode($data)
  536. {
  537. $order = $data;
  538. $storeName = app()->make(StoreOrderCartInfoServices::class)->getCarIdByProductTitle((int)$order['id']);
  539. $title = '亲,来新订单啦!';
  540. $status = '新订单';
  541. $link = '/pages/admin/orderDetail/index?id=' . $order['order_id'];
  542. //站内信
  543. $this->getNoticeService('SysMsg')->kefuSystemSend(['order_id' => $order['order_id']]);
  544. //短信
  545. $this->getNoticeService('Sms')->sendAdminPaySuccess($order);
  546. //模版消息
  547. $this->getNoticeService('Wechat')->sendAdminOrder($order['order_id'], $storeName, $title, $status, $link);
  548. //企业微信通知
  549. $this->getNoticeService('WeWork')->weComSend(['order_id' => $order['order_id']]);
  550. return true;
  551. }
  552. /**
  553. * 确认收货给客服发消息
  554. * @param $data
  555. * @return bool
  556. * @throws \think\db\exception\DataNotFoundException
  557. * @throws \think\db\exception\DbException
  558. * @throws \think\db\exception\ModelNotFoundException
  559. * @author: 吴汐
  560. * @email: 442384644@qq.com
  561. * @date: 2023/8/29
  562. */
  563. protected function handleSendAdminConfirmTakeOver($data)
  564. {
  565. $order = $data['order'];
  566. $storeTitle = $data['storeTitle'];
  567. $storeName = app()->make(StoreOrderCartInfoServices::class)->getCarIdByProductTitle((int)$order['id']);
  568. $title = '亲,用户已经收到货物啦!';
  569. $status = '订单收货';
  570. $link = '/pages/admin/orderDetail/index?id=' . $order['order_id'];
  571. //站内信
  572. $this->getNoticeService('SysMsg')->kefuSystemSend(['storeTitle' => $storeTitle, 'order_id' => $order['order_id']]);
  573. //短信
  574. $this->getNoticeService('Sms')->sendAdminConfirmTakeOver($order);
  575. //公众号
  576. $this->getNoticeService('Wechat')->sendAdminOrder($order['order_id'], $storeName, $title, $status, $link);
  577. //企业微信通知
  578. $this->getNoticeService('WeWork')->weComSend(['storeTitle' => $storeTitle, 'order_id' => $order['order_id']]);
  579. return true;
  580. }
  581. /**
  582. * 申请退款给客服发消息
  583. * @param $data
  584. * @return bool
  585. * @throws \think\db\exception\DataNotFoundException
  586. * @throws \think\db\exception\DbException
  587. * @throws \think\db\exception\ModelNotFoundException
  588. * @author: 吴汐
  589. * @email: 442384644@qq.com
  590. * @date: 2023/8/29
  591. */
  592. protected function handleSendOrderApplyRefund($data)
  593. {
  594. $order = $data['order'];
  595. $storeName = app()->make(StoreOrderCartInfoServices::class)->getCarIdByProductTitle((int)$order['id']);
  596. $title = '亲,您有个退款订单待处理!';
  597. $status = '订单退款';
  598. $link = '/pages/admin/orderDetail/index?id=' . $order['refund_no'] . '&types=-3';
  599. //站内信
  600. $this->getNoticeService('SysMsg')->kefuSystemSend(['order_id' => $order['order_id']]);
  601. //短信
  602. $this->getNoticeService('Sms')->sendAdminRefund($order);
  603. //公众号
  604. $this->getNoticeService('Wechat')->sendAdminOrder($order['refund_no'], $storeName, $title, $status, $link);
  605. //企业微信通知
  606. $this->getNoticeService('WeWork')->weComSend(['order_id' => $order['order_id']]);
  607. return true;
  608. }
  609. /**
  610. * 提现申请给客服发消息
  611. * @param $data
  612. * @return bool
  613. * @author: 吴汐
  614. * @email: 442384644@qq.com
  615. * @date: 2023/8/29
  616. */
  617. protected function handleKefuSendExtractApplication($data)
  618. {
  619. //站内信
  620. $this->getNoticeService('SysMsg')->kefuSystemSend($data);
  621. //企业微信通知
  622. $this->getNoticeService('WeWork')->weComSend($data);
  623. return true;
  624. }
  625. }