dever 4 vuotta sitten
vanhempi
commit
f231ef6a87
7 muutettua tiedostoa jossa 425 lisäystä ja 68 poistoa
  1. 42 22
      assets/manage/html/sku.html
  2. 122 0
      database/freight.php
  3. 24 3
      database/info.php
  4. 62 2
      database/info_sku.php
  5. 63 28
      lib/Info.php
  6. 110 13
      lib/Manage.php
  7. 2 0
      template/manage/sku.php

+ 42 - 22
assets/manage/html/sku.html

@@ -1,24 +1,44 @@
-<table class="layui-table" id="sku">
-  <thead>
-    <tr>
-      <th>昵称</th>
-      <th>加入时间</th>
-      <th>签名</th>
-    </tr> 
-  </thead>
-  <tbody>
-    <tr>
-      <td>贤心</td>
-      <td>2016-11-29</td>
-      <td>人生就像是一场修行</td>
-    </tr>
-    <tr>
-      <td>许闲心</td>
-      <td>2016-11-28</td>
-      <td>于千万人之中遇见你所遇见的人,于千万年之中,时间的无涯的荒野里…</td>
-    </tr>
-  </tbody>
-</table>
-<script>
+</form>
+<form class="layui-form form10" action="" target="f10" method="post">
+<input type="hidden" name="info_id" id="info_id" value="">
+<input type="hidden" name="function" id="function" value="skuMsg">
+<iframe id="f10" name="f10" style="display:none;"></iframe>
+	<div class="layui-form-item">
+		<table class="layui-table" id="sku">
+		  <thead>
+		    <tr>
+		      <th>昵称</th>
+		      <th>加入时间</th>
+		      <th>签名</th>
+		    </tr> 
+		  </thead>
+		  <tbody>
+		    <tr>
+		      <td>贤心</td>
+		      <td>2016-11-29</td>
+		      <td>人生就像是一场修行</td>
+		    </tr>
+		    <tr>
+		      <td>许闲心</td>
+		      <td>2016-11-28</td>
+		      <td>于千万人之中遇见你所遇见的人,于千万年之中,时间的无涯的荒野里…</td>
+		    </tr>
+		  </tbody>
+		</table>
+	</div>
 
+	<div class="layui-form-item">
+	    <div class="">
+	      <button type="button" class="layui-btn" onclick="saveSku()">保存</button>
+	    </div>
+	</div>
+<script>
+function saveSku()
+{
+	$('.form10').submit();
+}
+function skuMsg()
+{
+	showAlert('保存成功');
+}
 </script>

+ 122 - 0
database/freight.php

@@ -0,0 +1,122 @@
+<?php
+$type = array
+(
+	1 => '数值',
+	2 => '百分比',
+);
+return array
+(
+	# 表名
+	'name' => 'freight',
+	# 显示给用户看的名称
+	'lang' => '运费设置',
+	'order' => 1,
+
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'search'	=> 'order',
+			//'list'		=> true,
+		),
+
+		'category'		=> array
+		(
+			'type' 		=> 'varchar-500',
+			'name' 		=> '分类',
+			'default' 	=> '',
+			'desc' 		=> '分类',
+			'match' 	=> 'is_string',
+			'search'	=> 'linkage',
+			'update'	=> 'linkage',
+			'option'	=> Dever::url('api.get', 'category'),
+			'list'		=> 'Dever::load("category/api.string", "{category}")',
+		),
+
+		'area'		=> array
+		(
+			'type' 		=> 'varchar-500',
+			'name' 		=> '地区',
+			'default' 	=> '',
+			'desc' 		=> '地区',
+			'match' 	=> 'is_string',
+			'search'	=> 'linkage',
+			'update'	=> 'linkage',
+			'option'	=> Dever::url('api.get', 'area'),
+			'list'		=> 'Dever::load("area/api.string", "{area}")',
+		),
+
+		'type'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '运费类型',
+			'default' 	=> '1',
+			'desc' 		=> '运费类型',
+			'match' 	=> 'option',
+			'update'	=> 'radio',
+			'option'	=> $type,
+			'list'		=> true,
+			'search'	=> 'select',
+		),
+		
+		'price'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '运费价格-如果是百分比类型,这里如果填的是10,那就是总价的10%',
+			'default' 	=> '',
+			'desc' 		=> '运费价格',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'free'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '总价满多少减免运费',
+			'default' 	=> '',
+			'desc' 		=> '满多少减免运费',
+			'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
+	(
+		
+	)
+);

+ 24 - 3
database/info.php

@@ -170,6 +170,27 @@ $config = array
 			'place'		=> '750*422',
 		),
 
+		'sell_num'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '销量',
+			'default' 	=> '0',
+			'desc' 		=> '请填写销量',
+			'match' 	=> 'option',
+			'search'	=> 'order',
+			'list'		=> '{sell_num}+{sell_add_num}',
+		),
+
+		'sell_add_num'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '销量基数',
+			'default' 	=> '0',
+			'desc' 		=> '销量基数',
+			'match' 	=> 'option',
+			//'update'	=> 'text',
+		),
+
 		'audit'		=> array
 		(
 			'type' 		=> 'tinyint-1',
@@ -367,8 +388,8 @@ $config = array
 			'col' => '*',
 		),
 		
-		# 更新浏览
-		'addView' => array
+		# 更新售出
+		'addSell' => array
 		(
 			'type' => 'update',
 			'where' => array
@@ -377,7 +398,7 @@ $config = array
 			),
 			'set' => array
 			(
-				'num_view' => array('1', '+='),
+				'sell_num' => array('1', '+='),
 			),
 		),
 	),

+ 62 - 2
database/info_sku.php

@@ -33,6 +33,16 @@ $config = array
 			'list'		=> true,
 		),
 
+		'key'		=> array
+		(
+			'type' 		=> 'varchar-100',
+			'name' 		=> '属性标识',
+			'default' 	=> '',
+			'desc' 		=> '属性标识',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+		),
+
 		'attr'		=> array
 		(
 			'type' 		=> 'text-255',
@@ -58,9 +68,9 @@ $config = array
 		's_price'		=> array
 		(
 			'type' 		=> 'varchar-50',
-			'name' 		=> '价',
+			'name' 		=> '价',
 			'default' 	=> '',
-			'desc' 		=> '价',
+			'desc' 		=> '价',
 			'match' 	=> 'is_string',
 			'update'	=> 'text',
 			'list'		=> true,
@@ -120,7 +130,57 @@ $config = array
         'delete' => false,
         'num' => false,
         'page_list_table' => 'sku',
+
+        # 自定义快捷新增和编辑
+        'button' => array
+        (
+            '自定义属性' => array('fast', 1, 'config&where_id=1'),
+        ),
     ),
+
+    # request 请求接口定义
+	'request' => array
+	(
+		# 列表
+		'getData' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'info_id' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('id' => 'desc'),
+			'col' => '*|key',
+		),
+
+		'getMinOne' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'info_id' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'one',
+			'order' => array('price' => 'asc', 'id' => 'desc'),
+			'col' => '*',
+		),
+
+		'getMaxOne' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'info_id' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'one',
+			'order' => array('price' => 'desc', 'id' => 'desc'),
+			'col' => '*',
+		),
+	),
 );
 
 return $config;

+ 63 - 28
lib/Info.php

@@ -37,7 +37,8 @@ class Info
 
         # 必有有分类才能进入到需求中
         if (!$this->top_category) {
-            Dever::alert('错误的分类信息');
+            $this->top_category = -1;
+            //Dever::alert('错误的分类信息');
         }
 	}
 
@@ -246,45 +247,27 @@ class Info
             $info = $this->info($info, $order);
         }
 
-        if ($info['poster_uid'] < 0) {
-            $info['poster_uid'] = 1;
-        }
-
-        if ($info['poster_uid'] > 0) {
-            $info['user'] = Dever::db('passport/user')->one($info['poster_uid']);
-            $sex = Dever::db('passport/user')->config['sex'];
-            if ($info['user']['area']) {
-                $info['user']['area'] = str_replace(',', '-', $info['user']['area']);
-                $info['user']['area'] .= '-';
-            }
-            $info['user']['text'] = $info['user']['area'] . $sex[$info['user']['sex']];
-
-            if (!$info['user']['avatar']) {
-                $config = Dever::db('main/config')->one();
-                $info['user']['avatar'] = $config['avatar'];
-            }
-        }
-
-        $info['num_view_text'] = $info['num_view'] + $info['num_add_view'];
-
-        $info['num_view_text'] .= '人浏览';
-
         if ($info['pic']) {
             $info['pic'] = explode(',', $info['pic']);
         }
-        
 
         return $info;
     }
 
-    # 获取需求基本信息
+    # 获取基本信息
     public function info($info, $key = 'list_reorder', $is_sell = false)
     {
+        # 销量
+        $info['sell_num'] = $info['sell_num'] + $info['sell_add_num'];
+
+        # 获取运费
+        $info['freight'] = $this->freight($info);
+
         $attr = $this->setAttr($info['category'], $key);
         $attr_data = $attr->one($info['id']);
         $info['category_array'] = Dever::load('category/api')->string($info['category']);
 
-        $info['attr'] = array();
+        $info['attr'] = $info['sell_attr'] = array();
 
         if ($attr->config['attr']) {
             foreach ($attr->config['attr'] as $k => $v) {
@@ -310,6 +293,8 @@ class Info
                             
                         } else {
                             $info['attr'][] = $v;
+                            # 设置sku
+                            $this->sku($v, $info);
                         }
                     }
                 }
@@ -321,10 +306,60 @@ class Info
         }
 
         $info = $this->getInfoLink($info);
-        
+
     	return $info;
     }
 
+    private function freight($info)
+    {
+        # 之后要加入当前用户的地理位置
+        $array = explode(',', $info['category']);
+        $cate = $freight = array();
+        $total = count($array);
+        $total -= 1;
+        foreach ($array as $k => $v) {
+            $cate[$k] = $v;
+            if ($k < $total) {
+                $cate[] = '-1';
+            }
+            $where['category'] = $cate;
+            $data = Dever::db('goods/freight')->one($where);
+            if ($data) {
+                $freight = $data;
+            }
+        }
+
+        return $freight;
+    }
+
+    private function sku($data, &$info)
+    {
+        # 获取销售属性
+        if ($data['is_sell'] == 2) {
+            if ($data['option']) {
+                $value = explode(',', $data['value']);
+                foreach($data['option'] as $k => $v) {
+                    if (in_array($v['id'], $value)) {
+                        $data['option_sku'][] = array
+                        (
+                            'id' => $v['id'],
+                            'info_id' => $v['info_id'],
+                            'name' => $v['name'],
+                            'icon' => $v['icon'],
+                        );
+                    }
+                }
+            }
+            
+            $info['sell_attr'][] = $data;
+
+            # 获取最便宜的价格
+            $where['info_id'] = $info['id'];
+            $info['price']['min'] = Dever::db('goods/info_sku')->getMinOne($where);
+            $info['price']['max'] = Dever::db('goods/info_sku')->getMaxOne($where);
+        }
+    }
+
     public function getInfoLink($info)
     {
         if (isset($this->view_path)) {

+ 110 - 13
lib/Manage.php

@@ -6,6 +6,53 @@ use Dever;
 
 class Manage
 {
+    public function search_api()
+    {
+        $table = 'goods/info';
+        $keyword = Dever::input('keyword');
+
+        $yes = Dever::input('yes');
+
+        $where = array();
+
+        $cate = Dever::input('cate');
+        if ($cate) {
+            $where['cate_id'] = $cate;
+        }
+
+        if ($yes) {
+            $yes = Dever::db($table)->search(array('ids' => $yes));
+        }
+        if (!$keyword) {
+            $where['limit'] = '0,50';
+            $data = Dever::db($table)->search($where);
+        } else {
+            $where['name'] = $keyword;
+            $data = Dever::db($table)->search($where);
+        }
+
+        $result = array();
+        if ($yes) {
+            foreach ($yes as $k => $v) {
+                if (isset($data[$k])) {
+                    unset($data[$k]);
+                }
+                $yes[$k]['selected'] = 'selected';
+            }
+            $data = $yes + $data;
+
+            $data = array_merge($data, array());
+        } else {
+            $data = array_merge($data, array());
+        }
+
+        if (!$data) {
+            Dever::alert('暂无数据');
+        }
+
+        return $data;
+    }
+
     /**
      * 更新信息
      *
@@ -152,27 +199,63 @@ class Manage
         }
     }
 
+    public function skuConfig()
+    {
+        $data['action'] = Dever::url('goods/lib/manage.skuUp');
+        $data['info_id'] = Dever::input('search_option_info_id');
+        return $data;
+    }
+
+    public function skuUp_api()
+    {
+        $info_id = Dever::input('info_id');
+        $attr = Dever::input('attr');
+        $key = Dever::input('key');
+        $price = Dever::input('price');
+        $s_price = Dever::input('s_price');
+        $num = Dever::input('num');
+
+        if ($key) {
+            foreach ($key as $k => $v) {
+                if (isset($price[$k]) && $price[$k]) {
+                    $info = Dever::db('goods/info_sku')->one(array('key' => $v));
+                    $data['info_id'] = $info_id;
+                    $data['attr'] = $attr[$k];
+                    $data['key'] = $v;
+                    $data['price'] = $price[$k];
+                    $data['s_price'] = $s_price[$k];
+                    $data['num'] = $num[$k];
+                    if (!$info) {
+                        Dever::db('goods/info_sku')->insert($data);
+                    } else {
+                        $data['where_id'] = $info['id'];
+                        Dever::db('goods/info_sku')->update($data);
+                    }
+                }
+            }
+        }
+
+        Dever::out('yes');
+    }
+
     public function skuInput()
     {
         $id = Dever::input('search_option_info_id');
 
+        $sku = Dever::db('goods/info_sku')->getData(array('info_id' => $id));
+
         $info = Dever::db('goods/info')->one($id);
 
-        $info = Info::init(-1)->info($info, 'list_reorder', 2);
+        $info = Info::init(-1)->info($info, 'list_reorder');
 
-        if ($info['attr']) {
+        if ($info['sell_attr']) {
             $head = '<thead><tr>';
             $body = '<tbody>';
             $option = array();
-            foreach ($info['attr'] as $k => $v) {
+            foreach ($info['sell_attr'] as $k => $v) {
                 $head .= '<th>'.$v['name'].'</th>';
-                foreach($v['option'] as $k1 => $v1) {
-                    $option[$k][$k1] = array
-                    (
-                        'id' => $v1['id'],
-                        'attr_id' => $v1['info_id'],
-                        'name' => $v1['name']
-                    );
+                if (isset($v['option_sku'])) {
+                    $option[$k] = $v['option_sku'];
                 }
             }
 
@@ -187,13 +270,27 @@ class Manage
                 foreach ($option as $k => $v) {
                     $body .= '<tr data-row="' .($k+1). '">';
 
+                    $key = $id = array();
                     foreach ($v['name'] as $k1 => $v1) {
                         $rows = 1;
                         $body .= '<td width="50" rowspan="'.$rows.'">'.$v1.'</td>';
+                        $id[] = array
+                        (
+                            'id' => $v['id'][$k1],
+                            'attr_id' => $v['info_id'][$k1],
+                        );
+                        $key[] = $v['info_id'][$k1] . '-' . $v['id'][$k1];
+                    }
+                    $key = implode('_', $key);
+                    $s_price = $price = $num = '';
+                    if (isset($sku[$key])) {
+                        $s_price = $sku[$key]['s_price'];
+                        $price = $sku[$key]['price'];
+                        $num = $sku[$key]['num'];
                     }
-                    $body .= '<td width="30"><input type="text" class="layui-input" name="price[]" /></td>';
-                    $body .= '<td width="30"><input type="text" class="layui-input" name="price[]" /></td>';
-                    $body .= '<td width="30"><input type="text" class="layui-input" name="price[]" /></td>';
+                    $body .= '<td width="30"><input type="text" class="layui-input" name="s_price['.$k.']" value="'.$s_price.'"/></td>';
+                    $body .= '<td width="30"><input type="text" class="layui-input" name="price['.$k.']"  value="'.$price.'"/></td>';
+                    $body .= '<td width="30"><input type="text" class="layui-input" name="num['.$k.']"  value="'.$num.'"/><input type="hidden" name="key['.$k.']" value="'.$key.'"/><textarea style="display:none;" name="attr['.$k.']"/>'.json_encode($id).'</textarea></td>';
                     $body .= '</tr>';
                 }
             }

+ 2 - 0
template/manage/sku.php

@@ -1,5 +1,7 @@
 <?php
 
 $view
+->fetch('.form10@action', 'goods/lib/manage.skuConfig#action')
+->fetch('#info_id@value', 'goods/lib/manage.skuConfig#info_id')
 ->fetch('#sku', 'goods/lib/manage.skuInput')
 ->display();