123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <?php
- /**
- *
- * @author: xaboy<365615158@qq.com>
- * @day: 2017/12/18
- */
- namespace crmeb\subscribes;
- use app\models\store\StoreOrder;
- use app\models\store\StoreOrderCartInfo;
- use app\models\user\User;
- use app\models\user\WechatUser;
- use crmeb\services\SystemConfigService;
- use crmeb\repositories\CustomerRepository;
- use crmeb\repositories\NoticeRepositories;
- use crmeb\services\WechatService;
- use crmeb\services\WechatTemplateService;
- use crmeb\services\workerman\ChannelService;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\DbException;
- use think\db\exception\ModelNotFoundException;
- use think\facade\Log;
- /**
- * 订单事件
- * Class OrderSubscribe
- * @package crmeb\subscribes
- */
- class OrderSubscribe
- {
- public function handle()
- {
- }
- /**
- * 送货发送模板消息
- * @param $event
- * @throws DataNotFoundException
- * @throws ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function onStoreProductOrderDeliveryAfter($event)
- {
- list($data, $oid) = $event;
- StoreOrder::orderPostageAfter($oid, $data);
- }
- /**
- * 发货发送模板消息
- * @param $event
- * @throws DataNotFoundException
- * @throws ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function onStoreProductOrderDeliveryGoodsAfter($event)
- {
- list($data, $oid) = $event;
- StoreOrder::orderPostageAfter($oid, $data);
- }
- /**
- * 订单状态不退款 发送模板消息
- * @param $event
- */
- public function onStoreProductOrderRefundNAfter($event)
- {
- list($data, $id) = $event;
- StoreOrder::refundNoPrieTemplate($id, $data);
- }
- /**
- * 线下付款成功后
- * @param $event
- */
- public function onStoreProductOrderOffline($event)
- {
- list($id) = $event;
- //订单编号 $id
- }
- /**
- * 修改订单金额
- * @param $event
- */
- public function onStoreProductOrderEditAfter($event)
- {
- list($data, $id) = $event;
- //$data total_price 商品总价 pay_price 实际支付
- //订单编号 $id
- }
- /**
- * 修改配送信息
- * @param $event
- */
- public function onStoreProductOrderDistributionAfter($event)
- {
- list($data, $id) = $event;
- //$data 送货人姓名/快递公司 送货人电话/快递单号
- //订单编号 $id
- }
- /**
- * 订单全部商品评价完
- * @param $event
- */
- public function onStoreProductOrderOver($event)
- {
- list($oid) = $event;
- }
- /**
- * 回退所有 未支付和已退款的状态下才可以退积分退库存退优惠券
- * @param $event
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- */
- public function onStoreOrderRegressionAllAfter($event)
- {
- list($order) = $event;
- StoreOrder::RegressionStock($order) && StoreOrder::RegressionIntegral($order) && StoreOrder::RegressionCoupon($order);
- }
- /**
- * 订单支付成功
- * @param array $event
- */
- public static function onOrderPaySuccess($event)
- {
- $order = $event;
- Log::info('订单支付成功下发队列消息成功订单号为:' . $order['order_id']);
- //更新用户支付订单数量
- $userInfo = User::get($order['uid']);
- if ($userInfo) {
- $userInfo->pay_count = $userInfo->pay_count + 1;
- if (!$userInfo->is_promoter) {
- $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'uid' => $userInfo['uid']])->sum('pay_price');
- $status = is_brokerage_statu($price);
- if ($status) {
- $userInfo->is_promoter = 1;
- }
- }
- $userInfo->save();
- }
- //发送模版消息、客服消息、短信、小票打印给客户和管理员
- NoticeRepositories::noticeOrderPaySuccess($order, $order['mer_id']);
- //检测会员等级
- $user = User::where('uid', $order['uid'])->find()->toArray();
- event('UserLevelAfter', [$user]);
- try {
- //向后台发送新订单消息
- ChannelService::instance()->send('NEW_ORDER', ['order_id' => $order['order_id']]);
- } catch (\Throwable $exception) {
- };
- }
- }
|