CategoryTelCity.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/4/4
  6. * Time: 上午11:34
  7. */
  8. namespace common\models;
  9. use yii\db\ActiveRecord;
  10. use yii\behaviors\TimestampBehavior;
  11. class CategoryTelCity extends Common
  12. {
  13. // public $setDel = 1;
  14. public function behaviors()
  15. {
  16. return [
  17. [
  18. 'class' => TimestampBehavior::className(),
  19. 'attributes' => [
  20. # 创建之前
  21. ActiveRecord::EVENT_BEFORE_INSERT => ['create_at'],
  22. # 修改之前
  23. // ActiveRecord::EVENT_BEFORE_UPDATE => ['update_at']
  24. ],
  25. #设置默认值
  26. 'value' => $_SERVER['REQUEST_TIME']
  27. ]
  28. ];
  29. }
  30. public function rules()
  31. {
  32. return [
  33. ['cid','number'],
  34. ['tid','number'],
  35. ];
  36. }
  37. public function getList()
  38. {
  39. $query = self::find();
  40. $query = $this->WhereColumn($query);
  41. return $query->asArray()->all();
  42. }
  43. public function attributeLabels()
  44. {
  45. // return [
  46. // 'tel'=>'电话集合',
  47. // 'name'=>'方案名称',
  48. // ];
  49. }
  50. private function WhereColumn($query)
  51. {
  52. $query->andFilterWhere(['cid'=>$this->cid]);
  53. $query->andFilterWhere(['tid'=>$this->tid]);
  54. return $query;
  55. }
  56. /*
  57. * 调用里面的验证,错误返回数组,正确返回对象
  58. * */
  59. public function Authenticator($input)
  60. {
  61. $this->load($input,'');
  62. if(!$this->validate()) return $this->errors;
  63. return $this;
  64. }
  65. public function findByOne()
  66. {
  67. $query = self::find();
  68. $query = $this->WhereColumn($query);
  69. return $query->one();
  70. }
  71. public function FindById($id)
  72. {
  73. return self::findOne($id);
  74. }
  75. public function CityTelOne()
  76. {
  77. $query = self::find();
  78. $query->select(['pfg_category_tel.tel']);
  79. $query->andFilterWhere(['pfg_category_tel_city.cid'=>$this->cid]);
  80. $query->leftJoin('pfg_category_tel','pfg_category_tel_city.tid = pfg_category_tel.id and pfg_category_tel.del = 1');
  81. return $query->asArray()->one();
  82. }
  83. public function QgetAll()
  84. {
  85. $query = self::find();
  86. $query->select(['pfg_category_tel.tel','pfg_category_tel_city.cid']);
  87. $query->leftJoin('pfg_category_tel','pfg_category_tel_city.tid = pfg_category_tel.id and pfg_category_tel.del = 1');
  88. return $query->asArray()->all();
  89. }
  90. }