JsProjectController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2020-09-07
  6. * Time: 14:38
  7. */
  8. namespace api\js\controller;
  9. use api\js\model\JsModel;
  10. use api\js\model\JsProjectModel;
  11. use cmf\controller\RestBaseController;
  12. use think\Db;
  13. use api\js\model\RegionModel;
  14. class JsProjectController extends RestBaseController
  15. {
  16. /**
  17. * @throws \think\db\exception\DataNotFoundException
  18. * @throws \think\db\exception\ModelNotFoundException
  19. * @throws \think\exception\DbException
  20. * 获取分类列表
  21. */
  22. public function getList()
  23. {
  24. $where = [];
  25. $JsProjectModel = new JsProjectModel();
  26. $categoryId = $this->request->param('category_id');
  27. $page = $this->request->param('page',1);
  28. $district = $this->request->param('district');
  29. $xlng = $this->request->param('xlng');
  30. $xlat = $this->request->param('xlat');
  31. $lng = $this->request->param('lng');
  32. $lat = $this->request->param('lat');
  33. $lat = isset($xlat) ? $xlat : $lat;
  34. $lng = isset($xlng) ? $xlng : $lng;
  35. // if($lat && $lng) {
  36. // $res = getdistrict($xlng, $xlat);
  37. // if ($res['status'] == 0) {
  38. // $this->success('经纬度不正确', []);
  39. // } else {
  40. // $district = $res['regeocode']['addressComponent']['district'];
  41. // }
  42. // }
  43. // $district = isset($district) ? $district : $district1;
  44. $RegionModel = new RegionModel();
  45. $serviceId = $RegionModel->getId($district);
  46. if($categoryId){
  47. $projectIds = Db::name('js_project_category_relevancy')->where('category_id',$categoryId)->field('project_id')->select();
  48. $project_id = [];
  49. foreach ($projectIds as $vo){
  50. $project_id[] = $vo['project_id'];
  51. }
  52. if($project_id){
  53. $where = $project_id;
  54. }else{
  55. $list = [];
  56. $this->success('ok',$list);
  57. }
  58. }
  59. $name = $this->request->param('name');
  60. $user_id = $this->userId;
  61. $js_id = 0;
  62. if($user_id){
  63. $JsModel = new JsModel();
  64. $js_id = $JsModel->where('user_id',$user_id)->value('id');
  65. }
  66. $list = $JsProjectModel->getList($name,$where,$page,$serviceId,$js_id);
  67. $this->success('ok',$list);
  68. }
  69. public function getInfo()
  70. {
  71. $id = $this->request->param('id');
  72. $district= $this->request->param('district');
  73. $xlng = $this->request->param('xlng');
  74. $xlat = $this->request->param('xlat');
  75. $lng = $this->request->param('lng');
  76. $lat = $this->request->param('lat');
  77. $lat = isset($xlat) ? $xlat : $lat;
  78. $lng = isset($xlng) ? $xlng : $lng;
  79. // if($lng && $lat){
  80. // $res = getdistrict($lng,$lat);
  81. // if($res['status'] == 0){
  82. // $this->success('经纬度不正确',[]);
  83. // }else{
  84. // $district = $res['regeocode']['addressComponent']['district'];
  85. // }
  86. // }
  87. // $district = isset($district) ? $district : $district1;
  88. $JsProjectModel = new JsProjectModel();
  89. $info = $JsProjectModel->getInfo($id,$district);
  90. $this->success('ok',$info);
  91. }
  92. }