From ae79e2dedeafd68c2d1c2852214783ba934e3166 Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Mon, 18 Mar 2024 19:09:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=9C=80=E5=90=8E?= =?UTF-8?q?=E4=B8=80=E6=AC=A1=E7=BB=93=E7=AE=97=E6=97=B6=E9=97=B4=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E9=94=99=E8=AF=AF=20=E5=AF=BC=E8=87=B4=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=86=85=E5=AE=B9=E9=94=99=E8=AF=AF=EF=BC=8C=E6=9C=AA?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=A4=8D=E6=8A=95=E4=BF=A1=E6=81=AF=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E6=8E=A8=E8=8D=90=E5=A5=96=E5=8A=B1?= =?UTF-8?q?=20-=20=E7=AD=89=E7=BA=A7=E8=AE=B0=E5=BD=95=E4=B8=AD=E7=AD=89?= =?UTF-8?q?=E7=BA=A7=E5=88=97=E8=A1=A8=E6=8C=89=E7=85=A7=E6=9D=83=E9=87=8D?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F=E6=8E=92=E5=BA=8F=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=EF=BC=9A=E6=8E=A8=E8=8D=90=E5=A5=96=E5=8A=B1=20-=20=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E7=AD=89=E7=BA=A7=E4=BF=A1=E6=81=AF=E6=9C=AA=E8=BE=93?= =?UTF-8?q?=E5=87=BA=EF=BC=8C=E5=AF=BC=E8=87=B4=E7=A7=BB=E5=8A=A8=E7=AB=AF?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=94=99=E8=AF=AF=EF=BC=8C=E7=AD=89=E7=BA=A7?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E4=B8=AD=E7=9A=84=E7=AD=89=E7=BA=A7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=9C=AA=E6=94=B9=E5=8F=98=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=EF=BC=9A=E6=8E=A8=E8=8D=90=E5=A5=96=E5=8A=B1=20-=20=E5=A5=96?= =?UTF-8?q?=E5=8A=B1=E6=8C=89=E7=85=A7=E9=A2=84=E8=AE=A1=E7=BB=93=E7=AE=97?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/services/income/IncomeService.php | 2 +- plugins/rebate/src/PluginApplication.php | 2 +- plugins/rebate/src/admin/IndexController.php | 15 +++ plugins/rebate/src/api/IndexController.php | 21 +++- plugins/rebate/src/models/Rebate.php | 118 +++++++++++-------- plugins/rebate/views/index/index.blade.php | 17 +++ 6 files changed, 118 insertions(+), 57 deletions(-) diff --git a/app/common/services/income/IncomeService.php b/app/common/services/income/IncomeService.php index 13bbefc6..00a19abe 100644 --- a/app/common/services/income/IncomeService.php +++ b/app/common/services/income/IncomeService.php @@ -494,7 +494,7 @@ class IncomeService { $income_config_desc = [ self::COMMISSION_ORDER => \Setting::get('shop.lang.zh_cn.commission.commission_amount') ? : '直推奖励', - self::TEAM_DIVIDEND => '团队收益', + self::TEAM_DIVIDEND => '经销商佣金',//团队收益 self::AGENT_DIVIDEND => '代理商分红', self::APPOINTMENT_ORDER => '门店预约', self::AREA_DIVIDEND => '区域分红', diff --git a/plugins/rebate/src/PluginApplication.php b/plugins/rebate/src/PluginApplication.php index 53a89677..4aee08cb 100644 --- a/plugins/rebate/src/PluginApplication.php +++ b/plugins/rebate/src/PluginApplication.php @@ -121,7 +121,7 @@ class PluginApplication extends \app\common\services\PluginApplication{ return; }); // 每5分钟 执行一次消费返利失效判断 - \Cron::add('rebate-lose-efficacy', '*/5 * * * *', function () { + \Cron::add('rebate-lose-efficacy', '*/1 * * * *', function () { Rebate::loseEfficacy(); return; }); diff --git a/plugins/rebate/src/admin/IndexController.php b/plugins/rebate/src/admin/IndexController.php index 8d8f1261..ce9bf71c 100644 --- a/plugins/rebate/src/admin/IndexController.php +++ b/plugins/rebate/src/admin/IndexController.php @@ -54,5 +54,20 @@ class IndexController extends BaseController{ } + public function test(){ + + + // Rebate::loseEfficacy(); + + + debug("调试结束"); + + } + + + + + + } diff --git a/plugins/rebate/src/api/IndexController.php b/plugins/rebate/src/api/IndexController.php index 3ff28f7c..68c1aaac 100644 --- a/plugins/rebate/src/api/IndexController.php +++ b/plugins/rebate/src/api/IndexController.php @@ -3,6 +3,7 @@ namespace Yunshop\Rebate\Api; use app\common\components\ApiController; +use app\common\facades\Setting; use app\common\models\Goods; use app\common\models\Income; use app\common\models\Member; @@ -123,6 +124,8 @@ class IndexController extends ApiController{ ->where('yz_member_income.status', 0) ->sum('yz_member_income.amount'); // 获取全部返利信息 并且循环处理 + $set = Setting::get('plugin.rebate'); + $repurchase_day = $set['repurchase_day'] ?? 0; $monthList = Rebate::select(['id','quarter','month','expect_thaw_time','money','status','is_repurchase','repurchase_money','reality_thaw_time']) ->where([ 'uid' => $uid, @@ -148,7 +151,11 @@ class IndexController extends ApiController{ if($quarterList[$monthInfo['quarter']]['status'] != 2) $quarterList[$monthInfo['quarter']]['status'] = (int)$monthInfo['status']; // 当前记录最后一次结算时间 $reality_thaw_time = $monthInfo['reality_thaw_time'] ? strtotime($monthInfo['reality_thaw_time']) : 0; - if((int)$reality_thaw_time > 0) $quarterList[$monthInfo['quarter']]['last_reality_thaw_time'] = (int)$reality_thaw_time; + if(!array_key_exists('last_reality_thaw_time',$quarterList[$monthInfo['quarter']])) $quarterList[$monthInfo['quarter']]['last_reality_thaw_time'] = 0; + if((int)$reality_thaw_time > 0) { + $quarterList[$monthInfo['quarter']]['last_reality_thaw_time'] = (int)$reality_thaw_time; + $quarterList[$monthInfo['quarter']]['repurchase_end_time'] = (int)strtotime(date("Y-m-d H:i:s",$reality_thaw_time)." +{$repurchase_day} day");; + } // 最后一次预计结算时间 $quarterList[$monthInfo['quarter']]['last_expect_thaw_time'] = $monthInfo['expect_thaw_time'] ? strtotime($monthInfo['expect_thaw_time']) : 0; } @@ -190,12 +197,13 @@ class IndexController extends ApiController{ $uid = \YunShop::app()->getMemberId(); $levelId = (int)request()->input('level_id'); // 获取全部等级 - $level_list = TeamDividendLevelModel::uniacid()->select(['id','level_name'])->get()->toArray(); + $level_list = TeamDividendLevelModel::uniacid()->select(['id','level_name'])->orderBy('level_weight','ASC')->get()->toArray(); // 获取登记统计 不存在则使用默认第一个等级 - $levelId = $levelId <= 0 ? $level_list[0]['id'] : $levelId; + $levelId = $levelId <= 0 ? TeamDividendAgencyModel::where('uid', $uid)->value('level') : $levelId; $list = TeamDividendModel::where('member_id', $uid) ->select(['id','expect_thaw_time','dividend_amount','status','type']) ->where('agent_level',$levelId) + ->orderBy('expect_thaw_time','ASC') ->get()->each(function($item){ $item['expect_thaw_time'] = date("m月d日",$item['expect_thaw_time']); @@ -203,10 +211,11 @@ class IndexController extends ApiController{ })->toArray(); // 统计 $all_income = TeamDividendModel::where('member_id', $uid)->where('agent_level',$levelId)->sum('dividend_amount'); - $credited = TeamDividendModel::where('member_id', $uid)->where('agent_level',$levelId)->sum('dividend_amount'); + $credited = TeamDividendModel::where('member_id', $uid)->where('agent_level',$levelId)->where('status', 2)->sum('dividend_amount'); + // 当前等级 + $levelInfo = TeamDividendLevelModel::select(['id','level_name'])->where('id',$levelId)->first(); - - return $this->successJson('success',compact('level_list','list','all_income','credited')); + return $this->successJson('success',compact('level_list','list','all_income','credited','levelInfo')); } } \ No newline at end of file diff --git a/plugins/rebate/src/models/Rebate.php b/plugins/rebate/src/models/Rebate.php index ed734765..0a173c06 100644 --- a/plugins/rebate/src/models/Rebate.php +++ b/plugins/rebate/src/models/Rebate.php @@ -8,6 +8,7 @@ use app\common\models\Goods; use app\common\models\Member; use app\common\models\Order; use app\common\models\OrderGoods; +use app\common\models\UniAccount; use app\common\services\income\IncomeService; use Illuminate\Support\Facades\DB; @@ -47,6 +48,9 @@ class Rebate extends BaseModel{ if($ids) $ids = $ids->toArray(); $query->whereIn('uid',(array)$ids); }) + ->when(isset($search['status']) && $search['status'] != '',function($query) use ($search){ + $query->where('status', $search['status']); + }) ->with([ 'member' => function($query){ $query->select(['uid','nickname','realname','avatar']); @@ -211,57 +215,73 @@ class Rebate extends BaseModel{ * 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() - ]); + set_time_limit(0); + DB::beginTransaction(); + try{ + // 循环平台 进行处理 + $uniAccount = UniAccount::getEnable() ?: []; + foreach ($uniAccount as $u) { + Setting::$uniqueAccountId = \YunShop::app()->uniacid = $u->uniacid; + // 分组 获取最新一条已处理数据 状态: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() + ]); + } + } } + DB::commit(); + }catch(\Exception $e){ + \Log::debug('--- 消费返利 - 失效判断 - 错误:'.$e->getMessage()); + DB::rollBack(); } + + + } diff --git a/plugins/rebate/views/index/index.blade.php b/plugins/rebate/views/index/index.blade.php index e26d4a5b..7a33f289 100644 --- a/plugins/rebate/views/index/index.blade.php +++ b/plugins/rebate/views/index/index.blade.php @@ -63,6 +63,23 @@ +
+
+
+
+ {{--状态:0=冻结中,1=待结算,2=已结算,3=已失效,4=已退款(失效)--}} + +
+
+
+