IndexController.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Http\Controllers\Admin;
  12. use App\Http\Validator\MemberValidator;
  13. use App\Models\UserModel;
  14. use App\Services\Common\CoinLogService;
  15. use App\Services\Common\MemberService;
  16. use App\Services\Common\MemberSettingService;
  17. use App\Services\Common\MenuService;
  18. use App\Services\Common\TradeOrderService;
  19. use App\Services\Common\UserService;
  20. use App\Services\ConfigService;
  21. use App\Services\RedisService;
  22. use App\Services\UsdtWalletService;
  23. /**
  24. * 系统主页控制器
  25. * @author laravel开发员
  26. * @since 2020/11/10
  27. * Class IndexController
  28. * @package App\Http\Controllers\Admin
  29. */
  30. class IndexController extends Backend
  31. {
  32. /**
  33. * 构造函数
  34. * @author laravel开发员
  35. * @since 2020/11/10
  36. * IndexController constructor.
  37. */
  38. public function __construct()
  39. {
  40. $this->model = new UserModel();
  41. parent::__construct();
  42. }
  43. /**
  44. * 后台主页
  45. * @author laravel开发员
  46. * @since 2020/11/10
  47. */
  48. public function getMenuList()
  49. {
  50. $menuService = new MenuService();
  51. $menuList = $menuService->getPermissionList($this->userId);
  52. return $menuList;
  53. }
  54. /**
  55. * 获取个人信息
  56. * @return array
  57. * @since 2020/11/10
  58. * @author laravel开发员
  59. */
  60. public function getUserInfo()
  61. {
  62. $userService = new UserService();
  63. $result = $userService->getUserInfo($this->userId);
  64. return $result;
  65. }
  66. /**
  67. * 更新个人资料
  68. * @return mixed
  69. * @since 2020/11/11
  70. * @author laravel开发员
  71. */
  72. public function updateUserInfo()
  73. {
  74. $userService = new UserService();
  75. $result = $userService->updateUserInfo($this->userId);
  76. return $result;
  77. }
  78. /**
  79. * 承兑商提交资料认证
  80. * @return mixed
  81. * @since 2020/11/11
  82. * @author laravel开发员
  83. */
  84. public function authSubmit(MemberValidator $validate)
  85. {
  86. $params = $validate->check(request()->post(),'business_auth');
  87. if(!is_array($params)){
  88. return returnJson($params, false);
  89. }
  90. $userService = new UserService();
  91. $result = $userService->authSubmit($this->userInfo['user_id']);
  92. return $result;
  93. }
  94. /**
  95. * 更新密码
  96. * @return mixed
  97. * @since 2020/11/11
  98. * @author laravel开发员
  99. */
  100. public function updatePwd()
  101. {
  102. $userService = new UserService();
  103. $result = $userService->updatePwd($this->userId);
  104. return $result;
  105. }
  106. /**
  107. * 设置修改交易密码
  108. * @return mixed
  109. */
  110. public function updateTradePwd()
  111. {
  112. $userService = new UserService();
  113. $result = $userService->updateTradePwd($this->userInfo['user_id'], $this->userId);
  114. return $result;
  115. }
  116. /**
  117. * 清除缓存
  118. * @return array
  119. */
  120. public function clearCache(){
  121. RedisService::keyDel("caches:d*");
  122. RedisService::keyDel("caches:inde*");
  123. RedisService::keyDel("caches:advert*");
  124. RedisService::keyDel("caches:article*");
  125. RedisService::keyDel("caches:qrcode*");
  126. RedisService::keyDel("laravel_cache:model*");
  127. return returnJson(MESSAGE_OK, true);
  128. }
  129. /**
  130. * 获取首页数据
  131. * @return array
  132. */
  133. public function indexData()
  134. {
  135. $this->userId;
  136. $info = $this->model->getInfo($this->userId);
  137. $userId = isset($info['user_id'])? $info['user_id'] : 0;
  138. $userInfo = MemberService::make()->getInfo($userId);
  139. if($userId<=0 || empty($userInfo)){
  140. return returnJson(MESSAGE_FAILED, true);
  141. }
  142. // 用户交易设置参数
  143. $setting = MemberSettingService::make()->getInfo($userId);
  144. // 15分钟内的买卖比统计
  145. $counts = TradeOrderService::make()->getCountRateByTime(1, $this->userInfo['user_id'], 15);
  146. $sellTotal = TradeOrderService::make()->getCompleteTotalByDay(2, $this->userInfo['user_id']);
  147. $datas = [
  148. 'counts'=> [
  149. 'usdt_num'=> isset($userInfo['usdt_num'])? moneyFormat($userInfo['usdt_num'], 2) : '0.00',
  150. 'buy_total'=> TradeOrderService::make()->getCompleteTotalByDay(1, $this->userInfo['user_id']),
  151. 'sell_total'=> $sellTotal,
  152. 'day_sell_quota'=> isset($setting['day_sell_quota'])? max(0,$setting['day_sell_quota']-$sellTotal) : '0.00',
  153. 'buy_rate'=> isset($counts['buy_rate'])? $counts['buy_rate'] : '0.00',
  154. 'sell_rate'=> isset($counts['sell_rate'])? $counts['sell_rate'] : '0.00',
  155. 'rate_count'=> $counts,
  156. ],
  157. 'setting'=> $setting
  158. ];
  159. return returnJson(MESSAGE_OK, true, $datas);
  160. }
  161. /**
  162. * 获取交易员配置
  163. * @return array
  164. */
  165. public function setting()
  166. {
  167. $this->userId;
  168. $info = $this->model->getInfo($this->userId);
  169. $userId = isset($info['user_id'])? $info['user_id'] : 0;
  170. $userInfo = MemberService::make()->getInfo($userId);
  171. if($userId<=0 || empty($userInfo)){
  172. return returnJson(MESSAGE_FAILED, false);
  173. }
  174. // 用户交易设置参数
  175. $setting = MemberSettingService::make()->getInfo($userId);
  176. return returnJson(MESSAGE_OK, true, $setting);
  177. }
  178. /**
  179. * 获取交易员配置
  180. * @return array
  181. */
  182. public function tradeConfig()
  183. {
  184. $data = ConfigService::make()->getConfigOptionByGroup(6);
  185. $data1 = ConfigService::make()->getConfigOptionTextByGroup(6);
  186. $data['coin_in_tips'] = isset($data1['coin_in_tips'])? $data1['coin_in_tips'] : '';
  187. $data['coin_out_tips'] = isset($data1['coin_out_tips'])? $data1['coin_out_tips'] : '';
  188. return returnJson(MESSAGE_OK, true, $data);
  189. }
  190. /**
  191. * 平台钱包
  192. */
  193. public function wallet()
  194. {
  195. $data = ConfigService::make()->getConfigOptionByGroup(5);
  196. if(isset($data['trc_address']) && $data['trc_address']){
  197. $qrcode = \App\Services\Api\MemberService::make()->makeQrcode($data['trc_address']);
  198. $data['trc_qrcode'] = $qrcode? get_image_url($qrcode) : '';
  199. $data['wallet']['trc_usdt'] = UsdtWalletService::make()->getTrc20Usdt($data['trc_address']);
  200. }
  201. if(isset($data['trc_out_address']) && $data['trc_out_address']){
  202. $qrcode = \App\Services\Api\MemberService::make()->makeQrcode($data['trc_out_address']);
  203. $data['trc_out_qrcode'] = $qrcode? get_image_url($qrcode) : '';
  204. $data['wallet']['trc_out_usdt'] = UsdtWalletService::make()->getTrc20Usdt($data['trc_out_address']);
  205. }
  206. if(isset($data['erc_address']) && $data['erc_address']){
  207. $qrcode = \App\Services\Api\MemberService::make()->makeQrcode($data['erc_address']);
  208. $data['erc_qrcode'] = $qrcode? get_image_url($qrcode) : '';
  209. $data['wallet']['erc_usdt'] = UsdtWalletService::make()->getErc20Usdt($data['erc_address']);
  210. }
  211. if(isset($data['erc_out_address']) && $data['erc_out_address']){
  212. $qrcode = \App\Services\Api\MemberService::make()->makeQrcode($data['erc_out_address']);
  213. $data['erc_out_qrcode'] = $qrcode? get_image_url($qrcode) : '';
  214. $data['wallet']['erc_out_usdt'] = UsdtWalletService::make()->getErc20Usdt($data['erc_out_address']);
  215. }
  216. return returnJson(MESSAGE_OK, true, $data);
  217. }
  218. /**
  219. * 获取钱包地址交易记录
  220. * @return array
  221. */
  222. public function transfer()
  223. {
  224. $contactType = request()->post('contact_type', 1);
  225. $type = request()->post('type', 1);
  226. $changeType = request()->post('change_type', 1);
  227. $address = request()->post('address', '');
  228. $limit = request()->post('limit', 10);
  229. if(empty($address)){
  230. return returnJson(MESSAGE_OK, true);
  231. }
  232. // trc
  233. $params = [
  234. 'change_type'=> $changeType,
  235. 'contact_type'=> $contactType,
  236. 'from'=> $changeType==1? '' : $address,
  237. 'to'=> $changeType==1? $address : '',
  238. ];
  239. $datas = CoinLogService::make()->getDataList($params, $limit);
  240. return returnJson(MESSAGE_OK, true, is_array($datas)? $datas : []);
  241. }
  242. /**
  243. * 后台手动归集总钱包
  244. * @return array
  245. * @throws \Tron\Exceptions\TransactionException
  246. * @throws \Tron\Exceptions\TronErrorException
  247. */
  248. public function trigger()
  249. {
  250. $type = request()->post('type',1);
  251. if($type == 1){
  252. if($result = UsdtWalletService::make()->usdtTrcTrigger(true)){
  253. return showJson(UsdtWalletService::make()->getError(), true, $result);
  254. }else{
  255. return showJson(UsdtWalletService::make()->getError(), false);
  256. }
  257. }else{
  258. if($result = UsdtWalletService::make()->usdtErcTrigger(true)){
  259. return showJson(UsdtWalletService::make()->getError(), true, $result);
  260. }else{
  261. return showJson(UsdtWalletService::make()->getError(), false);
  262. }
  263. }
  264. }
  265. }