You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

875 lines
31 KiB
PHTML

3 years ago
<?php
namespace Base\Service;
1 year ago
use Base\Tool\GameResource\JmxyClient;
1 year ago
use Base\Tool\GameResource\YjlyClient;
2 years ago
use Base\Tool\GameResource\ZzylClient;
3 years ago
use Think\Model;
3 years ago
class GameRebateService
{
public $sendStatusList = [
0 => '待发放',
1 => '发放成功',
2 => '发放异常',
];
public $reviewStatusList = [
0 => '待审核',
1 => '审核通过',
2 => '审核拒绝',
];
public $typeDisplayNames = [
'A' => '单笔充值福利',
'B' => '月卡福利发放',
'C' => '创角累充福利',
'D' => '首充福利发放',
'E' => '单日累充福利发放',
'F' => '周卡福利发放',
3 years ago
'G' => '首次进游福利',
'H' => '签到福利发放',
3 years ago
'I' => '充值返利发放',
'J' => '定制道具申请',
3 years ago
'K' => '新服七日礼包',
1 year ago
'L' => '等级福利发放',
];
public $typeNames = [
'A' => 'single',
'B' => 'daily',
'C' => 'accumulative',
'D' => 'firstPay',
'E' => 'dayAccumulative',
'F' => 'weekly',
3 years ago
'G' => 'newRole',
'H' => 'dailySign',
3 years ago
'I' => 'singleTimes',
3 years ago
'J' => 'propsApplication',
3 years ago
'K' => 'openSevenDay',
1 year ago
'L' => 'roleLevel',
];
1 year ago
public $rebateBaseGameIds = [11, 17, 21];
3 years ago
public function isGiftItemSend($order, $item)
{
// 每日发放奖励暂时通过send_status来判断是否第一次发放
3 years ago
if ($order['send_status'] == 1 && isset($item['once']) && $item['once']) {
return false;
}
return true;
}
public function sendByOrder($order, $handleDate = null)
3 years ago
{
3 years ago
$gift = null;
if ($order['gift_key']) {
1 year ago
$gift = M('rebate_gifts', 'tab_')
->where(['base_game_id' => $order['base_game_id'], 'type' => $order['type'], 'gift_key' => $order['gift_key'], 'group' => $order['gift_group']])->find();
3 years ago
}
1 year ago
$order['type_name'] = $this->typeDisplayNames[$order['type']] ?: '返利福利';
3 years ago
$hasError = false;
$sendResult = '';
3 years ago
if ($gift && $gift['game_currency'] > 0) {
$result = $this->sendGold($order, $gift['game_currency']);
3 years ago
if (!$result['status']) {
3 years ago
$hasError = true;
}
$sendResult .= ($result['message'] ?? '') . ';';
3 years ago
}
3 years ago
$index = 1;
3 years ago
$giftItems = $gift ? json_decode($gift['gifts'], true) : [];
foreach ($giftItems as $giftItem) {
3 years ago
$giftItem['index'] = $index;
$index ++;
if (!$this->isGiftItemSend($order, $giftItem)) {
continue;
}
$result = $this->sendGift($order, $giftItem);
3 years ago
if (!$result['status']) {
3 years ago
$hasError = true;
}
$sendResult .= ($result['message'] ?? '') . ';';
3 years ago
}
3 years ago
if ($order['props'] && $order['props'] != 'null') {
3 years ago
$result = $this->sendProps($order);
if (!$result['status']) {
$hasError = true;
}
$sendResult .= ($result['message'] ?? '') . ';';
}
$data = [
3 years ago
'send_status' => $hasError ? 2 : 1,
'send_time' => time(),
'send_result' => $sendResult,
];
if ($handleDate) {
$data['current_award_date'] = $handleDate;
}
M('rebate_orders', 'tab_')->where(['id' => $order['id']])->save($data);
3 years ago
}
private function getClient($baseGameId)
3 years ago
{
$client = null;
switch ($baseGameId) {
2 years ago
case 11:
$client = new ZzylClient();
3 years ago
break;
1 year ago
case 17:
1 year ago
$client = new JmxyClient();
break;
1 year ago
case 21:
$client = new YjlyClient();
break;
default:
throw new \Exception('客户端未实现');
break;
}
return $client;
3 years ago
}
public function sendGold($order, $gold)
3 years ago
{
$client = $this->getClient($order['base_game_id']);
return $client->sendGold($gold, $order);
3 years ago
}
public function sendGift($order, $giftItem)
3 years ago
{
$client = $this->getClient($order['base_game_id']);
return $client->sendEmail($giftItem, $order);
3 years ago
}
3 years ago
public function sendProps($order)
{
$client = $this->getClient($order['base_game_id']);
return $client->sendProps($order);
}
private function checkPropNumOfOrders($orders, $numMap)
{
$settings = M('rebate_times_setting', 'tab_')->where(['type' => 'I'])->select();
$settings = index_by_column('base_game_id', $settings);
foreach ($orders as $order) {
$setting = $settings[$order['base_game_id']] ?? null;
$maxTimes = $setting ? $setting['max_times'] : 0;
if ($numMap[$order['id']] > $maxTimes) {
throw new \Exception('返利倍数超过设定的最大值');
}
}
}
3 years ago
public function review(array $ids, $status, $handler)
3 years ago
{
if (!in_array($status, [1, 2])) {
throw new \Exception('状态异常');
}
if (count($ids) == 0) {
throw new \Exception('请选择要操作的记录');
}
3 years ago
$isSingleUpdate = is_array($ids[0]);
$numMap = [];
$idList = [];
if ($isSingleUpdate) {
foreach ($ids as $item) {
$idList[] = $item[0];
$numMap[$item[0]] = $item[1];
}
} else {
$idList = $ids;
}
$orders = M('rebate_orders', 'tab_')->where(['review_status' => 0, 'id' => ['in', $idList]])->select();
$orders = index_by_column('id', $orders);
if (count($orders) != count($idList)) {
3 years ago
throw new \Exception('含有不存在的记录或者已审核的记录');
}
3 years ago
$this->checkPropNumOfOrders($orders, $numMap);
$commonData = [
3 years ago
'review_type' => $handler['type'],
3 years ago
'review_status' => $status,
'review_time' => time(),
3 years ago
'reviewer_id' => $handler['id'],
'reviewer_username' => $handler['username'],
3 years ago
];
if ($isSingleUpdate) {
foreach ($ids as $item) {
$order = $orders[$item[0]];
$props = json_decode($order['props'], true);
foreach ($props as $key => $prop) {
$prop['num'] = $item[1];
$props[$key] = $prop;
}
$giftContent = $this->getGiftContentByProps($props);
M('rebate_orders', 'tab_')
->where(['review_status' => 0, 'id' => $item[0]])
->save(array_merge($commonData, [
'times' => $item[1],
'gift_content' => $giftContent,
'props' => json_encode($props)
]));
}
} else {
M('rebate_orders', 'tab_')->where(['review_status' => 0, 'id' => ['in', $idList]])->save($commonData);
}
3 years ago
}
public function sendOnce($type)
3 years ago
{
$orders = M('rebate_orders', 'tab_')->where(['type' => $type, 'review_status' => 1, 'send_status' => 0])->select();
foreach ($orders as $order) {
$this->sendByOrder($order);
}
}
public function sendDaily($type, $date)
3 years ago
{
$map = [
'type' => $type,
3 years ago
'review_status' => 1,
'award_started_at' => ['elt', $date],
'award_ended_at' => ['egt', $date],
'_string' => '(current_award_date is null or current_award_date < "' . $date . '")'
3 years ago
];
$orders = M('rebate_orders', 'tab_')->where($map)->select();
foreach ($orders as $order) {
$this->sendByOrder($order, $date);
}
}
public function listQuery($params, $awardType, $promote = null)
{
$isExport = $params['is_export'] ?? 0;
$page = $params['page'] ?? 0;
$limit = $params['limit'] ?? 0;
$baseGameId = $params['base_game_id'] ?? 0;
$serverId = $params['server_id'] ?? '';
$roleName = $params['role_name'] ?? '';
$userAccount = $params['user_account'] ?? '';
$reviewStatus = $params['review_status'] ?? -1;
$sendStatus = $params['send_status'] ?? -1;
$reviewerId = $params['reviewer_id'] ?? 0;
3 years ago
$reviewType = $params['review_type'] ?? -1;
$where = [
'_string' => '1=1',
];
$where['type'] = $awardType;
if ($baseGameId != 0) {
$where['base_game_id'] = $baseGameId;
}
if ($userAccount != '') {
$where['user_account'] = ['like', $userAccount . '%'];
}
if ($roleName != '') {
$where['role_name'] = ['like', $roleName . '%'];
}
if ($serverId != '') {
$where['server_id'] = $serverId;
3 years ago
}
if ($reviewStatus != -1) {
$where['review_status'] = $reviewStatus;
}
if ($sendStatus != -1) {
$where['send_status'] = $sendStatus;
}
if ($reviewerId != 0) {
$where['reviewer_id'] = $reviewerId;
}
3 years ago
if ($reviewType != -1) {
$where['review_type'] = $reviewType;
}
if (I('send_time_start', '') != '') {
$where['_string'] .= ' and send_time>=' . strtotime(I('send_time_start') . ' 00:00:00');
}
if (I('send_time_end', '') != '') {
$where['_string'] .= ' and send_time<=' . strtotime(I('send_time_end') . ' 23:59:59');
}
if (I('create_time_start', '') != '') {
$where['_string'] .= ' and create_time>=' . strtotime(I('create_time_start') . ' 00:00:00');
}
if (I('create_time_end', '') != '') {
$where['_string'] .= ' and create_time<=' . strtotime(I('create_time_end') . ' 23:59:59');
}
if ($promote) {
$promoteService = new PromoteService();
$subSql = M('user', 'tab_')->field(['id'])->where(['_string' => 'promote_id in(' . $promoteService->subInSql($promote) . ')'])->select(false);
$where['_string'] .= ' and user_id in(' . $subSql . ')';
}
$query = M('rebate_orders', 'tab_')->where($where);
$count = 0;
$records = [];
if ($isExport == 1 || $limit == 'all') {
$records = $query->order('create_time desc')->select();
$count = count($records);
} else {
$countQuery = clone $query;
$records = $query->order('create_time desc')->page($page, $limit)->select();
$count = $countQuery->count();
}
return [$records, $count];
}
public function listRange(array $records, $isExport = false)
{
$users = [];
if (count($records) > 0) {
$userIds = array_column($records, 'user_id');
$users = M('user', 'tab_')->field(['id', 'promote_account'])->where(['id' => ['in', $userIds]])->select();
$users = index_by_column('id', $users);
3 years ago
$settings = M('rebate_times_setting', 'tab_')->where(['type' => 'I'])->select();
$settings = index_by_column('base_game_id', $settings);
}
$newLine = $isExport == 1 ? "\n" : '<br/>';
foreach ($records as $key => $record) {
$user = $users[$record['user_id']];
3 years ago
$setting = $settings[$record['base_game_id']] ?? null;
$records[$key]['max_times'] = $setting ? $setting['max_times'] : 0;
$records[$key]['promote_account'] = $user['promote_account'];
$records[$key]['review_status_text'] = $this->reviewStatusList[$record['review_status']];
$records[$key]['review_time'] = $record['review_time'] > 0 ? date('Y-m-d H:i:s', $record['review_time']) : '--';
$records[$key]['send_status_text'] = $this->sendStatusList[$record['send_status']];
$records[$key]['send_time'] = $record['send_time'] > 0 ? date('Y-m-d H:i:s', $record['send_time']) : '--';
$records[$key]['create_time'] = $record['create_time'] > 0 ? date('Y-m-d H:i:s', $record['create_time']) : '--';
$records[$key]['award_date_range'] = is_null($record['award_started_at']) || is_null($record['award_ended_at'])
? '' : $record['award_started_at'] . ' ~ ' . $record['award_ended_at'];
$records[$key]['gift_content'] = implode($newLine, explode('|', $record['gift_content']));
}
return $records;
}
public function getExportHeadings($awardType)
{
$fields = [
'base_game_name' => '游戏名称',
'server_name' => '区服',
'user_account' => '账号',
'role_id' => '角色ID',
'role_name' => '角色名称',
3 years ago
'promote_account' => '所属推广员',
];
if ($awardType == 'A') {
$fields['pay_amount'] = '充值金额';
} elseif ($awardType == 'B') {
$fields['pay_amount'] = '当日累计充值金额';
$fields['award_date_range'] = '可领取福利日期';
} elseif ($awardType == 'C') {
$fields['amount'] = '达到档位金额';
} elseif ($awardType == 'D') {
$fields['pay_amount'] = '首充金额';
} elseif($awardType == 'E') {
$fields['pay_amount'] = '当日累计充值金额';
$fields['award_date'] = '达成日期';
} elseif($awardType == 'F') {
$fields['award_date_range'] = '可领取福利日期';
3 years ago
} elseif($awardType == 'H') {
$fields['award_date'] = '签到日期';
3 years ago
} elseif ($awardType == 'I') {
$fields['pay_amount'] = '充值金额';
$fields['times'] = '返利倍数';
} elseif($awardType == 'J') {
$fields['award_date'] = '达成日期';
$fields['pay_amount'] = '当日累充总额';
$fields['times'] = '返利倍数';
$fields['amount'] = '申请总价值';
3 years ago
} elseif ($awardType == 'K') {
$fields['pay_amount'] = '充值金额';
1 year ago
} elseif ($awardType == 'L') {
$fields['pay_amount'] = '当前等级';
$fields['mount'] = '奖励等级';
3 years ago
}
if ($awardType == 'J') {
$fields['gift_content'] = '申请道具';
} elseif($awardType == 'I') {
} else {
$fields['gift_content'] = '奖励内容';
}
$fields = array_merge($fields, [
'create_time' => '订单生成时间',
'review_status_text' => '审核状态',
'review_time' => '审核时间',
'send_status_text' => '发放状态',
'send_time' => '发放时间',
'reviewer_username' => '审核人',
]);
return $fields;
3 years ago
}
3 years ago
3 years ago
public function addSimulateSpend($params, $handler)
3 years ago
{
$baseGameId = $params['base_game_id'] ?? 0;
$roleId = $params['role_id'] ?? '';
$amount = $params['amount'] ?? 0;
$remark = $params['remark'] ?? '';
if ($baseGameId == 0) {
throw new \Exception('请选择游戏');
}
if ($roleId == 0) {
throw new \Exception('请输入角色ID');
}
if ($amount <= 0) {
throw new \Exception('金额必须大于0');
}
$baseGame = M('base_game', 'tab_')->where(['id' => $baseGameId])->find();
if ($baseGame == null) {
throw new \Exception('游戏不存在');
}
$gameIds = [$baseGame['android_game_id'], $baseGame['ios_game_id']];
$role = M('user_play_info', 'tab_')->where(['role_id' => $roleId, 'game_id' => ['in', $gameIds]])->find();
if ($role == null) {
throw new \Exception('角色不存在');
}
3 years ago
3 years ago
$data = [
'user_id' => $role['user_id'],
'user_account' => $role['user_account'],
'base_game_id' => $baseGame['id'],
'base_game_name' => $baseGame['name'],
'role_id' => $role['role_id'],
'role_name' => $role['role_name'],
'server_id' => $role['server_id'],
'server_name' => $role['server_name'],
3 years ago
'order_no' => 'SS_' . date('YmdHis') . getRandomPassword(4),
3 years ago
'create_time' => time(),
'amount' => $amount,
3 years ago
'remark' => $remark,
'creator_id' => $handler['id'],
'creator_username' => $handler['username'],
3 years ago
];
M('simulate_spend', 'tab_')->add($data);
}
public function reviewSimulateSpend(array $ids, $status, $handler)
{
if (!in_array($status, [1, 2])) {
throw new \Exception('状态异常');
}
if (count($ids) == 0) {
throw new \Exception('请选择要操作的记录');
}
$orders = M('simulate_spend', 'tab_')->field(['id'])->where(['review_status' => 0, 'id' => ['in', $ids]])->select();
if (count($orders) != count($ids)) {
throw new \Exception('含有不存在的记录或者已审核的记录');
}
M('simulate_spend', 'tab_')->where(['status' => 0, 'id' => ['in', $ids]])->save([
'status' => $status,
'review_time' => time(),
'reviewer_id' => $handler['id'],
'reviewer_username' => $handler['username'],
]);
}
3 years ago
public function deleteProp($id)
{
3 years ago
M('rebate_props', 'tab_')->where(['id' => $id])->delete();
3 years ago
}
public function batchDeleteProp($ids, $baseGameId)
{
3 years ago
M('rebate_props', 'tab_')->where(['id' => ['in', $ids], 'base_game_id' => $baseGameId])->delete();
3 years ago
}
public function saveProp($params)
{
$id = $params['id'] ?? 0;
$this->checkPropItem($params);
$prop = null;
if ($id > 0) {
3 years ago
$prop = M('rebate_props', 'tab_')->where(['id' => $id])->find();
3 years ago
if (!$prop) {
throw new \Exception('道具不存在');
}
}
$data = [
'ref_id' => $params['ref_id'],
'name' => $params['name'],
'value' => $params['value'],
'update_time' => time()
];
if ($id > 0) {
3 years ago
M('rebate_props', 'tab_')->where(['id' => $id])->save($data);
3 years ago
} else {
3 years ago
$data['base_game_id'] = $params['base_game_id'] ?? 0;
3 years ago
$data['create_time'] = time();
3 years ago
M('rebate_props', 'tab_')->add($data);
3 years ago
}
}
private function checkPropItem($prop)
{
3 years ago
$value = $prop['value'] ?? 0;
if (!isset($prop['value'])) {
3 years ago
throw new \Exception('缺少参数道具价值');
}
3 years ago
if (!isset($prop['name'])) {
3 years ago
throw new \Exception('缺少参数道具名称');
}
3 years ago
if (!isset($prop['ref_id'])) {
3 years ago
throw new \Exception('缺少参数道具ID');
}
3 years ago
if (!is_numeric($value) || $value < 0) {
3 years ago
throw new \Exception('道具价值必须为大于0的整数');
}
}
public function saveProps($baseGameId, $props)
{
3 years ago
if (count($props) == 0) {
throw new \Exception('道具项为0');
}
3 years ago
foreach ($props as $prop) {
$this->checkPropItem($prop);
3 years ago
}
$refIds = array_column($props, 'ref_id');
$existItems = M('rebate_props', 'tab_')->field(['ref_id'])->where(['base_game_id' => $baseGameId, 'ref_id' => ['in', $refIds]])->select();
$existItems = index_by_column('ref_id', $existItems);
$model = new Model();
$model->startTrans();
try {
$updateRecords = [];
$newRecords = [];
foreach ($props as $prop) {
$record = [
'base_game_id' => $baseGameId,
'ref_id' => $prop['ref_id'],
'name' => $prop['name'],
'value' => $prop['value'],
'update_time' => time()
];
if (isset($existItems[$prop['ref_id']])) {
$updateRecords[] = $record;
} else {
$record['create_time'] = time();
$newRecords[] = $record;
}
}
M('rebate_props', 'tab_')->addAll($newRecords);
foreach ($updateRecords as $record) {
M('rebate_props', 'tab_')->where(['base_game_id' => $baseGameId, 'ref_id' => $record['ref_id']])->save($record);
}
$model->commit();
} catch (\Exception $e) {
$model->rollback();
throw new \Exception('保存失败');
}
3 years ago
}
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('请选择游戏');
}
3 years ago
if (!is_numeric($defaultTimes)) {
throw new \Exception('默认倍数格式错误');
}
if (!is_numeric($maxTimes)) {
throw new \Exception('倍数上限格式错误');
}
$defaultTimes = intval($defaultTimes);
$maxTimes = intval($maxTimes);
if ($defaultTimes < 0) {
throw new \Exception('默认倍数需大于0');
}
if ($maxTimes < 0) {
throw new \Exception('倍数上限需大于0');
}
3 years ago
if ($defaultTimes > $maxTimes) {
throw new \Exception('默认倍数不能大于倍数上限');
}
3 years ago
3 years ago
$setting = M('rebate_times_setting', 'tab_')->where(['base_game_id' => $baseGameId, 'type' => $type])->find();
3 years ago
// $baseGame = M('base_game', 'tab_')->where(['id' => $baseGameId])->find();
3 years ago
$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)
{
3 years ago
$spendMap = [
3 years ago
'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')]]
];
3 years ago
$payAmount = M('spend', 'tab_')->where($spendMap)->sum('pay_amount');
$simulateMap = [
'status' => 1,
'role_id' => $role['role_id'],
'user_id' => $role['user_id'],
'base_game_id' => $role['base_game_id'],
'review_time' => ['between', [strtotime($date . ' 00:00:00'), strtotime($date . ' 23:59:59')]]
];
$simulateAmount = M('simulate_spend', 'tab_')->where($simulateMap)->sum('amount');
return floatval($payAmount) + floatval($simulateAmount);
3 years ago
}
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);
}
3 years ago
public function propsApply($params, $handler = null)
3 years ago
{
$baseGameId = $params['base_game_id'] ?? 0;
$roleId = $params['role_id'] ?? '';
3 years ago
$propItems = $params['props'] ?? [];
3 years ago
$date = $params['date'] ?? '';
3 years ago
if ($baseGameId == 0) {
throw new \Exception('请选择游戏');
}
3 years ago
if ($date == '') {
throw new \Exception('请选择日期');
}
if (count($propItems) == 0) {
3 years ago
throw new \Exception('至少选择一项道具');
}
3 years ago
$baseGame = M('base_game', 'tab_')->where(['id' => $baseGameId])->find();
3 years ago
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('未设定定制道具返利倍数');
}
3 years ago
$props = M('rebate_props', 'tab_')->where(['id' => ['in', array_column($propItems, 'id')], 'base_game_id' => $baseGameId])->select();
3 years ago
$props = index_by_column('id', $props);
$applyAmount = 0;
3 years ago
$applyProps = [];
3 years ago
foreach ($propItems as $item) {
if (isset($props[$item['id']])) {
3 years ago
$prop = $props[$item['id']];
3 years ago
$applyAmount += ($prop['value'] * $item['num']);
3 years ago
$applyProps[] = [
'ref_id' => $prop['ref_id'],
'value' => $prop['value'],
'num' => $item['num'],
'name' => $prop['name']
];
3 years ago
} else {
throw new \Exception('道具不存在');
}
}
3 years ago
$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);
if ($dailyPayAmount * $setting['max_times'] - $applyAmount - $appliedAmount < 0) {
throw new \Exception('额度不足');
}
$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,
3 years ago
'gift_key' => 'J-0',
'gift_content' => $this->getGiftContentByProps($applyProps),
3 years ago
'props' => json_encode($applyProps, JSON_UNESCAPED_UNICODE),
3 years ago
'times' => $setting['max_times'],
3 years ago
'create_time' => time(),
];
3 years ago
if ($handler) {
$record['creator_id'] = $handler['id'];
$record['creator_username'] = $handler['username'];
$record['creator_type'] = $handler['type'];
}
3 years ago
// 是否自动审核
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);
}
3 years ago
private function getGiftContentByProps($props)
{
$items = [];
foreach ($props as $prop) {
$items[] = $prop['name'] . '*' . $prop['num'];
}
return implode('|', $items);
}
public function getRebateBaseGames()
{
return M('base_game', 'tab_')->where(['id' => ['in', $this->rebateBaseGameIds]])->select();
}
public function getRoleInfo($params, $permPromote = null)
{
$baseGameId = $params['base_game_id'] ?? 0;
$roleId = $params['role_id'] ?? '';
$date = $params['date'] ?? '';
$baseGame = M('base_game', 'tab_')->where(['id' => $baseGameId])->find();
if (!$baseGame) {
throw new \Exception('游戏不存在');
}
$gameIds = [$baseGame['android_game_id'] , $baseGame['ios_game_id']];
$roleStr = '1=1';
if ($permPromote != null) {
$promoteService = new PromoteService();
$roleStr .= ' and promote_id in (' . $promoteService->subInSql($permPromote) . ')';
}
$role = M('user_play_info', 'tab_')->where(['game_id' => ['in', $gameIds], 'role_id' => $roleId, '_string' => $roleStr])->order('play_time', 'desc')->limit(1)->find();
if (!$role) {
throw new \Exception('角色不存在');
}
$spendMap = ['game_id' => ['in', $gameIds], 'game_player_id' => $roleId, 'pay_status' => 1, 'user_id' => $role['user_id']];
$simulateMap = ['base_game_id' => $baseGameId, 'role_id' => $roleId, 'status' => 1, 'user_id' => $role['user_id']];
if ($date) {
$spendMap['pay_time'] = ['between', [strtotime($date . ' 00:00:00'), strtotime($date . ' 23:59:59')]];
$simulateMap['review_time'] = ['between', [strtotime($date . ' 00:00:00'), strtotime($date . ' 23:59:59')]];
}
$payAmount = M('spend', 'tab_')->where($spendMap)->sum('pay_amount');
$payAmount = floatval($payAmount);
$simulateAmount = M('simulate_spend', 'tab_')->where($simulateMap)->sum('amount');
$simulateAmount = floatval($simulateAmount);
$data = [
'server_name' => $role['server_name'],
'role_name' => $role['role_name'],
'pay_amount' => $payAmount,
'simulate_amount' => $simulateAmount
];
if ($date) {
$setting = M('rebate_times_setting', 'tab_')->where(['base_game_id' => $baseGameId, 'type' => 'J'])->find();
if (!$setting) {
throw new \Exception('返利倍数未设置');
}
$totalQuota = intval(($payAmount + $simulateAmount) * $setting['max_times']);
$appliedQuota = M('rebate_orders', 'tab_')
->where(['base_game_id' => $baseGameId, 'type' => 'J', 'role_id' => $roleId, 'award_date' => $date, 'review_status' => ['in', [0, 1]]])
->sum('amount');
$appliedQuota = intval($appliedQuota);
$remainQuota = $totalQuota - $appliedQuota;
$data = array_merge($data,
[
'applied_quota' => $appliedQuota,
'remain_quota' => $remainQuota,
'total_quota' => $totalQuota,
'max_times' => $setting['max_times'],
]
);
}
return $data;
}
3 years ago
}