游戏统计添加聚合充值数据

master
ELF 4 years ago
parent 6fa8984aa8
commit e8a925b64c

@ -12,6 +12,7 @@ use GuzzleHttp\Client;
use think\Db;
use Base\Task\Task;
use Base\Service\MarketService;
use Base\Tool\AggregateClient;
class ConsoleController extends Think {
@ -123,6 +124,13 @@ class ConsoleController extends Think {
}
}
public function testAggregate()
{
$client = new AggregateClient();
$result = $client->api('game-data', ['unique_codes' => ['abc']]);
var_dump($result);
}
public function initMarketAdmin()
{
$marketService = new MarketService();

@ -4,7 +4,7 @@
namespace Admin\Controller;
use OSS\Core\OssException;
use Base\Tool\AggregateClient;
class FinanceController extends ThinkController
{
@ -735,9 +735,32 @@ class FinanceController extends ThinkController
$startTime = time();
//游戏统计列表
$data = D("spend")->gameStatistics($map, $row, $p);
$uniqueCodes = array_column($data, 'unique_code');
$uniqueCodes = array_filter($uniqueCodes, function($value) {
if ($value) {
return true;
}
return false;
});
$client = new AggregateClient();
$result = $client->api('game-data', ['unique_codes' => $uniqueCodes]);
$aggData = [];
$aggTotal = '0.00';
if ($result['code'] == '0000') {
$aggData = $result['data']['records'];
$aggTotal = $result['data']['total'];
}
$endTime = time();
foreach ($data as $key => $value) {
$aggAmount = '0.00';
$deviceType = $value['sdk_version'] == 1 ? 'android' : 'ios';
if ($value['unique_code'] && isset($aggData[$value['unique_code']]) && isset($aggData[$value['unique_code']][$deviceType])) {
$aggAmount = number_format($aggData[$value['unique_code']][$deviceType], 2, '.', '');
}
$data[$key]['all_cash_count'] = number_format($value['cash_count'] + $value['balance_coin_count'] + $value['inside_cash_count'],2,'.','');
$data[$key]['agg_amount'] = $value['unique_code'] ? $aggAmount : '0.00';
}
$count = D("spend")->gameStatisticsCount($map);//列表总数
@ -760,6 +783,13 @@ class FinanceController extends ThinkController
$sumAll = $sumCash + $sumBalance + $sumInside;
$game_types = M("game_type", 'tab_')->field('id, type_name')->select();
$aggRate = round($aggTotal/($sumAll + $aggTotal) * 100, 2) . '%';
$allRate = round($sumAll/($sumAll + $aggTotal) * 100, 2) . '%';
$this->assign('aggRate', $aggRate);
$this->assign('allRate', $allRate);
$this->assign('aggTotal', $aggTotal);
$this->assign('game_types', $game_types);
$this->assign('sumCash', $sumCash);
$this->assign('sumBalance', $sumBalance);

@ -166,6 +166,8 @@ class GameController extends ThinkController
{
if (IS_POST) {
$gameService = new GameService();
$_POST['introduction'] = str_replace(array("\r\n", "\r", "\n"), "~~", $_POST['introduction']);
if ($_POST['game_name'] == '') {
$this->error('游戏名称不能为空!');
@ -184,6 +186,9 @@ class GameController extends ThinkController
return $this->error("请填写正确的极速版下载链接");
}
}
if ($_POST['unique_code'] && $gameService->isUniqueCodeExists($_POST['unique_code'])) {
return $this->error("聚合游戏标识已存在");
}
$_POST['relation_game_name'] = $_POST['game_name'];
if ($_POST['sdk_version'] == 1) {
unset($_POST['ios_game_address']);
@ -217,7 +222,6 @@ class GameController extends ThinkController
$_POST['discount'] == '' ? $_POST['discount'] = 10 : $_POST['discount'];
$_POST['short'] = $short;
$gameService = new GameService();
$_POST['download_ways'] = $gameService->getDownLoadWaysValue($downloadWays);
$game = D(self::model_name);//M('$this->$model_name','tab_');
@ -344,32 +348,10 @@ class GameController extends ThinkController
public function edit($id = null)
{
if (IS_POST) {
if(!empty($_REQUEST['apply_auth'])) {
$gameData['apply_auth'] = $_REQUEST['apply_auth'];
$game_appid = $_REQUEST['game_appid'];
$gameId = M('game','tab_')->where(['game_appid' => $game_appid])->getField('id');
M('game','tab_')->where(['id'=>$gameId])->save($gameData);
if($_REQUEST['apply_auth'] == 1) {
M('sociaty_games','tab_')->where(['game_id'=>$gameId])->delete();
}
if(!empty($_REQUEST['promote_data'])) {
$promote_data = json_decode($_REQUEST['promote_data'],TRUE);
$game_appid = $_REQUEST['game_appid'];
$gameId = M('game','tab_')->where(['game_appid' => $game_appid])->getField('id');
$gameInfo = M('game','tab_')->field('game_name,game_status')->where(['id'=>$gameId])->select();
$dataList = array();
foreach($promote_data as $key => $promoteInfo) {
$isSociaty = M('sociaty_games','tab_')->where(['promote_id'=>intval($promoteInfo['value']),'game_id'=>intval($gameId)])->getField('id');
if(!empty($isSociaty)) {
// $this->error("选择会长中有已存在会长");
}else {
$dataList[] = ['promote_id' => intval($promoteInfo['value']),'game_id' => intval($gameId),'status'=>$gameInfo[0]['game_status'],'create_time'=>time()];
}
}
M('sociaty_games','tab_')->addAll($dataList);
}
// $_REQUEST['apply_auth'] == 1 ? $this->success('开放全部会长权限成功') : $this->success('设置会长权限成功');
$game = M('game', 'tab_')->where(['id' => $id])->find();
if (!$game) {
$this->error('游戏不存在!');
exit;
}
if ($_POST['game_score'] < 0 || $_POST['game_score'] > 5) {
$this->error('游戏评分只能为0-5之间的数字');
@ -389,6 +371,11 @@ class GameController extends ThinkController
return $this->error("请填写正确的极速版下载链接");
}
}
$gameService = new GameService();
if ($_POST['unique_code'] && $gameService->isUniqueCodeExists($_POST['unique_code'], $game['relation_game_id'], 'relation_game_id')) {
return $this->error("聚合游戏标识已存在");
}
/*if($_POST['apply_status']==0&&$_POST['game_status']==1){
$this->error('游戏未审核不允许显示');//游戏添加完成
}*/
@ -400,15 +387,14 @@ class GameController extends ThinkController
$_POST['display_site'] = '';
}
$content = $_POST['content'];
$gameRatio = M('Game', 'tab_')->where(array('id' => I('post.id', 0)))->getField('ratio');//游戏推广分成比例
$game = D(self::model_name);//M('$this->$model_name','tab_');
$gameModel = D(self::model_name);//M('$this->$model_name','tab_');
$_POST['discount'] == '' ? $_POST['discount'] = 10 : $_POST['discount'];
$_POST['detail_content'] = $content;
$_POST['pay_config'] = json_encode($_POST['pay_config']);
$gameService = new GameService();
$_POST['download_ways'] = $gameService->getDownLoadWaysValue($downloadWays);
unset($_POST['apply_auth']);
$res = $game->update();
$res = $gameModel->update();
$id = $res["id"];
$sibling = D("Game")->find($id);
@ -425,36 +411,37 @@ class GameController extends ThinkController
];
$gameService->saveBaseGame($baseData);
$phone['apply_auth'] = $sibling['apply_auth'];
$phone['game_type_id'] = $sibling['game_type_id'];
$phone['dow_num'] = $sibling['dow_num'];
$phone['game_type_name'] = $sibling['game_type_name'];
$phone['category'] = $sibling['category'];
$phone['recommend_status'] = $sibling['recommend_status'];
//$phone['game_status']= $sibling['game_status'];
$phone['sort'] = $sibling['sort'];
$phone['game_score'] = $sibling['game_score'];
$phone['features'] = $sibling['features'];
$phone['flooring_page_imgs'] = $sibling['flooring_page_imgs'];
$phone['introduction'] = $sibling['introduction'];
$phone['icon'] = $sibling['icon'];
$phone['cover'] = $sibling['cover'];
$phone['screenshot'] = $sibling['screenshot'];
$phone['material_url'] = $sibling['material_url'];
$phone['game_detail_cover'] = $sibling['game_detail_cover'];
$phone['first_level_name'] = $sibling['first_level_name'];
$phone['second_level_name'] = $sibling['second_level_name'];
$phone['third_level_name'] = $sibling['third_level_name'];
$phone['first_level'] = $sibling['first_level'];
$phone['second_level'] = $sibling['second_level'];
$phone['third_level'] = $sibling['third_level'];
$phone['display_site'] = $sibling['display_site'];
$phone['back_describe'] = $sibling['back_describe'];
$phone['dow_icon'] = $sibling['dow_icon'];
$phone['back_map'] = $sibling['back_map'];
$phone['flooring_page_video'] = $sibling['flooring_page_video'];
$phone['flooring_page_video_cover'] = $sibling['flooring_page_video_cover'];
M('Game', 'tab_')->data($phone)->where(array('id' => $another['id']))->save();
$otherData = [];
$otherData['apply_auth'] = $sibling['apply_auth'];
$otherData['game_type_id'] = $sibling['game_type_id'];
$otherData['dow_num'] = $sibling['dow_num'];
$otherData['game_type_name'] = $sibling['game_type_name'];
$otherData['category'] = $sibling['category'];
$otherData['recommend_status'] = $sibling['recommend_status'];
$otherData['sort'] = $sibling['sort'];
$otherData['game_score'] = $sibling['game_score'];
$otherData['features'] = $sibling['features'];
$otherData['flooring_page_imgs'] = $sibling['flooring_page_imgs'];
$otherData['introduction'] = $sibling['introduction'];
$otherData['icon'] = $sibling['icon'];
$otherData['cover'] = $sibling['cover'];
$otherData['screenshot'] = $sibling['screenshot'];
$otherData['material_url'] = $sibling['material_url'];
$otherData['game_detail_cover'] = $sibling['game_detail_cover'];
$otherData['first_level_name'] = $sibling['first_level_name'];
$otherData['second_level_name'] = $sibling['second_level_name'];
$otherData['third_level_name'] = $sibling['third_level_name'];
$otherData['first_level'] = $sibling['first_level'];
$otherData['second_level'] = $sibling['second_level'];
$otherData['third_level'] = $sibling['third_level'];
$otherData['display_site'] = $sibling['display_site'];
$otherData['back_describe'] = $sibling['back_describe'];
$otherData['dow_icon'] = $sibling['dow_icon'];
$otherData['back_map'] = $sibling['back_map'];
$otherData['unique_code'] = $sibling['unique_code'];
$otherData['flooring_page_video'] = $sibling['flooring_page_video'];
$otherData['flooring_page_video_cover'] = $sibling['flooring_page_video_cover'];
M('Game', 'tab_')->data($otherData)->where(array('id' => $another['id']))->save();
//同时修改代充游戏折扣
$set_fidel['status'] = 1;
$set_fidel['game_id'] = $id;
@ -462,7 +449,7 @@ class GameController extends ThinkController
$promoteModel = new \Admin\Model\PromoteWelfareModel();
$promoteModel->set_game_discount($set_fidel);
if (!$res) {
$this->error($game->getError());
$this->error($gameModel->getError());
} else {
\Think\Log::actionLog('Game/edit', 'Game', 1);
addOperationLog(array(

@ -851,7 +851,7 @@ class SpendModel extends Model
->select(false);
$query = M("Spend s use index(game_time)","tab_")
->field("s.game_id,g.relation_game_name game_name,p.partner as partner_name, g.game_type_name,
->field("s.game_id,g.relation_game_name game_name, g.unique_code, p.partner as partner_name, g.game_type_name,
SUM(CASE WHEN pay_way > 0 and s.pay_status = 1 and pay_game_status = 1 THEN pay_amount ELSE 0 END) as cash_count,
SUM(CASE WHEN pay_way = 0 and s.pay_status = 1 and pay_game_status = 1 THEN pay_amount ELSE 0 END) as balance_coin_count,
SUM(CASE WHEN pay_way = -1 and s.pay_status = 1 and pay_game_status = 1 THEN pay_amount ELSE 0 END) as inside_cash_count,g.sdk_version,notice_fail_count")

@ -175,7 +175,7 @@
<th ><div class="tooltip">内充支出<span class="tooltiptext"><span style="margin-left: -10px">玩家用绑币购买游戏道具所产生的金额</span></span></div></th>
<th ><div class="tooltip">游戏内充值合计<span class="tooltiptext"><span style="margin-left: -10px">游戏现金金额+平台币直充支出+平台币内充支出</span></span></div></th>
<th ><div class="tooltip">聚合平台数据<span class="tooltiptext"><span style="margin-left: -10px">包含聚合万盟平台数据,因为聚合平台数据是用接口获取并且涉及其他平台数据,所以只能添加总数据,无法判定平台币还是现金充值</span></span></div></th>
<th ><div class="tooltip"><span style="color: red">通知失败合计</span><span class="tooltiptext"><span style="margin-left: -10px">所有通知失败的合计金额</span></span></div></th>
<th >操作</th>
@ -222,6 +222,7 @@
'pay_way'=>-1,
false))}"><if condition="$data.inside_cash_count neq ''">{$data.inside_cash_count}<else/>0</if></td>
<td ><if condition="$data.all_cash_count neq ''">{$data.all_cash_count}<else/>0</if></td>
<td >{$data.agg_amount}</td>
<td ><span style="color:red;"><if condition="$data.notice_fail_count neq ''">{$data.notice_fail_count}<else/>0</if></span></td>
<td >
<a href="{:U('Finance/gameStatisticsDetail',array(
@ -241,6 +242,7 @@
<td><if condition="$sumBalance neq ''">{$sumBalance}<else/>0</if></td>
<td><if condition="$sumInside neq ''">{$sumInside}<else/>0</if></td>
<td><if condition="$sumAll neq ''">{$sumAll}<else/>0</if></td>
<td>{$aggTotal}</td>
<td><span style="color: red"><if condition="$sumNoticeFail neq ''">{$sumNoticeFail}<else/>0</if></span></td>
<td>
<a href="{:U('Finance/gameStatisticsDetail',
@ -258,6 +260,7 @@
</tbody>
</table>
<p style="text-align: center; margin-top: 5px;">联运渠道数据:{$sumAll} 占比:{$allRate} 聚合渠道数据:{$aggTotal} 占比:{$aggRate}</p>
</div>
</div>
<div class="page">

@ -150,6 +150,13 @@
<span class="notice-text">设置游戏的推荐类型,更改此游戏在网站所属的推荐板块;</span>
</td>
</tr>
<tr>
<td class="l">聚合游戏标识:</td>
<td class="r">
<input type="text" class="txt" name="unique_code" value="" placeholder="请输入聚合游戏标识">
<span class="notice-text">用于与聚合后台数据相关联使用,如果聚合后台有相关游戏,则需填写对应标识。标识可自由定义,字母数字均可,双平台一致即可。</span>
</td>
</tr>
<tr>
<td class="l">游戏排序:</td>
<td class="r">

@ -175,6 +175,13 @@
<span class="notice-text">设置游戏的推荐类型,更改此游戏在网站所属的推荐板块;</span>
</td>
</tr>
<tr>
<td class="l">聚合游戏标识:</td>
<td class="r">
<input type="text" class="txt" name="unique_code" value="{$data['unique_code']}" placeholder="请输入聚合游戏标识">
<span class="notice-text">用于与聚合后台数据相关联使用,如果聚合后台有相关游戏,则需填写对应标识。标识可自由定义,字母数字均可,双平台一致即可。</span>
</td>
</tr>
<tr>
<td class="l">游戏排序:</td>
<td class="r">

@ -141,6 +141,13 @@
<span class="notice-text">设置游戏的推荐类型更改此游戏在PC官网所属的推荐板块</span>
</td>
</tr>
<tr>
<td class="l">聚合游戏标识:</td>
<td class="r">
<input type="text" class="txt" name="unique_code" value="{$data['unique_code']}" readonly = "readonly" style="background:#e7e7e7" placeholder="请输入聚合游戏标识">
<span class="notice-text">用于与聚合后台数据相关联使用,如果聚合后台有相关游戏,则需填写对应标识。标识可自由定义,字母数字均可,双平台一致即可。</span>
</td>
</tr>
<tr>
<td class="l">游戏排序:</td>
<td class="r">

@ -46,4 +46,17 @@ class GameService {
return M('base_game', 'tab_')->where(['id' => $baseGame['id']])->save($data);
}
}
public function isUniqueCodeExists($uniqueCode, $exceptId = 0, $exceptType = 'id')
{
$map = ['unique_code' => $uniqueCode];
if ($exceptId > 0) {
$map[$exceptType] = ['neq', $exceptId];
}
$count = M('game', 'tab_')->where($map)->count();
if ($count > 0) {
return true;
}
return false;
}
}

@ -0,0 +1,52 @@
<?php
namespace Base\Tool;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
class AggregateClient
{
const SUCCESS = '0000';
protected $client;
private $apis = [
'game-data' => '/index.php?g=api&m=Game&a=rechargeData',
];
public function __construct()
{
$this->client = new Client([
'base_uri' => C('AGGREGATE_URL'),
'timeout' => 10.0,
]);
}
public function api($api, array $params = [])
{
$uri = $this->apis[$api] ?? null;
if (is_null($uri)) {
throw new \Exception('接口不存在');
}
$params['api-name'] = $api;
$sign = Sign::generate($params);
$params[Sign::SIGN_NAME] = $sign;
try {
return $this->post($uri, $params);
} catch (\Exception $e) {
return ['code' => '1000', 'message' => '接口请求错误:' . $e->getMessage() , 'data' => []];
}
}
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);
}
}

@ -0,0 +1,21 @@
<?php
namespace Base\Tool;
class Sign
{
const SIGN_NAME = 'sign';
const SIGN_KEY = 'Wmtx_2019!@#API';
public static function generate($params, $signName = self::SIGN_NAME)
{
unset($params[$signName]);
ksort($params);
return md5(http_build_query($params) . self::SIGN_KEY);
}
public static function check($params, $signName = self::SIGN_NAME)
{
return self::generate($params) === $params[$signName];
}
}
Loading…
Cancel
Save