BalanceLogService.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  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\Common;
  12. use App\Models\AcceptorModel;
  13. use App\Models\AccountLogModel;
  14. use App\Models\ActionLogModel;
  15. use App\Models\BalanceLogModel;
  16. use App\Models\MemberModel;
  17. use App\Models\MerchantModel;
  18. use App\Services\Api\FinanceService;
  19. use App\Services\Api\MessageService;
  20. use App\Services\BaseService;
  21. use App\Services\RedisService;
  22. use App\Services\WalletService;
  23. use Illuminate\Support\Facades\DB;
  24. /**
  25. * 承兑商管理-服务类
  26. * @author laravel开发员
  27. * @since 2020/11/11
  28. * @package App\Services\Common
  29. */
  30. class BalanceLogService extends BaseService
  31. {
  32. // 静态对象
  33. protected static $instance = null;
  34. /**
  35. * 构造函数
  36. * @author laravel开发员
  37. * @since 2020/11/11
  38. */
  39. public function __construct()
  40. {
  41. $this->model = new BalanceLogModel();
  42. }
  43. /**
  44. * 静态入口
  45. * @return static|null
  46. */
  47. public static function make()
  48. {
  49. if (!self::$instance) {
  50. self::$instance = (new static());
  51. }
  52. return self::$instance;
  53. }
  54. /**
  55. * 获取列表
  56. * @param $params 参数
  57. * @param int $pageSize 分页大小:默认 15
  58. * @return array
  59. */
  60. public function getDataList($params, $pageSize = 10, $field = [])
  61. {
  62. $query = $this->getQuery($params);
  63. $list = $query->select($field ? $field : ['a.*', 'b.username','b.trc_url as user_trc_url', 'b.nickname','c.user_id as merchant_uid','d.user_id as acceptor_uid'])
  64. ->orderBy('a.status','asc')
  65. ->orderBy('a.create_time','desc')
  66. ->orderBy('a.pay_at','desc')
  67. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  68. $list = $list ? $list->toArray() : [];
  69. if ($list) {
  70. foreach ($list['data'] as &$item) {
  71. $item['create_time'] = datetime($item['create_time'],'Y-m-d H:i:s');
  72. $item['pay_img'] = isset($item['pay_img'])?get_image_url($item['pay_img']):'';
  73. $item['trc_url'] = $item['trc_url']?$item['trc_url'] : $item['user_trc_url'];
  74. if($item['user_type'] == 1){
  75. $item['uid'] = $item['user_id'];
  76. $item['account'] = isset($item['nickname'])&& $item['nickname']?$item['nickname'].(isset($item['username'])?' '.$item['username']:'') : $item['user_id'];
  77. }else if($item['user_type'] == 2){
  78. $item['uid'] = isset($item['merchant']['user_id'])&& $item['merchant']? $item['merchant']['user_id'] : 0;
  79. $item['account'] = isset($item['merchant']['nickname'])&& $item['merchant']?$item['merchant']['nickname'].(isset($item['merchant']['mobile'])?' '.$item['merchant']['mobile']:'') : $item['merchant_uid'];
  80. }else if($item['user_type'] == 3){
  81. $item['uid'] = isset($item['acceptor']['user_id'])&& $item['acceptor']? $item['acceptor']['user_id'] : 0;
  82. $item['account'] = isset($item['acceptor']['nickname'])&& $item['acceptor']?$item['acceptor']['nickname'].(isset($item['acceptor']['mobile'])?' '.$item['acceptor']['mobile']:'') : $item['acceptor_uid'];
  83. }
  84. }
  85. }
  86. return [
  87. 'pageSize' => $pageSize,
  88. 'total' => isset($list['total']) ? $list['total'] : 0,
  89. 'list' => isset($list['data']) ? $list['data'] : []
  90. ];
  91. }
  92. /**
  93. * 查询构造
  94. * @param $params
  95. * @return \Illuminate\Database\Eloquent\Builder
  96. */
  97. public function getQuery($params)
  98. {
  99. $where = ['a.mark' => 1];
  100. return $this->model->with(['member','acceptor','merchant','payment'])
  101. ->from('balance_logs as a')
  102. ->leftJoin('member as b', function($join) {
  103. $join->on('b.id','=', 'a.user_id')->where('a.user_type',1);
  104. })
  105. ->leftJoin('merchant as c', function($join) {
  106. $join->on('c.id','=', 'a.user_id')->where('a.user_type',2);
  107. })
  108. ->leftJoin('acceptor as d', function($join) {
  109. $join->on('d.id','=', 'a.user_id')->where('a.user_type',3);
  110. })
  111. ->where($where)
  112. ->where(function ($query) use ($params) {
  113. $userType = isset($params['user_type'])? intval($params['user_type']) : 1;
  114. $kw = isset($params['keyword']) ? trim($params['keyword']) : '';
  115. if ($kw) {
  116. if($userType == 3){
  117. $query->where('d.user_id', '=', "{$params['keyword']}")
  118. ->orWhere('d.name', 'like', "%{$params['keyword']}%")
  119. ->orWhere('d.mobile', 'like', "%{$params['keyword']}%");
  120. }else if($userType == 2){
  121. $query->where('c.user_id', '=', "{$params['keyword']}")
  122. ->orWhere('c.name', 'like', "%{$params['keyword']}%")
  123. ->orWhere('c.mobile', 'like', "%{$params['keyword']}%");
  124. }else if($userType == 1){
  125. $query->where('b.id', '=', "{$params['keyword']}")
  126. ->orWhere('b.nickname', 'like', "%{$params['keyword']}%")
  127. ->orWhere('b.username', 'like', "%{$params['keyword']}%");
  128. }else{
  129. $query->where('a.user_id', '=', "{$params['keyword']}")
  130. ->orWhere('b.nickname', 'like', "%{$params['keyword']}%")
  131. ->orWhere('b.username', 'like', "%{$params['keyword']}%")
  132. ->orWhere('c.name', 'like', "%{$params['keyword']}%")
  133. ->orWhere('c.mobile', 'like', "%{$params['keyword']}%")
  134. ->orWhere('d.name', 'like', "%{$params['keyword']}%")
  135. ->orWhere('d.mobile', 'like', "%{$params['keyword']}%");
  136. }
  137. }
  138. })
  139. ->where(function ($query) use($params){
  140. // 日期
  141. $date = isset($params['date']) ? $params['date'] : [];
  142. $start = isset($date[0])? $date[0] : '';
  143. $end = isset($date[1])? $date[1] : '';
  144. $end = $start>=$end? '' : $end;
  145. if ($start) {
  146. $query->where('a.create_time','>=', strtotime($start));
  147. }
  148. if($end){
  149. $query->where('a.create_time','<=', strtotime($end));
  150. }
  151. $orderNo = isset($params['order_no'])? trim($params['order_no']) : '';
  152. if($orderNo){
  153. $query->where('a.order_no', 'like', "%{$orderNo}%");
  154. }
  155. $trcUrl = isset($params['trc_url'])? trim($params['trc_url']) : '';
  156. if($trcUrl){
  157. $query->where('a.trc_url', '=', $trcUrl);
  158. }
  159. $hash = isset($params['hash'])? trim($params['hash']) : '';
  160. if($hash){
  161. $query->where('a.trc_url', '=', $hash);
  162. }
  163. $orderNo = isset($params['order_no'])? trim($params['order_no']) : '';
  164. if($orderNo){
  165. $query->where('a.order_no', 'like', "%{$orderNo}%");
  166. }
  167. $userType = isset($params['user_type'])? $params['user_type'] : 0;
  168. if ($userType) {
  169. $query->where('a.user_type', $userType);
  170. }
  171. $payType = isset($params['pay_type'])? $params['pay_type'] : 0;
  172. if ($payType) {
  173. $query->where('a.pay_type', $payType);
  174. }
  175. $payStatus = isset($params['pay_status'])? $params['pay_status'] : 0;
  176. if ($payStatus) {
  177. $query->where('a.pay_status', $payStatus);
  178. }
  179. $type = isset($params['type'])? $params['type'] : 0;
  180. if (is_array($type)) {
  181. $query->whereIn('a.type', $type);
  182. } else if($type){
  183. $query->where('a.type', $type);
  184. }
  185. $coinType = isset($params['coin_type'])? $params['coin_type'] : 0;
  186. if (is_array($coinType)) {
  187. $query->whereIn('a.coin_type', $coinType);
  188. } else if($coinType){
  189. $query->where('a.coin_type', $coinType);
  190. }
  191. $status = isset($params['status'])? $params['status'] : 0;
  192. if (is_array($status)) {
  193. $query->whereIn('a.status', $status);
  194. } else if($status){
  195. $query->where('a.status', $status);
  196. }
  197. });
  198. }
  199. /**
  200. * 统计
  201. * @param $params
  202. * @return array
  203. */
  204. public function count($params)
  205. {
  206. $query = $this->getQuery($params);
  207. $count = $query->count('a.id');
  208. $total = $query->sum('a.actual_money');
  209. return [
  210. 'count' => $count,
  211. 'total' => $total
  212. ];
  213. }
  214. /**
  215. * 充值审核
  216. * @param $params
  217. * @return bool
  218. */
  219. public function rechargeAuth($params)
  220. {
  221. $id = isset($params['id'])? $params['id'] : 0;
  222. $checkStatus = isset($params['status'])? $params['status'] : 0;
  223. $remark = isset($params['audit_remark'])? trim($params['audit_remark']) : '';
  224. $payImg = isset($params['pay_img'])? trim($params['pay_img']) : '';
  225. if(!in_array($checkStatus,[2,3])){
  226. $this->error = 1073;
  227. return false;
  228. }
  229. $info = $this->model->with(['member','merchant','acceptor'])->where(['id'=> $id,'mark'=>1])->first();
  230. $type = isset($info['type'])? $info['type'] : 0;
  231. $userType = isset($info['user_type'])? $info['user_type'] : 0;
  232. $coinType = isset($info['coin_type'])? $info['coin_type'] : 0;
  233. $payType = isset($info['pay_type'])? $info['pay_type'] : 0;
  234. $accountId = isset($info['user_id'])? $info['user_id'] : 0;
  235. $money = isset($info['money'])? $info['money'] : 0;
  236. $actualMoney = isset($info['actual_money'])? $info['actual_money'] : 0;
  237. $status = isset($info['status'])? $info['status'] : 0;
  238. if($id<=0 || empty($info) || $accountId<=0){
  239. $this->error = 4001;
  240. return false;
  241. }
  242. if($status != 1){
  243. $this->error = 4002;
  244. return false;
  245. }
  246. if($type != 1){
  247. $this->error = 1031;
  248. return false;
  249. }
  250. $cacheKey ="caches:recharge:lock_{$id}";
  251. if(RedisService::get($cacheKey)){
  252. $this->error = 1034;
  253. // return false;
  254. }
  255. // 绑定的用户ID
  256. $userId = $accountId;
  257. $userInfo = isset($info['member'])? $info['member'] : [];
  258. $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
  259. if($userType == 2){
  260. $userInfo = isset($info['merchant'])? $info['merchant'] : [];
  261. $userId = isset($userInfo['user_id'])? $userInfo['user_id'] : 0;
  262. $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
  263. }else if($userType == 3){
  264. $userInfo = isset($info['acceptor'])? $info['acceptor'] : [];
  265. $userId = isset($userInfo['user_id'])? $userInfo['user_id'] : 0;
  266. $balance = isset($userInfo['quota'])? $userInfo['quota'] : 0;
  267. }
  268. if(empty($userInfo)){
  269. $this->error = 4004;
  270. return false;
  271. }
  272. // 审核处理
  273. RedisService::set($cacheKey, true, rand(2,3));
  274. $updateData = ['status'=> $checkStatus,'audit_remark'=> $remark,'update_time'=> time()];
  275. DB::beginTransaction();
  276. if(!$this->model->where(['id'=> $id])->update($updateData)){
  277. DB::rollBack();
  278. $this->error = 1072;
  279. RedisService::clear($cacheKey);
  280. return false;
  281. }
  282. // 审核通过到账处理
  283. $dateTime = date('Y-m-d H:i:s');
  284. $coinTypes = [1=>'USDT余额',2=>'星豆余额',6=>'交易额度'];
  285. $accountTypes = [1=>'会员账户',2=>'商家账户',3=>'承兑商账户'];
  286. $coinName = isset($coinTypes[$coinType])? $coinTypes[$coinType] : '账户';
  287. $accountName = isset($accountTypes[$userType])? $accountTypes[$userType] : '会员账户';
  288. if($checkStatus == 2) {
  289. // 线下交易
  290. if($payType == 30){
  291. if(!in_array($userType,[1,3]) && !in_array($coinType,[1,6])){
  292. DB::rollBack();
  293. $this->error = 1021;
  294. RedisService::clear($cacheKey);
  295. return false;
  296. }
  297. // USDT入账
  298. if($userType == 1 && $coinType == 1){
  299. $updateData = ['usdt' => DB::raw("usdt + {$actualMoney}"),'update_time'=>time()];
  300. if (!MemberModel::where(['id' => $accountId])->update($updateData)){
  301. DB::rollBack();
  302. $this->error = 1072;
  303. RedisService::clear($cacheKey);
  304. return false;
  305. }
  306. }
  307. // 交易额度入账
  308. else if($userType == 3 && $coinType == 6){
  309. $updateData = ['quota' => DB::raw("quota + {$actualMoney}"),'update_time'=>time()];
  310. if (!AcceptorModel::where(['id' => $accountId])->update($updateData)){
  311. DB::rollBack();
  312. $this->error = 1072;
  313. RedisService::clear($cacheKey);
  314. return false;
  315. }
  316. }
  317. // 账户明细
  318. $log = [
  319. 'user_id' => $accountId,
  320. 'source_id' => 0,
  321. 'source_order_no' => $info['order_no'],
  322. 'type' => 5,
  323. 'coin_type' => $coinType,
  324. 'user_type'=> $userType,
  325. 'money' => $money,
  326. 'actual_money' => $actualMoney,
  327. 'balance' => $balance,
  328. 'create_time' => time(),
  329. 'update_time' => time(),
  330. 'remark' => "{$coinName}充值",
  331. 'status' => 1,
  332. 'mark' => 1,
  333. ];
  334. if(!AccountLogModel::insertGetId($log)){
  335. DB::rollBack();
  336. $this->error = 2029;
  337. RedisService::clear($cacheKey);
  338. return false;
  339. }
  340. }else{
  341. DB::rollBack();
  342. $this->error = 1021;
  343. RedisService::clear($cacheKey);
  344. return false;
  345. }
  346. $title = "{$coinName}充值审核成功通知";
  347. $message = "您的充值申请在{$dateTime}UTC+8审核成功,明细如下:\n单号:{$info['order_no']}\n账户:{$accountName}\n金额:{$money}\n到账:{$actualMoney}\n审核状态:成功\n审核说明:{$remark}";
  348. }else{
  349. $title = "{$coinName}充值审核失败通知";
  350. $message = "您的充值申请在{$dateTime}UTC+8审核失败,明细如下:\n单号:{$info['order_no']}\n账户:{$accountName}\n金额:{$money}\n到账:{$actualMoney}\n审核状态:未通过\n审核说明:{$remark}";
  351. }
  352. // 消息通知
  353. MessageService::make()->pushMessage($userId, $title, $message, 3);
  354. DB::commit();
  355. $this->error = 1071;
  356. RedisService::clear($cacheKey);
  357. ActionLogModel::setTitle("充值审核");
  358. ActionLogModel::record();
  359. return true;
  360. }
  361. /**
  362. * 提现审核
  363. * @param $params
  364. * @return bool
  365. */
  366. public function withdrawAuth($params)
  367. {
  368. $id = isset($params['id'])? $params['id'] : 0;
  369. $checkStatus = isset($params['status'])? $params['status'] : 0;
  370. $remark = isset($params['audit_remark'])? trim($params['audit_remark']) : '';
  371. $payImg = isset($params['pay_img'])? trim($params['pay_img']) : '';
  372. if(!in_array($checkStatus,[2,3])){
  373. $this->error = 1073;
  374. return false;
  375. }
  376. $info = $this->model->with(['member','merchant','acceptor'])->where(['id'=> $id,'mark'=>1])->first();
  377. $type = isset($info['type'])? $info['type'] : 0;
  378. $userType = isset($info['user_type'])? $info['user_type'] : 0;
  379. $coinType = isset($info['coin_type'])? $info['coin_type'] : 0;
  380. $payType = isset($info['pay_type'])? $info['pay_type'] : 0;
  381. $accountId = isset($info['user_id'])? $info['user_id'] : 0;
  382. $money = isset($info['money'])? $info['money'] : 0;
  383. $actualMoney = isset($info['actual_money'])? $info['actual_money'] : 0;
  384. $fee = isset($info['fee'])? $info['fee'] : 0;
  385. $status = isset($info['status'])? $info['status'] : 0;
  386. if($id<=0 || empty($info) || $accountId<=0){
  387. $this->error = 4001;
  388. return false;
  389. }
  390. if($status != 1){
  391. $this->error = 4002;
  392. return false;
  393. }
  394. if($type != 2){
  395. $this->error = 1031;
  396. return false;
  397. }
  398. $cacheKey ="caches:withdraw:lock_{$id}";
  399. if(RedisService::get($cacheKey)){
  400. $this->error = 1034;
  401. return false;
  402. }
  403. // 绑定的用户ID
  404. $userId = $accountId;
  405. $userInfo = isset($info['member'])? $info['member'] : [];
  406. $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
  407. if($userType == 2){
  408. $userInfo = isset($info['merchant'])? $info['merchant'] : [];
  409. $userId = isset($userInfo['user_id'])? $userInfo['user_id'] : 0;
  410. $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
  411. }else if($userType == 3){
  412. $userInfo = isset($info['acceptor'])? $info['acceptor'] : [];
  413. $userId = isset($userInfo['user_id'])? $userInfo['user_id'] : 0;
  414. $balance = isset($userInfo['quota'])? $userInfo['quota'] : 0;
  415. }
  416. if(empty($userInfo)){
  417. $this->error = 4004;
  418. return false;
  419. }
  420. // 审核处理
  421. RedisService::set($cacheKey, true);
  422. DB::beginTransaction();
  423. // 审核通过到账处理
  424. $dateTime = date('Y-m-d H:i:s');
  425. $accountTypes = [1=>'会员账户',2=>'商家账户',3=>'承兑商账户'];
  426. $coinName = 'USDT余额';
  427. if($userType == 2 && $coinType==1){
  428. $coinName = 'USDT佣金';
  429. }else if($userType == 3 && $coinType==1){
  430. $coinName = 'USDT佣金';
  431. }else if($userType == 3 && $coinType==6){
  432. $coinName = '交易额度';
  433. }
  434. $accountName = isset($accountTypes[$userType])? $accountTypes[$userType] : '会员账户';
  435. if($checkStatus == 2) {
  436. // USDT链上打款
  437. $hash = '';
  438. if($payType == 20){
  439. $trcUrl = isset($info['trc_url'])? $info['trc_url'] : '';
  440. if(empty($trcUrl)){
  441. DB::rollBack();
  442. $this->error = 4005;
  443. RedisService::clear($cacheKey);
  444. return false;
  445. }
  446. $result = WalletService::make()->usdtTrcTransfer($trcUrl, $actualMoney);
  447. $hash = isset($result['txId']) ? $result['txId'] : '';
  448. if(empty($hash)){
  449. DB::rollBack();
  450. $this->error = WalletService::make()->getError();
  451. RedisService::clear($cacheKey);
  452. return false;
  453. }
  454. $payAddress = isset($result['address']) ? $result['address'] : '';
  455. $updateData = ['status'=>2,'audit_remark'=>$remark,'pay_img'=> get_image_path($payImg),'hash' => $hash, 'wallet_url' => $payAddress,'pay_status'=>20,'pay_at'=> $dateTime, 'update_time' => time()];
  456. if(!$this->model->where(['id'=> $id])->update($updateData)){
  457. DB::rollBack();
  458. $this->error = 4006;
  459. RedisService::clear($cacheKey);
  460. return false;
  461. }
  462. }
  463. // 线下打款
  464. else if($payType == 30){
  465. $updateData = ['status'=> 2,'pay_status'=>20,'pay_at'=>$dateTime,'pay_img'=> get_image_path($payImg),'audit_remark'=> $remark,'update_time'=> time()];
  466. if(!$this->model->where(['id'=> $id])->update($updateData)){
  467. DB::rollBack();
  468. $this->error = 1072;
  469. RedisService::clear($cacheKey);
  470. return false;
  471. }
  472. }else{
  473. DB::rollBack();
  474. $this->error = 1021;
  475. RedisService::clear($cacheKey);
  476. return false;
  477. }
  478. // 平台手续费明细
  479. if($fee>0){
  480. $log = [
  481. 'user_id' => 0,
  482. 'source_id' => $accountId,
  483. 'source_order_no' => $info['order_no'],
  484. 'type' => 5,
  485. 'coin_type' => $coinType,
  486. 'user_type' => 4,
  487. 'money' => $fee,
  488. 'actual_money' => $fee,
  489. 'balance' => 0,
  490. 'create_time' => time(),
  491. 'update_time' => time(),
  492. 'hash' => $hash,
  493. 'remark' => "{$coinName}提现",
  494. 'status' => 1,
  495. 'mark' => 1,
  496. ];
  497. if(!AccountLogModel::insertGetId($log)){
  498. DB::rollBack();
  499. $this->error = 2029;
  500. RedisService::clear($cacheKey);
  501. return false;
  502. }
  503. FinanceService::make()->saveLog(0, $fee, 1);
  504. }
  505. $title = "{$coinName}提现审核成功通知";
  506. $message = "您的提现申请在{$dateTime}UTC+8审核成功,明细如下:\n单号:{$info['order_no']}\n账户:{$accountName}\n提现金额:{$money}\n到账:{$actualMoney}\n审核状态:审核成功\n审核说明:{$remark}";
  507. }
  508. // 审核失败驳回退款
  509. else{
  510. if(!in_array($userType,[1,2,3]) && !in_array($coinType,[1,6])){
  511. DB::rollBack();
  512. $this->error = 1021;
  513. RedisService::clear($cacheKey);
  514. return false;
  515. }
  516. $updateData = ['status'=> 3,'pay_img'=> get_image_path($payImg),'audit_remark'=> $remark,'update_time'=> time()];
  517. if(!$this->model->where(['id'=> $id])->update($updateData)){
  518. DB::rollBack();
  519. $this->error = 1072;
  520. RedisService::clear($cacheKey);
  521. return false;
  522. }
  523. // 会员:USDT驳回入账
  524. if($userType == 1 && $coinType == 1){
  525. $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
  526. $updateData = ['usdt' => DB::raw("usdt + {$money}"),'update_time'=>time()];
  527. if (!MemberModel::where(['id' => $accountId])->update($updateData)){
  528. DB::rollBack();
  529. $this->error = 1072;
  530. RedisService::clear($cacheKey);
  531. return false;
  532. }
  533. }
  534. // 商家:佣金入账
  535. else if($userType == 2 && $coinType == 1){
  536. $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
  537. $updateData = ['usdt' => DB::raw("usdt + {$money}"),'update_time'=>time()];
  538. if (!MerchantModel::where(['id' => $accountId])->update($updateData)){
  539. DB::rollBack();
  540. $this->error = 1072;
  541. RedisService::clear($cacheKey);
  542. return false;
  543. }
  544. }
  545. // 承兑商:佣金入账
  546. else if($userType == 3 && $coinType == 1){
  547. $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
  548. $updateData = ['usdt' => DB::raw("usdt + {$money}"),'update_time'=>time()];
  549. if (!AcceptorModel::where(['id' => $accountId])->update($updateData)){
  550. DB::rollBack();
  551. $this->error = 1072;
  552. RedisService::clear($cacheKey);
  553. return false;
  554. }
  555. }
  556. // 承兑商:交易额度入账
  557. else if($userType == 3 && $coinType == 6){
  558. $balance = isset($userInfo['quota'])? $userInfo['quota'] : 0;
  559. $updateData = ['quota' => DB::raw("quota + {$money}"),'update_time'=>time()];
  560. if (!AcceptorModel::where(['id' => $accountId])->update($updateData)){
  561. DB::rollBack();
  562. $this->error = 1072;
  563. RedisService::clear($cacheKey);
  564. return false;
  565. }
  566. }
  567. // 账户明细
  568. $log = [
  569. 'user_id' => $accountId,
  570. 'source_id' => 0,
  571. 'source_order_no' => $info['order_no'],
  572. 'type' => 5,
  573. 'coin_type' => $coinType,
  574. 'user_type'=> $userType,
  575. 'money' => $money,
  576. 'actual_money' => $money,
  577. 'balance' => $balance,
  578. 'create_time' => time(),
  579. 'update_time' => time(),
  580. 'remark' => "{$coinName}提现驳回",
  581. 'status' => 1,
  582. 'mark' => 1,
  583. ];
  584. if(!AccountLogModel::insertGetId($log)){
  585. DB::rollBack();
  586. $this->error = 2029;
  587. RedisService::clear($cacheKey);
  588. return false;
  589. }
  590. $title = "{$coinName}提现审核失败通知";
  591. $message = "您的提现申请在{$dateTime}UTC+8审核失败,提现金额已退回对应账户,明细如下:\n单号:{$info['order_no']}\n账户:{$accountName}\n提现金额:{$money}\n到账:{$actualMoney}\n审核状态:未通过\n审核说明:{$remark}";
  592. }
  593. // 消息通知
  594. MessageService::make()->pushMessage($userId, $title, $message, 3);
  595. DB::commit();
  596. $this->error = 1071;
  597. RedisService::clear($cacheKey);
  598. ActionLogModel::setTitle("提现审核");
  599. ActionLogModel::record();
  600. return true;
  601. }
  602. }