select('id, user_id, mall_id, order_no, mobile, region_name, address, pay_status, receiver_name, order_source'); return $model->where(['id' => $order_id]) ->with(['detail' => function($query) { $query->select('id, order_id, num, goods_attr_id, goods_id')->with([ 'goods' => function($query) { $query->select('id, goods_source'); } ]); }]) ->one(); } /** * 获取地址 * * @return array */ public function getRegion() { $region = $this->region_name; list($province, $city, $area, $town) = explode(' ', $region); $town = $town ?? $area; $address = $this->address; return compact('province', 'city', 'area', 'town', 'address'); } /** * 是否已经创建供应链订单 * * @return boolean */ public function hasChainOrder() { return ModelsOrder::find()->select('id')->where([ 'mall_id' => $this->mall_id, 'order_no' => $this->order_no ])->one() ? true : false; } /** * 判断当前订单是否是供应链订单 * * @return boolean */ public function isChainOrder() { if (empty($this->detail)) return false; $goods_sources = array_map(function($goods) { return $goods->goods_source; }, array_column($this->detail, 'goods')); return array_unique($goods_sources) == [StarChainEnum::PLUGIN_SIGN]; } /** * @return boolean */ public function changeOrderSource() { $this->order_source = StarChainEnum::PLUGIN_SIGN; return $this->save(); } }