GroupPurchase.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace common\models;
  3. class GroupPurchase extends Common
  4. {
  5. public function rules()
  6. {
  7. return [
  8. [['title'],'required','message'=>'不能为空'],
  9. ['sort','default','value'=>0],
  10. ['is_view','default','value'=>0],
  11. [['hid','sort','sign_num','is_view'],'number'],
  12. [['title','city','keyword','description','address','type','odiscount','tel','market_pricce','group_price','clicks','content','end_date','start_date','img_pc','img_mobile','many_img'],'string'],
  13. ];
  14. }
  15. public function attributeLabels()
  16. {
  17. return [
  18. 'title'=>'团购标题',
  19. 'img_pc'=>'手机封面图',
  20. 'keyword'=>'关键词',
  21. 'city'=>'所属城市',
  22. 'content'=>'内容介绍',
  23. 'description'=>'描述',
  24. 'address'=>'地址',
  25. 'sort'=>'排序',
  26. 'clicks'=>'点击数',
  27. 'is_view'=>'显示/隐藏',
  28. ];
  29. }
  30. public function Authenticator($input)
  31. {
  32. $this->load($input,'');
  33. if(!$this->validate()) return $this->errors;
  34. return $this;
  35. }
  36. public function FindById($id)
  37. {
  38. return self::findOne($id);
  39. }
  40. public function getList($data)
  41. {
  42. $query = $this->QueryFind();
  43. $query->select(['pfg_house.name as house_name','pfg_house.id as house_id','pfg_group_purchase.*','pfg_category_city.city_name']);
  44. $query = $this->LeftJoinWhere($query);
  45. $query = $this->LeftJoinCategoryCity($query);
  46. $query = $this->LeftJoinHouse($query);
  47. if(!empty($input))
  48. {
  49. $query->offset = ($input['page'] -1) * $input['limit'];
  50. $query->limit = $input['limit'];
  51. }
  52. return $query->orderBy(['pfg_group_purchase.create_at'=>SORT_DESC])->asArray()->all();
  53. }
  54. public function Total()
  55. {
  56. $query = $this->QueryFind();
  57. $query = $this->LeftJoinWhere($query);
  58. $query = $this->LeftJoinCategoryCity($query);
  59. $query = $this->LeftJoinHouse($query);
  60. return $query->count();
  61. }
  62. private function LeftJoinWhere($query)
  63. {
  64. $query->andFilterWhere(['pfg_group_purchase.del'=>$this->setDel]);
  65. $query->andFilterWhere(['pfg_group_purchase.city'=>$this->city]);
  66. $query->andFilterWhere(['like','pfg_group_purchase.title',$this->title]);
  67. $query->andFilterWhere(['like','pfg_house.name',$this->hid]);
  68. return $query;
  69. }
  70. private function LeftJoinHouse($query)
  71. {
  72. return $query->leftJoin('pfg_house','pfg_group_purchase.hid = pfg_house.id');
  73. }
  74. private function LeftJoinCategoryCity($query)
  75. {
  76. return $query->leftJoin('pfg_category_city','pfg_group_purchase.city = pfg_category_city.id');
  77. }
  78. private function QueryFind()
  79. {
  80. return self::find();
  81. }
  82. }