You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.9 KiB
64 lines
1.9 KiB
<?php
|
|
|
|
namespace App\AdminSupplier\Controllers;
|
|
|
|
use App\AdminAgent\Repositories\WithdrawalAlipay;
|
|
use App\Models\Agent;
|
|
use App\Models\Withdrawal;
|
|
use App\Traits\DemandTraits;
|
|
use App\Traits\WithdrawalTraits;
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Http\Controllers\AdminController;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class WithdrawalAlipayController extends AdminController
|
|
{
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new WithdrawalAlipay(), function (Form $form) {
|
|
$form->display('id');
|
|
$form->decimal('price','提现金额')->required();
|
|
$form->text('account')->required();
|
|
$form->text('name')->required();
|
|
$form->image('qrcode')->required();
|
|
$form->hidden('withdrawal_id');
|
|
|
|
$form->saving(function (Form $form) {
|
|
$user = Agent::query()->where('id', Admin::user()->id)->lockForUpdate()->first();
|
|
if ($form->price > $user->balance) {
|
|
return $form->response()->error('余额不足,当前可用余额为'.$user->balance);
|
|
}
|
|
|
|
$user->balance = bcsub($user->balance,$form->price,6);
|
|
$user->save();
|
|
|
|
$withdrawal = new Withdrawal();
|
|
$withdrawal->user_id = Admin::user()->id;
|
|
$withdrawal->user_type = DemandTraits::$col[1];
|
|
$withdrawal->price = request('price',0);
|
|
//$withdrawal->pay_id = $form->getKey();
|
|
$withdrawal->pay_type = WithdrawalTraits::$userType[0];
|
|
$withdrawal->save();
|
|
|
|
$form->withdrawal_id = $withdrawal->id;
|
|
$form->deleteInput('price');
|
|
});
|
|
|
|
$form->saved(function (Form $form) {
|
|
$withdrawal = Withdrawal::find($form->withdrawal_id);
|
|
$withdrawal->pay_id = $form->getKey();
|
|
$withdrawal->save();
|
|
});
|
|
});
|
|
}
|
|
}
|