68 lines
1.6 KiB
PHP
68 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Forms;
|
|
|
|
use App\Services\DistributeService;
|
|
use App\Exceptions\BizException;
|
|
use App\Models\OrderProfit;
|
|
use Dcat\Admin\Contracts\LazyRenderable;
|
|
use Dcat\Admin\Traits\LazyWidget;
|
|
use Dcat\Admin\Widgets\Form;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Throwable;
|
|
|
|
class ProfitSuccessForm extends Form implements LazyRenderable
|
|
{
|
|
use LazyWidget;
|
|
|
|
/**
|
|
* 权限判断,如不需要可以删除此方法
|
|
*
|
|
* @param Model|Authenticatable|HasPermissions|null $user
|
|
*
|
|
* @return bool
|
|
*/
|
|
protected function authorize($user): bool
|
|
{
|
|
return $user->can('dcat.admin.profit.pay');
|
|
}
|
|
|
|
/**
|
|
* Handle the form request.
|
|
*
|
|
* @param array $input
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle(array $input)
|
|
{
|
|
$order = OrderProfit::findOrFail($this->payload['id']);
|
|
$service = new DistributeService();
|
|
try {
|
|
DB::beginTransaction();
|
|
$service->success($order, $input);
|
|
DB::commit();
|
|
} catch (Throwable $th) {
|
|
DB::rollBack();
|
|
report($th);
|
|
throw new BizException('操作失败:'.$th->getMessage());
|
|
}
|
|
return $this->response()->success('操作成功')->refresh();
|
|
}
|
|
|
|
/**
|
|
* Build a form here.
|
|
*/
|
|
public function form()
|
|
{
|
|
$order = OrderProfit::findOrFail($this->payload['id']);
|
|
|
|
$this->datetime('paid_at')->value(now());
|
|
$this->text('pay_way');
|
|
$this->text('pay_no');
|
|
$this->text('remarks')->value($order->remark);
|
|
|
|
$this->disableResetButton();
|
|
}
|
|
}
|