CategoryAlbum.php 1.9 KB

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