SystemCity.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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\model\shipping;
  12. use crmeb\basic\BaseModel;
  13. use crmeb\traits\ModelTrait;
  14. use think\Model;
  15. /**
  16. * 城市数据
  17. * Class SystemCity
  18. * @package app\model\shipping
  19. */
  20. class SystemCity extends BaseModel
  21. {
  22. use ModelTrait;
  23. /**
  24. * 数据表主键
  25. * @var string
  26. */
  27. protected $pk = 'id';
  28. /**
  29. * 模型名称
  30. * @var string
  31. */
  32. protected $name = 'system_city';
  33. /**
  34. * 获取子集分类查询条件
  35. * @return \think\model\relation\HasMany
  36. */
  37. public function children()
  38. {
  39. return $this->hasMany(self::class, 'parent_id', 'city_id')->order('id ASC');
  40. }
  41. /**
  42. * city搜索器
  43. * @param Model $query
  44. * @param $value
  45. */
  46. public function searchCityIdAttr($query, $value)
  47. {
  48. if (is_array($value)) {
  49. $query->whereIn('city_id', $value);
  50. } else {
  51. $query->where('city_id', $value);
  52. }
  53. }
  54. /**
  55. * ParentId搜索器
  56. * @param Model $query
  57. * @param $value
  58. */
  59. public function searchParentIdAttr($query, $value)
  60. {
  61. $query->where('parent_id', $value);
  62. }
  63. }