0, 'count' => $count, 'each' => 0]; } if ($count <= 0) { PartnerRewardService::write([ 'order_id' => PartnerRewardService::dailyOrderId($settleDate), 'buyer_id' => 0, 'user_id' => 0, 'role' => 'system', 'reward_type' => 'madow_share', 'amount' => 0, 'madow' => $pool, 'base_amount' => $pool, 'settle_date' => $settleDate, 'ext' => ['formula' => "分母为0,马豆池 {$pool} 进平台", 'skip_reason' => ''], '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; $dailyOrderId = PartnerRewardService::dailyOrderId($settleDate); $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' => $dailyOrderId, 'buyer_id' => 0, 'user_id' => $userId, 'role' => 'taster', 'reward_type' => 'madow_share', 'amount' => 0, 'madow' => $each, 'base_amount' => $pool, 'settle_date' => $settleDate, 'ext' => json_encode(['formula' => "GMV {$pool} / {$count} = {$each}", 'share_user_count' => $count, 'gmv' => $pool], 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' => PartnerRewardService::dailyOrderId($settleDate), 'buyer_id' => 0, 'user_id' => 0, 'role' => 'system', 'reward_type' => 'madow_share', 'amount' => 0, 'madow' => $tail, 'base_amount' => $pool, 'settle_date' => $settleDate, 'ext' => ['formula' => "尾差 {$tail} 进平台"], 'status' => 1, ]); } return ['pool' => $pool, 'count' => $count, 'each' => $each]; } public function rollback($settleDate) { $rows = \app\admin\model\shopro\partner\Reward::where('settle_date', $settleDate) ->where('reward_type', 'madow_share') ->where('status', 1) ->where('user_id', '>', 0) ->select(); foreach ($rows as $row) { if ((float) $row->madow > 0) { AgentModel::where('user_id', $row->user_id)->setDec('madow', $row->madow); } } } }