海南旅游SAAS
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

<?php
namespace App\AdminSupplier\Controllers;
use App\AdminSupplier\Repositories\WithdrawalBank;
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;
class WithdrawalBankController extends AdminController
{
/**
* Make a form builder.
*
* @return Form
*/
protected function form()
{
return Form::make(new WithdrawalBank(), function (Form $form) {
$form->display('id');
$form->decimal('price','提现金额')->required()->maxLength(50);
$form->text('name')->required()->maxLength(50);
$form->text('card_number')->required()->maxLength(50)->type('number');
$form->text('account_name')->required()->maxLength(50);
$form->text('branch')->required()->maxLength(100);
$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[1];
$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();
});
});
}
}