From 6abd4636cf509b5f70c8cb3fdfc9017a2df82854 Mon Sep 17 00:00:00 2001 From: Terry <2358269014@qq.com> Date: Fri, 27 Sep 2019 22:10:12 +0800 Subject: [PATCH] customer address services --- services/customer/Address.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/services/customer/Address.php b/services/customer/Address.php index 872e88ee..b4447a05 100644 --- a/services/customer/Address.php +++ b/services/customer/Address.php @@ -28,6 +28,8 @@ class Address extends Service protected $_addressModelName = '\fecshop\models\mysqldb\customer\Address'; protected $_addressModel; + public $is_default = 1; + public $is_not_default = 2; public function init() { @@ -422,4 +424,26 @@ class Address extends Service } } */ + /** + * 得到登陆用户的默认货运地址。 + */ + public function getDefaultAddress(){ + if (Yii::$app->user->isGuest) { + Yii::$service->helper->errors->add('customer is guest'); + + return null; + } + $identity = Yii::$app->user->identity; + $customer_id = $identity->id; + $one = $this->_addressModel->findOne([ + 'customer_id' => $customer_id, + 'is_default' => $this->is_default, + ]); + if ($one['customer_id']) { + + return $one; + } + + return null; + } } -- GitLab