dever 3 years ago
parent
commit
57e659e1fd

+ 44 - 0
app/factory/assets/manage/html/sku.html

@@ -0,0 +1,44 @@
+</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>

+ 29 - 1
app/factory/database/goods.php

@@ -7,6 +7,11 @@ return array
     'lang' => '商品列表',
     'order' => 10,
     'menu'  => false,
+    'end' => array
+    (
+        'insert' => 'factory/lib/manage.goodsUpdate',
+        'update' => 'factory/lib/manage.goodsUpdate',
+    ),
     # 数据结构
     'struct' => array
     (
@@ -47,6 +52,25 @@ return array
             'list'      => 'Dever::load("goods/info-find#name", {goods_id})',
         ),
 
+        'price_type'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '价格类型',
+            'default'   => '1',
+            'desc'      => '价格类型',
+            'match'     => 'is_numeric',
+        ),
+
+        'c_price'     => array
+        (
+            'type'      => 'decimal-10,2',
+            'name'      => '出厂价',
+            'default'   => '',
+            'desc'      => '出厂价',
+            'match'     => 'option',
+            'update'    => 'text',
+        ),
+
         'state'     => array
         (
             'type'      => 'tinyint-1',
@@ -71,7 +95,11 @@ return array
 
     'manage' => array
     (
-
+        # 列表里的按钮
+        'list_button' => array
+        (
+            'list' => array('多个价格设置', '"goods_sku&project=factory&search_option_factory_goods_id={id}&oper_parent=goods&oper_project=factory&top_table=info&oper_save_jump=goods&page_type=1"', '{price_type} == 2'),
+        ),
     ),
 
     'request' => array

+ 156 - 0
app/factory/database/goods_sku.php

@@ -0,0 +1,156 @@
+<?php
+
+$config = array
+(
+    # 表名
+    'name' => 'goods_sku',
+    # 显示给用户看的名称
+    'lang' => '商品价格设置',
+    'order' => 200,
+    'menu' => false,
+
+    # 数据结构 不同的字段放这里
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            //'list'        => true,
+        ),
+
+        'store_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '所属仓库',
+            'default'   => '',
+            'desc'      => '所属仓库',
+            'list'      => 'Dever::load("store/info-find#name", {store_id})',
+        ),
+
+        'goods_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '商品名称',
+            'default'   => '',
+            'desc'      => '商品名称',
+            'match'     => 'is_numeric',
+            'list'      => 'Dever::load("goods/info-find#name", {goods_id})',
+        ),
+
+        'store_goods_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '商品名称',
+            'default'   => '',
+            'desc'      => '商品名称',
+            'value'     => Dever::input('search_option_fatory_goods_id'),
+            'update'    => 'hidden',
+            'match'     => 'is_numeric',
+        ),
+
+        'sku_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '商品sku',
+            'default'   => '',
+            'desc'      => '商品sku',
+            'match'     => 'is_numeric',
+        ),
+
+        'c_price'     => array
+        (
+            'type'      => 'decimal-10,2',
+            'name'      => '出厂价',
+            'default'   => '',
+            'desc'      => '出厂价',
+            'match'     => 'option',
+            'update'    => 'text',
+        ),
+
+        'reorder'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '排序-数值越大越靠前,相当于置顶',
+            'default'   => '1',
+            'desc'      => '请输入排序',
+            'match'     => 'option',
+            //'update'  => 'text',
+            'search'    => 'order',
+            '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
+    (
+        'insert' => false,
+        'edit' => false,
+        'delete' => false,
+        'num' => false,
+        'page_list_table' => 'sku',
+
+        # 自定义快捷新增和编辑
+        'button' => array
+        (
+            //'自定义属性' => array('fast', 1, 'config&where_id=1'),
+        ),
+    ),
+
+    # request 请求接口定义
+    'request' => array
+    (
+        '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;

+ 124 - 0
app/factory/lib/Manage.php

@@ -33,4 +33,128 @@ class Manage
             Dever::db('factory/info')->update($update);
         }
     }
+
+    /**
+     * 更新商品信息
+     *
+     * @return mixed
+     */
+    public function goodsUpdate($id, $name, $data)
+    {
+        $update = array();
+        $goods_id = Dever::param('goods_id', $data);
+        if ($goods_id) {
+            $info = Dever::db('goods/info')->find($goods_id);
+            $update['price_type'] = $info['price_type'];
+        }
+
+        if (isset($update) && $update) {
+            $update['where_id'] = $id;
+            Dever::db('store/goods')->update($update);
+        }
+    }
+
+    public function skuConfig()
+    {
+        $data['action'] = Dever::url('store/lib/manage.skuUp');
+        $data['info_id'] = Dever::input('search_option_store_goods_id');
+        return $data;
+    }
+
+    public function skuUp_api()
+    {
+        $store_goods_id = Dever::input('info_id');
+        $key = Dever::input('key');
+        $num = Dever::input('num');
+
+        $store_goods = Dever::db('store/goods')->one($store_goods_id);
+        if ($key) {
+            foreach ($key as $k => $v) {
+                if (isset($num[$k]) && $num[$k]) {
+                    $info = Dever::db('goods/info_sku')->one(array('key' => $v));
+                    $data = array();
+                    $data['store_id'] = $store_goods['store_id'];
+                    $data['goods_id'] = $store_goods['goods_id'];
+                    $data['store_goods_id'] = $store_goods_id;
+                    $data['sku_id'] = $info['id'];
+                    $store_info = Dever::db('store/goods_sku')->one($data);
+
+                    $data['num'] = $num[$k];
+                    if (!$store_info) {
+                        Dever::db('store/goods_sku')->insert($data);
+                    } else {
+                        $data['where_id'] = $info['id'];
+                        Dever::db('store/goods_sku')->update($data);
+                    }
+                }
+            }
+        }
+
+        Dever::out('yes');
+    }
+
+    public function skuInput()
+    {
+        $id = Dever::input('search_option_store_goods_id');
+
+        $store_goods = Dever::db('store/goods')->one($id);
+
+        $sku = Dever::db('goods/info_sku')->getData(array('info_id' => $store_goods['goods_id']));
+
+        $sku_num = Dever::db('store/goods_sku')->getData(array('store_goods_id' => $id));
+
+        $info = Dever::db('goods/info')->one($store_goods['goods_id']);
+
+        $info = \Goods\Lib\Info::init(-1)->info($info, 'list_reorder');
+
+        $html = '请先选择属性';
+        if ($info['sell_attr']) {
+            $head = '<thead><tr>';
+            $body = '<tbody>';
+            $option = array();
+            foreach ($info['sell_attr'] as $k => $v) {
+                $head .= '<th>'.$v['name'].'</th>';
+                if (isset($v['option_sku'])) {
+                    $option[$k] = $v['option_sku'];
+                }
+            }
+            $head .= '<th>库存</th>';
+            $head .= '</tr></thead>';
+
+            if ($option) {
+                $option = Dever::cartesian($option);
+
+                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);
+                    $f_price = $s_price = $price = $num = '';
+                    if (isset($sku[$key]) && isset($sku_num[$sku[$key]['id']])) {
+                        $num = $sku_num[$sku[$key]['id']]['num'];
+                    }
+                    $body .= '<td width="30"><input type="text" class="layui-input" name="num['.$k.']"  value="'.$num.'"/></td>';
+
+                    $body .= '<input type="hidden" name="key['.$k.']" value="'.$key.'"/>';
+                    $body .= '</tr>';
+                }
+            }
+
+            $body .= '</tbody>';
+            
+            $html = $head . $body;
+        }
+
+        return $html;
+    }
 }

+ 7 - 0
app/factory/template/manage/sku.php

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

+ 2 - 2
app/goods/database/info.php

@@ -178,9 +178,9 @@ $config = array
         'f_price'       => array
         (
             'type'      => 'decimal-10,2',
-            'name'      => '价',
+            'name'      => '采购价',
             'default'   => '',
-            'desc'      => '价',
+            'desc'      => '采购价',
             'match'     => 'option',
             'update'    => 'text',
             'show'      => 'price_type=1',

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

@@ -79,9 +79,9 @@ $config = array
         'f_price'       => array
         (
             'type'      => 'decimal-10,2',
-            'name'      => '价',
+            'name'      => '采购价',
             'default'   => '',
-            'desc'      => '价',
+            'desc'      => '采购价',
             'match'     => 'option',
             'update'    => 'text',
             'list'      => true,

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

@@ -48,6 +48,8 @@ $config = array
             'name'      => '商品名称',
             'default'   => '',
             'desc'      => '商品名称',
+            'value'     => Dever::input('search_option_shop_goods_id'),
+            'update'    => 'hidden',
             'match'     => 'is_numeric',
         ),
 

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

@@ -28,7 +28,6 @@ $config = array
             'name'      => '所属仓库',
             'default'   => '',
             'desc'      => '所属仓库',
-            'value'     => Dever::input('search_option_store_id'),
             'list'      => 'Dever::load("store/info-find#name", {store_id})',
         ),
 
@@ -48,6 +47,8 @@ $config = array
             'name'      => '商品名称',
             'default'   => '',
             'desc'      => '商品名称',
+            'value'     => Dever::input('search_option_store_goods_id'),
+            'update'    => 'hidden',
             'match'     => 'is_numeric',
         ),
 
@@ -165,32 +166,6 @@ $config = array
             'col' => '*,num-sell_num as num',
         ),
 
-        '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' => '*',
-        ),
-
         # 更新售出量
         'updateSell' => array
         (