Lookhouse.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/3/4
  6. * Time: 上午9:40
  7. */
  8. namespace common\models;
  9. class Lookhouse extends Common
  10. {
  11. public function rules()
  12. {
  13. return [
  14. [['title','hid','odiscount','recommend'],'required','message'=>'{attribute}不能为空'],
  15. ['is_show','default','value'=>2],
  16. ['is_show','in','range'=>[1,2]],
  17. ['del','in','range'=>[1,2]],
  18. ['is_num','in','range'=>[1,2]],
  19. ['type','in','range'=>[1,2]],
  20. ['img','string','max'=>40],
  21. ['tel','string','max'=>15],
  22. [['uid','click','click_true','attend_num'],'number'],
  23. ['introduce','string'],
  24. ['satisfaction','number'],
  25. [['start_at','end_at'],'date', 'format'=>'yyyy-mm-dd HH:mm:ss','message'=>'时间格式为:1990-01-01 00:00:00'],
  26. ];
  27. }
  28. public function attributeLabels()
  29. {
  30. return [
  31. 'title'=>'标题',
  32. // 'description'=>'描述',
  33. 'author'=>'作者',
  34. 'odiscount'=>'优惠说明',
  35. 'recommend'=>'推荐理由',
  36. 'start_at'=>'开始时间',
  37. 'end_at'=>'结束时间',
  38. 'tel'=>'电话',
  39. 'hid'=>'楼盘',
  40. 'img'=>'缩略图',
  41. 'attend_num'=>'参团人数',
  42. 'type'=>'标签',
  43. 'is_num'=>'标识',//标识单个楼盘还是多个楼盘
  44. 'click'=>'点击数',
  45. 'click_true'=>'真实点击数',
  46. 'uid'=>'添加人',
  47. ];
  48. }
  49. public function Authenticator($input)
  50. {
  51. $this->load($input,'');
  52. if(!$this->validate()) return $this->errors;
  53. return $this;
  54. }
  55. public function FindById($id)
  56. {
  57. return self::findOne($id);
  58. }
  59. public function getList($data)
  60. {
  61. $query = $this->QueryFind();
  62. $query->select(['pfg_link.*','pfg_category_city.city_name','pfg_sysmenu_q.name as sys_name']);
  63. $query = $this->LeftJoinWhere($query);
  64. $query = $this->LeftJoinTable($query);
  65. if(!empty($data['page']))
  66. {
  67. $query->offset = ($data['page'] - 1) * $data['limit'];
  68. $query->limit = $data['limit'];
  69. }
  70. return $query->orderBy('create_at')->asArray()->all();
  71. }
  72. public function Total()
  73. {
  74. $query = $this->QueryFind();
  75. $query = $this->LeftJoinWhere($query);
  76. $query = $this->LeftJoinTable($query);
  77. return $query->count();
  78. }
  79. private function LeftJoinWhere($query)
  80. {
  81. $query->andWhere(['pfg_link.del'=>$this->setDel]);
  82. return $query;
  83. }
  84. private function LeftJoinTable($query)
  85. {
  86. $query->leftJoin('pfg_category_city','pfg_link.city = pfg_category_city.id');
  87. $query->leftJoin('pfg_sysmenu_q','pfg_link.linktype = pfg_sysmenu_q.id');
  88. return $query;
  89. }
  90. private function QueryFind()
  91. {
  92. return self::find();
  93. }
  94. }