can('dcat.admin.orders.create_package'); } /** * Handle the form request. * * @param array $input * * @return mixed */ public function handle(array $input) { $orderId = $this->payload['id'] ?? 0; $order = Order::findOrFail($orderId); try { DB::beginTransaction(); $orderService = new AdminOrderService(); $orderService->createPackage($order, $input); DB::commit(); } catch (BizException $e) { DB::rollBack(); report($e); throw new BizException('操作失败:'.$e->getMessage()); } catch (Throwable $th) { DB::rollBack(); report($th); throw new BizException('操作失败:'.$th->getMessage()); } return $this->response() ->success(__('admin.update_succeeded')) ->refresh(); } /** * Build a form here. */ public function form() { $orderId = $this->payload['id'] ?? 0; $order = Order::findOrFail($orderId); $this->select('shipping_company')->options([ '圆通速递'=>'圆通速递', '韵达快递'=>'韵达快递', '中通快递'=>'中通快递', '申通快递'=>'申通快递', '百世快递'=>'百世快递', 'EMS'=>'EMS', '顺丰速运'=>'顺丰速运', '德邦快递'=>'德邦快递', ])->required(); $this->text('shipping_number')->required(); $this->hasMany('packages', function (Form $form) use ($order) { $form->select('order_product_id')->options($order->products()->where('after_sale_state', '<>', 1)->pluck('name', 'id')); $form->number('quantity')->min(1); }); $this->disableResetButton(); } /** * The data of the form. * * @return array */ public function default() { return [ // 'name' => 'John Doe', // 'email' => 'John.Doe@gmail.com', ]; } }