78 lines
1.8 KiB
PHP
78 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Forms;
|
|
|
|
use App\Enums\DealerWalletAction;
|
|
use App\Models\Dealer;
|
|
use App\Services\Dealer\WalletService;
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Contracts\LazyRenderable;
|
|
use Dcat\Admin\Traits\LazyWidget;
|
|
use Dcat\Admin\Widgets\Form;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Throwable;
|
|
|
|
class DealerWalletRecharge extends Form implements LazyRenderable
|
|
{
|
|
use LazyWidget;
|
|
|
|
/**
|
|
* @param Model|Authenticatable|HasPermissions|null $user
|
|
*
|
|
* @return bool
|
|
*/
|
|
protected function authorize($user): bool
|
|
{
|
|
return $user->can('dcat.admin.dealers.wallet_recharge');
|
|
}
|
|
|
|
/**
|
|
* Handle the form request.
|
|
*
|
|
* @param array $input
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle(array $input)
|
|
{
|
|
if (($input['change_balance'] ?? 0) <= 0) {
|
|
return $this->response()->error('充值金额必须大于0');
|
|
}
|
|
|
|
$dealer = Dealer::findOrFail($this->payload['id']);
|
|
|
|
try {
|
|
DB::beginTransaction();
|
|
|
|
(new WalletService())->changeBalance(
|
|
$dealer->user,
|
|
$input['change_balance'],
|
|
DealerWalletAction::Recharge,
|
|
'充值',
|
|
Admin::user()
|
|
);
|
|
|
|
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->currency('change_balance', '充值金额')->symbol('¥')->required();
|
|
$this->confirm('是否确认充值?', '提交后该动作无法逆转');
|
|
}
|
|
}
|