道具返利等

master
elf 3 years ago
parent eb7a9f6390
commit ffc5412c37

@ -353,4 +353,146 @@ class GameRebateController extends ThinkController
]);
}
}
private function propsQuery($params)
{
$isExport = $params['export'] ?? 0;
$page = $params['page'] ?? 0;
$limit = $params['limit'] ?? 0;
$baseGameId = $params['base_game_id'] ?? 0;
$refId = $params['refId'] ?? '';
$name = $params['name'] ?? '';
$where = [
'_string' => '1=1',
];
if ($baseGameId != 0) {
$where['base_game_id'] = $baseGameId;
}
if ($refId) {
$where['ref_id'] = $refId;
}
if ($name != '') {
$where['name'] = ['like', '%' . $name . '%'];
}
$query = M('rebate_props', '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 props()
{
$params = I('get.');
$baseGameId = $params['base_game_id'] ?? 0;
$isExport = $params['export'] ?? 0;
$records = [];
$count = 0;
$baseGame = null;
$setting = null;
if ($baseGameId > 0) {
$baseGame = M('base_game', 'tab_')->where(['id' => $baseGameId])->find();
$setting = M('rebate_times_setting', 'tab_')->where(['base_game_id' => $baseGameId, 'type' => 'J'])->find();
[$records, $count] = $this->propsQuery($params);
} else {
return $this->error('请选择游戏搜索');
}
if (count($records) > 0) {
if ($isExport) {
$field = [
'ref_id' => '道具ID',
'name' => '道具名称',
'num' => '道具数量',
'value' => '道具价值',
];
addOperationLog(['op_type'=>3,'key'=>getNowDate(),'op_name'=>'导出定制道具记录','url'=>U('GameRebate/props'),'menu'=>'推广员-发放福利管理-' . '定制道具记录']);
data2csv($records, $baseGame['name'] . '-定制道具记录', $field);
exit;
}
}
$page = set_pagination($count, $params['limit'] == 'all' ? 99999999 : $params['limit']);
if($page) {
$this->assign('_page', $page);
}
$this->assign('records', $records);
$this->assign('setting', $setting);
$this->display('props');
}
public function timesSettings()
{
$params = I('get.');
$isExport = $params['export'] ?? 0;
$baseGameId = $params['base_game_id'] ?? 0;
$page = $params['page'] ?? 0;
$limit = $params['limit'] ?? 0;
$type = $params['type'] ?? '';
$where = [
'_string' => '1=1',
];
if ($baseGameId != 0) {
$where['base_game_id'] = $baseGameId;
}
if ($type) {
$where['type'] = $type;
}
$query = M('rebate_times_setting', '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();
}
if (count($records) > 0) {
if ($isExport) {
$field = [
'base_game_name' => '游戏名称',
'max_times' => '倍数上限',
];
$menuName = '';
if ($type == 'J') {
$menuName = '定制道具功';
} else {
$menuName = '游戏倍数设置';
$field['default_times'] = '默认倍数';
}
addOperationLog(['op_type'=>3,'key'=>getNowDate(),'op_name'=>'导出' . $menuName,'url'=>U('GameRebate/props'),'menu'=>'推广员-发放福利管理-' . $$menuName]);
data2csv($records, $menuName, $field);
exit;
}
}
$page = set_pagination($count, $params['limit'] == 'all' ? 99999999 : $params['limit']);
$baseGames = M('base_game', 'tab_')->select();
if($page) {
$this->assign('_page', $page);
}
$this->assign('baseGames', $baseGames);
$this->assign('records', $records);
$this->display('props');
}
}

@ -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);
}
}

@ -26,6 +26,7 @@ class XlqyClient
private $apis = [
'send-email' => ['uri' => '/apip/payWM450S00/emRebate', 'method' => 'post'],
'send-testing' => ['uri' => '/apip/payWM450S00/testingOrder', 'method' => 'post'],
'send-props' => ['uri' => '', 'method' => 'post'],
];
public function __construct()
@ -129,6 +130,18 @@ class XlqyClient
$params['time'] .
self::SIGN_KEY
);
} elseif ($name == 'send-props') {
$signStr = '';
ksort($data);
foreach ($data as $key => $value) {
if ($key == 'prop') {
$value = json_encode($value);
}
$signStr .= $key . '='. trim(urlencode($value)) . '&';
}
$signStr .= 'key=' . self::SIGN_KEY;
$signStr = md5($signStr);
return $signStr;
} else {
return '';
}
@ -150,6 +163,36 @@ class XlqyClient
return $this->getCommonResult($result);
}
public function sendProps($order)
{
$props = [];
$order['props'] = json_decode($order['props'], true);
foreach ($order['props'] as $prop) {
$props[] = [
'goods_id' => $prop['ref_id'],
'quantity' => $prop['num'],
];
}
/**
* @todo
*/
$data = [
'mailtitle' => '请查收',
'mailcontent' => '道具发放',
'uid' => $order['user_id'],
'server_id' => $order['server_id'],
'time' => date('Y-m-d H:i:s'),
'role_id' => $order['role_id'],
'appId' => self::APP_ID,
'totalprice' => $order['amount'],
'prop' => $props,
'price' => '', // ??
'buytype' => '', // ??
];
$result = $this->api('send-props', $data);
return $this->getCommonResult($result, 200);
}
private function generateOrderNumber($order, $index = 0)
{
$length = 8 - strlen(strval($order['id']));
@ -157,9 +200,9 @@ class XlqyClient
return date('Ymd') . str_repeat('0', $length) . $order['id'] . str_repeat('0', $indexLength) . $index;
}
private function getCommonResult($result)
private function getCommonResult($result, $successCode = 0)
{
if ($result['code'] == 0) {
if ($result['code'] == $successCode) {
return [
'status' => true,
'message' => $result['msg'],

Loading…
Cancel
Save