OrderSubscribe.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. namespace crmeb\subscribes;
  3. use app\models\user\UserNotice;
  4. use think\Event;
  5. use app\admin\model\order\StoreOrder as AdminStoreOrder;
  6. use app\models\store\StoreOrder;
  7. use app\models\user\User;
  8. use crmeb\repositories\NoticeRepositories;
  9. use crmeb\services\workerman\ChannelService;
  10. use think\facade\Config;
  11. /**
  12. * 订单事件
  13. * Class OrderSubscribe
  14. * @package crmeb\subscribes
  15. */
  16. class OrderSubscribe
  17. {
  18. public function handle()
  19. {
  20. }
  21. /**
  22. * 送货发送模板消息
  23. * @param $event
  24. * @throws \think\db\exception\DataNotFoundException
  25. * @throws \think\db\exception\ModelNotFoundException
  26. * @throws \think\exception\DbException
  27. */
  28. public function onStoreProductOrderDeliveryAfter($event)
  29. {
  30. list($data, $oid) = $event;
  31. AdminStoreOrder::orderPostageAfter($oid, $data);
  32. }
  33. /**
  34. * 发货发送模板消息
  35. * @param $event
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. * @throws \think\exception\DbException
  39. */
  40. public function onStoreProductOrderDeliveryGoodsAfter($event)
  41. {
  42. list($data, $oid) = $event;
  43. AdminStoreOrder::orderPostageAfter($oid, $data);
  44. }
  45. /**
  46. * 订单状态不退款 发送模板消息
  47. * @param $event
  48. */
  49. public function onStoreProductOrderRefundNAfter($event)
  50. {
  51. list($data, $order) = $event;
  52. AdminStoreOrder::refundNoPrieTemplate($order['id'], $data);
  53. // TODO: 发送消息
  54. $icon = Config::get('app.header_cs_1', '');
  55. UserNotice::sendNoticeTo(
  56. $order['uid'],
  57. '您的退款申请已处理',
  58. '您申请退款的订单号: ' . $order['order_id']
  59. . ' 未成功退款;原因:' . $data . '。如有问题,请联系客服。',
  60. $icon
  61. );
  62. }
  63. /**
  64. * 线下付款成功后
  65. * @param $event
  66. */
  67. public function onStoreProductOrderOffline($event)
  68. {
  69. list($id) = $event;
  70. //订单编号 $id
  71. }
  72. /**
  73. * 修改订单金额
  74. * @param $event
  75. */
  76. public function onStoreProductOrderEditAfter($event)
  77. {
  78. list($data, $id) = $event;
  79. //$data total_price 商品总价 pay_price 实际支付
  80. //订单编号 $id
  81. }
  82. /**
  83. * 修改配送信息
  84. * @param $event
  85. */
  86. public function onStoreProductOrderDistributionAfter($event)
  87. {
  88. list($data, $id) = $event;
  89. //$data 送货人姓名/快递公司 送货人电话/快递单号
  90. //订单编号 $id
  91. }
  92. /**
  93. * 订单全部产品评价完
  94. * @param $event
  95. */
  96. public function onStoreProductOrderOver($event)
  97. {
  98. list($oid) = $event;
  99. }
  100. /**
  101. * 回退所有 未支付和已退款的状态下才可以退积分退库存退优惠券
  102. * @param $event
  103. */
  104. public function onStoreOrderRegressionAllAfter($event)
  105. {
  106. list($order) = $event;
  107. StoreOrder::RegressionStock($order) && StoreOrder::RegressionIntegral($order) && StoreOrder::RegressionCoupon($order);
  108. }
  109. /**
  110. * 订单支付成功 OrderPaySuccess
  111. * @param array $event
  112. */
  113. public function onOrderPaySuccess($event)
  114. {
  115. list($order, $formId) = $event;
  116. //更新用户支付订单数量
  117. $userInfo = User::get($order['uid']);
  118. if ($userInfo) {
  119. if (intval($userInfo->pay_count) <= 0) {
  120. event('UserFirstOrder', ['order' => $order]);
  121. }
  122. $userInfo->pay_count = $userInfo->pay_count + 1;
  123. $becomingPromoter = false; // flag
  124. if (!$userInfo->is_promoter) {
  125. $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'uid' => $userInfo->uid])->sum('pay_price');
  126. $status = is_brokerage_statu($price);
  127. if ($status) {
  128. $becomingPromoter = true;
  129. $userInfo->is_promoter = 1;
  130. }
  131. }
  132. $userInfo->save();
  133. if ($becomingPromoter) {
  134. event('UserBecomedPromoter', [$userInfo->toArray()]);
  135. }
  136. }
  137. //发送模版消息、客服消息、短信、小票打印给客户和管理员
  138. NoticeRepositories::noticeOrderPaySuccess($order);
  139. //检测会员等级
  140. event('UserLevelAfter', [$order['uid']]);
  141. try {
  142. //向后台发送新订单消息
  143. ChannelService::instance()->send('NEW_ORDER', ['order_id' => $order['order_id']]);
  144. } catch (\Throwable $e) {
  145. }
  146. }
  147. }