|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\admin\service;
|
|
|
|
|
|
|
|
use app\admin\validate\UserValidate;
|
|
|
|
use app\home\service\BaseHomeService;
|
|
|
|
use app\model\AccountFrozenModel;
|
|
|
|
use app\model\AdminModel;
|
|
|
|
use app\model\AuthRoleModel;
|
|
|
|
use app\model\AwsS3Model;
|
|
|
|
use app\model\CountryModel;
|
|
|
|
use app\model\StockMarketModel;
|
|
|
|
use app\model\UserBankModel;
|
|
|
|
use app\model\UserChatGroupModel;
|
|
|
|
use app\model\UserChatLinkModel;
|
|
|
|
use app\model\UserContractModel;
|
|
|
|
use app\model\UserContractSecModel;
|
|
|
|
use app\model\UserDigitalModel;
|
|
|
|
use app\model\UserForexModel;
|
|
|
|
use app\model\UserLoanModel;
|
|
|
|
use app\model\UserLoginLog;
|
|
|
|
use app\model\UserMarketModel;
|
|
|
|
use app\model\UserModel;
|
|
|
|
use app\model\UserStageStateModel;
|
|
|
|
use app\model\UserStockBrlModel;
|
|
|
|
use app\model\UserStockEurModel;
|
|
|
|
use app\model\UserStockFurModel;
|
|
|
|
use app\model\UserStockGBXModel;
|
|
|
|
use app\model\UserStockHkdModel;
|
|
|
|
use app\model\UserStockIdnModel;
|
|
|
|
use app\model\UserStockIndexInrModel;
|
|
|
|
use app\model\UserStockInModel;
|
|
|
|
use app\model\UserStockJpModel;
|
|
|
|
use app\model\UserStockModel;
|
|
|
|
use app\model\UserStockMysModel;
|
|
|
|
use app\model\UserStockOptionInrModel;
|
|
|
|
use app\model\UserStockSgdModel;
|
|
|
|
use app\model\UserStockThaModel;
|
|
|
|
use app\model\UserVerifyLogModel;
|
|
|
|
use app\model\UserStockFundModel;
|
|
|
|
use think\exception\ValidateException;
|
|
|
|
use app\utility\UnqId;
|
|
|
|
use think\facade\Cache;
|
|
|
|
use think\facade\Log;
|
|
|
|
|
|
|
|
class UserService extends AdminBaseService
|
|
|
|
{
|
|
|
|
|
|
|
|
// 用户列表
|
|
|
|
public function index($param, $adminId)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
// 参数校验
|
|
|
|
validate(UserValidate::class)->scene('index')->check($param);
|
|
|
|
|
|
|
|
$where = [];
|
|
|
|
|
|
|
|
// 角色数据权限过滤: 管理员登录可查看所有用户数据;代理登录查看代理下用户数据;客服登录查看客服关联用户的数据
|
|
|
|
$account = AdminModel::where(['id'=>$adminId])->find();
|
|
|
|
if (empty($account)) {
|
|
|
|
return $this->toData('500', '当前账号数据错误');
|
|
|
|
}
|
|
|
|
$role = AuthRoleModel::where(['id'=>$account->role_id])->find();
|
|
|
|
if (empty($role)) {
|
|
|
|
return $this->toData('500', '当前角色数据错误');
|
|
|
|
}
|
|
|
|
|
|
|
|
// 如果是代理,过滤代理下的用户
|
|
|
|
if ($role->name == AuthRoleModel::NAME_AGENT) {
|
|
|
|
$where['agent_id'] = $adminId;
|
|
|
|
}
|
|
|
|
// 如果是客服,过滤客服下的用户
|
|
|
|
if ($role->name == AuthRoleModel::NAME_CUSTOMER) {
|
|
|
|
$where['customer_id'] = $adminId;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// base_label过滤
|
|
|
|
if (!empty($param['base_label'])) {
|
|
|
|
$where['base_label'] = trim($param['base_label']);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 用户标签状态过滤
|
|
|
|
$cdt = [];
|
|
|
|
if (isset($param['first_stage_state'])) {
|
|
|
|
$filterUserIds = UserStageStateModel::where(['first_stage_state' => $param['first_stage_state']])->column('user_id');
|
|
|
|
}
|
|
|
|
if (isset($param['second_stage_state'])) {
|
|
|
|
$filterUserIds = UserStageStateModel::where(['second_stage_state' => $param['second_stage_state']])->column('user_id');
|
|
|
|
}
|
|
|
|
if (isset($param['third_stage_state'])) {
|
|
|
|
$filterUserIds = UserStageStateModel::where(['third_stage_state' => $param['third_stage_state']])->column('user_id');
|
|
|
|
}
|
|
|
|
if (!empty($filterUserIds)) {
|
|
|
|
$cdt[] = ['user_id', 'in', $filterUserIds];
|
|
|
|
}
|
|
|
|
|
|
|
|
// 邮箱搜索
|
|
|
|
if (!empty($param['email']) && trim($param['email'])) {
|
|
|
|
$where['email'] = $param['email'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// 用户审核状态筛选
|
|
|
|
if (!empty($param['real_status']) && is_numeric($param['real_status'])) {
|
|
|
|
$where['real_status'] = $param['real_status'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// 用户号
|
|
|
|
if (!empty($param['user_no']) && trim($param['user_no'])) {
|
|
|
|
$where['user_no'] = $param['user_no'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// 手机号搜索
|
|
|
|
if (!empty($param['phone']) && trim($param['phone'])) {
|
|
|
|
$where['phone_number'] = $param['phone'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// 用户审核状态筛选
|
|
|
|
if (!empty($param['agent_id']) && is_numeric($param['agent_id'])) {
|
|
|
|
$where['agent_id'] = $param['agent_id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
//邀请码
|
|
|
|
if (!empty($param['invite_code']) && trim($param['invite_code'])) {
|
|
|
|
$where['invite_code'] = $param['invite_code'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// 杠杆申请状态
|
|
|
|
if (!empty($param['leve_status']) && is_numeric($param['leve_status'])) {
|
|
|
|
$where['leve_status'] = $param['leve_status'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// 测试用户
|
|
|
|
if (!empty($param['is_test_user']) && is_numeric($param['is_test_user'])) {
|
|
|
|
$where['is_test_user'] = $param['is_test_user'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// 注册时间
|
|
|
|
if (!empty($param['start_time']) && !empty($param['end_time'])) {
|
|
|
|
$where['create_time'] = ['between time', [$param['start_time'], $param['end_time']]];
|
|
|
|
}
|
|
|
|
|
|
|
|
$IsAgent = AdminModel::checkUserIsAgent($adminId);
|
|
|
|
$agentNameArr = AdminModel::where('role_id', 10)->column('user_name', 'id');
|
|
|
|
|
|
|
|
$marketRate = StockMarketModel::column('rate', 'stock_market_type');
|
|
|
|
$tapeList = (new StockMarketModel)->getAllTape();
|
|
|
|
// 父级用户号
|
|
|
|
if (!empty($param['parent_user_no']) && trim($param['parent_user_no'])) {
|
|
|
|
$parentUser = UserModel::where('user_no', $param['parent_user_no'])->find();
|
|
|
|
if (empty($parentUser)) {
|
|
|
|
return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => [], 'extent' => ['market_type_list' => StockMarketModel::STOCK_MARKET_TYPE, 'is_agent' => $IsAgent, 'agent_list' => $agentNameArr, 'market_rate' => $marketRate, 'market_tape_list' => $tapeList]]);
|
|
|
|
}
|
|
|
|
$where['parent_id'] = $parentUser->user_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($where['user_id']) && is_numeric($where['user_id']) && $where['user_id'] == 0) {
|
|
|
|
return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => [], 'extent' => ['market_type_list' => StockMarketModel::STOCK_MARKET_TYPE, 'is_agent' => $IsAgent, 'agent_list' => $agentNameArr, 'market_rate' => $marketRate, 'market_tape_list' => $tapeList]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$whereU = $this->getWhereByIsAgentAndUserId($adminId, [], 0);
|
|
|
|
if (!is_array($whereU)) {
|
|
|
|
return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => [], 'extent' => ['market_type_list' => StockMarketModel::STOCK_MARKET_TYPE, 'is_agent' => $IsAgent, 'agent_list' => $agentNameArr, 'market_rate' => $marketRate, 'market_tape_list' => $tapeList]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$userList = UserModel::where($where)->where($cdt)->where($whereU)->page($param['page'], $param['limit'])->order('user_id', 'desc')->select();
|
|
|
|
if (empty($userList)) {
|
|
|
|
return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => [], 'extent' => ['market_type_list' => StockMarketModel::STOCK_MARKET_TYPE, 'is_agent' => $IsAgent, 'agent_list' => $agentNameArr, 'market_rate' => $marketRate, 'market_tape_list' => $tapeList]]);
|
|
|
|
}
|
|
|
|
$total = UserModel::where($where)->where($cdt)->where($whereU)->count();
|
|
|
|
|
|
|
|
|
|
|
|
$rows = [];
|
|
|
|
$userIdArr = [];
|
|
|
|
$parentIdArr = [];
|
|
|
|
$customerRelationList = [];
|
|
|
|
foreach ($userList as $value) {
|
|
|
|
$userIdArr[] = $value['user_id'];
|
|
|
|
if ($value['parent_id'] > 0) {
|
|
|
|
$parentIdArr[] = $value['parent_id'];
|
|
|
|
}
|
|
|
|
if (!empty($value['customer_id'])) {
|
|
|
|
$customerRelationList[$value['user_id']] = $value['customer_id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 查询父级
|
|
|
|
$parentNos = UserModel::where('user_id', 'in', $parentIdArr)->column('user_no', 'user_id');
|
|
|
|
|
|
|
|
// 查询用户余额
|
|
|
|
$userContractList = UserContractModel::where('user_id', 'in', $userIdArr)
|
|
|
|
->where('contract_id', 'USDT')
|
|
|
|
->column('usable_num,frozen_num', 'user_id');
|
|
|
|
// 查询用户余额
|
|
|
|
$userContractSecList = UserContractSecModel::where('user_id', 'in', $userIdArr)
|
|
|
|
->where('contract_id', 'USDT')
|
|
|
|
->column('usable_num,frozen_num', 'user_id');
|
|
|
|
$userStockList = UserStockModel::where('user_id', 'in', $userIdArr)
|
|
|
|
->where('stock_id', 'USD')
|
|
|
|
->column('usable_num,frozen_num', 'user_id');
|
|
|
|
$userDigitalList = UserDigitalModel::where('user_id', 'in', $userIdArr)
|
|
|
|
->where('digital_id', 'USDT')
|
|
|
|
->column('usable_num,frozen_num', 'user_id');
|
|
|
|
|
|
|
|
// 印尼资产
|
|
|
|
$userStockIdrList = UserStockIdnModel::where('user_id', 'in', $userIdArr)
|
|
|
|
->where('stock_id', 'IDR')
|
|
|
|
->column('usable_num,frozen_num', 'user_id');
|
|
|
|
|
|
|
|
// 泰股资产
|
|
|
|
$userStockThaList = UserStockThaModel::where('user_id', 'in', $userIdArr)
|
|
|
|
->where('stock_id', 'THB')
|
|
|
|
->column('usable_num,frozen_num', 'user_id');
|
|
|
|
|
|
|
|
// 马股资产
|
|
|
|
$userStockMysList = UserStockMysModel::where('user_id', 'in', $userIdArr)
|
|
|
|
->where('stock_id', 'MYR')
|
|
|
|
->column('usable_num,frozen_num', 'user_id');
|
|
|
|
|
|
|
|
// 印度股票资产
|
|
|
|
$userStockInList = UserStockInModel::where('user_id', 'in', $userIdArr)
|
|
|
|
->where('stock_id', 'INR')
|
|
|
|
->column('usable_num,frozen_num', 'user_id');
|
|
|
|
// 印度股指资产
|
|
|
|
$userStockIndexInrList = UserStockIndexInrModel::where('user_id', 'in', $userIdArr)
|
|
|
|
->where('contract_id', 'INR')
|
|
|
|
->column('usable_num,frozen_num', 'user_id');
|
|
|
|
//新加坡股票资产
|
|
|
|
$userStockSGDList = UserStockSgdModel::where('user_id', 'in', $userIdArr)
|
|
|
|
->where('stock_id', 'SGD')
|
|
|
|
->column('usable_num,frozen_num', 'user_id');
|
|
|
|
//基金资产
|
|
|
|
$userStockFundList = UserStockFundModel::where('user_id', 'in', $userIdArr)
|
|
|
|
->where('stock_id', 'USD')
|
|
|
|
->column('usable_num,frozen_num', 'user_id');
|
|
|
|
//印度期权
|
|
|
|
$userStockOptionInrList = UserStockOptionInrModel::where('user_id', 'in', $userIdArr)
|
|
|
|
->where('stock_id', 'INR')
|
|
|
|
->column('usable_num,frozen_num', 'user_id');
|
|
|
|
//港股
|
|
|
|
$userStockHkList = UserStockHkdModel::where('user_id', 'in', $userIdArr)
|
|
|
|
->where('stock_id', 'HKD')
|
|
|
|
->column('usable_num,frozen_num', 'user_id');
|
|
|
|
//英股
|
|
|
|
$userStockUkList = UserStockGBXModel::where('user_id', 'in', $userIdArr)
|
|
|
|
->where('stock_id', 'GBX')
|
|
|
|
->column('usable_num,frozen_num', 'user_id');
|
|
|
|
//法股
|
|
|
|
$userStockFurList = UserStockFurModel::where('user_id', 'in', $userIdArr)
|
|
|
|
->where('stock_id', 'EUR')
|
|
|
|
->column('usable_num,frozen_num', 'user_id');
|
|
|
|
//德股
|
|
|
|
$userStockEurList = UserStockEurModel::where('user_id', 'in', $userIdArr)
|
|
|
|
->where('stock_id', 'EUR')
|
|
|
|
->column('usable_num,frozen_num', 'user_id');
|
|
|
|
//巴西
|
|
|
|
$userStockBrlList = UserStockBrlModel::where('user_id', 'in', $userIdArr)
|
|
|
|
->where('stock_id', 'BRL')
|
|
|
|
->column('usable_num,frozen_num', 'user_id');
|
|
|
|
|
|
|
|
$userStockJpList = UserStockJpModel::where('user_id', 'in', $userIdArr)
|
|
|
|
->where('stock_id', 'JPY')
|
|
|
|
->column('usable_num,frozen_num', 'user_id');
|
|
|
|
//外汇
|
|
|
|
$userForexList = UserForexModel::where('user_id', 'in', $userIdArr)
|
|
|
|
->where('contract_id', 'USD')
|
|
|
|
->column('usable_num,frozen_num', 'user_id');
|
|
|
|
|
|
|
|
// 获取每个客服的名称
|
|
|
|
$customerNames = [];
|
|
|
|
if ($customerRelationList) {
|
|
|
|
$customerIds = array_values($customerRelationList);
|
|
|
|
$customerNames = AdminModel::where('id', 'in', $customerIds)->column('nick_name', 'id');
|
|
|
|
}
|
|
|
|
|
|
|
|
// 查询用户充值、提款冻结状态
|
|
|
|
$accountFrozenList = AccountFrozenModel::where('user_id', 'in', $userIdArr)->column('frozen_recharge,frozen_withdraw', 'user_id');
|
|
|
|
|
|
|
|
// 用户实名认证信息
|
|
|
|
$realNameTranslation = UserVerifyLogModel::where('user_id', 'in', $userIdArr)->column('user_id,name,code,front_img,back_img,status,country', 'user_id');
|
|
|
|
if ($realNameTranslation) {
|
|
|
|
// 获取s3图片
|
|
|
|
$frontImgIds = array_column($realNameTranslation, 'front_img');
|
|
|
|
$imgArr = AwsS3Model::where('id', 'in', $frontImgIds)->column('s3_url', 'id');
|
|
|
|
// 获取国家
|
|
|
|
$countryIds = array_column($realNameTranslation, 'country');
|
|
|
|
$countryArr = CountryModel::where('id', 'in', $countryIds)->column('name_cn', 'id');
|
|
|
|
foreach ($realNameTranslation as $k=>$v) {
|
|
|
|
if (!empty($v['front_img'])) {
|
|
|
|
$realNameTranslation[$k]['front_img'] = $imgArr[$v['front_img']] ?? '';
|
|
|
|
}
|
|
|
|
if (!empty($v['country'])) {
|
|
|
|
$realNameTranslation[$k]['country'] = $countryArr[$v['country']] ?? '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 用户阶段信息
|
|
|
|
$userStageStateList = UserStageStateModel::where('user_id', 'in', $userIdArr)->column('first_stage,first_stage_state,second_stage,second_stage_state,third_stage,third_stage_state', 'user_id');
|
|
|
|
|
|
|
|
//最近登录IP、最近登录国家
|
|
|
|
$subQuery = UserLoginLog::field('user_id,MAX(login_date) AS last_login_date')
|
|
|
|
->where('user_id', 'in', $userIdArr)->group('user_id')->buildSql();
|
|
|
|
$lastLoginLog = UserLoginLog::alias('a')->field('a.id')
|
|
|
|
->join([$subQuery => 'w'], 'a.user_id=w.user_id AND a.login_date=w.last_login_date')->column(['id', 'ip', 'country', 'city'], 'a.user_id');
|
|
|
|
|
|
|
|
foreach ($userList as $item) {
|
|
|
|
$itmCustomerId = $customerRelationList[$item['user_id']] ?? 0; //当前用户关联的客服ID
|
|
|
|
$itmCustomerName = "";
|
|
|
|
if ($itmCustomerId) {
|
|
|
|
$itmCustomerName = $customerNames[$itmCustomerId] ?? ""; //当前客服的名称
|
|
|
|
}
|
|
|
|
|
|
|
|
$rows[] = [
|
|
|
|
'id' => $item['user_id'],
|
|
|
|
'user_no' => $item['user_no'],
|
|
|
|
'nickname' => $item['nick_name'],
|
|
|
|
'regTime' => $item['create_time'],
|
|
|
|
'parentNo' => $parentNos[$item['parent_id']] ?? '-',
|
|
|
|
'parent_id' => $item['parent_id'],
|
|
|
|
'invite_code' => $item['invite_code'],
|
|
|
|
'email' => $item['email'],
|
|
|
|
'mobile' => $item['country_code'] . '-' . $item['phone_number'],
|
|
|
|
'customer_remark' => $item['customer_remark'],
|
|
|
|
'label' => $item['label'],
|
|
|
|
'base_label' => $item['base_label'],
|
|
|
|
'customer_id' => $itmCustomerId,
|
|
|
|
'customer_name' => $itmCustomerName,
|
|
|
|
'real_name_translation' => $realNameTranslation[$item['user_id']] ?? [],
|
|
|
|
'frozen_recharge' => $accountFrozenList[$item['user_id']]['frozen_recharge'] ?? 0,
|
|
|
|
'frozen_withdraw' => $accountFrozenList[$item['user_id']]['frozen_withdraw'] ?? 0,
|
|
|
|
'first_stage' => $userStageStateList[$item['user_id']]['first_stage'] ?? '',
|
|
|
|
'first_stage_state' => $userStageStateList[$item['user_id']]['first_stage_state'] ?? 0,
|
|
|
|
'second_stage' => $userStageStateList[$item['user_id']]['second_stage'] ?? '',
|
|
|
|
'second_stage_state' => $userStageStateList[$item['user_id']]['second_stage_state'] ?? 0,
|
|
|
|
'third_stage' => $userStageStateList[$item['user_id']]['third_stage'] ?? '',
|
|
|
|
'third_stage_state' => $userStageStateList[$item['user_id']]['third_stage_state'] ?? 0,
|
|
|
|
|
|
|
|
//余额
|
|
|
|
'digital' => $userDigitalList[$item['user_id']]['usable_num'] ?? '0',
|
|
|
|
'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',//外汇
|
|
|
|
'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', // 马股资产
|
|
|
|
'stock_in' => $userStockInList[$item['user_id']]['usable_num'] ?? '0', // 印度股资产
|
|
|
|
'stock_index_inr' => $userStockIndexInrList[$item['user_id']]['usable_num'] ?? '0', //印度股指资产
|
|
|
|
'stock_sgd' => $userStockSGDList[$item['user_id']]['usable_num'] ?? '0', // 新加坡股资产
|
|
|
|
'stock_fund' => $userStockFundList[$item['user_id']]['usable_num'] ?? '0', // 基金资产
|
|
|
|
'stock_option_in' => $userStockOptionInrList[$item['user_id']]['usable_num'] ?? '0', // 印度期权资产
|
|
|
|
'stock_hk' => $userStockHkList[$item['user_id']]['usable_num'] ?? '0', // 香港股资产
|
|
|
|
'stock_uk' => $userStockUkList[$item['user_id']]['usable_num'] ?? '0', // 英股资产
|
|
|
|
'stock_fur' => $userStockFurList[$item['user_id']]['usable_num'] ?? '0', // 法股资产
|
|
|
|
'stock_eur' => $userStockEurList[$item['user_id']]['usable_num'] ?? '0', // 德股资产
|
|
|
|
'stock_brl' => $userStockBrlList[$item['user_id']]['usable_num'] ?? '0', // 巴西股资产
|
|
|
|
'stock_jp' => $userStockJpList[$item['user_id']]['usable_num'] ?? '0', // 巴西股资产
|
|
|
|
|
|
|
|
//冻结资金
|
|
|
|
'digital_frozen' => $userDigitalList[$item['user_id']]['frozen_num'] ?? '0',
|
|
|
|
'stock_frozen' => $userStockList[$item['user_id']]['frozen_num'] ?? '0',
|
|
|
|
'contract_frozen' => $userContractList[$item['user_id']]['frozen_num'] ?? '0',
|
|
|
|
'forex_frozen' => $userForexList[$item['user_id']]['frozen_num'] ?? '0',
|
|
|
|
'contract_sec_frozen' => $userContractSecList[$item['user_id']]['frozen_num'] ?? '0',
|
|
|
|
'stock_idn_frozen' => $userStockIdrList[$item['user_id']]['frozen_num'] ?? '0', // 印尼股票余额
|
|
|
|
'stock_tha_frozen' => $userStockThaList[$item['user_id']]['frozen_num'] ?? '0', // 泰股资产
|
|
|
|
'stock_mys_frozen' => $userStockMysList[$item['user_id']]['frozen_num'] ?? '0', // 马股资产
|
|
|
|
'stock_in_frozen' => $userStockInList[$item['user_id']]['frozen_num'] ?? '0', // 印度股资产
|
|
|
|
'stock_index_inr_frozen' => $userStockIndexInrList[$item['user_id']]['frozen_num'] ?? '0', // 印度股指资产资产
|
|
|
|
'stock_sgd_frozen' => $userStockSGDList[$item['user_id']]['frozen_num'] ?? '0', // 新加坡股资产
|
|
|
|
'stock_fund_frozen' => $userStockFundList[$item['user_id']]['frozen_num'] ?? '0', // 基金资产
|
|
|
|
'stock_option_in_frozen' => $userStockOptionInrList[$item['user_id']]['frozen_num'] ?? '0', // 印度期权资产
|
|
|
|
'stock_hk_frozen' => $userStockHkList[$item['user_id']]['frozen_num'] ?? '0', // 香港股资产
|
|
|
|
'stock_uk_frozen' => $userStockUkList[$item['user_id']]['frozen_num'] ?? '0', // 英港股资产
|
|
|
|
'stock_fur_frozen' => $userStockFurList[$item['user_id']]['frozen_num'] ?? '0', // 法股资产
|
|
|
|
'stock_eur_frozen' => $userStockEurList[$item['user_id']]['frozen_num'] ?? '0', // 德股资产
|
|
|
|
'stock_brl_frozen' => $userStockBrlList[$item['user_id']]['frozen_num'] ?? '0', // 德股资产
|
|
|
|
'stock_jp_frozen' => $userStockJpList[$item['user_id']]['frozen_num'] ?? '0', // 德股资产
|
|
|
|
|
|
|
|
'rechargeAmount' => 0,
|
|
|
|
'withdrawalAmount' => 0,
|
|
|
|
'regIp' => $item['reg_ip'],
|
|
|
|
'status' => $item['status'],
|
|
|
|
'statusName' => UserModel::$statusMap[$item['status']] ?? '-',
|
|
|
|
'loginTime' => $item['last_login_time'],
|
|
|
|
'is_real' => $item['is_real'],
|
|
|
|
'real_status' => $item['real_status'],
|
|
|
|
'lever_status' => $item['lever_status'],
|
|
|
|
'is_test_user' => $item['is_test_user'],
|
|
|
|
'is_test_user_text' => UserModel::$isTestUserMap[$item['is_test_user']] ?? '-',
|
|
|
|
'last_ip' => $lastLoginLog[$item['user_id']]['ip'] ?? '-',
|
|
|
|
'last_country' => empty($lastLoginLog[$item['user_id']]['country']) ? '-' : json_decode($lastLoginLog[$item['user_id']]['country'], true)['en'],
|
|
|
|
'agent_id' => $item['agent_id'],
|
|
|
|
'agent_name' => $item['agent_id'] > 0 ? $agentNameArr[$item['agent_id']] ?? '-' : '-',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows, 'extent' => ['market_type_list' => StockMarketModel::STOCK_MARKET_TYPE, 'is_agent' => $IsAgent, 'agent_list' => $agentNameArr, 'market_rate' => $marketRate, 'market_tape_list' => $tapeList]]);
|
|
|
|
} catch (ValidateException $validateException) {
|
|
|
|
// 参数校验失败
|
|
|
|
$message = $validateException->getError();
|
|
|
|
return $this->toData('1', $message);
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 修改用户状态
|
|
|
|
public function status($param, $adminId)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
// 参数校验
|
|
|
|
validate(UserValidate::class)->scene('status')->check($param);
|
|
|
|
$userId = $param['id'];
|
|
|
|
$status = $param['status'];
|
|
|
|
$user = UserModel::where('user_id', $userId)->find();
|
|
|
|
if (empty($user)) {
|
|
|
|
return $this->toData('1', '用户不存在');
|
|
|
|
}
|
|
|
|
|
|
|
|
$bool = $this->checkUserIdInAgent($adminId, $userId);
|
|
|
|
if (!$bool) {
|
|
|
|
return $this->toData('1', '无权操作');
|
|
|
|
}
|
|
|
|
|
|
|
|
UserModel::update(['status' => $status], ['user_id' => $userId]);
|
|
|
|
// 强制推出登录
|
|
|
|
if ($status != UserModel::STATUS_ON) {
|
|
|
|
(new BaseHomeService())->delUserTokenCache($userId);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->toData('0', 'SUCCESS');
|
|
|
|
} catch (ValidateException $validateException) {
|
|
|
|
// 参数校验失败
|
|
|
|
$message = $validateException->getError();
|
|
|
|
return $this->toData('1', $message);
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 资产修改
|
|
|
|
public function change($param, $adminId)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
// 参数校验
|
|
|
|
validate(UserValidate::class)->scene('change')->check($param);
|
|
|
|
|
|
|
|
// 手动判断额度是否有效
|
|
|
|
if (empty($param['amount']) || !preg_match('/^[0-9]+(.[0-9]{0,18})?$/', $param['amount'])) {
|
|
|
|
return $this->toData('1', '调整额度格式错误');
|
|
|
|
}
|
|
|
|
|
|
|
|
$userId = $param['id'];
|
|
|
|
$type = $param['type']; // 1 现货 2 合约 3 股票
|
|
|
|
$amount = $param['amount']; // 调整为
|
|
|
|
$user = UserModel::where('user_id', $userId)->find();
|
|
|
|
if (empty($user)) {
|
|
|
|
return $this->toData('1', '用户不存在');
|
|
|
|
}
|
|
|
|
$bool = AdminModel::checkUserIsAgent($adminId);
|
|
|
|
if ($bool) {
|
|
|
|
return $this->toData('1', '无权操作');
|
|
|
|
}
|
|
|
|
|
|
|
|
$rate = 0;
|
|
|
|
$marketArr = StockMarketModel::column('rate', 'unit');
|
|
|
|
|
|
|
|
// 查询账户余额
|
|
|
|
switch ($param['type']) {
|
|
|
|
case '1': //现货
|
|
|
|
$originMoney = UserDigitalModel::where('user_id', $param['id'])->value('usable_num');
|
|
|
|
$rate = 1;
|
|
|
|
break;
|
|
|
|
case '2': //合约
|
|
|
|
$originMoney = UserContractModel::where('user_id', $param['id'])->value('usable_num');
|
|
|
|
$rate = 1;
|
|
|
|
break;
|
|
|
|
case '3': //美股
|
|
|
|
$originMoney = UserStockModel::where('user_id', $param['id'])
|
|
|
|
->where('stock_id', 'USD')
|
|
|
|
->value('usable_num');
|
|
|
|
if (empty($originMoney)) { // 没有资产记录时候新增一条默认记录
|
|
|
|
UserStockModel::create([
|
|
|
|
'user_id' => $param['id'],
|
|
|
|
'stock_id' => 'USD',
|
|
|
|
'usable_num' => 0,
|
|
|
|
'frozen_num' => 0,
|
|
|
|
'create_time' => date("Y-m-d H:i:s"),
|
|
|
|
'update_time' => date("Y-m-d H:i:s"),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
$originMoney = UserStockModel::where('user_id', $param['id'])
|
|
|
|
->where('stock_id', 'USD')
|
|
|
|
->value('usable_num');
|
|
|
|
$rate = $marketArr['USD'] ?? 0;
|
|
|
|
break;
|
|
|
|
case '4':
|
|
|
|
$originMoney = UserStockIdnModel::where('user_id', $param['id'])
|
|
|
|
->where('stock_id', 'IDR')
|
|
|
|
->value('usable_num');
|
|
|
|
$rate = $marketArr['IDR'] ?? 0;
|
|
|
|
break;
|
|
|
|
case '5':
|
|
|
|
$originMoney = UserStockMysModel::where('user_id', $param['id'])
|
|
|
|
->where('stock_id', 'MYR')
|
|
|
|
->value('usable_num');
|
|
|
|
$rate = $marketArr['MYR'] ?? 0;
|
|
|
|
break;
|
|
|
|
case '6':
|
|
|
|
$originMoney = UserStockThaModel::where('user_id', $param['id'])
|
|
|
|
->where('stock_id', 'THB')
|
|
|
|
->value('usable_num');
|
|
|
|
$rate = $marketArr['THB'] ?? 0;
|
|
|
|
break;
|
|
|
|
case '7':
|
|
|
|
$originMoney = UserStockInModel::where('user_id', $param['id'])
|
|
|
|
->where('stock_id', 'INR')
|
|
|
|
->value('usable_num');
|
|
|
|
$rate = $marketArr['INR'] ?? 0;
|
|
|
|
break;
|
|
|
|
case '8': //秒合约
|
|
|
|
$originMoney = UserContractSecModel::where('user_id', $param['id'])->value('usable_num');
|
|
|
|
$rate = 1;
|
|
|
|
break;
|
|
|
|
case '9':
|
|
|
|
$originMoney = UserStockSgdModel::where('user_id', $param['id'])
|
|
|
|
->where('stock_id', 'SGD')
|
|
|
|
->value('usable_num');
|
|
|
|
$rate = $marketArr['SGD'] ?? 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '10':
|
|
|
|
$originMoney = UserStockFundModel::where('user_id', $param['id'])
|
|
|
|
->where('stock_id', 'USD')
|
|
|
|
->value('usable_num');
|
|
|
|
$rate = $marketArr['USD'] ?? 0;
|
|
|
|
break;
|
|
|
|
case '11':
|
|
|
|
$originMoney = UserStockOptionInrModel::where('user_id', $param['id'])
|
|
|
|
->where('stock_id', 'INR')
|
|
|
|
->value('usable_num');
|
|
|
|
$rate = $marketArr['INR'] ?? 0;
|
|
|
|
break;
|
|
|
|
case '12':
|
|
|
|
$originMoney = UserStockHkdModel::where('user_id', $param['id'])
|
|
|
|
->where('stock_id', 'HKD')
|
|
|
|
->value('usable_num');
|
|
|
|
$rate = $marketArr['HKD'] ?? 0;
|
|
|
|
break;
|
|
|
|
case '14':
|
|
|
|
$originMoney = UserStockGBXModel::where('user_id', $param['id'])
|
|
|
|
->where('stock_id', 'GBX')
|
|
|
|
->value('usable_num');
|
|
|
|
$rate = $marketArr['GBX'] ?? 0;
|
|
|
|
break;
|
|
|
|
case '15':
|
|
|
|
$originMoney = UserStockFurModel::where('user_id', $param['id'])
|
|
|
|
->where('stock_id', 'EUR')
|
|
|
|
->value('usable_num');
|
|
|
|
$rate = $marketArr['EUR'] ?? 0;
|
|
|
|
break;
|
|
|
|
case '16':
|
|
|
|
$originMoney = UserStockEurModel::where('user_id', $param['id'])
|
|
|
|
->where('stock_id', 'EUR')
|
|
|
|
->value('usable_num');
|
|
|
|
$rate = $marketArr['EUR'] ?? 0;
|
|
|
|
break;
|
|
|
|
case '17':
|
|
|
|
$originMoney = UserStockBrlModel::where('user_id', $param['id'])
|
|
|
|
->where('stock_id', 'BRL')
|
|
|
|
->value('usable_num');
|
|
|
|
$rate = $marketArr['BRL'] ?? 0;
|
|
|
|
break;
|
|
|
|
case '18':
|
|
|
|
$originMoney = UserStockJpModel::where('user_id', $param['id'])
|
|
|
|
->where('stock_id', 'JPY')
|
|
|
|
->value('usable_num');
|
|
|
|
$rate = $marketArr['JPY'] ?? 0;
|
|
|
|
break;
|
|
|
|
case '19':
|
|
|
|
$originMoney = UserForexModel::where('user_id', $param['id'])
|
|
|
|
->where('contract_id', 'USD')
|
|
|
|
->value('usable_num');
|
|
|
|
$rate = $marketArr['USD'] ?? 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return $this->toData('1', '无权操作');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($originMoney)) {
|
|
|
|
$originMoney = 0;
|
|
|
|
}
|
|
|
|
$diff = bcsub($amount, $originMoney, 18);
|
|
|
|
// 未进行修改
|
|
|
|
if ($diff == 0) {
|
|
|
|
return $this->toData('0', 'SUCCESS');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($rate == 0) {
|
|
|
|
return $this->toData('1', '兑换汇率错误');
|
|
|
|
}
|
|
|
|
|
|
|
|
$operateType = '13';
|
|
|
|
if ($diff > 0) {
|
|
|
|
$operateType = '12';
|
|
|
|
}
|
|
|
|
|
|
|
|
//正式用户 && 给用户加钱 -> 需要写入变更日志
|
|
|
|
$changeLogAdminId = ($user->is_test_user == 1 && abs($diff) > 0) ? $adminId : 0;
|
|
|
|
// 执行修改账户额度
|
|
|
|
$res = $this->updateUserAsset($userId, $type, $operateType, $diff, 0, "", $changeLogAdminId, $rate);
|
|
|
|
if (isset($res['status']) && $res['status'] == 200) {
|
|
|
|
return $this->toData('0', 'SUCCESS');
|
|
|
|
}
|
|
|
|
return $this->toData('1', '操作失败', [$res]);
|
|
|
|
} catch (ValidateException $validateException) {
|
|
|
|
// 参数校验失败
|
|
|
|
$message = $validateException->getError();
|
|
|
|
return $this->toData('1', $message);
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 用户关系
|
|
|
|
public function relation($param, $adminId)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
// 参数校验
|
|
|
|
validate(UserValidate::class)->scene('relation')->check($param);
|
|
|
|
|
|
|
|
$where = [];
|
|
|
|
$userId = 0;
|
|
|
|
// 用户号精确搜索
|
|
|
|
if (!empty($param['user_no'])) {
|
|
|
|
$user = UserModel::where('user_no', $param['user_no'])->find();
|
|
|
|
if (empty($user)) {
|
|
|
|
return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => [],]);
|
|
|
|
}
|
|
|
|
$userId = $user['user_id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// 判断是否是代理 如果是代理 只能看他自己管理的用户
|
|
|
|
$whereU = $this->getWhereByIsAgentAndUserId($adminId, $where, $userId);
|
|
|
|
if (!is_array($whereU)) {
|
|
|
|
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($whereU)
|
|
|
|
->order('user_id', 'desc')
|
|
|
|
->page($param['page'], $param['limit'])
|
|
|
|
->select();
|
|
|
|
// 查询总数
|
|
|
|
$total = UserModel::where($whereU)->count();
|
|
|
|
|
|
|
|
|
|
|
|
$rows = [];
|
|
|
|
if (!empty($userList)) {
|
|
|
|
$userIdArr = [];
|
|
|
|
$parentIdArr = [];
|
|
|
|
foreach ($userList as $value) {
|
|
|
|
$userIdArr[] = $value['user_id'];
|
|
|
|
if ($value['parent_id'] > 0) {
|
|
|
|
$parentIdArr[] = $value['parent_id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 查询父级
|
|
|
|
$parentNos = UserModel::where('user_id', 'in', $parentIdArr)->column('user_no', 'user_id');
|
|
|
|
|
|
|
|
// 查询用户余额
|
|
|
|
$userContractList = UserContractModel::where('user_id', 'in', $userIdArr)->column('usable_num', 'user_id');
|
|
|
|
$userStockList = UserStockModel::where('user_id', 'in', $userIdArr)->column('usable_num', 'user_id');
|
|
|
|
$userDigitalList = UserDigitalModel::where('user_id', 'in', $userIdArr)->column('usable_num', 'user_id');
|
|
|
|
|
|
|
|
foreach ($userList as $item) {
|
|
|
|
// 展示层级关系
|
|
|
|
$parentIdsArr = array_reverse(explode(',', $item['parent_ids']));
|
|
|
|
$level = '-';
|
|
|
|
for ($i = 1; $i <= count($parentIdsArr); $i++) {
|
|
|
|
if ($parentIdsArr[$i - 1] == $userId) {
|
|
|
|
$level = '下 ' . $i . ' 级';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$rows[] = [
|
|
|
|
'id' => $item['user_id'],
|
|
|
|
'user_no' => $item['user_no'],
|
|
|
|
'regTime' => $item['create_time'],
|
|
|
|
'nickname' => $item['nick_name'],
|
|
|
|
'parentId' => $parentNos[$item['parent_id']] ?? '-',
|
|
|
|
'parent_id' => $item['parent_id'],
|
|
|
|
'email' => $item['email'],
|
|
|
|
'mobile' => $item['country_code'] . '-' . $item['phone_number'],
|
|
|
|
'digital' => $userDigitalList[$item['user_id']] ?? '0',
|
|
|
|
'stock' => $userStockList[$item['user_id']] ?? '0',
|
|
|
|
'contract' => $userContractList[$item['user_id']] ?? '0',
|
|
|
|
'rechargeAmount' => 0,
|
|
|
|
'withdrawalAmount' => 0,
|
|
|
|
'regIp' => $item['reg_ip'],
|
|
|
|
'status' => UserModel::$statusMap[$item['status']] ?? '-',
|
|
|
|
'loginTime' => $item['last_login_time'],
|
|
|
|
'level' => $level,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows]);
|
|
|
|
} catch (ValidateException $validateException) {
|
|
|
|
// 参数校验失败
|
|
|
|
$message = $validateException->getError();
|
|
|
|
return $this->toData('1', $message);
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function reg_phone($param, $adminId)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
// 参数校验
|
|
|
|
validate(UserValidate::class)->scene('add_phone')->check($param);
|
|
|
|
$phoneExists = UserModel::checkPhoneExists($param['phone']);
|
|
|
|
if ($phoneExists) {
|
|
|
|
return $this->toData('100400', 'The phone number has already been registered.', []);
|
|
|
|
}
|
|
|
|
// 入库
|
|
|
|
$userNo = (new BaseHomeService())->getUniqUserNo();
|
|
|
|
$salt = env('ENCRYPT.SALT');
|
|
|
|
$password = (new UnqId())->encryptPassword($param['password'], $salt);
|
|
|
|
$userInviteCode = (new BaseHomeService())->getUniqInviteCode();
|
|
|
|
$parentUserId = 0;
|
|
|
|
$ip = (new BaseHomeService())->getClientRealIp();
|
|
|
|
$userId = UserModel::phoneRegister($param['nation'], $param['phone'], $userNo, $userInviteCode, $parentUserId, $password, $ip, $salt, $param['is_test_user'] ?? 1, 0);
|
|
|
|
(new \app\home\service\UserService())->doRegInitUserInfo($userId, $parentUserId);
|
|
|
|
// 判断是否是代理
|
|
|
|
$isAgent = AdminModel::checkUserIsAgent($adminId);
|
|
|
|
if ($isAgent) {
|
|
|
|
UserModel::where('user_id', $userId)->update([
|
|
|
|
'agent_id' => $adminId
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->toData('0', 'SUCCESS');
|
|
|
|
} catch (ValidateException $validateException) {
|
|
|
|
// 参数校验失败
|
|
|
|
$message = $validateException->getError();
|
|
|
|
return $this->toData('1', $message);
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function reg_email($param, $adminId)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
// 参数校验
|
|
|
|
validate(UserValidate::class)->scene('add_email')->check($param);
|
|
|
|
if ((new BaseHomeService())->checkForbidEmail($param['email'])) {
|
|
|
|
return $this->toData('100500', 'You are not allowed to register with Chinese email addresses.', []);
|
|
|
|
}
|
|
|
|
// 邮箱是否已经存在
|
|
|
|
$emailExists = UserModel::checkEmailExists($param['email']);
|
|
|
|
if ($emailExists) {
|
|
|
|
return $this->toData('100300', 'The email has already been registered.', []);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 获取代理id
|
|
|
|
$isAgent = AdminModel::checkUserIsAgent($adminId);
|
|
|
|
if ($isAgent) {
|
|
|
|
$agentId = $adminId;
|
|
|
|
} else { // 指定一个默认代理
|
|
|
|
$getAgent = AdminModel::where(['role_id'=>AdminModel::ROLE_ID_AGENT])->find();
|
|
|
|
if (empty($getAgent)) {
|
|
|
|
return $this->toData('500', '系统缺少代理账号');
|
|
|
|
}
|
|
|
|
$agentId = $getAgent->id;
|
|
|
|
}
|
|
|
|
// 查询代理下的一个客服
|
|
|
|
$getCustomer = AdminModel::where(['parent_id'=>$agentId])->find();
|
|
|
|
if (empty($getCustomer)) {
|
|
|
|
return $this->toData('500', '代理下缺少客服账号', ['agent_id'=>$agentId]);
|
|
|
|
}
|
|
|
|
$customerId = $getCustomer->id;
|
|
|
|
// 查询客服的chat信息
|
|
|
|
$customerChatInfo = UserChatLinkModel::where(['user_id'=>$customerId, 'user_type'=>UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_ADMIN])->find(); //查询客服的聊天账号uuid
|
|
|
|
if (empty($customerChatInfo)) {
|
|
|
|
return $this->toData('500', '客服账号缺少chat信息');
|
|
|
|
}
|
|
|
|
// 查询代理创建的chat群聊信息
|
|
|
|
$agentGroup = UserChatGroupModel::where(['user_id'=>$agentId,'remark'=>UserChatGroupModel::USER_CHAT_GROUP_REMARK_ADMIN_INIT])->find();
|
|
|
|
if (empty($agentGroup)) {
|
|
|
|
return $this->toData('500', '当前代理还未创建chat群聊');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 生成userNo
|
|
|
|
$userNo = (new BaseHomeService())->getUniqUserNo();
|
|
|
|
|
|
|
|
// 请求聊天服务,注册聊天账号
|
|
|
|
$chatData = [
|
|
|
|
'Username' => $userNo,
|
|
|
|
'Password' => '123456',
|
|
|
|
'Nickname' => 'user_'.explode('@', $param['email'])[0],
|
|
|
|
'Email' => $param['email'],
|
|
|
|
];
|
|
|
|
$chatUrl = env('CHAT_SERVER.BASE_URL') . '/api/user/register';
|
|
|
|
$chatRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatUrl, $chatData);
|
|
|
|
if (!isset($chatRes['data']['uuid'])) {
|
|
|
|
return $this->toData('100400', '注册聊天账号失败,请稍后再试');
|
|
|
|
}
|
|
|
|
|
|
|
|
// 創建用戶
|
|
|
|
$salt = env('ENCRYPT.SALT');
|
|
|
|
$password = (new UnqId())->encryptPassword($param['password'], $salt);
|
|
|
|
$userInviteCode = (new BaseHomeService())->getUniqInviteCode();
|
|
|
|
$parentUserId = 0;
|
|
|
|
$ip = (new BaseHomeService())->getClientRealIp();
|
|
|
|
$userId = UserModel::emailRegister($param['email'], $userNo, $userInviteCode, $parentUserId, $password, $ip, $salt, $param['is_test_user'] ?? 1, $agentId, $customerId);
|
|
|
|
|
|
|
|
// 关联用户与聊天账号
|
|
|
|
UserChatLinkModel::create([
|
|
|
|
'user_id' => $userId,
|
|
|
|
'user_type' => 1,
|
|
|
|
'chat_uuid' => $chatRes['data']['uuid'],
|
|
|
|
'chat_name' => $chatRes['data']['username']
|
|
|
|
]);
|
|
|
|
|
|
|
|
// 将当前账号与客服账号的chat_id加为好友
|
|
|
|
$chatFriendsData = [
|
|
|
|
'UserUuid' => $chatRes['data']['uuid'],
|
|
|
|
'CustomerUuid' => $customerChatInfo->chat_uuid,
|
|
|
|
];
|
|
|
|
$chatFriendsUrl = env('CHAT_SERVER.BASE_URL') . '/api/eachOtherFriends';
|
|
|
|
$chatFriendsRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatFriendsUrl, $chatFriendsData);
|
|
|
|
Log::info("admin创建用户 - 用户与客服chat_id加好友结果:".json_encode($chatFriendsRes));
|
|
|
|
// 将当前用户加入到代理创建的群聊中
|
|
|
|
$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));
|
|
|
|
|
|
|
|
(new \app\home\service\UserService())->doRegInitUserInfo($userId, $parentUserId);
|
|
|
|
return $this->toData('0', 'SUCCESS');
|
|
|
|
} catch (ValidateException $validateException) {
|
|
|
|
// 参数校验失败
|
|
|
|
$message = $validateException->getError();
|
|
|
|
return $this->toData('1', $message);
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 实名认证操作
|
|
|
|
public function verifyDetail($param)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$userId = $param['user_id'] ?? '';
|
|
|
|
if (!is_numeric($userId)) {
|
|
|
|
return $this->toData('100400', 'Param error', []);
|
|
|
|
}
|
|
|
|
|
|
|
|
$log = UserVerifyLogModel::where('user_id', $userId)->order('id', 'desc')->find();
|
|
|
|
if (empty($log)) {
|
|
|
|
return $this->toData('0', 'success', []);
|
|
|
|
}
|
|
|
|
|
|
|
|
// $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');
|
|
|
|
}
|
|
|
|
|
|
|
|
$country = CountryModel::where('id', $log->country)->find();
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'id' => $log->id,
|
|
|
|
'name' => $log->name,
|
|
|
|
'code' => $log->code,
|
|
|
|
'country' => $country,
|
|
|
|
'front_img' => $front ?? '',
|
|
|
|
'back_img' => $back ?? '',
|
|
|
|
'lock_password' => $log->lock_password
|
|
|
|
];
|
|
|
|
|
|
|
|
return $this->toData('0', 'success', $data);
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function verifyDo($param, $adminId)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$id = $param['id'] ?? '';
|
|
|
|
$status = $param['status'] ?? '3';
|
|
|
|
if (!is_numeric($id)) {
|
|
|
|
return $this->toData('100400', 'Param error', []);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_numeric($status) || !in_array($status, [UserVerifyLogModel::STATUS_SUCCESS, UserVerifyLogModel::STATUS_FAIL])) {
|
|
|
|
return $this->toData('100400', 'Status param error', []);
|
|
|
|
}
|
|
|
|
|
|
|
|
$log = UserVerifyLogModel::where('id', $id)->find();
|
|
|
|
if (empty($log)) {
|
|
|
|
return $this->toData('100400', 'ID param error', []);
|
|
|
|
}
|
|
|
|
|
|
|
|
$agentAuth = env('AGENT_AUTH.AGENT_AUTH_VERIFY'); // 0代理不可审核 1代理可审核
|
|
|
|
if (empty($agentAuth)){
|
|
|
|
$isAgent = AdminModel::checkUserIsAgent($adminId);
|
|
|
|
if ($isAgent) {
|
|
|
|
return $this->toData('10040', '代理无权限操作');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$isReal = 0;
|
|
|
|
$realStatus = 4;
|
|
|
|
// 如果是成功 修改用户表
|
|
|
|
if ($status == UserVerifyLogModel::STATUS_SUCCESS) {
|
|
|
|
$isReal = 1;
|
|
|
|
$realStatus = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 更新用户
|
|
|
|
UserModel::where('user_id', $log->user_id)->update(['is_real' => $isReal, 'real_status' => $realStatus, 'update_time' => date('Y-m-d H:i:s')]);
|
|
|
|
// 更新记录
|
|
|
|
$log->status = $status;
|
|
|
|
$log->update_time = date('Y-m-d H:i:s');
|
|
|
|
$log->save();
|
|
|
|
return $this->toData('0', 'success');
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 杠杆状态审核
|
|
|
|
public function leverReview($param)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$userId = $param['user_id'] ?? '';
|
|
|
|
if (!is_numeric($userId)) {
|
|
|
|
return $this->toData('100400', 'Param error', []);
|
|
|
|
}
|
|
|
|
|
|
|
|
$lever_status = $param['lever_status'] ?? 4;
|
|
|
|
if (!is_numeric($lever_status)) {
|
|
|
|
return $this->toData('100400', 'Param error', []);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!in_array($lever_status, [UserModel::LEVER_STATUS_PASSED, UserModel::LEVER_STATUS_FAIL])) {
|
|
|
|
return $this->toData('100400', 'Param error', []);
|
|
|
|
}
|
|
|
|
|
|
|
|
$key = 'USER:LEVER_STATUS:' . $userId;
|
|
|
|
$lever_status = $lever_status + 0;
|
|
|
|
$this->getRedis()->set($key, $lever_status);
|
|
|
|
UserModel::update(['lever_status' => $lever_status, 'update_time' => date('Y-m-d H:i:s')], ['user_id' => $userId]);
|
|
|
|
return $this->toData('0', 'success');
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getUserLoan($param,$adminId)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$where = [];
|
|
|
|
$userId = 0;
|
|
|
|
// 用户号精确搜索
|
|
|
|
if (!empty($param['user_no'])) {
|
|
|
|
$user = UserModel::where('user_no', $param['user_no'])->find();
|
|
|
|
if (empty($user)) {
|
|
|
|
return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => [], 'extent' => ['totalMoney' => 0]]);
|
|
|
|
}
|
|
|
|
$userId = $user['user_id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// 判断是否是代理 如果是代理 只能看他自己管理的用户
|
|
|
|
$where = $this->getWhereByIsAgentAndUserId($adminId, $where, $userId);
|
|
|
|
|
|
|
|
if(isset($param['status'])){
|
|
|
|
$where['status']=intval($param['status']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$data['where']=$where;
|
|
|
|
|
|
|
|
$data['page']=isset($param['page']) ? intval($param['page']) : 1;
|
|
|
|
$data['size']=isset($param['size']) ? intval($param['size']) : 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->toData('0', 'SUCCESS', $list);
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
return $this->toData('1', '系统繁忙', [$exception->getMessage(),$exception->getTrace()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dealUserLoan($param,$adminId)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$where = [];
|
|
|
|
$userId = 0;
|
|
|
|
// 用户号精确搜索
|
|
|
|
if (!empty($param['user_no'])) {
|
|
|
|
$user = UserModel::where('user_no', $param['user_no'])->find();
|
|
|
|
if (empty($user)) {
|
|
|
|
return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => [], 'extent' => ['totalMoney' => 0]]);
|
|
|
|
}
|
|
|
|
$userId = $user['user_id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// 判断是否是代理 如果是代理 只能看他自己管理的用户
|
|
|
|
$where = $this->getWhereByIsAgentAndUserId($adminId, $where, $userId);
|
|
|
|
|
|
|
|
$where['id']=intval($param['id']);
|
|
|
|
|
|
|
|
$info=UserLoanModel::where($where)->find();
|
|
|
|
if(empty($info)){
|
|
|
|
return $this->toData('1', '数据不存在');
|
|
|
|
}
|
|
|
|
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')
|
|
|
|
]);
|
|
|
|
|
|
|
|
return $this->toData('0', 'SUCCESS', []);
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取用户验证码
|
|
|
|
public function getUserCode($param)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$extend = [
|
|
|
|
'business' => ['1' => '已登录操作', '3' => '未登录操作'],
|
|
|
|
'code_type' => ['6' => '邮箱', '9' => '短信'],
|
|
|
|
];
|
|
|
|
if (empty($param['search']) || empty($param['business']) || empty($param['code_type'])) {
|
|
|
|
return $this->toData('0', 'success', ['extend' => $extend, 'get_code' => 0, 'code' => '']);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_numeric($param['business']) || !is_numeric($param['code_type']) || !is_string($param['search'])) {
|
|
|
|
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()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getRegCode($param)
|
|
|
|
{
|
|
|
|
$key = "USER:REG:CODE";
|
|
|
|
$redis = $this->getRedis();
|
|
|
|
$code = $redis->get($key);
|
|
|
|
if (empty($code)) {
|
|
|
|
$code = random_int(1000, 9999);
|
|
|
|
$time = 300;
|
|
|
|
$redis->setex($key, $time, $code);
|
|
|
|
} else {
|
|
|
|
$time = $redis->pttl($key);
|
|
|
|
}
|
|
|
|
return $this->toData('0', 'success', ['code' => $code, 'expiration_time' => $time]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 用户银行卡
|
|
|
|
public function bankDetail($param)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$userId = $param['user_id'] ?? '';
|
|
|
|
if (!is_numeric($userId)) {
|
|
|
|
return $this->toData('100400', 'Param error', []);
|
|
|
|
}
|
|
|
|
|
|
|
|
$bank = UserBankModel::getUserBankInfoById(['user_id' => $userId]);
|
|
|
|
if (empty($bank)) {
|
|
|
|
return $this->toData('0', 'success', []);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->toData('0', 'success', $bank);
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function editBank($param)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
if (empty($param['id'])) {
|
|
|
|
return $this->toData('100400', 'Param error', []);
|
|
|
|
}
|
|
|
|
|
|
|
|
$bank = UserBankModel::getUserBankInfoById(['id' => $param['id']]);
|
|
|
|
if (empty($bank)) {
|
|
|
|
return $this->toData('100400', 'Param error', []);
|
|
|
|
}
|
|
|
|
|
|
|
|
$updateArr = [
|
|
|
|
'true_name' => $param['true_name'] ?? $bank['true_name'],
|
|
|
|
'bank_name' => $param['bank_name'] ?? $bank['bank_name'],
|
|
|
|
'bank_code' => $param['bank_code'] ?? $bank['bank_code'],
|
|
|
|
'bank_card' => $param['bank_card'] ?? $bank['bank_card'],
|
|
|
|
'bank_phone' => $param['bank_phone'] ?? $bank['bank_phone'],
|
|
|
|
'bank_email' => $param['bank_email'] ?? $bank['bank_email'],
|
|
|
|
'ifsc' => $param['ifsc'] ?? $bank['ifsc'],
|
|
|
|
'update_time' => date('Y-m-d H:i:s')
|
|
|
|
];
|
|
|
|
UserBankModel::where('id', $param['id'])->update($updateArr);
|
|
|
|
return $this->toData('0', 'SUCCESS', []);
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function editPassword($param)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
if (empty($param['id'])) {
|
|
|
|
return $this->toData('100400', 'Param error', []);
|
|
|
|
}
|
|
|
|
|
|
|
|
$user = UserModel::where('user_id', $param['id'])->find();
|
|
|
|
if (empty($user)) {
|
|
|
|
return $this->toData('100400', 'Param error', []);
|
|
|
|
}
|
|
|
|
|
|
|
|
$updateArr = [];
|
|
|
|
// $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', '系统异常 请稍后重试', []);
|
|
|
|
return $this->toData('0', 'SUCCESS', []);
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setAutoLogin($param)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
if (empty($param['id'])) {
|
|
|
|
return $this->toData('100400', 'Param error', []);
|
|
|
|
}
|
|
|
|
$userId = $param['id'];
|
|
|
|
$user = UserModel::where('user_id', $userId)->find();
|
|
|
|
if (empty($user)) {
|
|
|
|
return $this->toData('1', '用户不存在');
|
|
|
|
}
|
|
|
|
$token = md5($param['id'] . time() . date('Y-m-d H:i:s'));
|
|
|
|
$tokenKey = 'AUTO:TOKEN:' . $token; // 根据token查找用户id
|
|
|
|
|
|
|
|
$expired = 5 * 60;
|
|
|
|
// 由中间件自动续期
|
|
|
|
Cache::store('redis')->set($tokenKey, $userId, $expired);
|
|
|
|
return $this->toData('0', 'SUCCESS', [
|
|
|
|
'login_token' => $token
|
|
|
|
]);
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getLeverageNum($param)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
if (!is_numeric($param['id'])) {
|
|
|
|
return $this->toData('100400', 'Param error', []);
|
|
|
|
}
|
|
|
|
|
|
|
|
$key = 'LEVERAGE:' . $param['id'];
|
|
|
|
$value = Cache::store('redis')->get($key);
|
|
|
|
if (empty($value)) {
|
|
|
|
$key = 'LEVERAGE:0';
|
|
|
|
$value = Cache::store('redis')->get($key);
|
|
|
|
}
|
|
|
|
return $this->toData('0', 'SUCCESS', ['leverage_num' => $value]);
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function editLeverageNum($param)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
if (empty($param['leverage_num'])) {
|
|
|
|
return $this->toData('100400', 'Param error', []);
|
|
|
|
}
|
|
|
|
if (!empty($param['id'])) {
|
|
|
|
$userId = $param['id'];
|
|
|
|
} else {
|
|
|
|
$userId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$key = 'LEVERAGE:' . $userId;
|
|
|
|
Cache::store('redis')->del($key);
|
|
|
|
Cache::store('redis')->set($key, $param['leverage_num']);
|
|
|
|
return $this->toData('0', 'SUCCESS', []);
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
return $this->toData('500', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 编辑用户的 customer_remark 字段
|
|
|
|
public function editCustomerRemark($param)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
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();
|
|
|
|
if (empty($user)) {
|
|
|
|
return $this->toData('500', '操作的用户数据错误');
|
|
|
|
}
|
|
|
|
$user->customer_remark = $param['remark'];
|
|
|
|
$user->save();
|
|
|
|
return $this->toData('0', 'SUCCESS');
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
return $this->toData('500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 编辑用户标签字段
|
|
|
|
public function editUserLabel($param)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
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();
|
|
|
|
if (empty($user)) {
|
|
|
|
return $this->toData('500', '操作的用户数据错误');
|
|
|
|
}
|
|
|
|
$user->label = $param['label'];
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
// 同步更新chat服务
|
|
|
|
$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', '该用户的聊天信息错误');
|
|
|
|
}
|
|
|
|
$upChaData = [
|
|
|
|
'username' => $userChatInfo->chat_name,
|
|
|
|
'label' => $param['label'],
|
|
|
|
];
|
|
|
|
$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('0', 'SUCCESS');
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
return $this->toData('500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function editUserBaseLabel($param)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
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();
|
|
|
|
if (empty($user)) {
|
|
|
|
return $this->toData('500', '操作的用户数据错误');
|
|
|
|
}
|
|
|
|
$user->base_label = $param['base_label'];
|
|
|
|
$user->save();
|
|
|
|
return $this->toData('0', 'SUCCESS');
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
return $this->toData('500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 用户充值、提款封禁与解封
|
|
|
|
public function frozen($param, $adminId)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
// 参数校验
|
|
|
|
validate(UserValidate::class)->scene('frozen_state')->check($param);
|
|
|
|
$userId = $param['id'];
|
|
|
|
$user = UserModel::where('user_id', $userId)->find();
|
|
|
|
if (empty($user)) {
|
|
|
|
return $this->toData('1', '用户不存在');
|
|
|
|
}
|
|
|
|
$bool = $this->checkUserIdInAgent($adminId, $userId);
|
|
|
|
if (!$bool) {
|
|
|
|
return $this->toData('1', '无权操作');
|
|
|
|
}
|
|
|
|
// 查询冻结记录表
|
|
|
|
$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']]);
|
|
|
|
}
|
|
|
|
if (isset($param['frozen_withdraw'])) {
|
|
|
|
AccountFrozenModel::create(['user_id'=>$userId, 'frozen_withdraw' => $param['frozen_withdraw']]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (isset($param['frozen_recharge'])) {
|
|
|
|
AccountFrozenModel::update(['frozen_recharge' => $param['frozen_recharge']], ['user_id' => $userId]);
|
|
|
|
}
|
|
|
|
if (isset($param['frozen_withdraw'])) {
|
|
|
|
AccountFrozenModel::update(['frozen_withdraw' => $param['frozen_withdraw']], ['user_id' => $userId]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->toData('0', 'SUCCESS');
|
|
|
|
} catch (ValidateException $validateException) {
|
|
|
|
$message = $validateException->getError();
|
|
|
|
return $this->toData('1', $message);
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 编辑用户阶段信息
|
|
|
|
public function editUserStage($param)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
if (empty($param['user_id'])) {
|
|
|
|
return $this->toData('400', '缺少参数');
|
|
|
|
}
|
|
|
|
// 检测用户数据
|
|
|
|
$user = UserModel::where('user_id', $param['user_id'])->findOrEmpty()->toArray();
|
|
|
|
if (empty($user)) {
|
|
|
|
return $this->toData('1', '用户不存在');
|
|
|
|
}
|
|
|
|
// 检测用户阶段数据
|
|
|
|
$userStageState = UserStageStateModel::where(['user_id'=>$user['user_id']])->find();
|
|
|
|
if (empty($userStageState)) {
|
|
|
|
UserStageStateModel::create([
|
|
|
|
'user_id' => $user['user_id'],
|
|
|
|
'first_stage' => $param['first_stage'] ?? '',
|
|
|
|
'first_stage_state' => $param['first_stage_state'] ?? 0,
|
|
|
|
'second_stage' => $param['second_stage'] ?? '',
|
|
|
|
'second_stage_state' => $param['second_stage_state'] ?? 0,
|
|
|
|
'third_stage' => $param['third_stage'] ?? '',
|
|
|
|
'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['third_stage'])) {
|
|
|
|
$userStageState->third_stage = $param['third_stage'];
|
|
|
|
$userStageState->third_stage_state = $param['third_stage_state'] ?? 0;
|
|
|
|
}
|
|
|
|
$userStageState->save();
|
|
|
|
}
|
|
|
|
return $this->toData('0', 'SUCCESS');
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
return $this->toData('500', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 用户收藏的股票(自选股票)
|
|
|
|
public function userMarketList($param)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
if (empty($param['page']) || !is_numeric($param['page'])) {
|
|
|
|
return $this->toData('400', '参错错误');
|
|
|
|
}
|
|
|
|
if (empty($param['limit']) || !is_numeric($param['limit'])) {
|
|
|
|
return $this->toData('400', '参错错误');
|
|
|
|
}
|
|
|
|
$where = [];
|
|
|
|
if (!empty($param['user_id'])) {
|
|
|
|
$where['user_id'] = $param['user_id'];
|
|
|
|
}
|
|
|
|
if (!empty($param['market_type'])) {
|
|
|
|
$where['market_type'] = $param['market_type'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$list = UserMarketModel::where($where)->order('id', 'desc')->paginate([
|
|
|
|
'list_rows' => $param['limit'],
|
|
|
|
'page' => $param['page'],
|
|
|
|
]);
|
|
|
|
return $this->toData('0', 'Successful', [
|
|
|
|
'list' => $list->items(), // 当前页的数据
|
|
|
|
'page' => $list->currentPage(), // 当前页码
|
|
|
|
'total' => $list->total(), // 总记录数
|
|
|
|
'last_page' => $list->lastPage(), // 最后一页页码
|
|
|
|
]);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return $this->toData('500', '系统异常 请稍后重试', [$e->getMessage(), $e->getTrace()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|