IndexController.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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\Common\MemberService;
  14. use App\Services\Common\MemberSettingService;
  15. use App\Services\Common\MenuService;
  16. use App\Services\Common\TradeOrderService;
  17. use App\Services\Common\UserService;
  18. use App\Services\ConfigService;
  19. use App\Services\RedisService;
  20. use App\Services\UsdtWalletService;
  21. use Earnp\GoogleAuthenticator\GoogleAuthenticator;
  22. use Illuminate\Support\Facades\Cache;
  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 updatePwd()
  85. {
  86. $userService = new UserService();
  87. $result = $userService->updatePwd($this->userId);
  88. return $result;
  89. }
  90. /**
  91. * 设置修改交易密码
  92. * @return mixed
  93. */
  94. public function updateTradePwd()
  95. {
  96. $userService = new UserService();
  97. $result = $userService->updateTradePwd($this->userInfo['user_id'], $this->userId);
  98. return $result;
  99. }
  100. /**
  101. * 清除缓存
  102. * @return array
  103. */
  104. public function clearCache(){
  105. RedisService::keyDel("caches:d*");
  106. RedisService::keyDel("caches:inde*");
  107. RedisService::keyDel("caches:advert*");
  108. RedisService::keyDel("caches:article*");
  109. RedisService::keyDel("caches:qrcode*");
  110. RedisService::keyDel("laravel_cache:model*");
  111. return message(MESSAGE_OK, true);
  112. }
  113. /**
  114. * 获取首页数据
  115. * @return array
  116. */
  117. public function indexData()
  118. {
  119. $this->userId;
  120. $info = $this->model->getInfo($this->userId);
  121. $userId = isset($info['user_id'])? $info['user_id'] : 0;
  122. $userInfo = MemberService::make()->getInfo($userId);
  123. if($userId<=0 || empty($userInfo)){
  124. return message(MESSAGE_FAILED, false);
  125. }
  126. // 用户交易设置参数
  127. $setting = MemberSettingService::make()->getInfo($userId);
  128. // 15分钟内的买卖比统计
  129. $counts = TradeOrderService::make()->getCountRateByTime(1, $this->userInfo['user_id'], 15);
  130. $sellTotal = TradeOrderService::make()->getCompleteTotalByDay(2, $this->userInfo['user_id']);
  131. $datas = [
  132. 'counts'=> [
  133. 'usdt_num'=> isset($userInfo['usdt_num'])? moneyFormat($userInfo['usdt_num'], 2) : '0.00',
  134. 'buy_total'=> TradeOrderService::make()->getCompleteTotalByDay(1, $this->userInfo['user_id']),
  135. 'sell_total'=> $sellTotal,
  136. 'day_sell_quota'=> isset($setting['day_sell_quota'])? max(0,$setting['day_sell_quota']-$sellTotal) : '0.00',
  137. 'buy_rate'=> isset($counts['buy_rate'])? $counts['buy_rate'] : '0.00',
  138. 'sell_rate'=> isset($counts['sell_rate'])? $counts['sell_rate'] : '0.00',
  139. 'rate_count'=> $counts,
  140. ],
  141. 'setting'=> $setting
  142. ];
  143. return message(MESSAGE_OK, true, $datas);
  144. }
  145. /**
  146. * 获取交易员配置
  147. * @return array
  148. */
  149. public function setting()
  150. {
  151. $this->userId;
  152. $info = $this->model->getInfo($this->userId);
  153. $userId = isset($info['user_id'])? $info['user_id'] : 0;
  154. $userInfo = MemberService::make()->getInfo($userId);
  155. if($userId<=0 || empty($userInfo)){
  156. return message(MESSAGE_FAILED, false);
  157. }
  158. // 用户交易设置参数
  159. $setting = MemberSettingService::make()->getInfo($userId);
  160. return message(MESSAGE_OK, true, $setting);
  161. }
  162. /**
  163. * 获取交易员配置
  164. * @return array
  165. */
  166. public function tradeConfig()
  167. {
  168. $data = ConfigService::make()->getConfigOptionByGroup(6);
  169. $data1 = ConfigService::make()->getConfigOptionTextByGroup(6);
  170. $data['coin_in_tips'] = isset($data1['coin_in_tips'])? $data1['coin_in_tips'] : '';
  171. $data['coin_out_tips'] = isset($data1['coin_out_tips'])? $data1['coin_out_tips'] : '';
  172. return message(MESSAGE_OK, true, $data);
  173. }
  174. /**
  175. * 平台钱包
  176. */
  177. public function wallet()
  178. {
  179. $data = ConfigService::make()->getConfigOptionByGroup(5);
  180. if(isset($data['trc_address']) && $data['trc_address']){
  181. $qrcode = \App\Services\Api\MemberService::make()->makeQrcode($data['trc_address']);
  182. $data['trc_qrcode'] = $qrcode? get_image_url($qrcode) : '';
  183. $data['wallet']['trc_usdt'] = UsdtWalletService::make()->getTrc20Usdt($data['trc_address']);
  184. }
  185. if(isset($data['erc_address']) && $data['erc_address']){
  186. $qrcode = \App\Services\Api\MemberService::make()->makeQrcode($data['erc_address']);
  187. $data['erc_qrcode'] = $qrcode? get_image_url($qrcode) : '';
  188. $data['wallet']['erc_usdt'] = UsdtWalletService::make()->getErc20Usdt($data['erc_address']);
  189. }
  190. if(isset($data['trc_out_address']) && $data['trc_out_address']){
  191. $qrcode = \App\Services\Api\MemberService::make()->makeQrcode($data['trc_out_address']);
  192. $data['trc_out_qrcode'] = $qrcode? get_image_url($qrcode) : '';
  193. $data['wallet']['trc_out_usdt'] = UsdtWalletService::make()->getTrc20Usdt($data['trc_out_address']);
  194. }
  195. if(isset($data['erc_out_address']) && $data['erc_out_address']){
  196. $qrcode = \App\Services\Api\MemberService::make()->makeQrcode($data['erc_out_address']);
  197. $data['erc_out_qrcode'] = $qrcode? get_image_url($qrcode) : '';
  198. $data['wallet']['erc_out_usdt'] = UsdtWalletService::make()->getErc20Usdt($data['erc_out_address']);
  199. }
  200. return message(MESSAGE_OK, true, $data);
  201. }
  202. /**
  203. * 获取钱包地址交易记录
  204. * @return array
  205. */
  206. public function transfer()
  207. {
  208. $contactType = request()->post('contact_type', 1);
  209. $type = request()->post('type', 1);
  210. $address = request()->post('address', 1);
  211. $limit = request()->post('limit', 15);
  212. if(empty($address)){
  213. return message(MESSAGE_OK, false);
  214. }
  215. // trc
  216. if($contactType == 1){
  217. $datas = UsdtWalletService::make()->getTrc20TransferLog($address,$type, $limit);
  218. }else {
  219. $datas = UsdtWalletService::make()->getErc20TransferLog($address,$type, $limit);
  220. }
  221. return message(MESSAGE_OK, true, is_array($datas)? $datas : []);
  222. }
  223. }