添加:商品购买赠送优惠券添加每月支付时间赠送
This commit is contained in:
parent
0ed0b0928a
commit
75d798dd24
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: CGOD
|
||||
* Date: 2019/12/18
|
||||
* Time: 16:00
|
||||
*/
|
||||
|
||||
namespace app\common\cron;
|
||||
|
||||
use app\frontend\modules\coupon\services\CronSendService;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use app\common\models\Order;
|
||||
use app\common\facades\Setting;
|
||||
use app\common\models\UniAccount;
|
||||
use app\common\models\coupon\OrderGoodsCoupon;
|
||||
|
||||
// 商品购买每月支付时间发放优惠券
|
||||
class MonthPayTimeCouponSend{
|
||||
use DispatchesJobs;
|
||||
|
||||
public function handle(){
|
||||
set_time_limit(0);
|
||||
$uniAccount = UniAccount::get() ?: [];
|
||||
foreach ($uniAccount as $u) {
|
||||
Setting::$uniqueAccountId = \YunShop::app()->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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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();
|
||||
});
|
||||
|
||||
/**
|
||||
* 购买商品订单完成发放优惠券
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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)));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -81,11 +81,6 @@ class IndexController extends BaseController{
|
|||
|
||||
return $this->successJson('success');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Common: 基本设置
|
||||
* Author: wu-hui
|
||||
|
|
|
|||
|
|
@ -13,9 +13,10 @@ define({
|
|||
<div class="form-item_tips">订单完成赠送优惠券</div>
|
||||
<template v-if="form.is_give">
|
||||
<el-radio v-model="form.send_type" :label="0">每月1号0:00发放</el-radio>
|
||||
<el-radio v-model="form.send_type" :label="3">每月支付时间发放</el-radio>
|
||||
<el-radio v-model="form.send_type" :label="1">订单完成后的1分钟后发放</el-radio>
|
||||
<el-radio v-model="form.send_type" :label="2">订单付款后的1分钟后发放</el-radio>
|
||||
<el-form-item v-if="form.send_type == 0" prop="month">
|
||||
<el-form-item v-if="form.send_type == 0 || form.send_type == 3" prop="month">
|
||||
<el-input style="width:300px;" v-model.trim="form.send_num" type="number" @keyup.native="prevent($event)">
|
||||
<template slot="prepend">连续发放</template>
|
||||
<template slot="append">月</template>
|
||||
|
|
|
|||
Loading…
Reference in New Issue