HouseFacilities.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/3/31
  6. * Time: 下午7:20
  7. */
  8. namespace common\models;
  9. class HouseFacilities extends Common
  10. {
  11. public function rules()
  12. {
  13. return [
  14. [['name','fid','distance'],'required','message'=>'{attribute}不能为空'],
  15. // [,'required','message'=>'不能为空'],
  16. ['fid','number'],
  17. ['hid','number'],
  18. // [,'required','message'=>'不能为空'],
  19. ['distance','string','max'=>50],
  20. ['latitude_longitude','string','max'=>100],
  21. ['del','in','range'=>[1,2]],
  22. ['del','default','value'=>1],
  23. ];
  24. }
  25. public function attributeLabels()
  26. {
  27. return [
  28. 'name'=>'配套名称',
  29. 'distance'=>'距离',
  30. 'latitude_longitude'=>'经纬度',
  31. 'fid'=>'配套类目'
  32. // '配套名称'=>'name',
  33. // '配套类目'=>'fid',
  34. // '距离'=>'distance',
  35. // '经纬度'=>'latitude_longitude',
  36. ];
  37. }
  38. public function Authenticator($input)
  39. {
  40. $this->load($input,'');
  41. if(!$this->validate()) return $this->errors;
  42. return $this;
  43. }
  44. //分组
  45. public function FacilitiesGroup()
  46. {
  47. $query = self::find();
  48. $query->andFilterWhere(['pfg_house_facilities.hid'=>$this->hid]);
  49. $query->andWhere(['pfg_house_facilities.del'=>$this->setDel]);
  50. $query->select(['pfg_category_facilities.name','pfg_house_facilities.id','pfg_house_facilities.fid','pfg_house_facilities.state',"count('fid') as num"]);
  51. $query->leftJoin('pfg_category_facilities','pfg_house_facilities.fid = pfg_category_facilities.id');
  52. return $query->groupBy('pfg_house_facilities.fid')->orderBy(['pfg_house_facilities.create_at'=>SORT_DESC])->asArray()->all();
  53. }
  54. public function getList()
  55. {
  56. $query = self::find();
  57. $query->andFilterWhere(['hid'=>$this->hid]);
  58. $query->andFilterWhere(['fid'=>$this->fid]);
  59. $query->andWhere(['del'=>$this->setDel]);
  60. return $query->orderBy(['create_at'=>SORT_DESC])->asArray()->all();
  61. }
  62. //
  63. public function InfoList()
  64. {
  65. $query = self::find();
  66. $query->andWhere(['pfg_house_facilities.hid'=>$this->hid]);
  67. $query->andWhere(['pfg_house_facilities.del'=>$this->setDel]);
  68. $query->select(['pfg_category_facilities.name','pfg_house_facilities.id','pfg_house_facilities.fid','pfg_house_facilities.state','pfg_house_facilities.name as pname','pfg_house_facilities.distance','pfg_house_facilities.latitude_longitude']);
  69. $query->leftJoin('pfg_category_facilities','pfg_house_facilities.fid = pfg_category_facilities.id');
  70. return $query->orderBy(['pfg_house_facilities.fid'=>SORT_DESC])->asArray()->all();
  71. }
  72. public function GroupPeitao()
  73. {
  74. $query = self::find();
  75. $query->andFilterWhere(['pfg_house_facilities.hid'=>$this->hid]);
  76. $query->andWhere(['pfg_house_facilities.del'=>$this->setDel]);
  77. $group = $query->groupBy('fid')->asArray()->all();
  78. if(!empty($group))
  79. {
  80. }
  81. }
  82. //楼盘分组查询统计
  83. public function HidTotal()
  84. {
  85. $query = self::find();
  86. $query->select(["count('hid') as num",'hid']);
  87. $query->andFilterWhere(['hid'=>$this->hid]);
  88. $query->andWhere(['del'=>$this->setDel]);
  89. // $query->andWhere(['NOT',['img'=>'']]);
  90. return $query->groupBy('hid')->asArray()->all();
  91. }
  92. }