6
0
Fork 0
jiqu-library-server/app/Admin/Forms/DealerOrderRefuse.php

89 lines
1.9 KiB
PHP

<?php
namespace App\Admin\Forms;
use App\Enums\DealerOrderStatus;
use App\Exceptions\BizException;
use App\Models\DealerOrder;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
use Illuminate\Support\Facades\DB;
use Throwable;
class DealerOrderRefuse extends Form
{
use LazyWidget;
/**
* Handle the form request.
*
* @param array $input
*
* @return mixed
*/
public function handle(array $input)
{
try {
$id = $this->payload['id'] ?? null;
DB::beginTransaction();
$order = DealerOrder::lockForUpdate()->findOrFail($id);
if (! $order->isPayWayOffline()) {
throw new BizException('订单付款方式不是线下打款');
}
if (! $order->isPay()) {
throw new BizException('无法收款:订单状态异常,请刷新后再试');
}
$order->update([
'status' => DealerOrderStatus::Paying,
//置空已支付的信息
'pay_way'=> null,
'pay_image'=> null,
'pay_info' => null,
'pay_time' => null,
]);
$order->refuseLogs()->create([
'reason' => $input['reason'],
]);
DB::commit();
} catch (Throwable $e) {
DB::rollBack();
report($e);
return $this->response()->error('操作失败,'.$e->getMessage())->refresh();
}
return $this
->response()
->success('操作成功')
->refresh();
}
/**
* Build a form here.
*/
public function form()
{
$this->textarea('reason', '原因')->rules('required|max:255');
}
/**
* The data of the form.
*
* @return array
*/
public function default()
{
return [
'reason' => '',
];
}
}