// +---------------------------------------------------------------------- namespace App\Http\Controllers\Admin; use App\Http\Validator\MemberValidator; use App\Models\UserModel; use App\Services\Common\CoinLogService; use App\Services\Common\MemberService; use App\Services\Common\MemberSettingService; use App\Services\Common\MenuService; use App\Services\Common\TradeOrderService; use App\Services\Common\UserService; use App\Services\ConfigService; use App\Services\RedisService; use App\Services\UsdtWalletService; /** * 系统主页控制器 * @author laravel开发员 * @since 2020/11/10 * Class IndexController * @package App\Http\Controllers\Admin */ class IndexController extends Backend { /** * 构造函数 * @author laravel开发员 * @since 2020/11/10 * IndexController constructor. */ public function __construct() { $this->model = new UserModel(); parent::__construct(); } /** * 后台主页 * @author laravel开发员 * @since 2020/11/10 */ public function getMenuList() { $menuService = new MenuService(); $menuList = $menuService->getPermissionList($this->userId); return $menuList; } /** * 获取个人信息 * @return array * @since 2020/11/10 * @author laravel开发员 */ public function getUserInfo() { $userService = new UserService(); $result = $userService->getUserInfo($this->userId); return $result; } /** * 更新个人资料 * @return mixed * @since 2020/11/11 * @author laravel开发员 */ public function updateUserInfo() { $userService = new UserService(); $result = $userService->updateUserInfo($this->userId); return $result; } /** * 承兑商提交资料认证 * @return mixed * @since 2020/11/11 * @author laravel开发员 */ public function authSubmit(MemberValidator $validate) { $params = $validate->check(request()->post(),'business_auth'); if(!is_array($params)){ return returnJson($params, false); } $userService = new UserService(); $result = $userService->authSubmit($this->userInfo['user_id']); return $result; } /** * 更新密码 * @return mixed * @since 2020/11/11 * @author laravel开发员 */ public function updatePwd() { $userService = new UserService(); $result = $userService->updatePwd($this->userId); return $result; } /** * 设置修改交易密码 * @return mixed */ public function updateTradePwd() { $userService = new UserService(); $result = $userService->updateTradePwd($this->userInfo['user_id'], $this->userId); return $result; } /** * 清除缓存 * @return array */ public function clearCache(){ RedisService::keyDel("caches:d*"); RedisService::keyDel("caches:inde*"); RedisService::keyDel("caches:advert*"); RedisService::keyDel("caches:article*"); RedisService::keyDel("caches:qrcode*"); RedisService::keyDel("laravel_cache:model*"); return returnJson(MESSAGE_OK, true); } /** * 获取首页数据 * @return array */ public function indexData() { $this->userId; $info = $this->model->getInfo($this->userId); $userId = isset($info['user_id'])? $info['user_id'] : 0; $userInfo = MemberService::make()->getInfo($userId); if($userId<=0 || empty($userInfo)){ return returnJson(MESSAGE_FAILED, true); } // 用户交易设置参数 $setting = MemberSettingService::make()->getInfo($userId); // 15分钟内的买卖比统计 $counts = TradeOrderService::make()->getCountRateByTime(1, $this->userInfo['user_id'], 15); $sellTotal = TradeOrderService::make()->getCompleteTotalByDay(2, $this->userInfo['user_id']); $datas = [ 'counts'=> [ 'usdt_num'=> isset($userInfo['usdt_num'])? moneyFormat($userInfo['usdt_num'], 2) : '0.00', 'buy_total'=> TradeOrderService::make()->getCompleteTotalByDay(1, $this->userInfo['user_id']), 'sell_total'=> $sellTotal, 'day_sell_quota'=> isset($setting['day_sell_quota'])? max(0,$setting['day_sell_quota']-$sellTotal) : '0.00', 'buy_rate'=> isset($counts['buy_rate'])? $counts['buy_rate'] : '0.00', 'sell_rate'=> isset($counts['sell_rate'])? $counts['sell_rate'] : '0.00', 'rate_count'=> $counts, ], 'setting'=> $setting ]; return returnJson(MESSAGE_OK, true, $datas); } /** * 获取交易员配置 * @return array */ public function setting() { $this->userId; $info = $this->model->getInfo($this->userId); $userId = isset($info['user_id'])? $info['user_id'] : 0; $userInfo = MemberService::make()->getInfo($userId); if($userId<=0 || empty($userInfo)){ return returnJson(MESSAGE_FAILED, false); } // 用户交易设置参数 $setting = MemberSettingService::make()->getInfo($userId); return returnJson(MESSAGE_OK, true, $setting); } /** * 获取交易员配置 * @return array */ public function tradeConfig() { $data = ConfigService::make()->getConfigOptionByGroup(6); $data1 = ConfigService::make()->getConfigOptionTextByGroup(6); $data['coin_in_tips'] = isset($data1['coin_in_tips'])? $data1['coin_in_tips'] : ''; $data['coin_out_tips'] = isset($data1['coin_out_tips'])? $data1['coin_out_tips'] : ''; return returnJson(MESSAGE_OK, true, $data); } /** * 平台钱包 */ public function wallet() { $data = ConfigService::make()->getConfigOptionByGroup(5); if(isset($data['trc_address']) && $data['trc_address']){ $qrcode = \App\Services\Api\MemberService::make()->makeQrcode($data['trc_address']); $data['trc_qrcode'] = $qrcode? get_image_url($qrcode) : ''; $data['wallet']['trc_usdt'] = UsdtWalletService::make()->getTrc20Usdt($data['trc_address']); } if(isset($data['trc_out_address']) && $data['trc_out_address']){ $qrcode = \App\Services\Api\MemberService::make()->makeQrcode($data['trc_out_address']); $data['trc_out_qrcode'] = $qrcode? get_image_url($qrcode) : ''; $data['wallet']['trc_out_usdt'] = UsdtWalletService::make()->getTrc20Usdt($data['trc_out_address']); } if(isset($data['erc_address']) && $data['erc_address']){ $qrcode = \App\Services\Api\MemberService::make()->makeQrcode($data['erc_address']); $data['erc_qrcode'] = $qrcode? get_image_url($qrcode) : ''; $data['wallet']['erc_usdt'] = UsdtWalletService::make()->getErc20Usdt($data['erc_address']); } if(isset($data['erc_out_address']) && $data['erc_out_address']){ $qrcode = \App\Services\Api\MemberService::make()->makeQrcode($data['erc_out_address']); $data['erc_out_qrcode'] = $qrcode? get_image_url($qrcode) : ''; $data['wallet']['erc_out_usdt'] = UsdtWalletService::make()->getErc20Usdt($data['erc_out_address']); } return returnJson(MESSAGE_OK, true, $data); } /** * 获取钱包地址交易记录 * @return array */ public function transfer() { $contactType = request()->post('contact_type', 1); $type = request()->post('type', 1); $changeType = request()->post('change_type', 1); $address = request()->post('address', ''); $limit = request()->post('limit', 10); if(empty($address)){ return returnJson(MESSAGE_OK, true); } // trc $params = [ 'change_type'=> $changeType, 'contact_type'=> $contactType, 'from'=> $changeType==1? '' : $address, 'to'=> $changeType==1? $address : '', ]; $datas = CoinLogService::make()->getDataList($params, $limit); return returnJson(MESSAGE_OK, true, is_array($datas)? $datas : []); } /** * 后台手动归集总钱包 * @return array * @throws \Tron\Exceptions\TransactionException * @throws \Tron\Exceptions\TronErrorException */ public function trigger() { $type = request()->post('type',1); if($type == 1){ if($result = UsdtWalletService::make()->usdtTrcTrigger(true)){ return showJson(UsdtWalletService::make()->getError(), true, $result); }else{ return showJson(UsdtWalletService::make()->getError(), false); } }else{ if($result = UsdtWalletService::make()->usdtErcTrigger(true)){ return showJson(UsdtWalletService::make()->getError(), true, $result); }else{ return showJson(UsdtWalletService::make()->getError(), false); } } } }