|
@@ -35,8 +35,10 @@ class Sku
|
|
|
|
|
|
$data['attr'] = Dever::input('attr');
|
|
|
$data['key'] = Dever::input('key');
|
|
|
- $data['option_attr'] = Dever::input('option_attr');
|
|
|
- $data['option_key'] = Dever::input('option_key');
|
|
|
+ $data['single_attr'] = Dever::input('single_attr');
|
|
|
+ $data['single_key'] = Dever::input('single_key');
|
|
|
+ $data['input_attr'] = Dever::input('input_attr');
|
|
|
+ $data['input_key'] = Dever::input('input_key');
|
|
|
$data['hook'] = Dever::input('hook');
|
|
|
|
|
|
$data['set'] = $this->getSet($data['other']);
|
|
@@ -202,19 +204,68 @@ class Sku
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if ($config['option_key']) {
|
|
|
+ if ($config['single_key']) {
|
|
|
|
|
|
- if (!is_array($config['option_key'])) {
|
|
|
- $config['option_key'] = explode(',', $config['option_key']);
|
|
|
+ if (!is_array($config['single_key'])) {
|
|
|
+ $config['single_key'] = explode(',', $config['single_key']);
|
|
|
}
|
|
|
- foreach ($config['option_key'] as $k => $v) {
|
|
|
+ foreach ($config['single_key'] as $k => $v) {
|
|
|
+ $type = 2;
|
|
|
+ if (strstr($v, '||')) {
|
|
|
+ $temp = explode('||', $v);
|
|
|
+ $v = $temp[0];
|
|
|
+ $type = $temp[1];
|
|
|
+ }
|
|
|
+ if (isset($config['single_attr'][$k])) {
|
|
|
+
|
|
|
+ $data = $where;
|
|
|
+ if ($config['other']) {
|
|
|
+ $sku = Dever::db('goods/info_sku')->one(array('key' => $v, 'info_id' => $config['goods_id']));
|
|
|
+ if (!$sku) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $data[$key] = $sku['id'];
|
|
|
+
|
|
|
+ $info = Dever::db($sku_table)->one($data);
|
|
|
+ } else {
|
|
|
+ $info = Dever::db('goods/info_sku')->one(array('key' => $v, 'info_id' => $config['goods_id']));
|
|
|
+ $data['attr'] = $config['single_attr'][$k];
|
|
|
+ $data[$key] = $v;
|
|
|
+ }
|
|
|
+
|
|
|
+ $data['type'] = $type;
|
|
|
+
|
|
|
+ foreach ($config['set']['col'] as $k1 => $v1) {
|
|
|
+ $value = Dever::input('single_' . $k1);
|
|
|
+ if (isset($value[$k])) {
|
|
|
+ $data[$k1] = $value[$k];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Dever::config('base')->hook = false;
|
|
|
+ if (!$info) {
|
|
|
+ $temp = Dever::db($sku_table)->insert($data);
|
|
|
+ } else {
|
|
|
+ $data['where_id'] = $info['id'];
|
|
|
+ Dever::db($sku_table)->update($data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($config['input_key']) {
|
|
|
+
|
|
|
+ if (!is_array($config['input_key'])) {
|
|
|
+ $config['input_key'] = explode(',', $config['input_key']);
|
|
|
+ }
|
|
|
+ foreach ($config['input_key'] as $k => $v) {
|
|
|
$type = 3;
|
|
|
if (strstr($v, '||')) {
|
|
|
$temp = explode('||', $v);
|
|
|
$v = $temp[0];
|
|
|
$type = $temp[1];
|
|
|
}
|
|
|
- if (isset($config['option_attr'][$k])) {
|
|
|
+ if (isset($config['input_key'][$k])) {
|
|
|
|
|
|
$data = $where;
|
|
|
if ($config['other']) {
|
|
@@ -227,14 +278,14 @@ class Sku
|
|
|
$info = Dever::db($sku_table)->one($data);
|
|
|
} else {
|
|
|
$info = Dever::db('goods/info_sku')->one(array('key' => $v, 'info_id' => $config['goods_id']));
|
|
|
- $data['attr'] = $config['option_attr'][$k];
|
|
|
+ $data['attr'] = $config['input_key'][$k];
|
|
|
$data[$key] = $v;
|
|
|
}
|
|
|
|
|
|
$data['type'] = $type;
|
|
|
|
|
|
foreach ($config['set']['col'] as $k1 => $v1) {
|
|
|
- $value = Dever::input('option_' . $k1);
|
|
|
+ $value = Dever::input('input_' . $k1);
|
|
|
if (isset($value[$k])) {
|
|
|
$data[$k1] = $value[$k];
|
|
|
}
|
|
@@ -294,33 +345,43 @@ class Sku
|
|
|
|
|
|
$sku = Dever::db('goods/info_sku')->getDataByKeys(array('info_id' => $info['id']));
|
|
|
|
|
|
- $sell_attr = $option_attr = array();
|
|
|
- $head = $option_head = '<thead><tr>';
|
|
|
+ $group_attr = $single_attr = $input_attr = array();
|
|
|
+ $head = $single_head = $input_head = '<thead><tr>';
|
|
|
$html = '请先选择属性';
|
|
|
|
|
|
if ($parent_goods) {
|
|
|
$head .= '<th>商品名称</th>';
|
|
|
- $option_head .= '<th>商品名称</th>';
|
|
|
+ $single_head .= '<th>商品名称</th>';
|
|
|
+ $input_head .= '<th>商品名称</th>';
|
|
|
}
|
|
|
|
|
|
- if (isset($info['sell_attr']) && $info['sell_attr']) {
|
|
|
- foreach ($info['sell_attr'] as $k => $v) {
|
|
|
- $head .= '<th>'.$v['name'].'</th>';
|
|
|
- if (isset($v['option_sku'])) {
|
|
|
- $sell_attr[$k] = $v['option_sku'];
|
|
|
+ if (isset($info['group_attr']) && $info['group_attr']) {
|
|
|
+ foreach ($info['group_attr'] as $k => $v) {
|
|
|
+ if (isset($info['attr'][$v]['option'])) {
|
|
|
+ $group_attr[$k] = $info['attr'][$v]['option'];
|
|
|
+ $head .= '<th>'.$info['attr'][$v]['name'].'</th>';
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (isset($info['option_attr']) && $info['option_attr']) {
|
|
|
- $option_head .= '<th>属性名称</th>';
|
|
|
- foreach ($info['option_attr'] as $k => $v) {
|
|
|
- if (isset($v['option_sku'])) {
|
|
|
- $option_attr = array_merge($option_attr, $v['option_sku']);
|
|
|
+ if (isset($info['single_attr']) && $info['single_attr']) {
|
|
|
+ $single_head .= '<th>属性名称</th>';
|
|
|
+ foreach ($info['single_attr'] as $k => $v) {
|
|
|
+ if (isset($info['attr'][$v]['option'])) {
|
|
|
+ $single_attr = array_merge($single_attr, $info['attr'][$v]['option']);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if (isset($info['input_attr']) && $info['input_attr']) {
|
|
|
+ $input_head .= '<th>属性名称</th>';
|
|
|
+ $input_head .= '<th>起算</th>';
|
|
|
+ foreach ($info['input_attr'] as $k => $v) {
|
|
|
+ if (isset($info['attr'][$v]['option'])) {
|
|
|
+ $input_attr[$k] = $info['attr'][$v];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
$col_num = 0;
|
|
|
|
|
@@ -337,18 +398,21 @@ class Sku
|
|
|
}
|
|
|
|
|
|
$head .= '<th>'.$v.'</th>';
|
|
|
- $option_head .= '<th>'.$v.'</th>';
|
|
|
+ $single_head .= '<th>'.$v.'</th>';
|
|
|
+ $input_head .= '<th>'.$v.'</th>';
|
|
|
}
|
|
|
|
|
|
$head .= '</tr></thead>';
|
|
|
- $option_head .= '</tr></thead>';
|
|
|
+ $single_head .= '</tr></thead>';
|
|
|
+ $input_head .= '</tr></thead>';
|
|
|
|
|
|
$body = '<tbody>';
|
|
|
- $option_body = '<tbody>';
|
|
|
+ $single_body = '<tbody>';
|
|
|
+ $input_body = '<tbody>';
|
|
|
|
|
|
- if (!$sell_attr) {
|
|
|
+ if (!$group_attr) {
|
|
|
|
|
|
- $prefix = '[单价设置]:';
|
|
|
+ $prefix = '[总价设置]:';
|
|
|
|
|
|
if (!$update && $col_num <= 1) {
|
|
|
$head = '';
|
|
@@ -393,13 +457,13 @@ class Sku
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- $prefix = '[多价设置]:';
|
|
|
+ $prefix = '[组合价格设置]:';
|
|
|
|
|
|
- $sell_attr = Dever::cartesian($sell_attr);
|
|
|
+ $group_attr = Dever::cartesian($group_attr);
|
|
|
|
|
|
$show = false;
|
|
|
|
|
|
- foreach ($sell_attr as $k => $v) {
|
|
|
+ foreach ($group_attr as $k => $v) {
|
|
|
$body .= '<tr data-row="' .($k+1). '">';
|
|
|
|
|
|
if ($parent_goods) {
|
|
@@ -446,7 +510,6 @@ class Sku
|
|
|
}
|
|
|
|
|
|
if ($update) {
|
|
|
- $key .= '||2';
|
|
|
$body .= '<input type="hidden" name="key['.$k.']" value="'.$key.'"/><textarea style="display:none;" name="attr['.$k.']">'.json_encode($id).'</textarea>';
|
|
|
}
|
|
|
|
|
@@ -464,19 +527,19 @@ class Sku
|
|
|
$html = '<table class="layui-table">' . $html . '</table>';
|
|
|
}
|
|
|
|
|
|
- if ($option_attr) {
|
|
|
+ if ($single_attr) {
|
|
|
$html = $prefix . $html;
|
|
|
- foreach ($option_attr as $k => $v) {
|
|
|
+ foreach ($single_attr as $k => $v) {
|
|
|
|
|
|
$id = array();
|
|
|
- $option_body .= '<tr data-row="' .($k+1). '">';
|
|
|
+ $single_body .= '<tr data-row="' .($k+1). '">';
|
|
|
|
|
|
if ($parent_goods) {
|
|
|
- $option_body .= '<td>'.$parent_goods['name'].'</td>';
|
|
|
+ $single_body .= '<td>'.$parent_goods['name'].'</td>';
|
|
|
}
|
|
|
|
|
|
$rows = 1;
|
|
|
- $option_body .= '<td width="50" rowspan="'.$rows.'">'. $v['parent_name'].'->'. $v['name'].'</td>';
|
|
|
+ $single_body .= '<td width="100" rowspan="'.$rows.'">'. $v['parent_name'].'->'. $v['name'].'</td>';
|
|
|
$id[] = array
|
|
|
(
|
|
|
'id' => $v['id'],
|
|
@@ -500,28 +563,102 @@ class Sku
|
|
|
if ($update) {
|
|
|
if (strstr($v1, '|')) {
|
|
|
$v1 = str_replace('|', '', $v1);
|
|
|
- $option_body .= '<td width="30">'.$value.'</td>';
|
|
|
+ $single_body .= '<td width="30">'.$value.'</td>';
|
|
|
+ } else {
|
|
|
+ $single_body .= '<td width="30"><input type="text" class="layui-input" name="single_'.$k1.'['.$k.']" value="'.$value.'"/></td>';
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ $single_body .= '<td width="30">'.$value.'</td>';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($update) {
|
|
|
+ $single_body .= '<input type="hidden" name="single_key['.$k.']" value="'.$key.'"/><textarea style="display:none;" name="single_attr['.$k.']">'.json_encode($id).'</textarea>';
|
|
|
+ }
|
|
|
+
|
|
|
+ $single_body .= '</tr>';
|
|
|
+ }
|
|
|
+
|
|
|
+ $html = $html . '<br />[单选价格设置]:<table class="layui-table">' . $single_head . $single_body . '</table>';;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($input_attr) {
|
|
|
+ foreach ($input_attr as $k => $v) {
|
|
|
+
|
|
|
+ if ($v['sell_compute'] == 2) {
|
|
|
+ $v['sell_compute_type'] = '+';
|
|
|
+ } elseif ($v['sell_compute'] == 3) {
|
|
|
+ $v['sell_compute_type'] = '-';
|
|
|
+ } else {
|
|
|
+ $v['sell_compute_type'] = '*';
|
|
|
+ }
|
|
|
+
|
|
|
+ $id = array();
|
|
|
+ $input_body .= '<tr data-row="' .($k+1). '">';
|
|
|
+
|
|
|
+ if ($parent_goods) {
|
|
|
+ $input_body .= '<td>'.$parent_goods['name'].'</td>';
|
|
|
+ }
|
|
|
+
|
|
|
+ $rows = 1;
|
|
|
+ $key = $id = $name = array();
|
|
|
+ foreach ($v['option'] as $k1 => $v1) {
|
|
|
+ $id[] = array
|
|
|
+ (
|
|
|
+ 'id' => $v1['id'],
|
|
|
+ 'attr_id' => $v1['info_id'],
|
|
|
+ );
|
|
|
+ $key[] = $v1['price_key'];
|
|
|
+ $name[] = $v1['name'];
|
|
|
+ }
|
|
|
+ $key = implode('_', $key);
|
|
|
+ $input_body .= '<td width="100" rowspan="'.$rows.'">'. $v['name'].'->'. implode($v['sell_compute_type'], $name).'</td>';
|
|
|
+ $input_body .= '<td width="5"> >='.$v['sell_value'].'</td>';
|
|
|
+ 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);
|
|
|
+ $input_body .= '<td width="30">'.$value.'</td>';
|
|
|
} else {
|
|
|
- $option_body .= '<td width="30"><input type="text" class="layui-input" name="option_'.$k1.'['.$k.']" value="'.$value.'"/></td>';
|
|
|
+ $input_body .= '<td width="30"><input type="text" class="layui-input" name="input_'.$k1.'['.$k.']" value="'.$value.'"/></td>';
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
- $option_body .= '<td width="30">'.$value.'</td>';
|
|
|
+ $input_body .= '<td width="30">'.$value.'</td>';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if ($update) {
|
|
|
- $key .= '||3';
|
|
|
- $option_body .= '<input type="hidden" name="option_key['.$k.']" value="'.$key.'"/><textarea style="display:none;" name="option_attr['.$k.']">'.json_encode($id).'</textarea>';
|
|
|
+ $input_body .= '<input type="hidden" name="input_key['.$k.']" value="'.$key.'"/><textarea style="display:none;" name="input_attr['.$k.']">'.json_encode($id).'</textarea>';
|
|
|
}
|
|
|
|
|
|
- $option_body .= '</tr>';
|
|
|
+ $input_body .= '</tr>';
|
|
|
}
|
|
|
|
|
|
- $html = $html . '<br />[加价设置]:<table class="layui-table">' . $option_head . $option_body . '</table>';;
|
|
|
+ $html = $html . '<br />[计算价设置]:<table class="layui-table">' . $input_head . $input_body . '</table>';;
|
|
|
}
|
|
|
|
|
|
|
|
|
return $html;
|
|
|
}
|
|
|
+
|
|
|
+ private function create_table($head, $body)
|
|
|
+ {
|
|
|
+ $html = '<table class="layui-table">';
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
}
|