玄灵契约返利
parent
5f6c10bcc1
commit
d188bb9072
@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
namespace Base\Tool\GameResource;
|
||||
|
||||
use Base\Tool\Log;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
|
||||
/**
|
||||
* 玄灵契约-测试资源接口
|
||||
*/
|
||||
class XlqyClient
|
||||
{
|
||||
const SIGN_NAME = 'sign';
|
||||
const SUCCESS = '0000';
|
||||
|
||||
const APP_ID = 'FD32BDA67D6024D71';
|
||||
const SIGN_KEY = 'FzYrrm23eN8sMkomGiHM0QG2Uvk8uAPw';
|
||||
|
||||
// const APP_ID = '77A38AE4C5CAD6756'; // IOS
|
||||
// const SIGN_KEY = 'rKkoznJcEhWaVPSuBnH1QnC9goDd4TcB'; // IOS
|
||||
|
||||
protected $client;
|
||||
|
||||
private $apis = [
|
||||
'send-email' => ['uri' => '', 'method' => 'post'],
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->client = new Client([
|
||||
'base_uri' => 'http://xx2api.hnputihd.com/apip/payWM450S00/emRebate',
|
||||
'timeout' => 10.0,
|
||||
]);
|
||||
}
|
||||
|
||||
public function api($name, array $params = [])
|
||||
{
|
||||
$api = $this->apis[$name] ?? null;
|
||||
if (is_null($api)) {
|
||||
throw new \Exception('接口不存在');
|
||||
}
|
||||
$params[self::SIGN_NAME] = $this->sign($name, $params);
|
||||
try {
|
||||
return $this->request($api, $params);
|
||||
} catch (\Exception $e) {
|
||||
$env = C('APP_ENV', null, 'prod');
|
||||
Log::error('rebate:XLQY ' . $e->getMessage());
|
||||
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();
|
||||
Log::info('rebate:XLQY ' . $uri . ' -- '. json_encode($params) . ' -- '. $result);
|
||||
return json_decode($result, true);
|
||||
}
|
||||
|
||||
protected function get($uri, array $params = [])
|
||||
{
|
||||
$response = $this->client->get($uri, [
|
||||
'verify' => false,
|
||||
'query' => $params,
|
||||
]);
|
||||
$result = (string)$response->getBody();
|
||||
Log::info('rebate:XLQY ' . $uri . ' -- '. json_encode($params) . ' -- '. $result);
|
||||
return json_decode($result, true);
|
||||
}
|
||||
|
||||
protected function sign($name, $params)
|
||||
{
|
||||
if ($name == 'send-email') {
|
||||
return md5(
|
||||
$params['appId'] .
|
||||
$params['orderNum'] .
|
||||
$params['userId'] .
|
||||
$params['mailId'] .
|
||||
$params['serviceId'] .
|
||||
$params['roleId'] .
|
||||
$params['time'] .
|
||||
self::SIGN_KEY
|
||||
);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
public function sendEmail($giftItem, $order)
|
||||
{
|
||||
$data = [
|
||||
'appId' => self::APP_ID,
|
||||
'userId' => $order['user_id'],
|
||||
'serviceId' => $order['server_id'],
|
||||
'roleId' => $order['role_id'],
|
||||
'mailId' => $giftItem['id'],
|
||||
'orderNum' => $this->generateOrderNumber($order),
|
||||
'time' => time(),
|
||||
];
|
||||
|
||||
$result = $this->api('send-email', $data);
|
||||
return $this->getCommonResult($result);
|
||||
}
|
||||
|
||||
private function generateOrderNumber($order)
|
||||
{
|
||||
$length = 8 - strlen(strval($order['id']));
|
||||
return date('Ymd') . str_repeat('0', $length) . $order['id'];
|
||||
}
|
||||
|
||||
private function getCommonResult($result)
|
||||
{
|
||||
if ($result['code'] == 0) {
|
||||
return [
|
||||
'status' => true,
|
||||
'message' => $result['msg'],
|
||||
'result' => $result
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'status' => false,
|
||||
'message' => $result['msg'],
|
||||
'result' => $result
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo 暂时没有测试资源
|
||||
*/
|
||||
public function apply($order, $role)
|
||||
{
|
||||
return $this->sendEmail($order['ref_amount'], $role);
|
||||
}
|
||||
|
||||
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],
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Home\Controller;
|
||||
|
||||
use Base\Model\PromoteModel;
|
||||
use Base\Service\PromoteService;
|
||||
use OSS\Core\OssException;
|
||||
use Think\Model;
|
||||
use Base\Service\TestingResourceService;
|
||||
use Base\Repository\TestingResourceRepository;
|
||||
use Base\Repository\GameRepository;
|
||||
use Base\Service\GameRebateService;
|
||||
use Base\Service\GameService;
|
||||
|
||||
class GameRebateController extends BaseController
|
||||
{
|
||||
protected function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
|
||||
$loginPromote = $this->getLoginPromote();
|
||||
if ($loginPromote['rebate_over_perm'] == 0) {
|
||||
return $this->error('无权限操作');
|
||||
}
|
||||
}
|
||||
|
||||
public function single()
|
||||
{
|
||||
$this->records('A');
|
||||
}
|
||||
|
||||
public function accumulative()
|
||||
{
|
||||
$this->records('C');
|
||||
}
|
||||
|
||||
public function daily()
|
||||
{
|
||||
$this->records('B');
|
||||
}
|
||||
|
||||
public function firstPay()
|
||||
{
|
||||
$this->records('D');
|
||||
}
|
||||
|
||||
public function dayAccumulative()
|
||||
{
|
||||
$this->records('E');
|
||||
}
|
||||
|
||||
public function weekly()
|
||||
{
|
||||
$this->records('F');
|
||||
}
|
||||
|
||||
public function records($awardType)
|
||||
{
|
||||
$promoteService = new PromoteService();
|
||||
$loginPromote = $this->getLoginPromote();
|
||||
$permPromote = $promoteService->getTopPromote($loginPromote);
|
||||
|
||||
$params = I('get.');
|
||||
$params['is_export'] = ($params['export'] ?? 0);
|
||||
$params['page'] = ($params['p'] ?? 1);
|
||||
$params['limit'] = ($params['row'] ?? 10);
|
||||
|
||||
$baseGameId = $params['base_game_id'] ?? 0;
|
||||
$isExport = $params['is_export'] == 1;
|
||||
|
||||
$service = new GameRebateService();
|
||||
[$records, $count] = $service->listQuery($params, $awardType, $permPromote);
|
||||
|
||||
$pageTitle = $service->typeDisplayNames[$awardType];
|
||||
$pageName = $service->typeNames[$awardType];
|
||||
if (count($records) > 0) {
|
||||
$records = $service->listRange($records);
|
||||
if ($isExport) {
|
||||
$field = $service->getExportHeadings($awardType);
|
||||
data2csv($records, $pageTitle, $field);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$pagination = $this->getPagination($count, $params['page'], $params['limit']);
|
||||
|
||||
$admins = M('ucenter_member', 'sys_')->field(['id', 'username'])->select();
|
||||
$baseGames = M('base_game', 'tab_')->select();
|
||||
|
||||
$gameRepository = new GameRepository();
|
||||
$this->assign('pageTitle', $pageTitle);
|
||||
$this->assign('pageName', $pageName);
|
||||
$this->assign('awardType', $awardType);
|
||||
$this->assign('servers', $gameRepository->getServersByBaseGameId($baseGameId));
|
||||
$this->assign('admins', $admins);
|
||||
$this->assign('baseGames', $baseGames);
|
||||
$this->assign('sendStatusList', $service->sendStatusList);
|
||||
$this->assign('reviewStatusList', $service->reviewStatusList);
|
||||
$this->assign('pagination', $pagination);
|
||||
$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]]);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue