dever 3 年之前
父节点
当前提交
56ce53b112

+ 32 - 0
app/goods/database/info.php

@@ -33,6 +33,17 @@ $column = function()
     return $array;
 };
 
+$tag = function()
+{
+    $array = array();
+    $info = Dever::load('goods/tag-state');
+    if($info)
+    {
+        $array += $info;
+    }
+    return $array;
+};
+
 $config = array
 (
     # 表名
@@ -68,6 +79,15 @@ $config = array
             'update' => array('column_id' => 'column_id'),
             # 同步更新的类型,delete为先删再插入,update为直接更新
             'type' => 'delete',
+        ),
+        'goods/info_tag' => array
+        (
+            # 更新另外一个表的字段 => 本表的字段
+            'where' => array('info_id', 'id'),
+            # 要更新的数据
+            'update' => array('tag_id' => 'tag_id'),
+            # 同步更新的类型,delete为先删再插入,update为直接更新
+            'type' => 'delete',
         )
     ),
 
@@ -150,6 +170,18 @@ $config = array
             'match'     => 'is_numeric',
         ),
 
+        'tag_id'        => array
+        (
+            'type'      => 'varchar-800',
+            'name'      => '标签',
+            'default'   => '',
+            'desc'      => '标签',
+            'match'     => 'is_string',
+            'update'    => 'checkbox',
+            'option'    => $tag,
+            //'list'      => true,
+        ),
+
         'area'        => array
         (
             'type'      => 'int-11',

+ 1 - 1
app/goods/database/info_category.php

@@ -95,7 +95,7 @@ return array
                 ),
             ),
             'type' => 'all',
-            'order' => array('t_2.top' => 'asc', 't_2.reorder' => 'desc', 't_2.id' => 'desc'),
+            'order' => array('t_2.reorder' => 'desc', 't_2.id' => 'desc'),
             'col' => '*,t_2.*',
         ),
     ),

+ 1 - 1
app/goods/database/info_column.php

@@ -95,7 +95,7 @@ return array
                 ),
             ),
             'type' => 'all',
-            'order' => array('t_2.top' => 'asc', 't_2.reorder' => 'desc', 't_2.id' => 'desc'),
+            'order' => array('t_2.reorder' => 'desc', 't_2.id' => 'desc'),
             'col' => '*,t_2.*',
         ),
     ),

+ 16 - 2
app/goods/database/info_sku.php

@@ -165,6 +165,20 @@ $config = array
     (
         # 列表
         'getData' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'info_id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('id' => 'desc'),
+            'col' => 'id,info_id,`key`,price,s_price',
+        ),
+
+        # 列表
+        'getDataByKeys' => array
         (
             # 匹配的正则或函数 选填项
             'option' => array
@@ -200,7 +214,7 @@ $config = array
             ),
             'type' => 'one',
             'order' => array('price' => 'asc', 'id' => 'desc'),
-            'col' => 'id,info_id,price,s_price,f_price',
+            'col' => 'id,info_id,price,s_price',
         ),
 
         'getMaxOne' => array
@@ -213,7 +227,7 @@ $config = array
             ),
             'type' => 'one',
             'order' => array('price' => 'desc', 'id' => 'desc'),
-            'col' => 'id,info_id,price,s_price,f_price',
+            'col' => 'id,info_id,price,s_price',
         ),
 
         # 更新售出量

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

@@ -0,0 +1,102 @@
+<?php
+
+return array
+(
+    # 表名
+    'name' => 'info_tag',
+    # 显示给用户看的名称
+    '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,
+        ),
+
+        'tag_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
+            (
+                'tag_id' => array('yes-t_1.tag_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.reorder' => 'desc', 't_2.id' => 'desc'),
+            'col' => '*,t_2.*',
+        ),
+    ),
+);

+ 106 - 0
app/goods/database/tag.php

@@ -0,0 +1,106 @@
+<?php
+
+return array
+(
+	# 表名
+	'name' => 'tag',
+	# 显示给用户看的名称
+	'lang' => '标签管理',
+	# 是否显示在后台菜单
+	'order' => 10,
+
+	# 数据结构
+	'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,
+		),
+
+		'color'		=> array
+		(
+			'type' 		=> 'varchar-10',
+			'name' 		=> '颜色-请填写颜色代码',
+			'default' 	=> '',
+			'desc' 		=> '颜色',
+			'match' 	=> 'option',
+			'update'	=> 'color',
+		),
+
+		'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
+	(
+		
+	),
+
+	'request' => array
+	(
+		'getAllByIds' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'ids' => array('yes-id', 'in'),
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('reorder' => 'desc', 'id' => 'desc'),
+			'col' => '*',
+		),
+	)
+);

+ 69 - 26
app/goods/lib/Info.php

@@ -338,14 +338,14 @@ class Info
     }
 
     # 获取基本信息
-    public function getInfo($info, $attr = true, $order = 'view_reorder', $user = array(), $reward = false)
+    public function getInfo($info, $attr = true, $other = false, $order = 'view_reorder', $user = array(), $reward = false)
     {
         if (!is_array($info)) {
             $info = Dever::db($this->table_info)->find($info);
-        } 
+        }
         
         if ($info && $attr) {
-            $info = $this->info($info, $order, false, $user, $reward);
+            $info = $this->info($info, $order, $other, false, $user, $reward);
         }
 
         if (!isset($info['goods_id'])) {
@@ -376,11 +376,15 @@ class Info
             $info['goods'] = $goods_info;
         }
 
+        if ($info['tag_id']) {
+            $info['tag'] = Dever::db('goods/tag')->getAllByIds($info['tag_id']);
+        }
+
         return $info;
     }
 
     # 获取基本信息
-    public function info($info, $key = 'list_reorder', $is_sell = false, $user = array(), $reward = false)
+    public function info($info, $key = 'list_reorder', $other = false, $is_sell = false, $user = array(), $reward = false)
     {
         $info['category_array'] = Dever::load('category/api')->string($info['category']);
         if ($info['price_type'] == 2) {
@@ -420,21 +424,10 @@ class Info
                         }
                     }
                 }
-            }
 
-            if (isset($info['price_array']['min']['price'])) {
-                $info['price'] = $info['price_array']['min']['price'];
-                $info['sku_id'] = $info['price_array']['min']['id'];
+                # 获取sku的价格
+                $this->getPrice($info, $other);
             }
-        } else {
-            $info['price_array'] = array();
-            $info['price_array']['list'] = array();
-            $info['price_array']['min'] = array
-            (
-                'price' => $info['price'],
-                's_price' => $info['s_price'],
-            );
-            $info['price_array']['max'] = array();
         }
        
         if (isset($info['cdate']) && $info['cdate']) {
@@ -553,13 +546,14 @@ class Info
                 $value = explode(',', $data['value']);
                 foreach($data['option'] as $k => $v) {
                     if (in_array($v['id'], $value)) {
-                        $data['option_sku'][] = array
+                        $key = $v['info_id'] . '-' . $v['id'];
+                        $info['option_sku'][$key] = $data['option_sku'][] = array
                         (
                             'id' => $v['id'],
                             'info_id' => $v['info_id'],
                             'name' => $v['name'],
                             'icon' => $v['icon'],
-                            'value' => $v['info_id'] . '-' . $v['id'],
+                            'value' => $key,
                         );
                     }
                 }
@@ -567,18 +561,67 @@ class Info
             }
             
             $info['sell_attr'][] = $data;
-
-            # 获取最便宜的价格
-            $where['info_id'] = $info['id'];
-            $info['price_array'] = array();
-            $info['price_array']['list'] = Dever::db('goods/info_sku')->getData($where);
-            $info['price_array']['min'] = Dever::db('goods/info_sku')->getMinOne($where);
-            $info['price_array']['max'] = Dever::db('goods/info_sku')->getMaxOne($where);
         } elseif ($data['is_sell'] == 3) {
             $info['option_attr'][] = $data;
         }
     }
 
+    private function getPrice(&$info, $other = false)
+    {
+        # 获取价格
+        $where['info_id'] = $info['id'];
+        $info['price_array'] = array();
+        $list = Dever::db('goods/info_sku')->getData($where);
+
+        $info['price_array']['list'] = array();
+
+        $min = $max = array();
+        if ($list) {
+            foreach ($list as $k => $v) {
+
+                $v['name'] = array();
+                $temp = explode('_', $v['key']);
+                foreach ($temp as $k1 => $v1) {
+                    if (isset($info['option_sku'][$v1])) {
+                        $v['name'][] = $info['option_sku'][$v1]['name'];
+                    }
+                }
+                $v['name'] = implode(';', $v['name']);
+
+                if ($other) {
+                    foreach ($other[1] as $k1 => $v1) {
+                        $v[$v1] = isset($other[0][$v['id']][$v1]) ? $other[0][$v['id']][$v1] : 0;
+                    }
+                }
+
+                $info['price_array']['list'][$v['key']] = $v;
+                if (!$min) {
+                    $min = $v;
+                }
+                if (!$max) {
+                    $max = $v;
+                }
+
+                if ($min['price'] > $v['price']) {
+                    $min = $v;
+                }
+
+                if ($max['price'] < $v['price']) {
+                    $max = $v;
+                }
+            }
+        }
+        $info['price_array']['min'] = $min;
+        $info['price_array']['max'] = $max;
+
+        if ($min) {
+            $info['price'] = $min['price'];
+            $info['s_price'] = $min['s_price'];
+            $info['sku_id'] = $min['id'];
+        }
+        unset($info['option_sku']);
+    }
+
     public function getInfoLink($info)
     {
         if (isset($this->view_path)) {

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

@@ -207,7 +207,7 @@ class Sku
             $input = '<input type="hidden" name="goods_id" value="'.$goods_id.'"/><input type="hidden" name="'.$other_col.'" value="'.$other_id.'"/>';
         }
 
-        $sku = Dever::db('goods/info_sku')->getData(array('info_id' => $goods_id));
+        $sku = Dever::db('goods/info_sku')->getDataByKeys(array('info_id' => $goods_id));
 
         $info = Dever::db('goods/info')->one($goods_id);
 

+ 2 - 2
app/shop/database/goods_sku.php

@@ -152,7 +152,7 @@ $config = array
             ),
             'type' => 'all',
             'order' => array('id' => 'desc'),
-            'col' => '*,total_num-sell_num as num|sku_id',
+            'col' => '*,total_num-sell_num as total|sku_id',
         ),
 
         # 获取单条数据
@@ -167,7 +167,7 @@ $config = array
                 'state' => 1,
             ),
             'type' => 'one',
-            'col' => '*,total_num-sell_num as num',
+            'col' => '*,total_num-sell_num as total',
         ),
 
         # 更新售出量

+ 51 - 0
app/shop/database/sell_order.php

@@ -411,6 +411,57 @@ return array
             'option'    => $tk_status,
         ),
 
+        'area'       => array
+        (
+            'type'      => 'varchar-500',
+            'name'      => '所在地区',
+            'default'   => '',
+            'desc'      => '所在地区',
+            'match'     => 'option',
+            'search'    => 'linkage',
+            'option'    => Dever::url('api.get?level_total=4', 'area'),
+        ),
+
+        'province'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '省份',
+            'default'   => '',
+            'desc'      => '省份',
+            'match'     => 'option',
+            //'update'  => 'text',
+        ),
+
+        'city'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '城市',
+            'default'   => '',
+            'desc'      => '城市',
+            'match'     => 'option',
+            //'update'  => 'text',
+        ),
+
+        'county'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '县区',
+            'default'   => '',
+            'desc'      => '县区',
+            'match'     => 'option',
+            //'update'  => 'text',
+        ),
+
+        'town'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '街道',
+            'default'   => '',
+            'desc'      => '街道',
+            'match'     => 'option',
+            //'update'  => 'text',
+        ),
+
         'status'        => array
         (
             'type'      => 'tinyint-1',

+ 12 - 18
app/shop/lib/Info.php

@@ -80,6 +80,7 @@ class Info
                 $data['open'] = 2;
             }
         }
+
         return $data;
     }
 
@@ -115,7 +116,10 @@ class Info
     # 获取库存
     public function getGoodsInfo($shop_id, $info, $sku_id = false, $attr = true)
     {
-        $data = Dever::load('goods/lib/info')->getInfo($info, $attr);
+        $where['shop_id'] = $shop_id;
+        $where['goods_id'] = isset($info['goods_id']) ? $info['goods_id'] : $info;
+        $other = Dever::db('shop/goods_sku')->getData($where);
+        $data = Dever::load('goods/lib/info')->getInfo($info, $attr, array($other, array('total')));
 
         if($data) {
 
@@ -124,7 +128,7 @@ class Info
             if ($data['price_type'] == 3) {
                 if (isset($data['goods']) && is_array($data['goods'])) {
                     foreach ($data['goods'] as $k => $v) {
-                        $data['goods'][$k]['total'] = $this->getTotal($shop_id, $v['id'], -1);
+                        $data['goods'][$k]['total'] = $this->getTotal($other, -1);
 
                         if ($data['total'] > $data['goods'][$k]['total']) {
                             $data['total'] = $data['goods'][$k]['total'];
@@ -132,7 +136,7 @@ class Info
                     }
                 }
             } else {
-                $data['total'] = $this->getTotal($shop_id, $data['goods_id'], $sku_id);
+                $data['total'] = $this->getTotal($other, $sku_id);
             }
         }
 
@@ -159,22 +163,12 @@ class Info
     }
 
     # 获取库存
-    public function getTotal($shop_id, $goods_id, $sku_id)
+    public function getTotal($other, $sku_id)
     {
-        $total = 0;
-        $w['shop_id'] = $shop_id;
-        $w['goods_id'] = $goods_id;
-        $w['sku_id'] = $sku_id ? $sku_id : -1;
-        $sku = Dever::db('shop/goods_sku')->getOne($w);
-
-        if ($sku) {
-            $total = $sku['num'];
-        }
-
-        if (!$total) {
-            $total = 0;
+        if (isset($other[$sku_id])) {
+            return $other[$sku_id]['total'];
+        } else {
+            return 0;
         }
-
-        return $total;
     }
 }

+ 6 - 0
app/shop/lib/Sell.php

@@ -38,6 +38,12 @@ class Sell
         $order_data['info'] = $info;
         $order_data['price'] = $price;
 
+        $order_data['area'] = $shop['area'];
+        $order_data['province'] = $shop['province'];
+        $order_data['city'] = $shop['city'];
+        $order_data['county'] = $shop['county'];
+        $order_data['town'] = $shop['town'];
+
         $order_data['method'] = $method;
         $order_data['pay_method'] = $pay_method;
 

+ 2 - 1
app/shop/lib/Sku.php

@@ -10,6 +10,7 @@ class Sku
 	public $col = array
     (
         'add_num' => '新增库存数^-输入小于0的数字,则为减少库存',
-        'total_num' => '当前库存|',
+        'total' => '当前库存|',
+        'total_num' => '总库存|',
     );
 }

+ 2 - 0
app/shop/src/Main.php

@@ -78,6 +78,8 @@ class Main extends Core
 
         $data = array();
 
+        # 这里要加一下缓存
+
         $data['shop'] = Dever::load('shop/lib/info')->getOne($shop_id, $lng, $lat);
         if ($column) {
             foreach ($column as $k => $v) {

+ 2 - 2
app/store/database/goods_sku.php

@@ -152,7 +152,7 @@ $config = array
             ),
             'type' => 'all',
             'order' => array('id' => 'desc'),
-            'col' => '*,total_num-sell_num as num|sku_id',
+            'col' => '*,total_num-sell_num as total|sku_id',
         ),
 
         # 获取单条数据
@@ -167,7 +167,7 @@ $config = array
                 'state' => 1,
             ),
             'type' => 'one',
-            'col' => '*,total_num-sell_num as num',
+            'col' => '*,total_num-sell_num as total',
         ),
 
         # 更新售出量

+ 2 - 1
app/store/lib/Sku.php

@@ -10,6 +10,7 @@ class Sku
 	public $col = array
     (
         'add_num' => '新增库存数^-输入小于0的数字,则为减少库存',
-        'total_num' => '当前库存|',
+        'total' => '当前库存|',
+        'total_num' => '总库存|',
     );
 }