CommonController.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shaoguo
  5. * Date: 2020/4/24
  6. * Time: 3:31 PM
  7. */
  8. namespace app\web\controller;
  9. use model\Community;
  10. use model\HouseInfo;
  11. use model\UserInfo;
  12. use service\DepartmentService;
  13. use service\HouseMemberService;
  14. use service\HouseService;
  15. use service\PositionService;
  16. use think\Controller;
  17. use think\helper\Arr;
  18. class CommonController extends Controller
  19. {
  20. public function province(){
  21. return json([
  22. 'code'=>200,
  23. 'data'=>db('provinces')->where(['code'=>"32"])->field('code,name')->select()
  24. ]);
  25. }
  26. public function city(){
  27. $code=$this->request->param('code');
  28. return json([
  29. 'code'=>200,
  30. 'data'=>db('cities')->where('province_code',$code)->where('code',3205)->field('code,name')->select()
  31. ]);
  32. }
  33. public function area(){
  34. $code=$this->request->param('code');
  35. return json([
  36. 'code'=>200,
  37. 'data'=>db('areas')->where('city_code',$code)->field('code,name')->select()
  38. ]);
  39. }
  40. public function street(){
  41. $code=$this->request->param('code');
  42. return json([
  43. 'code'=>200,
  44. 'data'=>db('streets')->where('area_code',$code)->field('code,name')->select()
  45. ]);
  46. }
  47. public function village(){
  48. $code=$this->request->param('code');
  49. return json([
  50. 'code'=>200,
  51. 'data'=>db('villages')->where('street_code',$code)->field('code,name')->select()
  52. ]);
  53. }
  54. public function community(){
  55. $data=$this->request->get();
  56. $where[]=array('is_delete','=',0);
  57. if(isset($data['code']) && !empty($data['code'])){
  58. $where[]=['province_code|city_code|areas_code|street_code|village_code','=',$data['code']];
  59. }
  60. if(isset($data['id']) && !empty($data['id']))$where[]=['id','=',$data['id']];
  61. $communities=Community::where($where)->select();
  62. return json([
  63. 'code'=>200,
  64. 'data'=>$communities
  65. ]);
  66. }
  67. /**
  68. * @name 获取家庭
  69. */
  70. public function getHouse(){
  71. $where[]=['House.is_delete','=',0];
  72. $data=$this->request->param();
  73. if(isset($data['keyword']) && !empty($data['keyword'])){
  74. $where[]=['House.name','like','%'.$data['keyword'].'%'];
  75. }
  76. $lists=HouseService::get($where,"id,name",['House.create_time'=>'desc'],'',true);
  77. $count=HouseService::get($where,"id,name",['House.create_time'=>'desc'])->count();
  78. $result['item']=$lists->items();
  79. $result['count']=$count;
  80. $result = [
  81. 'code' => 1,
  82. 'msg' => 'ok',
  83. 'time' => time(),
  84. 'data' => $result,
  85. ];
  86. return json($result,200);
  87. }
  88. /**
  89. * @name 获取家庭
  90. */
  91. public function getInfo(){
  92. $where[]=['is_delete','=',0];
  93. $data=$this->request->param();
  94. if(isset($data['keyword']) && !empty($data['keyword'])){
  95. $where[]=['name','like','%'.$data['keyword'].'%'];
  96. }
  97. $lists=HouseMemberService::get($where,"user_id as id,name",['create_time'=>'desc'],true);
  98. $count=HouseMemberService::get($where,"user_id as id,name",['create_time'=>'desc'])->count();
  99. $result['item']=$lists->items();
  100. $result['count']=$count;
  101. $result = [
  102. 'code' => 1,
  103. 'msg' => 'ok',
  104. 'time' => time(),
  105. 'data' => $result,
  106. ];
  107. return json($result,200);
  108. }
  109. /**
  110. * @name 获取员工
  111. */
  112. public function user_info(){
  113. $with_where=array();
  114. $data=$this->request->param();
  115. if(isset($data['id']) && !empty($data['id']))$with_where[]=['pivot.department_id','=',$data['id']];
  116. $userinfos=DepartmentService::getOne([['id','=',$data['id']]])->userInfo;
  117. $result = [
  118. 'code' => 1,
  119. 'msg' => 'ok',
  120. 'time' => time(),
  121. 'data' => $userinfos,
  122. ];
  123. return json($result,200);
  124. }
  125. public function position(){
  126. $id=$this->request->param('id');
  127. $where=array(['delete_time','=',0]);
  128. if(!empty($id)){
  129. $where[]=['id','in',$id];
  130. }
  131. $positions=PositionService::get($where);
  132. $result = [
  133. 'code' => 1,
  134. 'msg' => 'ok',
  135. 'time' => time(),
  136. 'data' => $positions,
  137. ];
  138. return json($result,200);
  139. }
  140. }