JsController.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2020-09-15
  6. * Time: 11:25
  7. */
  8. namespace api\js\controller;
  9. use api\js\model\JsModel;
  10. use api\js\model\JsOrderModel;
  11. use api\js\model\JsScoreModel;
  12. use cmf\controller\RestBaseController;
  13. use think\Db;
  14. class JsController extends RestBaseController
  15. {
  16. public function getList()
  17. {
  18. $lat = $this->request->param('lat',1);//维度
  19. $lng = $this->request->param('lng',1);//经度
  20. $lat = $lat > 1 ? $lat :37.475375;
  21. $lng = $lng > 1 ? $lng :121.373573;
  22. $jsModel = new JsModel();
  23. $category_id = $this->request->param('category_id');
  24. $project_id = $this->request->param('project_id');
  25. $isss = $this->request->param('isss');
  26. $isyy = $this->request->param('isyy');
  27. $sex = $this->request->param('sex');
  28. $page = $this->request->param('page',1);
  29. $paixu = $this->request->param('paixu','asc');
  30. $name = $this->request->param('name');
  31. $js_ids = [];
  32. $list = [];
  33. if($category_id){
  34. $js_id_list = Db::name('js_category_relevancy')->where('category_id',$category_id)->field('js_id')->select();
  35. foreach ($js_id_list as $value){
  36. $js_ids[] = $value['js_id'];
  37. }
  38. if(!$js_ids){
  39. $this->success('ok',$list);
  40. }
  41. }
  42. if($project_id){
  43. $js_project_category_id = Db::name('js_project_category')->where('id',$project_id)->value('id');
  44. $project_ids = Db::name('js_project_category_relevancy')->where('category_id',$js_project_category_id)->field('project_id')->select();
  45. $project_new_ids = [];
  46. foreach ($project_ids as $v){
  47. if(!in_array($v['project_id'],$project_new_ids)){
  48. array_push($project_new_ids,$v['project_id']);
  49. }
  50. }
  51. $js_id_list = Db::name('js_project_relevancy')->where('project_id','in',$project_new_ids)->field('js_id')->group('js_id')->select();
  52. foreach ($js_id_list as $value){
  53. $js_ids[] = $value['js_id'];
  54. }
  55. if(!$js_ids){
  56. $this->success('ok',$list);
  57. }
  58. }
  59. if($isss){
  60. $js_id_list = JsModel::where(['is_real_time'=>1])->field('id')->select();
  61. foreach ($js_id_list as $value){
  62. $js_ids[] = $value['id'];
  63. }
  64. if(!$js_ids){
  65. $this->success('ok',$list);
  66. }
  67. }
  68. if($isyy){
  69. $js_id_list = JsModel::where(['is_make'=>1])->field('id')->select();
  70. foreach ($js_id_list as $value){
  71. $js_ids[] = $value['id'];
  72. }
  73. if(!$js_ids){
  74. $this->success('ok',$list);
  75. }
  76. }
  77. if($sex){
  78. $js_id_list = JsModel::where(['sex'=>$sex])->field('id')->select();
  79. foreach ($js_id_list as $value){
  80. $js_ids[] = $value['id'];
  81. }
  82. if(!$js_ids){
  83. $this->success('ok',$list);
  84. }
  85. }
  86. if($name){
  87. $testModel = new JsModel();
  88. $js_id_list = $testModel->where('name','like',"%{$name}%")->field('id')->select();
  89. foreach ($js_id_list as $value){
  90. $js_ids[] = $value['id'];
  91. }
  92. if(!$js_ids){
  93. $this->success('ok',$list);
  94. }
  95. }
  96. $list = $jsModel->getLits($js_ids,$lat,$lng,$page);
  97. $len = count($list);
  98. for ($i = 1;$i < $len; $i++){
  99. for ($k = 0; $k < $len-$i;$k++){
  100. if($paixu == 'asc' ||$paixu == ''){
  101. if($list[$k]['distance'] > $list[$k+1]['distance']){
  102. $array = $list[$k+1];
  103. $list[$k+1] = $list[$k];
  104. $list[$k] = $array;
  105. }
  106. }else{
  107. if($list[$k]['distance'] < $list[$k+1]['distance']){
  108. $array = $list[$k+1];
  109. $list[$k+1] = $list[$k];
  110. $list[$k] = $array;
  111. }
  112. }
  113. }
  114. }
  115. for ($i = 1;$i < $len; $i++){
  116. for ($k = 0; $k < $len-$i;$k++){
  117. if(!$list[$k]['shangban']){
  118. $array = $list[$k+1];
  119. $list[$k+1] = $list[$k];
  120. $list[$k] = $array;
  121. }
  122. }
  123. }
  124. $this->success('ok',$list);
  125. }
  126. public function getInfo()
  127. {
  128. $id = $this->request->param('js_id');
  129. if(!$id){
  130. $this->error('参数错误!');
  131. }
  132. $lat = $this->request->param('lat');//维度
  133. $lng = $this->request->param('lng');//经度
  134. // $lat = $lat > 1 ? $lat :37.475375;
  135. // $lng = $lng > 1 ? $lng :121.373573;
  136. $district = $this->request->param('district');
  137. $xlng = $this->request->param('xlng');
  138. $xlat = $this->request->param('xlat');
  139. if(!$lng && !$lat){
  140. $this->success('没有获取经纬度',[]);
  141. }
  142. // else{
  143. // $res = getdistrict($lng,$lat);
  144. // if($res['status'] == 0){
  145. // $this->success('经纬度不正确',[]);
  146. // }else{
  147. // $district = $res['regeocode']['addressComponent']['district'];
  148. // }
  149. // }
  150. $JsModel = new JsModel();
  151. $info = $JsModel->getInfo($id,$lat,$lng,$district);
  152. $info['phone'] = null;
  153. $info['identity'] = [];
  154. $this->success('ok',$info);
  155. }
  156. public function getJsScore()
  157. {
  158. $js_id = $this->request->param('js_id');
  159. $JsScoreModel = new JsScoreModel();
  160. $page = $this->request->param('page',1);
  161. $list = $JsScoreModel->getList($js_id,$page);
  162. $this->success('ok',$list);
  163. }
  164. }