From 818023ed2ce2d55bb87d368bb226ee72f3d1a224 Mon Sep 17 00:00:00 2001 From: liyang <2154243450@qq.com> Date: Fri, 26 Sep 2025 15:57:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B4=B7=E6=AC=BE=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=BF=BB=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/service/UserService.php | 180 +++++++++++++++--------------- 1 file changed, 87 insertions(+), 93 deletions(-) diff --git a/app/admin/service/UserService.php b/app/admin/service/UserService.php index 3f67e311..46177e17 100644 --- a/app/admin/service/UserService.php +++ b/app/admin/service/UserService.php @@ -62,11 +62,11 @@ class UserService extends AdminBaseService $where = []; // 角色数据权限过滤: 管理员登录可查看所有用户数据;代理登录查看代理下用户数据;客服登录查看客服关联用户的数据 - $account = AdminModel::where(['id'=>$adminId])->find(); + $account = AdminModel::where(['id' => $adminId])->find(); if (empty($account)) { return $this->toData('500', '当前账号数据为空'); } - $role = AuthRoleModel::where(['id'=>$account->role_id])->find(); + $role = AuthRoleModel::where(['id' => $account->role_id])->find(); if (empty($role)) { return $this->toData('500', '当前账号分配的角色为空'); } @@ -315,7 +315,7 @@ class UserService extends AdminBaseService $sellerIds = array_keys($sellerList); } // 合并account账号,一次性查出account信息 - $accountIds = array_merge($customerIds,$groupLeaderIds,$sellerIds); + $accountIds = array_merge($customerIds, $groupLeaderIds, $sellerIds); $accountList = AdminModel::where('id', 'in', $accountIds)->column('user_name', 'id'); // 查询用户充值、提款冻结状态 @@ -330,7 +330,7 @@ class UserService extends AdminBaseService // 获取国家 $countryIds = array_column($realNameTranslation, 'country'); $countryArr = CountryModel::where('id', 'in', $countryIds)->column('name_cn', 'id'); - foreach ($realNameTranslation as $k=>$v) { + foreach ($realNameTranslation as $k => $v) { if (!empty($v['front_img'])) { $realNameTranslation[$k]['front_img'] = $imgArr[$v['front_img']] ?? ''; } @@ -379,7 +379,7 @@ class UserService extends AdminBaseService $vipExpire = $vipInfo[$item['user_id']]['expire']; } // 话务数据 - $business = BusinessLogModel::where(['uid'=>$item['user_id']])->order('id', 'desc')->find(); + $business = BusinessLogModel::where(['uid' => $item['user_id']])->order('id', 'desc')->find(); if (!empty($business)) { $business = $business->toArray(); } else { @@ -424,7 +424,7 @@ class UserService extends AdminBaseService 'stock' => $userStockList[$item['user_id']]['usable_num'] ?? '0', 'contract' => $userContractList[$item['user_id']]['usable_num'] ?? '0', 'contract_sec' => $userContractSecList[$item['user_id']]['usable_num'] ?? '0', - 'forex' => $userForexList[$item['user_id']]['usable_num'] ?? '0',//外汇 + 'forex' => $userForexList[$item['user_id']]['usable_num'] ?? '0', //外汇 'stock_idn' => $userStockIdrList[$item['user_id']]['usable_num'] ?? '0', // 印尼股票余额 'stock_tha' => $userStockThaList[$item['user_id']]['usable_num'] ?? '0', // 泰股资产 'stock_mys' => $userStockMysList[$item['user_id']]['usable_num'] ?? '0', // 马股资产 @@ -749,14 +749,14 @@ class UserService extends AdminBaseService return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => []]); } -// // 查询列表数据 -// $userList = UserModel::where('FIND_IN_SET(:id,parent_ids)', ['id' => $userId]) -// ->order('user_id', 'desc') -// ->page($param['page'], $param['limit']) -// ->select(); -// // 查询总数 -// $total = UserModel::where('FIND_IN_SET(:id,parent_ids)', ['id' => $userId]) -// ->count(); + // // 查询列表数据 + // $userList = UserModel::where('FIND_IN_SET(:id,parent_ids)', ['id' => $userId]) + // ->order('user_id', 'desc') + // ->page($param['page'], $param['limit']) + // ->select(); + // // 查询总数 + // $total = UserModel::where('FIND_IN_SET(:id,parent_ids)', ['id' => $userId]) + // ->count(); // 查询列表数据 $userList = UserModel::where($whereU) @@ -862,7 +862,6 @@ class UserService extends AdminBaseService } catch (\Exception $exception) { return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); } - } public function reg_email($param, $adminId) @@ -878,7 +877,7 @@ class UserService extends AdminBaseService if ($emailExists) { return $this->toData('100300', 'The email has already been registered.', []); } - + // 获取代理id $isAgent = AdminModel::checkUserIsAgent($adminId); if ($isAgent) { @@ -904,12 +903,12 @@ class UserService extends AdminBaseService } $customerId = $customer->id; // 查询客服的chat信息 - $customerChatInfo = UserChatLinkModel::where(['user_id'=>$customerId, 'user_type'=>UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_ADMIN])->find(); + $customerChatInfo = UserChatLinkModel::where(['user_id' => $customerId, 'user_type' => UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_ADMIN])->find(); if (empty($customerChatInfo)) { return $this->toData('500', '客服账号缺少chat信息'); } // 查询代理创建的chat群聊信息 - $agentGroup = UserChatGroupModel::where(['user_id'=>$agentId,'remark'=>UserChatGroupModel::USER_CHAT_GROUP_REMARK_ADMIN_INIT])->find(); + $agentGroup = UserChatGroupModel::where(['user_id' => $agentId, 'remark' => UserChatGroupModel::USER_CHAT_GROUP_REMARK_ADMIN_INIT])->find(); if (empty($agentGroup)) { return $this->toData('500', '当前代理还未创建chat群聊'); } @@ -921,7 +920,7 @@ class UserService extends AdminBaseService $chatData = [ 'Username' => $userNo, 'Password' => '123456', - 'Nickname' => 'user_'.explode('@', $param['email'])[0], + 'Nickname' => 'user_' . explode('@', $param['email'])[0], 'Email' => $param['email'], ]; $chatUrl = env('CHAT_SERVER.BASE_URL') . '/api/user/register'; @@ -953,11 +952,11 @@ class UserService extends AdminBaseService ]; $chatFriendsUrl = env('CHAT_SERVER.BASE_URL') . '/api/eachOtherFriends'; $chatFriendsRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatFriendsUrl, $chatFriendsData); - Log::info("admin创建用户 - 用户与客服chat_id加好友结果:".json_encode($chatFriendsRes)); + Log::info("admin创建用户 - 用户与客服chat_id加好友结果:" . json_encode($chatFriendsRes)); // 将当前用户加入到代理创建的群聊中 - $joinChatGroupUrl = env('CHAT_SERVER.BASE_URL') . '/api/group/join/'.$chatRes['data']['uuid'].'/'.$agentGroup->group_uuid; + $joinChatGroupUrl = env('CHAT_SERVER.BASE_URL') . '/api/group/join/' . $chatRes['data']['uuid'] . '/' . $agentGroup->group_uuid; $joinChatGroupRes = (new \app\utility\RequestChatServer())->ReqChatServer($joinChatGroupUrl, []); - Log::info("admin创建用户 - 用户的chat_id加入群聊结果:".json_encode($joinChatGroupRes)); + Log::info("admin创建用户 - 用户的chat_id加入群聊结果:" . json_encode($joinChatGroupRes)); (new \app\home\service\UserService())->doRegInitUserInfo($userId, $parentUserId); return $this->toData('0', 'SUCCESS'); @@ -968,7 +967,6 @@ class UserService extends AdminBaseService } catch (\Exception $exception) { return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); } - } // 实名认证操作 @@ -985,16 +983,15 @@ class UserService extends AdminBaseService return $this->toData('0', 'success', []); } -// $front = FileModel::where('id', $log->front_img)->value('path'); -// $back = FileModel::where('id', $log->back_img)->value('path'); + // $front = FileModel::where('id', $log->front_img)->value('path'); + // $back = FileModel::where('id', $log->back_img)->value('path'); if ($log->front_img) { $front = AwsS3Model::where('id', $log->front_img)->value('s3_url'); - } -// if ($log->back_img) { -// $back = AwsS3Model::where('id', $log->back_img)->value('s3_url'); -// } + // if ($log->back_img) { + // $back = AwsS3Model::where('id', $log->back_img)->value('s3_url'); + // } $country = CountryModel::where('id', $log->country)->find(); @@ -1079,7 +1076,7 @@ class UserService extends AdminBaseService } } - public function getUserLoan($param,$adminId) + public function getUserLoan($param, $adminId) { try { $where = []; @@ -1096,30 +1093,30 @@ class UserService extends AdminBaseService // 判断是否是代理 如果是代理 只能看他自己管理的用户 $where = $this->getWhereByIsAgentAndUserId($adminId, $where, $userId); - if(isset($param['status'])){ - $where['status']=intval($param['status']); + if (isset($param['status'])) { + $where['status'] = intval($param['status']); } - $data['where']=$where; + $data['where'] = $where; - $data['page']=isset($param['page']) ? intval($param['page']) : 1; - $data['size']=isset($param['size']) ? intval($param['size']) : 10; + $data['page'] = isset($param['page']) ? intval($param['page']) : 1; + $data['size'] = isset($param['limit']) ? intval($param['limit']) : 10; $list = UserLoanModel::getUserLoanList($data); - if(!empty($list['list'])){ - foreach ($list['list'] as $key=>$item){ - $user= UserModel::where('user_id', $item['user_id'])->find(); - $list['list'][$key]['nick_name']=$user->nick_name; + if (!empty($list['list'])) { + foreach ($list['list'] as $key => $item) { + $user = UserModel::where('user_id', $item['user_id'])->find(); + $list['list'][$key]['nick_name'] = $user->nick_name; } } return $this->toData('0', 'SUCCESS', $list); } catch (\Exception $exception) { - return $this->toData('1', '系统繁忙', [$exception->getMessage(),$exception->getTrace()]); + return $this->toData('1', '系统繁忙', [$exception->getMessage(), $exception->getTrace()]); } } - public function dealUserLoan($param,$adminId) + public function dealUserLoan($param, $adminId) { try { $where = []; @@ -1136,19 +1133,19 @@ class UserService extends AdminBaseService // 判断是否是代理 如果是代理 只能看他自己管理的用户 $where = $this->getWhereByIsAgentAndUserId($adminId, $where, $userId); - $where['id']=intval($param['id']); + $where['id'] = intval($param['id']); - $info=UserLoanModel::where($where)->find(); - if(empty($info)){ + $info = UserLoanModel::where($where)->find(); + if (empty($info)) { return $this->toData('1', '数据不存在'); } - if($info['status']!=0){ + if ($info['status'] != 0) { return $this->toData('1', '数据已审核'); } UserLoanModel::where($where)->update([ - 'status'=>intval($param['status']), - 'update_time'=>date('Y-m-d H:i:s') + 'status' => intval($param['status']), + 'update_time' => date('Y-m-d H:i:s') ]); return $this->toData('0', 'SUCCESS', []); @@ -1178,9 +1175,9 @@ class UserService extends AdminBaseService switch ($param['code_type']) { case 6: if ($param['business'] == 1) { - $key = 'USER:sendEmailLoginNoTrade:'.$param['search']; + $key = 'USER:sendEmailLoginNoTrade:' . $param['search']; } elseif ($param['business'] == 3) { - $key = 'USER:sendEmailLoginTrade:'.$param['search']; + $key = 'USER:sendEmailLoginTrade:' . $param['search']; } break; case 9: @@ -1196,23 +1193,23 @@ class UserService extends AdminBaseService $getCode = Cache::store('redis')->get($key); return $this->toData('0', 'success', ['extend' => $extend, 'get_code' => 1, 'code' => $getCode]); -// -// $key_12 = "DB:USER:UNLOGIN:SMS_CODE:" . $param['search']; -// $key_9 = "DB:USER:UNLOGIN:EMAIL_CODE:" . $param['search']; -// $key_7 = "USER:sendEmailLoginNoTrade:" . $param['search']; -// $key_10 = "USER:sendSmsLoginNoTrade:" . $param['search']; -// -// $key = "key_" . ($param['business'] + $param['code_type']); -// if (!isset($$key)) { -// return $this->toData('0', 'success', ['extend' => $extend, 'get_code' => 0, 'code' => '']); -// } -// -// $redis = $this->getRedis(); -// $code = $redis->get($$key); -// if ($code) { -// return $this->toData('0', 'success', ['extend' => $extend, 'get_code' => 1, 'code' => $code]); -// } -// return $this->toData('0', 'success', ['extend' => $extend, 'get_code' => 0, 'code' => '']); + // + // $key_12 = "DB:USER:UNLOGIN:SMS_CODE:" . $param['search']; + // $key_9 = "DB:USER:UNLOGIN:EMAIL_CODE:" . $param['search']; + // $key_7 = "USER:sendEmailLoginNoTrade:" . $param['search']; + // $key_10 = "USER:sendSmsLoginNoTrade:" . $param['search']; + // + // $key = "key_" . ($param['business'] + $param['code_type']); + // if (!isset($$key)) { + // return $this->toData('0', 'success', ['extend' => $extend, 'get_code' => 0, 'code' => '']); + // } + // + // $redis = $this->getRedis(); + // $code = $redis->get($$key); + // if ($code) { + // return $this->toData('0', 'success', ['extend' => $extend, 'get_code' => 1, 'code' => $code]); + // } + // return $this->toData('0', 'success', ['extend' => $extend, 'get_code' => 0, 'code' => '']); } catch (\Exception $exception) { return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); } @@ -1242,7 +1239,7 @@ class UserService extends AdminBaseService if (empty($userId) || !is_numeric($userId)) { return $this->toData('400', 'Param error user_id', [$userId]); } - $list = UserBankModel::where(['user_id'=>$param['user_id']])->select()->toArray(); + $list = UserBankModel::where(['user_id' => $param['user_id']])->select()->toArray(); return $this->toData('0', 'success', $list); } catch (\Exception $e) { return $this->toData('1', '系统异常 请稍后重试', [$e->getMessage(), $e->getTrace()]); @@ -1312,11 +1309,11 @@ class UserService extends AdminBaseService } $updateArr = []; -// $bool = 0; + // $bool = 0; if (!empty($param['login_password'])) $updateArr['login_password'] = (new UnqId())->encryptPassword($param['login_password'], $user->salt); if (!empty($param['trade_password'])) $updateArr['trade_password'] = (new UnqId())->encryptPassword($param['trade_password'], $user->salt); if (!empty($updateArr)) UserModel::where('user_id', $param['id'])->update($updateArr); -// if (empty($bool)) return $this->toData('1', '系统异常 请稍后重试', []); + // if (empty($bool)) return $this->toData('1', '系统异常 请稍后重试', []); return $this->toData('0', 'SUCCESS', []); } catch (\Exception $exception) { return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); @@ -1395,7 +1392,7 @@ class UserService extends AdminBaseService if (empty($param['user_id']) || !is_numeric($param['user_id']) || empty($param['remark'])) { return $this->toData('400', 'Missing parameter user_id'); } - $user = UserModel::where(['user_id'=>$param['user_id']])->find(); + $user = UserModel::where(['user_id' => $param['user_id']])->find(); if (empty($user)) { return $this->toData('500', '操作的用户数据错误'); } @@ -1414,7 +1411,7 @@ class UserService extends AdminBaseService if (empty($param['user_id']) || !is_numeric($param['user_id']) || empty($param['label'])) { return $this->toData('400', 'Missing parameter user_id'); } - $user = UserModel::where(['user_id'=>$param['user_id']])->find(); + $user = UserModel::where(['user_id' => $param['user_id']])->find(); if (empty($user)) { return $this->toData('500', '操作的用户数据错误'); } @@ -1422,7 +1419,7 @@ class UserService extends AdminBaseService $user->save(); // 同步更新chat服务 - $userChatInfo = UserChatLinkModel::where(['user_id'=>$user->user_id, 'user_type'=>UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_PC])->find(); + $userChatInfo = UserChatLinkModel::where(['user_id' => $user->user_id, 'user_type' => UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_PC])->find(); if (empty($userChatInfo)) { return $this->toData('500', '该用户的聊天信息错误'); } @@ -1433,7 +1430,7 @@ class UserService extends AdminBaseService $chatFriendsUrl = env('CHAT_SERVER.BASE_URL') . '/api/user'; $chatFriendsRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatFriendsUrl, $upChaData, 'PUT'); if (!isset($chatFriendsRes['code']) || !$chatFriendsRes['code'] == 0) { - return $this->toData('500', 'chat服务错误:'.$chatFriendsRes['msg']); + return $this->toData('500', 'chat服务错误:' . $chatFriendsRes['msg']); } return $this->toData('0', 'SUCCESS'); } catch (\Exception $exception) { @@ -1447,7 +1444,7 @@ class UserService extends AdminBaseService if (empty($param['user_id']) || !is_numeric($param['user_id']) || empty($param['base_label'])) { return $this->toData('400', 'Missing parameter user_id'); } - $user = UserModel::where(['user_id'=>$param['user_id']])->find(); + $user = UserModel::where(['user_id' => $param['user_id']])->find(); if (empty($user)) { return $this->toData('500', '操作的用户数据错误'); } @@ -1478,10 +1475,10 @@ class UserService extends AdminBaseService $accountFrozen = AccountFrozenModel::where('user_id', $userId)->find(); if (empty($accountFrozen)) { if (isset($param['frozen_recharge'])) { - AccountFrozenModel::create(['user_id'=>$userId, 'frozen_recharge' => $param['frozen_recharge']]); + AccountFrozenModel::create(['user_id' => $userId, 'frozen_recharge' => $param['frozen_recharge']]); } if (isset($param['frozen_withdraw'])) { - AccountFrozenModel::create(['user_id'=>$userId, 'frozen_withdraw' => $param['frozen_withdraw']]); + AccountFrozenModel::create(['user_id' => $userId, 'frozen_withdraw' => $param['frozen_withdraw']]); } } else { if (isset($param['frozen_recharge'])) { @@ -1513,7 +1510,7 @@ class UserService extends AdminBaseService return $this->toData('1', '用户不存在'); } // 检测用户阶段数据 - $userStageState = UserStageStateModel::where(['user_id'=>$user['user_id']])->find(); + $userStageState = UserStageStateModel::where(['user_id' => $user['user_id']])->find(); if (empty($userStageState)) { UserStageStateModel::create([ 'user_id' => $user['user_id'], @@ -1525,14 +1522,14 @@ class UserService extends AdminBaseService 'third_stage_state' => $param['third_stage_state'] ?? 0, ]); } else { - if (isset($param['first_stage'])) { - $userStageState->first_stage = $param['first_stage']; - $userStageState->first_stage_state = $param['first_stage_state'] ?? 0; - } - if (isset($param['second_stage'])) { - $userStageState->second_stage = $param['second_stage']; - $userStageState->second_stage_state = $param['second_stage_state'] ?? 0; - } + if (isset($param['first_stage'])) { + $userStageState->first_stage = $param['first_stage']; + $userStageState->first_stage_state = $param['first_stage_state'] ?? 0; + } + if (isset($param['second_stage'])) { + $userStageState->second_stage = $param['second_stage']; + $userStageState->second_stage_state = $param['second_stage_state'] ?? 0; + } if (isset($param['third_stage'])) { $userStageState->third_stage = $param['third_stage']; $userStageState->third_stage_state = $param['third_stage_state'] ?? 0; @@ -1607,7 +1604,7 @@ class UserService extends AdminBaseService if (empty($param['business_id']) || empty($param['reply_content'])) { return $this->toData('400', '参错错误'); } - $info = BusinessLogModel::where(['id'=>$param['business_id']])->find(); + $info = BusinessLogModel::where(['id' => $param['business_id']])->find(); if (empty($info)) { return $this->toData('500', '数据不存在'); } @@ -1639,11 +1636,11 @@ class UserService extends AdminBaseService return $this->toData('400', '缺少uid'); } // 获取用户信息 - $userInfo = UserModel::where(['user_id'=>$param['user_id']])->find(); + $userInfo = UserModel::where(['user_id' => $param['user_id']])->find(); if (empty($userInfo)) { return $this->toData('500', '用户信息错误'); } - $where = ['uid'=>$param['user_id']]; + $where = ['uid' => $param['user_id']]; if (!empty($param['is_reply']) && $param['is_reply'] < 2) { $where['is_reply'] = $param['is_reply']; // 根据回复状态过滤:0-未回复的; 1-已经回复的; 2-全部 } @@ -1686,10 +1683,10 @@ class UserService extends AdminBaseService if (!empty($list->items())) { foreach ($list->items() as $v) { $tmp = $v; - $userInfo = UserModel::where(['user_id'=>$v['user_id']])->find(); + $userInfo = UserModel::where(['user_id' => $v['user_id']])->find(); if (!empty($userInfo)) { $tmp['user_info'] = $userInfo->toArray(); - } else{ + } else { $tmp['user_info'] = []; } $data[] = $tmp; @@ -1706,7 +1703,4 @@ class UserService extends AdminBaseService return $this->toData('500', '系统异常 请稍后重试', [$e->getMessage(), $e->getTrace()]); } } - } - -