1、比如发货地址 我在管理后台和下订单处都要获取发货地址列表,怎么重用代码,但是目前很难重用
很简单的事情,直接从order services 查询就行了:
https://github.com/fecshop/yii2_fecshop/blob/master/services/Order.php
/** * @property $primaryKey | Int * @return Object($this->_orderModel) * 通过主键值,返回Order Model对象 */ protected function actionGetByPrimaryKey($primaryKey) { $one = $this->_orderModel->findOne($primaryKey); $primaryKey = $this->getPrimaryKey(); if ($one[$primaryKey]) { return $one; } else { return new $this->_orderModelName(); } } /** * @property $increment_id | String , 订单号 * @return object ($this->_orderModel),返回 $this->_orderModel model * 通过订单号incrementId,得到订单Model对象。 */ protected function actionGetByIncrementId($increment_id) { $one = $this->_orderModel->findOne(['increment_id' => $increment_id]); $primaryKey = $this->getPrimaryKey(); if ($one[$primaryKey]) { return $one; } else { return false; } }