BalanceLogService.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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.name', 'like', "%{$params['keyword']}%")
  117. ->orWhere('d.mobile', 'like', "%{$params['keyword']}%");
  118. }else if($userType == 2){
  119. $query->where('c.name', 'like', "%{$params['keyword']}%")
  120. ->orWhere('c.mobile', 'like', "%{$params['keyword']}%");
  121. }else if($userType == 1){
  122. $query->where('b.nickname', 'like', "%{$params['keyword']}%")
  123. ->orWhere('b.username', 'like', "%{$params['keyword']}%");
  124. }else{
  125. $query->where('b.nickname', 'like', "%{$params['keyword']}%")
  126. ->orWhere('b.username', 'like', "%{$params['keyword']}%")
  127. ->orWhere('c.name', 'like', "%{$params['keyword']}%")
  128. ->orWhere('c.mobile', 'like', "%{$params['keyword']}%")
  129. ->orWhere('d.name', 'like', "%{$params['keyword']}%")
  130. ->orWhere('d.mobile', 'like', "%{$params['keyword']}%");
  131. }
  132. }
  133. })
  134. ->where(function ($query) use($params){
  135. // 日期
  136. $date = isset($params['date']) ? $params['date'] : [];
  137. $start = isset($date[0])? $date[0] : '';
  138. $end = isset($date[1])? $date[1] : '';
  139. $end = $start>=$end? '' : $end;
  140. if ($start) {
  141. $query->where('a.create_time','>=', strtotime($start));
  142. }
  143. if($end){
  144. $query->where('a.create_time','<=', strtotime($end));
  145. }
  146. $orderNo = isset($params['order_no'])? trim($params['order_no']) : '';
  147. if($orderNo){
  148. $query->where('a.order_no', 'like', "%{$orderNo}%");
  149. }
  150. $trcUrl = isset($params['trc_url'])? trim($params['trc_url']) : '';
  151. if($trcUrl){
  152. $query->where('a.trc_url', '=', $trcUrl);
  153. }
  154. $hash = isset($params['hash'])? trim($params['hash']) : '';
  155. if($hash){
  156. $query->where('a.trc_url', '=', $hash);
  157. }
  158. $orderNo = isset($params['order_no'])? trim($params['order_no']) : '';
  159. if($orderNo){
  160. $query->where('a.order_no', 'like', "%{$orderNo}%");
  161. }
  162. $userType = isset($params['user_type'])? $params['user_type'] : 0;
  163. if ($userType) {
  164. $query->where('a.user_type', $userType);
  165. }
  166. $payType = isset($params['pay_type'])? $params['pay_type'] : 0;
  167. if ($payType) {
  168. $query->where('a.pay_type', $payType);
  169. }
  170. $payStatus = isset($params['pay_status'])? $params['pay_status'] : 0;
  171. if ($payStatus) {
  172. $query->where('a.pay_status', $payStatus);
  173. }
  174. $type = isset($params['type'])? $params['type'] : 0;
  175. if (is_array($type)) {
  176. $query->whereIn('a.type', $type);
  177. } else if($type){
  178. $query->where('a.type', $type);
  179. }
  180. $coinType = isset($params['coin_type'])? $params['coin_type'] : 0;
  181. if (is_array($coinType)) {
  182. $query->whereIn('a.coin_type', $coinType);
  183. } else if($coinType){
  184. $query->where('a.coin_type', $coinType);
  185. }
  186. $status = isset($params['status'])? $params['status'] : 0;
  187. if (is_array($status)) {
  188. $query->whereIn('a.status', $status);
  189. } else if($status){
  190. $query->where('a.status', $status);
  191. }
  192. });
  193. }
  194. /**
  195. * 统计
  196. * @param $params
  197. * @return array
  198. */
  199. public function count($params)
  200. {
  201. $query = $this->getQuery($params);
  202. $count = $query->count('a.id');
  203. $total = $query->sum('a.actual_money');
  204. return [
  205. 'count' => $count,
  206. 'total' => $total
  207. ];
  208. }
  209. /**
  210. * 充值审核
  211. * @param $params
  212. * @return bool
  213. */
  214. public function rechargeAuth($params)
  215. {
  216. $id = isset($params['id'])? $params['id'] : 0;
  217. $checkStatus = isset($params['status'])? $params['status'] : 0;
  218. $remark = isset($params['audit_remark'])? trim($params['audit_remark']) : '';
  219. $payImg = isset($params['pay_img'])? trim($params['pay_img']) : '';
  220. if(!in_array($checkStatus,[2,3])){
  221. $this->error = 1073;
  222. return false;
  223. }
  224. $info = $this->model->with(['member','merchant','acceptor'])->where(['id'=> $id,'mark'=>1])->first();
  225. $type = isset($info['type'])? $info['type'] : 0;
  226. $userType = isset($info['user_type'])? $info['user_type'] : 0;
  227. $coinType = isset($info['coin_type'])? $info['coin_type'] : 0;
  228. $payType = isset($info['pay_type'])? $info['pay_type'] : 0;
  229. $accountId = isset($info['user_id'])? $info['user_id'] : 0;
  230. $money = isset($info['money'])? $info['money'] : 0;
  231. $actualMoney = isset($info['actual_money'])? $info['actual_money'] : 0;
  232. $status = isset($info['status'])? $info['status'] : 0;
  233. if($id<=0 || empty($info) || $accountId<=0){
  234. $this->error = 4001;
  235. return false;
  236. }
  237. if($status != 1){
  238. $this->error = 4002;
  239. return false;
  240. }
  241. if($type != 1){
  242. $this->error = 1031;
  243. return false;
  244. }
  245. $cacheKey ="caches:recharge:lock_{$id}";
  246. if(RedisService::get($cacheKey)){
  247. $this->error = 1034;
  248. // return false;
  249. }
  250. // 绑定的用户ID
  251. $userId = $accountId;
  252. $userInfo = isset($info['member'])? $info['member'] : [];
  253. $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
  254. if($userType == 2){
  255. $userInfo = isset($info['merchant'])? $info['merchant'] : [];
  256. $userId = isset($userInfo['user_id'])? $userInfo['user_id'] : 0;
  257. $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
  258. }else if($userType == 3){
  259. $userInfo = isset($info['acceptor'])? $info['acceptor'] : [];
  260. $userId = isset($userInfo['user_id'])? $userInfo['user_id'] : 0;
  261. $balance = isset($userInfo['quota'])? $userInfo['quota'] : 0;
  262. }
  263. if(empty($userInfo)){
  264. $this->error = 4004;
  265. return false;
  266. }
  267. // 审核处理
  268. RedisService::set($cacheKey, true, rand(2,3));
  269. $updateData = ['status'=> $checkStatus,'audit_remark'=> $remark,'update_time'=> time()];
  270. DB::beginTransaction();
  271. if(!$this->model->where(['id'=> $id])->update($updateData)){
  272. DB::rollBack();
  273. $this->error = 1072;
  274. RedisService::clear($cacheKey);
  275. return false;
  276. }
  277. // 审核通过到账处理
  278. $dateTime = date('Y-m-d H:i:s');
  279. $coinTypes = [1=>'USDT余额',2=>'星豆余额',6=>'交易额度'];
  280. $accountTypes = [1=>'会员账户',2=>'商家账户',3=>'承兑商账户'];
  281. $coinName = isset($coinTypes[$coinType])? $coinTypes[$coinType] : '账户';
  282. $accountName = isset($accountTypes[$userType])? $accountTypes[$userType] : '会员账户';
  283. if($checkStatus == 2) {
  284. // 线下交易
  285. if($payType == 30){
  286. if(!in_array($userType,[1,3]) && !in_array($coinType,[1,6])){
  287. DB::rollBack();
  288. $this->error = 1021;
  289. RedisService::clear($cacheKey);
  290. return false;
  291. }
  292. // USDT入账
  293. if($userType == 1 && $coinType == 1){
  294. $updateData = ['usdt' => DB::raw("usdt + {$actualMoney}"),'update_time'=>time()];
  295. if (!MemberModel::where(['id' => $accountId])->update($updateData)){
  296. DB::rollBack();
  297. $this->error = 1072;
  298. RedisService::clear($cacheKey);
  299. return false;
  300. }
  301. }
  302. // 交易额度入账
  303. else if($userType == 3 && $coinType == 6){
  304. $updateData = ['quota' => DB::raw("quota + {$actualMoney}"),'update_time'=>time()];
  305. if (!AcceptorModel::where(['id' => $accountId])->update($updateData)){
  306. DB::rollBack();
  307. $this->error = 1072;
  308. RedisService::clear($cacheKey);
  309. return false;
  310. }
  311. }
  312. // 账户明细
  313. $log = [
  314. 'user_id' => $accountId,
  315. 'source_id' => 0,
  316. 'source_order_no' => $info['order_no'],
  317. 'type' => 5,
  318. 'coin_type' => $coinType,
  319. 'user_type'=> $userType,
  320. 'money' => $money,
  321. 'actual_money' => $actualMoney,
  322. 'balance' => $balance,
  323. 'create_time' => time(),
  324. 'update_time' => time(),
  325. 'remark' => "{$coinName}充值",
  326. 'status' => 1,
  327. 'mark' => 1,
  328. ];
  329. if(!AccountLogModel::insertGetId($log)){
  330. DB::rollBack();
  331. $this->error = 2029;
  332. RedisService::clear($cacheKey);
  333. return false;
  334. }
  335. }else{
  336. DB::rollBack();
  337. $this->error = 1021;
  338. RedisService::clear($cacheKey);
  339. return false;
  340. }
  341. $title = "{$coinName}充值审核成功通知";
  342. $message = "您的充值申请在{$dateTime}UTC+8审核成功,明细如下:\n单号:{$info['order_no']}\n账户:{$accountName}\n金额:{$money}\n到账:{$actualMoney}\n审核状态:成功\n审核说明:{$remark}";
  343. }else{
  344. $title = "{$coinName}充值审核失败通知";
  345. $message = "您的充值申请在{$dateTime}UTC+8审核失败,明细如下:\n单号:{$info['order_no']}\n账户:{$accountName}\n金额:{$money}\n到账:{$actualMoney}\n审核状态:未通过\n审核说明:{$remark}";
  346. }
  347. // 消息通知
  348. MessageService::make()->pushMessage($userId, $title, $message, 3);
  349. DB::commit();
  350. $this->error = 1071;
  351. RedisService::clear($cacheKey);
  352. return true;
  353. }
  354. /**
  355. * 提现审核
  356. * @param $params
  357. * @return bool
  358. */
  359. public function withdrawAuth($params)
  360. {
  361. $id = isset($params['id'])? $params['id'] : 0;
  362. $checkStatus = isset($params['status'])? $params['status'] : 0;
  363. $remark = isset($params['audit_remark'])? trim($params['audit_remark']) : '';
  364. $payImg = isset($params['pay_img'])? trim($params['pay_img']) : '';
  365. if(!in_array($checkStatus,[2,3])){
  366. $this->error = 1073;
  367. return false;
  368. }
  369. $info = $this->model->with(['member','merchant','acceptor'])->where(['id'=> $id,'mark'=>1])->first();
  370. $type = isset($info['type'])? $info['type'] : 0;
  371. $userType = isset($info['user_type'])? $info['user_type'] : 0;
  372. $coinType = isset($info['coin_type'])? $info['coin_type'] : 0;
  373. $payType = isset($info['pay_type'])? $info['pay_type'] : 0;
  374. $accountId = isset($info['user_id'])? $info['user_id'] : 0;
  375. $money = isset($info['money'])? $info['money'] : 0;
  376. $actualMoney = isset($info['actual_money'])? $info['actual_money'] : 0;
  377. $fee = isset($info['fee'])? $info['fee'] : 0;
  378. $status = isset($info['status'])? $info['status'] : 0;
  379. if($id<=0 || empty($info) || $accountId<=0){
  380. $this->error = 4001;
  381. return false;
  382. }
  383. if($status != 1){
  384. $this->error = 4002;
  385. return false;
  386. }
  387. if($type != 2){
  388. $this->error = 1031;
  389. return false;
  390. }
  391. $cacheKey ="caches:withdraw:lock_{$id}";
  392. if(RedisService::get($cacheKey)){
  393. $this->error = 1034;
  394. return false;
  395. }
  396. // 绑定的用户ID
  397. $userId = $accountId;
  398. $userInfo = isset($info['member'])? $info['member'] : [];
  399. $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
  400. if($userType == 2){
  401. $userInfo = isset($info['merchant'])? $info['merchant'] : [];
  402. $userId = isset($userInfo['user_id'])? $userInfo['user_id'] : 0;
  403. $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
  404. }else if($userType == 3){
  405. $userInfo = isset($info['acceptor'])? $info['acceptor'] : [];
  406. $userId = isset($userInfo['user_id'])? $userInfo['user_id'] : 0;
  407. $balance = isset($userInfo['quota'])? $userInfo['quota'] : 0;
  408. }
  409. if(empty($userInfo)){
  410. $this->error = 4004;
  411. return false;
  412. }
  413. // 审核处理
  414. RedisService::set($cacheKey, true);
  415. DB::beginTransaction();
  416. // 审核通过到账处理
  417. $dateTime = date('Y-m-d H:i:s');
  418. $accountTypes = [1=>'会员账户',2=>'商家账户',3=>'承兑商账户'];
  419. $coinName = 'USDT余额';
  420. if($userType == 2 && $coinType==1){
  421. $coinName = 'USDT佣金';
  422. }else if($userType == 3 && $coinType==1){
  423. $coinName = 'USDT佣金';
  424. }else if($userType == 3 && $coinType==6){
  425. $coinName = '交易额度';
  426. }
  427. $accountName = isset($accountTypes[$userType])? $accountTypes[$userType] : '会员账户';
  428. if($checkStatus == 2) {
  429. // USDT链上打款
  430. $hash = '';
  431. if($payType == 20){
  432. $trcUrl = isset($userInfo['trc_url'])? $userInfo['trc_url'] : '';
  433. if(empty($trcUrl)){
  434. DB::rollBack();
  435. $this->error = 4005;
  436. RedisService::clear($cacheKey);
  437. return false;
  438. }
  439. $result = WalletService::make()->usdtTrcTransfer($trcUrl, $actualMoney);
  440. $hash = isset($result['txId']) ? $result['txId'] : '';
  441. if(empty($hash)){
  442. DB::rollBack();
  443. $this->error = 4005;
  444. RedisService::clear($cacheKey);
  445. return false;
  446. }
  447. $payAddress = isset($result['address']) ? $result['address'] : '';
  448. $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()];
  449. if(!$this->model->where(['id'=> $id])->update($updateData)){
  450. DB::rollBack();
  451. $this->error = 4006;
  452. RedisService::clear($cacheKey);
  453. return false;
  454. }
  455. }
  456. // 线下打款
  457. else if($payType == 30){
  458. $updateData = ['status'=> 2,'pay_status'=>20,'pay_at'=>$dateTime,'pay_img'=> get_image_path($payImg),'audit_remark'=> $remark,'update_time'=> time()];
  459. if(!$this->model->where(['id'=> $id])->update($updateData)){
  460. DB::rollBack();
  461. $this->error = 1072;
  462. RedisService::clear($cacheKey);
  463. return false;
  464. }
  465. }else{
  466. DB::rollBack();
  467. $this->error = 1021;
  468. RedisService::clear($cacheKey);
  469. return false;
  470. }
  471. // 平台手续费明细
  472. if($fee>0){
  473. $log = [
  474. 'user_id' => 0,
  475. 'source_id' => $accountId,
  476. 'source_order_no' => $info['order_no'],
  477. 'type' => 5,
  478. 'coin_type' => $coinType,
  479. 'user_type' => 4,
  480. 'money' => $fee,
  481. 'actual_money' => $fee,
  482. 'balance' => 0,
  483. 'create_time' => time(),
  484. 'update_time' => time(),
  485. 'hash' => $hash,
  486. 'remark' => "{$coinName}提现",
  487. 'status' => 1,
  488. 'mark' => 1,
  489. ];
  490. if(!AccountLogModel::insertGetId($log)){
  491. DB::rollBack();
  492. $this->error = 2029;
  493. RedisService::clear($cacheKey);
  494. return false;
  495. }
  496. FinanceService::make()->saveLog(0, $fee, 1);
  497. }
  498. $title = "{$coinName}提现审核成功通知";
  499. $message = "您的提现申请在{$dateTime}UTC+8审核成功,明细如下:\n单号:{$info['order_no']}\n账户:{$accountName}\n提现金额:{$money}\n到账:{$actualMoney}\n审核状态:审核成功\n审核说明:{$remark}";
  500. }
  501. // 审核失败驳回退款
  502. else{
  503. if(!in_array($userType,[1,2,3]) && !in_array($coinType,[1,6])){
  504. DB::rollBack();
  505. $this->error = 1021;
  506. RedisService::clear($cacheKey);
  507. return false;
  508. }
  509. $updateData = ['status'=> 3,'pay_img'=> get_image_path($payImg),'audit_remark'=> $remark,'update_time'=> time()];
  510. if(!$this->model->where(['id'=> $id])->update($updateData)){
  511. DB::rollBack();
  512. $this->error = 1072;
  513. RedisService::clear($cacheKey);
  514. return false;
  515. }
  516. // 会员:USDT驳回入账
  517. if($userType == 1 && $coinType == 1){
  518. $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
  519. $updateData = ['usdt' => DB::raw("usdt + {$money}"),'update_time'=>time()];
  520. if (!MemberModel::where(['id' => $accountId])->update($updateData)){
  521. DB::rollBack();
  522. $this->error = 1072;
  523. RedisService::clear($cacheKey);
  524. return false;
  525. }
  526. }
  527. // 商家:佣金入账
  528. else if($userType == 2 && $coinType == 1){
  529. $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
  530. $updateData = ['usdt' => DB::raw("usdt + {$money}"),'update_time'=>time()];
  531. if (!MerchantModel::where(['id' => $accountId])->update($updateData)){
  532. DB::rollBack();
  533. $this->error = 1072;
  534. RedisService::clear($cacheKey);
  535. return false;
  536. }
  537. }
  538. // 承兑商:佣金入账
  539. else if($userType == 3 && $coinType == 1){
  540. $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
  541. $updateData = ['usdt' => DB::raw("usdt + {$money}"),'update_time'=>time()];
  542. if (!AcceptorModel::where(['id' => $accountId])->update($updateData)){
  543. DB::rollBack();
  544. $this->error = 1072;
  545. RedisService::clear($cacheKey);
  546. return false;
  547. }
  548. }
  549. // 承兑商:交易额度入账
  550. else if($userType == 3 && $coinType == 6){
  551. $balance = isset($userInfo['quota'])? $userInfo['quota'] : 0;
  552. $updateData = ['quota' => DB::raw("quota + {$money}"),'update_time'=>time()];
  553. if (!AcceptorModel::where(['id' => $accountId])->update($updateData)){
  554. DB::rollBack();
  555. $this->error = 1072;
  556. RedisService::clear($cacheKey);
  557. return false;
  558. }
  559. }
  560. // 账户明细
  561. $log = [
  562. 'user_id' => $accountId,
  563. 'source_id' => 0,
  564. 'source_order_no' => $info['order_no'],
  565. 'type' => 5,
  566. 'coin_type' => $coinType,
  567. 'user_type'=> $userType,
  568. 'money' => $money,
  569. 'actual_money' => $money,
  570. 'balance' => $balance,
  571. 'create_time' => time(),
  572. 'update_time' => time(),
  573. 'remark' => "{$coinName}提现驳回",
  574. 'status' => 1,
  575. 'mark' => 1,
  576. ];
  577. if(!AccountLogModel::insertGetId($log)){
  578. DB::rollBack();
  579. $this->error = 2029;
  580. RedisService::clear($cacheKey);
  581. return false;
  582. }
  583. $title = "{$coinName}提现审核失败通知";
  584. $message = "您的提现申请在{$dateTime}UTC+8审核失败,提现金额已退回对应账户,明细如下:\n单号:{$info['order_no']}\n账户:{$accountName}\n提现金额:{$money}\n到账:{$actualMoney}\n审核状态:未通过\n审核说明:{$remark}";
  585. }
  586. // 消息通知
  587. MessageService::make()->pushMessage($userId, $title, $message, 3);
  588. DB::commit();
  589. $this->error = 1071;
  590. RedisService::clear($cacheKey);
  591. return true;
  592. }
  593. }