SystemCityDao.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\dao\shipping;
  12. use app\dao\BaseDao;
  13. use app\model\shipping\SystemCity;
  14. /**
  15. * 城市数据
  16. * Class SystemCityDao
  17. * @package app\dao\shipping
  18. */
  19. class SystemCityDao extends BaseDao
  20. {
  21. /**
  22. * 设置模型
  23. * @return string
  24. */
  25. protected function setModel(): string
  26. {
  27. return SystemCity::class;
  28. }
  29. /**
  30. * 获取城市数据列表
  31. * @param array $where
  32. * @return array
  33. * @throws \think\db\exception\DataNotFoundException
  34. * @throws \think\db\exception\DbException
  35. * @throws \think\db\exception\ModelNotFoundException
  36. */
  37. public function getCityList(array $where, string $field = '*')
  38. {
  39. return $this->search($where)->field($field)->select()->toArray();
  40. }
  41. /**
  42. * 获取城市数据以数组形式返回
  43. * @param array $where
  44. * @param string $field
  45. * @param string $key
  46. * @return array
  47. */
  48. public function getCityArray(array $where, string $field, string $key)
  49. {
  50. return $this->search($where)->column($field, $key);
  51. }
  52. /**
  53. * 删除上级城市和当前城市id
  54. * @param int $cityId
  55. * @return bool
  56. * @throws \Exception
  57. */
  58. public function deleteCity(int $cityId)
  59. {
  60. return $this->getModel()->where('city_id', $cityId)->whereOr('parent_id', $cityId)->delete();
  61. }
  62. /**
  63. * 获取city_id的最大值
  64. * @return mixed
  65. */
  66. public function getCityIdMax()
  67. {
  68. return $this->getModel()->max('city_id');
  69. }
  70. /**
  71. * 获取运费模板城市选择
  72. * @return array
  73. * @throws \think\db\exception\DataNotFoundException
  74. * @throws \think\db\exception\DbException
  75. * @throws \think\db\exception\ModelNotFoundException
  76. */
  77. public function getShippingCity()
  78. {
  79. return $this->getModel()->with('children')->where('parent_id', 0)->order('id asc')->select()->toArray();
  80. }
  81. /**
  82. * 获取城市数据完整列表
  83. * @author 吴汐
  84. * @email 442384644@qq.com
  85. * @date 2023/04/10
  86. */
  87. public function fullList($field = '*')
  88. {
  89. return $this->getModel()->order('id asc')->field($field)->select()->toArray();
  90. }
  91. }