口腔客户管理系统
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

District.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class District extends Model
  5. {
  6. // public function city()
  7. // {
  8. // $result = $this->where('level', '1')->field('adcode as value,name as label')->select();
  9. //// foreach ($result as $k => $v) {
  10. //// $result[$k]['city_id'] = $result[$k]['adcode'];
  11. //// unset($result[$k]['id']);
  12. //// }
  13. // $result = ['rows' => $result];
  14. // return $result;
  15. // }
  16. public function getChildren($adcode)
  17. {
  18. return $this->where('parent_id', $adcode)->field('adcode as value,name as label')->select();
  19. }
  20. private static function getChildren2($adcode)
  21. {
  22. // $arr = $this->where('parent_id',$adcode)->field('adcode as value,name as label')->select();
  23. $arr = \think\Db::name('district')->where('parent_id', $adcode)->field('adcode as value,name as label')->select();
  24. foreach ($arr as $k => $v) {
  25. // var_dump($v['value']);
  26. $arr[$k]['children'] = self::getChildren2($v['value']);
  27. if (!$arr[$k]['children']) {
  28. unset($arr[$k]['children']);
  29. }
  30. }
  31. return $arr;
  32. }
  33. public function province()
  34. {
  35. $result = $this->where('level', '1')->field('adcode as value,name as label')->select();
  36. // $result_a= $this->District();
  37. foreach ($result as $k => $v) {
  38. $result[$k]['children'] = self::getChildren($v['value']);
  39. // $result[$k]['children']=$result_a;
  40. }
  41. $result = ['rows' => $result];
  42. return $result;
  43. }
  44. public function area()
  45. {
  46. $result = $this->where('level', '1')->field('adcode as value,name as label')->select();
  47. // $result_a= $this->District();
  48. foreach ($result as $k => $v) {
  49. $result[$k]['children'] = self::getChildren2($v['value']);
  50. // $result[$k]['children']=$result_a;
  51. }
  52. $result = ['rows' => $result];
  53. return $result;
  54. }
  55. /* public function District()
  56. {
  57. $result = $this->where('level','2')->field('adcode as value,name as label')->select();
  58. foreach ($result as $k => $v) {
  59. $result[$k]['children'] = $this->getChildren($v['value']);
  60. // $result[$k]['District'] = $this->District();
  61. }
  62. // $result = ['children' => $result];
  63. return $result;
  64. }*/
  65. // public function getAll($param, $page, $pageSize)
  66. // {
  67. // unset($param['page']);
  68. // unset($param['pageSize']);
  69. // $result = $this->where($param)->limit($page, $pageSize)->select();
  70. // $total = $this->where($param)->count();
  71. // return ['rows' => $result, 'total' => $total];
  72. // }
  73. //
  74. // public function read($param)
  75. // {
  76. // $result = $this->where($this->getPk(), $param[$this->getPk()])->find();
  77. // if (isset($result[$this->getPk()])) {
  78. // return $result->toArray();
  79. // } else {
  80. // return [];
  81. // }
  82. // }
  83. }