12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/4/14
- * Time: 下午5:38
- */
- namespace common\models;
- class Email extends Common
- {
- public function rules()
- {
- return [
- ['email','required','message'=>'不能为空'],
- ['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');
- }
- }
|