OrderSubscribe.php 4.3 KB

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