IndexController.php 9.1 KB

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