添加:每日结算豆豆
This commit is contained in:
parent
9f9593e9bc
commit
bfd14e5f2c
|
|
@ -3,6 +3,7 @@ declare (strict_types=1);
|
||||||
|
|
||||||
namespace app\command;
|
namespace app\command;
|
||||||
|
|
||||||
|
use app\common\repositories\store\platformCommission\LegumesRepository;
|
||||||
use app\common\repositories\store\platformCommission\PartnerSettlementCycleRepository;
|
use app\common\repositories\store\platformCommission\PartnerSettlementCycleRepository;
|
||||||
use think\console\Command;
|
use think\console\Command;
|
||||||
use think\console\Input;
|
use think\console\Input;
|
||||||
|
|
@ -29,6 +30,11 @@ class platformCommission extends Command{
|
||||||
Log::info('合伙人佣金周期计算 - 开始处理');
|
Log::info('合伙人佣金周期计算 - 开始处理');
|
||||||
app()->make(PartnerSettlementCycleRepository::class)->settlementInit();
|
app()->make(PartnerSettlementCycleRepository::class)->settlementInit();
|
||||||
break;
|
break;
|
||||||
|
// 计算昨天产生的豆豆总数
|
||||||
|
case 'compute_legumes_total':
|
||||||
|
Log::info('计算昨日产生的豆豆总数 - 开始处理');
|
||||||
|
app()->make(LegumesRepository::class)->computeYesterdayLegumes();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Log::info('平台抽成计划任务 - 错误 - 不明确的执行内容');
|
Log::info('平台抽成计划任务 - 错误 - 不明确的执行内容');
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
namespace app\common\dao\store\platformCommission;
|
||||||
|
|
||||||
|
use app\common\dao\BaseDao;
|
||||||
|
use app\common\model\store\platformCommission\Legumes;
|
||||||
|
|
||||||
|
class LegumesDao extends BaseDao{
|
||||||
|
|
||||||
|
protected function getModel():string{
|
||||||
|
return Legumes::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace app\common\model\store\platformCommission;
|
||||||
|
|
||||||
|
use app\common\model\BaseModel;
|
||||||
|
|
||||||
|
class Legumes extends BaseModel{
|
||||||
|
|
||||||
|
public static function tablePk():string{
|
||||||
|
return 'id';
|
||||||
|
}
|
||||||
|
public static function tableName():string{
|
||||||
|
return 'platform_commission_legumes';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,73 @@
|
||||||
|
<?php
|
||||||
|
namespace app\common\repositories\store\platformCommission;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\dao\store\platformCommission\LegumesDao;
|
||||||
|
use app\common\model\store\platformCommission\Legumes;
|
||||||
|
use app\common\repositories\BaseRepository;
|
||||||
|
use app\common\repositories\system\config\ConfigClassifyRepository;
|
||||||
|
use app\common\repositories\system\config\ConfigValueRepository;
|
||||||
|
use app\jobs\store\platformCommission\SparateLegumesJob;
|
||||||
|
use think\facade\Db;
|
||||||
|
use think\facade\Log;
|
||||||
|
use Exception;
|
||||||
|
use think\facade\Queue;
|
||||||
|
|
||||||
|
class LegumesRepository extends BaseRepository{
|
||||||
|
|
||||||
|
protected $dao;
|
||||||
|
|
||||||
|
public function __construct(LegumesDao $dao){
|
||||||
|
$this->dao = $dao;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Common: 计算昨天产生的豆豆总数
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2023/12/28 18:57
|
||||||
|
*/
|
||||||
|
public function computeYesterdayLegumes(){
|
||||||
|
$set = app()->make(RecordRepository::class)->getBaseConfig();
|
||||||
|
Db::startTrans();
|
||||||
|
try{
|
||||||
|
// 获取周期时间
|
||||||
|
[$startTime,$endTime] = getTimeStamp('yesterday');// 天
|
||||||
|
// 获取周期内基金池金额
|
||||||
|
$totalIntegralReleaseMoney = (float)app()->make(RecordRepository::class)->getTotalIntegralReleaseMoney($startTime,$endTime);
|
||||||
|
if($totalIntegralReleaseMoney <= 0) throw new Exception('基金池金额为0');
|
||||||
|
// 计算豆豆数量 文创豆=平台抽成的销售额10%➗首次价格0.5
|
||||||
|
$legumesNum = sprintf("%.2f",$totalIntegralReleaseMoney / $set['legumes_price']);
|
||||||
|
// 明日价格 下次文创豆价格=基金池金额(消费者的70%)➗文创豆数量
|
||||||
|
$allIntegralReleaseMoney = (float)app()->make(RecordRepository::class)->getTotalIntegralReleaseMoney();
|
||||||
|
$allLegumes = $this->dao->getSearch([])->sum('legumes_num');
|
||||||
|
$tomorrowLegumesPrice = sprintf("%.2f",$allIntegralReleaseMoney / $allLegumes);
|
||||||
|
// 记录
|
||||||
|
$recordId = Legumes::insertGetId([
|
||||||
|
'total_platform_commission_money' => $totalIntegralReleaseMoney,
|
||||||
|
'legumes_price' => $set['legumes_price'],
|
||||||
|
'legumes_num' => $legumesNum,
|
||||||
|
'tomorrow_legumes_price' => $tomorrowLegumesPrice,
|
||||||
|
'start_time' => $startTime,
|
||||||
|
'end_time' => $endTime,
|
||||||
|
]);
|
||||||
|
// 修改豆豆实时价格
|
||||||
|
$cid = app()->make(ConfigClassifyRepository::class)->keyById('platform_commission');
|
||||||
|
$set['legumes_price'] = $legumesNum;
|
||||||
|
app()->make(ConfigValueRepository::class)->save($cid, $set, 0);
|
||||||
|
// 触发事件 开始给每个消费用户分豆豆
|
||||||
|
Queue::push(SparateLegumesJob::class,[
|
||||||
|
'legumes_id' => $recordId
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
Db::commit();
|
||||||
|
}catch(Exception $e){
|
||||||
|
Db::rollback();
|
||||||
|
Log::info('合伙人佣金结算 - 错误:'.$e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -29,7 +29,8 @@ class RecordRepository extends BaseRepository{
|
||||||
'commission_partner_cycle' => 0,
|
'commission_partner_cycle' => 0,
|
||||||
'commission_merchants_rate' => 0,
|
'commission_merchants_rate' => 0,
|
||||||
'commission_promoter_rate' => 0,
|
'commission_promoter_rate' => 0,
|
||||||
'commission_integral_release_rate' => 0
|
'commission_integral_release_rate' => 0,
|
||||||
|
'legumes_price' => 0.5
|
||||||
];
|
];
|
||||||
$config = systemConfig(array_keys($default));
|
$config = systemConfig(array_keys($default));
|
||||||
return array_filter($config,function($v){
|
return array_filter($config,function($v){
|
||||||
|
|
@ -128,5 +129,25 @@ class RecordRepository extends BaseRepository{
|
||||||
->whereBetweenTime('create_time', $startTime, $endTime)
|
->whereBetweenTime('create_time', $startTime, $endTime)
|
||||||
->update($updateData);
|
->update($updateData);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Common: 获取基金池总基金
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2023/12/28 18:49
|
||||||
|
* @param int $startTime
|
||||||
|
* @param int $endTime
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
public function getTotalIntegralReleaseMoney($startTime = 0,$endTime = 0){
|
||||||
|
return (float)$this->dao->getSearch([])
|
||||||
|
->when($startTime > 0 && $endTime > 0,function($query) use ($startTime,$endTime){
|
||||||
|
$query->whereBetweenTime('create_time', $startTime, $endTime);
|
||||||
|
})
|
||||||
|
->sum('commission_integral_release_money');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,8 @@ class PlatformCommission extends BaseController{
|
||||||
'commission_partner_cycle',
|
'commission_partner_cycle',
|
||||||
'commission_merchants_rate',
|
'commission_merchants_rate',
|
||||||
'commission_promoter_rate',
|
'commission_promoter_rate',
|
||||||
'commission_integral_release_rate'
|
'commission_integral_release_rate',
|
||||||
|
'legumes_price'
|
||||||
]);
|
]);
|
||||||
$validate->check($config);
|
$validate->check($config);
|
||||||
$cid = app()->make(ConfigClassifyRepository::class)->keyById('platform_commission');
|
$cid = app()->make(ConfigClassifyRepository::class)->keyById('platform_commission');
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\jobs\store\platformCommission;
|
||||||
|
|
||||||
|
|
||||||
|
use crmeb\interfaces\JobInterface;
|
||||||
|
use think\facade\Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common: 给昨日消费者分豆豆
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2023/12/28 19:01
|
||||||
|
* Class SparateLegumesJob
|
||||||
|
* @package app\jobs\store\platformCommission
|
||||||
|
*/
|
||||||
|
class SparateLegumesJob implements JobInterface{
|
||||||
|
|
||||||
|
public function fire($job,$data){
|
||||||
|
try{
|
||||||
|
Log::info('给昨日消费者分豆豆 - 开始处理: '.var_export($data,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