AcceptorService.php 24 KB

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