PushmCity.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/5/21
  6. * Time: 下午5:18
  7. */
  8. namespace common\models;
  9. class PushmCity extends Common
  10. {
  11. public function rules()
  12. {
  13. return [
  14. ['city_id', 'unique', 'targetClass' => 'common\models\PushmCity','on'=>['add'],'message'=>'该区域已存在','filter'=>function($query){
  15. $query->andWhere(['del'=>$this->setDel]);
  16. return $query->andWhere(['type'=>$this->type]);
  17. }],
  18. ['city_id','number','message'=>'请选择区域'],
  19. ['type','number'],
  20. ['abroad','number'],
  21. ['url','string','max'=>255],
  22. ['title','string','max'=>50],
  23. // ['city_id','each','rule'=>['integer'],'message'=>'请输入正确的区域信息'],
  24. ['sort','number','message'=>'排序只能是数字'],
  25. ['sort','number','max'=>10000],
  26. ];
  27. }
  28. public function attributeLabels()
  29. {
  30. return [
  31. 'sort'=>'排序',
  32. 'title'=>'标题',
  33. ];
  34. }
  35. public function Authenticator($input)
  36. {
  37. $this->load($input,'');
  38. if(!$this->validate()) return $this->errors;
  39. return $this;
  40. }
  41. public function FindById($id)
  42. {
  43. return self::findOne($id);
  44. }
  45. public function getList($input)
  46. {
  47. $query = self::find();
  48. $query->select(['pfg_pushm_city.url','pfg_pushm_city.title','pfg_pushm_city.id','pfg_category_city.city_name','pfg_pushm_city.create_at','pfg_pushm_city.is_show','pfg_pushm_city.sort','pfg_pushm_city.img']);
  49. $query->andWhere(['pfg_pushm_city.del'=>$this->setDel]);
  50. if(!empty($input['city_name']))
  51. {
  52. $query->andWhere(['like','pfg_category_city.city_name',$input['city_name']]);
  53. }
  54. if(!empty($input['city_id']))
  55. {
  56. $query->andWhere(['pfg_pushm_city.city_id'=>$input['city_id']]);
  57. }
  58. $query->andFilterWhere(['pfg_pushm_city.type'=>$this->type]);
  59. $query->leftJoin('pfg_category_city','pfg_pushm_city.city_id=pfg_category_city.id');
  60. if(!empty($input['page']))
  61. {
  62. $query->limit = $input['limit'];
  63. $query->offset = ($input['page']-1 )* $input['limit'];
  64. }
  65. return $query->orderBy(['pfg_pushm_city.sort'=>SORT_ASC])->asArray()->all();
  66. }
  67. public function WhereColumn($query)
  68. {
  69. }
  70. public function Total()
  71. {
  72. $query = self::find();
  73. $query->andWhere(['pfg_pushm_city.del'=>$this->setDel]);
  74. $query->andFilterWhere(['pfg_pushm_city.type'=>$this->type]);
  75. $query->leftJoin('pfg_category_city','pfg_pushm_city.city_id=pfg_category_city.id');
  76. return $query->count();
  77. }
  78. public function Homegetlist($limit)
  79. {
  80. $query = self::find();
  81. $query->select(['pfg_category_city.id','pfg_category_city.city_name','pfg_pushm_city.img','pfg_pushm_city.url','pfg_pushm_city.title','pfg_pushm_city.abroad']);
  82. $query->andWhere(['pfg_pushm_city.del'=>$this->setDel]);
  83. $query->andWhere(['pfg_pushm_city.is_show'=>1]);
  84. $query->andFilterWhere(['pfg_pushm_city.type'=>$this->type]);
  85. $query->leftJoin('pfg_category_city','pfg_pushm_city.city_id=pfg_category_city.id');
  86. $query->orderBy(['pfg_pushm_city.sort'=>SORT_DESC]);
  87. $query->limit = $limit;
  88. return $query->asArray()->all();
  89. }
  90. /*
  91. * 返回区域的随机电话号码
  92. * */
  93. public function RandFind()
  94. {
  95. $query = self::find();
  96. $query->andWhere(['pfg_pushm_city.del'=>$this->setDel]);
  97. $query->andWhere(['pfg_pushm_city.is_show'=>1]);
  98. $query->andFilterWhere(['pfg_pushm_city.type'=>$this->type]);
  99. return $query->orderBy('RAND()')->one();
  100. }
  101. public function Homelist($limit)
  102. {
  103. $query = self::find();
  104. $query->select(['pfg_category_city.id','pfg_category_city.city_name','pfg_pushm_city.img','pfg_pushm_city.url','pfg_pushm_city.title','pfg_pushm_city.abroad']);
  105. $query->andWhere(['pfg_pushm_city.del'=>$this->setDel]);
  106. $query->andWhere(['pfg_pushm_city.is_show'=>1]);
  107. $query->andFilterWhere(['pfg_pushm_city.type'=>$this->type]);
  108. $query->andFilterWhere(['pfg_pushm_city.abroad'=>$this->abroad]);
  109. $query->leftJoin('pfg_category_city','pfg_pushm_city.city_id=pfg_category_city.id');
  110. $query->orderBy(['pfg_pushm_city.sort'=>SORT_DESC]);
  111. $query->limit = $limit;
  112. return $query->asArray()->all();
  113. }
  114. }