From bfd14e5f2cef1f0947bc1f4f7925cbad04d5b620 Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Thu, 28 Dec 2023 19:03:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E6=AF=8F=E6=97=A5?= =?UTF-8?q?=E7=BB=93=E7=AE=97=E8=B1=86=E8=B1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/command/platformCommission.php | 6 ++ .../store/platformCommission/LegumesDao.php | 19 +++++ .../store/platformCommission/Legumes.php | 20 +++++ .../platformCommission/LegumesRepository.php | 73 +++++++++++++++++++ .../platformCommission/RecordRepository.php | 23 +++++- .../store/marketing/PlatformCommission.php | 3 +- .../platformCommission/SparateLegumesJob.php | 51 +++++++++++++ 7 files changed, 193 insertions(+), 2 deletions(-) create mode 100644 app/common/dao/store/platformCommission/LegumesDao.php create mode 100644 app/common/model/store/platformCommission/Legumes.php create mode 100644 app/common/repositories/store/platformCommission/LegumesRepository.php create mode 100644 app/jobs/store/platformCommission/SparateLegumesJob.php diff --git a/app/command/platformCommission.php b/app/command/platformCommission.php index b1e3609..754b1d7 100644 --- a/app/command/platformCommission.php +++ b/app/command/platformCommission.php @@ -3,6 +3,7 @@ declare (strict_types=1); namespace app\command; +use app\common\repositories\store\platformCommission\LegumesRepository; use app\common\repositories\store\platformCommission\PartnerSettlementCycleRepository; use think\console\Command; use think\console\Input; @@ -29,6 +30,11 @@ class platformCommission extends Command{ Log::info('合伙人佣金周期计算 - 开始处理'); app()->make(PartnerSettlementCycleRepository::class)->settlementInit(); break; + // 计算昨天产生的豆豆总数 + case 'compute_legumes_total': + Log::info('计算昨日产生的豆豆总数 - 开始处理'); + app()->make(LegumesRepository::class)->computeYesterdayLegumes(); + break; default: Log::info('平台抽成计划任务 - 错误 - 不明确的执行内容'); break; diff --git a/app/common/dao/store/platformCommission/LegumesDao.php b/app/common/dao/store/platformCommission/LegumesDao.php new file mode 100644 index 0000000..c3710cc --- /dev/null +++ b/app/common/dao/store/platformCommission/LegumesDao.php @@ -0,0 +1,19 @@ +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()); + } + } + + + + + +} diff --git a/app/common/repositories/store/platformCommission/RecordRepository.php b/app/common/repositories/store/platformCommission/RecordRepository.php index 38cfed7..b680140 100644 --- a/app/common/repositories/store/platformCommission/RecordRepository.php +++ b/app/common/repositories/store/platformCommission/RecordRepository.php @@ -29,7 +29,8 @@ class RecordRepository extends BaseRepository{ 'commission_partner_cycle' => 0, 'commission_merchants_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)); return array_filter($config,function($v){ @@ -128,5 +129,25 @@ class RecordRepository extends BaseRepository{ ->whereBetweenTime('create_time', $startTime, $endTime) ->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'); + } + + + + + } diff --git a/app/controller/admin/store/marketing/PlatformCommission.php b/app/controller/admin/store/marketing/PlatformCommission.php index 319f521..b846bd6 100644 --- a/app/controller/admin/store/marketing/PlatformCommission.php +++ b/app/controller/admin/store/marketing/PlatformCommission.php @@ -47,7 +47,8 @@ class PlatformCommission extends BaseController{ 'commission_partner_cycle', 'commission_merchants_rate', 'commission_promoter_rate', - 'commission_integral_release_rate' + 'commission_integral_release_rate', + 'legumes_price' ]); $validate->check($config); $cid = app()->make(ConfigClassifyRepository::class)->keyById('platform_commission'); diff --git a/app/jobs/store/platformCommission/SparateLegumesJob.php b/app/jobs/store/platformCommission/SparateLegumesJob.php new file mode 100644 index 0000000..dc7c929 --- /dev/null +++ b/app/jobs/store/platformCommission/SparateLegumesJob.php @@ -0,0 +1,51 @@ +getMessage(); + Log::info('给昨日消费者分豆豆 - 失败: '.var_export($data,1)); + } + $job->delete(); + } + + public function failed($data){ + Log::info('给昨日消费者分豆豆 - 失败(failed): '.var_export($data,1)); + } + + + + + + + + + + + +}