OrderSubscribe.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. //订单编号 $id
  69. }
  70. /**
  71. * 修改订单金额
  72. * @param $event
  73. */
  74. public function onStoreProductOrderEditAfter($event)
  75. {
  76. list($data, $id) = $event;
  77. //$data total_price 商品总价 pay_price 实际支付
  78. //订单编号 $id
  79. }
  80. /**
  81. * 修改配送信息
  82. * @param $event
  83. */
  84. public function onStoreProductOrderDistributionAfter($event)
  85. {
  86. list($data, $id) = $event;
  87. //$data 送货人姓名/快递公司 送货人电话/快递单号
  88. //订单编号 $id
  89. }
  90. /**
  91. * 订单全部产品评价完
  92. * @param $event
  93. */
  94. public function onStoreProductOrderOver($event)
  95. {
  96. list($oid) = $event;
  97. }
  98. /**
  99. * 回退所有 未支付和已退款的状态下才可以退积分退库存退优惠券
  100. * @param $event
  101. */
  102. public function onStoreOrderRegressionAllAfter($event)
  103. {
  104. list($order) = $event;
  105. StoreOrder::RegressionStock($order) && StoreOrder::RegressionIntegral($order) && StoreOrder::RegressionCoupon($order);
  106. }
  107. /**
  108. * 订单支付成功
  109. * @param array $event
  110. */
  111. public function onOrderPaySuccess($event)
  112. {
  113. list($order, $formId) = $event;
  114. //更新用户支付订单数量
  115. $userInfo = User::get($order['uid']);
  116. if ($userInfo) {
  117. $userInfo->pay_count = $userInfo->pay_count + 1;
  118. if (!$userInfo->is_promoter) {
  119. $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'uid' => $userInfo['uid']])->sum('pay_price');
  120. $status = is_brokerage_statu($price);
  121. if ($status) {
  122. $userInfo->is_promoter = 1;
  123. }
  124. }
  125. $userInfo->save();
  126. }
  127. //发送模版消息、客服消息、短信、小票打印给客户和管理员
  128. NoticeRepositories::noticeOrderPaySuccess($order);
  129. //检测会员等级
  130. event('UserLevelAfter', [$order['uid']]);
  131. try {
  132. //向后台发送新订单消息
  133. ChannelService::instance()->send('NEW_ORDER', ['order_id' => $order['order_id']]);
  134. } catch (\Throwable $e) {
  135. }
  136. }
  137. }