PushFreshcity.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 PushFreshcity extends Common
  10. {
  11. public function rules()
  12. {
  13. return [
  14. ['city_id','number','message'=>'请输入正确的区域信息'],
  15. ['sort','number','message'=>'排序只能是数字'],
  16. ['sort','number','max'=>10000],
  17. ];
  18. }
  19. public function attributeLabels()
  20. {
  21. return [
  22. 'city_id'=>'区域',
  23. ];
  24. }
  25. public function Authenticator($input)
  26. {
  27. $this->load($input,'');
  28. if(!$this->validate()) return $this->errors;
  29. return $this;
  30. }
  31. public function FindById($id)
  32. {
  33. return self::findOne($id);
  34. }
  35. public function getList($input)
  36. {
  37. $query = self::find();
  38. $query->select(['pfg_push_freshcity.img','pfg_push_freshcity.city_id','pfg_push_freshcity.id','pfg_category_city.city_name','pfg_push_freshcity.create_at','pfg_push_freshcity.is_show','pfg_push_freshcity.sort']);
  39. $query->andWhere(['pfg_push_freshcity.del'=>$this->setDel]);
  40. if(!empty($input['city_name']))
  41. {
  42. $query->andWhere(['like','pfg_category_city.city_name',$input['city_name']]);
  43. }
  44. if(!empty($input['city_id']))
  45. {
  46. $query->andWhere(['pfg_push_city.city_id'=>$input['city_id']]);
  47. }
  48. $query->leftJoin('pfg_category_city','pfg_push_freshcity.city_id=pfg_category_city.id');
  49. if(!empty($input['page']))
  50. {
  51. $query->limit = $input['limit'];
  52. $query->offset = ($input['page']-1 )* $input['limit'];
  53. }
  54. return $query->orderBy(['pfg_push_freshcity.create_at'=>SORT_DESC])->asArray()->all();
  55. }
  56. public function WhereColumn($query)
  57. {
  58. }
  59. public function Total()
  60. {
  61. $query = self::find();
  62. $query->andWhere(['pfg_push_freshcity.del'=>$this->setDel]);
  63. $query->leftJoin('pfg_category_city','pfg_push_freshcity.city_id=pfg_category_city.id');
  64. return $query->count();
  65. }
  66. public function Homegetlist()
  67. {
  68. $query = self::find();
  69. $query->select(['pfg_category_city.id','pfg_category_city.city_name','pfg_push_freshcity.img']);
  70. $query->andWhere(['pfg_push_freshcity.del'=>$this->setDel]);
  71. $query->andWhere(['pfg_push_freshcity.is_show'=>1]);
  72. $query->leftJoin('pfg_category_city','pfg_push_freshcity.city_id=pfg_category_city.id');
  73. $query->orderBy(['pfg_push_freshcity.sort'=>SORT_ASC]);
  74. $query->limit = 10;
  75. return $query->asArray()->all();
  76. }
  77. }