CategoryVideo.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/3/4
  6. * Time: 上午9:29
  7. */
  8. namespace common\models;
  9. //use yii\db\ActiveRecord;
  10. //use yii\behaviors\TimestampBehavior;
  11. class CategoryVideo extends Common
  12. {
  13. // public $Setdel = 1;
  14. // public $item = [1=>'不推荐',2=>'推荐'];
  15. // public function behaviors()
  16. // {
  17. // return [
  18. // [
  19. // 'class' => TimestampBehavior::className(),
  20. // 'attributes' => [
  21. // # 创建之前
  22. // ActiveRecord::EVENT_BEFORE_INSERT => ['create_at', 'update_at'],
  23. // # 修改之前
  24. // ActiveRecord::EVENT_BEFORE_UPDATE => ['update_at']
  25. // ],
  26. // #设置默认值
  27. // 'value' => $_SERVER['REQUEST_TIME']
  28. // ]
  29. // ];
  30. // }
  31. public function rules()
  32. {
  33. return [
  34. ['type_name','required','message'=>'不能为空'],
  35. ['sort','number'],
  36. ['is_recommend','in','range'=>[1,2]],
  37. ['del','in','range'=>[1,2],'on'=>'del'],
  38. ];
  39. }
  40. public function Authenticator($input)
  41. {
  42. $this->load($input,'');
  43. if(!$this->validate()) return $this->errors;
  44. return $this;
  45. }
  46. public function FindById($id)
  47. {
  48. return self::findOne($id);
  49. }
  50. public function getList($input,$select = null)
  51. {
  52. $query = $this->FindQuery();
  53. $query->select($select);
  54. $query = $this->WhereFocus($query);
  55. if (!empty($input['page']))
  56. {
  57. $query->limit = $input['limit'];
  58. $query->offset = ($input['page'] - 1) * $input['limit'];
  59. }
  60. return $query->orderBy(['sort'=>SORT_DESC,'create_at'=>SORT_DESC])->asArray()->all();
  61. }
  62. public function WhereFocus($query)
  63. {
  64. $query->andFilterWhere(['type_name'=>$this->type_name]);
  65. $query->andWhere(['del'=>$this->setDel]);
  66. return $query;
  67. }
  68. public function Total()
  69. {
  70. $query = $this->FindQuery();
  71. $query = $this->WhereFocus($query);
  72. return $query->count();
  73. }
  74. private function FindQuery()
  75. {
  76. return self::find();
  77. }
  78. }