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