Browse Source

Wesmiler 三勾多商户商城提交

wesmiler 4 years ago
parent
commit
3cfc455004

+ 18 - 0
app/api/common.php

@@ -1,2 +1,20 @@
 <?php
 // 应用公共文件
+if (!function_exists('getPreview')) {
+    /**
+     * 图片资源预览地址
+     * @param $url 原始地址
+     * @return null|string|string[]
+     */
+    function getPreview($url){
+        if ($url) {
+            $host = request()->header('host');
+            $url = preg_match("/^(http|https):\/\//", trim($url,'//')) ? $url : '//'.$host . '/' . ltrim($url, '/');
+        }
+        $url = $url? preg_replace("/^(https|http):\/\//", '//', $url) : '';
+        if(preg_match("/127.0|localhost/", $host) && $url){
+            $url = preg_replace("/^\/\//", 'http://', $url);
+        }
+        return $url;
+    }
+}

+ 4 - 0
app/api/controller/Controller.php

@@ -71,6 +71,10 @@ class Controller extends JjjController
             }
             return false;
         }
+        // 格式化头像
+        if(isset($user['avatarUrl']) && $user['avatarUrl']){
+            $user['avatarUrl'] = getPreview($user['avatarUrl']);
+        }
         if ($user['is_delete'] == 1) {
             throw new BaseException(['msg' => '没有找到用户信息', 'code' => -2]);
             Cache::delete($token);

+ 1 - 0
app/api/controller/Index.php

@@ -8,6 +8,7 @@ use app\common\enum\settings\SettingEnum;
 use app\common\model\app\AppUpdate as AppUpdateModel;
 use app\common\model\supplier\Service as ServiceModel;
 use app\api\model\plus\chat\Chat as ChatModel;
+use think\facade\Cache;
 
 /**
  * 页面控制器

+ 16 - 0
app/api/controller/store/Store.php

@@ -29,6 +29,22 @@ class Store extends Controller
     }
 
     /**
+     * 选择门店列表
+     */
+    public function choiceLists($longitude = '', $latitude = '', $url = '', $shop_supplier_id = 0)
+    {
+        $model = new StoreModel;
+        $list = $model->getChoiceLists(true, $longitude, $latitude, false, $shop_supplier_id);
+        $signPackage = '';
+        if($url != ''){
+            $app = AppMp::getApp($this->app_id);
+            $app->jssdk->setUrl($url);
+            $signPackage = $app->jssdk->buildConfig(array('getLocation', 'openLocation'), false);
+        }
+        return $this->renderSuccess('', compact('list', 'signPackage'));
+    }
+
+    /**
      * 门店详情
      */
     public function detail($store_id)

+ 4 - 4
app/api/model/plus/seckill/Product.php

@@ -100,15 +100,15 @@ class Product extends SeckillProductModel
             ->limit($limit)
             ->visible(['product.product_id','product.product_name','product.file_path'])
             ->select();
-
+        $list = $list? $list->toArray() : [];
         foreach ($list as $product) {
-            $seckill_arr = array_column($product['seckillSku']->toArray(), 'seckill_price');
-            $product_arr = array_column($product['seckillSku']->toArray(), 'product_price');
+            $seckill_arr = array_column($product['seckillSku'], 'seckill_price');
+            $product_arr = array_column($product['seckillSku'], 'product_price');
             sort($seckill_arr);
             sort($product_arr);
             $product['seckill_price'] =  current($seckill_arr);
             $product['product_price'] =  current($product_arr);
-            $product['product']['file_path'] = $product['product']['image'][0]['file_path'];
+            $product['product']['file_path'] = isset($product['product']['image'])?$product['product']['image'][0]['file_path'] : '';
             unset($product['seckillSku']);
             unset($product['product']['image']);
         }

+ 81 - 14
app/api/model/store/Store.php

@@ -3,6 +3,8 @@
 namespace app\api\model\store;
 
 use app\common\model\store\Store as StoreModel;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+use think\Db;
 
 /**
  * 商家门店模型
@@ -37,10 +39,62 @@ class Store extends StoreModel
             ->order(['sort' => 'asc', 'create_time' => 'desc'])
             ->select();
         // 根据距离排序
+        return $this->sortByDistance($data, $longitude, $latitude);
+    }
+
+    /**
+     * 获取平台门店列表
+     */
+    public function getChoiceLists($is_check = null, $longitude = '', $latitude = '', $limit = false, $shop_supplier_id = 0)
+    {
+        $model = $this;
+        // 是否支持自提核销
+        $is_check && $model = $model->where('is_check', '=', $is_check);
+        // 商家id
+        $shop_supplier_id && $model = $model->where('shop_supplier_id', '=', $shop_supplier_id);
+        // 获取数量
+        $limit != false && $model = $model->limit($limit);
+        $distanceSql = '';
+        $sort = ['sort' => 'asc', 'create_time' => 'desc'];
         if (!empty($longitude) && !empty($latitude)) {
-            return $this->sortByDistance($data, $longitude, $latitude);
+            $fieldSql = "*,".\think\facade\Db::Raw("(6378.138 * 2 * asin(sqrt(pow(sin((latitude * pi() / 180 - " . $latitude . " * pi() / 180) / 2),2) + cos(latitude * pi() / 180) * cos(" . $latitude . " * pi() / 180) * pow(sin((longitude * pi() / 180 - " . $longitude . " * pi() / 180) / 2),2))) * 1000) as distance");
+            $sort['distance'] = 'asc';
+        }else {
+            $fieldSql = '*';
         }
-        return $data;
+
+        // 获取门店列表数据
+        $list = $model->with(['logo'])
+            ->with('supplier')
+            ->where('is_delete', '=', '0')
+            ->where('status', '=', '1')
+            ->field($fieldSql)
+            ->order($sort)
+            ->paginate()
+            ->each(function ($store, $k){
+                $store['distance'] = round($store['distance'], 3);
+                $store['shop_business'] = 0;
+                $shop_hours = isset($store['shop_hours'])? $store['shop_hours'] : '';
+                $shop_hours = explode('~', $shop_hours);
+                $start = isset($shop_hours[0])? $shop_hours[0] : '';
+                $end = isset($shop_hours[1])? $shop_hours[1] : '';
+                if($start && date('H:i') >= $start){
+                    if($end && date('H:i') <= $end || empty($end)){
+                        $store['shop_business'] = 1;
+                    }
+                }
+                if($store['distance'] > 0){
+                    if ($store['distance'] >= 1000) {
+                        $distance = bcdiv($store['distance'], 1000, 2);
+                        $store['distance_unit'] = $distance . 'km';
+                    } else
+                        $store['distance_unit'] = round($store['distance'], 2) . 'm';
+                }else{
+                    $store['distance_unit'] = '未知';
+                }
+            });
+
+        return $list;
     }
 
     /**
@@ -52,19 +106,32 @@ class Store extends StoreModel
         $list = $data->isEmpty() ? [] : $data->toArray();
         $sortArr = [];
         foreach ($list as &$store) {
-            // 计算距离
-            $distance = self::getDistance($longitude, $latitude, $store['longitude'], $store['latitude']);
-            // 排序列
-            $sortArr[] = $distance;
-            $store['distance'] = $distance;
-            if ($distance >= 1000) {
-                $distance = bcdiv($distance, 1000, 2);
-                $store['distance_unit'] = $distance . 'km';
-            } else
-                $store['distance_unit'] = $distance . 'm';
+            /* $logo_image_id = isset($store['logo_image_id'])? $store['logo_image_id'] : 0;
+             $store['logo_image'] = '';
+             if($logo_image_id){
+                 $store['logo_image'] =
+             }*/
+
+            if (!empty($longitude) && !empty($latitude)) {
+                // 计算距离
+                $distance = self::getDistance($longitude, $latitude, $store['longitude'], $store['latitude']);
+                // 排序列
+                $sortArr[] = $distance;
+                $store['distance'] = $distance;
+                if ($distance >= 1000) {
+                    $distance = bcdiv($distance, 1000, 2);
+                    $store['distance_unit'] = $distance . 'km';
+                } else
+                    $store['distance_unit'] = $distance . 'm';
+            } else {
+                $store['distance'] = '0.00';
+                $store['distance_unit'] = '未知';
+            }
+        }
+        if (!empty($longitude) && !empty($latitude)) {
+            // 根据距离排序
+            array_multisort($sortArr, SORT_ASC, $list);
         }
-        // 根据距离排序
-        array_multisort($sortArr, SORT_ASC, $list);
         return $list;
     }
 

+ 3 - 2
app/api/model/user/User.php

@@ -51,9 +51,10 @@ class User extends UserModel
         $userInfo = json_decode(htmlspecialchars_decode($post['user_info']), true);
 
         $reg_source = $post['source'];
-        $user_id = $this->register($session['openid'], $userInfo, $refereeId, $session, $reg_source);
+        $openid = isset($session['openid'])? $session['openid'] : '';
+        $user_id = $this->register($openid, $userInfo, $refereeId, $session, $reg_source);
         // 生成token (session3rd)
-        $this->token = $this->token($session['openid']);
+        $this->token = $this->token($openid);
         // 记录缓存, 7天
         Cache::tag('cache')->set($this->token, $user_id, 86400 * 7);
         return $user_id;

+ 1 - 0
app/api/model/user/UserOpen.php

@@ -126,6 +126,7 @@ class UserOpen extends UserModel
             ->where('password', '=', md5($data['password']))
             ->order('user_id desc')
             ->find();
+
         if (!$user) {
             $this->error = '手机号或密码错误';
             return false;

+ 2 - 2
app/common/model/page/Page.php

@@ -76,12 +76,12 @@ class Page extends BaseModel
                 ],
                 'data' => [
                     [
-                        'imgUrl' => self::$base_url . 'image/diy/banner/01.png',
+                        'imgUrl' => self::$base_url . 'image/diy/banner/01.jpg',
                         'imgName' => 'image-1.jpg',
                         'linkUrl' => ''
                     ],
                     [
-                        'imgUrl' => self::$base_url . 'image/diy/banner/01.png',
+                        'imgUrl' => self::$base_url . 'image/diy/banner/01.jpg',
                         'imgName' => 'banner-2.jpg',
                         'linkUrl' => ''
                     ]

+ 76 - 46
app/common/model/settings/Setting.php

@@ -40,39 +40,41 @@ class Setting extends BaseModel
     {
         $data = self::getAll($app_id);
         $data_key = $data[$key];
-        if(isset($data_key)){
+        if (isset($data_key)) {
             $data_key = $data[$key]['values'];
             jsonRecursive($data_key);
-        }else{
+        } else {
             $data_key = [];
         }
         return $data_key;
     }
-   /**
+
+    /**
      * 获取系统配置
      */
     public static function getSysConfig()
     {
         $model = new static;
         $result = $model->withoutGlobalScope()->where('key', '=', SettingEnum::SYS_CONFIG)->value('values');
-        if(!$result){
+        if (!$result) {
             $result = $model->defaultData()[SettingEnum::SYS_CONFIG]['values'];
-        }else{
-            $result = json_decode($result,true); 
+        } else {
+            $result = json_decode($result, true);
         }
         return $result;
     }
-     /**
+
+    /**
      * 获取指定项设置
      */
     public static function getSupplierItem($key, $shop_supplier_id, $app_id = null)
     {
         $data = self::getAll($app_id, $shop_supplier_id);
         $data_key = $data[$key];
-        if(isset($data_key)){
+        if (isset($data_key)) {
             $data_key = $data[$key]['values'];
             jsonRecursive($data_key);
-        }else{
+        } else {
             $data_key = [];
         }
 
@@ -82,10 +84,10 @@ class Setting extends BaseModel
     /**
      * 获取设置项信息
      */
-    public static function detail($key,$shop_supplier_id=0)
-    {   
+    public static function detail($key, $shop_supplier_id = 0)
+    {
         $where = [];
-        if($shop_supplier_id){
+        if ($shop_supplier_id) {
             $where['shop_supplier_id'] = $shop_supplier_id;
         }
 
@@ -102,7 +104,7 @@ class Setting extends BaseModel
         if (!$data = Cache::get('setting_' . $app_id . '_' . $shop_supplier_id)) {
             $setting = $static->where(compact('app_id'))->where('shop_supplier_id', $shop_supplier_id)->select();
             $data = empty($setting) ? [] : array_column($static->collection($setting)->toArray(), null, 'key');
-            Cache::tag('cache')->set('setting_' . $app_id. '_' .$shop_supplier_id, $data);
+            Cache::tag('cache')->set('setting_' . $app_id . '_' . $shop_supplier_id, $data);
         }
         return $static->getMergeData($data);
     }
@@ -137,7 +139,8 @@ class Setting extends BaseModel
     /**
      * 店铺是否开启
      */
-    public static function getStoreOpen(){
+    public static function getStoreOpen()
+    {
         $data = (new static())->getItem(SettingEnum::BOTTOMNAV);
         return $data['menu_type'] == 1;
     }
@@ -146,7 +149,7 @@ class Setting extends BaseModel
      * 默认配置
      */
     public function defaultData($storeName = null)
-    {   
+    {
         $url = base_url();
         return [
             'store' => [
@@ -242,7 +245,7 @@ class Setting extends BaseModel
                         'aliyun' => [
                             'AccessKeyId' => '',
                             'AccessKeySecret' => '',
-                            'sign' => '三勾商城',
+                            'sign' => '小程序商城',
                             'login_template' => '',
                             'apply_template' => '',
                             'supplier_reject_code' => '',
@@ -434,7 +437,7 @@ class Setting extends BaseModel
                     // 显示区域
                     'area_type' => [],
                     // 不再提示天数
-                   'send_day' => 7
+                    'send_day' => 7
                 ],
             ],
             'live' => [
@@ -446,7 +449,7 @@ class Setting extends BaseModel
                     //是否开启审核
                     'is_audit' => '1',
                     //礼物名称
-                    'gift_name'=>'玖币',
+                    'gift_name' => '玖币',
                     // appid
                     'sdkappid' => '',
                     // key
@@ -486,19 +489,19 @@ class Setting extends BaseModel
                 'key' => 'nav',
                 'describe' => '底部导航',
                 'values' => [
-                    'data'=>[
-                    "type"=>0,
-                    "backgroundColor"=>"#FFFFFF",
-                    "textColor"=>"#000000",
-                    "textHoverColor"=>"#E2231A",
-                    "bulge"=>"true",
-                    "list"=>[
-                    ["iconPath"=>$url."image/diy/navbar/home.png","text"=>"首页","is_show"=>"true","selectedIconPath"=>$url."image/diy/navbar/home-on.png","link"=>["wap_url"=>"/pages/index/index"]],
-                    ["iconPath"=>$url."image/diy/navbar/fl.png","text"=>"分类","is_show"=>"true","selectedIconPath"=>$url."image/diy/navbar/fl-on.png","link"=>["wap_url"=>"/pages/product/category"]],
-                    ["iconPath"=>$url."image/diy/navbar/store.png","text"=>"店铺","is_show"=>"true","selectedIconPath"=>$url."image/diy/navbar/store-on.png","link"=>["wap_url"=>"/pages/shop/shop_list"]],
-                    ["iconPath"=>$url."image/diy/navbar/cart.png","text"=>"购物车","is_show"=>"true","selectedIconPath"=>$url."image/diy/navbar/cart-on.png","link"=>["wap_url"=>"/pages/cart/cart"]],
-                    ["iconPath"=>$url."image/diy/navbar/wode.png","text"=>"我的","is_show"=>"true","selectedIconPath"=>$url."image/diy/navbar/wode-on.png","link"=>["wap_url"=>"/pages/user/index/index"]]
-                    ]
+                    'data' => [
+                        "type" => 0,
+                        "backgroundColor" => "#FFFFFF",
+                        "textColor" => "#000000",
+                        "textHoverColor" => "#E2231A",
+                        "bulge" => "true",
+                        "list" => [
+                            ["iconPath" => $url . "image/diy/navbar/home.png", "text" => "首页", "is_show" => "true", "selectedIconPath" => $url . "image/diy/navbar/home-on.png", "link" => ["wap_url" => "/pages/index/index"]],
+                            ["iconPath" => $url . "image/diy/navbar/fl.png", "text" => "分类", "is_show" => "true", "selectedIconPath" => $url . "image/diy/navbar/fl-on.png", "link" => ["wap_url" => "/pages/product/category"]],
+                            ["iconPath" => $url . "image/diy/navbar/store.png", "text" => "店铺", "is_show" => "true", "selectedIconPath" => $url . "image/diy/navbar/store-on.png", "link" => ["wap_url" => "/pages/shop/shop_list"]],
+                            ["iconPath" => $url . "image/diy/navbar/cart.png", "text" => "购物车", "is_show" => "true", "selectedIconPath" => $url . "image/diy/navbar/cart-on.png", "link" => ["wap_url" => "/pages/cart/cart"]],
+                            ["iconPath" => $url . "image/diy/navbar/wode.png", "text" => "我的", "is_show" => "true", "selectedIconPath" => $url . "image/diy/navbar/wode-on.png", "link" => ["wap_url" => "/pages/user/index/index"]]
+                        ]
                     ]
                 ]
             ],
@@ -506,9 +509,9 @@ class Setting extends BaseModel
                 'key' => 'sys_config',
                 'describe' => '系统设置',
                 'values' => [
-                    'shop_name' => '三勾商城管理系统',
+                    'shop_name' => '商城管理系统',
                     'shop_bg_img' => '',
-                    'supplier_name' => '三勾商城供应商管理系统',
+                    'supplier_name' => '商城供应商管理系统',
                     'supplier_bg_img' => '',
                     'url' => 'wss://',
                     'service_open' => 0,
@@ -526,7 +529,7 @@ class Setting extends BaseModel
                     'min_money' => 1,
                     // 充值说明
                     'describe' => "a) 账户充值仅限在线方式支付,充值金额实时到账;\n" .
-                        "b) 有问题请联系客服;\n" ,
+                        "b) 有问题请联系客服;\n",
                 ]
             ],
             'h5Alipay' => [
@@ -558,38 +561,65 @@ class Setting extends BaseModel
                         [
                             'index' => 0,
                             'text' => '首页',
-                            'iconPath' => self::$base_url .'image/tabbar/home.png',
-                            'selectedIconPath' => self::$base_url .'image/tabbar/home_active.png',
+                            'iconPath' => self::$base_url . 'image/tabbar/shop.png',
+                            'selectedIconPath' => self::$base_url . 'image/tabbar/shop_active.png',
+                        ],
+                        [
+                            'index' => 1,
+                            'text' => '商品',
+                            'iconPath' => self::$base_url . 'image/tabbar/goods.png',
+                            'selectedIconPath' => self::$base_url . 'image/tabbar/goods_active.png',
+                        ],
+                        [
+                            'index' => 3,
+                            'text' => '购物车',
+                            'iconPath' => self::$base_url . 'image/tabbar/cart.png',
+                            'selectedIconPath' => self::$base_url . 'image/tabbar/cart_active.png',
+                        ],
+                        [
+                            'index' => 4,
+                            'text' => '我的',
+                            'iconPath' => self::$base_url . 'image/tabbar/user.png',
+                            'selectedIconPath' => self::$base_url . 'image/tabbar/user_active.png',
+                        ],
+                    ],
+
+                    'menus1' => [
+                        [
+                            'index' => 0,
+                            'text' => '首页',
+                            'iconPath' => self::$base_url . 'image/tabbar/home.png',
+                            'selectedIconPath' => self::$base_url . 'image/tabbar/home_active.png',
                         ],
                         [
                             'index' => 1,
                             'text' => '分类',
-                            'iconPath' => self::$base_url .'image/tabbar/category.png',
-                            'selectedIconPath' => self::$base_url .'image/tabbar/category_active.png',
+                            'iconPath' => self::$base_url . 'image/tabbar/category.png',
+                            'selectedIconPath' => self::$base_url . 'image/tabbar/category_active.png',
                         ],
                         [
                             'index' => 2,
                             'text' => '店铺',
-                            'iconPath' => self::$base_url .'image/tabbar/shop.png',
-                            'selectedIconPath' => self::$base_url .'image/tabbar/shop_active.png',
+                            'iconPath' => self::$base_url . 'image/tabbar/shop.png',
+                            'selectedIconPath' => self::$base_url . 'image/tabbar/shop_active.png',
                         ],
                         [
                             'index' => 3,
                             'text' => '购物车',
-                            'iconPath' => self::$base_url .'image/tabbar/cart.png',
-                            'selectedIconPath' => self::$base_url .'image/tabbar/cart_active.png',
+                            'iconPath' => self::$base_url . 'image/tabbar/cart.png',
+                            'selectedIconPath' => self::$base_url . 'image/tabbar/cart_active.png',
                         ],
                         [
                             'index' => 4,
                             'text' => '我的',
-                            'iconPath' => self::$base_url .'image/tabbar/user.png',
-                            'selectedIconPath' => self::$base_url .'image/tabbar/user_active.png',
+                            'iconPath' => self::$base_url . 'image/tabbar/user.png',
+                            'selectedIconPath' => self::$base_url . 'image/tabbar/user_active.png',
                         ],
                         [
                             'index' => 5,
                             'text' => '订单',
-                            'iconPath' => self::$base_url .'image/tabbar/order.png',
-                            'selectedIconPath' => self::$base_url .'image/tabbar/order_active.png',
+                            'iconPath' => self::$base_url . 'image/tabbar/order.png',
+                            'selectedIconPath' => self::$base_url . 'image/tabbar/order_active.png',
                         ],
                     ]
                 ]