diff --git a/app/common/model/store/coupon/StoreCouponDetail.php b/app/common/model/store/coupon/StoreCouponDetail.php index 2d0c7503..4603e3c0 100644 --- a/app/common/model/store/coupon/StoreCouponDetail.php +++ b/app/common/model/store/coupon/StoreCouponDetail.php @@ -61,9 +61,10 @@ class StoreCouponDetail extends BaseModel * @param $order * @param $id * @param $amount + * @param $status * @return void */ - public static function income($order, $id, $amount) + public static function income($order, $id, $amount, $status = 1) { $detailModel = new self(); $detailModel->uid = $order['uid']; @@ -73,6 +74,7 @@ class StoreCouponDetail extends BaseModel $detailModel->type = StoreCouponDetail::TYPE_INCOME; $detailModel->amount = $amount; $detailModel->pay_price = $order['pay_price']; + $detailModel->status = $status; $detailModel->create_time = time(); $detailModel->save(); } diff --git a/app/common/repositories/store/coupon/StoreCouponUserRepository.php b/app/common/repositories/store/coupon/StoreCouponUserRepository.php index 85d2eb7c..7916bab2 100644 --- a/app/common/repositories/store/coupon/StoreCouponUserRepository.php +++ b/app/common/repositories/store/coupon/StoreCouponUserRepository.php @@ -36,6 +36,11 @@ class StoreCouponUserRepository extends BaseRepository const SEND_TYPE_SEND = 'send'; const SEND_TYPE_GIVE = 'give'; const SEND_TYPE_NEW = 'new'; + + const STATUS_REPEAL = -1; //作废的 + const STATUS_UNUSED = 0; //未使用的 + const STATUS_USED = 1; //已使用的 + const STATUS_EXPIRED = 2; //过期的 /** * @var StoreCouponUserDao */ diff --git a/app/event.php b/app/event.php index 9789e755..3c98fcc6 100644 --- a/app/event.php +++ b/app/event.php @@ -30,32 +30,33 @@ return [ 'swoole.workerError' => [\crmeb\listens\SwooleWorkerExitListen::class], 'swoole.workerStop' => [\crmeb\listens\SwooleWorkerExitListen::class], 'create_timer' => env('INSTALLED', false) ? [ - \crmeb\listens\AutoOrderProfitsharingListen::class, - \crmeb\listens\AuthTakeOrderListen::class, - \crmeb\listens\AutoCancelGroupOrderListen::class, - \crmeb\listens\AuthCancelPresellOrderListen::class, - \crmeb\listens\AutoUnLockBrokerageListen::class, - \crmeb\listens\AutoSendPayOrderSmsListen::class, - \crmeb\listens\SyncSmsResultCodeListen::class, - \crmeb\listens\SyncBroadcastStatusListen::class, //直播间同步监听,未开启可删除次行 - \crmeb\listens\RefundOrderAgreeListen::class, - \crmeb\listens\SeckillTImeCheckListen::class, - \crmeb\listens\AutoOrderReplyListen::class, - \crmeb\listens\ProductPresellStatusListen::class, - \crmeb\listens\ProductGroupStatusCheckListen::class, - \crmeb\listens\SyncSpreadStatusListen::class, - \crmeb\listens\GuaranteeCountListen::class, - \crmeb\listens\AutoUnLockIntegralListen::class, - \crmeb\listens\AutoClearIntegralListen::class, - \crmeb\listens\MerchantApplyMentsCheckListen::class, - \crmeb\listens\AutoUnlockMerchantMoneyListen::class, - \crmeb\listens\SumCountListen::class, - \crmeb\listens\SyncHotRankingListen::class, - \crmeb\listens\AuthCancelActivityListen::class, - \crmeb\listens\CloseUserSvipListen::class, - \crmeb\listens\SendSvipCouponListen::class, - \crmeb\listens\SyncMerchantMarginStatusListen::class, - \crmeb\listens\SyncQueueStatusListen::class, + \crmeb\listens\AutoOrderProfitsharingListen::class, + \crmeb\listens\AuthTakeOrderListen::class, + \crmeb\listens\AutoCancelGroupOrderListen::class, + \crmeb\listens\AuthCancelPresellOrderListen::class, + \crmeb\listens\AutoUnLockBrokerageListen::class, + \crmeb\listens\AutoSendPayOrderSmsListen::class, + \crmeb\listens\SyncSmsResultCodeListen::class, + \crmeb\listens\SyncBroadcastStatusListen::class, //直播间同步监听,未开启可删除次行 + \crmeb\listens\RefundOrderAgreeListen::class, + \crmeb\listens\SeckillTImeCheckListen::class, + \crmeb\listens\AutoOrderReplyListen::class, + \crmeb\listens\ProductPresellStatusListen::class, + \crmeb\listens\ProductGroupStatusCheckListen::class, + \crmeb\listens\SyncSpreadStatusListen::class, + \crmeb\listens\GuaranteeCountListen::class, + \crmeb\listens\AutoUnLockIntegralListen::class, + \crmeb\listens\AutoClearIntegralListen::class, + \crmeb\listens\MerchantApplyMentsCheckListen::class, + \crmeb\listens\AutoUnlockMerchantMoneyListen::class, + \crmeb\listens\SumCountListen::class, + \crmeb\listens\SyncHotRankingListen::class, + \crmeb\listens\AuthCancelActivityListen::class, + \crmeb\listens\CloseUserSvipListen::class, + \crmeb\listens\SendSvipCouponListen::class, + \crmeb\listens\SyncMerchantMarginStatusListen::class, + \crmeb\listens\SyncQueueStatusListen::class, + \crmeb\listens\ActivateCouponListen::class, ] : [], 'pay_success_user_recharge' => [\crmeb\listens\pay\UserRechargeSuccessListen::class], 'pay_success_user_order' => [\crmeb\listens\pay\UserOrderSuccessListen::class], @@ -63,7 +64,7 @@ return [ 'pay_success_presell' => [\crmeb\listens\pay\PresellPaySuccessListen::class], 'pay_success_meal' => [\crmeb\listens\pay\MealSuccessListen::class], //数据大屏 - 'data.screen.send' =>[\crmeb\listens\DataScreenListen::class], + 'data.screen.send' => [\crmeb\listens\DataScreenListen::class], //操作日志 'create_operate_log' => [\crmeb\listens\CreateOperateLogListen::class], // 操作日志事件 'mini_order_shipping' => [\crmeb\listens\MiniOrderShippingListen::class], // 小程序发货管理事件 diff --git a/crmeb/listens/ActivateCouponListen.php b/crmeb/listens/ActivateCouponListen.php new file mode 100644 index 00000000..763c9d73 --- /dev/null +++ b/crmeb/listens/ActivateCouponListen.php @@ -0,0 +1,62 @@ +tick(1000 * 60, function () { + Log::info('定时任务:激活商户补贴'); + try { + $couponId = StoreCoupon::where('type', StoreCouponRepository::TYPE_STORE_COUPON) + ->where('send_type', StoreCouponRepository::GET_COUPON_TYPE_PAY) + ->value('coupon_id'); + if (empty($couponId)) { + return; + } + $storeCouponUser = StoreCouponUser::where('coupon_id', $couponId) + ->where('coupon_type', StoreCouponRepository::TYPE_STORE_COUPON) + ->where('buy', StoreCouponUserRepository::SEND_TYPE_BUY) + ->where('status', StoreCouponUserRepository::STATUS_REPEAL) + ->select(); + foreach ($storeCouponUser as $item) { + $mainCouponId = StoreCouponDetail::where('order_id', $item['order_id']) + ->where('type', StoreCouponDetail::TYPE_INCOME) + ->value('coupon_user_id'); + $couponBalance = StoreCouponUser::where('coupon_user_id', $mainCouponId)->value('coupon_price'); + $merchantId = Merchant::where('uid', $item['uid'])->value('mer_id'); + $saleTotal = StoreOrder::where('mer_id', $merchantId) + ->whereIn('status', [StoreOrderDao::ORDER_STATUS_REPLY, StoreOrderDao::ORDER_STATUS_SUCCESS]) + ->sum('total_price'); + if ($saleTotal >= $item['origin_price'] && $couponBalance <= 0) { + $item->status = StoreCouponUserRepository::STATUS_UNUSED; + $item->start_time = date('Y-m-d H:i:s'); + $item->end_time = date('Y-m-d H:i:s', strtotime('+1 year')); + $item->save(); + StoreCouponDetail::where('coupon_user_id', $item['coupon_user_id'])->update(['status', 1]); + } + } + } catch (\Throwable $e) { + Log::info('定时任务:激活商户补贴,error => ' . $e->getMessage()); + } + }); + } + +} diff --git a/crmeb/listens/OrderDeliveryListen.php b/crmeb/listens/OrderDeliveryListen.php index 5782ccd5..5e8882b3 100644 --- a/crmeb/listens/OrderDeliveryListen.php +++ b/crmeb/listens/OrderDeliveryListen.php @@ -43,7 +43,7 @@ class OrderDeliveryListen implements ListenerInterface $repo->endTime = '2025-07-01'; $repo->status = -1; $couponUser = $repo->sendCoupon($giveCoupon, $order['uid'], StoreCouponUserRepository::SEND_TYPE_BUY); - StoreCouponDetail::income($order, $couponUser['coupon_user_id'], $giveCoupon->coupon_price); + StoreCouponDetail::income($order, $couponUser['coupon_user_id'], $giveCoupon->coupon_price, 0); } catch (\Exception $e) { Log::info('自动发放买赠优惠券:' . $e->getMessage()); }