90 lines
2.5 KiB
PHP
90 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Forms;
|
|
|
|
use App\Enums\DealerWalletToBankLogPayWay;
|
|
use App\Enums\DealerWalletToBankLogStatus;
|
|
use App\Exceptions\BizException;
|
|
use App\Models\DealerWalletToBankLog;
|
|
use Carbon\Carbon;
|
|
use Dcat\Admin\Contracts\LazyRenderable;
|
|
use Dcat\Admin\Traits\LazyWidget;
|
|
use Dcat\Admin\Widgets\Form;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Throwable;
|
|
|
|
class DealerWalletPay extends Form implements LazyRenderable
|
|
{
|
|
use LazyWidget;
|
|
|
|
/**
|
|
* @param Model|Authenticatable|HasPermissions|null $user
|
|
*
|
|
* @return bool
|
|
*/
|
|
protected function authorize($user): bool
|
|
{
|
|
return $user->can('dcat.admin.dealer_wallet_to_bank_logs.verify');
|
|
}
|
|
|
|
/**
|
|
* Handle the form request.
|
|
*
|
|
* @param array $input
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle(array $input)
|
|
{
|
|
$id = $this->payload['id'] ?? 0;
|
|
|
|
try {
|
|
DB::beginTransaction();
|
|
|
|
$log = DealerWalletToBankLog::lockForUpdate()->findOrFail($id);
|
|
|
|
if (! in_array($log->status, [DealerWalletToBankLogStatus::Pending, DealerWalletToBankLogStatus::Failed])) {
|
|
throw new BizException('提现记录状态异常');
|
|
}
|
|
|
|
$log->pay_info = $log->user->dealer->pay_info;
|
|
$log->pay_image = $input['pay_image'] ?? null;
|
|
$log->pay_way = $input['pay_way'];
|
|
if ($log->pay_way == DealerWalletToBankLogPayWay::Offline) {
|
|
$log->pay_at = now();
|
|
$log->status = DealerWalletToBankLogStatus::Success;
|
|
} else {
|
|
$log->pay_sn = serial_number();
|
|
$log->status = DealerWalletToBankLogStatus::Passed;
|
|
}
|
|
$log->save();
|
|
|
|
DB::commit();
|
|
} catch (Throwable $th) {
|
|
DB::rollBack();
|
|
report($th);
|
|
return $this->response()->error('操作失败:'.$th->getMessage());
|
|
}
|
|
|
|
return $this->response()
|
|
->success(__('admin.update_succeeded'))
|
|
->refresh();
|
|
}
|
|
|
|
/**
|
|
* Build a form here.
|
|
*/
|
|
public function form()
|
|
{
|
|
$this->hidden('pay_way')->value(DealerWalletToBankLogPayWay::Offline->value);
|
|
// $this->select('pay_way')
|
|
// ->options(DealerWalletToBankLogPayWay::texts())
|
|
// ->required();
|
|
$this->image('pay_image')
|
|
->move('dealer-pay/'.Carbon::now()->toDateString())
|
|
->saveFullUrl()
|
|
->removable(false)
|
|
->autoUpload();
|
|
}
|
|
}
|