|
@@ -0,0 +1,74 @@
|
|
|
|
+<?php
|
|
|
|
+
|
|
|
|
+namespace app\api\controller;
|
|
|
|
+
|
|
|
|
+use app\common\controller\Api;
|
|
|
|
+use think\Db;
|
|
|
|
+/**
|
|
|
|
+ * 商家联盟
|
|
|
|
+ */
|
|
|
|
+class Store extends Api
|
|
|
|
+{
|
|
|
|
+ protected $noNeedLogin = ['*'];
|
|
|
|
+ protected $noNeedRight = ['*'];
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //分类
|
|
|
|
+ public function category(){
|
|
|
|
+ $list = Db::name('store_category')->field('id, name')->where('status',1)->order('weigh', 'desc')->select();
|
|
|
|
+
|
|
|
|
+ $this->success(1,$list);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //店铺列表
|
|
|
|
+ public function store_list(){
|
|
|
|
+ $category_id = input('category_id',0,'intval');
|
|
|
|
+ $longitude = input('longitude',0,'trim');
|
|
|
|
+ $latitude = input('latitude',0,'trim');
|
|
|
|
+
|
|
|
|
+ $where = [];
|
|
|
|
+ if($category_id){
|
|
|
|
+ $where['category_id'] = $category_id;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $field = ['id', 'name', 'image', 'longitude', 'latitude'];
|
|
|
|
+ $field[] = '(st_distance(point (' . $longitude . ', ' . $latitude . '),point(longitude,latitude))*111195) as distance';
|
|
|
|
+
|
|
|
|
+ $list = Db::name('store')->field($field)
|
|
|
|
+ ->where('status',1)->where($where)
|
|
|
|
+ ->order('weigh', 'desc')->select();
|
|
|
|
+ $list = list_domain_image($list, ['image']);
|
|
|
|
+
|
|
|
|
+ foreach($list as $k=>$v){
|
|
|
|
+ $v['distance'] = bcdiv(intval($v['distance']),1000,1).'km';
|
|
|
|
+
|
|
|
|
+ if($longitude == 0 || $v['longitude'] == 0){
|
|
|
|
+ $v['distance'] = '未知';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $list[$k] = $v;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $this->success(1,$list);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //店铺详情
|
|
|
|
+ public function store_detail(){
|
|
|
|
+ $id = input('id',0,'intval');
|
|
|
|
+ $longitude = input('longitude',0,'trim');
|
|
|
|
+ $latitude = input('latitude',0,'trim');
|
|
|
|
+
|
|
|
|
+ $field = ['*'];
|
|
|
|
+ $field[] = '(st_distance(point (' . $longitude . ', ' . $latitude . '),point(longitude,latitude))*111195) as distance';
|
|
|
|
+
|
|
|
|
+ $info = Db::name('store')->field($field)->where('id',$id)->find();
|
|
|
|
+ $info = info_domain_image($info, ['image','images']);
|
|
|
|
+
|
|
|
|
+ $info['distance'] = bcdiv(intval($info['distance']),1000,1).'km';
|
|
|
|
+ if($longitude == 0 || $info['longitude'] == 0){
|
|
|
|
+ $info['distance'] = '未知';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $this->success(1,$info);
|
|
|
|
+ }
|
|
|
|
+}
|