123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2020-09-15
- * Time: 11:25
- */
-
- namespace api\js\controller;
-
-
- use api\js\model\JsModel;
- use api\js\model\JsOrderModel;
- use api\js\model\JsScoreModel;
- use cmf\controller\RestBaseController;
- use think\Db;
- class JsController extends RestBaseController
- {
- public function getList()
- {
- $lat = $this->request->param('lat',1);//维度
- $lng = $this->request->param('lng',1);//经度
- $lat = $lat > 1 ? $lat :37.475375;
- $lng = $lng > 1 ? $lng :121.373573;
- $jsModel = new JsModel();
- $category_id = $this->request->param('category_id');
- $project_id = $this->request->param('project_id');
- $isss = $this->request->param('isss');
- $isyy = $this->request->param('isyy');
- $sex = $this->request->param('sex');
- $page = $this->request->param('page',1);
- $paixu = $this->request->param('paixu','asc');
- $name = $this->request->param('name');
- $js_ids = [];
- $list = [];
- if($category_id){
- $js_id_list = Db::name('js_category_relevancy')->where('category_id',$category_id)->field('js_id')->select();
- foreach ($js_id_list as $value){
- $js_ids[] = $value['js_id'];
- }
- if(!$js_ids){
- $this->success('ok',$list);
- }
- }
- if($project_id){
- $js_project_category_id = Db::name('js_project_category')->where('id',$project_id)->value('id');
- $project_ids = Db::name('js_project_category_relevancy')->where('category_id',$js_project_category_id)->field('project_id')->select();
- $project_new_ids = [];
- foreach ($project_ids as $v){
- if(!in_array($v['project_id'],$project_new_ids)){
- array_push($project_new_ids,$v['project_id']);
- }
-
- }
- $js_id_list = Db::name('js_project_relevancy')->where('project_id','in',$project_new_ids)->field('js_id')->group('js_id')->select();
- foreach ($js_id_list as $value){
- $js_ids[] = $value['js_id'];
- }
- if(!$js_ids){
- $this->success('ok',$list);
- }
- }
-
-
- if($isss){
- $js_id_list = JsModel::where(['is_real_time'=>1])->field('id')->select();
- foreach ($js_id_list as $value){
- $js_ids[] = $value['id'];
- }
- if(!$js_ids){
- $this->success('ok',$list);
- }
- }
- if($isyy){
- $js_id_list = JsModel::where(['is_make'=>1])->field('id')->select();
- foreach ($js_id_list as $value){
- $js_ids[] = $value['id'];
- }
- if(!$js_ids){
- $this->success('ok',$list);
- }
- }
- if($sex){
- $js_id_list = JsModel::where(['sex'=>$sex])->field('id')->select();
- foreach ($js_id_list as $value){
- $js_ids[] = $value['id'];
- }
- if(!$js_ids){
- $this->success('ok',$list);
- }
- }
- if($name){
- $testModel = new JsModel();
- $js_id_list = $testModel->where('name','like',"%{$name}%")->field('id')->select();
- foreach ($js_id_list as $value){
- $js_ids[] = $value['id'];
- }
- if(!$js_ids){
- $this->success('ok',$list);
- }
- }
-
- $list = $jsModel->getLits($js_ids,$lat,$lng,$page);
- $len = count($list);
- for ($i = 1;$i < $len; $i++){
- for ($k = 0; $k < $len-$i;$k++){
- if($paixu == 'asc' ||$paixu == ''){
-
- if($list[$k]['distance'] > $list[$k+1]['distance']){
- $array = $list[$k+1];
- $list[$k+1] = $list[$k];
- $list[$k] = $array;
- }
- }else{
- if($list[$k]['distance'] < $list[$k+1]['distance']){
- $array = $list[$k+1];
- $list[$k+1] = $list[$k];
- $list[$k] = $array;
- }
- }
- }
- }
- for ($i = 1;$i < $len; $i++){
- for ($k = 0; $k < $len-$i;$k++){
- if(!$list[$k]['shangban']){
- $array = $list[$k+1];
- $list[$k+1] = $list[$k];
- $list[$k] = $array;
- }
-
- }
- }
-
- $this->success('ok',$list);
- }
-
- public function getInfo()
- {
- $id = $this->request->param('js_id');
- if(!$id){
- $this->error('参数错误!');
- }
- $lat = $this->request->param('lat');//维度
- $lng = $this->request->param('lng');//经度
- // $lat = $lat > 1 ? $lat :37.475375;
- // $lng = $lng > 1 ? $lng :121.373573;
- $district = $this->request->param('district');
- $xlng = $this->request->param('xlng');
- $xlat = $this->request->param('xlat');
- if(!$lng && !$lat){
- $this->success('没有获取经纬度',[]);
- }
- // else{
- // $res = getdistrict($lng,$lat);
- // if($res['status'] == 0){
- // $this->success('经纬度不正确',[]);
- // }else{
- // $district = $res['regeocode']['addressComponent']['district'];
- // }
- // }
- $JsModel = new JsModel();
- $info = $JsModel->getInfo($id,$lat,$lng,$district);
- $info['phone'] = null;
- $info['identity'] = [];
- $this->success('ok',$info);
- }
-
- public function getJsScore()
- {
- $js_id = $this->request->param('js_id');
- $JsScoreModel = new JsScoreModel();
- $page = $this->request->param('page',1);
- $list = $JsScoreModel->getList($js_id,$page);
- $this->success('ok',$list);
- }
- }
|