CategoryTel.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 CategoryTel extends ActiveRecord
  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. ];
  36. }
  37. public function attributeLabels()
  38. {
  39. return [
  40. 'tel'=>'电话集合',
  41. 'name'=>'方案名称',
  42. ];
  43. }
  44. public function getList()
  45. {
  46. $query = self::find();
  47. $query->andWhere(['del'=>$this->setDel]);
  48. $query->orderBy(['create_at'=>SORT_DESC]);
  49. $query->asArray();
  50. return $query->all();
  51. }
  52. public function CitySchemeTouch()
  53. {
  54. $query = CategoryCity::find();
  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 FindById($id)
  66. {
  67. return self::findOne($id);
  68. }
  69. }