优化:合伙人佣金结算 - 添加已退款信息处理
This commit is contained in:
parent
b1d3c95c4f
commit
dfc2785eb5
|
|
@ -32,18 +32,20 @@ class LegumesRepository extends BaseRepository{
|
||||||
// 获取周期时间
|
// 获取周期时间
|
||||||
[$startTime,$endTime] = getTimeStamp('yesterday');// 天
|
[$startTime,$endTime] = getTimeStamp('yesterday');// 天
|
||||||
// 获取周期内基金池金额
|
// 获取周期内基金池金额
|
||||||
$totalIntegralReleaseMoney = (float)app()->make(RecordRepository::class)->getTotalIntegralReleaseMoney($startTime,$endTime);
|
[$totalIntegralReleaseMoney,$refundMoney,$realityMoney] = app()->make(RecordRepository::class)->getTotalIntegralReleaseMoney($startTime,$endTime);
|
||||||
if($totalIntegralReleaseMoney <= 0) throw new Exception('基金池金额为0');
|
if($realityMoney <= 0) throw new Exception('基金池金额为0');
|
||||||
$legumesPrice = $set['legumes_price'] <= 0 ? 0.5 : $set['legumes_price'];
|
$legumesPrice = $set['legumes_price'] <= 0 ? 0.5 : $set['legumes_price'];
|
||||||
// 计算豆豆数量 文创豆=平台抽成的销售额10%➗首次价格0.5
|
// 计算豆豆数量 文创豆=平台抽成的销售额10%➗首次价格0.5
|
||||||
$legumesNum = (float)sprintf("%.2f",$totalIntegralReleaseMoney / $legumesPrice);
|
$legumesNum = (float)sprintf("%.2f",$realityMoney / $legumesPrice);
|
||||||
// 明日价格 下次文创豆价格=基金池金额(消费者的70%)➗ 文创豆数量
|
// 明日价格 下次文创豆价格=基金池金额(消费者的70%)➗ 文创豆数量
|
||||||
$allIntegralReleaseMoney = (float)app()->make(RecordRepository::class)->getTotalIntegralReleaseMoney();
|
[$allTotalIntegralReleaseMoney,$allRefundMoney,$allRealityMoney] = app()->make(RecordRepository::class)->getTotalIntegralReleaseMoney();
|
||||||
$allLegumes = (float)$this->dao->getSearch([])->sum('legumes_num');
|
$allLegumes = (float)$this->dao->getSearch([])->sum('legumes_num');
|
||||||
$tomorrowLegumesPrice = sprintf("%.2f",$allIntegralReleaseMoney / ($allLegumes + $legumesNum));
|
$tomorrowLegumesPrice = sprintf("%.2f",$allRealityMoney / ($allLegumes + $legumesNum));
|
||||||
// 记录
|
// 记录
|
||||||
$recordId = Legumes::insertGetId([
|
$recordId = Legumes::insertGetId([
|
||||||
'total_platform_commission_money' => $totalIntegralReleaseMoney,
|
'total_platform_commission_money' => $totalIntegralReleaseMoney,
|
||||||
|
'refund_money' => $refundMoney,
|
||||||
|
'reality_money' => $realityMoney,
|
||||||
'legumes_price' => $legumesPrice,
|
'legumes_price' => $legumesPrice,
|
||||||
'legumes_num' => $legumesNum,
|
'legumes_num' => $legumesNum,
|
||||||
'tomorrow_legumes_price' => $tomorrowLegumesPrice,
|
'tomorrow_legumes_price' => $tomorrowLegumesPrice,
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ class PartnerSettlementCycleRepository extends BaseRepository{
|
||||||
protected $dao;
|
protected $dao;
|
||||||
private $set;
|
private $set;
|
||||||
private $startTime,$endTime;
|
private $startTime,$endTime;
|
||||||
private $totalCommission;
|
private $totalCommission,$refundTotalCommission,$realityMoney;
|
||||||
|
|
||||||
public function __construct(PartnerSettlementCycleDao $dao){
|
public function __construct(PartnerSettlementCycleDao $dao){
|
||||||
$this->dao = $dao;
|
$this->dao = $dao;
|
||||||
|
|
@ -102,8 +102,9 @@ class PartnerSettlementCycleRepository extends BaseRepository{
|
||||||
throw new Exception("执行时间错误(上一个周期结束时间{$upCycleEndDate},下一个周期结束时间{$nextCycleEndDate})");
|
throw new Exception("执行时间错误(上一个周期结束时间{$upCycleEndDate},下一个周期结束时间{$nextCycleEndDate})");
|
||||||
}
|
}
|
||||||
// 判断:分红总金额是否大于0
|
// 判断:分红总金额是否大于0
|
||||||
$this->totalCommission = (float)app()->make(RecordRepository::class)->getTotalCommission($this->startTime,$this->endTime);
|
[$this->totalCommission,$this->refundTotalCommission,$this->realityMoney] = (float)app()->make(RecordRepository::class)->getTotalCommission($this->startTime,$this->endTime);
|
||||||
if($this->totalCommission <= 0) throw new Exception('分红总金额为0');
|
|
||||||
|
if($this->realityMoney <= 0) throw new Exception('分红总金额为0');
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Common: 合伙人结算 - 佣金计算并且记录
|
* Common: 合伙人结算 - 佣金计算并且记录
|
||||||
|
|
@ -125,6 +126,8 @@ class PartnerSettlementCycleRepository extends BaseRepository{
|
||||||
// 记录周期分红信息
|
// 记录周期分红信息
|
||||||
$cycleId = PartnerSettlementCycle::insertGetId([
|
$cycleId = PartnerSettlementCycle::insertGetId([
|
||||||
'total_commission' => $this->totalCommission,
|
'total_commission' => $this->totalCommission,
|
||||||
|
'refund_money' => $this->refundTotalCommission,
|
||||||
|
'reality_money' => $this->realityMoney,
|
||||||
'total_weight_value' => $totalWeightValue,
|
'total_weight_value' => $totalWeightValue,
|
||||||
'total_people' => count($userList),
|
'total_people' => count($userList),
|
||||||
'start_time' => $this->startTime,
|
'start_time' => $this->startTime,
|
||||||
|
|
@ -135,7 +138,7 @@ class PartnerSettlementCycleRepository extends BaseRepository{
|
||||||
foreach($userList as $userId => $weightValue){
|
foreach($userList as $userId => $weightValue){
|
||||||
// 添加贡献分享分红信息记录 这里必须进行100的偏移计算
|
// 添加贡献分享分红信息记录 这里必须进行100的偏移计算
|
||||||
$radio = (float)sprintf("%.2f",($weightValue / $totalWeightValue) * 100);// 佣金比例
|
$radio = (float)sprintf("%.2f",($weightValue / $totalWeightValue) * 100);// 佣金比例
|
||||||
$money = (float)sprintf("%.2f",($this->totalCommission * $radio) / 100);// 实际获得佣金
|
$money = (float)sprintf("%.2f",($this->realityMoney * $radio) / 100);// 实际获得佣金
|
||||||
if($money > 0){
|
if($money > 0){
|
||||||
$logInsertData[] = [
|
$logInsertData[] = [
|
||||||
'uid' => $userId,
|
'uid' => $userId,
|
||||||
|
|
|
||||||
|
|
@ -116,13 +116,28 @@ class RecordRepository extends BaseRepository{
|
||||||
* Time: 2023/12/28 14:22
|
* Time: 2023/12/28 14:22
|
||||||
* @param $startTime
|
* @param $startTime
|
||||||
* @param $endTime
|
* @param $endTime
|
||||||
* @return float
|
* @return float[]
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
*/
|
*/
|
||||||
public function getTotalCommission($startTime,$endTime):float{
|
public function getTotalCommission($startTime,$endTime):array{
|
||||||
return (float)$this->dao->getSearch([])
|
// 获取总数量
|
||||||
|
$totalMoney = (float)$this->dao->getSearch([])
|
||||||
->whereBetweenTime('create_time', $startTime, $endTime)
|
->whereBetweenTime('create_time', $startTime, $endTime)
|
||||||
->where('commission_partner_status',0)
|
->where('commission_partner_status',0)
|
||||||
->sum('commission_partner_money');
|
->sum('commission_partner_money');
|
||||||
|
// 获取退款金额
|
||||||
|
$refundMoneyInfo = $this->dao->getSearch([])
|
||||||
|
->field('sum((commission_partner_money * refund_ratio / 100)) as refund_money')
|
||||||
|
->whereBetweenTime('create_time', $startTime, $endTime)
|
||||||
|
->where('commission_partner_status',0)
|
||||||
|
->find();
|
||||||
|
$refundMoney = sprintf("%.2f",$refundMoneyInfo->refund_money ?? 0);
|
||||||
|
// 实际金额
|
||||||
|
$realityMoney = sprintf("%.2f",$totalMoney - $refundMoney);
|
||||||
|
|
||||||
|
return [(float)$totalMoney,(float)$refundMoney,(float)$realityMoney];
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Common: 修改指定时间内 合伙人佣金结算状态
|
* Common: 修改指定时间内 合伙人佣金结算状态
|
||||||
|
|
@ -144,14 +159,31 @@ class RecordRepository extends BaseRepository{
|
||||||
* Time: 2023/12/28 18:49
|
* Time: 2023/12/28 18:49
|
||||||
* @param int $startTime
|
* @param int $startTime
|
||||||
* @param int $endTime
|
* @param int $endTime
|
||||||
* @return float
|
* @return array
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
*/
|
*/
|
||||||
public function getTotalIntegralReleaseMoney($startTime = 0,$endTime = 0){
|
public function getTotalIntegralReleaseMoney(int $startTime = 0,int $endTime = 0):array{
|
||||||
return (float)$this->dao->getSearch([])
|
// 获取总数量
|
||||||
|
$totalIntegralReleaseMoney = (float)$this->dao->getSearch([])
|
||||||
->when($startTime > 0 && $endTime > 0,function($query) use ($startTime,$endTime){
|
->when($startTime > 0 && $endTime > 0,function($query) use ($startTime,$endTime){
|
||||||
$query->whereBetweenTime('create_time', $startTime, $endTime);
|
$query->whereBetweenTime('create_time', $startTime, $endTime);
|
||||||
})
|
})
|
||||||
->sum('commission_integral_release_money');
|
->sum('commission_integral_release_money');
|
||||||
|
// 获取退款金额
|
||||||
|
$refundTotalIntegralReleaseMoney = $this->dao->getSearch([])
|
||||||
|
->field('sum((commission_integral_release_money * refund_ratio / 100)) as refund_money')
|
||||||
|
->when($startTime > 0 && $endTime > 0,function($query) use ($startTime,$endTime){
|
||||||
|
$query->whereBetweenTime('create_time', $startTime, $endTime);
|
||||||
|
})
|
||||||
|
->find();
|
||||||
|
$refundMoney = sprintf("%.2f",$refundTotalIntegralReleaseMoney->refund_money ?? 0);
|
||||||
|
// 实际金额
|
||||||
|
$realityMoney = sprintf("%.2f",$totalIntegralReleaseMoney - $refundMoney);
|
||||||
|
|
||||||
|
|
||||||
|
return [(float)$totalIntegralReleaseMoney,(float)$refundMoney,(float)$realityMoney];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue