SystemCity.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\admin\model\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 DESC');
  30. }
  31. public static function getList($where = [])
  32. {
  33. $list = self::withAttr('parent_id', function($value, $data) {
  34. if($value == 0){
  35. return '中国';
  36. }else{
  37. return self::where('city_id',$value)->value('name');
  38. }
  39. })->where('parent_id', $where['parent_id'])->select()->toArray();
  40. return $list;
  41. }
  42. }