Kaynağa Gözat

商家联盟

lizhen 1 hafta önce
ebeveyn
işleme
f3fb1ba0be
2 değiştirilmiş dosya ile 77 ekleme ve 1 silme
  1. 74 0
      application/api/controller/Store.php
  2. 3 1
      application/common.php

+ 74 - 0
application/api/controller/Store.php

@@ -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);
+    }
+}

+ 3 - 1
application/common.php

@@ -569,7 +569,9 @@ if (!function_exists('localpath_to_netpath')) {
         } elseif (strrpos($path, 'http') !== false) {
             return $path;
         } else {
-            return config('upload.cdnurl') . str_replace("\\", "/", $path);
+            $cdnurl = config('upload.cdnurl');
+            $cdnurl = $cdnurl ? $cdnurl : 'http://' . $_SERVER['HTTP_HOST'];
+            return $cdnurl . str_replace("\\", "/", $path);
         }
     }
 }