|
@@ -37,30 +37,33 @@ class Sku
|
|
$data['key'] = Dever::input('key');
|
|
$data['key'] = Dever::input('key');
|
|
$data['hook'] = Dever::input('hook');
|
|
$data['hook'] = Dever::input('hook');
|
|
|
|
|
|
- $data['col'] = $this->getCol($data['other']);
|
|
|
|
|
|
+ $data['set'] = $this->getSet($data['other']);
|
|
return $data;
|
|
return $data;
|
|
}
|
|
}
|
|
|
|
|
|
- private function getCol($other)
|
|
|
|
|
|
+ private function getSet($other)
|
|
{
|
|
{
|
|
if ($other) {
|
|
if ($other) {
|
|
if (Dever::project($other)) {
|
|
if (Dever::project($other)) {
|
|
- $col = Dever::load($other . '/lib/sku')->col;
|
|
|
|
|
|
+ $set = Dever::load($other . '/lib/sku')->set;
|
|
|
|
+ if (!isset($set['price_type'])) {
|
|
|
|
+ $set['price_type'] = false;
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
Dever::alert($other . '不存在');
|
|
Dever::alert($other . '不存在');
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- $col = $this->col;
|
|
|
|
|
|
+ $set = array('col' => $this->col, 'price_type' => false);
|
|
}
|
|
}
|
|
|
|
|
|
- return $col;
|
|
|
|
|
|
+ return $set;
|
|
}
|
|
}
|
|
|
|
|
|
public function show()
|
|
public function show()
|
|
{
|
|
{
|
|
$config = Dever::load('goods/lib/sku')->config();
|
|
$config = Dever::load('goods/lib/sku')->config();
|
|
|
|
|
|
- return $this->table($config['goods_id'], $config['other'], $config['other_id'], $config['col'], true);
|
|
|
|
|
|
+ return $this->table($config['goods_id'], $config['other'], $config['other_id'], $config['set'], true);
|
|
}
|
|
}
|
|
|
|
|
|
public function update_api()
|
|
public function update_api()
|
|
@@ -90,7 +93,7 @@ class Sku
|
|
}
|
|
}
|
|
|
|
|
|
$update = $where;
|
|
$update = $where;
|
|
- foreach ($config['col'] as $k => $v) {
|
|
|
|
|
|
+ foreach ($config['set']['col'] as $k => $v) {
|
|
$update[$k] = Dever::input($k);
|
|
$update[$k] = Dever::input($k);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -141,7 +144,7 @@ class Sku
|
|
$data[$key] = $v;
|
|
$data[$key] = $v;
|
|
}
|
|
}
|
|
|
|
|
|
- foreach ($config['col'] as $k1 => $v1) {
|
|
|
|
|
|
+ foreach ($config['set']['col'] as $k1 => $v1) {
|
|
$value = Dever::input($k1);
|
|
$value = Dever::input($k1);
|
|
$cur_sku = false;
|
|
$cur_sku = false;
|
|
if (isset($value[$k])) {
|
|
if (isset($value[$k])) {
|
|
@@ -179,7 +182,7 @@ class Sku
|
|
if ($sku_id) {
|
|
if ($sku_id) {
|
|
$update['sku_id'] = $sku_id;
|
|
$update['sku_id'] = $sku_id;
|
|
}
|
|
}
|
|
- foreach ($config['col'] as $k => $v) {
|
|
|
|
|
|
+ foreach ($config['set']['col'] as $k => $v) {
|
|
if (isset($min[$k])) {
|
|
if (isset($min[$k])) {
|
|
$update[$k] = $min[$k];
|
|
$update[$k] = $min[$k];
|
|
}
|
|
}
|
|
@@ -194,28 +197,31 @@ class Sku
|
|
Dever::out('yes');
|
|
Dever::out('yes');
|
|
}
|
|
}
|
|
|
|
|
|
- public function table($goods, $other = false, $other_id = false, $col = false, $update = true, $parent_goods = false)
|
|
|
|
|
|
+ public function table($goods, $other = false, $other_id = false, $set = false, $update = true, $parent_goods = false)
|
|
{
|
|
{
|
|
- if (!$col) {
|
|
|
|
- $col = $this->getCol($other);
|
|
|
|
|
|
+ if (!$set) {
|
|
|
|
+ $set = $this->getSet($other);
|
|
}
|
|
}
|
|
$info = is_array($goods) ? $goods : Dever::db('goods/info')->one($goods);
|
|
$info = is_array($goods) ? $goods : Dever::db('goods/info')->one($goods);
|
|
$info = Info::init(-1)->info($info, 'view_reorder');
|
|
$info = Info::init(-1)->info($info, 'view_reorder');
|
|
|
|
|
|
- if ($info && $info['price_type'] == 4) {
|
|
|
|
- if ($update) {
|
|
|
|
- return '组合商品无法设置库存';
|
|
|
|
- }
|
|
|
|
- if ($info['goods'] && is_array($info['goods'])) {
|
|
|
|
- $html = '';
|
|
|
|
- foreach ($info['goods'] as $k => $v) {
|
|
|
|
- $html .= $this->table($v['id'], $other, $other_id, $col, $update, $v) . '<br />';
|
|
|
|
|
|
+ if ($info && $other && isset($set['price_type']) && $set['price_type']) {
|
|
|
|
+ $price_type = explode(',', $set['price_type']);
|
|
|
|
+ if (in_array($info['price_type'], $price_type)) {
|
|
|
|
+ if ($update) {
|
|
|
|
+ return '组合商品无法设置库存';
|
|
}
|
|
}
|
|
|
|
+ if ($info['goods'] && is_array($info['goods'])) {
|
|
|
|
+ $html = '';
|
|
|
|
+ foreach ($info['goods'] as $k => $v) {
|
|
|
|
+ $html .= $this->table($v['id'], $other, $other_id, $set, $update, $v) . '<br />';
|
|
|
|
+ }
|
|
|
|
|
|
- $html .= '*组合商品的库存为以上商品中的最低库存为准';
|
|
|
|
- return $html;
|
|
|
|
- } else {
|
|
|
|
- return '';
|
|
|
|
|
|
+ $html .= '*组合商品的库存为以上商品中的最低库存为准';
|
|
|
|
+ return $html;
|
|
|
|
+ } else {
|
|
|
|
+ return '';
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -229,24 +235,37 @@ class Sku
|
|
|
|
|
|
$sku = Dever::db('goods/info_sku')->getDataByKeys(array('info_id' => $info['id']));
|
|
$sku = Dever::db('goods/info_sku')->getDataByKeys(array('info_id' => $info['id']));
|
|
|
|
|
|
- $option = array();
|
|
|
|
- $head = '<thead><tr>';
|
|
|
|
|
|
+ $sell_attr = $option_attr = array();
|
|
|
|
+ $head = $option_head = '<thead><tr>';
|
|
$html = '请先选择属性';
|
|
$html = '请先选择属性';
|
|
|
|
|
|
|
|
+ if ($parent_goods) {
|
|
|
|
+ $head .= '<th>商品名称</th>';
|
|
|
|
+ $option_head .= '<th>商品名称</th>';
|
|
|
|
+ }
|
|
|
|
+
|
|
if (isset($info['sell_attr']) && $info['sell_attr']) {
|
|
if (isset($info['sell_attr']) && $info['sell_attr']) {
|
|
foreach ($info['sell_attr'] as $k => $v) {
|
|
foreach ($info['sell_attr'] as $k => $v) {
|
|
$head .= '<th>'.$v['name'].'</th>';
|
|
$head .= '<th>'.$v['name'].'</th>';
|
|
if (isset($v['option_sku'])) {
|
|
if (isset($v['option_sku'])) {
|
|
- $option[$k] = $v['option_sku'];
|
|
|
|
|
|
+ $sell_attr[$k] = $v['option_sku'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- $col_num = 0;
|
|
|
|
- if ($parent_goods) {
|
|
|
|
- $head .= '<th>商品名称</th>';
|
|
|
|
|
|
+ if (isset($info['option_attr']) && $info['option_attr']) {
|
|
|
|
+ $option_head .= '<th>属性名称</th>';
|
|
|
|
+ foreach ($info['option_attr'] as $k => $v) {
|
|
|
|
+ if (isset($v['option'])) {
|
|
|
|
+ $option_attr = array_merge($option_attr, $v['option']);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- foreach ($col as $k => $v) {
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ $col_num = 0;
|
|
|
|
+
|
|
|
|
+ foreach ($set['col'] as $k => $v) {
|
|
if (!$update && strstr($v, '^')) {
|
|
if (!$update && strstr($v, '^')) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
@@ -259,13 +278,18 @@ class Sku
|
|
}
|
|
}
|
|
|
|
|
|
$head .= '<th>'.$v.'</th>';
|
|
$head .= '<th>'.$v.'</th>';
|
|
|
|
+ $option_head .= '<th>'.$v.'</th>';
|
|
}
|
|
}
|
|
|
|
|
|
$head .= '</tr></thead>';
|
|
$head .= '</tr></thead>';
|
|
|
|
+ $option_head .= '</tr></thead>';
|
|
|
|
|
|
$body = '<tbody>';
|
|
$body = '<tbody>';
|
|
|
|
+ $option_body = '<tbody>';
|
|
|
|
|
|
- if (!$option) {
|
|
|
|
|
|
+ if (!$sell_attr) {
|
|
|
|
+
|
|
|
|
+ $prefix = '[单价设置]:';
|
|
|
|
|
|
if (!$update && $col_num <= 1) {
|
|
if (!$update && $col_num <= 1) {
|
|
$head = '';
|
|
$head = '';
|
|
@@ -277,10 +301,10 @@ class Sku
|
|
$body .= '<tr>';
|
|
$body .= '<tr>';
|
|
|
|
|
|
if ($parent_goods) {
|
|
if ($parent_goods) {
|
|
- $body .= '<td>'.$parent_goods['name'].'</td>';
|
|
|
|
|
|
+ $body .= '<td width="10">'.$parent_goods['name'].'</td>';
|
|
}
|
|
}
|
|
|
|
|
|
- foreach ($col as $k1 => $v1) {
|
|
|
|
|
|
+ foreach ($set['col'] as $k1 => $v1) {
|
|
if (!$update && strstr($v1, '^')) {
|
|
if (!$update && strstr($v1, '^')) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
@@ -310,11 +334,13 @@ class Sku
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- $option = Dever::cartesian($option);
|
|
|
|
|
|
+ $prefix = '[多价设置]:';
|
|
|
|
+
|
|
|
|
+ $sell_attr = Dever::cartesian($sell_attr);
|
|
|
|
|
|
$show = false;
|
|
$show = false;
|
|
|
|
|
|
- foreach ($option as $k => $v) {
|
|
|
|
|
|
+ foreach ($sell_attr as $k => $v) {
|
|
$body .= '<tr data-row="' .($k+1). '">';
|
|
$body .= '<tr data-row="' .($k+1). '">';
|
|
|
|
|
|
if ($parent_goods) {
|
|
if ($parent_goods) {
|
|
@@ -334,7 +360,7 @@ class Sku
|
|
}
|
|
}
|
|
$key = implode('_', $key);
|
|
$key = implode('_', $key);
|
|
|
|
|
|
- foreach ($col as $k1 => $v1) {
|
|
|
|
|
|
+ foreach ($set['col'] as $k1 => $v1) {
|
|
if (!$update && strstr($v1, '^')) {
|
|
if (!$update && strstr($v1, '^')) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
@@ -372,9 +398,67 @@ class Sku
|
|
|
|
|
|
$html = $head . $body;
|
|
$html = $head . $body;
|
|
|
|
|
|
- if (!$update) {
|
|
|
|
- $html = '<table>' . $html . '</table>';
|
|
|
|
|
|
+ if ($update) {
|
|
|
|
+ $html = $prefix . '<table class="layui-table">' . $html . '</table>';
|
|
|
|
+ } else {
|
|
|
|
+ $html = '<table class="layui-table">' . $html . '</table>';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ($option_attr) {
|
|
|
|
+ print_r($option_attr);die;
|
|
|
|
+ foreach ($option_attr as $k => $v) {
|
|
|
|
+
|
|
|
|
+ $option_body .= '<tr data-row="' .($k+1). '">';
|
|
|
|
+
|
|
|
|
+ if ($parent_goods) {
|
|
|
|
+ $option_body .= '<td>'.$parent_goods['name'].'</td>';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $rows = 1;
|
|
|
|
+ $option_body .= '<td width="50" rowspan="'.$rows.'">'.$v['parent_name'] . '-' . $v['name'].'</td>';
|
|
|
|
+ $id = array
|
|
|
|
+ (
|
|
|
|
+ 'id' => $v['id'],
|
|
|
|
+ 'attr_id' => $v['info_id'],
|
|
|
|
+ );
|
|
|
|
+ $key = $v['info_id'] . '-' . $v['id'];
|
|
|
|
+
|
|
|
|
+ foreach ($set['col'] as $k1 => $v1) {
|
|
|
|
+ if (!$update && strstr($v1, '^')) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ $value = '';
|
|
|
|
+ if (isset($sku[$key])) {
|
|
|
|
+ if (isset($sku_value[$sku[$key]['id']][$k1])) {
|
|
|
|
+ $value = $sku_value[$sku[$key]['id']][$k1];
|
|
|
|
+ } elseif (isset($sku[$key][$k1])) {
|
|
|
|
+ $value = $sku[$key][$k1];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ($update) {
|
|
|
|
+ if (strstr($v1, '|')) {
|
|
|
|
+ $v1 = str_replace('|', '', $v1);
|
|
|
|
+ $option_body .= '<td width="30">'.$value.'</td>';
|
|
|
|
+ } else {
|
|
|
|
+ $option_body .= '<td width="30"><input type="text" class="layui-input" name="'.$k1.'['.$k.']" value="'.$value.'"/></td>';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ $option_body .= '<td width="30">'.$value.'</td>';
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ($update) {
|
|
|
|
+ $option_body .= '<input type="hidden" name="key['.$k.']" value="'.$key.'"/><textarea style="display:none;" name="attr['.$k.']">'.json_encode($id).'</textarea>';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $option_body .= '</tr>';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $html = $html . '<br />[加价设置]:<table class="layui-table">' . $option_head . $option_body . '</table>';;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
|
|
return $html;
|
|
return $html;
|
|
}
|
|
}
|