You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1303 lines
60 KiB
1303 lines
60 KiB
<?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\CountryModel;
|
|
use app\model\FileModel;
|
|
use app\model\StockMarketModel;
|
|
use app\model\UserBankModel;
|
|
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\UserModel;
|
|
use app\model\UserMoneyModel;
|
|
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\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;
|
|
|
|
class UserService extends AdminBaseService
|
|
{
|
|
|
|
// 用户列表
|
|
public function index($param, $adminId)
|
|
{
|
|
try {
|
|
// 参数校验
|
|
validate(UserValidate::class)->scene('index')->check($param);
|
|
Cache::store('redis')->set('User_Read_Time'.$adminId,time());
|
|
$where = [];
|
|
// 邮箱搜索
|
|
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($whereU)->page($param['page'], $param['limit'])->order('user_id', 'desc')->select();
|
|
$total = UserModel::where($where)->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');
|
|
|
|
if(env('ACCOUT_TYPE.ALL_IN_ONE')==1){
|
|
$userMoneyList=UserMoneyModel::where('user_id', 'in', $userIdArr) ->where('stock_id', 'USD')
|
|
->column('usable_num,frozen_num', 'user_id');
|
|
}else{
|
|
// 查询用户余额
|
|
$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');
|
|
//新加坡股票资产
|
|
$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');
|
|
}
|
|
|
|
// 查询用户冻结状态
|
|
$accountFrozenList = [];
|
|
if ($userIdArr) {
|
|
$accountFrozenList = AccountFrozenModel::where('user_id', 'in', $userIdArr)
|
|
->column('frozen_recharge,frozen_withdraw', '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) {
|
|
$frozenRecharge = isset($accountFrozenList[$item['user_id']]['frozen_recharge']) ? $accountFrozenList[$item['user_id']]['frozen_recharge'] : 0;
|
|
$frozenWithdraw = isset($accountFrozenList[$item['user_id']]['frozen_withdraw']) ? $accountFrozenList[$item['user_id']]['frozen_withdraw'] : 0;
|
|
$key = 'LEVERAGE:' . $item['user_id'];
|
|
$leverage_num=empty(Cache::store('redis')->get($key))? 1: Cache::store('redis')->get($key);
|
|
$userRow= [
|
|
'id' => $item['user_id'],
|
|
'frozen_recharge' => $frozenRecharge,
|
|
'frozen_withdraw' => $frozenWithdraw,
|
|
'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'],
|
|
'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']] ?? '-' : '-',
|
|
'leverage_num'=>$leverage_num
|
|
];
|
|
if(env('ACCOUT_TYPE.ALL_IN_ONE')==1){
|
|
$userRow['money'] = $userMoneyList[$item['user_id']]['usable_num'] ?? '0';
|
|
$userRow['money_frozen']=$userMoneyList[$item['user_id']]['frozen_num'] ?? '0';
|
|
}else{
|
|
//余额
|
|
$userRow['digital'] = $userDigitalList[$item['user_id']]['usable_num'] ?? '0';
|
|
$userRow['stock'] = $userStockList[$item['user_id']]['usable_num'] ?? '0';
|
|
$userRow['contract'] = $userContractList[$item['user_id']]['usable_num'] ?? '0';
|
|
$userRow['contract_sec'] = $userContractSecList[$item['user_id']]['usable_num'] ?? '0';
|
|
$userRow['forex'] = $userForexList[$item['user_id']]['usable_num'] ?? '0';//外汇
|
|
$userRow['stock_idn']=$userStockIdrList[$item['user_id']]['usable_num'] ?? '0'; // 印尼股票余额
|
|
$userRow['stock_tha']=$userStockThaList[$item['user_id']]['usable_num'] ?? '0'; // 泰股资产
|
|
$userRow['stock_mys']=$userStockMysList[$item['user_id']]['usable_num'] ?? '0'; // 马股资产
|
|
$userRow['stock_in']=$userStockInList[$item['user_id']]['usable_num'] ?? '0';// 印度股资产
|
|
$userRow['stock_sgd']=$userStockSGDList[$item['user_id']]['usable_num'] ?? '0'; // 新加坡股资产
|
|
$userRow['stock_fund']=$userStockFundList[$item['user_id']]['usable_num'] ?? '0'; // 基金资产
|
|
$userRow['stock_option_in']=$userStockOptionInrList[$item['user_id']]['usable_num'] ?? '0'; // 印度期权资产
|
|
$userRow['stock_hk']=$userStockHkList[$item['user_id']]['usable_num'] ?? '0';// 香港股资产
|
|
$userRow['stock_uk']=$userStockUkList[$item['user_id']]['usable_num'] ?? '0'; // 英股资产
|
|
$userRow['stock_fur']=$userStockFurList[$item['user_id']]['usable_num'] ?? '0'; // 法股资产
|
|
$userRow['stock_eur']=$userStockEurList[$item['user_id']]['usable_num'] ?? '0'; // 德股资产
|
|
$userRow['stock_brl']=$userStockBrlList[$item['user_id']]['usable_num'] ?? '0'; // 巴西股资产
|
|
$userRow['stock_jp']=$userStockJpList[$item['user_id']]['usable_num'] ?? '0';// 巴西股资产
|
|
//冻结资金
|
|
$userRow['digital_frozen']=$userDigitalList[$item['user_id']]['frozen_num'] ?? '0';
|
|
$userRow['stock_frozen']=$userStockList[$item['user_id']]['frozen_num'] ?? '0';
|
|
$userRow['contract_frozen']=$userContractList[$item['user_id']]['frozen_num'] ?? '0';
|
|
$userRow['forex_frozen']=$userForexList[$item['user_id']]['frozen_num'] ?? '0';
|
|
$userRow['contract_sec_frozen']=$userContractSecList[$item['user_id']]['frozen_num'] ?? '0';
|
|
$userRow['stock_idn_frozen']=$userStockIdrList[$item['user_id']]['frozen_num'] ?? '0'; // 印尼股票余额
|
|
$userRow['stock_tha_frozen']=$userStockThaList[$item['user_id']]['frozen_num'] ?? '0'; // 泰股资产
|
|
$userRow['stock_mys_frozen']=$userStockMysList[$item['user_id']]['frozen_num'] ?? '0'; // 马股资产
|
|
$userRow['stock_in_frozen']=$userStockInList[$item['user_id']]['frozen_num'] ?? '0';// 印度股资产
|
|
$userRow['stock_sgd_frozen']=$userStockSGDList[$item['user_id']]['frozen_num'] ?? '0'; // 新加坡股资产
|
|
$userRow['stock_fund_frozen']=$userStockFundList[$item['user_id']]['frozen_num'] ?? '0'; // 基金资产
|
|
$userRow['stock_option_in_frozen']=$userStockOptionInrList[$item['user_id']]['frozen_num'] ?? '0';// 印度期权资产
|
|
$userRow['stock_hk_frozen']=$userStockHkList[$item['user_id']]['frozen_num'] ?? '0'; // 香港股资产
|
|
$userRow['stock_uk_frozen']=$userStockUkList[$item['user_id']]['frozen_num'] ?? '0'; // 英港股资产
|
|
$userRow['stock_fur_frozen']=$userStockFurList[$item['user_id']]['frozen_num'] ?? '0'; // 法股资产
|
|
$userRow['stock_eur_frozen']=$userStockEurList[$item['user_id']]['frozen_num'] ?? '0'; // 德股资产
|
|
$userRow['stock_brl_frozen']=$userStockBrlList[$item['user_id']]['frozen_num'] ?? '0'; // 德股资产
|
|
$userRow['stock_jp_frozen']=$userStockJpList[$item['user_id']]['frozen_num'] ?? '0'; // 德股资产
|
|
}
|
|
$rows[] =$userRow;
|
|
}
|
|
}
|
|
|
|
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 RealList($param, $adminId)
|
|
{
|
|
try {
|
|
Cache::store('redis')->set('User_Read_Time'.$adminId,time());
|
|
// 参数校验
|
|
validate(UserValidate::class)->scene('index')->check($param);
|
|
|
|
$where = [];
|
|
// 邮箱搜索
|
|
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($whereU)
|
|
->where('real_status',2)->page($param['page'], $param['limit'])->order('user_id', 'desc')->select();
|
|
$total = UserModel::where($where)->where($whereU) ->where('real_status',2)->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');
|
|
|
|
//最近登录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) {
|
|
$key = 'LEVERAGE:' . $item['user_id'];
|
|
$leverage_num=empty(Cache::store('redis')->get($key))? 1: Cache::store('redis')->get($key);
|
|
$userRow= [
|
|
'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'],
|
|
'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']] ?? '-' : '-',
|
|
'leverage_num'=>$leverage_num
|
|
];
|
|
$rows[] =$userRow;
|
|
}
|
|
}
|
|
|
|
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 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 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');
|
|
|
|
if(env('ACCOUT_TYPE.ALL_IN_ONE')==1){
|
|
$user_money=UserMoneyModel::getUserUSDByUserId(['user_id'=>$param['id']]);
|
|
$originMoney=$user_money['usable_num'];
|
|
// $originMoney = UserMoneyModel::where('user_id', $param['id'])
|
|
// ->where('stock_id', 'USD')
|
|
// ->value('usable_num');
|
|
$rate = 1;
|
|
}else{
|
|
// 查询账户余额
|
|
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');
|
|
|
|
$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;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$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;
|
|
// 执行修改账户额度
|
|
if(env('ACCOUT_TYPE.ALL_IN_ONE')==1){
|
|
$res = $this->updateUserAssetNew($userId, $operateType, $diff);
|
|
}else{
|
|
$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.', []);
|
|
}
|
|
|
|
// 入库
|
|
$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::emailRegister($param['email'], $userNo, $userInviteCode, $parentUserId, $password, $ip, $salt, $param['is_test_user'] ?? 1, 0);
|
|
// 判断是否是代理
|
|
$isAgent = AdminModel::checkUserIsAgent($adminId);
|
|
if ($isAgent) {
|
|
UserModel::where('user_id', $userId)->update([
|
|
'agent_id' => $adminId
|
|
]);
|
|
}
|
|
(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');
|
|
$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 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('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()]);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|