transfer
This commit is contained in:
parent
dede1c501a
commit
8bed8714ce
@ -1,174 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Facades\AlipayService;
|
||||
use App\Facades\WechatPayService;
|
||||
use App\Http\Response\ResponseJson;
|
||||
use App\Models\Live\Anchor;
|
||||
use App\Models\Server\MEarningAccount;
|
||||
use App\Models\Server\MEarningwithdraws;
|
||||
use App\Models\Server\MerchantAccount;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class EarningController
|
||||
{
|
||||
use ResponseJson;
|
||||
public function auditWithdraw(Request $request, $id)
|
||||
{
|
||||
try {
|
||||
$admin_id = auth()->id();
|
||||
$log = MEarningwithdraws::where('id', $id)->where('status', 'freezing')->first();
|
||||
if (empty($log))
|
||||
return $this->failure('该记录不存在或已被其他管理员审核');
|
||||
//获取该商户的收益账号
|
||||
$account = MEarningAccount::where('m_id', $log->m_id)->where('m_user_id', 0)->first();
|
||||
$balance = $account->balance;//账户余额
|
||||
$frozen_withdraw = $account->frozen_withdraw;//账户冻结提现金额
|
||||
//如果当前用户冻结提现金额 小于 本次提现金额
|
||||
if ($frozen_withdraw < $log->value)
|
||||
return $this->failure('当前账户异常,联系开发人员处理');
|
||||
$anchor = Anchor::where('m_id', $log->m_id)->first();
|
||||
$openid = MerchantAccount::where('id', $log->m_id)->value('openid');//商家openid
|
||||
if (empty($openid))
|
||||
$openid = $anchor->openid;
|
||||
if ($log->way == 'alipay') {
|
||||
$transfer_way = '支付宝';
|
||||
} elseif ($log->way == 'weixin') {
|
||||
$transfer_way = '微信';
|
||||
} elseif ($log->way == 'bank') {
|
||||
$transfer_way = '银行卡';
|
||||
}
|
||||
$status = $request->status;
|
||||
if (!in_array($status, ['finished', 'canceled', 'manual']))
|
||||
throw new \Exception("提供审核参数有误", 1);
|
||||
$url = '';
|
||||
DB::beginTransaction();
|
||||
switch ($status) {
|
||||
case 'finished': //审核通过
|
||||
if ($log->way == 'alipay') {
|
||||
$data = [];
|
||||
$data['remark'] = '提现已到账'; //提现备注
|
||||
$data['out_biz_no'] = $log->trade_no;
|
||||
$data['amount'] = $log->real_value;//实际到账金额
|
||||
$data['payee_account'] = $log->account;//支付宝账号
|
||||
$data['payee_real_name'] = $log->name;//支付宝绑定姓名
|
||||
if ($log->alipay_id)
|
||||
$data['payee_account'] = $log->alipay_id;
|
||||
if ($log->alipay_id) {//通过支付宝id打款
|
||||
$result = AlipayService::UserTransferAccount($data);
|
||||
} else {//通过支付宝账号和名字打款
|
||||
$result = AlipayService::platTransferAccount($data);
|
||||
}
|
||||
} elseif ($log->way == 'weixin') {
|
||||
$result = WechatPayService::officialUserTransfer($log->trade_no, $log->account, $log->real_value * 100, '提现已到账');
|
||||
} elseif ($log->way == 'bank') {
|
||||
$result = WechatPayService::bankTransfer($log->trade_no, $log->account, $log->name, $log->bank_code, $log->real_value * 100, '打款至个人银行卡');
|
||||
}
|
||||
//\Log::info($result);
|
||||
//判断打款是否成功
|
||||
if (is_array($result)) {//失败
|
||||
//\Log::info('打款失败');
|
||||
$err_msg = isset($result['msg']) ? $result['msg'] : $result['err_code_des'];
|
||||
return $this->failure($err_msg);
|
||||
$log->update(['status' => 'canceled', 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s'), 'err_msg' => $err_msg]);
|
||||
$account->update(['frozen_withdraw' => $frozen_withdraw - $log->value, 'balance' => $balance + $log->value]);
|
||||
// 短信通知 邓智锋
|
||||
$mobile = '15707534403';
|
||||
$message = '商户' . $anchor->name . ' 提现' . $log->real_value . '元失败,原因:' . $err_msg;
|
||||
$this->sentMessage($mobile, $message);
|
||||
//模板通知 邓智锋
|
||||
$data['touser'] = ['oPC_2vnSECnYp5p--uaq3rca3Ry0', 'oPC_2vpJd34uN2E1tTsFbf8Lhlcs'];
|
||||
$data['template_id'] = 'AqwVt0liVmQfzfnX3ZGvmVOdOh62nkCbhlOUI0NVQGs';
|
||||
$data['url'] = $url;
|
||||
$data['data'] = [
|
||||
'first' => '商户' . $anchor->name . '提现失败',
|
||||
'keyword1' => $log->real_value . '元',
|
||||
'keyword2' => $transfer_way,
|
||||
'keyword3' => $err_msg,
|
||||
'remark' => '点击查看提现记录',
|
||||
];
|
||||
SendTemplateMsg::dispatch($data)->onQueue('template_message');
|
||||
//短信通知
|
||||
$message = $anchor->name . ',提现' . $log->real_value . '元失败,具体原因请查看你的后台系统的提现反馈。';
|
||||
$this->sentMessage($anchor->mobile, $message);
|
||||
DB::commit();
|
||||
return $this->failure($err_msg);
|
||||
} else {//成功
|
||||
//\Log::info('打款成功');
|
||||
$log->update(['status' => 'finished', 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s')]);
|
||||
//将冻结提现金额 换成已提现金额 //冻结提现金额 0
|
||||
$account->withdrawl = $account->withdrawl + $log->value;
|
||||
$account->frozen_withdraw = $account->frozen_withdraw - $log->value;
|
||||
$account->save();
|
||||
//模板通知
|
||||
$data['touser'] = $openid;
|
||||
$data['template_id'] = 'aV4ic7jr5bOlf55CgR0jmMsFYyhdRAiVmqqXEjnUqQU';
|
||||
$data['url'] = $url;
|
||||
$data['data'] = [
|
||||
'first' => '提现已到账,请在' . $transfer_way . '查收',
|
||||
'keyword1' => $log->real_value . '元',
|
||||
'keyword2' => date('Y-m-d H:i:s'),
|
||||
'keyword3' => '提现到' . $transfer_way . '余额',
|
||||
'remark' => '感谢您的的使用',
|
||||
];
|
||||
SendTemplateMsg::dispatch($data)->onQueue('template_message');
|
||||
//短信通知
|
||||
$message = $anchor->name . ',提现金额' . $log->real_value . '元已到账,请在' . $transfer_way . '查收。';
|
||||
$this->sentMessage($anchor->mobile, $message);
|
||||
}
|
||||
break;
|
||||
case 'canceled': //审核拒绝
|
||||
$reason = $request->reason;
|
||||
if (!$reason)
|
||||
return $this->failure('请输入拒绝理由');
|
||||
$account->update(['frozen_withdraw' => $frozen_withdraw - $log->value, 'balance' => $balance + $log->value]);
|
||||
$log->update(['status' => $status, 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s'), 'err_msg' => $request->reason]);
|
||||
$data['touser'] = $openid;
|
||||
$data['template_id'] = 'AqwVt0liVmQfzfnX3ZGvmVOdOh62nkCbhlOUI0NVQGs';
|
||||
$data['url'] = $url;
|
||||
$data['data'] = [
|
||||
'first' => '商户' . $anchor->name . '提现失败',
|
||||
'keyword1' => $log->real_value . '元',
|
||||
'keyword2' => $transfer_way,
|
||||
'keyword3' => $reason,
|
||||
'remark' => '账号信息存在异常',
|
||||
];
|
||||
$message = $anchor->name . ',提现' . $log->real_value . '元失败,失败原因:' . $reason . ',具体原因请查看你的后台系统的提现反馈。';
|
||||
$this->sentMessage($anchor->mobile, $message);
|
||||
SendTemplateMsg::dispatch($data)->onQueue('template_message');
|
||||
break;
|
||||
case 'manual': //手工处理
|
||||
//\Log::info('打款已经由人工处理');
|
||||
// $log->update(['status' => 'finished', 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s'), 'way' => 'manual']);
|
||||
// //将冻结提现金额 换成已提现金额 //冻结提现金额 0
|
||||
// $account->withdrawl = $account->withdrawl + $log->value;
|
||||
// $account->frozen_withdraw = $account->frozen_withdraw - $log->value;
|
||||
// $account->save();
|
||||
// //模板通知用户
|
||||
// $data['touser'] = ['oPC_2vudVLVHj2U7dNinr2IEDHR4', 'oPC_2vuTj7YRgUzQQY7PlSJVLBBc'];
|
||||
// $data['template_id'] = 'OwXPF2dKEjPQUoGyzH944ATsJ6SgxpZ8kzB-KVVxanY';
|
||||
// $data['url'] = $url;
|
||||
// $data['data'] = [
|
||||
// 'first' => '商户:' . $anchor->name . '提现人工审核通过,处理方式:手工打款,请即时处理',
|
||||
// 'keyword1' => $anchor->name,
|
||||
// 'keyword2' => date('Y-m-d H:i:s'),
|
||||
// 'keyword3' => $log->real_value . '元',
|
||||
// 'keyword4' => '手动打款处理',
|
||||
// 'remark' => '提现人工审核通过,处理方式:手工打款',
|
||||
// ];
|
||||
// SendTemplateMsg::dispatch($data)->onQueue('template_message');
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
DB::commit();
|
||||
return $this->success('审核完成');
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
$this->getError($e);
|
||||
return $this->failure('审核失败,请联系开发人员');
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -15,15 +15,15 @@ class Controller extends BaseController
|
||||
|
||||
public function test()
|
||||
{
|
||||
$trade_no1 = UtilService::getTradeNo();
|
||||
$trade_no2 = UtilService::getTradeNo();
|
||||
// $trade_no1 = UtilService::getTradeNo();
|
||||
// $trade_no2 = UtilService::getTradeNo();
|
||||
|
||||
$scene_id = config("wechatpay.screen.commission");
|
||||
$openid = "oPC_2vneOWpQbicNZQAUCxuwZ4mw";
|
||||
$amount = 10;
|
||||
$remark = "测试";
|
||||
// $res = WechatPayService::transferBatches($trade_no1, $trade_no2, $openid, $amount, $remark);
|
||||
$res = WechatPayService::mchTransfer($trade_no1, $scene_id, $openid, $amount, $remark);
|
||||
dd($res);
|
||||
// $scene_id = config("wechatpay.screen.commission");
|
||||
// $openid = "oPC_2vneOWpQbicNZQAUCxuwZ4mw";
|
||||
// $amount = 10;
|
||||
// $remark = "测试";
|
||||
// // $res = WechatPayService::transferBatches($trade_no1, $trade_no2, $openid, $amount, $remark);
|
||||
// $res = WechatPayService::mchTransfer($trade_no1, $scene_id, $openid, $amount, $remark);
|
||||
// dd($res);
|
||||
}
|
||||
}
|
||||
|
||||
26
app/Http/Controllers/WechatPayController.php
Normal file
26
app/Http/Controllers/WechatPayController.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Facades\WechatPayService;
|
||||
use App\Http\Response\ResponseJson;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class WechatPayController extends Controller
|
||||
{
|
||||
use ResponseJson;
|
||||
function mchTransfer(Request $request)
|
||||
{
|
||||
$trade_no = $request->trade_no;
|
||||
$scene_id = $request->scene_id;
|
||||
if (empty($scene_id)) {
|
||||
$scene_id = config("wechatpay.screen.commission");
|
||||
}
|
||||
$openid = $request->openid;
|
||||
$amount = $request->amount;
|
||||
$remark = $request->remark;
|
||||
$res = WechatPayService::mchTransfer($trade_no, $scene_id, $openid, $amount, $remark, []);
|
||||
|
||||
return $this->success("ok", $res);
|
||||
}
|
||||
}
|
||||
@ -64,6 +64,6 @@ class Kernel extends HttpKernel
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
'merchant' => \App\Http\Middleware\CheckMerchant::class,
|
||||
|
||||
'merchant_user' => \App\Http\Middleware\CheckMerchantUser::class,
|
||||
];
|
||||
}
|
||||
|
||||
52
app/Http/Middleware/CheckMerchantUser.php
Normal file
52
app/Http/Middleware/CheckMerchantUser.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CheckMerchantUser
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
try {
|
||||
$token = $request->bearerToken();
|
||||
$result = decrypt($token);
|
||||
if (!$result)
|
||||
return $this->fail('验证失败,请重新登录', 2);
|
||||
$key = explode('-', $result);
|
||||
if (time() - $key[2] > 60480000)
|
||||
return $this->fail('请重新登录', 2);
|
||||
if ($key[0]) {
|
||||
$request->merchant_user_id = $key[0];
|
||||
return $next($request);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail('信息有误,请重新登录', 2);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
|
||||
//接口返回失败
|
||||
public function fail($msg, $code = 5, $path = '', $operate = '', $notice = '')
|
||||
{
|
||||
$result = [
|
||||
'code' => $code,
|
||||
'path' => $path,
|
||||
'message' => $msg,
|
||||
'operate' => $operate,
|
||||
'notice' => $notice,
|
||||
];
|
||||
|
||||
return Response()->json($result);
|
||||
}
|
||||
}
|
||||
@ -39,6 +39,10 @@ class RouteServiceProvider extends ServiceProvider
|
||||
Route::middleware('api')
|
||||
->prefix("util/api")
|
||||
->group(base_path('routes/util/api.php'));
|
||||
|
||||
Route::middleware('api')
|
||||
->prefix("api/wechatpay")
|
||||
->group(base_path('routes/pay/wechat.php'));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -91,17 +91,17 @@ class WechatPayService
|
||||
"json" => $data
|
||||
]);
|
||||
$res = json_decode($resp->getBody(), true);
|
||||
dd($res);
|
||||
return ["code" => 0, "err_msg" => "", "data" => $res];
|
||||
} catch (\Exception $e) {
|
||||
// 进行异常捕获并进行错误判断处理
|
||||
Log::info($e->getMessage());
|
||||
if ($e instanceof \GuzzleHttp\Exception\RequestException && $e->hasResponse()) {
|
||||
$r = $e->getResponse();
|
||||
$res = json_decode($r->getBody());
|
||||
return ["code" => 1, "err_msg" => $r->getBody()];
|
||||
return ["code" => 1, "err_msg" => $r->getBody(), "data" => null];
|
||||
}
|
||||
|
||||
return ["code" => 1, "err_msg" => $e->getMessage()];
|
||||
return ["code" => 1, "err_msg" => $e->getMessage(), "data" => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
6
routes/pay/wechat.php
Normal file
6
routes/pay/wechat.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Controllers\WechatPayController;
|
||||
|
||||
//发起转账
|
||||
Route::post('saas/mch/transfer', [WechatPayController::class, "mchTransfer"])->middleware('merchant_user');
|
||||
@ -1,3 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Controllers\Admin\EarningController;
|
||||
use App\Http\Controllers\CommonController;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
@ -10,12 +9,6 @@ Route::prefix("upload")->group(function () {
|
||||
Route::match(["get", "post"], '/ueditor', [CommonController::class, "upload"]);
|
||||
});
|
||||
|
||||
//微信转账
|
||||
Route::prefix("transfer")->group(function () {
|
||||
//saas端提现审核
|
||||
Route::put('saas/withdraw/{id}/audit/transfer', [EarningController::class, "auditWithdraw"])->where('id', '[0-9]+');
|
||||
|
||||
});
|
||||
|
||||
Route::get("test", [Controller::class, "test"]);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user