|
@@ -11,21 +11,18 @@
|
|
|
|
|
|
|
|
namespace App\Services\Common;
|
|
namespace App\Services\Common;
|
|
|
|
|
|
|
|
-use App\Models\AcceptorModel;
|
|
|
|
|
use App\Models\AccountLogModel;
|
|
use App\Models\AccountLogModel;
|
|
|
use App\Models\ActionLogModel;
|
|
use App\Models\ActionLogModel;
|
|
|
use App\Models\BalanceLogModel;
|
|
use App\Models\BalanceLogModel;
|
|
|
use App\Models\MemberModel;
|
|
use App\Models\MemberModel;
|
|
|
-use App\Models\MerchantModel;
|
|
|
|
|
use App\Services\Api\FinanceService;
|
|
use App\Services\Api\FinanceService;
|
|
|
-use App\Services\Api\MessageService;
|
|
|
|
|
use App\Services\BaseService;
|
|
use App\Services\BaseService;
|
|
|
use App\Services\RedisService;
|
|
use App\Services\RedisService;
|
|
|
use App\Services\WalletService;
|
|
use App\Services\WalletService;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 承兑商管理-服务类
|
|
|
|
|
|
|
+ * 充值提现管理-服务类
|
|
|
* @author laravel开发员
|
|
* @author laravel开发员
|
|
|
* @since 2020/11/11
|
|
* @since 2020/11/11
|
|
|
* @package App\Services\Common
|
|
* @package App\Services\Common
|
|
@@ -66,7 +63,7 @@ class BalanceLogService extends BaseService
|
|
|
public function getDataList($params, $pageSize = 10, $field = [])
|
|
public function getDataList($params, $pageSize = 10, $field = [])
|
|
|
{
|
|
{
|
|
|
$query = $this->getQuery($params);
|
|
$query = $this->getQuery($params);
|
|
|
- $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'])
|
|
|
|
|
|
|
+ $list = $query->select($field ? $field : ['a.*', 'b.nickname'])
|
|
|
->orderBy('a.status','asc')
|
|
->orderBy('a.status','asc')
|
|
|
->orderBy('a.create_time','desc')
|
|
->orderBy('a.create_time','desc')
|
|
|
->orderBy('a.pay_at','desc')
|
|
->orderBy('a.pay_at','desc')
|
|
@@ -75,17 +72,9 @@ class BalanceLogService extends BaseService
|
|
|
if ($list) {
|
|
if ($list) {
|
|
|
foreach ($list['data'] as &$item) {
|
|
foreach ($list['data'] as &$item) {
|
|
|
$item['create_time'] = datetime($item['create_time'],'Y-m-d H:i:s');
|
|
$item['create_time'] = datetime($item['create_time'],'Y-m-d H:i:s');
|
|
|
- $item['pay_img'] = isset($item['pay_img'])?get_image_url($item['pay_img']):'';
|
|
|
|
|
- $item['trc_url'] = $item['trc_url']?$item['trc_url'] : $item['user_trc_url'];
|
|
|
|
|
if($item['user_type'] == 1){
|
|
if($item['user_type'] == 1){
|
|
|
$item['uid'] = $item['user_id'];
|
|
$item['uid'] = $item['user_id'];
|
|
|
- $item['account'] = isset($item['nickname'])&& $item['nickname']?$item['nickname'].(isset($item['username'])?' '.$item['username']:'') : $item['user_id'];
|
|
|
|
|
- }else if($item['user_type'] == 2){
|
|
|
|
|
- $item['uid'] = isset($item['merchant']['user_id'])&& $item['merchant']? $item['merchant']['user_id'] : 0;
|
|
|
|
|
- $item['account'] = isset($item['merchant']['nickname'])&& $item['merchant']?$item['merchant']['nickname'].(isset($item['merchant']['mobile'])?' '.$item['merchant']['mobile']:'') : $item['merchant_uid'];
|
|
|
|
|
- }else if($item['user_type'] == 3){
|
|
|
|
|
- $item['uid'] = isset($item['acceptor']['user_id'])&& $item['acceptor']? $item['acceptor']['user_id'] : 0;
|
|
|
|
|
- $item['account'] = isset($item['acceptor']['nickname'])&& $item['acceptor']?$item['acceptor']['nickname'].(isset($item['acceptor']['mobile'])?' '.$item['acceptor']['mobile']:'') : $item['acceptor_uid'];
|
|
|
|
|
|
|
+ $item['account'] = isset($item['nickname'])&& $item['nickname']? $item['nickname'] : $item['user_id'];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -105,44 +94,18 @@ class BalanceLogService extends BaseService
|
|
|
public function getQuery($params)
|
|
public function getQuery($params)
|
|
|
{
|
|
{
|
|
|
$where = ['a.mark' => 1];
|
|
$where = ['a.mark' => 1];
|
|
|
- return $this->model->with(['member','acceptor','merchant','payment'])
|
|
|
|
|
|
|
+ return $this->model->with(['member'])
|
|
|
->from('balance_logs as a')
|
|
->from('balance_logs as a')
|
|
|
->leftJoin('member as b', function($join) {
|
|
->leftJoin('member as b', function($join) {
|
|
|
$join->on('b.id','=', 'a.user_id')->where('a.user_type',1);
|
|
$join->on('b.id','=', 'a.user_id')->where('a.user_type',1);
|
|
|
})
|
|
})
|
|
|
- ->leftJoin('merchant as c', function($join) {
|
|
|
|
|
- $join->on('c.id','=', 'a.user_id')->where('a.user_type',2);
|
|
|
|
|
- })
|
|
|
|
|
- ->leftJoin('acceptor as d', function($join) {
|
|
|
|
|
- $join->on('d.id','=', 'a.user_id')->where('a.user_type',3);
|
|
|
|
|
- })
|
|
|
|
|
->where($where)
|
|
->where($where)
|
|
|
->where(function ($query) use ($params) {
|
|
->where(function ($query) use ($params) {
|
|
|
- $userType = isset($params['user_type'])? intval($params['user_type']) : 1;
|
|
|
|
|
$kw = isset($params['keyword']) ? trim($params['keyword']) : '';
|
|
$kw = isset($params['keyword']) ? trim($params['keyword']) : '';
|
|
|
|
|
|
|
|
if ($kw) {
|
|
if ($kw) {
|
|
|
- if($userType == 3){
|
|
|
|
|
- $query->where('d.user_id', '=', "{$params['keyword']}")
|
|
|
|
|
- ->orWhere('d.name', 'like', "%{$params['keyword']}%")
|
|
|
|
|
- ->orWhere('d.mobile', 'like', "%{$params['keyword']}%");
|
|
|
|
|
- }else if($userType == 2){
|
|
|
|
|
- $query->where('c.user_id', '=', "{$params['keyword']}")
|
|
|
|
|
- ->orWhere('c.name', 'like', "%{$params['keyword']}%")
|
|
|
|
|
- ->orWhere('c.mobile', 'like', "%{$params['keyword']}%");
|
|
|
|
|
- }else if($userType == 1){
|
|
|
|
|
- $query->where('b.id', '=', "{$params['keyword']}")
|
|
|
|
|
- ->orWhere('b.nickname', 'like', "%{$params['keyword']}%")
|
|
|
|
|
- ->orWhere('b.username', 'like', "%{$params['keyword']}%");
|
|
|
|
|
- }else{
|
|
|
|
|
- $query->where('a.user_id', '=', "{$params['keyword']}")
|
|
|
|
|
- ->orWhere('b.nickname', 'like', "%{$params['keyword']}%")
|
|
|
|
|
- ->orWhere('b.username', 'like', "%{$params['keyword']}%")
|
|
|
|
|
- ->orWhere('c.name', 'like', "%{$params['keyword']}%")
|
|
|
|
|
- ->orWhere('c.mobile', 'like', "%{$params['keyword']}%")
|
|
|
|
|
- ->orWhere('d.name', 'like', "%{$params['keyword']}%")
|
|
|
|
|
- ->orWhere('d.mobile', 'like', "%{$params['keyword']}%");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ $query->where('b.id', '=', $params['keyword'])
|
|
|
|
|
+ ->orWhere('b.nickname', 'like', "%{$params['keyword']}%");
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
->where(function ($query) use($params){
|
|
->where(function ($query) use($params){
|
|
@@ -163,19 +126,19 @@ class BalanceLogService extends BaseService
|
|
|
$query->where('a.order_no', 'like', "%{$orderNo}%");
|
|
$query->where('a.order_no', 'like', "%{$orderNo}%");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $trcUrl = isset($params['trc_url'])? trim($params['trc_url']) : '';
|
|
|
|
|
- if($trcUrl){
|
|
|
|
|
- $query->where('a.trc_url', '=', $trcUrl);
|
|
|
|
|
|
|
+ $walletUrl = isset($params['wallet_url'])? trim($params['wallet_url']) : '';
|
|
|
|
|
+ if($walletUrl){
|
|
|
|
|
+ $query->where('a.wallet_url', '=', $walletUrl);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $hash = isset($params['hash'])? trim($params['hash']) : '';
|
|
|
|
|
- if($hash){
|
|
|
|
|
- $query->where('a.trc_url', '=', $hash);
|
|
|
|
|
|
|
+ $ptWalletUrl = isset($params['pt_wallet_url'])? trim($params['pt_wallet_url']) : '';
|
|
|
|
|
+ if($ptWalletUrl){
|
|
|
|
|
+ $query->where('a.pt_wallet_url', '=', $ptWalletUrl);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $orderNo = isset($params['order_no'])? trim($params['order_no']) : '';
|
|
|
|
|
- if($orderNo){
|
|
|
|
|
- $query->where('a.order_no', 'like', "%{$orderNo}%");
|
|
|
|
|
|
|
+ $hash = isset($params['hash'])? trim($params['hash']) : '';
|
|
|
|
|
+ if($hash){
|
|
|
|
|
+ $query->where('a.hash', '=', $hash);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$userType = isset($params['user_type'])? $params['user_type'] : 0;
|
|
$userType = isset($params['user_type'])? $params['user_type'] : 0;
|
|
@@ -225,7 +188,7 @@ class BalanceLogService extends BaseService
|
|
|
{
|
|
{
|
|
|
$query = $this->getQuery($params);
|
|
$query = $this->getQuery($params);
|
|
|
$count = $query->count('a.id');
|
|
$count = $query->count('a.id');
|
|
|
- $total = $query->sum('a.actual_money');
|
|
|
|
|
|
|
+ $total = $query->sum('a.money');
|
|
|
return [
|
|
return [
|
|
|
'count' => $count,
|
|
'count' => $count,
|
|
|
'total' => $total
|
|
'total' => $total
|
|
@@ -233,168 +196,6 @@ class BalanceLogService extends BaseService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 充值审核
|
|
|
|
|
- * @param $params
|
|
|
|
|
- * @return bool
|
|
|
|
|
- */
|
|
|
|
|
- public function rechargeAuth($params)
|
|
|
|
|
- {
|
|
|
|
|
- $id = isset($params['id'])? $params['id'] : 0;
|
|
|
|
|
- $checkStatus = isset($params['status'])? $params['status'] : 0;
|
|
|
|
|
- $remark = isset($params['audit_remark'])? trim($params['audit_remark']) : '';
|
|
|
|
|
- $payImg = isset($params['pay_img'])? trim($params['pay_img']) : '';
|
|
|
|
|
- if(!in_array($checkStatus,[2,3])){
|
|
|
|
|
- $this->error = 1073;
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- $info = $this->model->with(['member','merchant','acceptor'])->where(['id'=> $id,'mark'=>1])->first();
|
|
|
|
|
- $type = isset($info['type'])? $info['type'] : 0;
|
|
|
|
|
- $userType = isset($info['user_type'])? $info['user_type'] : 0;
|
|
|
|
|
- $coinType = isset($info['coin_type'])? $info['coin_type'] : 0;
|
|
|
|
|
- $payType = isset($info['pay_type'])? $info['pay_type'] : 0;
|
|
|
|
|
- $accountId = isset($info['user_id'])? $info['user_id'] : 0;
|
|
|
|
|
- $money = isset($info['money'])? $info['money'] : 0;
|
|
|
|
|
- $actualMoney = isset($info['actual_money'])? $info['actual_money'] : 0;
|
|
|
|
|
- $status = isset($info['status'])? $info['status'] : 0;
|
|
|
|
|
- if($id<=0 || empty($info) || $accountId<=0){
|
|
|
|
|
- $this->error = 4001;
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if($status != 1){
|
|
|
|
|
- $this->error = 4002;
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if($type != 1){
|
|
|
|
|
- $this->error = 1031;
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- $cacheKey ="caches:recharge:lock_{$id}";
|
|
|
|
|
- if(RedisService::get($cacheKey)){
|
|
|
|
|
- $this->error = 1034;
|
|
|
|
|
-// return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 绑定的用户ID
|
|
|
|
|
- $userId = $accountId;
|
|
|
|
|
- $userInfo = isset($info['member'])? $info['member'] : [];
|
|
|
|
|
- $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
|
|
|
|
|
- if($userType == 2){
|
|
|
|
|
- $userInfo = isset($info['merchant'])? $info['merchant'] : [];
|
|
|
|
|
- $userId = isset($userInfo['user_id'])? $userInfo['user_id'] : 0;
|
|
|
|
|
- $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
|
|
|
|
|
- }else if($userType == 3){
|
|
|
|
|
- $userInfo = isset($info['acceptor'])? $info['acceptor'] : [];
|
|
|
|
|
- $userId = isset($userInfo['user_id'])? $userInfo['user_id'] : 0;
|
|
|
|
|
- $balance = isset($userInfo['quota'])? $userInfo['quota'] : 0;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if(empty($userInfo)){
|
|
|
|
|
- $this->error = 4004;
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 审核处理
|
|
|
|
|
- RedisService::set($cacheKey, true, rand(2,3));
|
|
|
|
|
- $updateData = ['status'=> $checkStatus,'audit_remark'=> $remark,'update_time'=> time()];
|
|
|
|
|
- DB::beginTransaction();
|
|
|
|
|
- if(!$this->model->where(['id'=> $id])->update($updateData)){
|
|
|
|
|
- DB::rollBack();
|
|
|
|
|
- $this->error = 1072;
|
|
|
|
|
- RedisService::clear($cacheKey);
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 审核通过到账处理
|
|
|
|
|
- $dateTime = date('Y-m-d H:i:s');
|
|
|
|
|
- $coinTypes = [1=>'USDT余额',2=>'星豆余额',6=>'交易额度'];
|
|
|
|
|
- $accountTypes = [1=>'会员账户',2=>'商家账户',3=>'承兑商账户'];
|
|
|
|
|
- $coinName = isset($coinTypes[$coinType])? $coinTypes[$coinType] : '账户';
|
|
|
|
|
- $accountName = isset($accountTypes[$userType])? $accountTypes[$userType] : '会员账户';
|
|
|
|
|
- if($checkStatus == 2) {
|
|
|
|
|
- // 线下交易
|
|
|
|
|
- if($payType == 30){
|
|
|
|
|
- if(!in_array($userType,[1,3]) && !in_array($coinType,[1,6])){
|
|
|
|
|
- DB::rollBack();
|
|
|
|
|
- $this->error = 1021;
|
|
|
|
|
- RedisService::clear($cacheKey);
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // USDT入账
|
|
|
|
|
- if($userType == 1 && $coinType == 1){
|
|
|
|
|
- $updateData = ['usdt' => DB::raw("usdt + {$actualMoney}"),'update_time'=>time()];
|
|
|
|
|
- if (!MemberModel::where(['id' => $accountId])->update($updateData)){
|
|
|
|
|
- DB::rollBack();
|
|
|
|
|
- $this->error = 1072;
|
|
|
|
|
- RedisService::clear($cacheKey);
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- // 交易额度入账
|
|
|
|
|
- else if($userType == 3 && $coinType == 6){
|
|
|
|
|
- $updateData = ['quota' => DB::raw("quota + {$actualMoney}"),'update_time'=>time()];
|
|
|
|
|
- if (!AcceptorModel::where(['id' => $accountId])->update($updateData)){
|
|
|
|
|
- DB::rollBack();
|
|
|
|
|
- $this->error = 1072;
|
|
|
|
|
- RedisService::clear($cacheKey);
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 账户明细
|
|
|
|
|
- $log = [
|
|
|
|
|
- 'user_id' => $accountId,
|
|
|
|
|
- 'source_id' => 0,
|
|
|
|
|
- 'source_order_no' => $info['order_no'],
|
|
|
|
|
- 'type' => 5,
|
|
|
|
|
- 'coin_type' => $coinType,
|
|
|
|
|
- 'user_type'=> $userType,
|
|
|
|
|
- 'money' => $money,
|
|
|
|
|
- 'actual_money' => $actualMoney,
|
|
|
|
|
- 'balance' => $balance,
|
|
|
|
|
- 'create_time' => time(),
|
|
|
|
|
- 'update_time' => time(),
|
|
|
|
|
- 'remark' => "{$coinName}充值",
|
|
|
|
|
- 'status' => 1,
|
|
|
|
|
- 'mark' => 1,
|
|
|
|
|
- ];
|
|
|
|
|
- if(!AccountLogModel::insertGetId($log)){
|
|
|
|
|
- DB::rollBack();
|
|
|
|
|
- $this->error = 2029;
|
|
|
|
|
- RedisService::clear($cacheKey);
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- }else{
|
|
|
|
|
- DB::rollBack();
|
|
|
|
|
- $this->error = 1021;
|
|
|
|
|
- RedisService::clear($cacheKey);
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- $title = "{$coinName}充值审核成功通知";
|
|
|
|
|
- $message = "您的充值申请在{$dateTime}UTC+8审核成功,明细如下:\n单号:{$info['order_no']}\n账户:{$accountName}\n金额:{$money}\n到账:{$actualMoney}\n审核状态:成功\n审核说明:{$remark}";
|
|
|
|
|
-
|
|
|
|
|
- }else{
|
|
|
|
|
- $title = "{$coinName}充值审核失败通知";
|
|
|
|
|
- $message = "您的充值申请在{$dateTime}UTC+8审核失败,明细如下:\n单号:{$info['order_no']}\n账户:{$accountName}\n金额:{$money}\n到账:{$actualMoney}\n审核状态:未通过\n审核说明:{$remark}";
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 消息通知
|
|
|
|
|
- MessageService::make()->pushMessage($userId, $title, $message, 3);
|
|
|
|
|
-
|
|
|
|
|
- DB::commit();
|
|
|
|
|
- $this->error = 1071;
|
|
|
|
|
- RedisService::clear($cacheKey);
|
|
|
|
|
- ActionLogModel::setTitle("充值审核");
|
|
|
|
|
- ActionLogModel::record();
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
* 提现审核
|
|
* 提现审核
|
|
|
* @param $params
|
|
* @param $params
|
|
|
* @return bool
|
|
* @return bool
|