MemberService.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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\Services\Api;
  12. use App\Helpers\Jwt;
  13. use App\Models\ActionLogModel;
  14. use App\Models\MemberModel;
  15. use App\Services\BaseService;
  16. use App\Services\Common\ApiService;
  17. use App\Services\Common\MemberSettingService;
  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\DB;
  23. use phpQrcode\QRcode;
  24. /**
  25. * 会员-服务类
  26. * Class MemberService
  27. * @package App\Services\Api
  28. */
  29. class MemberService extends BaseService
  30. {
  31. // 静态对象
  32. protected static $instance = null;
  33. /**
  34. * 构造函数
  35. * @since 2020/11/10
  36. * MemberService constructor.
  37. */
  38. public function __construct()
  39. {
  40. $this->model = new MemberModel();
  41. }
  42. /**
  43. * 静态入口
  44. * @return static|null
  45. */
  46. public static function make()
  47. {
  48. if (!self::$instance) {
  49. self::$instance = (new static());
  50. }
  51. return self::$instance;
  52. }
  53. /**
  54. * 获取资料详情
  55. * @param $where
  56. * @param array $field
  57. */
  58. public function getInfo($where, array $field = [])
  59. {
  60. $field = $field ? $field : ['id', 'api_id', 'username', 'realname', 'nickname', 'openid', 'idcard', 'google_secret', 'password', 'trade_password', 'trc_address', 'erc_address', 'erc_hexaddress', 'source', 'idcard_check', 'idcard_front_img', 'idcard_back_img', 'idcard_hand_img', 'bank_front_img', 'bank_back_img', 'safe_level', 'user_type', 'member_level', 'usdt_num', 'user_type', 'status', 'credit', 'avatar'];
  61. if (is_array($where)) {
  62. $info = $this->model->where($where)->select($field)->first();
  63. } else {
  64. $info = $this->model->where(['id' => (int)$where])->select($field)->first();
  65. }
  66. $info = $info ? $info->toArray() : [];
  67. if ($info) {
  68. $tradePrice = ConfigService::make()->getConfigByCode('usdt_sell_price');
  69. $tradePrice = $tradePrice ? $tradePrice : 0;
  70. $info['avatar'] = $info['avatar'] ? get_image_url($info['avatar']) : '';
  71. $info['idcard_front_img'] = $info['idcard_front_img'] ? get_image_url($info['idcard_front_img']) : '';
  72. $info['idcard_back_img'] = $info['idcard_back_img'] ? get_image_url($info['idcard_back_img']) : '';
  73. $info['idcard_hand_img'] = $info['idcard_hand_img'] ? get_image_url($info['idcard_hand_img']) : '';
  74. $info['bank_front_img'] = $info['bank_front_img'] ? get_image_url($info['bank_front_img']) : '';
  75. $info['bank_back_img'] = $info['bank_back_img'] ? get_image_url($info['bank_back_img']) : '';
  76. $info['usdt_num'] = isset($info['usdt_num']) ? moneyFormat($info['usdt_num'], 4) : '0.0000';
  77. $info['cny_num'] = $info['usdt_num'] && $tradePrice > 0 ? moneyFormat($info['usdt_num'] * $tradePrice, 6) : '0.0000';
  78. $info['is_collection'] = MemberPaymentService::make()->checkHasByUser($info['id']);
  79. $info['set_trade_password'] = $info['trade_password'] ? 1 : 0;
  80. $info['set_trade_password'] = $info['trade_password'] == $info['password'] ? 2 : $info['set_trade_password'];
  81. unset($info['password']);
  82. unset($info['trade_password']);
  83. // 收款二维码
  84. $qrcode = $this->makeQrcode($info['trc_address']);
  85. $info['trc_qrcode'] = $qrcode ? get_image_url($qrcode) : '';
  86. $ercQrcode = $this->makeQrcode($info['erc_hexaddress']);
  87. $info['erc_qrcode'] = $ercQrcode ? get_image_url($ercQrcode) : '';
  88. }
  89. return $info;
  90. }
  91. /**
  92. * 用户注册
  93. * @param $params
  94. * @return bool
  95. */
  96. public function register($params)
  97. {
  98. // 检测账号是否存在
  99. if ($this->checkExists('username', $params['username'])) {
  100. $this->error = '2005';
  101. return false;
  102. }
  103. $username = isset($params['username']) ? trim($params['username']) : '';
  104. $password = isset($params['password']) ? trim($params['password']) : '';
  105. $userType = isset($params['user_type']) ? intval($params['user_type']) : 1;
  106. if (!checkPassword($password)) {
  107. $this->error = '2007';
  108. return false;
  109. }
  110. $data = [
  111. 'user_type' => $userType ? $userType : 1,
  112. 'username' => $username,
  113. 'password' => get_password($password . md5($password . 'otc')),
  114. 'trade_password' => get_password($password . md5($password . 'otc')),
  115. 'mobile' => isPhone($username) ? $username : '',
  116. 'status' => 1,
  117. 'mark' => 1,
  118. 'create_time' => time(),
  119. ];
  120. // 谷歌验证码
  121. $google = GoogleAuthenticator::CreateSecret();
  122. $data['google_secret'] = isset($google['secret']) ? $google['secret'] : '';
  123. // 生成trc2.0钱包地址
  124. $trcAddress = UsdtWalletService::make()->getTrxAddress();
  125. if ($trcAddress) {
  126. $data['trc_wif'] = isset($trcAddress['wif']) ? $trcAddress['wif'] : '';
  127. $data['trc_hexaddress'] = isset($trcAddress['hexAddress']) ? $trcAddress['hexAddress'] : '';
  128. $data['trc_address'] = isset($trcAddress['address']) ? $trcAddress['address'] : '';
  129. } else {
  130. $this->error = 2201;
  131. return false;
  132. }
  133. // 生erc2.0钱包地址
  134. $ercAddress = UsdtWalletService::make()->getErcAddress();
  135. if ($trcAddress) {
  136. $data['erc_wif'] = isset($ercAddress['wif']) ? $ercAddress['wif'] : '';
  137. $data['erc_hexaddress'] = isset($ercAddress['hexAddress']) ? $ercAddress['hexAddress'] : '';
  138. $data['erc_address'] = isset($ercAddress['address']) ? $ercAddress['address'] : '';
  139. } else {
  140. $this->error = 2202;
  141. return false;
  142. }
  143. if ($id = $this->model->edit($data)) {
  144. MemberSettingService::make()->getInfo($id);
  145. return true;
  146. }
  147. $this->error = 2007;
  148. return false;
  149. }
  150. /**
  151. * 用户登录
  152. * @param $params
  153. * @return array|false
  154. */
  155. public function login($params)
  156. {
  157. $username = isset($params['username']) ? $params['username'] : '';
  158. $password = isset($params['password']) ? $params['password'] : '';
  159. if (empty($username) || empty($password)) {
  160. $this->error = 1013;
  161. return false;
  162. }
  163. // 用户验证
  164. $info = $this->model->getOne([['username', '=', $username]]);
  165. if (!$info) {
  166. $this->error = 2001;
  167. return false;
  168. }
  169. // 密码校验
  170. $password = get_password($password . md5($password . 'otc'));
  171. if ($password != $info['password']) {
  172. $this->error = 2002;
  173. return false;
  174. }
  175. // 使用状态校验
  176. if ($info['status'] != 1) {
  177. $this->error = 2009;
  178. return false;
  179. }
  180. // 承兑商
  181. if ($info['user_type'] == 2) {
  182. $this->error = 1024;
  183. return false;
  184. }
  185. // 设置日志标题
  186. ActionLogModel::setTitle("会员登录APP");
  187. ActionLogModel::record($info);
  188. // JWT生成token
  189. $jwt = new Jwt('jwt_app');
  190. $token = $jwt->getToken($info['id']);
  191. RedisService::set("stores:auths:info:{$info['id']}", $info, 5, 10);
  192. // 登录
  193. $updateData = ['login_time' => time(),'is_online'=>1,'login_count'=>$info['login_count']+1, 'login_ip' => get_client_ip()];
  194. if (empty($info['google_secret'])) {
  195. $google = GoogleAuthenticator::CreateSecret();
  196. $updateData['google_secret'] = isset($google['secret']) ? $google['secret'] : '';
  197. }
  198. $this->model->where(['id' => $info['id']])->update($updateData);
  199. // 登录数据
  200. return [
  201. 'token' => $token,
  202. 'user_id' => $info['id'],
  203. 'user_type' => $info['user_type'],
  204. ];
  205. }
  206. /**
  207. * API用户注册
  208. * @param $apiId
  209. * @param $params
  210. * @return bool
  211. * @throws \BitWasp\Bitcoin\Exceptions\RandomBytesFailure
  212. * @throws \Tron\Exceptions\TronErrorException
  213. */
  214. public function apiRegister($apiId, $params)
  215. {
  216. // 检测账号是否存在
  217. if ($this->checkExists('username', $params['username'])) {
  218. $this->error = '2005';
  219. return false;
  220. }
  221. var_dump($params);
  222. $username = isset($params['username']) ? trim($params['username']) : '';
  223. $password = isset($params['password']) ? trim($params['password']) : '';
  224. $userType = isset($params['user_type']) ? intval($params['user_type']) : 0;
  225. $apiInfo = ApiService::make()->getInfo($apiId);
  226. $limits = isset($apiInfo['user_limits']) ? $apiInfo['user_limits'] : [];
  227. if ($limits && !in_array($userType, $limits)) {
  228. $this->error = '6004';
  229. return false;
  230. }
  231. $data = [
  232. 'username' => $username,
  233. 'user_type' => $userType ? $userType : 3,
  234. 'password' => get_password($password . md5($password . 'otc')),
  235. 'trade_password' => get_password($password . md5($password . 'otc')),
  236. 'mobile' => isPhone($username) ? $username : '',
  237. 'status' => 1,
  238. 'mark' => 1,
  239. 'create_time' => time(),
  240. ];
  241. // 生成trc2.0钱包地址
  242. $trcAddress = UsdtWalletService::make()->getTrxAddress();
  243. if ($trcAddress) {
  244. $data['trc_wif'] = isset($trcAddress['wif']) ? $trcAddress['wif'] : '';
  245. $data['trc_hexaddress'] = isset($trcAddress['hexAddress']) ? $trcAddress['hexAddress'] : '';
  246. $data['trc_address'] = isset($trcAddress['address']) ? $trcAddress['address'] : '';
  247. } else {
  248. $this->error = 2201;
  249. return false;
  250. }
  251. // 生erc2.0钱包地址
  252. $ercAddress = UsdtWalletService::make()->getErcAddress();
  253. if ($trcAddress) {
  254. $data['erc_wif'] = isset($ercAddress['wif']) ? $ercAddress['wif'] : '';
  255. $data['erc_hexaddress'] = isset($ercAddress['hexAddress']) ? $ercAddress['hexAddress'] : '';
  256. $data['erc_address'] = isset($ercAddress['address']) ? $ercAddress['address'] : '';
  257. } else {
  258. $this->error = 2202;
  259. return false;
  260. }
  261. if ($id = $this->model->edit($data)) {
  262. MemberSettingService::make()->getInfo($id);
  263. return true;
  264. }
  265. $this->error = 2007;
  266. return false;
  267. }
  268. /**
  269. * API用户登录
  270. * @param $params
  271. * @return array|false
  272. */
  273. public function apiLogin($apiId, $params)
  274. {
  275. $username = isset($params['username']) ? $params['username'] : '';
  276. $password = isset($params['password']) ? $params['password'] : '';
  277. $userType = isset($params['user_type']) ? intval($params['user_type']) : 0;
  278. $apiKey = isset($params['api_key']) ? $params['api_key'] : '';
  279. if (empty($username) || empty($password) || empty($apiKey) || empty($userType)) {
  280. $this->error = 1013;
  281. return false;
  282. }
  283. // 用户验证
  284. $info = $this->model->getOne([['username', '=', $username]]);
  285. if (!$info) {
  286. // 直接注册
  287. if (!$this->apiRegister($apiId, $params)) {
  288. return false;
  289. }
  290. $info = $this->model->getOne([['username', '=', $username]]);
  291. } else {
  292. // 密码校验
  293. $password = get_password($password . md5($password . 'otc'));
  294. if ($password != $info['password']) {
  295. $this->error = 2002;
  296. return false;
  297. }
  298. // 使用状态校验
  299. if ($info['status'] != 1) {
  300. $this->error = 2009;
  301. return false;
  302. }
  303. if ($info['api_id'] != $apiId) {
  304. $this->error = 6010;
  305. return false;
  306. }
  307. // 用户类型
  308. if (!in_array($info['user_type'], [3, 4, 5])) {
  309. $this->error = 1024;
  310. return false;
  311. }
  312. }
  313. // 设置日志标题
  314. ActionLogModel::setTitle("接口平台会员授权登录");
  315. ActionLogModel::record($info);
  316. // JWT生成token
  317. $token = 'TB'.strtoupper(md5($info['id'] . $username).rand(100,999));
  318. RedisService::set("apis:auths:info:{$info['id']}", $info, rand(5, 10));
  319. RedisService::set("apis:tokens:{$token}", ['id' => $info['id'], 'info' => $info, 'token' => $token], 48 * 3600);
  320. // 登录
  321. $updateData = ['login_time' => time(), 'login_ip' => get_client_ip()];
  322. $this->model->where(['id' => $info['id']])->update($updateData);
  323. // 登录数据
  324. if ($info['idcard_check'] != 1) {
  325. $appUrl = ConfigService::make()->getConfigByCode('app_download_url');
  326. return [
  327. 'app_url' => $appUrl,
  328. ];
  329. } else {
  330. return [
  331. 'token' => $token,
  332. 'user_id' => $info['id'],
  333. ];
  334. }
  335. }
  336. /**
  337. * 身份认证
  338. * @param $userId
  339. * @param $params
  340. * @return false
  341. */
  342. public function auth($userId, $params)
  343. {
  344. $data = [
  345. 'idcard' => isset($params['idcard']) ? $params['idcard'] : '',
  346. 'realname' => isset($params['realname']) ? $params['realname'] : '',
  347. ];
  348. if (isset($params['idcard_front_img']) && strpos($params['idcard_front_img'], 'http') === false) {
  349. $data['idcard_front_img'] = $params['idcard_front_img'];
  350. }
  351. if (isset($params['idcard_back_img']) && strpos($params['idcard_back_img'], 'http') === false) {
  352. $data['idcard_back_img'] = $params['idcard_back_img'];
  353. }
  354. if (isset($params['idcard_hand_img']) && strpos($params['idcard_hand_img'], 'http') === false) {
  355. $data['idcard_hand_img'] = $params['idcard_hand_img'];
  356. }
  357. if (isset($params['bank_front_img']) && strpos($params['bank_front_img'], 'http') === false) {
  358. $data['bank_front_img'] = $params['bank_front_img'];
  359. }
  360. if (isset($params['bank_back_img']) && strpos($params['bank_back_img'], 'http') === false) {
  361. $data['bank_back_img'] = $params['bank_back_img'];
  362. }
  363. $info = $this->getInfo($userId);
  364. $idcardCheck = isset($info['idcard_check']) ? $info['idcard_check'] : 0;
  365. if ($idcardCheck == 1) {
  366. $this->error = '2011';
  367. return false;
  368. }
  369. return $this->model->where(['id' => $userId])->update($data);
  370. }
  371. /**
  372. * 修改账号
  373. * @param $userId
  374. * @param $params
  375. * @return bool
  376. */
  377. public function modify($userId, $params)
  378. {
  379. $username = isset($params['username']) ? $params['username'] : '';
  380. $newUsername = isset($params['new_username']) ? $params['new_username'] : '';
  381. $password = isset($params['password']) ? $params['password'] : '';
  382. if (empty($username) || empty($password)) {
  383. $this->error = 1013;
  384. return false;
  385. }
  386. // 用户验证
  387. $info = $this->model->getOne([['username', '=', $username]]);
  388. if (!$info || $info['id'] != $userId) {
  389. $this->error = 2001;
  390. return false;
  391. }
  392. // 使用状态校验
  393. if ($info['status'] != 1) {
  394. $this->error = 2009;
  395. return false;
  396. }
  397. // 密码校验
  398. $password = get_password($password . md5($password . 'otc'));
  399. if ($password != $info['password']) {
  400. $this->error = 2002;
  401. return false;
  402. }
  403. $checkInfo = $this->model->getOne([['username', '=', $newUsername]]);
  404. if ($checkInfo && $checkInfo['id'] != $info['id']) {
  405. $this->error = 2005;
  406. return false;
  407. }
  408. if (!$this->model->where(['id' => $info['id']])->update(['username' => $newUsername, 'update_time' => time()])) {
  409. $this->error = 2021;
  410. return false;
  411. }
  412. $this->error = 2020;
  413. return true;
  414. }
  415. /**
  416. * 修改更新登录密码
  417. * @param $userId
  418. * @param $params
  419. * @return bool
  420. */
  421. public function updatePassword($userId, $params)
  422. {
  423. $username = isset($params['username']) ? $params['username'] : '';
  424. $password = isset($params['password']) ? $params['password'] : '';
  425. if (empty($username) || empty($password)) {
  426. $this->error = 1013;
  427. return false;
  428. }
  429. // 用户验证
  430. $info = $this->model->getOne([['username', '=', $username]]);
  431. if (!$info || $info['id'] != $userId) {
  432. $this->error = 2001;
  433. return false;
  434. }
  435. // 使用状态校验
  436. if ($info['status'] != 1) {
  437. $this->error = 2009;
  438. return false;
  439. }
  440. // 更新登录密码
  441. $password = get_password($password . md5($password . 'otc'));
  442. if (!$this->model->where(['id' => $info['id']])->update(['password' => $password, 'update_time' => time()])) {
  443. $this->error = 2025;
  444. return false;
  445. }
  446. $this->error = 2024;
  447. return true;
  448. }
  449. /**
  450. * 修改更新交易密码
  451. * @param $userId
  452. * @param $params
  453. * @return bool
  454. */
  455. public function updateTradePassword($userId, $params)
  456. {
  457. $username = isset($params['username']) ? $params['username'] : '';
  458. $tradePassword = isset($params['trade_password']) ? $params['trade_password'] : '';
  459. if (empty($username) || empty($tradePassword)) {
  460. $this->error = 1013;
  461. return false;
  462. }
  463. // 用户验证
  464. $info = $this->model->getOne([['username', '=', $username]]);
  465. if (!$info || $info['id'] != $userId) {
  466. $this->error = 2001;
  467. return false;
  468. }
  469. // 使用状态校验
  470. if ($info['status'] != 1) {
  471. $this->error = 2009;
  472. return false;
  473. }
  474. // 交易密码
  475. $password = get_password($tradePassword . md5($tradePassword . 'otc'));
  476. if (!$this->model->where(['id' => $info['id']])->update(['safe_level' => 2, 'trade_password' => $password, 'update_time' => time()])) {
  477. $this->error = 2023;
  478. return false;
  479. }
  480. $this->error = 2022;
  481. return true;
  482. }
  483. /**
  484. * 获取钱包地址密钥参数
  485. * @param $address
  486. * @param string $type 链类型:trc-trc2.0,erc
  487. * @return mixed
  488. */
  489. public function getWallet($address, $type = 'trc')
  490. {
  491. return $this->model->where([$type . '_address' => $address])->select(['id', $type . '_address', $type . '_hexaddress', $type . '_wif'])->first();
  492. }
  493. /**
  494. * 获取待处理用户数据
  495. * @param int $page
  496. * @param int $pageSize
  497. * @return array|mixed
  498. */
  499. public function getCatchMember($page = 1, $pageSize = 500)
  500. {
  501. $cacheKey = "caches:wallet:members:{$page}_{$pageSize}";
  502. $datas = RedisService::get($cacheKey);
  503. if ($datas) {
  504. return $datas;
  505. }
  506. $datas = $this->model->where(['mark' => 1])
  507. ->select(['id', 'trc_address', 'usdt_num'])
  508. ->paginate($pageSize > 0 ? $pageSize : 9999999, [], 'page', $page);
  509. $datas = $datas ? $datas->toArray() : [];
  510. $datas = isset($datas['data']) ? $datas['data'] : [];
  511. if ($datas) {
  512. RedisService::set($cacheKey, $datas, rand(120, 600));
  513. }
  514. return $datas;
  515. }
  516. /**
  517. * 匹配承兑商
  518. * @param $num 交易数量
  519. * @param int $tradeType 交易类型:1-购买,2-出售
  520. */
  521. public function getTradeMember($num, $tradeType = 1, $userId = 0)
  522. {
  523. $data = $this->model->from('member as m')
  524. ->leftJoin('user as u', 'u.user_id', '=', 'm.id')
  525. ->leftJoin('member_setting as ms', 'ms.user_id', '=', 'm.id')
  526. ->where(['m.status' => 1, 'm.user_type' => 2, 'u.status' => 1, 'm.mark' => 1])
  527. ->where('m.usdt_num', '>=', $num)
  528. ->where(function ($query) use ($userId) {
  529. if ($userId) {
  530. $query->whereNotIn('m.id', [$userId]);
  531. }
  532. })
  533. ->where(function ($query) use ($tradeType) {
  534. $time = time();
  535. // 买单
  536. if ($tradeType == 1) {
  537. $query->whereRaw("(buy_online = 1 and buy_online_time>{$time}) or buy_online is null");
  538. } // 卖单
  539. else {
  540. $query->whereRaw("((sell_online = 1 and sell_online_time>{$time}) or sell_online is null) and day_sell_quota > day_sell_total");
  541. }
  542. })
  543. ->select(['m.id', 'm.usdt_num', 'm.username', 'm.credit'])
  544. ->orderBy("credit", 'desc')
  545. ->orderBy(DB::raw("rand()"))
  546. ->first();
  547. $data = $data ? $data->toArray() : [];
  548. return $data;
  549. }
  550. /**
  551. * 匹配承兑商
  552. * @param $num 交易数量
  553. * @param int $tradeType 交易类型:1-购买,2-出售
  554. */
  555. public function getTradeMemberOptions($num, $tradeType = 1, $userId = 0, $keyword = '', $paseSize = 50)
  556. {
  557. $cacheKey = "caches:tradeMenber:{$tradeType}_" . md5($num . $userId . $keyword . $paseSize);
  558. if ($datas = RedisService::get($cacheKey)) {
  559. return $datas;
  560. }
  561. $datas = $this->model->from('member as m')
  562. ->leftJoin('user as u', 'u.user_id', '=', 'm.id')
  563. ->leftJoin('member_setting as ms', 'ms.user_id', '=', 'm.id')
  564. ->where(['m.status' => 1, 'm.user_type' => 2, 'u.status' => 1, 'm.mark' => 1])
  565. ->where('m.usdt_num', '>=', $num)
  566. ->where(function ($query) use ($userId, $keyword) {
  567. if ($userId) {
  568. $query->whereNotIn('m.id', [$userId]);
  569. }
  570. if ($keyword) {
  571. $query->where('m.username', 'like', "%{$keyword}%");
  572. }
  573. })
  574. ->where(function ($query) use ($tradeType) {
  575. $time = time();
  576. // 买单
  577. if ($tradeType == 1) {
  578. $query->whereRaw("(buy_online = 1 and buy_online_time>{$time}) or buy_online is null");
  579. } // 卖单
  580. else {
  581. $query->whereRaw("((sell_online = 1 and sell_online_time>{$time}) or sell_online is null) and day_sell_quota > day_sell_total");
  582. }
  583. })
  584. ->select(['m.id', 'm.usdt_num', 'm.username', 'm.credit'])
  585. ->orderBy("credit", 'desc')
  586. ->orderBy("m.safe_level", 'desc')
  587. ->paginate($paseSize);
  588. $datas = $datas ? $datas->toArray() : [];
  589. $datas = isset($datas['data']) ? $datas['data'] : [];
  590. if ($datas) {
  591. RedisService::set($cacheKey, $datas, rand(10, 30));
  592. }
  593. return $datas;
  594. }
  595. /**
  596. * 生成普通参数二维码
  597. * @param $str 参数
  598. * @param bool $refresh 是否重新生成
  599. * @return bool
  600. */
  601. public function makeQrcode($str, $refresh = false, $size = 4, $margin = 2, $level = 2)
  602. {
  603. $qrFile = '/images/qrcode/';
  604. if (!is_dir('/uploads' . $qrFile)) {
  605. @mkdir('./uploads' . $qrFile, 0755, true);
  606. }
  607. $qrFile = $qrFile . 'C_' . strtoupper(md5($str . '_' . $size . $margin . $level)) . '.png';
  608. $cacheKey = "caches:qrcodes:member_" . md5($str);
  609. if (RedisService::get($cacheKey) && is_file('/uploads' . $qrFile) && !$refresh) {
  610. //return $qrFile;
  611. }
  612. QRcode::png($str, './uploads' . $qrFile, $level, $size, $margin);
  613. if (!file_exists('./uploads' . $qrFile)) {
  614. return false;
  615. }
  616. RedisService::set($cacheKey, ['str' => $str, 'qrcode' => $qrFile, 'date' => date('Y-m-d H:i:s')], 7 * 24 * 3600);
  617. return $qrFile;
  618. }
  619. /**
  620. * 获取钱包归集用户列表
  621. * @param float $minUsdt
  622. * @param int $page
  623. * @param int $pageSize
  624. * @return array|mixed
  625. */
  626. public function getTriggerAddressList($minUsdt = 0.2, $page = 1, $pageSize = 200)
  627. {
  628. $cacheKey = "caches:wallet:triggers:{$page}_{$pageSize}";
  629. $datas = RedisService::get($cacheKey);
  630. if ($datas) {
  631. return $datas;
  632. }
  633. $datas = $this->model->where(['mark' => 1])
  634. ->select(['id', 'trc_usdt', 'trc_address', 'trc_wif', 'trc_hexaddress', 'erc_address', 'erc_wif', 'erc_hexaddress'])
  635. ->orderBy('trc_usdt')
  636. ->paginate($pageSize > 0 ? $pageSize : 9999999, [], 'page', $page);
  637. $datas = $datas ? $datas->toArray() : [];
  638. $datas = isset($datas['data']) ? $datas['data'] : [];
  639. if ($datas) {
  640. RedisService::set($cacheKey, $datas, rand(10, 30));
  641. }
  642. return $datas;
  643. }
  644. }