添加:商品失效
This commit is contained in:
parent
7b3570a8a6
commit
3b36561999
|
|
@ -623,7 +623,8 @@ class Privilege extends BaseModel
|
||||||
$set = Setting::get('plugin.rebate');
|
$set = Setting::get('plugin.rebate');
|
||||||
$repurchase_day = $set['repurchase_day'] ?? 0;
|
$repurchase_day = $set['repurchase_day'] ?? 0;
|
||||||
$limitTime = strtotime(date("Y-m-d H:i:s",$maxTime)." +{$repurchase_day} day");
|
$limitTime = strtotime(date("Y-m-d H:i:s",$maxTime)." +{$repurchase_day} day");
|
||||||
if($limitTime >= time()) throw new AppException('已超过复购时间');
|
// 判断:最后复购时间 小于等于 当前时间,超出复购时间,禁止复购
|
||||||
|
if($limitTime <= time()) throw new AppException('已超过复购时间');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -111,12 +111,16 @@ class PluginApplication extends \app\common\services\PluginApplication{
|
||||||
|
|
||||||
public function cronConfig(){
|
public function cronConfig(){
|
||||||
\Event::listen('cron.collectJobs', function () {
|
\Event::listen('cron.collectJobs', function () {
|
||||||
// 每天5分钟 执行一次消费返利解冻判断
|
// 每5分钟 执行一次消费返利解冻判断
|
||||||
\Cron::add('rebate-settlement', '*/5 * * * *', function () {
|
\Cron::add('rebate-settlement', '*/5 * * * *', function () {
|
||||||
Rebate::rebateThaw();
|
Rebate::rebateThaw();
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
|
// 每5分钟 执行一次消费返利失效判断
|
||||||
|
\Cron::add('rebate-settlement', '*/5 * * * *', function () {
|
||||||
|
Rebate::loseEfficacy();
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Yunshop\Rebate\models;
|
namespace Yunshop\Rebate\models;
|
||||||
|
|
||||||
|
use app\common\exceptions\AppException;
|
||||||
use app\common\facades\Setting;
|
use app\common\facades\Setting;
|
||||||
use app\common\models\BaseModel;
|
use app\common\models\BaseModel;
|
||||||
use app\common\models\Goods;
|
use app\common\models\Goods;
|
||||||
|
|
@ -8,6 +9,7 @@ use app\common\models\Member;
|
||||||
use app\common\models\Order;
|
use app\common\models\Order;
|
||||||
use app\common\models\OrderGoods;
|
use app\common\models\OrderGoods;
|
||||||
use app\common\services\income\IncomeService;
|
use app\common\services\income\IncomeService;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class Rebate extends BaseModel{
|
class Rebate extends BaseModel{
|
||||||
|
|
||||||
|
|
@ -176,14 +178,14 @@ class Rebate extends BaseModel{
|
||||||
public static function rebateSettlement(){
|
public static function rebateSettlement(){
|
||||||
\Log::debug('--- 消费返利 - 结算到佣金 - 开始 ----');
|
\Log::debug('--- 消费返利 - 结算到佣金 - 开始 ----');
|
||||||
// 获取可以结算但是未结算的数据
|
// 获取可以结算但是未结算的数据
|
||||||
$list = self::select(['id','uid','money'])
|
$list = self::select(['id','uid','money','uniacid'])
|
||||||
->where('status', 1)
|
->where('status', 1)
|
||||||
->get()
|
->get()
|
||||||
->toArray();
|
->toArray();
|
||||||
$incomeData = [];
|
$incomeData = [];
|
||||||
foreach($list as $item){
|
foreach($list as $item){
|
||||||
$incomeData[] = [
|
$incomeData[] = [
|
||||||
'uniacid' => \YunShop::app()->uniacid,
|
'uniacid' => $item['uniacid'],
|
||||||
'member_id' => $item['uid'],
|
'member_id' => $item['uid'],
|
||||||
'amount' => $item['money'],
|
'amount' => $item['money'],
|
||||||
'detail' => '',
|
'detail' => '',
|
||||||
|
|
@ -202,7 +204,64 @@ class Rebate extends BaseModel{
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Common: 失效
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/03/16 10:59
|
||||||
|
*/
|
||||||
|
public static function loseEfficacy(){
|
||||||
|
// 分组 获取最新一条已处理数据 状态:0=冻结中,1=待结算,2=已结算,3=已失效,4=已退款(失效)
|
||||||
|
$list = self::selectRaw('max(id) as id,max(reality_thaw_time) as max_reality_thaw_time,max(status) as status,uid,goods_id,order_id,CONCAT(uid,"_",goods_id) as group_key')
|
||||||
|
->whereIn('status',[2,3,4])
|
||||||
|
->groupBy('group_key')
|
||||||
|
->get()
|
||||||
|
->toArray();
|
||||||
|
$ids = array_column($list, 'id');
|
||||||
|
// 获取复购订单 状态为已结算 不存在信息的都是未复购,立即失效
|
||||||
|
$settlement = self::select([
|
||||||
|
'yz_rebate.id',
|
||||||
|
'yz_order_goods.uid',
|
||||||
|
'yz_order_goods.order_id',
|
||||||
|
'yz_order_goods.goods_id',
|
||||||
|
'yz_order.pay_time',
|
||||||
|
'yz_rebate.reality_thaw_time',
|
||||||
|
DB::raw('ims_yz_order_goods.id as order_goods_id'),
|
||||||
|
DB::raw('CONCAT(ims_yz_order_goods.uid,"_",ims_yz_order_goods.goods_id) as group_key')
|
||||||
|
])
|
||||||
|
->rightJoin('yz_order_goods',function($join){
|
||||||
|
$join->on('yz_order_goods.goods_id','=','yz_rebate.goods_id')
|
||||||
|
->on('yz_order_goods.uid','=','yz_rebate.uid');
|
||||||
|
})
|
||||||
|
->rightJoin('yz_order',function($join){
|
||||||
|
$join->on('yz_order.id','=','yz_order_goods.order_id')
|
||||||
|
->on('yz_order.pay_time','>','yz_rebate.reality_thaw_time');
|
||||||
|
})
|
||||||
|
->whereIn('yz_rebate.id',$ids)
|
||||||
|
->where('yz_rebate.status',2)
|
||||||
|
->where('yz_rebate.is_repurchase',1)
|
||||||
|
->get()
|
||||||
|
->toArray();
|
||||||
|
// 获取两个数组差异
|
||||||
|
$set = Setting::get('plugin.rebate');
|
||||||
|
$repurchase_day = $set['repurchase_day'] ?? 0;
|
||||||
|
$groupKey = array_column($settlement,'group_key');
|
||||||
|
// 循环判断 处理失效内容
|
||||||
|
foreach($list as $item){
|
||||||
|
// 判断: 不存在复购信息;并且最后一条结算时间+N天 小于等于当前时间;最后一条信息状态为已结算 = 信息失效
|
||||||
|
$endTime = strtotime(date("Y-m-d H:i:s",$item['max_reality_thaw_time'])." +{$repurchase_day} day");
|
||||||
|
if(!in_array($item['group_key'], $groupKey) && $endTime <= time() && $item['status'] == 2){
|
||||||
|
self::where([
|
||||||
|
'status' => 0,
|
||||||
|
'uid' => $item['uid'],
|
||||||
|
'goods_id' => $item['goods_id'],
|
||||||
|
'order_id' => $item['order_id'],
|
||||||
|
])->update([
|
||||||
|
'status' => 3,
|
||||||
|
'reality_thaw_time' => time()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue