BalanceLogService.php 27 KB

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