添加:平台抽成 - 合伙人佣金结算到账
This commit is contained in:
parent
1335295cf9
commit
ffa433562e
|
|
@ -26,7 +26,7 @@ class platformCommission extends Command{
|
|||
switch($runType){
|
||||
// 合伙人佣金结算
|
||||
case 'commission_partner_settlement':
|
||||
Log::info('合伙人佣金结算 - 开始处理');
|
||||
Log::info('合伙人佣金周期计算 - 开始处理');
|
||||
app()->make(PartnerSettlementCycleRepository::class)->settlementInit();
|
||||
break;
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -26,7 +26,14 @@ class PartnerSettlement extends BaseModel{
|
|||
public function user(){
|
||||
return $this->hasOne(User::class, 'uid', 'uid');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Common: 关联周期表
|
||||
* Author: wu-hui
|
||||
* Time: 2023/12/28 17:25
|
||||
* @return \think\model\relation\HasOne
|
||||
*/
|
||||
public function cycle(){
|
||||
return $this->hasOne(PartnerSettlementCycle::class, 'id', 'cycle_id');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,11 @@ use app\common\dao\store\platformCommission\PartnerSettlementCycleDao;
|
|||
use app\common\model\store\platformCommission\PartnerSettlement;
|
||||
use app\common\model\store\platformCommission\PartnerSettlementCycle;
|
||||
use app\common\repositories\BaseRepository;
|
||||
use app\jobs\store\platformCommission\CommissionPartnerSettlementJob;
|
||||
use Exception;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
use think\facade\Queue;
|
||||
|
||||
class PartnerSettlementCycleRepository extends BaseRepository{
|
||||
|
||||
|
|
@ -113,7 +115,13 @@ class PartnerSettlementCycleRepository extends BaseRepository{
|
|||
private function settlementBonusHandle(){
|
||||
$userList = app()->make(WeightValueLogRepository::class)->getHoldList($this->endTime);
|
||||
$totalWeightValue = (float)array_sum($userList);// 总权重值
|
||||
if($totalWeightValue <= 0) throw new Exception('不存在分红用户或截至当前周期结束时间总共的权重值为0');
|
||||
if($totalWeightValue <= 0) {
|
||||
// 分红失败 修改分红状态
|
||||
app()->make(RecordRepository::class)->updateCommissionPartnerStatus($this->startTime,$this->endTime,[
|
||||
'commission_partner_status' => 2
|
||||
]);
|
||||
throw new Exception('不存在分红用户或截至当前周期结束时间总共的权重值为0');
|
||||
}
|
||||
// 记录周期分红信息
|
||||
$cycleId = PartnerSettlementCycle::insertGetId([
|
||||
'total_commission' => $this->totalCommission,
|
||||
|
|
@ -139,8 +147,18 @@ class PartnerSettlementCycleRepository extends BaseRepository{
|
|||
];
|
||||
}
|
||||
}
|
||||
|
||||
PartnerSettlement::insertAll($logInsertData);
|
||||
// 记录分红信息 并且开始结算
|
||||
if(count($logInsertData) > 0){
|
||||
PartnerSettlement::insertAll($logInsertData);
|
||||
// 修改分红佣金状态为已结算
|
||||
app()->make(RecordRepository::class)->updateCommissionPartnerStatus($this->startTime,$this->endTime,[
|
||||
'commission_partner_status' => 1
|
||||
]);
|
||||
// 推广员佣金结算
|
||||
Queue::push(CommissionPartnerSettlementJob::class,[
|
||||
'cycle_id' => $cycleId
|
||||
]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,4 +45,7 @@ class PartnerSettlementRepository extends BaseRepository{
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,8 +113,19 @@ class RecordRepository extends BaseRepository{
|
|||
->whereBetweenTime('create_time', $startTime, $endTime)
|
||||
->sum('commission_partner_money');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Common: 修改指定时间内 合伙人佣金结算状态
|
||||
* Author: wu-hui
|
||||
* Time: 2023/12/28 17:12
|
||||
* @param $startTime
|
||||
* @param $endTime
|
||||
* @param $updateData
|
||||
* @return \app\common\model\BaseModel
|
||||
*/
|
||||
public function updateCommissionPartnerStatus($startTime,$endTime,$updateData){
|
||||
return $this->dao->getSearch([])
|
||||
->whereBetweenTime('create_time', $startTime, $endTime)
|
||||
->update($updateData);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ class UserBillRepository extends BaseRepository
|
|||
'brokerage/order_two' => '获得二级推广佣金',
|
||||
'brokerage/refund_one' => '退还一级佣金',
|
||||
'brokerage/refund_two' => '退还二级佣金',
|
||||
'brokerage/commission_partner' => '权重值分红',// 权重值分红
|
||||
'brokerage/commission_merchants' => '招商员佣金',
|
||||
'brokerage/commission_promoter' => '推广员佣金',
|
||||
'integral/cancel' => '退回积分',
|
||||
|
|
|
|||
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
namespace app\jobs\store\platformCommission;
|
||||
|
||||
|
||||
use app\common\repositories\store\platformCommission\PartnerSettlementCycleRepository;
|
||||
use app\common\repositories\store\platformCommission\PartnerSettlementRepository;
|
||||
use app\common\repositories\user\UserBillRepository;
|
||||
use app\common\repositories\user\UserRepository;
|
||||
use crmeb\interfaces\JobInterface;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* Common: 合伙人佣金结算
|
||||
* Author: wu-hui
|
||||
* Time: 2023/12/28 17:06
|
||||
* Class CommissionPartnerSettlementJob
|
||||
* @package app\jobs\store\platformCommission
|
||||
*/
|
||||
class CommissionPartnerSettlementJob implements JobInterface{
|
||||
|
||||
public function fire($job,$data){
|
||||
try{
|
||||
Log::info('合伙人佣金结算 - 开始处理: '.var_export($data,1));
|
||||
// 获取全部佣金结算记录
|
||||
$cycleInfo = app()->make(PartnerSettlementCycleRepository::class)
|
||||
->getSearch([])
|
||||
->field('start_time,end_time')
|
||||
->where('id',$data['cycle_id'])
|
||||
->find()
|
||||
->toArray();
|
||||
$list = app()->make(PartnerSettlementRepository::class)
|
||||
->getSearch([])
|
||||
->field(['id','uid','cycle_id','money'])
|
||||
->where('cycle_id',$data['cycle_id'])
|
||||
->where('is_settlement',0)
|
||||
->select()
|
||||
->toArray();
|
||||
if($list){
|
||||
$userBillRepository = app()->make(UserBillRepository::class);
|
||||
$userRepository = app()->make(UserRepository::class);
|
||||
$dateCycle = date("Y-m-d H:i:s",$cycleInfo['start_time']) . ' ~ ' . date("Y-m-d H:i:s",$cycleInfo['end_time']);
|
||||
foreach($list as $singleInfo){
|
||||
$userBillRepository->incBill($singleInfo['uid'], 'brokerage', 'commission_partner', [
|
||||
'link_id' => $singleInfo['cycle_id'],
|
||||
'status' => 0,
|
||||
'title' => '获得权重值分红',
|
||||
'number' => $singleInfo['money'],
|
||||
'mark' => $dateCycle. '时间内获得权重值分红,分红金额:' . floatval($singleInfo['money']),
|
||||
'balance' => 0
|
||||
]);
|
||||
$userRepository->incBrokerage($singleInfo['uid'], $singleInfo['money']);
|
||||
}
|
||||
// 修改结算状态
|
||||
$ids = array_column($list,'id');
|
||||
app()->make(PartnerSettlementRepository::class)
|
||||
->getSearch([])
|
||||
->whereIn('id',$ids)
|
||||
->update([
|
||||
'is_settlement' => 1
|
||||
]);
|
||||
}
|
||||
}
|
||||
catch(\Exception $e){
|
||||
$data['error_msg'] = $e->getMessage();
|
||||
Log::info('合伙人佣金结算 - 失败: '.var_export($data,1));
|
||||
}
|
||||
$job->delete();
|
||||
}
|
||||
public function failed($data){
|
||||
Log::info('合伙人佣金结算 - 失败(failed): '.var_export($data,1));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue