|
|
@@ -171,143 +171,103 @@ class BaseLogic
|
|
|
{
|
|
|
$withSearch = array_keys($searchWhere);
|
|
|
$data = $searchWhere;
|
|
|
-
|
|
|
- // 获取游戏权限
|
|
|
- $authGameList = request()->header('auth_game_list');
|
|
|
-
|
|
|
- $authNormalGameList = request()->header('auth_normal_game_list');
|
|
|
- $authAdPermission = request()->header('auth_ad_permission');
|
|
|
-
|
|
|
-
|
|
|
foreach ($withSearch as $k => $v) {
|
|
|
if ($data[$v] === '') {
|
|
|
unset($data[$v]);
|
|
|
unset($withSearch[$k]);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- // 游戏权限
|
|
|
-
|
|
|
- if(!empty($authGameList)){
|
|
|
- if(!empty($data['game_id'])){
|
|
|
- // 如果传入了game_id,则取权限交集
|
|
|
- $inputGameIds = is_array($data['game_id']) ? $data['game_id'] : explode(',', $data['game_id']);
|
|
|
- $authGameIds = explode(',', $authGameList);
|
|
|
- $data['game_id'] = array_values(array_intersect($inputGameIds, $authGameIds));
|
|
|
- }else{
|
|
|
- // 如果没传入game_id,则取权限
|
|
|
- $data['game_id'] = $authGameList ? explode(',', $authGameList) : '';
|
|
|
- }
|
|
|
- }
|
|
|
- /**广告数据权限-开始***************************************** */
|
|
|
-
|
|
|
|
|
|
- // 广告数据权限-自己以及下面组员
|
|
|
- if($authAdPermission==2){
|
|
|
-
|
|
|
- // 根据用户id获取用户权限
|
|
|
- $token = getCurrentInfo();
|
|
|
- // 用户权限缓存
|
|
|
- $userAuthCache = new UserInfoCache($token['id']);
|
|
|
- $user_info = $userAuthCache->getUserInfo();
|
|
|
- $current_user_id = $user_info['id'];
|
|
|
- $result = Db::connect('db_system')->table('sa_system_user')->field('dept_id')->where('id', $current_user_id)->select()->toArray();
|
|
|
- $dept_ids = array_column($result, 'dept_id');
|
|
|
- $under_user_ids = Db::connect('db_system')->table('sa_system_user')->field('id')->where('dept_id', 'in', $dept_ids)->select()->toArray();
|
|
|
- $under_user_ids = array_column($under_user_ids, 'id');
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if(!empty($data['auth_id'])){
|
|
|
- // 如果传入了负责人ID,则取交集
|
|
|
- $data['auth_id'] = array_values(array_intersect( $data['auth_id'], array_values($under_user_ids)));
|
|
|
- }else{
|
|
|
- // 如果没有传入负责人ID, 则取当前用户以及下面组员
|
|
|
- $data['auth_id'] = array_values($under_user_ids);
|
|
|
- }
|
|
|
+ $userAuthCache = new UserInfoCache(getCurrentInfo()['id']);
|
|
|
+ $userInfo = $userAuthCache->getUserInfo();
|
|
|
+ // Todo 如果角色权限,超过跳过权限限制
|
|
|
+ $roleIds = array_column($userInfo['roleList'], 'id');
|
|
|
+ if(in_array(1, $roleIds)){
|
|
|
+ return $data;
|
|
|
}
|
|
|
|
|
|
- // 广告数据权限-如果auth_id为空,则取当前用户
|
|
|
- if($authAdPermission==0){
|
|
|
- // 根据用户id获取用户权限
|
|
|
- $token = getCurrentInfo();
|
|
|
- // 用户权限缓存
|
|
|
- $userAuthCache = new UserInfoCache($token['id']);
|
|
|
- $user_info = $userAuthCache->getUserInfo();
|
|
|
- $current_user_id = $user_info['id'];
|
|
|
- if(!empty($data['auth_id'])){
|
|
|
- // 如果传入了负责人ID,则取交集
|
|
|
- $data['auth_id'] = array_values(array_intersect( $data['auth_id'], array_values($under_user_ids)));
|
|
|
+ // Todo 1、游戏权限
|
|
|
+ $authGameList = $userInfo['deptList']['game_list'];
|
|
|
+ if($authGameList != '*'){
|
|
|
+ $authGameIds = explode(',', $authGameList);
|
|
|
+
|
|
|
+ if(!empty($data['game_id'])){
|
|
|
+ $inputGameIds = is_array($data['game_id']) ? $data['game_id'] : explode(',', $data['game_id']);
|
|
|
+ $data['game_id'] = array_values(array_intersect($inputGameIds, $authGameIds)); // 如果传入了game_id,则取权限交集
|
|
|
}else{
|
|
|
- // 如果没有传入负责人ID, 则取当前用户
|
|
|
- $data['auth_id'] = $current_user_id;
|
|
|
+ // 如果没传入game_id,则取权限
|
|
|
+ $data['game_id'] = $authGameIds;
|
|
|
}
|
|
|
}
|
|
|
- /**广告数据权限-结束***************************************** */
|
|
|
-
|
|
|
|
|
|
- /**自然量权限-开始***************************************** */
|
|
|
- // 全部游戏的自然量
|
|
|
- if($authNormalGameList=='*'){
|
|
|
- if(!empty($data['auth_id'])){
|
|
|
- $data['auth_id'][] = 0;
|
|
|
- }else{
|
|
|
- $data['auth_id'] = [];
|
|
|
+ // Todo 2、广告数据权限
|
|
|
+ $userId = $userInfo['id'];
|
|
|
+ $deptId = $userInfo['deptList']['id'];
|
|
|
+ // 广告权限,自己 or 全部
|
|
|
+ $authAdPermission = $userInfo['ad_permission'];
|
|
|
+ if($authAdPermission){
|
|
|
+ if($authAdPermission==1){ // Todo 1、仅自己
|
|
|
+ $data['auth_id'] = [$userId];
|
|
|
+ } elseif($authAdPermission==2) { // Todo 2、自己部门
|
|
|
+ $underUserIds = Db::connect('db_system')->table('sa_system_user')->where('dept_id', 'in', $deptId)->column('id');
|
|
|
+ if(!empty($data['auth_id'])) { // 如果传入了负责人ID,则取交集
|
|
|
+ $data['auth_id'] = array_values(array_intersect( $data['auth_id'], array_values($underUserIds)));
|
|
|
+ }else{ // 如果没有传入负责人ID, 则取当前用户以及下面组员
|
|
|
+ $data['auth_id'] = array_values($underUserIds);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 看指定游戏的自然量
|
|
|
- $data['nomal_game_id'] = "";
|
|
|
- if(!empty($authNormalGameList) && $authNormalGameList!='*' && $authNormalGameList!='-1'){
|
|
|
- // 如果传入了game_id,则取auth_normal_game_list交集
|
|
|
- if(!empty($data['game_id'])){
|
|
|
- $authNormalGameList = explode(',', $authNormalGameList);
|
|
|
- $data['nomal_game_id'] = array_values(array_intersect($authNormalGameList, $data['game_id']));
|
|
|
- }else{
|
|
|
- $data['nomal_game_id'] = $authNormalGameList ? explode(',', $authNormalGameList) : '';
|
|
|
- }
|
|
|
+ $authNormalGameList = $userInfo['normal_game_list']; // 可看自然量的游戏
|
|
|
+ if($authNormalGameList!='*' && $authNormalGameList!='-1' && !empty($data['game_id'])){
|
|
|
+ // 则取auth_normal_game_list交集
|
|
|
+ $data['normal_game_id'] = array_values(array_intersect(explode(',', $authNormalGameList), $data['game_id']));
|
|
|
}
|
|
|
|
|
|
- /**自然量权限-结束***************************************** */
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
- // Todo 玩家日志的公共 where 子句
|
|
|
- protected function getUlogCommonWhere($params): array
|
|
|
+ // Todo 公共 where 子句
|
|
|
+ protected function getCommonWhereRaw($params): string
|
|
|
{
|
|
|
$eqParams = ["user_name", "media_id", "site_id", "agent_id", "vt", "server_id", "server_name"];
|
|
|
$inParams = ["game_id", "auth_id"];
|
|
|
- $betweenParams = ["pay_date", "reg_date"];
|
|
|
- $betweenTimeParams = ["reg_time", "login_time"];
|
|
|
+ $betweenParams = ["tdate"];
|
|
|
+ $timeParams = ["reg_time", "pay_time", "login_time"];
|
|
|
+ $DateTimeParams = ["create_time"];
|
|
|
|
|
|
- $where = [];
|
|
|
+ // Todo And条件
|
|
|
+ $whereRaw = " 1=1 ";
|
|
|
foreach ($params as $key => $value){
|
|
|
if (in_array($key, $eqParams)) {
|
|
|
- $where[$key] = $value;
|
|
|
- } elseif (in_array($key, $inParams)) {
|
|
|
- $where[$key] = is_string($value) ? explode(',', $value) : $value;
|
|
|
- } elseif (in_array($key, $betweenParams)) {
|
|
|
- if (!empty($value)) {
|
|
|
- $where[] = [$key, 'between', [$value[0] .' 00:00:00', $value[1] .' 23:59:59']];
|
|
|
- }
|
|
|
+ $whereRaw .= " AND `{$key}`='{$value}'";
|
|
|
+ } elseif (in_array($key, $inParams) && !empty($value)) {
|
|
|
+ $value = is_string($value) ? explode(',', $value) : $value;
|
|
|
+ $whereRaw .= " AND `{$key}` IN ('".implode("','", $value)."')";
|
|
|
+ } elseif (in_array($key, $betweenParams) && !empty($value)) {
|
|
|
+ $whereRaw .= " AND `{$key}` BETWEEN '{$value[0]}' AND '{$value[1]}'";
|
|
|
+ } elseif (in_array($key, $DateTimeParams) && !empty($value)) {
|
|
|
+ $value[0] = $value[0] .' 00:00:00';
|
|
|
+ $value[1] = $value[1] .' 23:59:59';
|
|
|
+ $whereRaw .= " AND `{$key}` BETWEEN '{$value[0]}' AND '{$value[1]}'";
|
|
|
+ } elseif (in_array($key, $timeParams) && !empty($value)) {
|
|
|
+ $value[0] = strtotime($value[0] .' 00:00:00');
|
|
|
+ $value[1] = strtotime($value[1] .' 23:59:59');
|
|
|
+ $whereRaw .= " AND `{$key}` BETWEEN '{$value[0]}' AND '{$value[1]}'";
|
|
|
}
|
|
|
- elseif (in_array($key, $betweenTimeParams)) {
|
|
|
- if (!empty($value)) {
|
|
|
- $where[] = [$key, 'between', [strtotime($value[0] .' 00:00:00'), strtotime($value[1] .' 23:59:59')]];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+ // Todo 自然量走 Or 条件
|
|
|
$whereOr = [];
|
|
|
- if(!empty($params['nomal_game_id'])){
|
|
|
- foreach ($params['nomal_game_id'] as $gameId){
|
|
|
+ if(!empty($params['normal_game_id'])){
|
|
|
+ foreach ($params['normal_game_id'] as $gameId){
|
|
|
$whereOr[] = "(game_id = {$gameId} AND auth_id=0)";
|
|
|
}
|
|
|
}
|
|
|
- $whereRaw = $whereOr ? implode(' OR ', $whereOr) : "1=1";
|
|
|
+ $whereOr = $whereOr ? implode(' OR ', $whereOr) : "";
|
|
|
|
|
|
- return [$where, $whereRaw];
|
|
|
+ return $whereRaw . ($whereOr ? " OR {$whereOr}" : "");
|
|
|
}
|
|
|
/**
|
|
|
* 分页查询数据
|
|
|
@@ -347,29 +307,6 @@ class BaseLogic
|
|
|
$query->order($orderBy, $orderType);
|
|
|
return $query->select()->toArray();
|
|
|
}
|
|
|
- /**
|
|
|
- * 获取IP地理位置
|
|
|
- */
|
|
|
- public function getIpLocation($ip): string
|
|
|
- {
|
|
|
- $ip2region = new \Ip2Region();
|
|
|
- try {
|
|
|
- $region = $ip2region->memorySearch($ip);
|
|
|
- } catch (\Exception $e) {
|
|
|
- return '未知';
|
|
|
- }
|
|
|
- list($country, $number, $province, $city, $network) = explode('|', $region['region']);
|
|
|
- if ($network === '内网IP') {
|
|
|
- return $ip.' '.$network;
|
|
|
- }
|
|
|
- if ($country == '中国') {
|
|
|
- return $ip.' '.$province.'-'.$city.':'.$network;
|
|
|
- } else if ($country == '0') {
|
|
|
- return $ip.' 未知';
|
|
|
- } else {
|
|
|
- return $ip.' '.$country;
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 转换列表列
|
|
|
@@ -460,7 +397,7 @@ class BaseLogic
|
|
|
}
|
|
|
|
|
|
if(in_array('ip', $fields)){
|
|
|
- $data[$key]['ip'] = $this->getIpLocation($value['ip']) ?? '';
|
|
|
+ $data[$key]['ip'] = getIpLocation($value['ip']) ?? '';
|
|
|
}
|
|
|
}
|
|
|
return $data;
|
|
|
@@ -526,7 +463,7 @@ class BaseLogic
|
|
|
// 负责人
|
|
|
if (!empty($params['auth_id'])) {
|
|
|
if (is_array($params['auth_id'])) {
|
|
|
-
|
|
|
+
|
|
|
$whereSql .= " AND auth_id IN(" . implode(',', $params['auth_id']) . ")";
|
|
|
} else {
|
|
|
$whereSql .= " AND auth_id = {$params['auth_id']}";
|
|
|
@@ -538,9 +475,9 @@ class BaseLogic
|
|
|
}
|
|
|
|
|
|
// 自然量ID, auth_id=0为自然量
|
|
|
- if(!empty($params['nomal_game_id'])){
|
|
|
- for($i=0;$i<count($params['nomal_game_id']);$i++){
|
|
|
- $whereSql .= " OR (game_id = {$params['nomal_game_id'][$i]} AND auth_id=0)";
|
|
|
+ if(!empty($params['normal_game_id'])){
|
|
|
+ for($i=0;$i<count($params['normal_game_id']);$i++){
|
|
|
+ $whereSql .= " OR (game_id = {$params['normal_game_id'][$i]} AND auth_id=0)";
|
|
|
}
|
|
|
}
|
|
|
|