City.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 getNewFiveList()
  50. {
  51. $code_list=[];
  52. $area_list = Db::name('area_manage')->cache('area_manage',3600)->column('code_list');
  53. foreach ($area_list as $area) {
  54. $area = explode(',', $area);
  55. $code_list[] = end($area);
  56. }
  57. $pid = $this->request->param('pid',0);//上级地区id
  58. $regions = Db::name('regions_new')->field('id,name,pid')->where('pid', $pid)->select()
  59. ->each(function ($item) use ($code_list) {
  60. $item['is_exist_area'] = (int)in_array($item['id'], $code_list);
  61. if($item['name']=='其他')
  62. $item['is_exist_area'] =1;
  63. return $item;
  64. })->toArray();
  65. return app('json')->success($regions);
  66. }
  67. /**
  68. * 默认地址是否是五级地址
  69. * @return mixed
  70. */
  71. public function getDefaultisFive()
  72. {
  73. $uid = $this->request->param('uid', 0);//上级地区id
  74. $addressRepository = app()->make(UserAddressRepository::class);
  75. $address = $addressRepository->getWhere(['uid' => $uid, 'is_default' => 1]);
  76. if (empty($address))
  77. return app('json')->success(['is_five' => 0]);
  78. if (empty($address['village_id']))
  79. return app('json')->success(['is_five' => 0]);
  80. return app('json')->success(['is_five' => 1]);
  81. }
  82. }