73 lines
2.9 KiB
PHP
73 lines
2.9 KiB
PHP
<?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' => 1,
|
|
'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));
|
|
}
|
|
}
|