This commit is contained in:
Hankin 2026-04-23 16:58:16 +08:00
parent 35aa6b24f9
commit 050e0fd41e
4 changed files with 326 additions and 158 deletions

View File

@ -4,6 +4,8 @@ namespace App\Http\Controllers\Server\H5;
use App\Models\AccessRecord;
use App\Models\Server\SaasNotice;
use Exception;
use GuzzleHttp\RequestOptions;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
@ -23,6 +25,7 @@ use App\Models\Server\MerchantTransferLog;
use App\Models\Server\MerchantUser;
use App\Utils\Messenger;
use GuzzleHttp\Client;
use App\Services\LiveAlipayService;
use Illuminate\Support\Facades\DB;
@ -235,7 +238,8 @@ class EarningController extends Controller
'm_user_id' => $merchant_user_id
]);
}
if ($earning_acount->is_banned) throw new \Exception("账号id: {$earning_acount->id}异常");
if ($earning_acount->is_banned)
throw new \Exception("账号id: {$earning_acount->id}异常");
//冻结金额
$frezzing_value = \DB::table('m_advance_earnings')->where('m_id', $merchant_id)->where('m_user_id', $merchant_user_id)->whereNull('deleted_at')->sum('value');
@ -348,9 +352,12 @@ class EarningController extends Controller
$data = [];
// 查询用户的提现余额是否充足
$earning_accounts = MEarningAccount::where('m_user_id', $merchant_user_id)->where('m_id', $merchant_id)->first();
if (!$earning_accounts) return $this->failure('您暂无提现额度');
if ($amount < 0.1) return $this->failure('提现额度有误,请重新输入');
if ($earning_accounts->balance < $amount) return $this->failure('提现额度不足,请重新输入');
if (!$earning_accounts)
return $this->failure('您暂无提现额度');
if ($amount < 0.1)
return $this->failure('提现额度有误,请重新输入');
if ($earning_accounts->balance < $amount)
return $this->failure('提现额度不足,请重新输入');
$poundage = Redis::get('withdrawal_poundage') ?? 2; //提现手续费百分比
$poundage = $amount * ($poundage / 100) >= 0.01 ? $amount * ($poundage / 100) : 0.01;//收取手续费费用 不足1分 按一分处理
$poundage = floor($poundage * 100) / 100;
@ -438,7 +445,7 @@ class EarningController extends Controller
public function withdrawApply(Request $request)
{
try {
// return $this->failure("系统维护中");
return $this->failure("系统维护中");
$merchant_id = $request->merchant_id;
$merchant_user_id = $request->merchant_user_id ?? 0;
$wechatUser = session('wechat.oauth_user.new');
@ -454,12 +461,16 @@ class EarningController extends Controller
$alipay_real_name = $request->name;
//提现多少钱
$amount = $request->amount;
if (!is_numeric($amount) || $amount <= 0) return $this->failure('请输入正确的提现金额');
if ($amount < 1) return $this->failure('单笔提现最低金额为1元');
if (!is_numeric($amount) || $amount <= 0)
return $this->failure('请输入正确的提现金额');
if ($amount < 1)
return $this->failure('单笔提现最低金额为1元');
$earning_account = MEarningAccount::where('m_id', $merchant_id)->where('m_user_id', $merchant_user_id)->first();
if ($earning_account->is_banned) throw new \Exception("账号id: {$earning_account->id}异常");
if ($earning_account->is_banned)
throw new \Exception("账号id: {$earning_account->id}异常");
//查询余额足够?
if ($earning_account->balance < $amount) return $this->failure('提现金额不能大于可以提现的总金额!');
if ($earning_account->balance < $amount)
return $this->failure('提现金额不能大于可以提现的总金额!');
$trade_no = \CommonUtilsService::getTradeNO();
$poundage = Redis::get('withdrawal_poundage') ?? 2; //提现手续费百分比
$poundage = $amount * ($poundage / 100) >= 0.01 ? $amount * ($poundage / 100) : 0.01;//收取手续费费用 不足1分 按一分处理
@ -505,7 +516,8 @@ class EarningController extends Controller
//直接转账
list($res, $error_msg) = $this->transferWithdraw($withdraw);
//失败
if (empty($res)) return $this->success('ok', $error_msg);
if (empty($res))
return $this->success('ok', $error_msg);
//修改账号状态
$earning_account->decrement('frozen_withdraw', $amount);
$earning_account->increment('withdrawl', $amount);
@ -522,6 +534,127 @@ class EarningController extends Controller
}
}
public function withdrawApplyV2(Request $request)
{
try {
// return $this->failure("系统维护中");
$merchant_id = $request->merchant_id;
$merchant_user_id = $request->merchant_user_id ?? 0;
$wechatUser = session('wechat.oauth_user.new');
if ($wechatUser) {
$openid = $wechatUser->getId();
} else {
$openid = MerchantUsers::where('id', $merchant_user_id)->value('openid');
}
$merchant_user = MerchantUser::where('id', $merchant_user_id)->first();
// if ($merchant_user->id != 221) return $this->failure("提现功能维护中,请稍后再试");
$account = $request->account;
$way = $request->way ?? 'alipay';
$alipay_real_name = $request->name;
//提现多少钱
$amount = $request->amount;
if (!is_numeric($amount) || $amount <= 0)
return $this->failure('请输入正确的提现金额');
if ($amount < 1)
return $this->failure('单笔提现最低金额为1元');
$earning_account = MEarningAccount::where('m_id', $merchant_id)->where('m_user_id', $merchant_user_id)->first();
if (empty($earning_account)) {
throw new Exception("账号不存在");
}
if ($earning_account->is_banned)
throw new \Exception("账号id: {$earning_account->id}异常");
//查询余额足够?
if ($earning_account->balance < $amount)
return $this->failure('提现金额不能大于可以提现的总金额!');
$trade_no = \CommonUtilsService::getTradeNO();
$poundage = Redis::get('withdrawal_poundage') ?? 2; //提现手续费百分比
$poundage = $amount * ($poundage / 100) >= 0.01 ? $amount * ($poundage / 100) : 0.01;//收取手续费费用 不足1分 按一分处理
$poundage = floor($poundage * 100) / 100;
$actual_received = $amount - $poundage;//实际到账金额
//处理冻结金额
DB::beginTransaction();
$earning_account->balance = $earning_account->balance - $amount;
$earning_account->frozen_withdraw = $earning_account->frozen_withdraw + $amount;
$insert = ['m_id' => $merchant_id, 'm_user_id' => $merchant_user_id, 'way' => $way, 'real_value' => $actual_received, 'value' => $amount, 'trade_no' => $trade_no, 'account' => $account, 'name' => $alipay_real_name, 'status' => 'freezing'];
$earning_account->save();
$withdraw = MEarningwithdraws::create($insert);
if ($amount >= 500) {
//通知
$data['touser'] = ['oPC_2vudVLVHj2U7dNinr2IEDHR4', 'oPC_2vuTj7YRgUzQQY7PlSJVLBBc'];
$data['template_id'] = 'OwXPF2dKEjPQUoGyzH944ATsJ6SgxpZ8kzB-KVVxanY';
$data['url'] = '';
$data['data'] = [
'first' => 's端用户:' . $alipay_real_name . '刚刚提交了提现申请,请即时处理',
'keyword1' => $amount . '元',
'keyword2' => '提现申请提交',
'keyword3' => '请求提交时间' . date('Y-m-d H:i'),
'keyword4' => '福恋后台审核',
'remark' => '提现申请提交',
];
SendTemplateMsg::dispatch($data)->onQueue('template_message');
$data['touser'] = $openid;
$data['template_id'] = 'OwXPF2dKEjPQUoGyzH944ATsJ6SgxpZ8kzB-KVVxanY';
$data['url'] = '';
$data['data'] = [
'first' => '你已申请提现,正在审核中',
'keyword1' => $alipay_real_name,
'keyword2' => date('Y-m-d H:i:s'),
'keyword3' => $actual_received . '元',
'keyword4' => '支付宝',
'remark' => '审核结果请留意服务通知',
];
SendTemplateMsg::dispatch($data)->onQueue('template_message');
//短信通知
$message = $alipay_real_name . ',你已申请提现,正在审核中,审核结果请留意手机短信,请耐心等待。';
$this->sentMessage($merchant_user->mobile, $message);
} else {
$url = config("app.url") . "/util/api/wechatpay/saas/mch/transfer";
$data = [
"trade_no" => $withdraw->trade_no,
"openid" => $openid,
"amount" => (int) ($withdraw->actual_received * 100),
"remark" => "用户提现",
];
$token = $request->bearerToken();
$header = [
'APPTOKEN' => $token,
'Content-Type' => 'application/json'
];
$options = [
RequestOptions::TIMEOUT => 3,
RequestOptions::HTTP_ERRORS => false,
RequestOptions::HEADERS => $header,
RequestOptions::QUERY => $data,
];
$client = new Client();
$response = $client->post($url, $options);
$content = $response->getBody();
$res = json_decode($content, true);
if ($res && isset($res['code'])) {
if ($res['code']) {
throw new \Exception($res['message']);
}
} else {
throw new \Exception("提现失败");
}
// //修改账号状态
// $earning_account->decrement('frozen_withdraw', $amount);
// $earning_account->increment('withdrawl', $amount);
// $withdraw->update(['status' => 'finished']);
// //成功通知
// $this->sendWithdrawNotice($earning_account, $withdraw);
}
DB::commit();
return $this->success('ok', ['status' => 1]);
} catch (\Exception $e) {
DB::rollBack();
$this->getError($e);
return $this->failure('服务器休息,请稍后再试');
}
}
public function sendWithdrawNotice($account, $withdraw)
{
$openid = MerchantUser::where('id', $account->m_user_id)->value('openid');
@ -588,7 +721,8 @@ class EarningController extends Controller
}
//授权码
public function wechatAuthQrcode(Request $request){
public function wechatAuthQrcode(Request $request)
{
try {
$m_id = $request->merchant_id;
$m_user_id = $request->merchant_user_id;

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class TableMEarningWithdrawsAddPackageInfo extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('m_earning_withdraws', function (Blueprint $table) {
$table->string("package_info", 191)->nullable()->comment("微信转账信息")->after("status");
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('m_earning_withdraws', function (Blueprint $table) {
$table->dropColumn("package_info");
});
}
}

View File

@ -1,6 +1,7 @@
<?php
use App\Http\Controllers\Server\H5\ActivityController;
use App\Http\Controllers\Server\H5\EarningController;
@ -79,7 +80,8 @@ Route::middleware('merchant_user')->group(function () {
Route::post('communities/BindEarningAccounts', 'EarningController@BindEarningAccounts');
// 商户-用户提现
Route::post('communities/UserWithdrawal', 'EarningController@withdrawApply');
// 商户-用户提现(需要用户确认收款)
Route::post("communities/UserWithdrawal/v2", [EarningController::class, "withdrawApplyV2"]);
// ------------------------------- 问答测试 --------------------------