AcceptorService.php 23 KB

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