dever 3 years ago
parent
commit
2e059312ce

+ 132 - 0
app/content/database/feature.php

@@ -0,0 +1,132 @@
+<?php
+
+$status = Dever::config('base')->status;
+
+# 每页的数据量
+$page = 10;
+
+$share = array
+(
+    1 => '显示',
+    2 => '不显示',
+);
+
+$template = array
+(
+    1 => '图文',
+    2 => '视频',
+);
+
+# 常用的col
+$col = '*';
+
+return array
+(
+    # 表名
+    'name' => 'feature',
+    # 显示给用户看的名称
+    'lang' => '专题管理',
+    'order' => 99,
+
+    # 数据结构
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'list'      => true,
+        ),
+        
+        'name'      => array
+        (
+            'type'      => 'varchar-80',
+            'name'      => '标题-专题标题,同时也用于分享标题',
+            'default'   => '',
+            'desc'      => '标题',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'list'      => true,
+            'search'    => 'fulltext',
+            //增加预览
+            'preview'   => true,
+        ),
+
+        'desc'      => array
+        (
+            'type'      => 'varchar-500',
+            'name'      => '摘要-专题摘要,同时也用于分享内容',
+            'default'   => '',
+            'desc'      => '摘要',
+            'match'     => 'is_string',
+            'update'    => 'textarea',
+        ),
+
+        'content'       => array
+        (
+            'type'      => 'text-255',
+            'name'      => '内容',
+            'default'   => '',
+            'desc'      => '请输入内容',
+            'match'     => 'is_string',
+            'update'    => 'editor',
+            'key'       => '1',
+        ),
+
+        'state'     => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '状态',
+            'default'   => '1',
+            'desc'      => '请选择状态',
+            'match'     => 'is_numeric',
+        ),
+
+        'cdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '录入时间',
+            'match'     => array('is_numeric', time()),
+            'desc'      => '',
+            # 只有insert时才生效
+            'insert'    => true,
+        ),
+    ),
+    
+    # 管理功能
+    'manage' => array
+    (
+        //'insert' => false,
+        # 列表
+        'list_button' => array
+        (
+            //'edit' => array('预览', str_replace('https://api.', 'http://www.', Dever::url('main/preview.get?type=1'))),
+        ),
+    ),
+
+    # request 请求接口定义
+    'request' => array
+    (
+        'search' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'ids' => array('yes-id', 'in'),
+                'cate_id' => 'yes',
+                'name' => array('yes', 'like'),
+                'id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('reorder' => 'desc', 'pdate' => 'desc'),
+            'limit' => '0,1000',
+            'col' => 'name as name, id, id as value, "" as selected, "" as disabled|id',
+        ),
+
+        
+    ),
+);

+ 132 - 0
app/content/database/news.php

@@ -0,0 +1,132 @@
+<?php
+
+$status = Dever::config('base')->status;
+
+# 每页的数据量
+$page = 10;
+
+$share = array
+(
+    1 => '显示',
+    2 => '不显示',
+);
+
+$template = array
+(
+    1 => '图文',
+    2 => '视频',
+);
+
+# 常用的col
+$col = '*';
+
+return array
+(
+    # 表名
+    'name' => 'news',
+    # 显示给用户看的名称
+    'lang' => '文章管理',
+    'order' => 100,
+
+    # 数据结构
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'list'      => true,
+        ),
+        
+        'name'      => array
+        (
+            'type'      => 'varchar-80',
+            'name'      => '标题-文章标题,同时也用于分享标题',
+            'default'   => '',
+            'desc'      => '标题',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'list'      => true,
+            'search'    => 'fulltext',
+            //增加预览
+            'preview'   => true,
+        ),
+
+        'desc'      => array
+        (
+            'type'      => 'varchar-500',
+            'name'      => '摘要-文章摘要,同时也用于分享内容',
+            'default'   => '',
+            'desc'      => '摘要',
+            'match'     => 'is_string',
+            'update'    => 'textarea',
+        ),
+
+        'content'       => array
+        (
+            'type'      => 'text-255',
+            'name'      => '内容',
+            'default'   => '',
+            'desc'      => '请输入内容',
+            'match'     => 'is_string',
+            'update'    => 'editor',
+            'key'       => '1',
+        ),
+        
+        'state'     => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '状态',
+            'default'   => '1',
+            'desc'      => '请选择状态',
+            'match'     => 'is_numeric',
+        ),
+
+        'cdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '录入时间',
+            'match'     => array('is_numeric', time()),
+            'desc'      => '',
+            # 只有insert时才生效
+            'insert'    => true,
+        ),
+    ),
+    
+    # 管理功能
+    'manage' => array
+    (
+        //'insert' => false,
+        # 列表
+        'list_button' => array
+        (
+            //'edit' => array('预览', str_replace('https://api.', 'http://www.', Dever::url('main/preview.get?type=1'))),
+        ),
+    ),
+
+    # request 请求接口定义
+    'request' => array
+    (
+        'search' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'ids' => array('yes-id', 'in'),
+                'cate_id' => 'yes',
+                'name' => array('yes', 'like'),
+                'id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('reorder' => 'desc', 'pdate' => 'desc'),
+            'limit' => '0,1000',
+            'col' => 'name as name, id, id as value, "" as selected, "" as disabled|id',
+        ),
+
+        
+    ),
+);

+ 8 - 0
app/content/index.php

@@ -0,0 +1,8 @@
+<?php
+
+define('DEVER_APP_NAME', 'content');
+define('DEVER_APP_LANG', '内容管理');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+define('DEVER_MANAGE_ORDER', 200);
+define('DEVER_MANAGE_ICON', 'glyphicon glyphicon-tower layui-icon-tabs');
+include(DEVER_APP_PATH . '../boot.php');

+ 95 - 0
app/goods/database/column.php

@@ -0,0 +1,95 @@
+<?php
+
+return array
+(
+    # 表名
+    'name' => 'column',
+    # 显示给用户看的名称
+    'lang' => '栏目管理',
+    # 是否显示在后台菜单
+    'order' => 9,
+
+    # 数据结构
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'order'     => 'asc',
+            'list'      => true,
+        ),
+
+        'name'      => array
+        (
+            'type'      => 'varchar-150',
+            'name'      => '栏目名称',
+            'default'   => '',
+            'desc'      => '栏目名称',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+            'edit'      => true,
+        ),
+
+        'reorder'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '排序(数值越大越靠前)',
+            'default'   => '1',
+            'desc'      => '请输入排序',
+            'match'     => 'option',
+            'update'    => 'text',
+            'search'    => 'order',
+            'list_name' => '排序',
+            'list'      => true,
+            'order'     => 'desc',
+            'edit'      => true,
+        ),
+        
+        'state'     => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '状态',
+            'default'   => '1',
+            'desc'      => '请选择状态',
+            'match'     => 'is_numeric',
+        ),
+        
+        'cdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '录入时间',
+            'match'     => array('is_numeric', time()),
+            'desc'      => '',
+            # 只有insert时才生效
+            'insert'    => true,
+            'search'    => 'date',
+            'list'      => 'date("Y-m-d H:i:s", {cdate})',
+        ),
+    ),
+
+    'manage' => array
+    (
+
+    ),
+
+    # 默认值
+    'default' => array
+    (
+        'col' => 'name,state,cdate',
+        'value' => array
+        (
+            '"默认栏目",1,' . time(),
+        ),
+    ),
+
+    'request' => array
+    (
+        
+    )
+);

+ 67 - 4
app/goods/database/info.php

@@ -21,6 +21,17 @@ $yes = array
     2 => '否',
 );
 
+$column = function()
+{
+    $array = array();
+    $info = Dever::load('goods/column-state');
+    if($info)
+    {
+        $array += $info;
+    }
+    return $array;
+};
+
 $config = array
 (
     # 表名
@@ -47,6 +58,15 @@ $config = array
             'update' => array('category_id' => 'category'),
             # 同步更新的类型,delete为先删再插入,update为直接更新
             'type' => 'delete',
+        ),
+        'goods/info_column' => array
+        (
+            # 更新另外一个表的字段 => 本表的字段
+            'where' => array('info_id', 'id'),
+            # 要更新的数据
+            'update' => array('column_id' => 'column_id'),
+            # 同步更新的类型,delete为先删再插入,update为直接更新
+            'type' => 'delete',
         )
     ),
 
@@ -76,6 +96,18 @@ $config = array
             'edit'        => true,
         ),
 
+        'column_id'        => array
+        (
+            'type'      => 'varchar-8000',
+            'name'      => '栏目',
+            'default'   => '',
+            'desc'      => '所属项目',
+            'match'     => 'is_string',
+            'update'    => 'checkbox',
+            'option'    => $column,
+            //'list'      => true,
+        ),
+
         'category'      => array
         (
             'type'      => 'varchar-500',
@@ -227,12 +259,25 @@ $config = array
             'place'     => '750*422',
         ),
 
+        'hot'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '是否热门商品',
+            'default'   => '2',
+            'desc'      => '是否热门商品',
+            'match'     => 'is_numeric',
+            'update'    => 'radio',
+            'option'    => $yes,
+            'list'      => true,
+            'edit'      => true,
+        ),
+
         'top'      => array
         (
             'type'      => 'int-11',
-            'name'      => '是否人气推荐',
+            'name'      => '是否推荐商品',
             'default'   => '2',
-            'desc'      => '是否人气推荐',
+            'desc'      => '是否推荐商品',
             'match'     => 'is_numeric',
             'update'    => 'radio',
             'option'    => $yes,
@@ -247,9 +292,9 @@ $config = array
             'default'   => '2',
             'desc'      => '是否每日优惠',
             'match'     => 'is_numeric',
-            'update'    => 'radio',
+            //'update'    => 'radio',
             'option'    => $yes,
-            'list'      => true,
+            //'list'      => true,
             'edit'      => true,
         ),
 
@@ -397,6 +442,24 @@ $config = array
             'col' => 'name as name, id, id as value, "" as selected, "" as disabled|id',
         ),
 
+        # 推荐列表
+        'getTop' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'hot' => 'yes',
+                'top' => 'yes',
+                'youhui' => 'yes',
+                'status' => 1,
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('reorder' => 'desc', 'id' => 'desc'),
+            'limit' => '0,6',
+            'col' => '*,id as goods_id',
+        ),
+
         # 列表
         'getAll' => array
         (

+ 102 - 0
app/goods/database/info_column.php

@@ -0,0 +1,102 @@
+<?php
+
+return array
+(
+    # 表名
+    'name' => 'info_column',
+    # 显示给用户看的名称
+    'lang' => '商品栏目关联表',
+    'menu' => false,
+
+    # 数据结构
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            //'list'        => true,
+        ),
+        
+        'info_id'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '商品ID',
+            'default'   => '',
+            'desc'      => '商品ID',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'column_id'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '栏目ID',
+            'default'   => '',
+            'desc'      => '栏目ID',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'state'     => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '数据状态',
+            'default'   => '1',
+            'desc'      => '请选择状态',
+            'match'     => 'is_numeric',
+        ),
+        
+        'cdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '录入时间',
+            'match'     => array('is_numeric', DEVER_TIME),
+            'desc'      => '',
+            # 只有insert时才生效
+            'insert'    => true,
+            'list'      => 'date("Y-m-d H:i:s", {cdate})',
+        ),
+    ),
+
+    'manage' => array
+    (
+        'delete' => false,
+        'edit' => false,
+        'insert' => false,
+    ),
+
+    'request' => array
+    (
+        'getData' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'column_id' => array('yes-t_1.column_id'),
+                'status' => array('yes-t_2.status', 1),
+                'state' => array('yes-t_2.state', 1),
+            ),
+            # 联表
+            'join' => array
+            (
+                array
+                (
+                    'table' => 'goods/info',
+                    'type' => 'left join',
+                    'on' => array('info_id','id'),
+                    'col' => 'info_id',
+                ),
+            ),
+            'type' => 'all',
+            'order' => array('t_2.top' => 'asc', 't_2.reorder' => 'desc', 't_2.id' => 'desc'),
+            'col' => '*,t_2.*',
+        ),
+    ),
+);

+ 5 - 3
app/goods/lib/Info.php

@@ -336,10 +336,12 @@ class Info
     }
 
     # 获取基本信息
-    public function getInfo($id, $attr = true, $order = 'view_reorder', $user = array(), $reward = false)
+    public function getInfo($info, $attr = true, $order = 'view_reorder', $user = array(), $reward = false)
     {
-        $info = Dever::db($this->table_info)->find($id);
-
+        if (!is_array($info)) {
+            $info = Dever::db($this->table_info)->find($info);
+        } 
+        
         if ($info && $attr) {
             $info = $this->info($info, $order, false, $user, $reward);
         }

+ 16 - 0
app/goods/lib/Manage.php

@@ -133,6 +133,21 @@ class Manage
         }
     }
 
+    public function column($cate, $im = ',')
+    {
+        if ($cate) {
+            $cate = explode(',', $cate);
+            $result = array();
+            foreach ($cate as $k => $v) {
+                $info = Dever::db('goods/column')->one($v);
+                $result[$k] = $info['name'];
+            }
+            $result = implode($im, $result);
+            return $result;
+        }
+        return '';
+    }
+
     /**
      * 显示信息
      *
@@ -143,6 +158,7 @@ class Manage
         $info = Dever::db('goods/info')->one($id);
         if ($info) {
             $table['编号'] = $info['id'];
+            $table['栏目'] = $this->column($info['column_id']);
             //$table['标题'] = $info['name'];
             $table['分类'] = Dever::load("category/api.string", $info['category']);
 

+ 15 - 1
app/goods/lib/Sku.php

@@ -91,7 +91,7 @@ class Sku
                 $update[$k] = Dever::input($k);
             }
 
-            if ($info) {
+            if ($info && $update) {
                 $update['where_id'] = $info['id'];
                 Dever::db($table)->update($update);
 
@@ -116,6 +116,8 @@ class Sku
             if (!is_array($config['key'])) {
                 $config['key'] = explode(',', $config['key']);
             }
+
+            $min = array();
             foreach ($config['key'] as $k => $v) {
                 if (isset($config['attr'][$k])) {
                     
@@ -138,6 +140,12 @@ class Sku
                         $value = Dever::input($k1);
                         if (isset($value[$k])) {
                             $data[$k1] = $value[$k];
+
+                            if (!isset($min[$k1])) {
+                                $min[$k1] = $data[$k1];
+                            } elseif ($min[$k1] > $data[$k1]) {
+                                $min[$k1] = $data[$k1];
+                            }
                         }
                     }
 
@@ -150,6 +158,12 @@ class Sku
                     }
                 }
             }
+
+            if (!$config['other'] && $min) {
+                $update = $min;
+                $update['where_id'] = $info['id'];
+                Dever::db($table)->update($update);
+            }
         }
 
         Dever::config('base')->hook = true;

+ 49 - 0
app/mshop/src/Main.php

@@ -6,6 +6,55 @@ use Dever;
 
 class Main extends Core
 {
+    # 申请合作
+    public function apply()
+    {
+        $data['name'] = Dever::input('name');
+        $data['mobile'] = Dever::input('mobile');
+        $data['city'] = Dever::input('city');
+        $data['uid'] = $this->uid;
+
+        if (!$data['name']) {
+            Dever::alert('请输入姓名');
+        }
+        if (!$data['mobile']) {
+            Dever::alert('请输入手机号');
+        }
+        if (!$data['city']) {
+            Dever::alert('请选择城市');
+        }
+
+        $info = Dever::db('shop/info')->find($data);
+
+        if (!$info) {
+            $data['truename'] = $data['name'];
+            # 根据城市查找省份
+            $city = Dever::db('area/city')->find($data['city']);
+            $data['province'] = $city['province_id'];
+            $data['area'] = $data['province'] . ',' . $data['city'];
+
+            # 获取经纬度
+            $url = 'https://restapi.amap.com/v3/geocode/geo';
+            $param['key'] = 'f18cb42560b8aa54e3b53a6265bfd764';
+            $param['city'] = $data['city'];
+            $param['address'] = $city['name'];
+            $result = json_decode(Dever::curl($url, $param), true);
+
+            if (isset($result['geocodes'][0]['location']) && $result['geocodes'][0]['location']) {
+                $data['map'] = $city['name'] . ',' . $result['geocodes'][0]['location'] . ',11';
+                $temp = explode(',', $result['geocodes'][0]['location']);
+                $data['lng'] = $temp[0];
+                $data['lat'] = $temp[1];
+            }
+
+            $data['status'] = 3;
+            Dever::db('shop/info')->insert($data);
+        }
+
+        $this->data['msg'] = '提交成功,我们会在3个工作日内与您联系,感谢您的信任。';
+        return $this->data;
+    }
+    
     public function home()
     {
         $day = Dever::input('day');

+ 33 - 1
app/shop/database/goods.php

@@ -192,13 +192,45 @@ return array
             'col' => '*,total_num-sell_num as num',
         ),
 
+        # 推荐列表
+        'getTop' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'shop_id' => array('yes-t_1.shop_id'),
+                'hot' => array('yes-t_2.hot'),
+                'top' => array('yes-t_2.top'),
+                'status' => array('yes-t_2.status', 1),
+                'state' => array('yes-t_2.state', 1),
+            ),
+            # 联表
+            'join' => array
+            (
+                array
+                (
+                    'table' => 'goods/info',
+                    'type' => 'left join',
+                    'on' => array('goods_id','id'),
+                    'col' => 'goods_id',
+                ),
+            ),
+            'type' => 'all',
+            'order' => array('reorder' => 'desc', 'id' => 'desc'),
+            'limit' => '0,6',
+            'col' => '*,t_2.*,t_1.total_num-t_1.sell_num as num,t_1.sell_num',
+        ),
+
         'getData' => array
         (
             # 匹配的正则或函数 选填项
             'option' => array
             (
+                'shop_id' => array('yes-t_1.shop_id'),
+                'hot' => array('yes-t_2.hot'),
                 'top' => array('yes-t_2.top'),
-                'youhui' => array('yes-t_2.youhui'),
+                //'youhui' => array('yes-t_2.youhui'),
+                'column' => array('yes-t_2.column_id', 'like'),
                 'category' => array('yes-t_2.category', 'like'),
                 'top_category_id' => array('yes-t_2.top_category_id'),
                 'second_category_id' => array('yes-t_2.second_category_id'),

+ 116 - 0
app/shop/lib/Info.php

@@ -0,0 +1,116 @@
+<?php
+
+namespace Shop\Lib;
+
+use Dever;
+
+class Info
+{
+    # 获取店铺基本信息
+    public function get($city, $lng, $lat, $name = '', $method = 'fetch')
+    {
+        if (!$city) {
+            Dever::alert('请传入城市');
+        }
+
+        if (!$lng || !$lat) {
+            Dever::alert('请传入用户坐标');
+        }
+
+        $data = $this->fetch($city, $lng, $lat, 1, $name, $method);
+
+        # 验证本城市内有没有店
+        if (!$data) {
+            $data = $this->fetch($city, $lng, $lat, 2, $name, $method);
+        }
+
+        if ($data) {
+            $data = $this->getInfo($data);
+        }
+
+        return $data;
+    }
+
+    # 获取店铺的推荐商品列表
+    public function getGoods($shop, $type, $type_id = false)
+    {
+        if ($shop) {
+            $table = 'shop/goods';
+        } else {
+            $table = 'goods/info';
+        }
+
+        $method = 'getTop';
+        $where['shop_id'] = $shop['id'];
+        if ($type == 1) {
+            $where['hot'] = 1;
+        } elseif ($type == 2) {
+            $where['top'] = 1;
+        } elseif ($type == 3) {
+            $where['column'] = $type_id;
+            $method = 'getData';
+        }
+
+        $data = Dever::db($table)->$method($where);
+
+        if ($data) {
+            foreach ($data as $k => $v) {
+                $data[$k] = Dever::load('goods/lib/info')->getInfo($v);
+
+                /*
+                $price = $data[$k]['price']['value'];
+                $data[$k]['price'] = $price;
+                if (isset($data[$k]['sell_attr'])) {
+                    unset($data[$k]['sell_attr']);
+                }
+
+                if (isset($data[$k]['attr'])) {
+                    unset($data[$k]['attr']);
+                }
+                */
+            }
+        }
+
+        return $data;
+    }
+
+    # 获取详细信息
+    private function getInfo($data)
+    {
+        if ($data['worktime']) {
+            $time = date('Hi');
+            $worktime = str_replace(':', '', $data['worktime']);
+            $temp = explode('~', $worktime);
+            if ($time < $temp[0] || $time > $temp[1]) {
+                $data['open'] = 2;
+            }
+        }
+        return $data;
+    }
+
+    # 获取距离
+    private function fetch($city, $lng, $lat, $type = 1, $name = '', $method = 'fetch')
+    {
+        $page = array();
+        if ($method == 'fetchAll') {
+            $page['template'] = 'list';
+            $page['num'] = 10;
+        } else {
+            $page = false;
+        }
+
+        $where = 'type = '.$type.' and status = 1 and state = 1';
+
+        if ($type == 1) {
+            $where .= ' and city = ' . $city;
+        }
+        if ($name) {
+            $where .= ' and name like("%'.$name.'%")';
+        }
+        $sql = 'select *, round((st_distance(point(lng, lat), point('.$lng.', '.$lat.'))*111195)/1000, 2) as distance from {table} where '.$where.' order by distance asc';
+
+        $data = Dever::db('shop/info')->$method($sql, array(), $page);
+
+        return $data;
+    }
+}

+ 42 - 74
app/shop/src/Main.php

@@ -12,28 +12,6 @@ class Main extends Core
         parent::__construct();
         //$this->checkLogin();
     }
-    
-    # 获取门店销售小程序首页的数据
-    public function home()
-    {
-        $where['city'] = Dever::input('city');
-
-        $this->data['focus'] = Dever::db('shop/focus')->select(array('location' => 1));
-
-        if ($where['city']) {
-            # 获取当前城市是否开通门店
-            $where['status'] = 1;
-            $this->data['shop'] = Dever::db('shop/info')->getOne($where);
-            if ($this->data['shop']) {
-                # 有开通的门店
-                $this->data['city'] = 1;
-            } else {
-                # 没有开通的门店
-                $this->data['city'] = 2;
-            }
-        }
-        return $this->data;
-    }
 
     # 获取当前登录的信息
     public function user()
@@ -42,57 +20,53 @@ class Main extends Core
         $this->data['config'] = Dever::db('main/config')->find();
         return $this->data;
     }
-
-    # 申请合作
-    public function apply()
+    
+    # 获取门店销售小程序首页的数据
+    public function home()
     {
-        $data['name'] = Dever::input('name');
-        $data['mobile'] = Dever::input('mobile');
-        $data['city'] = Dever::input('city');
-        $data['uid'] = $this->uid;
+        $city = Dever::input('city');
+        $lng = Dever::input('lng');
+        $lat = Dever::input('lat');
 
-        if (!$data['name']) {
-            Dever::alert('请输入姓名');
-        }
-        if (!$data['mobile']) {
-            Dever::alert('请输入手机号');
-        }
-        if (!$data['city']) {
-            Dever::alert('请选择城市');
+        # 获取门店
+        $this->data['shop'] = array();
+        if ($city && $lng && $lat) {
+            $this->data['shop'] = Dever::load('shop/lib/info')->get($city, $lng, $lat);
         }
 
-        $info = Dever::db('shop/info')->find($data);
-
-        if (!$info) {
-            $data['truename'] = $data['name'];
-            # 根据城市查找省份
-            $city = Dever::db('area/city')->find($data['city']);
-            $data['province'] = $city['province_id'];
-            $data['area'] = $data['province'] . ',' . $data['city'];
-
-            # 获取经纬度
-            $url = 'https://restapi.amap.com/v3/geocode/geo';
-            $param['key'] = 'f18cb42560b8aa54e3b53a6265bfd764';
-            $param['city'] = $data['city'];
-            $param['address'] = $city['name'];
-            $result = json_decode(Dever::curl($url, $param), true);
-
-            if (isset($result['geocodes'][0]['location']) && $result['geocodes'][0]['location']) {
-                $data['map'] = $city['name'] . ',' . $result['geocodes'][0]['location'] . ',11';
-                $temp = explode(',', $result['geocodes'][0]['location']);
-                $data['lng'] = $temp[0];
-                $data['lat'] = $temp[1];
-            }
+        # 获取焦点图
+        $this->data['focus'] = Dever::db('shop/focus')->select(array('location' => 2));
+
+        # 获取活动推荐
+
+        # 获取热门商品
+        $this->data['hot'] = Dever::load('shop/lib/info')->getTopGoods($this->data['shop'], 1);
+
+        # 获取推荐商品
+        $this->data['top'] = Dever::load('shop/lib/info')->getTopGoods($this->data['shop'], 2);
+
+        return $this->data;
+    }
 
-            $data['status'] = 3;
-            Dever::db('shop/info')->insert($data);
+    # 获取店铺列表
+    public function getShop()
+    {
+        $city = Dever::input('city');
+        $lng = Dever::input('lng');
+        $lat = Dever::input('lat');
+        $name = Dever::input('name');
+
+        # 获取门店
+        $this->data['shop'] = array();
+        if ($city && $lng && $lat) {
+            $this->data['shop'] = Dever::load('shop/lib/info')->get($city, $lng, $lat, $name, 'fetchAll');
         }
 
-        $this->data['msg'] = '提交成功,我们会在3个工作日内与您联系,感谢您的信任。';
         return $this->data;
     }
 
     # 根据坐标,获取距离用户最近的店
+    /*
     public function getShop()
     {
         $config = Dever::db('main/config')->find(1);
@@ -138,25 +112,19 @@ class Main extends Core
 
         return $result;
     }
+    */
 
     # 根据店铺获取商品列表
-    public function getGoods($shop_id)
+    public function getGoods()
     {
-        $cate = Dever::load('category/api')->getTop(1);
+        $shop_id = Dever::input('shop_id');
+
+        $column = Dever::db('goods/column')->select();
 
         $data = array();
-        $data['cate'] = array();
-        $data['cate'] = array
-        (
-            array('id' => -1, 'name' => '人气食材'),
-            array('id' => -2, 'name' => '每日优惠'),
-        );
-
-        $data['cate'][0]['data'] = Dever::db('shop/goods')->getData(array('top' => 1));
-        $data['cate'][1]['data'] = Dever::db('shop/goods')->getData(array('youhui' => 1));
         if ($cate) {
             foreach ($cate as $k => $v) {
-                $v['data'] = Dever::db('shop/goods')->getData(array('top_category_id' => $v['id']));
+                $v['data'] = Dever::load('shop/lib/info')->getTopGoods($this->data['shop'], 3, $v['id']);
                 $data['cate'][] = $v;
             }
         }