OrderSubscribe.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/12/18
  6. */
  7. namespace crmeb\subscribes;
  8. use think\Event;
  9. use app\admin\model\order\StoreOrder as AdminStoreOrder;
  10. use app\models\store\StoreOrder;
  11. use app\models\user\User;
  12. use crmeb\repositories\NoticeRepositories;
  13. use crmeb\services\workerman\ChannelService;
  14. use app\models\store\StoreOrderCartInfo;
  15. use crmeb\services\SystemConfigService;
  16. use crmeb\services\YLYService;
  17. use think\facade\Log;
  18. /**
  19. * 订单事件
  20. * Class OrderSubscribe
  21. * @package crmeb\subscribes
  22. */
  23. class OrderSubscribe
  24. {
  25. public function handle()
  26. {
  27. }
  28. /**
  29. * 送货发送模板消息
  30. * @param $event
  31. * @throws \think\db\exception\DataNotFoundException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. * @throws \think\exception\DbException
  34. */
  35. public function onStoreProductOrderDeliveryAfter($event)
  36. {
  37. list($data, $oid) = $event;
  38. AdminStoreOrder::orderPostageAfter($oid, $data);
  39. }
  40. /**
  41. * 发货发送模板消息
  42. * @param $event
  43. * @throws \think\db\exception\DataNotFoundException
  44. * @throws \think\db\exception\ModelNotFoundException
  45. * @throws \think\exception\DbException
  46. */
  47. public function onStoreProductOrderDeliveryGoodsAfter($event)
  48. {
  49. list($data, $oid) = $event;
  50. AdminStoreOrder::orderPostageAfter($oid, $data);
  51. }
  52. /**
  53. * 订单状态不退款 发送模板消息
  54. * @param $event
  55. */
  56. public function onStoreProductOrderRefundNAfter($event)
  57. {
  58. list($data, $id) = $event;
  59. AdminStoreOrder::refundNoPrieTemplate($id, $data);
  60. }
  61. /**
  62. * 线下付款成功后
  63. * @param $event
  64. */
  65. public function onStoreProductOrderOffline($event)
  66. {
  67. list($id) = $event;
  68. $order = StoreOrder::find($id);
  69. StoreOrder::handle_order($order);
  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. * 订单支付成功
  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. $userInfo->pay_count = $userInfo->pay_count + 1;
  120. if (!$userInfo->is_promoter) {
  121. $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'uid' => $userInfo['uid']])->sum('pay_price');
  122. $status = is_brokerage_statu($price);
  123. if ($status) {
  124. $userInfo->is_promoter = 1;
  125. }
  126. }
  127. $userInfo->save();
  128. }
  129. StoreOrder::handle_order($order);
  130. //发送模版消息、客服消息、短信、小票打印给客户和管理员
  131. NoticeRepositories::noticeOrderPaySuccess($order);
  132. //检测会员等级
  133. event('UserLevelAfter', [$order['uid']]);
  134. try {
  135. //向后台发送新订单消息
  136. ChannelService::instance()->send('NEW_ORDER', ['order_id' => $order['order_id']]);
  137. } catch (\Throwable $e) {
  138. }
  139. }
  140. }