City.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * @package merchant
  4. * @Author: Qinii
  5. * @Date: 2020/5/6
  6. * @Time: 14:37
  7. */
  8. namespace app\controller\merchant\store\shipping;
  9. use app\common\repositories\user\UserAddressRepository;
  10. use think\App;
  11. use crmeb\basic\BaseController;
  12. use app\common\repositories\store\shipping\CityRepository as repository;
  13. use think\facade\Db;
  14. class City extends BaseController
  15. {
  16. protected $repository;
  17. /**
  18. * City constructor.
  19. * @param App $app
  20. * @param repository $repository
  21. */
  22. public function __construct(App $app, repository $repository)
  23. {
  24. parent::__construct($app);
  25. $this->repository = $repository;
  26. }
  27. /**
  28. * @Author:Qinii
  29. * @Date: 2020/5/8
  30. * @Time: 14:40
  31. * @return mixed
  32. */
  33. public function lst()
  34. {
  35. return app('json')->success($this->repository->getFormatList([['is_show', '=', 1],['level','<',2]]));
  36. }
  37. /**
  38. * @return mixed
  39. * @author Qinii
  40. */
  41. public function getlist()
  42. {
  43. return app('json')->success($this->repository->getFormatList(['is_show' => 1]));
  44. }
  45. public function newgetlist(){
  46. $regions = Db::name('regions') -> field('id,name,pid') -> select() -> toArray();
  47. return app('json')->success(formatCategory($regions));
  48. }
  49. public function newList()
  50. {
  51. $regions = Db::name('regions')
  52. ->where('level', '<=', 2)
  53. ->field('id,name,pid')
  54. ->select()
  55. ->toArray();
  56. return app('json')->success(formatCategory($regions));
  57. }
  58. public function getNewFiveList()
  59. {
  60. $code_list=[];
  61. $area_list = Db::name('area_manage')->cache('area_manage',3600)->column('code_list');
  62. foreach ($area_list as $area) {
  63. $area = explode(',', $area);
  64. $code_list[] = end($area);
  65. }
  66. $pid = $this->request->param('pid',0);//上级地区id
  67. $regions = Db::name('regions_new')->field('id,name,pid')->where('pid', $pid)->select()
  68. ->each(function ($item) use ($code_list) {
  69. $item['is_exist_area'] = (int)in_array($item['id'], $code_list);
  70. if($item['name']=='其他')
  71. $item['is_exist_area'] =1;
  72. return $item;
  73. })->toArray();
  74. return app('json')->success($regions);
  75. }
  76. /**
  77. * 默认地址是否是五级地址
  78. * @return mixed
  79. */
  80. public function getDefaultisFive()
  81. {
  82. $uid = $this->request->param('uid', 0);//上级地区id
  83. $addressRepository = app()->make(UserAddressRepository::class);
  84. $address = $addressRepository->getWhere(['uid' => $uid, 'is_default' => 1]);
  85. if (empty($address))
  86. return app('json')->success(['is_five' => 0]);
  87. if (empty($address['village_id']))
  88. return app('json')->success(['is_five' => 0]);
  89. return app('json')->success(['is_five' => 1]);
  90. }
  91. }