OrderSubscribe.php 4.3 KB

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