PushmbController.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace backend\controllers;
  3. use backend\base\CommonController;
  4. use backend\base\Help;
  5. use common\models\CategoryCity;
  6. use Yii;
  7. class PushmbController extends CommonController
  8. {
  9. public function actionCity()
  10. {
  11. return $this->render('city');
  12. }
  13. public function actionCityform()
  14. {
  15. $row = $this->City();
  16. if ($row != null){
  17. return Help::JsonData(0,Yii::t('app','get_success'),0,$row);
  18. }
  19. return Help::JsonCode(Help::ERROR,Yii::t('app','get_error'));
  20. }
  21. private function City()
  22. {
  23. $model = CategoryCity::find()
  24. ->select(['id','city_name'])
  25. ->andWhere(['pid'=>0,'level'=>1])
  26. ->andWhere(['del'=>1,'abroad'=>1])
  27. ->orderBy(['sort'=>SORT_DESC,'id'=>SORT_DESC])
  28. ->asArray()->all();
  29. $model_haiwai = CategoryCity::find()
  30. ->select(['id'])
  31. ->andWhere(['pid'=>0,'level'=>1])
  32. ->andWhere(['del'=>1,'abroad'=>2])
  33. ->column();
  34. $haiwai = [
  35. 'id'=>$model_haiwai,
  36. 'city_name'=>'海外',
  37. ];
  38. $model[] = $haiwai;
  39. if ($model != null)
  40. {
  41. foreach ($model as &$val) {
  42. $val['son'] = CategoryCity::find()
  43. ->select(['id'])
  44. ->andWhere(['pid'=>$val['id'],'level'=>2,'del'=>1])
  45. ->orderBy(['sort'=>SORT_DESC,'id'=>SORT_DESC])
  46. ->column();
  47. }
  48. }
  49. return $model;
  50. }
  51. }