From 531b94bae88786f5b9f0d95ddf18d83f2530e71c Mon Sep 17 00:00:00 2001
From: ELF <360197197@qq.com>
Date: Tue, 26 Jan 2021 15:19:19 +0800
Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Controller/ConsoleController.class.php | 82 +++++++++++++++++++
.../Base/Service/PromoteService.class.php | 32 +++++---
Application/Base/Tool/Redis.class.php | 16 ++++
.../Home/Controller/QueryController.class.php | 4 +-
Data/update.sql | 12 +++
5 files changed, 132 insertions(+), 14 deletions(-)
diff --git a/Application/Admin/Controller/ConsoleController.class.php b/Application/Admin/Controller/ConsoleController.class.php
index 3c10092fa..c36acb21f 100644
--- a/Application/Admin/Controller/ConsoleController.class.php
+++ b/Application/Admin/Controller/ConsoleController.class.php
@@ -14,6 +14,8 @@ use Base\Task\Task;
use Base\Service\MarketService;
use Base\Tool\AggregateClient;
use Base\Repository\GameRepository;
+use Base\Tool\Redis;
+use Think\Model;
class ConsoleController extends Think {
@@ -666,4 +668,84 @@ class ConsoleController extends Think {
}
echo '
';
}
+
+ public function generateHistoryGame()
+ {
+ $items = M('spend', 'tab_')
+ ->field(['tab_promote.level1_id', 'group_concat(distinct tab_spend.game_id) game_ids'])
+ ->join('left join tab_promote on tab_spend.promote_id=tab_promote.id')
+ ->where('tab_spend.is_check=1 and tab_spend.pay_status=1')
+ ->group('tab_promote.level1_id')
+ ->select();
+ foreach ($items as $item) {
+ if ($item['level1_id']) {
+ $key = Redis::getKey('promote_history_games', ['promote_id' => $item['level1_id']]);
+ Redis::set($key, $item['game_ids']);
+ }
+ }
+ }
+
+ public function updateHistoryGame()
+ {
+ $items = M('spend', 'tab_')
+ ->field(['tab_promote.level1_id', 'group_concat(distinct tab_spend.game_id) game_ids'])
+ ->join('left join tab_promote on tab_spend.promote_id=tab_promote.id')
+ ->where('tab_spend.is_check=1 and tab_spend.pay_status=1 and tab_spend.pay_time>' . strtotime(date('Y-m-d 00:00:00')))
+ ->group('tab_promote.level1_id')
+ ->select();
+ foreach ($items as $item) {
+ if ($item['level1_id']) {
+ $key = Redis::getKey('promote_history_games', ['promote_id' => $item['level1_id']]);
+ $value = Redis::get($key);
+ $gameIds = $value ? explode(',', $value) : [];
+ $nowGameIds = explode(',', $item['game_ids']);
+ $gameIds = array_unique(array_merge($gameIds, $nowGameIds));
+ Redis::set($key, implode(',', $gameIds));
+ }
+ }
+ }
+
+ public function generatePromotesLevelId()
+ {
+ $promotes = M('promote', 'tab_')->field(['chain', 'id'])->select();
+ foreach ($promotes as $promote) {
+ $fullChain = explode('/', $promote['chain'] . $promote['id']);
+ M('promote', 'tab_')->where(['id' => $promote['id']])->save([
+ 'level1_id' => $fullChain[1] ?? 0,
+ 'level2_id' => $fullChain[2] ?? 0,
+ 'level3_id' => $fullChain[3] ?? 0,
+ 'level4_id' => $fullChain[4] ?? 0,
+ ]);
+ }
+ }
+
+ public function setUserFirstPayTime()
+ {
+ $hasNext = true;
+ $limit = 500;
+ $lastId = 0;
+ do {
+ $items = M('spend', 'tab_')
+ ->field(['user_id', 'min(pay_time) first_pay_time'])
+ ->where(['pay_status' => 1, 'user_id' => ['gt', $lastId]])
+ ->group('user_id')
+ ->order('user_id asc')
+ ->limit($limit)
+ ->select();
+
+ $model = new Model();
+ $model->startTrans();
+ foreach ($items as $item) {
+ M('user', 'tab_')->where(['id' => $item['user_id']])->save([
+ 'first_pay_time' => $item['first_pay_time']
+ ]);
+ $lastId = $item['user_id'];
+ }
+ $model->commit();
+
+ if (count($items) < $limit) {
+ $hasNext = false;
+ }
+ } while($hasNext);
+ }
}
diff --git a/Application/Base/Service/PromoteService.class.php b/Application/Base/Service/PromoteService.class.php
index 383da0f30..6ab11124b 100644
--- a/Application/Base/Service/PromoteService.class.php
+++ b/Application/Base/Service/PromoteService.class.php
@@ -7,6 +7,7 @@ use Base\Model\UserPlayModel;
use Base\Model\UserModel;
use Base\Tool\IdCard;
use Base\Tool\Registry;
+use Base\Tool\Redis;
use Think\Model;
use Base\Repository\SpendRepository;
@@ -396,6 +397,11 @@ class PromoteService {
}
}
+ $toTopPromote = $this->getTopPromote($toPromote);
+ $hasGameIds = $toTopPromote['game_ids'] == '' ? [] : explode(',', $toTopPromote['game_ids']);
+ $hasNotGameIds = M('game', 'tab_')->where(['game_id' => ['not in', $hasGameIds]])->getField('id', true);
+ $hasNotGameIds = $hasNotGameIds ?? [];
+
$model = new Model();
$model->startTrans();
@@ -433,7 +439,17 @@ class PromoteService {
M('user_play_info', 'tab_')->where($otherMap)->save($updateData);
unset($spendMap['pay_status']);
- M('spend', 'tab_')->where($spendMap)->save(array_merge($updateData, $updateMarket)); // 只改未对账的数据
+
+ $updateCheck = [];
+ if (count($hasGameIds) > 0) {
+ $spendMap['game_id'] = ['in', $hasGameIds];
+ M('spend', 'tab_')->where($spendMap)->save(array_merge($updateData, $updateMarket, ['is_check' => 1]));
+ }
+
+ if (count($hasNotGameIds) > 0) {
+ $spendMap['game_id'] = ['in', $hasNotGameIds];
+ M('spend', 'tab_')->where($spendMap)->save(array_merge($updateData, $updateMarket, ['is_check' => 0]));
+ }
$bindMap = $otherMap;
$bindMap['pay_time'] = ['egt', $orderTime];
@@ -1253,17 +1269,9 @@ class PromoteService {
public function getHistoryGameIds($promote)
{
$topPromote = $this->getTopPromote($promote);
-
- $spendRepository = new SpendRepository();
-
- $map = [];
- $map['_string'] = ' promote_id in(' . $this->subInSql($topPromote) . ')';
- $map = $spendRepository->withIsCheck($map);
- $historyGames = M('spend', 'tab_')->field(['distinct game_id'])->where($map)->select();
- $historyGameIds = [];
- if ($historyGames) {
- $historyGameIds = array_column($historyGames, 'game_id');
- }
+ $key = Redis::getKey('promote_history_games', ['promote_id' => $item['level1_id']]);
+ $value = Redis::get($key);
+ $historyGameIds = $value ? explode(',', $value) : [];
$nowGameIds = $topPromote['game_ids'] == '' ? [] : explode(',', $topPromote['game_ids']);
return array_unique(array_merge($historyGameIds, $nowGameIds));
}
diff --git a/Application/Base/Tool/Redis.class.php b/Application/Base/Tool/Redis.class.php
index 8c8988b1a..329880bb8 100644
--- a/Application/Base/Tool/Redis.class.php
+++ b/Application/Base/Tool/Redis.class.php
@@ -8,6 +8,22 @@ class Redis
{
private static $handler;
+ public static $allKeys = [
+ 'promote_history_games' => 'promote_history_games:{promote_id}', // 会长历史游戏
+ ];
+
+ public static function getKey($name, $params = [])
+ {
+ $realKey = self::$allKeys[$name] ?? null;
+ if (is_null($realKey)) {
+ throw new \Exception('KEY不存在');
+ }
+ foreach ($params as $key => $value) {
+ $realKey = str_replace('{' . $key . '}', $value, $realKey);
+ }
+ return $realKey;
+ }
+
public static function getHandler()
{
if(self::$handler == null) {
diff --git a/Application/Home/Controller/QueryController.class.php b/Application/Home/Controller/QueryController.class.php
index c73569d46..16300c0c8 100644
--- a/Application/Home/Controller/QueryController.class.php
+++ b/Application/Home/Controller/QueryController.class.php
@@ -801,7 +801,7 @@ class QueryController extends BaseController
$newPayUserCountList = $spendRepository->getNewPayUserCountGroupByDay($params);
$payAmountList = $spendRepository->getPayAmountGroupByDay($params);
$newPayAmountList = $spendRepository->getNewPayAmountGroupByDay($params);
- $historyPayCountList = $spendRepository->getHistoryPayCountGroupByDay($params);
+ // $historyPayCountList = $spendRepository->getHistoryPayCountGroupByDay($params);
$loginCountList = $userRepository->getLoginCountGroupByDay($params);
$registerCountList = $userRepository->getRegisterCountGroupByDay($params);
@@ -813,7 +813,7 @@ class QueryController extends BaseController
'newPayUserCount' => $newPayUserCountList[$day],
'payAmount' => number_format($payAmountList[$day], 2),
'newPayAmount' => number_format($newPayAmountList[$day], 2),
- 'historyPayCount' => $historyPayCountList[$day],
+ // 'historyPayCount' => $historyPayCountList[$day],
'loginCount' => $loginCountList[$day],
'registerCount' => $registerCountList[$day],
'payRate' => $loginCountList[$day] == 0 ? '--' : round($payUserCountList[$day] / $loginCountList[$day] * 100, 2) . '%',
diff --git a/Data/update.sql b/Data/update.sql
index 308fb3613..d48d00763 100644
--- a/Data/update.sql
+++ b/Data/update.sql
@@ -2781,3 +2781,15 @@ ALTER TABLE `tab_testing_resource_batch`
ADD COLUMN `verify_admin_id` int(11) NOT NULL DEFAULT 0 COMMENT '審核管理員ID' AFTER `verify_status`;
ALTER TABLE `tab_testing_resource_batch`
ADD COLUMN `apply_admin_id` int(11) NOT NULL DEFAULT 0 COMMENT '申請管理員ID' AFTER `apply_promote_id`;
+
+ALTER TABLE `tab_promote`
+ADD COLUMN `level1_id` int(11) NOT NULL DEFAULT 0 COMMENT '一级推广员ID(会长)' AFTER `chain`;
+ALTER TABLE `tab_promote`
+ADD COLUMN `level2_id` int(11) NOT NULL DEFAULT 0 COMMENT '二级推广员ID(部门长)' AFTER `level1_id`;
+ALTER TABLE `tab_promote`
+ADD COLUMN `level3_id` int(11) NOT NULL DEFAULT 0 COMMENT '三级推广员ID(组长)' AFTER `level2_id`;
+ALTER TABLE `tab_promote`
+ADD COLUMN `level4_id` int(11) NOT NULL DEFAULT 0 COMMENT '四级推广员ID(推广员)' AFTER `level3_id`;
+
+ALTER TABLE `tab_user`
+ADD COLUMN `first_pay_time` int(11) NOT NULL DEFAULT 0 COMMENT '首次充值时间' AFTER `fgame_name`;
\ No newline at end of file