添加:每日豆豆结算分配给每个用户,按照订单分配
This commit is contained in:
parent
bfd14e5f2c
commit
bb411c89dd
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
namespace app\common\dao\store\platformCommission;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\platformCommission\LegumesLog;
|
||||
|
||||
class LegumesLogDao extends BaseDao{
|
||||
|
||||
protected function getModel():string{
|
||||
return LegumesLog::class;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
|
||||
|
||||
namespace app\common\model\store\platformCommission;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class LegumesLog extends BaseModel{
|
||||
|
||||
public static function tablePk():string{
|
||||
return 'id';
|
||||
}
|
||||
public static function tableName():string{
|
||||
return 'platform_commission_legumes_log';
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
namespace app\common\repositories\store\platformCommission;
|
||||
|
||||
|
||||
use app\common\dao\store\platformCommission\LegumesLogDao;
|
||||
use app\common\repositories\BaseRepository;
|
||||
|
||||
class LegumesLogRepository extends BaseRepository{
|
||||
|
||||
protected $dao;
|
||||
|
||||
public function __construct(LegumesLogDao $dao){
|
||||
$this->dao = $dao;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -34,16 +34,17 @@ class LegumesRepository extends BaseRepository{
|
|||
// 获取周期内基金池金额
|
||||
$totalIntegralReleaseMoney = (float)app()->make(RecordRepository::class)->getTotalIntegralReleaseMoney($startTime,$endTime);
|
||||
if($totalIntegralReleaseMoney <= 0) throw new Exception('基金池金额为0');
|
||||
$legumesPrice = $set['legumes_price'] <= 0 ? 0.5 : $set['legumes_price'];
|
||||
// 计算豆豆数量 文创豆=平台抽成的销售额10%➗首次价格0.5
|
||||
$legumesNum = sprintf("%.2f",$totalIntegralReleaseMoney / $set['legumes_price']);
|
||||
// 明日价格 下次文创豆价格=基金池金额(消费者的70%)➗文创豆数量
|
||||
$legumesNum = (float)sprintf("%.2f",$totalIntegralReleaseMoney / $legumesPrice);
|
||||
// 明日价格 下次文创豆价格=基金池金额(消费者的70%)➗ 文创豆数量
|
||||
$allIntegralReleaseMoney = (float)app()->make(RecordRepository::class)->getTotalIntegralReleaseMoney();
|
||||
$allLegumes = $this->dao->getSearch([])->sum('legumes_num');
|
||||
$tomorrowLegumesPrice = sprintf("%.2f",$allIntegralReleaseMoney / $allLegumes);
|
||||
$allLegumes = (float)$this->dao->getSearch([])->sum('legumes_num');
|
||||
$tomorrowLegumesPrice = sprintf("%.2f",$allIntegralReleaseMoney / ($allLegumes + $legumesNum));
|
||||
// 记录
|
||||
$recordId = Legumes::insertGetId([
|
||||
'total_platform_commission_money' => $totalIntegralReleaseMoney,
|
||||
'legumes_price' => $set['legumes_price'],
|
||||
'legumes_price' => $legumesPrice,
|
||||
'legumes_num' => $legumesNum,
|
||||
'tomorrow_legumes_price' => $tomorrowLegumesPrice,
|
||||
'start_time' => $startTime,
|
||||
|
|
@ -62,12 +63,24 @@ class LegumesRepository extends BaseRepository{
|
|||
Db::commit();
|
||||
}catch(Exception $e){
|
||||
Db::rollback();
|
||||
Log::info('合伙人佣金结算 - 错误:'.$e->getMessage());
|
||||
Log::info('计算昨天产生的豆豆总数 - 错误:'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Common: 获取某条信息
|
||||
* Author: wu-hui
|
||||
* Time: 2023/12/29 9:24
|
||||
* @param $id
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getLegumes($id){
|
||||
$info = $this->dao->get($id);
|
||||
return $info ? $info->toArray() : [];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,11 +3,15 @@
|
|||
namespace app\jobs\store\platformCommission;
|
||||
|
||||
|
||||
use app\common\model\store\order\StoreOrder;
|
||||
use app\common\model\store\platformCommission\LegumesLog;
|
||||
use app\common\repositories\store\platformCommission\LegumesLogRepository;
|
||||
use app\common\repositories\store\platformCommission\LegumesRepository;
|
||||
use crmeb\interfaces\JobInterface;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* Common: 给昨日消费者分豆豆
|
||||
* Common: 给本周期内消费者分豆豆
|
||||
* Author: wu-hui
|
||||
* Time: 2023/12/28 19:01
|
||||
* Class SparateLegumesJob
|
||||
|
|
@ -17,15 +21,41 @@ class SparateLegumesJob implements JobInterface{
|
|||
|
||||
public function fire($job,$data){
|
||||
try{
|
||||
Log::info('给昨日消费者分豆豆 - 开始处理: '.var_export($data,1));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Log::info('给本周期内消费者分豆豆 - 开始处理: '.var_export($data,1));
|
||||
// 获取周期信息
|
||||
$cycleLegumes = app()->make(LegumesRepository::class)->getLegumes($data['legumes_id']);
|
||||
if(!$cycleLegumes) throw new \Exception('信息不存在');
|
||||
if((int)$cycleLegumes['status'] != 0) throw new \Exception('当前豆豆已分配!');
|
||||
// 获取时间段所有消费用户
|
||||
$orderList = StoreOrder::whereNotIn('status',[-1,11])
|
||||
->field('order_id,uid,(sum(pay_price) + sum(use_platform_integral_price)) as sum_money')
|
||||
->whereBetweenTime('pay_time',$cycleLegumes['start_time'],$cycleLegumes['end_time'])
|
||||
->group('order_id')
|
||||
->select()
|
||||
->toArray();
|
||||
$totalMoney = array_sum(array_column($orderList,'sum_money'));
|
||||
$insertData = [];
|
||||
foreach($orderList as $orderInfo){
|
||||
// 计算订单金额占比 必须进行100的偏移计算
|
||||
$rate = (float)sprintf("%.3f",$orderInfo['sum_money'] / $totalMoney * 100);
|
||||
$getLegumes = sprintf("%.3f",$cycleLegumes['legumes_num'] * $rate / 100);
|
||||
// 信息记录
|
||||
$insertData[] = [
|
||||
'legumes_id' => $data['legumes_id'],
|
||||
'order_id' => $orderInfo['order_id'],
|
||||
'cycle_total_legumes' => $cycleLegumes['legumes_num'],
|
||||
'total_sales_money' => $totalMoney,
|
||||
'order_money' => $orderInfo['sum_money'],
|
||||
'order_money_rate' => $rate,
|
||||
'get_legumes' => $getLegumes,
|
||||
];
|
||||
}
|
||||
// 添加数据
|
||||
if(count($insertData) > 0) app()->make(LegumesLogRepository::class)->insertAll($insertData);
|
||||
|
||||
app()->make(LegumesRepository::class)->update($data['legumes_id'],[
|
||||
'status' => 1
|
||||
]);
|
||||
}
|
||||
catch(\Exception $e){
|
||||
$data['error_msg'] = $e->getMessage();
|
||||
|
|
@ -35,7 +65,7 @@ class SparateLegumesJob implements JobInterface{
|
|||
}
|
||||
|
||||
public function failed($data){
|
||||
Log::info('给昨日消费者分豆豆 - 失败(failed): '.var_export($data,1));
|
||||
Log::info('给本周期内消费者分豆豆 - 失败(failed): '.var_export($data,1));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue