'{attribute}不能为空'], ['hid', 'unique', 'targetClass' => 'common\models\HouseEmail', 'on' => ['add', 'edit'], 'message' => '该楼盘已经设置过邮箱'], ['hid', 'number'], ['email', 'email'], ]; } public function attributeLabels() { return [ 'hid' => '楼盘', 'email' => '邮箱', ]; } public function Authenticator($input) { $this->load($input, ''); if (!$this->validate()) return $this->errors; return $this; } /** * 返回后台查询的数据 * @param $input * @return array|\yii\db\ActiveRecord[] */ public function getList($input) { $query = self::find(); $query->select(['pfg_house_email.id', 'pfg_house_email.email', 'pfg_house_email.create_at', 'pfg_house.name']); $query->leftJoin('pfg_house', 'pfg_house_email.hid = pfg_house.id'); if (!empty($input['text'])) { $query->andWhere(['like', 'pfg_house_email.email', $input['text']]); $query->orWhere(['like', 'pfg_house.name', $input['text']]); } $query->orderBy(['pfg_house_email.email' => SORT_DESC, 'pfg_house_email.id' => SORT_DESC]); return $query->asArray()->all(); } /** * 返回后台数据条数 * @param $input * @return int|string */ public function Total($input) { $query = self::find(); $query->leftJoin('pfg_house', 'pfg_house_email.hid = pfg_house.id'); if (!empty($input['text'])) { $query->andWhere(['like', 'pfg_house_email.email', $input['text']]); $query->orWhere(['like', 'pfg_house.name', $input['text']]); } return $query->count(); } /** * 查询该楼盘是否单独设置了邮箱 * @param $hid * @return array|null|\yii\db\ActiveRecord */ public function findEmail($hid) { $query = self::find(); $query->select(['email']); $query->andWhere(['hid' => $hid]); return $query->asArray()->one(); } }