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