From 7b3570a8a6a7515039a426e63da5430e9ce284ab Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Fri, 15 Mar 2024 18:13:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E5=8F=82=E4=B8=8E?= =?UTF-8?q?=E6=B6=88=E8=B4=B9=E8=BF=94=E5=88=A9=E5=95=86=E5=93=81=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E9=97=B4=E6=AE=B5=E5=86=85=E5=8F=AA=E8=83=BD?= =?UTF-8?q?=E8=B4=AD=E4=B9=B0=E4=B8=80=E6=AC=A1=E8=AF=A5=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/models/goods/Privilege.php | 47 +++++++++++++++++++ plugins/rebate/src/models/Rebate.php | 10 ++-- plugins/rebate/views/index/set.blade.php | 7 +++ .../team-dividend/src/PluginApplication.php | 2 +- .../src/services/TimedTaskService.php | 10 ++-- 5 files changed, 67 insertions(+), 9 deletions(-) diff --git a/app/common/models/goods/Privilege.php b/app/common/models/goods/Privilege.php index 3ea13ec4..1ed57ae8 100644 --- a/app/common/models/goods/Privilege.php +++ b/app/common/models/goods/Privilege.php @@ -20,6 +20,8 @@ use app\common\models\Order; use Carbon\Carbon; use Illuminate\Support\Facades\DB; use app\common\facades\Setting; +use Yunshop\Rebate\models\GoodsRebate; +use Yunshop\Rebate\models\Rebate; /** * Class Privilege @@ -180,6 +182,8 @@ class Privilege extends BaseModel $this->validateMemberGroupLimit($member); $this->validateBuyMultipleLimit($num); $this->validateTimeLimits($member,$num); + + $this->validateRebate($member,$num); } /** @@ -203,6 +207,8 @@ class Privilege extends BaseModel $this->validateMemberGroupLimit($member); $this->validateBuyMultipleLimit($num); $this->validateTimeLimits($member,$num); + + $this->validateRebate($member,$num); } @@ -582,4 +588,45 @@ class Privilege extends BaseModel } } + + + // 消费返利商品判断 + public function validateRebate($member,$num){ + // 判断:是否开启消费返利 + $goodsRebate = GoodsRebate::where('goods_id',$this->goods_id)->first(); + if($goodsRebate->is_open == 1){ + // 判断:当前返利记录是否已经失效 最后一条返利信息已失效或者已结算 则允许重新购买 状态:0=冻结中,1=待结算,2=已结算,3=已失效,4=已退款(失效) + $endTime = Rebate::where('uid', $member->uid) + ->where('goods_id', $this->goods_id) + ->max('expect_thaw_time'); + if(empty($endTime)) return false; + $endInfo = Rebate::where('uid', $member->uid) + ->where('goods_id', $this->goods_id) + ->where('expect_thaw_time', $endTime) + ->first(); + if(!$endInfo || in_array($endInfo->status,[2,3,4])) return false; + // 获取已经返利的 最大时间 + $maxTime = Rebate::where('uid', $member->uid) + ->where('goods_id', $this->goods_id) + ->where('status', 2) + ->max('reality_thaw_time'); + if(empty($maxTime)) return false; + $lastInfo = Rebate::where('uid', $member->uid) + ->where('goods_id', $this->goods_id) + ->where('status', 2) + ->where('reality_thaw_time', $maxTime) + ->first(); + if(!$lastInfo) return false; + $lastInfo = $lastInfo->toArray(); + if($lastInfo['is_repurchase'] != 1) throw new AppException('未到复购时间'); + // 判断:需要复购 最后一次结算时间N天内 + $set = Setting::get('plugin.rebate'); + $repurchase_day = $set['repurchase_day'] ?? 0; + $limitTime = strtotime(date("Y-m-d H:i:s",$maxTime)." +{$repurchase_day} day"); + if($limitTime >= time()) throw new AppException('已超过复购时间'); + } + } + + + } \ No newline at end of file diff --git a/plugins/rebate/src/models/Rebate.php b/plugins/rebate/src/models/Rebate.php index 9501e90e..a19a7f89 100644 --- a/plugins/rebate/src/models/Rebate.php +++ b/plugins/rebate/src/models/Rebate.php @@ -159,10 +159,12 @@ class Rebate extends BaseModel{ public static function rebateThaw(){ $time = time(); // 预计解冻时间 低于当前时间 解冻 - self::where('expect_thaw_time','<=', $time)->update([ - 'status' => 1, - 'reality_thaw_time' => $time - ]); + self::where('expect_thaw_time','<=',$time) + ->where('status',0) + ->update([ + 'status' => 1, + 'reality_thaw_time' => $time + ]); // 执行 已解冻佣金结算到账 self::rebateSettlement(); } diff --git a/plugins/rebate/views/index/set.blade.php b/plugins/rebate/views/index/set.blade.php index 3a4c94d7..70dddd35 100644 --- a/plugins/rebate/views/index/set.blade.php +++ b/plugins/rebate/views/index/set.blade.php @@ -73,6 +73,12 @@