CategoryTel.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/4/8
  6. * Time: 上午8:46
  7. */
  8. namespace common\models;
  9. //use yii\db\ActiveRecord;
  10. //use yii\behaviors\TimestampBehavior;
  11. class CategoryTel 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', 'update_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. [['tel','name'],'required','message'=>'{attribute}不能为空'],
  34. ['del','in','range'=>[1,2]],
  35. ['city','number'],
  36. ];
  37. }
  38. public function attributeLabels()
  39. {
  40. return [
  41. 'tel'=>'电话集合',
  42. 'name'=>'方案名称',
  43. ];
  44. }
  45. public function getList($input='')
  46. {
  47. $query = self::find();
  48. $query->andWhere(['del'=>$this->setDel]);
  49. if(!empty($input['city'])){
  50. if(is_numeric($input['city'])){
  51. $query->andWhere(['city'=>$input['city']]);
  52. }
  53. if(is_string($input['city'])){
  54. $city = explode(',',$input['city']);
  55. $query->andWhere(['city'=>$city]);
  56. }
  57. }
  58. $query->orderBy(['create_at'=>SORT_DESC]);
  59. $query->asArray();
  60. return $query->all();
  61. }
  62. public function CitySchemeTouch()
  63. {
  64. $query = CategoryCity::find();
  65. }
  66. /*
  67. * 调用里面的验证,错误返回数组,正确返回对象
  68. * */
  69. public function Authenticator($input)
  70. {
  71. $this->load($input,'');
  72. if(!$this->validate()) return $this->errors;
  73. return $this;
  74. }
  75. public function FindById($id)
  76. {
  77. return self::findOne($id);
  78. }
  79. }