123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/4/4
- * Time: 上午11:34
- */
- namespace common\models;
- use yii\db\ActiveRecord;
- use yii\behaviors\TimestampBehavior;
- class CategoryTelCity extends Common
- {
- // public $setDel = 1;
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::className(),
- 'attributes' => [
- # 创建之前
- ActiveRecord::EVENT_BEFORE_INSERT => ['create_at'],
- # 修改之前
- // ActiveRecord::EVENT_BEFORE_UPDATE => ['update_at']
- ],
- #设置默认值
- 'value' => $_SERVER['REQUEST_TIME']
- ]
- ];
- }
- public function rules()
- {
- return [
- ['cid','number'],
- ['tid','number'],
- ];
- }
- public function getList()
- {
- $query = self::find();
- $query = $this->WhereColumn($query);
- return $query->asArray()->all();
- }
- public function attributeLabels()
- {
- // return [
- // 'tel'=>'电话集合',
- // 'name'=>'方案名称',
- // ];
- }
- private function WhereColumn($query)
- {
- $query->andFilterWhere(['cid'=>$this->cid]);
- $query->andFilterWhere(['tid'=>$this->tid]);
- return $query;
- }
- /*
- * 调用里面的验证,错误返回数组,正确返回对象
- * */
- public function Authenticator($input)
- {
- $this->load($input,'');
- if(!$this->validate()) return $this->errors;
- return $this;
- }
- public function findByOne()
- {
- $query = self::find();
- $query = $this->WhereColumn($query);
- return $query->one();
- }
- public function FindById($id)
- {
- return self::findOne($id);
- }
- public function CityTelOne()
- {
- $query = self::find();
- $query->select(['pfg_category_tel.tel']);
- $query->andFilterWhere(['pfg_category_tel_city.cid'=>$this->cid]);
- $query->leftJoin('pfg_category_tel','pfg_category_tel_city.tid = pfg_category_tel.id and pfg_category_tel.del = 1');
- return $query->asArray()->one();
- }
- public function QgetAll()
- {
- $query = self::find();
- $query->select(['pfg_category_tel.tel','pfg_category_tel_city.cid']);
- $query->leftJoin('pfg_category_tel','pfg_category_tel_city.tid = pfg_category_tel.id and pfg_category_tel.del = 1');
- return $query->asArray()->all();
- }
- }
|