Brand.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace common\models;
  3. class Brand extends Common
  4. {
  5. public function rules()
  6. {
  7. return [
  8. [['name','country'],'required','message'=>'{attribute}不能为空'],
  9. ['name', 'unique','targetClass' => 'common\models\Brand','on'=>'add','message'=>'该品牌名称已经存在',
  10. 'filter'=>function($query){
  11. return $query->andWhere(['del'=>$this->setDel]);
  12. }],
  13. ['name','string','max'=>255],
  14. ['sort','number','max'=>10000],
  15. ];
  16. }
  17. public function attributeLabels()
  18. {
  19. return [
  20. 'name'=>'品牌名称',
  21. 'country'=>'所属国家',
  22. ];
  23. }
  24. public function Total($input)
  25. {
  26. $query = self::find();
  27. $query->andWhere(['del'=>$this->setDel]);
  28. if(!empty($input['name']))
  29. {
  30. $query->andWhere(['like','name',$input['name']]);
  31. }
  32. return $query->count();
  33. }
  34. /*
  35. * 后台 - 品牌页面数据
  36. */
  37. public function GetList($input)
  38. {
  39. $query = self::find();
  40. $query->andWhere(['del'=>$this->setDel]);
  41. if(!empty($input['name']))
  42. {
  43. $query->andWhere(['like','name',$input['name']]);
  44. }
  45. if(!empty($input['page']))
  46. {
  47. $query->limit = $input['limit'];
  48. $query->offset = ($input['page']-1 )* $input['limit'];
  49. }
  50. $query->orderBy(['pfg_brand.sort'=>SORT_DESC,'pfg_brand.id'=>SORT_DESC]);
  51. return $query->asArray()->all();
  52. }
  53. /*
  54. * PC首页品牌馆
  55. */
  56. public function getPcBrand($limit = null)
  57. {
  58. $query = self::find();
  59. $query->select(['pfg_brand.id','pfg_brand.name','pfg_brand.img','pfg_category_city.city_name']);
  60. $query->andWhere(['pfg_brand.is_show'=>1]);
  61. $query->leftJoin('pfg_category_city','pfg_category_city.id=pfg_brand.country');
  62. $query->orderBy(['pfg_brand.sort'=>SORT_DESC,'pfg_brand.id'=>SORT_DESC]);
  63. $query->limit = $limit;
  64. return $query->asArray()->all();
  65. }
  66. /*
  67. * PC首页品牌馆
  68. */
  69. public function getPcSearchBrand()
  70. {
  71. $query = self::find();
  72. $query->select(['id','name']);
  73. $query->andWhere(['is_show'=>1]);
  74. $query->orderBy(['sort'=>SORT_DESC,'id'=>SORT_DESC]);
  75. return $query->asArray()->all();
  76. }
  77. }