81 lines
2.1 KiB
PHP
81 lines
2.1 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;
|
|
use App\Enums\PayWay;
|
|
|
|
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();
|
|
if ($input['pay_way'] === PayWay::WxpayTransfer->value && !$order->pay_no) {
|
|
$order->update([
|
|
'pay_no' => serial_number()
|
|
]);
|
|
}
|
|
try {
|
|
DB::beginTransaction();
|
|
if ($input['pay_way'] === PayWay::WxpayTransfer->value) {
|
|
$service->wechatTransfer($order);
|
|
} else {
|
|
$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->radio('pay_way')->options([
|
|
PayWay::Offline->value => PayWay::Offline->text(),
|
|
PayWay::WxpayTransfer->value => PayWay::WxpayTransfer->text()
|
|
])->default(PayWay::Offline->value);
|
|
$this->text('pay_no');
|
|
$this->text('remarks')->value($order->remark);
|
|
|
|
$this->disableResetButton();
|
|
}
|
|
}
|