feat: 临时调整马豆结算与兑换券释放为1分钟执行一次
这个提交包含在:
@@ -82,6 +82,86 @@ class MadowService
|
||||
return ['pool' => $pool, 'count' => $count, 'each' => $each];
|
||||
}
|
||||
|
||||
/**
|
||||
* 临时分钟级马豆结算均分
|
||||
*/
|
||||
public function shareMinute($gmv, $userIds, $orderIds = [])
|
||||
{
|
||||
$count = count($userIds);
|
||||
$pool = (float) $gmv;
|
||||
if ($pool <= 0) {
|
||||
return ['pool' => 0, 'count' => $count, 'each' => 0];
|
||||
}
|
||||
|
||||
$minId = (int) \think\Db::name('shopro_partner_reward')->where('order_id', '<', 0)->min('order_id');
|
||||
$virtualOrderId = min(-100000, $minId - 1);
|
||||
|
||||
if ($count <= 0) {
|
||||
PartnerRewardService::write([
|
||||
'order_id' => $virtualOrderId,
|
||||
'buyer_id' => 0,
|
||||
'user_id' => 0,
|
||||
'role' => 'system',
|
||||
'reward_type' => 'madow_share',
|
||||
'amount' => 0,
|
||||
'madow' => $pool,
|
||||
'base_amount' => $pool,
|
||||
'settle_date' => null,
|
||||
'ext' => ['formula' => "分母为0,马豆池 {$pool} 进平台", 'orders' => $orderIds],
|
||||
'status' => 1,
|
||||
]);
|
||||
return ['pool' => $pool, 'count' => 0, 'each' => 0];
|
||||
}
|
||||
|
||||
$each = function_exists('bcdiv') ? bcdiv((string) $pool, (string) $count, 8) : number_format($pool / $count, 8, '.', '');
|
||||
$distributed = 0;
|
||||
$now = time();
|
||||
$chunks = array_chunk($userIds, 500);
|
||||
|
||||
foreach ($chunks as $chunk) {
|
||||
AgentModel::whereIn('user_id', $chunk)->setInc('madow', $each);
|
||||
$batchRows = [];
|
||||
foreach ($chunk as $userId) {
|
||||
$batchRows[] = [
|
||||
'order_id' => $virtualOrderId,
|
||||
'buyer_id' => 0,
|
||||
'user_id' => $userId,
|
||||
'role' => 'taster',
|
||||
'reward_type' => 'madow_share',
|
||||
'amount' => 0,
|
||||
'madow' => $each,
|
||||
'base_amount' => $pool,
|
||||
'settle_date' => null,
|
||||
'ext' => json_encode(['formula' => "GMV {$pool} / {$count} = {$each}", 'share_user_count' => $count, 'gmv' => $pool, 'orders' => $orderIds], JSON_UNESCAPED_UNICODE),
|
||||
'status' => 1,
|
||||
'createtime' => $now,
|
||||
'updatetime' => $now,
|
||||
];
|
||||
$distributed = function_exists('bcadd') ? bcadd((string) $distributed, (string) $each, 8) : ($distributed + $each);
|
||||
}
|
||||
\think\Db::name('shopro_partner_reward')->insertAll($batchRows);
|
||||
}
|
||||
|
||||
$tail = function_exists('bcsub') ? bcsub((string) $pool, (string) $distributed, 8) : round($pool - $distributed, 8);
|
||||
if ((float) $tail > 0) {
|
||||
PartnerRewardService::write([
|
||||
'order_id' => $virtualOrderId,
|
||||
'buyer_id' => 0,
|
||||
'user_id' => 0,
|
||||
'role' => 'system',
|
||||
'reward_type' => 'madow_share',
|
||||
'amount' => 0,
|
||||
'madow' => $tail,
|
||||
'base_amount' => $pool,
|
||||
'settle_date' => null,
|
||||
'ext' => ['formula' => "尾差 {$tail} 进平台", 'orders' => $orderIds],
|
||||
'status' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
return ['pool' => $pool, 'count' => $count, 'each' => $each];
|
||||
}
|
||||
|
||||
public function rollback($settleDate)
|
||||
{
|
||||
$rows = \app\admin\model\shopro\partner\Reward::where('settle_date', $settleDate)
|
||||
|
||||
在新工单中引用
屏蔽一个用户