1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace common\models;
- class GroupPurchase extends Common
- {
- public function rules()
- {
- return [
- [['title'],'required','message'=>'不能为空'],
- ['sort','default','value'=>0],
- ['is_view','default','value'=>0],
- [['hid','sort','sign_num','is_view'],'number'],
- [['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'],
- ];
- }
- public function attributeLabels()
- {
- return [
- 'title'=>'团购标题',
- 'img_pc'=>'手机封面图',
- 'keyword'=>'关键词',
- 'city'=>'所属城市',
- 'content'=>'内容介绍',
- 'description'=>'描述',
- 'address'=>'地址',
- 'sort'=>'排序',
- 'clicks'=>'点击数',
- 'is_view'=>'显示/隐藏',
- ];
- }
- public function Authenticator($input)
- {
- $this->load($input,'');
- if(!$this->validate()) return $this->errors;
- return $this;
- }
- public function FindById($id)
- {
- return self::findOne($id);
- }
- public function getList($data)
- {
- $query = $this->QueryFind();
- $query->select(['pfg_house.name as house_name','pfg_house.id as house_id','pfg_group_purchase.*','pfg_category_city.city_name']);
- $query = $this->LeftJoinWhere($query);
- $query = $this->LeftJoinCategoryCity($query);
- $query = $this->LeftJoinHouse($query);
- if(!empty($input))
- {
- $query->offset = ($input['page'] -1) * $input['limit'];
- $query->limit = $input['limit'];
- }
- return $query->orderBy(['pfg_group_purchase.create_at'=>SORT_DESC])->asArray()->all();
- }
- public function Total()
- {
- $query = $this->QueryFind();
- $query = $this->LeftJoinWhere($query);
- $query = $this->LeftJoinCategoryCity($query);
- $query = $this->LeftJoinHouse($query);
- return $query->count();
- }
- private function LeftJoinWhere($query)
- {
- $query->andFilterWhere(['pfg_group_purchase.del'=>$this->setDel]);
- $query->andFilterWhere(['pfg_group_purchase.city'=>$this->city]);
- $query->andFilterWhere(['like','pfg_group_purchase.title',$this->title]);
- $query->andFilterWhere(['like','pfg_house.name',$this->hid]);
- return $query;
- }
- private function LeftJoinHouse($query)
- {
- return $query->leftJoin('pfg_house','pfg_group_purchase.hid = pfg_house.id');
- }
- private function LeftJoinCategoryCity($query)
- {
- return $query->leftJoin('pfg_category_city','pfg_group_purchase.city = pfg_category_city.id');
- }
- private function QueryFind()
- {
- return self::find();
- }
- }
|