SystemCity.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\models\system;
  3. use crmeb\traits\ModelTrait;
  4. use crmeb\basic\BaseModel;
  5. /**
  6. * 菜单 model
  7. * Class SystemMenus
  8. * @package app\admin\model\system
  9. */
  10. class SystemCity extends BaseModel
  11. {
  12. /**
  13. * 数据表主键
  14. * @var string
  15. */
  16. protected $pk = 'id';
  17. /**
  18. * 模型名称
  19. * @var string
  20. */
  21. protected $name = 'system_city';
  22. use ModelTrait;
  23. /**
  24. * 获取子集分类查询条件
  25. * @return \think\model\relation\HasMany
  26. */
  27. public function children()
  28. {
  29. return $this->hasMany(self::class, 'parent_id','city_id')->order('id ASC');
  30. }
  31. /**
  32. * 获取城市数据列表
  33. * @param array $where
  34. * @return array
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\DbException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. */
  39. public static function getList($where = [])
  40. {
  41. $list = self::withAttr('parent_id', function($value) {
  42. if($value == 0){
  43. return '中国';
  44. }else{
  45. return self::where('city_id',$value)->value('name');
  46. }
  47. })->where('parent_id', $where['parent_id'])->select()->toArray();
  48. return $list;
  49. }
  50. }