AcceptorService.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  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\Models\AcceptorModel;
  13. use App\Models\AccountLogModel;
  14. use App\Models\BalanceLogModel;
  15. use App\Models\MemberModel;
  16. use App\Services\BaseService;
  17. use App\Services\ConfigService;
  18. use App\Services\RedisService;
  19. use App\Services\WalletService;
  20. use Illuminate\Support\Facades\DB;
  21. /**
  22. * 承兑商服务管理-服务类
  23. * @author laravel开发员
  24. * @since 2020/11/11
  25. * @package App\Services\Api
  26. */
  27. class AcceptorService extends BaseService
  28. {
  29. // 静态对象
  30. protected static $instance = null;
  31. /**
  32. * 构造函数
  33. * @author laravel开发员
  34. * @since 2020/11/11
  35. * MerchantService constructor.
  36. */
  37. public function __construct()
  38. {
  39. $this->model = new AcceptorModel();
  40. }
  41. /**
  42. * 静态入口
  43. * @return static|null
  44. */
  45. public static function make()
  46. {
  47. if (!self::$instance) {
  48. self::$instance = (new static());
  49. }
  50. return self::$instance;
  51. }
  52. /**
  53. * 获取缓存列表
  54. * @param $position
  55. * @param int $num
  56. * @return array|mixed
  57. */
  58. public function getDataList($params, $pageSize = 15, $refresh = false, $field = '')
  59. {
  60. $page = request()->post('page', 1);
  61. $cacheKey = "caches:acceptor:page_{$page}_" . md5(json_encode($params) . $pageSize);
  62. $datas = RedisService::get($cacheKey);
  63. $data = isset($datas['data']) ? $datas['data'] : [];
  64. if ($datas && $data && !$refresh) {
  65. return [
  66. 'list' => $data,
  67. 'total' => isset($datas['total']) ? $datas['total'] : 0,
  68. 'pageSize' => $pageSize
  69. ];
  70. }
  71. $field = $field ? $field : 'lev_a.*,lev_b.nickname,lev_b.username,lev_b.avatar';
  72. $order = 'lev_a.id desc';
  73. $datas = $this->model->from('acceptor as a')
  74. ->leftJoin('member as b', 'b.id', '=', 'a.user_id')
  75. ->where(['a.mark' => 1, 'b.mark' => 1])
  76. ->whereIn('a.trade_status', [1, 2])
  77. ->where(function ($query) use ($params) {
  78. $kw = isset($params['kw']) ? trim($params['kw']) : '';
  79. if ($kw) {
  80. $query->where('a.name', 'like', "%{$kw}%");
  81. }
  82. })
  83. ->where(function ($query) use ($params) {
  84. // 状态
  85. $status = isset($params['status']) && $params['status'] >= 0 ? intval($params['status']) : 2;
  86. if ($status > 0) {
  87. $query->where('a.status', $status);
  88. }
  89. $payType = isset($params['pay_type']) && $params['pay_type'] >0 ? intval($params['pay_type']) : 0;
  90. if($payType){
  91. $query->where('a.pay_type', $payType);
  92. }
  93. })
  94. ->selectRaw($field)
  95. ->orderByRaw($order)
  96. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  97. $datas = $datas ? $datas->toArray() : [];
  98. if ($datas) {
  99. $xdPrice = ConfigService::make()->getConfigByCode('xd_price', 100);
  100. $currency = isset($params['currency']) && $params['currency']? strtoupper($params['currency']) : 'CNY';
  101. $tradeType = isset($params['trade_type']) && $params['trade_type']? intval($params['trade_type']) : 1;
  102. $cnyPrice = $this->getRealPrice(1,$currency, $tradeType);
  103. foreach ($datas['data'] as &$item) {
  104. $item['avatar'] = $item['avatar'] ? get_image_url($item['avatar']) : '';
  105. $item['currency_price'] = $this->getRealPrice(1, 'CNY',0);
  106. $item['currency_quota'] = $this->getRealPrice(floatval($item['quota']), $currency, 3);
  107. $item['currency_rate'] = $currency=='CNY'? 1 : WalletService::make()->getRateByCNY($currency);
  108. $item['usdt_price'] = moneyFormat(1 / $xdPrice, 2);
  109. $item['price'] = $cnyPrice;
  110. $item['time'] = $item['time']>60? intval($item['time']/60) : 20;
  111. }
  112. unset($item);
  113. RedisService::set($cacheKey, $datas, rand(3, 5));
  114. }
  115. return [
  116. 'list' => isset($datas['data']) ? $datas['data'] : [],
  117. 'total' => isset($datas['total']) ? $datas['total'] : 0,
  118. 'pageSize' => $pageSize
  119. ];
  120. }
  121. /**
  122. * @param $price
  123. * @param $urrency
  124. * @param int $tradeType
  125. * @return string
  126. */
  127. public function getRealPrice($money,$currency='CNY', $tradeType=1)
  128. {
  129. $usdtPrice = RedisService::get("caches:wallets:usdt_rate");
  130. if($usdtPrice<=0){
  131. $usdtCnyPrice = ConfigService::make()->getConfigByCode('usdt_cny_price', 7.2);
  132. $usdtPrice = $usdtCnyPrice>0 && $usdtCnyPrice< 100? $usdtCnyPrice : 0;
  133. }
  134. // 人民币与其他币的汇率价格
  135. $currencyPrice = $currency=='CNY'? 1 : WalletService::make()->getRateByCNY($currency);
  136. // 买价
  137. $xdPrice = ConfigService::make()->getConfigByCode('xd_price', 100);
  138. $buyPrice = moneyFormat($money/$xdPrice,4); // 星豆价格
  139. $cnyPrice = moneyFormat($buyPrice * $usdtPrice,4); // 币种价格
  140. if($tradeType == 1){
  141. $xdBuyPriceRate = ConfigService::make()->getConfigByCode('trade_buy_price_rate', 0);
  142. $xdBuyPriceRate = $xdBuyPriceRate>0 && $xdBuyPriceRate<100? $xdBuyPriceRate : 0;
  143. $cnyBuyPrice = moneyFormat($cnyPrice + ($cnyPrice * $xdBuyPriceRate/100), 2); // 上浮价格
  144. return moneyFormat($cnyBuyPrice * $currencyPrice, 4); // 汇率价格
  145. }else if($tradeType == 2){
  146. $xdSellPriceRate = ConfigService::make()->getConfigByCode('trade_sell_price_rate', 0);
  147. $xdSellPriceRate = $xdSellPriceRate>0 && $xdSellPriceRate<100? $xdSellPriceRate : 0;
  148. $cnyBuyPrice = moneyFormat($cnyPrice - ($cnyPrice * $xdSellPriceRate/100), 2); // 下浮价格
  149. return moneyFormat($cnyBuyPrice * $currencyPrice, 4); // 汇率价格
  150. }
  151. return moneyFormat($cnyPrice * $currencyPrice, 4); // 汇率价格
  152. }
  153. /**
  154. * 获取信息
  155. * @param $where
  156. * @param array $field
  157. * @return array|mixed
  158. */
  159. public function getInfo($id, $field = [])
  160. {
  161. $defaultField = ['a.id', 'a.user_id', 'a.realname','a.name', 'a.mobile','a.telegram', 'a.quota','a.pay_type', 'a.usdt', 'a.status','b.nickname','b.avatar'];
  162. $field = $field ? $field : $defaultField;
  163. $info = $this->model->from('acceptor as a')
  164. ->leftjoin('member as b','b.id','=','a.user_id')
  165. ->where(['a.id'=> $id,'a.mark'=>1])
  166. ->select($field)
  167. ->first();
  168. $info = $info ? $info->toArray() : [];
  169. if ($info) {
  170. $info['avatar'] = get_image_url($info['avatar']);
  171. }
  172. return $info;
  173. }
  174. /**
  175. * 修改信息
  176. * @param $userId
  177. * @param $params
  178. * @return array|false|int[]
  179. */
  180. public function saveInfo($userId, $params)
  181. {
  182. // 验证是否入驻过和入驻状态
  183. $info = $this->model->where(['user_id' => $userId])->select('id', 'realname', 'trade_status', 'status', 'mark')->first();
  184. $tradeStatus = isset($info['trade_status']) ? $info['trade_status'] : 0;
  185. $mark = isset($info['mark']) ? $info['mark'] : 0;
  186. $id = isset($info['id']) ? $info['id'] : 0;
  187. if ($userId && empty($info)) {
  188. $this->error = 2216;
  189. return false;
  190. }
  191. // 是否被冻结
  192. if ($id && $tradeStatus == 4 && $mark) {
  193. $this->error = 2202;
  194. return false;
  195. }
  196. // 验证账户是否正常
  197. $userInfo = MemberService::make()->getCacheInfo(['id' => $userId], ['id', 'status']);
  198. $status = isset($userInfo['status']) ? $userInfo['status'] : 0;
  199. if (empty($userInfo) || $status != 1) {
  200. $this->error = 2017;
  201. return false;
  202. }
  203. // 入驻数据
  204. $data = [
  205. 'realname' => isset($params['realname']) ? $params['realname'] : '',
  206. 'user_id' => $userId,
  207. 'mobile' => isset($params['mobile']) ? $params['mobile'] : '',
  208. 'telegram' => isset($params['telegram']) ? $params['telegram'] : '',
  209. 'price_float' => isset($params['price_float']) ? $params['price_float'] : '',
  210. 'create_time' => time(),
  211. 'update_time' => time(),
  212. 'mark' => 1,
  213. ];
  214. // 写入数据
  215. if ($id) {
  216. if ($this->model->where(['id' => $id])->update($data)) {
  217. $this->error = 2228;
  218. RedisService::keyDel("caches:acceptor:info:temp_{$userId}*");
  219. return ['id' => $id];
  220. } else {
  221. $this->error = 2229;
  222. return false;
  223. }
  224. } else {
  225. if ($merchId = $this->model->insertGetId($data)) {
  226. $this->error = 2228;
  227. RedisService::keyDel("caches:acceptor:info:temp_{$userId}*");
  228. return ['id' => $id];
  229. } else {
  230. $this->error = 2229;
  231. return false;
  232. }
  233. }
  234. }
  235. /**
  236. * 申请入驻
  237. * @param $userId
  238. * @param $params
  239. * @return array|false|int[]
  240. */
  241. public function apply($userId, $params)
  242. {
  243. // 验证是否入驻过和入驻状态
  244. $info = $this->model->where(['user_id' => $userId])->select('id', 'name', 'trade_status', 'status', 'mark')->first();
  245. $status = isset($info['status']) ? $info['status'] : 0;
  246. $tradeStatus = isset($info['trade_status']) ? $info['trade_status'] : 0;
  247. $mark = isset($info['mark']) ? $info['mark'] : 0;
  248. $id = isset($info['id']) ? $info['id'] : 0;
  249. if ($id && $status == 2 && $mark) {
  250. $this->error = 2201;
  251. return false;
  252. }
  253. // 是否被冻结
  254. if ($id && $tradeStatus == 4 && $mark) {
  255. $this->error = 2202;
  256. return false;
  257. }
  258. // 验证账户是否正常
  259. $userInfo = MemberService::make()->getCacheInfo(['id' => $userId], ['id', 'status']);
  260. $status = isset($userInfo['status']) ? $userInfo['status'] : 0;
  261. if (empty($userInfo) || $status != 1) {
  262. $this->error = 2017;
  263. return false;
  264. }
  265. // 入驻数据
  266. // 入驻数据
  267. $data = [
  268. 'realname' => isset($params['realname']) ? $params['realname'] : '',
  269. 'user_id' => $userId,
  270. 'mobile' => isset($params['mobile']) ? $params['mobile'] : '',
  271. 'telegram' => isset($params['telegram']) ? $params['telegram'] : '',
  272. 'price_float' => isset($params['price_float']) ? $params['price_float'] : '',
  273. 'create_time' => time(),
  274. 'update_time' => time(),
  275. 'quota' => 0,
  276. 'trade_status' => 1,
  277. 'status' => 1,
  278. 'mark' => 1,
  279. ];
  280. // 写入数据
  281. if ($id) {
  282. if ($this->model->where(['id' => $id])->update($data)) {
  283. $this->error = 2213;
  284. return ['id' => $id];
  285. } else {
  286. $this->error = 2214;
  287. return false;
  288. }
  289. } else {
  290. if ($id = $this->model->insertGetId($data)) {
  291. $this->error = 2215;
  292. return ['id' => $id];
  293. } else {
  294. $this->error = 2214;
  295. return false;
  296. }
  297. }
  298. }
  299. /**
  300. * 获取入驻信息
  301. * @param $userId
  302. * @return mixed
  303. */
  304. public function getApplyInfo($userId)
  305. {
  306. $info = $this->model->where(['user_id' => $userId, 'mark' => 1])
  307. ->orderBy('id', 'desc')
  308. ->first();
  309. $info = $info ? $info->setHidden(['quota', 'update_time', 'mark'])->toArray() : [];
  310. return $info;
  311. }
  312. /**
  313. * 充值交易额度
  314. * @param $userId 用户ID
  315. * @param $params
  316. * @return array|false
  317. */
  318. public function rechargeQuota($userId, $params)
  319. {
  320. // $acceptId = isset($params['id'])? $params['id'] : 0;
  321. $usdt = isset($params['usdt']) ? floatval($params['usdt']) : 0;
  322. if ($usdt <= 0) {
  323. $this->error = 2031;
  324. return false;
  325. }
  326. $info = $this->model->with(['member'])->where(['user_id' => $userId, 'mark' => 1])
  327. ->select(['id', 'realname', 'mobile', 'usdt', 'quota', 'trade_status', 'status'])
  328. ->first();
  329. $quota = isset($info['quota']) ? $info['quota'] : 0;
  330. $status = isset($info['status']) ? $info['status'] : 0;
  331. $acceptId = isset($info['id']) ? $info['id'] : 0;
  332. $userInfo = isset($info['member']) ? $info['member'] : [];
  333. if ($userId <= 0 || empty($info) || $status != 2) {
  334. $this->error = 2015;
  335. return false;
  336. }
  337. // 充值订单
  338. DB::beginTransaction();
  339. $orderNo = get_order_num('DP');
  340. $xdPrice = ConfigService::make()->getConfigByCode('xd_price', 100);
  341. $xdPrice = $xdPrice > 0 && $xdPrice <= 10000 ? $xdPrice : 100;
  342. $money = round($xdPrice * $usdt, 2);
  343. $data = [
  344. 'order_no' => $orderNo,
  345. 'user_id' => $acceptId,
  346. 'type' => 1,
  347. 'user_type' => 3,
  348. 'coin_type' => 6,
  349. 'money' => $usdt,
  350. 'actual_money' => $money,
  351. 'pay_type' => 10,
  352. 'pay_status' => 20,
  353. 'trc_url' => isset($userInfo['trc_url']) ? $userInfo['trc_url'] : '',
  354. 'pay_at' => date('Y-m-d H:i:s'),
  355. 'date' => date('Y-m-d'),
  356. 'create_time' => time(),
  357. 'update_time' => time(),
  358. 'status' => 2,
  359. 'mark' => 1,
  360. ];
  361. if (!$orderId = BalanceLogModel::insertGetId($data)) {
  362. $this->error = 2033;
  363. DB::rollBack();
  364. return false;
  365. }
  366. // 扣除usdt余额
  367. $updateData = ['usdt' => DB::raw("usdt - {$usdt}"), 'update_time' => time()];
  368. if (!MemberModel::where(['id' => $userId])->update($updateData)) {
  369. $this->error = 2036;
  370. DB::rollBack();
  371. return false;
  372. }
  373. // 用户明细
  374. $userUsdt = isset($userInfo['usdt']) ? $userInfo['usdt'] : 0;
  375. $log = [
  376. 'user_id' => $userId,
  377. 'source_id' => $acceptId,
  378. 'source_order_no' => $data['order_no'],
  379. 'user_type' => 1,
  380. 'type' => 5,
  381. 'coin_type' => 1,
  382. 'money' => -$usdt,
  383. 'actual_money' => -$usdt,
  384. 'balance' => $usdt,
  385. 'date' => date('Y-m-d'),
  386. 'create_time' => time(),
  387. 'remark' => '交易额度充值扣除',
  388. 'status' => 1,
  389. 'mark' => 1
  390. ];
  391. if (!AccountLogModel::insertGetId($log)) {
  392. $this->error = 2029;
  393. DB::rollBack();
  394. return false;
  395. }
  396. // 额度增加
  397. $updateData = ['quota' => DB::raw("quota + {$money}"), 'update_time' => time()];
  398. if (!$this->model->where(['id' => $userId])->update($updateData)) {
  399. $this->error = 2036;
  400. DB::rollBack();
  401. return false;
  402. }
  403. // 额度明细
  404. $log = [
  405. 'user_id' => $acceptId,
  406. 'source_id' => $userId,
  407. 'source_order_no' => $data['order_no'],
  408. 'user_type' => 3,
  409. 'type' => 5,
  410. 'coin_type' => 6,
  411. 'money' => $money,
  412. 'actual_money' => $money,
  413. 'balance' => $quota,
  414. 'date' => date('Y-m-d'),
  415. 'create_time' => time(),
  416. 'remark' => '交易额度充值',
  417. 'status' => 1,
  418. 'mark' => 1
  419. ];
  420. if (!AccountLogModel::insertGetId($log)) {
  421. $this->error = 2029;
  422. DB::rollBack();
  423. return false;
  424. }
  425. // 消息
  426. $dateTime = date('Y-m-d H:i:s');
  427. MessageService::make()->pushMessage($userId, '交易额度充值成功', "您在{$dateTime}(UTC+8)成功支付{$usdt}USDT充值{$money}交易额度", 3);
  428. DB::commit();
  429. $this->error = 2037;
  430. return ['order_id' => $orderId, 'quota' => moneyFormat($quota + $money, 2), 'usdt' => moneyFormat($userUsdt - $usdt, 2)];
  431. }
  432. /**
  433. * 交易额度提现处理
  434. * @param $userId 用户
  435. * @param $params
  436. * @return bool
  437. */
  438. public function withdrawQuota($userId, $params)
  439. {
  440. $money = isset($params['money']) ? $params['money'] : 0;
  441. $coinType = isset($params['coin_type']) ? $params['coin_type'] : 0;
  442. if ($money <= 0) {
  443. $this->error = 2039;
  444. return false;
  445. }
  446. $info = $this->model->with(['member'])->where(['user_id' => $userId, 'mark' => 1])
  447. ->select(['id', 'user_id', 'realname', 'mobile', 'usdt', 'quota', 'status'])
  448. ->first();
  449. $usdt = isset($info['usdt']) ? floatval($info['usdt']) : 0;
  450. $quota = isset($info['quota']) ? floatval($info['quota']) : 0;
  451. $status = isset($info['status']) ? $info['status'] : 0;
  452. $tradeStatus = isset($info['trade_status']) ? $info['trade_status'] : 0;
  453. $acceptId = isset($info['accept_id']) ? $info['accept_id'] : 0;
  454. $userInfo = isset($info['member']) ? $info['member'] : [];
  455. if ($acceptId <= 0 || empty($info) || $status != 2) {
  456. $this->error = 2039;
  457. return false;
  458. }
  459. if (in_array($tradeStatus,[2,4])) {
  460. $this->error = 2015;
  461. return false;
  462. }
  463. // 提现账户
  464. $trcUrl = isset($userInfo['trc_url']) ? $userInfo['trc_url'] : '';
  465. if (empty($trcUrl)) {
  466. $this->error = 2403;
  467. return false;
  468. }
  469. DB::beginTransaction();
  470. // USDT 提现
  471. $payUsdt = 0;
  472. $orderNo = get_order_num('DP');
  473. if ($coinType == 1) {
  474. $payUsdt = $money;
  475. if ($money > $usdt) {
  476. $this->error = lang(2040, ['money' => $usdt]);
  477. return false;
  478. }
  479. $updateData = ['usdt' => DB::raw("usdt - {$money}"), 'update_time' => time()];
  480. if (!$this->model->where(['id' => $acceptId])->update($updateData)) {
  481. DB::rollBack();
  482. $this->error = 2042;
  483. return false;
  484. }
  485. // 明细
  486. $log = [
  487. 'user_id' => $acceptId,
  488. 'source_id' => $userId,
  489. 'source_order_no' => $orderNo,
  490. 'user_type' => 3,
  491. 'type' => 5,
  492. 'coin_type' => 1,
  493. 'money' => -$usdt,
  494. 'actual_money' => -$usdt,
  495. 'balance' => $usdt,
  496. 'date' => date('Y-m-d'),
  497. 'create_time' => time(),
  498. 'remark' => '交易余额提现',
  499. 'status' => 1,
  500. 'mark' => 1
  501. ];
  502. if (!AccountLogModel::insertGetId($log)) {
  503. $this->error = 2029;
  504. DB::rollBack();
  505. return false;
  506. }
  507. } // 额度提现
  508. else if ($coinType == 6) {
  509. // 时间限制
  510. $limitTime = ConfigService::make()->getConfigByCode('quota_withdraw_time');
  511. $limitTime = $limitTime >= 0 ? $limitTime : 0;
  512. $lockQuota = BalanceLogModel::where(['user_id' => $acceptId, 'user_type' => 3, 'coin_type' => 6, 'status' => 1, 'mark' => 1])
  513. ->where('pay_at', '>=', date('Y-m-d H:i:s', time() - $limitTime * 86400))
  514. ->sum('actual_money');
  515. if ($lockQuota > 0 && $money > ($quota - $lockQuota)) {
  516. $this->error = lang(2040, ['money' => ($quota - $lockQuota)]);
  517. return false;
  518. }
  519. $xdPrice = ConfigService::make()->getConfigByCode('xd_price', 100);
  520. $xdPrice = $xdPrice > 0 && $xdPrice <= 10000 ? $xdPrice : 100;
  521. $payUsdt = round($money / $xdPrice, 4);
  522. $updateData = ['quota' => DB::raw("quota - {$money}"), 'update_time' => time()];
  523. if (!$this->model->where(['id' => $acceptId])->update($updateData)) {
  524. DB::rollBack();
  525. $this->error = 2042;
  526. return false;
  527. }
  528. // 明细
  529. $log = [
  530. 'user_id' => $acceptId,
  531. 'source_id' => $userId,
  532. 'source_order_no' => $orderNo,
  533. 'user_type' => 3,
  534. 'type' => 5,
  535. 'coin_type' => 6,
  536. 'money' => -$money,
  537. 'actual_money' => -$money,
  538. 'balance' => $quota,
  539. 'date' => date('Y-m-d'),
  540. 'create_time' => time(),
  541. 'remark' => '交易额度提现',
  542. 'status' => 1,
  543. 'mark' => 1
  544. ];
  545. if (!AccountLogModel::insertGetId($log)) {
  546. $this->error = 2029;
  547. DB::rollBack();
  548. return false;
  549. }
  550. }
  551. // 提现记录
  552. $data = [
  553. 'order_no' => $orderNo,
  554. 'user_id' => $acceptId,
  555. 'type' => 2,
  556. 'coin_type' => $coinType,
  557. 'user_type' => 3,
  558. 'money' => $money,
  559. 'actual_money' => $payUsdt,
  560. 'balance' => $coinType == 1 ? $usdt : $quota,
  561. 'date' => date('Y-m-d'),
  562. 'trc_url' => $trcUrl,
  563. 'create_time' => time(),
  564. 'update_time' => time(),
  565. 'status' => 1,
  566. 'mark' => 1,
  567. ];
  568. if (!$id = BalanceLogModel::insertGetId($data)) {
  569. DB::rollBack();
  570. $this->error = 2042;
  571. return false;
  572. }
  573. DB::commit();
  574. // 站内消息
  575. $dateTime = date('Y-m-d H:i:s');
  576. $message = $coinType == 1 ? "您在{$dateTime}(UTC+8)申请提现{$money}USDT交易余额成功,请耐心等候审核!!!" : "您在{$dateTime}(UTC+8)申请提现{$money}交易额度成功,请耐心等候审核!!!";
  577. MessageService::make()->pushMessage($userId, $coinType == 1 ? '交易余额提现申请成功' : '交易额度提现申请成功', $message);
  578. // 提现自动审核,低于该金额自动审核
  579. $autoCheckUsdt = ConfigService::make()->getConfigByCode('withdraw_auto_money', 300);
  580. $autoCheckUsdt = $autoCheckUsdt > 0 ? $autoCheckUsdt : 0;
  581. if ($payUsdt <= $autoCheckUsdt) {
  582. // 打款处理
  583. $result = WalletService::make()->usdtTrcTransfer($trcUrl, $payUsdt);
  584. $txID = isset($result['txId']) ? $result['txId'] : '';
  585. $payAddress = isset($result['address']) ? $result['address'] : '';
  586. if ($txID && $payAddress) {
  587. $updateData = ['hash'=> $txID,'wallet_url'=> $payAddress,'audit_remark'=>'自动审核打款','status'=>2,'update_time'=>time()];
  588. if(BalanceLogModel::where(['user_id'=> $acceptId,'order_no'=> $orderNo])->update($updateData)){
  589. $message = $coinType == 1 ? "您在{$dateTime}(UTC+8)申请提现{$money}USDT交易余额审核成功,请耐心等候打款到账!!!" : "您在{$dateTime}(UTC+8)申请提现{$money}交易额度审核成功,请耐心等候打款到账!!!";
  590. MessageService::make()->pushMessage($userId, $coinType == 1 ? '交易余额提现审核成功' : '交易额度提现审核成功', $message);
  591. AccountLogModel::where(['source_order_no'=> $orderNo])->update(['hash'=> $txID,'update_time'=>time()]);
  592. }
  593. }
  594. }
  595. $this->error = 2043;
  596. return true;
  597. }
  598. }