游戏返利
parent
05dd251fec
commit
0ea585bd96
@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
namespace Admin\Controller;
|
||||
|
||||
use Base\Repository\GameRepository;
|
||||
use Base\Service\GameRebateService;
|
||||
use User\Api\UserApi as UserApi;
|
||||
use Base\Service\PresidentDepositService;
|
||||
|
||||
/**
|
||||
* 游戏返利
|
||||
*/
|
||||
class GameRebateController extends ThinkController
|
||||
{
|
||||
public function single()
|
||||
{
|
||||
$this->records('A');
|
||||
}
|
||||
|
||||
public function accumulative()
|
||||
{
|
||||
$this->records('C');
|
||||
}
|
||||
|
||||
public function daily()
|
||||
{
|
||||
$this->records('B');
|
||||
}
|
||||
|
||||
public function records($awardType)
|
||||
{
|
||||
$page = I('p', 1);
|
||||
$row = I('row', 10);
|
||||
$baseGameId = I('base_game_id', 0);
|
||||
$serverId = I('server_id', '');
|
||||
$roleName = I('role_name', '');
|
||||
$userAccount = I('user_account', '');
|
||||
$reviewStatus = I('review_status', -1);
|
||||
$sendStatus = I('send_status', -1);
|
||||
$reviewerId = I('reviewer_id', 0);
|
||||
|
||||
$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;
|
||||
}
|
||||
if ($reviewStatus != -1) {
|
||||
$where['review_status'] = $reviewStatus;
|
||||
}
|
||||
if ($sendStatus != -1) {
|
||||
$where['send_status'] = $sendStatus;
|
||||
}
|
||||
if ($reviewerId != 0) {
|
||||
$where['reviewer_id'] = $reviewerId;
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
$query = M('rebate_orders', 'tab_')->where($where);
|
||||
|
||||
$records = [];
|
||||
if (I('export', 0) == 1 || $row == 'all') {
|
||||
$records = $query->select();
|
||||
} else {
|
||||
$countQuery = clone $query;
|
||||
$records = $query->page($page, $row)->select();
|
||||
$count = $countQuery->count();
|
||||
}
|
||||
|
||||
$sendStatusList = [
|
||||
0 => '待发放',
|
||||
1 => '发放成功',
|
||||
2 => '发放异常',
|
||||
];
|
||||
|
||||
$reviewStatusList = [
|
||||
0 => '待审核',
|
||||
1 => '审核通过',
|
||||
2 => '审核拒绝',
|
||||
];
|
||||
|
||||
$pageTitles = [
|
||||
'A' => '单笔充值福利',
|
||||
'B' => '月卡福利发放',
|
||||
'C' => '累充福利发放',
|
||||
];
|
||||
$pageTitle = $pageTitles[$awardType];
|
||||
if (count($records) > 0) {
|
||||
foreach ($records as $key => $record) {
|
||||
$records[$key]['review_status_text'] = $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'] = $sendStatusList[$record['send_status']];
|
||||
$records[$key]['send_time'] = $record['send_time'] > 0 ? date('Y-m-d H:i:s', $record['send_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('<br/>', explode('|', $record['gift_content']));
|
||||
}
|
||||
if (I('export', 0) == 1) {
|
||||
$field = [
|
||||
'base_game_name' => '游戏名称',
|
||||
'server_name' => '区服',
|
||||
'user_account' => '账号',
|
||||
'role_id' => '角色ID',
|
||||
'role_name' => '角色名称',
|
||||
'pay_amount' => '充值金额',
|
||||
'gift_content' => '奖励内容',
|
||||
'review_status_text' => '审核状态',
|
||||
'review_time' => '审核时间',
|
||||
'send_status_text' => '发放状态',
|
||||
'send_time' => '发放时间',
|
||||
'reviewer_username' => '审核人',
|
||||
];
|
||||
|
||||
addOperationLog(['op_type'=>3,'key'=>getNowDate(),'op_name'=>'导出' . $pageTitle . '记录','url'=>U('GameRebate/records'),'menu'=>'推广员-发放福利管理-' . '导出' . $pageTitle . '记录']);
|
||||
|
||||
data2csv($records, $pageTitle, $field);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$page = set_pagination($count, $row == 'all' ? 99999999 : $row);
|
||||
|
||||
if($page) {
|
||||
$this->assign('_page', $page);
|
||||
}
|
||||
|
||||
$admins = M('ucenter_member', 'sys_')->field(['id', 'username'])->select();
|
||||
$baseGames = M('base_game', 'tab_')->select();
|
||||
|
||||
$gameRepository = new GameRepository();
|
||||
$this->assign('pageTitle', $pageTitle);
|
||||
$this->assign('awardType', $awardType);
|
||||
$this->assign('servers', $gameRepository->getServersByBaseGameId($baseGameId));
|
||||
$this->assign('admins', $admins);
|
||||
$this->assign('baseGames', $baseGames);
|
||||
$this->assign('sendStatusList', $sendStatusList);
|
||||
$this->assign('reviewStatusList', $reviewStatusList);
|
||||
$this->assign('records', $records);
|
||||
$this->display('records');
|
||||
}
|
||||
|
||||
public function review()
|
||||
{
|
||||
$ids = I('ids', []);
|
||||
$status = I('status', 0);
|
||||
try {
|
||||
$service = new GameRebateService();
|
||||
$service->review($ids, $status);
|
||||
$this->ajaxReturn([
|
||||
'status' => 1,
|
||||
'message' => '操作成功'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
$this->ajaxReturn([
|
||||
'status' => 0,
|
||||
'message' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getServers()
|
||||
{
|
||||
$gameId = I('game_id', 0);
|
||||
$gameRepository = new GameRepository();
|
||||
$servers = $gameRepository->getServersByBaseGameId($gameId);
|
||||
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['servers' => $servers]]);
|
||||
}
|
||||
}
|
@ -0,0 +1,137 @@
|
||||
<?php
|
||||
namespace Base\Service;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
class GameRebateService
|
||||
{
|
||||
const SIGN_KEY = 'Eza65532qaOIAAWasdq962aqweasd';
|
||||
|
||||
private function getClient()
|
||||
{
|
||||
return new Client([
|
||||
'base_uri' => 'http://rebate.99you.cn/xyy_apply.php/23400/',
|
||||
'timeout' => 10.0,
|
||||
]);
|
||||
}
|
||||
|
||||
public function sendByOrder($order)
|
||||
{
|
||||
$gift = M('rebate_gifts', 'tab_')->where(['type' => $order['type'], 'gift_key' => $order['gift_key']])->find();
|
||||
$hasError = false;
|
||||
$sendResult = '';
|
||||
if ($gift['game_currency'] > 0) {
|
||||
$result = $this->sendCurrency($order['server_id'], $order['role_id'], $gift['game_currency']);
|
||||
if ($result['code'] != 1) {
|
||||
$hasError = true;
|
||||
}
|
||||
$sendResult .= ($result['msg'] ?? '');
|
||||
$sendResult .= ';';
|
||||
}
|
||||
if ($gift['gift_id'] > 0) {
|
||||
$result = $this->sendGift($order['server_id'], $order['role_id'], $gift['gift_id']);
|
||||
if ($result['code'] != 1) {
|
||||
$hasError = true;
|
||||
}
|
||||
$sendResult .= ($result['msg'] ?? '');
|
||||
}
|
||||
M('rebate_orders', 'tab_')->where(['id' => $order['id']])->save([
|
||||
'send_status' => $hasError ? 2 : 1,
|
||||
'send_time' => time(),
|
||||
'send_result' => $sendResult,
|
||||
]);
|
||||
}
|
||||
|
||||
public function sendCurrency($serverId, $roleId, $currency)
|
||||
{
|
||||
$sign = md5($currency.$serverId.$roleId.self::SIGN_KEY);
|
||||
$params = [
|
||||
'act' => 'sendgold',
|
||||
'serverid' => $serverId,
|
||||
'role_id' => $roleId,
|
||||
'money' => $currency,
|
||||
'sign' => $sign
|
||||
];
|
||||
return $this->get('', $params);
|
||||
}
|
||||
|
||||
public function sendGift($serverId, $roleId, $giftId)
|
||||
{
|
||||
$sign = md5($giftId.$serverId.$roleId.self::SIGN_KEY);
|
||||
$params = [
|
||||
'act' => 'send_email',
|
||||
'serverid' => $serverId,
|
||||
'role_id' => $roleId,
|
||||
'prop_id' => $giftId,
|
||||
'sign' => $sign
|
||||
];
|
||||
return $this->get('', $params);
|
||||
}
|
||||
|
||||
protected function get($uri, array $params = [])
|
||||
{
|
||||
try {
|
||||
$response = $this->getClient()->get($uri, [
|
||||
'verify' => false,
|
||||
'query' => $params,
|
||||
]);
|
||||
$result = (string)$response->getBody();
|
||||
return json_decode($result, true);
|
||||
} catch (\Exception $e) {
|
||||
return [
|
||||
'code' => 3,
|
||||
'msg' => '网络异常:' . $e->getMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function review(array $ids, $status)
|
||||
{
|
||||
if (!in_array($status, [1, 2])) {
|
||||
throw new \Exception('状态异常');
|
||||
}
|
||||
if (count($ids) == 0) {
|
||||
throw new \Exception('请选择要操作的记录');
|
||||
}
|
||||
$orders = M('rebate_orders', 'tab_')->field(['id'])->where(['review_status' => 0, 'id' => ['in', $ids]])->select();
|
||||
if (count($orders) != count($ids)) {
|
||||
throw new \Exception('含有不存在的记录或者已审核的记录');
|
||||
}
|
||||
|
||||
$adminInfo = $_SESSION['onethink_admin']['user_auth'];
|
||||
M('rebate_orders', 'tab_')->where(['review_status' => 0, 'id' => ['in', $ids]])->save([
|
||||
'review_status' => $status,
|
||||
'review_time' => time(),
|
||||
'reviewer_id' => $adminInfo['uid'],
|
||||
'reviewer_username' => $adminInfo['username'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function sendAll($type)
|
||||
{
|
||||
$orders = M('rebate_orders', 'tab_')->where(['type' => $type, 'review_status' => 1, 'send_status' => 0])->select();
|
||||
foreach ($orders as $order) {
|
||||
if ($type == 'B') {
|
||||
if (time() < strtotime($order['award_started_at'] . ' 00:00:00') || time() > strtotime($order['award_ended_at'] . ' 23:59:59')) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$this->sendByOrder($order);
|
||||
}
|
||||
}
|
||||
|
||||
public function sendDaily($date)
|
||||
{
|
||||
$map = [
|
||||
'type' => 'B',
|
||||
'review_status' => 1,
|
||||
'send_status' => 1,
|
||||
'award_started_at' => ['elt', $date],
|
||||
'award_ended_at' => ['egt', $date]
|
||||
];
|
||||
$orders = M('rebate_orders', 'tab_')->where($map)->select();
|
||||
foreach ($orders as $order) {
|
||||
$this->sendByOrder($order);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace Base\Tool\GameResource;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
|
||||
/**
|
||||
* 逍遥游之仙魔降世-测试资源接口
|
||||
*/
|
||||
class XyyClient
|
||||
{
|
||||
const SIGN_NAME = 'sign';
|
||||
const SUCCESS = '0000';
|
||||
|
||||
const KEY = '6c9VLnZFlhEppATKKWeH5vV900K6Nhy5';
|
||||
|
||||
protected $client;
|
||||
|
||||
private $apis = [
|
||||
'provide' => ['uri' => '/', 'method' => 'get'],
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->client = new Client([
|
||||
'base_uri' => 'http://rebate.99you.cn/wdzx_apply.php/23399',
|
||||
'timeout' => 10.0,
|
||||
]);
|
||||
}
|
||||
|
||||
public function api($api, array $params = [])
|
||||
{
|
||||
$api = $this->apis[$api] ?? null;
|
||||
if (is_null($api)) {
|
||||
throw new \Exception('接口不存在');
|
||||
}
|
||||
$params[self::SIGN_NAME] = $this->sign($params);
|
||||
try {
|
||||
return $this->request($api, $params);
|
||||
} catch (\Exception $e) {
|
||||
$env = C('APP_ENV', null, 'prod');
|
||||
return ['code' => 3, 'msg' => '接口请求错误。' . ($env == 'prod' ? '' : $e->getMessage()) , 'data' => []];
|
||||
}
|
||||
}
|
||||
|
||||
public function request($api, $params)
|
||||
{
|
||||
if ($api['method'] == 'get') {
|
||||
return $this->get($api['uri'], $params);
|
||||
} else {
|
||||
return $this->post($api['uri'], $params);
|
||||
}
|
||||
}
|
||||
|
||||
protected function post($uri, array $params = [])
|
||||
{
|
||||
$response = $this->client->post($uri, [
|
||||
'verify' => false,
|
||||
'form_params' => $params,
|
||||
]);
|
||||
$result = (string)$response->getBody();
|
||||
return json_decode($result, true);
|
||||
}
|
||||
|
||||
protected function get($uri, array $params = [])
|
||||
{
|
||||
$response = $this->client->get($uri, [
|
||||
'verify' => false,
|
||||
'query' => $params,
|
||||
]);
|
||||
$result = (string)$response->getBody();
|
||||
return json_decode($result, true);
|
||||
}
|
||||
|
||||
protected function sign($params)
|
||||
{
|
||||
return md5($params['orderid'] . $params['serverid'] . $params['role_id'] . self::KEY);
|
||||
}
|
||||
|
||||
public function apply($order, $role)
|
||||
{
|
||||
$data = [
|
||||
'role_id' => $role['role_id'],
|
||||
'serverid' => $role['server_id'],
|
||||
'amount' => $order['ref_amount'],
|
||||
// 'money' => intval($order['ref_amount']) * 10,
|
||||
'orderid' => $order['order_no'],
|
||||
];
|
||||
|
||||
$result = $this->api('provide', $data);
|
||||
if ($result['code'] == 1) {
|
||||
return [
|
||||
'status' => true,
|
||||
'message' => $result['msg'],
|
||||
'result' => $result
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'status' => false,
|
||||
'message' => $result['msg'],
|
||||
'result' => $result
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function getResourceTypes($deviceType)
|
||||
{
|
||||
if ($deviceType == 'andriod') {
|
||||
return [['id' => 1, 'name' => '通用', 'device_type' => 'andriod']];
|
||||
} elseif ($deviceType == 'ios') {
|
||||
return [['id' => 2, 'name' => '通用', 'device_type' => 'ios']];
|
||||
}
|
||||
}
|
||||
|
||||
public function getResources($typeId, $deviceType)
|
||||
{
|
||||
return [
|
||||
1 => ['ref_id' => 1, 'name' => '60元宝', 'amount' => 6],
|
||||
2 => ['ref_id' => 2, 'name' => '300元宝', 'amount' => 30],
|
||||
3 => ['ref_id' => 3, 'name' => '980元宝', 'amount' => 98],
|
||||
4 => ['ref_id' => 4, 'name' => '1280元宝', 'amount' => 128],
|
||||
5 => ['ref_id' => 5, 'name' => '1980元宝', 'amount' => 198],
|
||||
6 => ['ref_id' => 6, 'name' => '3280元宝', 'amount' => 328],
|
||||
7 => ['ref_id' => 7, 'name' => '6480元宝', 'amount' => 648],
|
||||
8 => ['ref_id' => 8, 'name' => '10000元宝', 'amount' => 1000],
|
||||
9 => ['ref_id' => 9, 'name' => '20000元宝', 'amount' => 2000],
|
||||
10 => ['ref_id' => 10, 'name' => '30000元宝', 'amount' => 3000],
|
||||
11 => ['ref_id' => 11, 'name' => '50000元宝', 'amount' => 5000],
|
||||
12 => ['ref_id' => 12, 'name' => '100000元宝', 'amount' => 10000],
|
||||
13 => ['ref_id' => 13, 'name' => '200000元宝', 'amount' => 20000],
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue