BalanceLogService.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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);
  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=>'星豆余额',3=>'交易额度'];
  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. return true;
  352. }
  353. /**
  354. * 提现审核
  355. * @param $params
  356. * @return bool
  357. */
  358. public function withdrawAuth($params)
  359. {
  360. $id = isset($params['id'])? $params['id'] : 0;
  361. $checkStatus = isset($params['status'])? $params['status'] : 0;
  362. $remark = isset($params['audit_remark'])? trim($params['audit_remark']) : '';
  363. $payImg = isset($params['pay_img'])? trim($params['pay_img']) : '';
  364. if(!in_array($checkStatus,[2,3])){
  365. $this->error = 1073;
  366. return false;
  367. }
  368. $info = $this->model->with(['member','merchant','acceptor'])->where(['id'=> $id,'mark'=>1])->first();
  369. $type = isset($info['type'])? $info['type'] : 0;
  370. $userType = isset($info['user_type'])? $info['user_type'] : 0;
  371. $coinType = isset($info['coin_type'])? $info['coin_type'] : 0;
  372. $payType = isset($info['pay_type'])? $info['pay_type'] : 0;
  373. $accountId = isset($info['user_id'])? $info['user_id'] : 0;
  374. $money = isset($info['money'])? $info['money'] : 0;
  375. $actualMoney = isset($info['actual_money'])? $info['actual_money'] : 0;
  376. $fee = isset($info['fee'])? $info['fee'] : 0;
  377. $status = isset($info['status'])? $info['status'] : 0;
  378. if($id<=0 || empty($info) || $accountId<=0){
  379. $this->error = 4001;
  380. return false;
  381. }
  382. if($status != 1){
  383. $this->error = 4002;
  384. return false;
  385. }
  386. if($type != 2){
  387. $this->error = 1031;
  388. return false;
  389. }
  390. $cacheKey ="caches:withdraw:lock_{$id}";
  391. if(RedisService::get($cacheKey)){
  392. $this->error = 1034;
  393. return false;
  394. }
  395. // 绑定的用户ID
  396. $userId = $accountId;
  397. $userInfo = isset($info['member'])? $info['member'] : [];
  398. $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
  399. if($userType == 2){
  400. $userInfo = isset($info['merchant'])? $info['merchant'] : [];
  401. $userId = isset($userInfo['user_id'])? $userInfo['user_id'] : 0;
  402. $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
  403. }else if($userType == 3){
  404. $userInfo = isset($info['acceptor'])? $info['acceptor'] : [];
  405. $userId = isset($userInfo['user_id'])? $userInfo['user_id'] : 0;
  406. $balance = isset($userInfo['quota'])? $userInfo['quota'] : 0;
  407. }
  408. if(empty($userInfo)){
  409. $this->error = 4004;
  410. return false;
  411. }
  412. // 审核处理
  413. RedisService::set($cacheKey, true);
  414. DB::beginTransaction();
  415. // 审核通过到账处理
  416. $dateTime = date('Y-m-d H:i:s');
  417. $accountTypes = [1=>'会员账户',2=>'商家账户',3=>'承兑商账户'];
  418. $coinName = 'USDT余额';
  419. if($userType == 2 && $coinType==1){
  420. $coinName = 'USDT佣金';
  421. }else if($userType == 3 && $coinType==1){
  422. $coinName = 'USDT佣金';
  423. }else if($userType == 3 && $coinType==6){
  424. $coinName = '交易额度';
  425. }
  426. $accountName = isset($accountTypes[$userType])? $accountTypes[$userType] : '会员账户';
  427. if($checkStatus == 2) {
  428. // USDT链上打款
  429. $hash = '';
  430. if($payType == 20){
  431. $trcUrl = isset($userInfo['trc_url'])? $userInfo['trc_url'] : '';
  432. if(empty($trcUrl)){
  433. DB::rollBack();
  434. $this->error = 4005;
  435. RedisService::clear($cacheKey);
  436. return false;
  437. }
  438. $result = WalletService::make()->usdtTrcTransfer($trcUrl, $actualMoney);
  439. $hash = isset($result['txId']) ? $result['txId'] : '';
  440. if(empty($hash)){
  441. DB::rollBack();
  442. $this->error = 4005;
  443. RedisService::clear($cacheKey);
  444. return false;
  445. }
  446. $payAddress = isset($result['address']) ? $result['address'] : '';
  447. $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()];
  448. if(!$this->model->where(['id'=> $id])->update($updateData)){
  449. DB::rollBack();
  450. $this->error = 4006;
  451. RedisService::clear($cacheKey);
  452. return false;
  453. }
  454. }
  455. // 线下打款
  456. else if($payType == 30){
  457. $updateData = ['status'=> 2,'pay_status'=>20,'pay_at'=>$dateTime,'pay_img'=> get_image_path($payImg),'audit_remark'=> $remark,'update_time'=> time()];
  458. if(!$this->model->where(['id'=> $id])->update($updateData)){
  459. DB::rollBack();
  460. $this->error = 1072;
  461. RedisService::clear($cacheKey);
  462. return false;
  463. }
  464. }else{
  465. DB::rollBack();
  466. $this->error = 1021;
  467. RedisService::clear($cacheKey);
  468. return false;
  469. }
  470. // 平台手续费明细
  471. if($fee>0){
  472. $log = [
  473. 'user_id' => 0,
  474. 'source_id' => $accountId,
  475. 'source_order_no' => $info['order_no'],
  476. 'type' => 5,
  477. 'coin_type' => $coinType,
  478. 'user_type' => 4,
  479. 'money' => $fee,
  480. 'actual_money' => $fee,
  481. 'balance' => 0,
  482. 'create_time' => time(),
  483. 'update_time' => time(),
  484. 'hash' => $hash,
  485. 'remark' => "{$coinName}提现",
  486. 'status' => 1,
  487. 'mark' => 1,
  488. ];
  489. if(!AccountLogModel::insertGetId($log)){
  490. DB::rollBack();
  491. $this->error = 2029;
  492. RedisService::clear($cacheKey);
  493. return false;
  494. }
  495. FinanceService::make()->saveLog(0, $fee, 1);
  496. }
  497. $title = "{$coinName}提现审核成功通知";
  498. $message = "您的提现申请在{$dateTime}UTC+8审核成功,明细如下:\n单号:{$info['order_no']}\n账户:{$accountName}\n提现金额:{$money}\n到账:{$actualMoney}\n审核状态:审核成功\n审核说明:{$remark}";
  499. }
  500. // 审核失败驳回退款
  501. else{
  502. if(!in_array($userType,[1,2,3]) && !in_array($coinType,[1,6])){
  503. DB::rollBack();
  504. $this->error = 1021;
  505. RedisService::clear($cacheKey);
  506. return false;
  507. }
  508. $updateData = ['status'=> 3,'pay_img'=> get_image_path($payImg),'audit_remark'=> $remark,'update_time'=> time()];
  509. if(!$this->model->where(['id'=> $id])->update($updateData)){
  510. DB::rollBack();
  511. $this->error = 1072;
  512. RedisService::clear($cacheKey);
  513. return false;
  514. }
  515. // 会员:USDT驳回入账
  516. if($userType == 1 && $coinType == 1){
  517. $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
  518. $updateData = ['usdt' => DB::raw("usdt + {$money}"),'update_time'=>time()];
  519. if (!MemberModel::where(['id' => $accountId])->update($updateData)){
  520. DB::rollBack();
  521. $this->error = 1072;
  522. RedisService::clear($cacheKey);
  523. return false;
  524. }
  525. }
  526. // 商家:佣金入账
  527. else if($userType == 2 && $coinType == 1){
  528. $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
  529. $updateData = ['usdt' => DB::raw("usdt + {$money}"),'update_time'=>time()];
  530. if (!MerchantModel::where(['id' => $accountId])->update($updateData)){
  531. DB::rollBack();
  532. $this->error = 1072;
  533. RedisService::clear($cacheKey);
  534. return false;
  535. }
  536. }
  537. // 承兑商:佣金入账
  538. else if($userType == 3 && $coinType == 1){
  539. $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
  540. $updateData = ['usdt' => DB::raw("usdt + {$money}"),'update_time'=>time()];
  541. if (!AcceptorModel::where(['id' => $accountId])->update($updateData)){
  542. DB::rollBack();
  543. $this->error = 1072;
  544. RedisService::clear($cacheKey);
  545. return false;
  546. }
  547. }
  548. // 承兑商:交易额度入账
  549. else if($userType == 3 && $coinType == 6){
  550. $balance = isset($userInfo['quota'])? $userInfo['quota'] : 0;
  551. $updateData = ['quota' => DB::raw("quota + {$money}"),'update_time'=>time()];
  552. if (!AcceptorModel::where(['id' => $accountId])->update($updateData)){
  553. DB::rollBack();
  554. $this->error = 1072;
  555. RedisService::clear($cacheKey);
  556. return false;
  557. }
  558. }
  559. // 账户明细
  560. $log = [
  561. 'user_id' => $accountId,
  562. 'source_id' => 0,
  563. 'source_order_no' => $info['order_no'],
  564. 'type' => 5,
  565. 'coin_type' => $coinType,
  566. 'user_type'=> $userType,
  567. 'money' => $money,
  568. 'actual_money' => $money,
  569. 'balance' => $balance,
  570. 'create_time' => time(),
  571. 'update_time' => time(),
  572. 'remark' => "{$coinName}提现驳回",
  573. 'status' => 1,
  574. 'mark' => 1,
  575. ];
  576. if(!AccountLogModel::insertGetId($log)){
  577. DB::rollBack();
  578. $this->error = 2029;
  579. RedisService::clear($cacheKey);
  580. return false;
  581. }
  582. $title = "{$coinName}提现审核失败通知";
  583. $message = "您的提现申请在{$dateTime}UTC+8审核失败,提现金额已退回对应账户,明细如下:\n单号:{$info['order_no']}\n账户:{$accountName}\n提现金额:{$money}\n到账:{$actualMoney}\n审核状态:未通过\n审核说明:{$remark}";
  584. }
  585. // 消息通知
  586. MessageService::make()->pushMessage($userId, $title, $message, 3);
  587. DB::commit();
  588. $this->error = 1071;
  589. return true;
  590. }
  591. }