'不能为空'], ['email','email'], // ['email', 'unique', 'targetClass' => 'common\models\Email','on'=>['add'],'message'=>'该邮箱已存在','filter'=>function($query){ // return $query->andWhere(['del'=>1]); // }], ['city', 'unique', 'targetClass' => 'common\models\Email','on'=>['add'],'message'=>'该区域的邮箱已经存在','filter'=>function($query){ return $query->andWhere(['del'=>1]);; }], ['city','number'], ['name','string','max'=>10], [['email','name','city'],'trim'], // ['city', 'unique', 'targetClass' => 'common\models\Email','on'=>['edit'],'message'=>'该区域已存在','filter'=>function($query){ $query->andWhere(['del'=>1]); return $query->andWhere(['!=','id',$this->id]); }], ]; } public function attributeLabels() { return [ 'city'=>'区域', 'email'=>'邮箱', 'name'=>'姓名', ]; } public function FindById($id) { return self::findOne($id); } /* * 传入区域ID 获取相对应的邮箱 * */ public function FindByEmail($city) { $query = self::find(); $query->select(['pfg_email.email','pfg_category_city.city_name']); $query->andWhere(['pfg_email.city'=>$city]); $query->andWhere(['pfg_email.del'=>1]); $query = $this->LeftJoinCategoryCity($query); return $query->asArray()->one(); } public function Authenticator($input) { $this->load($input,''); if(!$this->validate()) return $this->errors; return $this; } public function getList($page) { $query = self::find(); $query->select(['pfg_email.*','pfg_category_city.city_name']); $query->andFilterWhere(['pfg_email.del'=>1]); $query = $this->LeftJoinCategoryCity($query); if(!empty($page['page'])) { $query->offset = ($page['page'] - 1) * $page['limit']; $query->limit = $page['limit']; } return $query->orderBy(['pfg_email.create_at'=>SORT_ASC])->asArray()->all(); } public function Total() { $query = self::find(); $query = $this->LeftJoinCategoryCity($query); return $query->count(); } private function LeftJoinCategoryCity($query) { return $query->leftJoin('pfg_category_city','pfg_email.city=pfg_category_city.id'); } }