Developers.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/3/4
  6. * Time: 上午9:32
  7. */
  8. namespace common\models;
  9. //use yii\db\ActiveRecord;
  10. //use yii\behaviors\TimestampBehavior;
  11. class Developers extends Common
  12. {
  13. public function rules()
  14. {
  15. return [
  16. ['name','required','message'=>'不能为空'],
  17. ['name', 'unique', 'targetClass' => 'common\models\Developers','on'=>['add']],
  18. ['info','string','max'=>200],
  19. ['logo','string','max'=>50],
  20. ['allow','in','range'=>[1,2]],
  21. ['is_del','in','range'=>[1,2]]
  22. ];
  23. }
  24. public function FindById($id)
  25. {
  26. return self::findOne($id);
  27. }
  28. public function getList($input,$select = null)
  29. {
  30. $query = self::find();
  31. $query->select($select);
  32. $query = $this->WhereFocus($query);
  33. if (!empty($input['name'])){
  34. $query->andWhere(['like','name',$input['name']]);
  35. }
  36. if(!empty($input['page']))
  37. {
  38. $query->offset = ($input['page'] - 1) * $input['limit'];
  39. $query->limit = $input['limit'];
  40. }
  41. return $query->orderBy(['create_at'=>SORT_DESC])->asArray()->all();
  42. }
  43. public function Total($input)
  44. {
  45. $query = self::find();
  46. $query = $this->WhereFocus($query);
  47. if (!empty($input['name'])){
  48. $query->andWhere(['like','name',$input['name']]);
  49. }
  50. return $query->count();
  51. }
  52. public function WhereFocus($query)
  53. {
  54. $query->andFilterWhere(['name'=>$this->name]);
  55. $query->andWhere(['is_del'=>$this->setDel]);
  56. return $query;
  57. }
  58. }