Area.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\common\model\base\other;
  3. /**
  4. * @title : 行政区域模型
  5. * @desc :
  6. * @Author : Rock
  7. * @Date : 2021-11-27 19:49:28
  8. * @LastEditTime : 2021-11-28 11:44:30
  9. */
  10. use app\common\model\Common;
  11. class Area extends Common{
  12. protected $name = "system_area";
  13. protected $pk = 'id';
  14. protected $append = [
  15. 'hasChildren',
  16. 'pname',
  17. 'pathName',
  18. 'common_txt'
  19. ];
  20. public function getHasChildrenAttr($value,$data)
  21. {
  22. $value = $value ? $value : (isset($data['id']) ? $data['id'] : '');
  23. $where = [];
  24. $where[] = ['pid','=',$value];
  25. $where[] = ['level','<',3];
  26. $where[] = ['name','NOT IN',['市辖区','县']];
  27. $info = self::where($where)->find();
  28. return !empty($info);
  29. }
  30. public function getPnameAttr($value,$data)
  31. {
  32. $value = $value ? $value : (isset($data['pid']) ? $data['pid'] : '');
  33. $info = self::where('id',$value)->field(['name'=>'title'])->find();
  34. return $info?$info['title']:'';
  35. }
  36. public function getPathNameAttr($value,$data)
  37. {
  38. $value = $value ? $value : (isset($data['path']) ? $data['path'] : '');
  39. if(!empty($value)){
  40. $pathids = explode(',',$value);
  41. $list = self::where('id','IN',$pathids)->field(['name'=>'title'])->select()->toArray();
  42. return implode(',',array_column($list,'title'));
  43. }else{
  44. return '';
  45. }
  46. }
  47. public function commonList()
  48. {
  49. return [0=>'不常用',1=>'常用'];
  50. }
  51. public function getCommonTxtAttr($value,$data)
  52. {
  53. $value = $value ? $value : (isset($data['common']) ? $data['common'] : 0);
  54. $info = $this->commonList();
  55. return $info[$value];
  56. }
  57. }