作者 王智

1

... ... @@ -78,41 +78,57 @@ class Index extends Api
$params = $this->request->param();
//用户所在省市区
// $UserAddress = $this->getCity($params['lng'], $params['lat']);
$Map['address'] = ['LIKE', '%' . $params['city'] . '%'];
$MapKey = [];
if (!empty($params['keywords']) || $params['keywords'] != '' || $params['keywords'] != "" || $params['keywords'] != null) {
$MapKey['title'] = ['LIKE', '%' . $params['keywords'] . '%'];
}
$SellerArray = Db::name('seller')->where($Map)->where($MapKey)->where('status', 0)->select();
//首页轮播图
$IndexBanner = [];
$IndexBanner = Db::name('index_banner')->order('weigh desc')->field('id,image,web')->select();
if (!empty($IndexBanner)) {
foreach ($IndexBanner as $k => $v) {
$IndexBanner[$k]['image'] = $this->ImgUrl($v['image']);
if (empty($params['lng']) || $params['lng'] == '' || $params['lng'] == "" || $params['lng'] == null) {
//首页轮播图
$IndexBanner = [];
$IndexBanner = Db::name('index_banner')->order('weigh desc')->field('id,image,web')->select();
if (!empty($IndexBanner)) {
foreach ($IndexBanner as $k => $v) {
$IndexBanner[$k]['image'] = $this->ImgUrl($v['image']);
}
}
}
if (empty($SellerArray)) {
$data = [
'IndexBanner' => $IndexBanner,
'Count' => 0,
'List' => []
];
} else {
foreach ($SellerArray as $k => $v) {
$List[$k]['id'] = $v['id'];
$List[$k]['Image'] = $this->ImgUrl($v['image']);
$List[$k]['Title'] = $v['title'];
$List[$k]['Content'] = $v['content'];
$List[$k]['Form'] = $this->getDistance($params['lng'], $params['lat'], $v['lng'], $v['lat']);
$Map['address'] = ['LIKE', '%' . $params['city'] . '%'];
$MapKey = [];
if (!empty($params['keywords']) || $params['keywords'] != '' || $params['keywords'] != "" || $params['keywords'] != null) {
$MapKey['title'] = ['LIKE', '%' . $params['keywords'] . '%'];
}
$SellerArray = Db::name('seller')->where($Map)->where($MapKey)->where('status', 0)->select();
//首页轮播图
$IndexBanner = [];
$IndexBanner = Db::name('index_banner')->order('weigh desc')->field('id,image,web')->select();
if (!empty($IndexBanner)) {
foreach ($IndexBanner as $k => $v) {
$IndexBanner[$k]['image'] = $this->ImgUrl($v['image']);
}
}
if (empty($SellerArray)) {
$data = [
'IndexBanner' => $IndexBanner,
'Count' => 0,
'List' => []
];
} else {
foreach ($SellerArray as $k => $v) {
$List[$k]['id'] = $v['id'];
$List[$k]['Image'] = $this->ImgUrl($v['image']);
$List[$k]['Title'] = $v['title'];
$List[$k]['Content'] = $v['content'];
$List[$k]['Form'] = $this->getDistance($params['lng'], $params['lat'], $v['lng'], $v['lat']);
}
$newarr = array_column($List, 'Form');
array_multisort($newarr, SORT_ASC, $List);
$data = [
'IndexBanner' => $IndexBanner,
'Count' => count($SellerArray),
'List' => $this->page_array($params['rows'], $params['pages'], $List, 0)
];
}
$newarr = array_column($List, 'Form');
array_multisort($newarr, SORT_ASC, $List);
$data = [
'IndexBanner' => $IndexBanner,
'Count' => count($SellerArray),
'List' => $this->page_array($params['rows'], $params['pages'], $List, 0)
];
}
$this->success('成功', $data);
}
... ...