AcceptorService.php 24 KB

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