master
elf 3 years ago
parent ffc5412c37
commit c37d9b8540

@ -417,7 +417,6 @@ class GameRebateService
'base_game_id' => $params['base_game_id'], 'base_game_id' => $params['base_game_id'],
'ref_id' => $params['ref_id'], 'ref_id' => $params['ref_id'],
'name' => $params['name'], 'name' => $params['name'],
'num' => $params['num'],
'value' => $params['value'], 'value' => $params['value'],
'update_time' => time() 'update_time' => time()
]; ];
@ -432,7 +431,6 @@ class GameRebateService
private function checkPropItem($prop) private function checkPropItem($prop)
{ {
$num = $params['num'] ?? 0;
$value = $params['value'] ?? 0; $value = $params['value'] ?? 0;
if (!isset($params['num'])) { if (!isset($params['num'])) {
throw new \Exception('缺少参数道具数量'); throw new \Exception('缺少参数道具数量');
@ -446,10 +444,6 @@ class GameRebateService
if (!isset($params['ref_id'])) { if (!isset($params['ref_id'])) {
throw new \Exception('缺少参数道具ID'); throw new \Exception('缺少参数道具ID');
} }
if (!is_int($num) || $num < 0) {
throw new \Exception('数量必须为大于0的整数');
}
if (!is_int($value) || $value < 0) { if (!is_int($value) || $value < 0) {
throw new \Exception('道具价值必须为大于0的整数'); throw new \Exception('道具价值必须为大于0的整数');
} }
@ -464,7 +458,6 @@ class GameRebateService
'base_game_id' => $baseGameId, 'base_game_id' => $baseGameId,
'ref_id' => $prop['ref_id'], 'ref_id' => $prop['ref_id'],
'name' => $prop['name'], 'name' => $prop['name'],
'num' => $prop['num'],
'value' => $prop['value'], 'value' => $prop['value'],
'create_time' => time(), 'create_time' => time(),
'update_time' => time() 'update_time' => time()
@ -548,14 +541,14 @@ class GameRebateService
{ {
$baseGameId = $params['base_game_id'] ?? 0; $baseGameId = $params['base_game_id'] ?? 0;
$roleId = $params['role_id'] ?? ''; $roleId = $params['role_id'] ?? '';
$propIds = $params['prop_ids'] ?? []; $propItems = $params['props'] ?? [];
$date = date('Y-m-d'); $date = date('Y-m-d');
if ($baseGameId == 0) { if ($baseGameId == 0) {
throw new \Exception('请选择游戏'); throw new \Exception('请选择游戏');
} }
if (count($propIds) == 0) { if (count($props) == 0) {
throw new \Exception('至少选择一项道具'); throw new \Exception('至少选择一项道具');
} }
@ -575,6 +568,20 @@ class GameRebateService
throw new \Exception('未设定定制道具返利倍数'); throw new \Exception('未设定定制道具返利倍数');
} }
$props = M('rebate_props')->where(['id' => ['in', array_column($propItems, 'id')], 'base_game_id' => $baseGameId])->select();
$props = index_by_column('id', $props);
$applyAmount = 0;
$giftContent = [];
foreach ($propItems as $item) {
if (isset($props[$item['id']])) {
$applyAmount += $props[$item['id']]['value'];
$giftContent[] = $props[$item['id']]['name'] . '*' . $item['num'];
} else {
throw new \Exception('道具不存在');
}
}
$gameIds = [$baseGame['android_game_id'], $baseGame['ios_game_id']]; $gameIds = [$baseGame['android_game_id'], $baseGame['ios_game_id']];
$role['game_ids'] = $gameIds; $role['game_ids'] = $gameIds;
$role['base_game_id'] = $baseGameId; $role['base_game_id'] = $baseGameId;
@ -582,9 +589,6 @@ class GameRebateService
$dailyPayAmount = $this->getRoleDailyPayAmount($role, $date); $dailyPayAmount = $this->getRoleDailyPayAmount($role, $date);
$appliedAmount = $this->getRoleDailyAppliedAmount($role, $date); $appliedAmount = $this->getRoleDailyAppliedAmount($role, $date);
$props = M('rebate_props')->where(['id' => ['in', $propIds], 'base_game_id' => $baseGameId])->select();
$applyAmount = array_sum(array_column($props, 'value'));
if ($dailyPayAmount * $setting['max_times'] - $applyAmount - $appliedAmount < 0) { if ($dailyPayAmount * $setting['max_times'] - $applyAmount - $appliedAmount < 0) {
throw new \Exception('额度不足'); throw new \Exception('额度不足');
} }
@ -615,7 +619,7 @@ class GameRebateService
'amount' => $applyAmount, 'amount' => $applyAmount,
'pay_amount' => $dailyPayAmount, 'pay_amount' => $dailyPayAmount,
'gift_key' => '', 'gift_key' => '',
'gift_content' => '', 'gift_content' => implode('|', $giftContent),
'props' => $applyProps, 'props' => $applyProps,
'create_time' => time(), 'create_time' => time(),
]; ];

Loading…
Cancel
Save