|
@@ -12,8 +12,14 @@
|
|
|
namespace App\Services\Common;
|
|
namespace App\Services\Common;
|
|
|
|
|
|
|
|
use App\Models\AcceptorModel;
|
|
use App\Models\AcceptorModel;
|
|
|
|
|
+use App\Models\AccountLogModel;
|
|
|
use App\Models\BalanceLogModel;
|
|
use App\Models\BalanceLogModel;
|
|
|
|
|
+use App\Models\MerchantModel;
|
|
|
|
|
+use App\Services\Api\FinanceService;
|
|
|
|
|
+use App\Services\Api\MessageService;
|
|
|
use App\Services\BaseService;
|
|
use App\Services\BaseService;
|
|
|
|
|
+use App\Services\WalletService;
|
|
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 承兑商管理-服务类
|
|
* 承兑商管理-服务类
|
|
@@ -39,101 +45,101 @@ class BalanceLogService extends BaseService
|
|
|
* @param int $pageSize 分页大小:默认 15
|
|
* @param int $pageSize 分页大小:默认 15
|
|
|
* @return array
|
|
* @return array
|
|
|
*/
|
|
*/
|
|
|
- public function getDataList($params, $pageSize = 10, $field=[])
|
|
|
|
|
|
|
+ public function getDataList($params, $pageSize = 10, $field = [])
|
|
|
{
|
|
{
|
|
|
$where = ['a.mark' => 1];
|
|
$where = ['a.mark' => 1];
|
|
|
$query = $this->model->with(['member'])
|
|
$query = $this->model->with(['member'])
|
|
|
->from('balance_logs as a')
|
|
->from('balance_logs as a')
|
|
|
- ->leftJoin('member as b','b.id','a.user_id')
|
|
|
|
|
|
|
+ ->leftJoin('member as b', 'b.id', 'a.user_id')
|
|
|
->where($where)
|
|
->where($where)
|
|
|
->select($field ? $field : ['a.*']);
|
|
->select($field ? $field : ['a.*']);
|
|
|
|
|
|
|
|
if (isset($params['keyword']) && $params['keyword'] != '') {
|
|
if (isset($params['keyword']) && $params['keyword'] != '') {
|
|
|
- $query->where(function($query) use($params){
|
|
|
|
|
- $kw = isset($params['keyword'])? trim($params['keyword']) : '';
|
|
|
|
|
- if($kw){
|
|
|
|
|
- $query->where('b.nickname','like',"%{$params['keyword']}%")->orWhere('b.realname','like',"%{$params['keyword']}%")->orWhere('b.username','like',"%{$params['keyword']}%");
|
|
|
|
|
|
|
+ $query->where(function ($query) use ($params) {
|
|
|
|
|
+ $kw = isset($params['keyword']) ? trim($params['keyword']) : '';
|
|
|
|
|
+ if ($kw) {
|
|
|
|
|
+ $query->where('b.nickname', 'like', "%{$params['keyword']}%")->orWhere('b.realname', 'like', "%{$params['keyword']}%")->orWhere('b.username', 'like', "%{$params['keyword']}%");
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (isset($params['order_no']) && $params['order_no'] != '') {
|
|
if (isset($params['order_no']) && $params['order_no'] != '') {
|
|
|
- $query->where('a.order_no','like',"%{$params['order_no']}%");
|
|
|
|
|
|
|
+ $query->where('a.order_no', 'like', "%{$params['order_no']}%");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (isset($params['user_type'])) {
|
|
if (isset($params['user_type'])) {
|
|
|
- if(is_array($params['user_type'])){
|
|
|
|
|
- $query->whereIn('a.type',$params['user_type']);
|
|
|
|
|
- }else{
|
|
|
|
|
- if($params['user_type'] != ''){
|
|
|
|
|
- $query->where('a.user_type',$params['user_type']);
|
|
|
|
|
|
|
+ if (is_array($params['user_type'])) {
|
|
|
|
|
+ $query->whereIn('a.type', $params['user_type']);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if ($params['user_type'] != '') {
|
|
|
|
|
+ $query->where('a.user_type', $params['user_type']);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (isset($params['type'])) {
|
|
if (isset($params['type'])) {
|
|
|
- if(is_array($params['type'])){
|
|
|
|
|
- $query->whereIn('a.type',$params['type']);
|
|
|
|
|
- }else{
|
|
|
|
|
- if($params['type'] != ''){
|
|
|
|
|
- $query->where('a.type',$params['type']);
|
|
|
|
|
|
|
+ if (is_array($params['type'])) {
|
|
|
|
|
+ $query->whereIn('a.type', $params['type']);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if ($params['type'] != '') {
|
|
|
|
|
+ $query->where('a.type', $params['type']);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (isset($params['pay_type'])) {
|
|
if (isset($params['pay_type'])) {
|
|
|
- if(is_array($params['pay_type'])){
|
|
|
|
|
- $query->whereIn('a.pay_type',$params['pay_type']);
|
|
|
|
|
- }else{
|
|
|
|
|
- if($params['pay_type'] != ''){
|
|
|
|
|
- $query->where('a.pay_type',$params['pay_type']);
|
|
|
|
|
|
|
+ if (is_array($params['pay_type'])) {
|
|
|
|
|
+ $query->whereIn('a.pay_type', $params['pay_type']);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if ($params['pay_type'] != '') {
|
|
|
|
|
+ $query->where('a.pay_type', $params['pay_type']);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (isset($params['pay_status'])) {
|
|
if (isset($params['pay_status'])) {
|
|
|
- if(is_array($params['pay_status'])){
|
|
|
|
|
- $query->whereIn('a.pay_status',$params['pay_status']);
|
|
|
|
|
- }else{
|
|
|
|
|
- if($params['pay_status'] != ''){
|
|
|
|
|
- $query->where('a.pay_status',$params['pay_status']);
|
|
|
|
|
|
|
+ if (is_array($params['pay_status'])) {
|
|
|
|
|
+ $query->whereIn('a.pay_status', $params['pay_status']);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if ($params['pay_status'] != '') {
|
|
|
|
|
+ $query->where('a.pay_status', $params['pay_status']);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (isset($params['coin_type'])) {
|
|
if (isset($params['coin_type'])) {
|
|
|
- if(is_array($params['coin_type'])){
|
|
|
|
|
- $query->whereIn('a.coin_type',$params['coin_type']);
|
|
|
|
|
- }else{
|
|
|
|
|
- if($params['coin_type'] != ''){
|
|
|
|
|
- $query->where('a.coin_type',$params['coin_type']);
|
|
|
|
|
|
|
+ if (is_array($params['coin_type'])) {
|
|
|
|
|
+ $query->whereIn('a.coin_type', $params['coin_type']);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if ($params['coin_type'] != '') {
|
|
|
|
|
+ $query->where('a.coin_type', $params['coin_type']);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (isset($params['status'])) {
|
|
if (isset($params['status'])) {
|
|
|
- if(is_array($params['status'])){
|
|
|
|
|
- $query->whereIn('a.status',$params['status']);
|
|
|
|
|
- }else{
|
|
|
|
|
- if($params['status'] != ''){
|
|
|
|
|
- $query->where('a.status',$params['status']);
|
|
|
|
|
|
|
+ if (is_array($params['status'])) {
|
|
|
|
|
+ $query->whereIn('a.status', $params['status']);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if ($params['status'] != '') {
|
|
|
|
|
+ $query->where('a.status', $params['status']);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$list = $query->paginate($pageSize > 0 ? $pageSize : 9999999);
|
|
$list = $query->paginate($pageSize > 0 ? $pageSize : 9999999);
|
|
|
$list = $list ? $list->toArray() : [];
|
|
$list = $list ? $list->toArray() : [];
|
|
|
- if($list){
|
|
|
|
|
- foreach($list['data'] as &$item){
|
|
|
|
|
- $item['create_time_text'] = $item['create_time']? datetime($item['create_time']):'';
|
|
|
|
|
|
|
+ if ($list) {
|
|
|
|
|
+ foreach ($list['data'] as &$item) {
|
|
|
|
|
+ $item['create_time_text'] = $item['create_time'] ? datetime($item['create_time']) : '';
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
return [
|
|
return [
|
|
|
- 'pageSize'=> $pageSize,
|
|
|
|
|
- 'total'=>isset($list['total'])? $list['total'] : 0,
|
|
|
|
|
- 'list'=> isset($list['data'])? $list['data'] : []
|
|
|
|
|
|
|
+ 'pageSize' => $pageSize,
|
|
|
|
|
+ 'total' => isset($list['total']) ? $list['total'] : 0,
|
|
|
|
|
+ 'list' => isset($list['data']) ? $list['data'] : []
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -147,38 +153,193 @@ class BalanceLogService extends BaseService
|
|
|
{
|
|
{
|
|
|
// 请求参数
|
|
// 请求参数
|
|
|
$data = request()->all();
|
|
$data = request()->all();
|
|
|
- // 头像处理
|
|
|
|
|
- if(isset($data['avatar'])){
|
|
|
|
|
- $avatar = trim($data['avatar']);
|
|
|
|
|
- if (strpos($avatar, "temp")) {
|
|
|
|
|
- $data['avatar'] = save_image($avatar, 'member');
|
|
|
|
|
- } else {
|
|
|
|
|
- $data['avatar'] = str_replace(IMG_URL, "", $data['avatar']);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ $balanceLog = BalanceLogModel::where(['id' => $data['id']])->first();
|
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 提现 审核通过
|
|
|
|
|
+ if ($balanceLog['type'] = 2 && isset($data['status'])) {
|
|
|
|
|
+ if ($data['status'] == 2) {
|
|
|
|
|
+ if ($data['user_type'] == 1) {
|
|
|
|
|
+ // 会员
|
|
|
|
|
+ $this->withdrawMember($data);
|
|
|
|
|
+ } else if ($data['user_type'] == 2) {
|
|
|
|
|
+ // 商家
|
|
|
|
|
+ $this->withdrawMerchat($data);
|
|
|
|
|
+ } else if ($data['user_type'] == 3) {
|
|
|
|
|
+ // 承兑商
|
|
|
|
|
+ $this->withdrawAcceptor($data);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ($data['status'] == 3) {
|
|
|
|
|
+ $money = $data['money'];
|
|
|
|
|
+ $userId = $data['user_id'];
|
|
|
|
|
+ $accountLog = AccountLogModel::where(['source_order_no' => $balanceLog['order_no']])->first();
|
|
|
|
|
+ if ($accountLog) {
|
|
|
|
|
+ AccountLogModel::where(['source_order_no' => $balanceLog])->update([
|
|
|
|
|
+ 'status' => 3,
|
|
|
|
|
+ 'update_time' => time(),
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ $updateData = ['usdt' => DB::raw("usdt - {$money}"), 'update_time' => time()];
|
|
|
|
|
+ if (!MerchantModel::where(['user_id' => $userId, 'mark' => 1])->update($updateData)) {
|
|
|
|
|
+ DB::rollBack();
|
|
|
|
|
+ return message('审核不通过操作失败');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
|
+ DB::rollBack();
|
|
|
|
|
+ return message('操作失败');
|
|
|
}
|
|
}
|
|
|
|
|
+ DB::commit();
|
|
|
|
|
+ return parent::edit($data); // TODO: Change the autogenerated stub
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function withdrawMember(array $data)
|
|
|
|
|
+ {
|
|
|
|
|
+ $trcUrl = $data['trc_url'];
|
|
|
|
|
+ $realUsdt = $data['actual_money'];
|
|
|
|
|
+ $orderNo = $data['order_no'];
|
|
|
|
|
+ $userType = $data['user_type'];
|
|
|
|
|
+ $dateTime = $dateTime = date('Y-m-d H:i:s');
|
|
|
|
|
+ $money = $data['money'];
|
|
|
|
|
+ $userId = $data['user_id'];
|
|
|
|
|
+ $fee = $data['fee'];
|
|
|
|
|
+ // 打款处理
|
|
|
|
|
+ $result = WalletService::make()->usdtTrcTransfer($trcUrl, $realUsdt);
|
|
|
|
|
+ $txID = isset($result['txId']) ? $result['txId'] : '';
|
|
|
|
|
+ $payAddress = isset($result['address']) ? $result['address'] : '';
|
|
|
|
|
+ if ($txID && $payAddress) {
|
|
|
|
|
+ $updateData = ['hash' => $txID, 'wallet_url' => $payAddress, 'audit_remark' => '审核打款', 'status' => 2, 'update_time' => time()];
|
|
|
|
|
+ if (BalanceLogModel::where(['order_no' => $orderNo, 'user_type' => $userType])->update($updateData)) {
|
|
|
|
|
+ $title = $userType == 1 ? 'USDT余额提现审核成功' : '商户余额提现审核成功';
|
|
|
|
|
+ $message = $userType == 1 ? "您在{$dateTime}(UTC+8)申请提现{$money}USDT余额审核成功,请耐心等候打款到账!!!" : "您在{$dateTime}(UTC+8)申请提现{$money}USDT商户余额审核成功,请耐心等候打款到账!!!";
|
|
|
|
|
+ MessageService::make()->pushMessage($userId, $title, $message);
|
|
|
|
|
+ AccountLogModel::where(['source_order_no' => $orderNo])->update(['hash' => $txID, 'update_time' => time()]);
|
|
|
|
|
+
|
|
|
|
|
+ // 平台明细
|
|
|
|
|
+ $log = [
|
|
|
|
|
+ 'user_id' => 0,
|
|
|
|
|
+ 'source_id' => $userId,
|
|
|
|
|
+ 'source_order_no' => $orderNo,
|
|
|
|
|
+ 'type' => 5,
|
|
|
|
|
+ 'coin_type' => 1,
|
|
|
|
|
+ 'user_type' => 4,
|
|
|
|
|
+ 'money' => $fee,
|
|
|
|
|
+ 'actual_money' => $fee,
|
|
|
|
|
+ 'balance' => 0,
|
|
|
|
|
+ 'create_time' => time(),
|
|
|
|
|
+ 'update_time' => time(),
|
|
|
|
|
+ 'hash' => $txID,
|
|
|
|
|
+ 'remark' => "USDT余额提现",
|
|
|
|
|
+ 'status' => 1,
|
|
|
|
|
+ 'mark' => 1,
|
|
|
|
|
+ ];
|
|
|
|
|
|
|
|
- // 出生日期
|
|
|
|
|
- if(isset($data['birthday'])){
|
|
|
|
|
- if ($data['birthday']) {
|
|
|
|
|
- $data['birthday'] = strtotime($data['birthday']);
|
|
|
|
|
|
|
+ AccountLogModel::insertGetId($log);
|
|
|
|
|
+
|
|
|
|
|
+ // 平台流水
|
|
|
|
|
+ FinanceService::make()->saveLog(0, $fee, 1);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function withdrawMerchat(array $data)
|
|
|
|
|
+ {
|
|
|
|
|
+ $trcUrl = $data['trc_url'];
|
|
|
|
|
+ $realUsdt = $data['actual_money'];
|
|
|
|
|
+ $orderNo = $data['order_no'];
|
|
|
|
|
+ $userType = $data['user_type'];
|
|
|
|
|
+ $dateTime = $dateTime = date('Y-m-d H:i:s');
|
|
|
|
|
+ $money = $data['money'];
|
|
|
|
|
+ $userId = $data['user_id'];
|
|
|
|
|
+ $fee = $data['fee'];
|
|
|
|
|
+ // 打款处理
|
|
|
|
|
+ $result = WalletService::make()->usdtTrcTransfer($trcUrl, $realUsdt);
|
|
|
|
|
+ $txID = isset($result['txId']) ? $result['txId'] : '';
|
|
|
|
|
+ $payAddress = isset($result['address']) ? $result['address'] : '';
|
|
|
|
|
+ if ($txID && $payAddress) {
|
|
|
|
|
+ $updateData = ['hash' => $txID, 'wallet_url' => $payAddress, 'audit_remark' => '审核打款', 'status' => 2, 'update_time' => time()];
|
|
|
|
|
+ if (BalanceLogModel::where(['order_no' => $orderNo, 'user_type' => $userType])->update($updateData)) {
|
|
|
|
|
+ $title = $userType == 1 ? 'USDT余额提现审核成功' : '商户余额提现审核成功';
|
|
|
|
|
+ $message = $userType == 1 ? "您在{$dateTime}(UTC+8)申请提现{$money}USDT余额审核成功,请耐心等候打款到账!!!" : "您在{$dateTime}(UTC+8)申请提现{$money}USDT商户余额审核成功,请耐心等候打款到账!!!";
|
|
|
|
|
+ MessageService::make()->pushMessage($userId, $title, $message);
|
|
|
|
|
+ AccountLogModel::where(['source_order_no' => $orderNo])->update(['hash' => $txID, 'update_time' => time()]);
|
|
|
|
|
|
|
|
- // 城市处理
|
|
|
|
|
- if(isset($data['city'])){
|
|
|
|
|
- $city = isset($data['city']) ? $data['city'] : [3];
|
|
|
|
|
- if (!empty($data['city'])) {
|
|
|
|
|
- // 省份
|
|
|
|
|
- $data['province_id'] = $city[0];
|
|
|
|
|
- // 城市
|
|
|
|
|
- $data['city_id'] = $city[1];
|
|
|
|
|
- // 县区
|
|
|
|
|
- $data['district_id'] = $city[2];
|
|
|
|
|
|
|
+ // 平台明细
|
|
|
|
|
+ $log = [
|
|
|
|
|
+ 'user_id' => 0,
|
|
|
|
|
+ 'source_id' => $userId,
|
|
|
|
|
+ 'source_order_no' => $orderNo,
|
|
|
|
|
+ 'type' => 5,
|
|
|
|
|
+ 'coin_type' => 1,
|
|
|
|
|
+ 'user_type' => 4,
|
|
|
|
|
+ 'money' => $fee,
|
|
|
|
|
+ 'actual_money' => $fee,
|
|
|
|
|
+ 'balance' => 0,
|
|
|
|
|
+ 'create_time' => time(),
|
|
|
|
|
+ 'update_time' => time(),
|
|
|
|
|
+ 'hash' => $txID,
|
|
|
|
|
+ 'remark' => "USDT余额提现",
|
|
|
|
|
+ 'status' => 1,
|
|
|
|
|
+ 'mark' => 1,
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ AccountLogModel::insertGetId($log);
|
|
|
|
|
+
|
|
|
|
|
+ // 平台流水
|
|
|
|
|
+ FinanceService::make()->saveLog(0, $fee, 1);
|
|
|
}
|
|
}
|
|
|
- unset($data['city']);
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- return parent::edit($data); // TODO: Change the autogenerated stub
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private function withdrawAcceptor(array $data)
|
|
|
|
|
+ {
|
|
|
|
|
+ $trcUrl = $data['trc_url'];
|
|
|
|
|
+ $realUsdt = $data['actual_money'];
|
|
|
|
|
+ $orderNo = $data['order_no'];
|
|
|
|
|
+ $userType = $data['user_type'];
|
|
|
|
|
+ $dateTime = $dateTime = date('Y-m-d H:i:s');
|
|
|
|
|
+ $money = $data['money'];
|
|
|
|
|
+ $userId = $data['user_id'];
|
|
|
|
|
+ $fee = $data['fee'];
|
|
|
|
|
+ // 打款处理
|
|
|
|
|
+ $result = WalletService::make()->usdtTrcTransfer($trcUrl, $realUsdt);
|
|
|
|
|
+ $txID = isset($result['txId']) ? $result['txId'] : '';
|
|
|
|
|
+ $payAddress = isset($result['address']) ? $result['address'] : '';
|
|
|
|
|
+ if ($txID && $payAddress) {
|
|
|
|
|
+ $updateData = ['hash' => $txID, 'wallet_url' => $payAddress, 'audit_remark' => '审核打款', 'status' => 2, 'update_time' => time()];
|
|
|
|
|
+ if (BalanceLogModel::where(['order_no' => $orderNo, 'user_type' => $userType])->update($updateData)) {
|
|
|
|
|
+ $title = $userType == 1 ? 'USDT余额提现审核成功' : '承兑商余额提现审核成功';
|
|
|
|
|
+ $message = $userType == 1 ? "您在{$dateTime}(UTC+8)申请提现{$money}USDT余额审核成功,请耐心等候打款到账!!!" : "您在{$dateTime}(UTC+8)申请提现{$money}USDT承兑商余额审核成功,请耐心等候打款到账!!!";
|
|
|
|
|
+ MessageService::make()->pushMessage($userId, $title, $message, 3);
|
|
|
|
|
+ AccountLogModel::where(['source_order_no' => $orderNo])->update(['hash' => $txID, 'update_time' => time()]);
|
|
|
|
|
+
|
|
|
|
|
+ // 平台明细
|
|
|
|
|
+ $log = [
|
|
|
|
|
+ 'user_id' => 0,
|
|
|
|
|
+ 'source_id' => $userId,
|
|
|
|
|
+ 'source_order_no' => $orderNo,
|
|
|
|
|
+ 'type' => 5,
|
|
|
|
|
+ 'coin_type' => 1,
|
|
|
|
|
+ 'user_type' => 4,
|
|
|
|
|
+ 'money' => $fee,
|
|
|
|
|
+ 'actual_money' => $fee,
|
|
|
|
|
+ 'balance' => 0,
|
|
|
|
|
+ 'create_time' => time(),
|
|
|
|
|
+ 'update_time' => time(),
|
|
|
|
|
+ 'hash' => $txID,
|
|
|
|
|
+ 'remark' => "USDT余额提现",
|
|
|
|
|
+ 'status' => 1,
|
|
|
|
|
+ 'mark' => 1,
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ AccountLogModel::insertGetId($log);
|
|
|
|
|
+
|
|
|
|
|
+ // 平台流水
|
|
|
|
|
+ FinanceService::make()->saveLog(0, $fee, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|