diff --git a/app/Admin/Actions/Show/AfterSaleShippingFail.php b/app/Admin/Actions/Show/AfterSaleShippingFail.php index 86ac733f..775759d1 100644 --- a/app/Admin/Actions/Show/AfterSaleShippingFail.php +++ b/app/Admin/Actions/Show/AfterSaleShippingFail.php @@ -2,13 +2,9 @@ namespace App\Admin\Actions\Show; -use App\Models\AfterSale; -use App\Services\AfterSaleService; +use App\Admin\Forms\AfterSaleShippingFail as AfterSaleShippingFailForm; use Dcat\Admin\Show\AbstractTool; -use Illuminate\Contracts\Auth\Authenticatable; -use Illuminate\Http\Request; -use Illuminate\Support\Facades\DB; -use Throwable; +use Dcat\Admin\Widgets\Modal; class AfterSaleShippingFail extends AbstractTool { @@ -24,59 +20,13 @@ class AfterSaleShippingFail extends AbstractTool */ protected $style = 'btn btn-sm btn-danger'; - /** - * 权限判断,如不需要可以删除此方法 - * - * @param Model|Authenticatable|HasPermissions|null $user - * - * @return bool - */ - protected function authorize($user): bool + public function render() { - return $user->can('dcat.admin.after_sales.shipping'); - } - - /** - * 处理请求,如果不需要接口处理,请直接删除这个方法 - * - * @param Request $request - * - * @return Response - */ - public function handle(Request $request) - { - // 获取主键 - $key = $this->getKey(); - - $afterSaleService = new AfterSaleService(); - try { - DB::beginTransaction(); - $afterSale = AfterSale::where('state', AfterSale::STATE_SHIPPING)->findOrFail($key); - $afterSaleService->shippingFail($afterSale); - DB::commit(); - } catch (Throwable $th) { - DB::rollBack(); - report($th); - return $this->response()->error('操作失败:'.$th->getMessage()); - } - - return $this->response() - ->success(__('admin.update_succeeded')) - ->refresh(); - } - - public function html() - { - return parent::html().'  '; - } - - /** - * 确认弹窗信息,如不需要可以删除此方法 - * - * @return string|array|void - */ - public function confirm() - { - return ['是否拒绝收货?', '该操作不可逆,确认后将退回客服审核。']; + $form = AfterSaleShippingFailForm::make()->payload(['id'=>$this->getKey()]); + return Modal::make() + ->lg() + ->title($this->title) + ->body($form) + ->button("style}\">{$this->title}  "); } } diff --git a/app/Admin/Actions/Show/AfterSaleShippingFill.php b/app/Admin/Actions/Show/AfterSaleShippingFill.php new file mode 100644 index 00000000..c81bf3dd --- /dev/null +++ b/app/Admin/Actions/Show/AfterSaleShippingFill.php @@ -0,0 +1,32 @@ + 确认补货'; + + /** + * 按钮样式定义,默认 btn btn-white waves-effect + * + * @var string + */ + protected $style = 'btn btn-sm btn-success'; + + public function render() + { + $form = AfterSaleShippingFillForm::make()->payload(['id'=>$this->getKey()]); + return Modal::make() + ->lg() + ->title($this->title) + ->body($form) + ->button("style}\">{$this->title}  "); + } +} diff --git a/app/Admin/Controllers/AfterSaleController.php b/app/Admin/Controllers/AfterSaleController.php index 1ff97cc9..ce1b0703 100644 --- a/app/Admin/Controllers/AfterSaleController.php +++ b/app/Admin/Controllers/AfterSaleController.php @@ -6,6 +6,7 @@ use App\Admin\Actions\Show\AfterSaleFinance; use App\Admin\Actions\Show\AfterSaleFinanceShipping; use App\Admin\Actions\Show\AfterSaleShipping; use App\Admin\Actions\Show\AfterSaleShippingFail; +use App\Admin\Actions\Show\AfterSaleShippingFill; use App\Admin\Actions\Show\AfterSaleVerify; use App\Admin\Repositories\AfterSale; use App\Models\AfterSale as AfterSaleModel; @@ -105,6 +106,7 @@ class AfterSaleController extends AdminController $show->field('id'); $show->field('sn'); $show->field('order.sn'); + $show->field('user.phone'); $show->field('order_product.name'); $show->field('num'); if (in_array($show->model()->type, [AfterSaleModel::TYPE_REFUND_AND_RETURN, AfterSaleModel::TYPE_REFUND])) { @@ -151,8 +153,13 @@ class AfterSaleController extends AdminController if ($show->model()->state == AfterSaleModel::STATE_SHIPPING) { //拒绝确认收货 $tools->append(new AfterSaleShippingFail()); - //同意确认收货 - $tools->append(new AfterSaleShipping()); + if ($show->model()->type == AfterSaleModel::TYPE_FILL) { + //同意确认收货 + $tools->append(new AfterSaleShippingFill()); + } else { + //同意确认收货 + $tools->append(new AfterSaleShipping()); + } } if ($show->model()->state == AfterSaleModel::STATE_FINANCE) { if (in_array($show->model()->type, [AfterSaleModel::TYPE_REFUND_AND_RETURN, AfterSaleModel::TYPE_REFUND])) { diff --git a/app/Admin/Forms/AfterSaleShippingFail.php b/app/Admin/Forms/AfterSaleShippingFail.php new file mode 100644 index 00000000..5616f6a4 --- /dev/null +++ b/app/Admin/Forms/AfterSaleShippingFail.php @@ -0,0 +1,64 @@ +can('dcat.admin.after_sales.shipping'); + } + + /** + * Handle the form request. + * + * @param array $input + * + * @return mixed + */ + public function handle(array $input) + { + $afterSaleService = new AfterSaleService(); + try { + DB::beginTransaction(); + $afterSale = AfterSale::where('state', AfterSale::STATE_SHIPPING)->findOrFail($this->payload['id']); + $afterSaleService->shippingFail($afterSale, $input['remarks']); + + 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(); + $this->confirm('是否拒绝通过?', '该操作不可逆,确认后将退回客服审核。'); + } +} diff --git a/app/Admin/Forms/AfterSaleShippingFill.php b/app/Admin/Forms/AfterSaleShippingFill.php new file mode 100644 index 00000000..42c4e1c4 --- /dev/null +++ b/app/Admin/Forms/AfterSaleShippingFill.php @@ -0,0 +1,64 @@ +can('dcat.admin.after_sales.shipping'); + } + + /** + * Handle the form request. + * + * @param array $input + * + * @return mixed + */ + public function handle(array $input) + { + $afterSaleService = new AfterSaleService(); + try { + DB::beginTransaction(); + $afterSale = AfterSale::where('state', AfterSale::STATE_SHIPPING)->findOrFail($this->payload['id']); + $afterSaleService->shippingFill($afterSale, $input['remarks']); + + 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(); + $this->confirm('是否确认补货完成', '该操作不可逆,确认后将完成该售后单。'); + } +} diff --git a/app/Admin/Forms/AfterSaleVerify.php b/app/Admin/Forms/AfterSaleVerify.php index 6f628b1b..a811d694 100644 --- a/app/Admin/Forms/AfterSaleVerify.php +++ b/app/Admin/Forms/AfterSaleVerify.php @@ -91,7 +91,7 @@ class AfterSaleVerify extends Form implements LazyRenderable $defaultRemarks = '同意换货,请填入回寄单号';//需要用户确认并填入回寄单号 break; case 4: - $defaultRemarks = '同意补货, 新的订单号:';//需要用户收到补货后确认,可后台关闭 + $defaultRemarks = '同意补货';//需要用户收到补货后确认,可后台关闭 } $this->text('remarks3')->value($defaultRemarks); }) diff --git a/app/Models/AfterSale.php b/app/Models/AfterSale.php index 424b9c47..a18d77cf 100644 --- a/app/Models/AfterSale.php +++ b/app/Models/AfterSale.php @@ -165,6 +165,8 @@ class AfterSale extends Model if ($afterSale->sn === null) { $afterSale->sn = self::createSn(); } + }); + parent::saved(function ($afterSale) { //如果取消订单 if ($afterSale->state == self::STATE_CANCEL) { $afterSale->createCancelLog(); diff --git a/app/Services/AfterSaleService.php b/app/Services/AfterSaleService.php index ff71ddc7..3d3b42fc 100644 --- a/app/Services/AfterSaleService.php +++ b/app/Services/AfterSaleService.php @@ -234,6 +234,11 @@ class AfterSaleService public function agree(AfterSale $afterSale, array $params, $remarks = '用户已同意客服审核结果') { if ($this->isWaitAgree($afterSale)) { + AfterSaleLog::create([ + 'after_sale_id' => $afterSale->id, + 'name' => '客户确认', + 'desc' => $remarks, + ]); switch ($afterSale->type) { case AfterSale::TYPE_REFUND_AND_RETURN: $afterSale->update([ @@ -258,15 +263,10 @@ class AfterSaleService case AfterSale::TYPE_FILL: $afterSale->update([ 'remarks' => $remarks, - 'state' => AfterSale::STATE_FINISH, + 'state' => AfterSale::STATE_SHIPPING, ]); break; } - AfterSaleLog::create([ - 'after_sale_id' => $afterSale->id, - 'name' => '客户确认', - 'desc' => $remarks, - ]); return $afterSale; } else { throw new BizException('售后订单状态异常,请稍后再试'); @@ -280,7 +280,7 @@ class AfterSaleService * @param string $remarks * @return void */ - public function shippingFail(AfterSale $afterSale, $remarks ='物流收货未通过') + public function shippingFail(AfterSale $afterSale, $remarks ='仓库验收未通过') { if ($this->isWaitShipping($afterSale)) { $afterSale->update([ @@ -297,6 +297,31 @@ class AfterSaleService } } + /** + * 物流补货 + * + * @param AfterSale $afterSale + * @param string $remarks + * @return void + */ + public function shippingFill(AfterSale $afterSale, $remarks) + { + $remarks = '补货完成,新的物流单号:'.$remarks; + if ($this->isWaitShipping($afterSale)) { + AfterSaleLog::create([ + 'after_sale_id' => $afterSale->id, + 'name' => '仓库审核', + 'desc' => $remarks, + ]); + $afterSale->update([ + 'state' => $afterSale::STATE_FINISH, + 'remarks' => $remarks, + ]); + } else { + throw new BizException('该售后订单状态异常'); + } + } + /** * 物流确认收货 * @@ -304,7 +329,7 @@ class AfterSaleService * @param string $remarks * @return void */ - public function shipping(AfterSale $afterSale, $remarks ='物流确认收货') + public function shipping(AfterSale $afterSale, $remarks ='仓库验收通过') { if ($this->isWaitShipping($afterSale)) { $afterSale->update([