form = $form; $this->isNewRecord = $is_new_record; $this->user = $user; } /** * @var BaseOrderForm */ public function getForm() { return $this->form; } /** * @param BaseOrderForm $form * @return void */ public function setForm(BaseOrderForm $form) { $this->form = $form; } /** * @return BaseOrderForm|boolean */ public function getResultForm() { if ($this->isError) return false; return $this->form; } /** * @return boolean */ public function isNewRecord() { return $this->isNewRecord; } /** * @param string $msg * @return void */ public function setErrorMsg(string $msg) { $this->isError = true; $this->errorMsg = $msg; } /** * @return string */ public function getErrorMsg() { return $this->errorMsg; } /** * @param string $source * @return boolean */ public function isCurrentSource(string $source): bool { return $this->getGoodsSource() == $source; } /** * 获取商品的来源类型 * * @return string */ public function getGoodsSource() { $sources = array_unique(array_column(array_column($this->getForm()->sku, 'goods'), 'goods_source')); if (count($sources) > 1) throw new Exception('商品来源不一致'); return reset($sources); } }