where("store_id=" . $id . " and isstop=0 ") ->where($where) ->order('pickup_id desc') ->select(); if ($list) { $count = count($list); $dos = null; foreach ($list as $k => $v) { $x1 = $v['lon']; $y1 = $v['lat']; $distance = sqrt(($x1 - $lx) * ($x1 - $lx) + ($y1 - $ly) * ($y1 - $ly)); $list[$k]['distance'] = round($distance, 2); //和定位点的距离 $v['province'] = $rglist[$v['province_id']]['name']; $v['city'] = $rglist[$v['city_id']]['name']; $v['district'] = $rglist[$v['district_id']]['name']; $list[$k]['address'] = $v['province'] . $v['city'] . $v['district'] . $v['pickup_address']; $dos[$k] = $list[$k]['distance']; } array_multisort($dos, SORT_ASC, $list); $pagesize = 10;//C('PAGESIZE'); //每页显示数 $p = I('p/d', 1); $fir = ($p - 1) * $pagesize; $end = $p * $pagesize; if ($end > $count) { $end = $count; } $returnlist = null; if ($fir < $count) { for ($i = $fir; $i < $end; $i++) { $returnlist[] = $list[$i]; } } } if (empty($returnlist)) { $jsonlist['state'] = "0"; $jsonlist['msg'] = '找不到相数据'; } else { $jsonlist['state'] = "1"; $jsonlist['msg'] = '成功'; } $jsonlist['item'] = $returnlist; //门店分类 $storetype = M('storage_category')->where(array('store_id' => $id, 'is_show' => 1))->order('sort asc')->select(); $this->assign('storetype', $storetype); $this->assign('list', $returnlist); if (I('is_ajax')) { return json($jsonlist); } upload_ylp_log('门店列表'); return $this->fetch('', getMobileStoId()); } public function storesinfo() { $getstoid = getMobileStoId(); $getid = I('id/d'); if ($getid) { $infolist = DB::name('pick_up') ->field(['a.*', 'b.name' => 'province', 'c.name' => 'city', 'd.name' => 'district']) ->alias('a') ->join('wxd_region b', 'a.province_id=b.id', 'left') ->join('wxd_region c', 'a.city_id=c.id', 'left') ->join('wxd_region d', 'a.district_id=d.id', 'left') ->where(" store_id=" . $getstoid . " and isstop=0 and pickup_id=" . $getid) ->find(); } $this->assign('infolist', $infolist); upload_ylp_log('门店详细'); return $this->fetch('', getMobileStoId()); } //门店搜索 public function searchstores() { //门店分类 $getstoid=getMobileStoId(); $storetype = M('storage_category')->where(array('store_id' => $getstoid, 'is_show' => 1))->order('sort asc')->select(); $this->assign('storetype', $storetype); return $this->fetch('', getMobileStoId()); } public function storespage() { $pagenum = 10;//C('PAGESIZE'); //每页显示数 $p = I('p/d', 1); $id = getMobileStoId(); $lx = I('lx'); $ly = I('ly'); $where = ""; $getkey = I('key'); $storetype = I('storetype'); if ($getkey) { $where['pickup_name'] = array('like', '%' . htmlspecialchars($getkey) . '%'); } if ($storetype) { $where['category_id'] = $storetype; } $count = M('pick_up')->where($where)->count(); $Page = $pager = new Page($count,$pagenum); $list = M('pick_up') ->where("store_id=" . $id . " and isstop=0 ") ->where($where) ->field('*,st_distance (POINT (lat,lon),POINT('.$ly.','.$lx.')) * 111195 AS distance') ->order('distance asc,pickup_id asc') ->limit($Page->firstRow.','.$Page->listRows)->select(); if (empty($list)) { $jsonlist['state'] = "0"; $jsonlist['msg'] = '找不到相数据'; return json($jsonlist); } foreach ($list as $k => $v) { $list[$k]['address'] = $v['fulladdress']; } $jsonlist['state'] = "1"; $jsonlist['msg'] = '成功'; $jsonlist['item'] = $list; return json($jsonlist); } }