|
|
|
@ -31,6 +31,8 @@ class GameRebateService
|
|
|
|
|
'F' => '周卡福利发放',
|
|
|
|
|
'G' => '首次进游福利',
|
|
|
|
|
'H' => '签到福利发放',
|
|
|
|
|
'I' => '充值返利发放',
|
|
|
|
|
'J' => '定制道具申请',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public $typeNames = [
|
|
|
|
@ -42,8 +44,12 @@ class GameRebateService
|
|
|
|
|
'F' => 'weekly',
|
|
|
|
|
'G' => 'newRole',
|
|
|
|
|
'H' => 'dailySign',
|
|
|
|
|
'I' => 'singleTimes',
|
|
|
|
|
'J' => 'propsApply',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public $rebateBaseGameIds = [];
|
|
|
|
|
|
|
|
|
|
public function isGiftItemSend($order, $item)
|
|
|
|
|
{
|
|
|
|
|
// 每日发放奖励暂时通过send_status来判断是否第一次发放
|
|
|
|
@ -382,4 +388,247 @@ class GameRebateService
|
|
|
|
|
'reviewer_username' => $handler['username'],
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function deleteProp($id)
|
|
|
|
|
{
|
|
|
|
|
M('rebate_prpos', 'tab_')->where(['id' => $id])->delete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function batchDeleteProp($ids, $baseGameId)
|
|
|
|
|
{
|
|
|
|
|
M('rebate_prpos', 'tab_')->where(['id' => ['in', $ids], 'base_game_id' => $baseGameId])->delete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function saveProp($params)
|
|
|
|
|
{
|
|
|
|
|
$id = $params['id'] ?? 0;
|
|
|
|
|
|
|
|
|
|
$this->checkPropItem($params);
|
|
|
|
|
|
|
|
|
|
$prop = null;
|
|
|
|
|
if ($id > 0) {
|
|
|
|
|
$prop = M('rebate_prpos', 'tab_')->where(['id' => $id])->find();
|
|
|
|
|
if (!$prop) {
|
|
|
|
|
throw new \Exception('道具不存在');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
|
'base_game_id' => $params['base_game_id'],
|
|
|
|
|
'ref_id' => $params['ref_id'],
|
|
|
|
|
'name' => $params['name'],
|
|
|
|
|
'num' => $params['num'],
|
|
|
|
|
'value' => $params['value'],
|
|
|
|
|
'update_time' => time()
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if ($id > 0) {
|
|
|
|
|
M('rebate_prpos', 'tab_')->where(['id' => $id])->save($data);
|
|
|
|
|
} else {
|
|
|
|
|
$data['create_time'] = time();
|
|
|
|
|
M('rebate_prpos', 'tab_')->add($data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function checkPropItem($prop)
|
|
|
|
|
{
|
|
|
|
|
$num = $params['num'] ?? 0;
|
|
|
|
|
$value = $params['value'] ?? 0;
|
|
|
|
|
if (!isset($params['num'])) {
|
|
|
|
|
throw new \Exception('缺少参数道具数量');
|
|
|
|
|
}
|
|
|
|
|
if (!isset($params['value'])) {
|
|
|
|
|
throw new \Exception('缺少参数道具价值');
|
|
|
|
|
}
|
|
|
|
|
if (!isset($params['name'])) {
|
|
|
|
|
throw new \Exception('缺少参数道具名称');
|
|
|
|
|
}
|
|
|
|
|
if (!isset($params['ref_id'])) {
|
|
|
|
|
throw new \Exception('缺少参数道具ID');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!is_int($num) || $num < 0) {
|
|
|
|
|
throw new \Exception('数量必须为大于0的整数');
|
|
|
|
|
}
|
|
|
|
|
if (!is_int($value) || $value < 0) {
|
|
|
|
|
throw new \Exception('道具价值必须为大于0的整数');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function saveProps($baseGameId, $props)
|
|
|
|
|
{
|
|
|
|
|
$records = [];
|
|
|
|
|
foreach ($props as $prop) {
|
|
|
|
|
$this->checkPropItem($prop);
|
|
|
|
|
$records[] = [
|
|
|
|
|
'base_game_id' => $baseGameId,
|
|
|
|
|
'ref_id' => $prop['ref_id'],
|
|
|
|
|
'name' => $prop['name'],
|
|
|
|
|
'num' => $prop['num'],
|
|
|
|
|
'value' => $prop['value'],
|
|
|
|
|
'create_time' => time(),
|
|
|
|
|
'update_time' => time()
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
M('rebate_prpos', 'tab_')->addAll($records);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function saveSetting($params)
|
|
|
|
|
{
|
|
|
|
|
$baseGameId = $params['base_game_id'] ?? 0;
|
|
|
|
|
$defaultTimes = $params['default_times'] ?? 0;
|
|
|
|
|
$maxTimes = $params['max_times'] ?? 0;
|
|
|
|
|
$type = $params['type'] ?? 'J';
|
|
|
|
|
|
|
|
|
|
if ($baseGameId == 0) {
|
|
|
|
|
throw new \Exception('请选择游戏');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$setting = M('rebate_times_setting', 'tab_')->where(['base_game_id' => $baseGameId, 'type' => $type])->find();
|
|
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
|
'base_game_id' => $params['base_game_id'],
|
|
|
|
|
'type' => $type,
|
|
|
|
|
'default_times' => $defaultTimes,
|
|
|
|
|
'max_times' => $maxTimes,
|
|
|
|
|
'update_time' => time()
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if ($setting) {
|
|
|
|
|
M('rebate_times_setting', 'tab_')->where(['id' => $setting['id']])->save($data);
|
|
|
|
|
} else {
|
|
|
|
|
$data['create_time'] = time();
|
|
|
|
|
M('rebate_times_setting', 'tab_')->add($data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function deleteSetting($id)
|
|
|
|
|
{
|
|
|
|
|
$setting = M('rebate_times_setting', 'tab_')->where(['id' => $id])->find();
|
|
|
|
|
if (!$setting) {
|
|
|
|
|
throw new \Exception('记录不存在');
|
|
|
|
|
}
|
|
|
|
|
if ($setting['type'] == 'J') {
|
|
|
|
|
$count = M('rebate_props', 'tab_')->where(['base_game_id' => $setting['base_game_id']])->count();
|
|
|
|
|
if ($count > 0) {
|
|
|
|
|
throw new \Exception('该游戏道具列表含有道具,无法删除!');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
M('rebate_times_setting', 'tab_')->where(['id' => $id])->delete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getRoleDailyPayAmount($role, $date)
|
|
|
|
|
{
|
|
|
|
|
$map = [
|
|
|
|
|
'pay_status' => 1,
|
|
|
|
|
'game_play_id' => $role['role_id'],
|
|
|
|
|
'user_id' => $role['user_id'],
|
|
|
|
|
'game_id' => ['in', $role['game_ids']],
|
|
|
|
|
'pay_time' => ['between', [strtotime($date . ' 00:00:00'), strtotime($date . ' 23:59:59')]]
|
|
|
|
|
];
|
|
|
|
|
$amount = M('spend', 'tab_')->where($map)->sum('pay_amount');
|
|
|
|
|
return floatval($amount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getRoleDailyAppliedAmount($role, $date)
|
|
|
|
|
{
|
|
|
|
|
$map = [
|
|
|
|
|
'review_status' => ['in', [0, 1]],
|
|
|
|
|
'role_id' => $role['role_id'],
|
|
|
|
|
'user_id' => $role['user_id'],
|
|
|
|
|
'base_game_id' => $role['base_game_id'],
|
|
|
|
|
'date' => $date,
|
|
|
|
|
'type' => 'J',
|
|
|
|
|
];
|
|
|
|
|
$amount = M('rebate_orders', 'tab_')->where($map)->sum('amount');
|
|
|
|
|
return floatval($amount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function propApply($params)
|
|
|
|
|
{
|
|
|
|
|
$baseGameId = $params['base_game_id'] ?? 0;
|
|
|
|
|
$roleId = $params['role_id'] ?? '';
|
|
|
|
|
$propIds = $params['prop_ids'] ?? [];
|
|
|
|
|
$date = date('Y-m-d');
|
|
|
|
|
|
|
|
|
|
if ($baseGameId == 0) {
|
|
|
|
|
throw new \Exception('请选择游戏');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (count($propIds) == 0) {
|
|
|
|
|
throw new \Exception('至少选择一项道具');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$baseGame = M('base_game', 'tab_')->where(['base_game_id' => $baseGameId])->find();
|
|
|
|
|
if (!$baseGame) {
|
|
|
|
|
throw new \Exception('游戏不存在');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$roleFields = ['user_id', 'user_account', 'game_id', 'role_id', 'role_name', 'server_id', 'server_name'];
|
|
|
|
|
$role = M('user_play_info', 'tab_')->field($roleFields)->where(['base_game_id' => $baseGameId, 'role_id' => $roleId])->find();
|
|
|
|
|
if (!$role) {
|
|
|
|
|
throw new \Exception('角色不存在');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$setting = M('rebate_times_setting', 'tab_')->where(['base_game_id' => $baseGameId, 'type' => 'J'])->find();
|
|
|
|
|
if (!$setting) {
|
|
|
|
|
throw new \Exception('未设定定制道具返利倍数');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$gameIds = [$baseGame['android_game_id'], $baseGame['ios_game_id']];
|
|
|
|
|
$role['game_ids'] = $gameIds;
|
|
|
|
|
$role['base_game_id'] = $baseGameId;
|
|
|
|
|
|
|
|
|
|
$dailyPayAmount = $this->getRoleDailyPayAmount($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) {
|
|
|
|
|
throw new \Exception('额度不足');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$applyProps = [];
|
|
|
|
|
foreach ($props as $prop) {
|
|
|
|
|
$applyProps[] = [
|
|
|
|
|
'ref_id' => $prop['ref_id'],
|
|
|
|
|
'value' => $prop['value'],
|
|
|
|
|
'num' => 1,
|
|
|
|
|
'name' => $prop['name']
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// $giftContent = implode('|', array_column($props, 'name'));
|
|
|
|
|
|
|
|
|
|
$record = [
|
|
|
|
|
'base_game_id' => $baseGame['id'],
|
|
|
|
|
'base_game_name' => $baseGame['name'],
|
|
|
|
|
'user_id' => $role['user_id'],
|
|
|
|
|
'user_account' => $role['user_account'],
|
|
|
|
|
'server_id' => $role['server_id'],
|
|
|
|
|
'server_name' => $role['server_name'],
|
|
|
|
|
'role_name' => $role['role_name'],
|
|
|
|
|
'role_id' => $role['role_id'],
|
|
|
|
|
'type' => 'J',
|
|
|
|
|
'award_date' => $date,
|
|
|
|
|
'amount' => $applyAmount,
|
|
|
|
|
'pay_amount' => $dailyPayAmount,
|
|
|
|
|
'gift_key' => '',
|
|
|
|
|
'gift_content' => '',
|
|
|
|
|
'props' => $applyProps,
|
|
|
|
|
'create_time' => time(),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// 是否自动审核
|
|
|
|
|
if (false) {
|
|
|
|
|
$record['review_type'] = 2;
|
|
|
|
|
$record['reviewer_id'] = 0;
|
|
|
|
|
$record['reviewer_username'] = '系统';
|
|
|
|
|
$record['review_status'] = 1;
|
|
|
|
|
$record['review_time'] = time();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
M('rebate_orders', 'tab_')->add($record);
|
|
|
|
|
}
|
|
|
|
|
}
|