70 lines
1.8 KiB
PHP
70 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Forms;
|
|
|
|
use App\Enums\DealerWalletAction;
|
|
use App\Enums\DealerWalletToBankLogStatus;
|
|
use App\Models\DealerWalletToBankLog;
|
|
use App\Services\Dealer\WalletService;
|
|
use Dcat\Admin\Contracts\LazyRenderable;
|
|
use Dcat\Admin\Traits\LazyWidget;
|
|
use Dcat\Admin\Widgets\Form;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Throwable;
|
|
|
|
class DealerWalletRefuse 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::findOrFail($id);
|
|
$log->update([
|
|
'remark' => $input['remark'] ?? '',
|
|
'status' => DealerWalletToBankLogStatus::Refused,
|
|
]);
|
|
//打回余额
|
|
$walletService = new WalletService();
|
|
$walletService->changeBalance($log->user, $log->amount, DealerWalletAction::WithdrawFiled, '提现-失败', $log);
|
|
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->text('remarks', '备注')->required();
|
|
}
|
|
}
|