orders = $orders; $this->initAttributes(); } protected function initAttributes() { $this->fill([ 'uniacid' => \YunShop::app()->uniacid, 'total_price' => $this->orders->sum('price'), 'outside_sn' => request()->input('outside_sn'), 'order_ids' => $this->orders->pluck('id'), 'trade_sn' => self::createSn(), ]); } /** * @throws ApiException */ public function store() { $this->save(); if ($this->id === null) { throw new ApiException('第三方订单请求记录保存失败'); } $this->orders()->attach($this->order_ids); } }