diff --git a/app/common/cron/MonthPayTimeCouponSend.php b/app/common/cron/MonthPayTimeCouponSend.php new file mode 100644 index 00000000..87c5f905 --- /dev/null +++ b/app/common/cron/MonthPayTimeCouponSend.php @@ -0,0 +1,53 @@ +uniacid = $u->uniacid; + $this->orderCouponSend(); + } + } + + public function orderCouponSend(){ + // \Log::debug(' 发放优惠券 - 每月订单支付时间后发放 - 开始处理'); + $records = OrderGoodsCoupon::uniacid() + ->where(function ($query){ + $query->where('next_time','<=', time())->orWhere('next_time','=',null); + }) + ->where(['send_type'=>OrderGoodsCoupon::MONTH_PAY_TIME,'status'=>OrderGoodsCoupon::WAIT_STATUS]) + ->whereHas('hasOneOrderGoods',function ($query){ + $query->whereHas('hasOneOrder',function ($q){ + $q->where('status',Order::COMPLETE); + }) ; + }) + ->get(); + + + if($records->isEmpty()) return; + foreach ($records as $record){ + $numReason = $record->num_reason?$record->num_reason.'||':''; + (new CronSendService($record,$numReason,2))->sendCoupon(); + } + } + +} \ No newline at end of file diff --git a/app/common/cron/config/CronConfig.php b/app/common/cron/config/CronConfig.php index aee7b26d..519c744c 100644 --- a/app/common/cron/config/CronConfig.php +++ b/app/common/cron/config/CronConfig.php @@ -18,6 +18,7 @@ use app\common\cron\MemberLevelValidity; use app\common\cron\MemberLower; use app\common\cron\MonthCouponSend; use app\common\cron\MonthParentRewardPoint; +use app\common\cron\MonthPayTimeCouponSend; use app\common\cron\OrderCouponSend; use app\common\cron\PayExceptionRefund; use app\common\cron\PhoneAttributions; @@ -267,6 +268,10 @@ class CronConfig \Cron::add('MonthCouponSend', '0 1 1 * *', function() { (new MonthCouponSend())->handle(); }); + // 购买商品 每月支付时间发放优惠券 + \Cron::add('MonthPayTimeCouponSend', '*/1 * * * *', function() { + (new MonthPayTimeCouponSend())->handle(); + }); /** * 购买商品订单完成发放优惠券 diff --git a/app/common/models/coupon/OrderGoodsCoupon.php b/app/common/models/coupon/OrderGoodsCoupon.php index b45c2100..385219a0 100644 --- a/app/common/models/coupon/OrderGoodsCoupon.php +++ b/app/common/models/coupon/OrderGoodsCoupon.php @@ -22,6 +22,7 @@ class OrderGoodsCoupon extends BaseModel const MONTH_TYPE = 0; const ORDER_TYPE = 1; const ORDER_PAID_TYPE = 2; + const MONTH_PAY_TIME = 3; const CLOSE_STATUS = -1; const WAIT_STATUS = 0; diff --git a/app/frontend/modules/coupon/services/CouponService.php b/app/frontend/modules/coupon/services/CouponService.php index 34b04c50..f54355d4 100644 --- a/app/frontend/modules/coupon/services/CouponService.php +++ b/app/frontend/modules/coupon/services/CouponService.php @@ -176,7 +176,7 @@ class CouponService continue; } //每月发送时,发送月数 为空 或为 0 - if ($goodsCoupon->send_type == '0' && empty($goodsCoupon->send_num)) { + if (($goodsCoupon->send_type == '0' || $goodsCoupon->send_type == '3') && empty($goodsCoupon->send_num)) { continue; } for ($i = 1; $i <= $goods->total; $i++) { @@ -207,7 +207,7 @@ class CouponService continue; } //每月发送时,发送月数 为空 或为 0 - if ($goodsCoupon->send_type == '0' && empty($goodsCoupon->send_num)) { + if (($goodsCoupon->send_type == '0' || $goodsCoupon->send_type == '3') && empty($goodsCoupon->send_num)) { continue; } //若添加项有多个一样的优惠劵这里做合并处理 @@ -272,8 +272,7 @@ class CouponService 'send_type' => $goodsCoupon->send_type, 'remark' => json_encode($goodsCoupon->coupon) ]; - if($goodsCoupon->send_type == 0) - { + if($goodsCoupon->send_type == 0 || $goodsCoupon->send_type == 3){ $monthArr = [ 'send_num' => $goodsCoupon->send_num, 'end_send_num' => 0, @@ -296,8 +295,10 @@ class CouponService 'send_num' => $goodsCoupon->send_num, 'end_send_num' => 0, 'status' => 0, - 'created_at' => time() + 'created_at' => time(), ]; + + $this->dispatch((new addGoodsCouponQueueJob($queueData))); } diff --git a/app/frontend/modules/coupon/services/CronSendService.php b/app/frontend/modules/coupon/services/CronSendService.php index 1beda5ba..a3c381dd 100644 --- a/app/frontend/modules/coupon/services/CronSendService.php +++ b/app/frontend/modules/coupon/services/CronSendService.php @@ -107,13 +107,13 @@ class CronSendService $model->save(); } - private function endMonthSend() - { + private function endMonthSend(){ $model = $this->record; $model->end_send_num += 1; $model->num_reason = $this->numReason; - if($model->end_send_num >= $model->send_num) - { + $model->next_time = getNextMonthDays(time(), 1); + + if($model->end_send_num >= $model->send_num){ $model->status = 1; } $model->save(); diff --git a/plugins/rebate/src/admin/IndexController.php b/plugins/rebate/src/admin/IndexController.php index ff28a548..87c9b205 100644 --- a/plugins/rebate/src/admin/IndexController.php +++ b/plugins/rebate/src/admin/IndexController.php @@ -81,11 +81,6 @@ class IndexController extends BaseController{ return $this->successJson('success'); } - - - - - /** * Common: 基本设置 * Author: wu-hui diff --git a/resources/views/goods/assets/js/components/marketing/coupon.js b/resources/views/goods/assets/js/components/marketing/coupon.js index 522b2615..95005602 100644 --- a/resources/views/goods/assets/js/components/marketing/coupon.js +++ b/resources/views/goods/assets/js/components/marketing/coupon.js @@ -13,9 +13,10 @@ define({
订单完成赠送优惠券