Example #1
0
 /**
  * @see \yii\db\BaseActiveRecord::beforeSave($insert)
  */
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         //地址设为默认
         if ($this->is_default) {
             CustomerAddress::updateAll(['is_default' => self::CUSTOMER_ADDRESS_NOT_DEFAULT], 'customer_id = :customer_id', [':customer_id' => $this->customer_id]);
         }
         return true;
     } else {
         return false;
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = CustomerAddress::find()->with('customer');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'customer_id' => $this->customer_id, 'district_id' => $this->district_id, 'city_id' => $this->city_id, 'province_id' => $this->province_id, 'country_id' => $this->country_id, 'created_at' => $this->created_at]);
     $query->andFilterWhere(['like', 'consignee', $this->consignee])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'telephone', $this->telephone])->andFilterWhere(['like', 'mobile_phone', $this->mobile_phone])->andFilterWhere(['like', 'postcode', $this->postcode]);
     return $dataProvider;
 }
 /**
  * Finds the CustomerAddress model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return CustomerAddress the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = CustomerAddress::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }