OrderSubscribe.php 4.7 KB

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