123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833 |
- <?php
- namespace Goods\Lib;
- use Dever;
- class Sku
- {
- # 设置sku特殊字段
- private $col = array
- (
- 'code' => '商品条码号',
- 's_price' => '市场价',
- 'f_price' => '门店采购价',
- 'c_price' => '成本价',
- 'price' => '销售价',
- 'min' => '采购起订数',
- 'unit' => '计量单位',
- 'weight' => '重量(kg)',
- 'cunhuo_code' => '存货编码',
- );
- private $unit = array
- (
- '请选择','件','箱','盒','袋','个','桶','台','套','瓶','罐','支','条','kg','g','L','ML'
- );
- # 主要价格字段
- private $main = 'price';
- public function __construct()
- {
- # 设置权限
- Dever::load('manage/auth.init');
- }
- public function config()
- {
- $data['action'] = Dever::url('goods/lib/sku.update');
- $data['goods_id'] = Dever::input('goods_id');
- $data['other'] = Dever::input('other');
- $data['other_id'] = Dever::input('other_id');
- if ($data['other']) {
- $data['other_col'] = $data['other'] . '_id';
- }
-
- $data['attr'] = Dever::input('attr');
- $data['key'] = Dever::input('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']);
- return $data;
- }
- private function getSet($other)
- {
- if ($other) {
- if (Dever::project($other)) {
- $set = Dever::load($other . '/lib/sku')->set;
- if (!isset($set['price_type'])) {
- $set['price_type'] = false;
- }
- } else {
- Dever::alert($other . '不存在');
- }
- } else {
- $set = array('col' => $this->col, 'price_type' => false);
- }
- return $set;
- }
- public function show()
- {
- $config = Dever::load('goods/lib/sku')->config();
- return $this->table($config['goods_id'], $config['other'], $config['other_id'], $config['set'], true);
- }
- public function update_api()
- {
- $config = Dever::load('goods/lib/sku')->config();
- $where = array();
- if ($config['other']) {
- $where[$config['other_col']] = $config['other_id'];
- $where['goods_id'] = $config['goods_id'];
- $key = 'sku_id';
- $table = $config['other'] . '/goods';
- } else {
- $where['info_id'] = $config['goods_id'];
- $key = 'key';
- $table = 'goods/info';
- $w['option_info_id'] = $config['goods_id'];
- $w['set_state'] = 2;
- Dever::db('goods/info_sku')->updates($w);
- }
- $sku_table = $table . '_sku';
- $code = array();
- if ($config['key'] == -1) {
- if ($config['other']) {
- if ($config['other'] == 'price') {
- $info = Dever::db($table)->one($config['other_id']);
- } else {
- $info = Dever::db($table)->one($where);
- }
-
- } else {
- $info = Dever::db($table)->one($config['goods_id']);
- }
- $update = $where;
- foreach ($config['set']['col'] as $k => $v) {
- $update[$k] = Dever::input($k);
- if (!$update[$k] && strstr($k, '_price')) {
- $update[$k] = 0;
- }
- if ($k == 'code') {
- if (!$update[$k]) {
- Dever::alert('商品条码号不能为空');
- }
- if (in_array($update[$k], $code)) {
- Dever::alert('商品条码号已重复');
- }
- $code[] = $update[$k];
- }
- }
- if ($info && $update) {
- $update['where_id'] = $info['id'];
- Dever::db($table)->update($update);
- unset($update['where_id']);
- }
- $where[$key] = -1;
- /*
- if ($config['other']) {
- $info_sku = Dever::db('goods/info_sku')->one(array('goods_id' => $config['goods_id'], 'key' => -1));
- $where[$key] = $info_sku['id'];
- }
- */
- $info = Dever::db($sku_table)->one($where);
- $update[$key] = $where[$key];
- Dever::config('base')->hook = false;
- if (!$info) {
- $state = Dever::db($sku_table)->insert($update);
- } else {
- $update['where_id'] = $info['id'];
- $update['state'] = 1;
- $state = Dever::db($sku_table)->update($update);
- }
-
- } elseif ($config['key']) {
- if (!is_array($config['key'])) {
- $config['key'] = explode(',', $config['key']);
- }
- $min = array();
- $cur_sku = false;
- $sku_id = false;
- foreach ($config['key'] as $k => $v) {
- $type = 1;
- if (strstr($v, '||')) {
- $temp = explode('||', $v);
- $v = $temp[0];
- $type = $temp[1];
- }
- if (isset($config['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['attr'][$k];
- $data[$key] = $v;
- }
- $data['type'] = $type;
-
- foreach ($config['set']['col'] as $k1 => $v1) {
- $value = Dever::input($k1);
- $cur_sku = false;
- if (isset($value[$k])) {
- $data[$k1] = $value[$k];
- if ($k1 == 'code') {
- if (!$data[$k1]) {
- Dever::alert('商品条码号不能为空');
- }
- if (in_array($data[$k1], $code)) {
- Dever::alert('商品条码号已重复');
- }
- $code[] = $data[$k1];
- }
- if ($k1 == $this->main) {
- if (!isset($min[$k1])) {
- $min = $data;
- $cur_sku = true;
- } elseif ($min[$k1] > $data[$k1]) {
- $min = $data;
- $cur_sku = true;
- }
- }
- }
- }
- Dever::config('base')->hook = false;
- if (!$info) {
- $temp = Dever::db($sku_table)->insert($data);
- if ($cur_sku) {
- $sku_id = $temp;
- }
- } else {
- $data['where_id'] = $info['id'];
- if ($cur_sku) {
- $sku_id = $data['where_id'];
- }
- $data['state'] = 1;
- Dever::db($sku_table)->update($data);
- }
- }
- }
- if (!$config['other'] && $min) {
- $update = array();
- if ($sku_id) {
- $update['sku_id'] = $sku_id;
- }
- foreach ($config['set']['col'] as $k => $v) {
- if (isset($min[$k])) {
- $update[$k] = $min[$k];
- }
- }
- $update['where_id'] = $config['goods_id'];
- Dever::db($table)->update($update);
- }
- }
- if ($config['single_key']) {
- if (!is_array($config['single_key'])) {
- $config['single_key'] = explode(',', $config['single_key']);
- }
- 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'];
- $data['state'] = 1;
- 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['input_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['input_attr'][$k];
- $data[$key] = $v;
- }
- $data['type'] = $type;
-
- foreach ($config['set']['col'] as $k1 => $v1) {
- $value = Dever::input('input_' . $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'];
- $data['state'] = 1;
- Dever::db($sku_table)->update($data);
- }
- }
- }
- }
- Dever::config('base')->hook = true;
- Dever::out('yes');
- }
- public function table($goods, $other = false, $other_id = false, $set = false, $update = true, $parent_goods = false)
- {
- if (!$set) {
- $set = $this->getSet($other);
- }
- $info = is_array($goods) ? $goods : Dever::db('goods/info')->one($goods);
- $info = Info::init(-1)->info($info, 'view_reorder');
- 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 '';
- }
- }
- }
- $input = '';
- $sku_value = array();
- if ($other) {
- $other_col = $other . '_id';
- $sku_value = Dever::db($other . '/goods_sku')->getData(array('goods_id' => $info['id'], $other_col => $other_id, 'state_1' => 1));
- if ($other == 'price') {
- $other_col = 'id';
- }
- $input = '<input type="hidden" name="goods_id" value="'.$info['id'].'"/><input type="hidden" name="'.$other_col.'" value="'.$other_id.'"/>';
- }
- $sku = Dever::db('goods/info_sku')->getDataByKeys(array('info_id' => $info['id']));
- $group_attr = $single_attr = $input_attr = array();
- $head = $single_head = $input_head = '<thead><tr>';
- $html = '请先选择属性';
- if ($parent_goods) {
- $head .= '<th>商品名称</th>';
- $single_head .= '<th>商品名称</th>';
- $input_head .= '<th>商品名称</th>';
- }
- if (isset($info['group_attr']) && $info['group_attr']) {
- foreach ($info['group_attr'] as $k => $v) {
- if (isset($info['attr'][$v]['option']) && $info['attr'][$v]['option']) {
- $group_attr[$k] = $info['attr'][$v]['option'];
- $head .= '<th>'.$info['attr'][$v]['name'].'</th>';
- }
- }
- }
- 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']) && $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']) && $info['attr'][$v]['option']) {
- $input_attr[$k] = $info['attr'][$v];
- }
- }
- }
- $col_num = 0;
-
- foreach ($set['col'] as $k => $v) {
- if (!$update && strstr($v, '^')) {
- continue;
- }
- $col_num++;
- if (strstr($v, '^')) {
- $v = str_replace('^', '', $v);
- }
- if (strstr($v, '|')) {
- $v = str_replace('|', '', $v);
- }
-
- $head .= '<th>'.$v.'</th>';
- $single_head .= '<th>'.$v.'</th>';
- $input_head .= '<th>'.$v.'</th>';
- }
-
- $head .= '</tr></thead>';
- $single_head .= '</tr></thead>';
- $input_head .= '</tr></thead>';
- $body = '<tbody>';
- $single_body = '<tbody>';
- $input_body = '<tbody>';
- if (!$group_attr) {
- $prefix = '[单一规格]:';
- if (!$update && $col_num <= 1) {
- $head = '';
- }
- if ($update) {
- $input .= '<input type="hidden" name="key" value="-1"/>';
- }
- $body .= '<tr>';
- if ($parent_goods) {
- $body .= '<td width="10">'.$parent_goods['name'].'</td>';
- }
- foreach ($set['col'] as $k1 => $v1) {
- if (!$update && strstr($v1, '^')) {
- continue;
- }
- $value = $this->getValue($k1, -1, $sku_value, $sku);
-
- if ($update) {
- if (strstr($v1, '|')) {
- $v1 = str_replace('|', '', $v1);
- $body .= '<td width="30">'.$value.'</td>';
- } elseif ($k1 == 'unit') {
- $select = '';
- foreach ($this->unit as $k9 => $v9) {
- if ($value == $v9) {
- $selected = 'selected';
- } else {
- $selected = '';
- }
- $k9 = $v9;
- if ($v9 == '请选择') {
- $k9 = '';
- }
- $select .= '<option value="'.$k9.'" '.$selected.'>'.$v9.'</option>';
- }
- $body .= '<td width="30"><select lay-ignore name="'.$k1.'" >'.$select.'</select></td>';
- } else {
- $body .= '<td width="30"><input type="text" class="layui-input" name="'.$k1.'" value="'.$value.'"/></td>';
- }
-
- } elseif ($col_num > 1) {
- $body .= '<td width="30">'.$value.'</td>';
- } else {
- $body .= $value;
- }
- }
- $body .= '</tr>';
- } else {
-
- $prefix = '[组合规格]:';
- $group_attr = Dever::cartesian($group_attr);
- if ($sku_value) {
- foreach ($group_attr as $k => $v) {
- $key = array();
- foreach ($v['name'] as $k1 => $v1) {
- $key[] = $v['info_id'][$k1] . '-' . $v['id'][$k1];
- }
- $key = implode('_', $key);
- if (!isset($sku[$key])) {
- unset($group_attr[$k]);
- } elseif (isset($sku[$key]) && !isset($sku_value[$sku[$key]['id']])) {
- unset($group_attr[$k]);
- }
- }
- }
- $show = false;
- if ($group_attr) {
- foreach ($group_attr as $k => $v) {
- $body .= '<tr data-row="' .($k+1). '">';
- if ($parent_goods) {
- $body .= '<td>'.$parent_goods['name'].'</td>';
- }
- $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);
- foreach ($set['col'] as $k1 => $v1) {
- if (!$update && strstr($v1, '^')) {
- continue;
- }
- $value = $this->getValue($k1, $key, $sku_value, $sku);
-
- if ($update) {
- if (strstr($v1, '|')) {
- $v1 = str_replace('|', '', $v1);
- $body .= '<td width="30">'.$value.'</td>';
- } elseif ($k1 == 'unit') {
- $select = '';
- foreach ($this->unit as $k9 => $v9) {
- if ($value == $v9) {
- $selected = 'selected';
- } else {
- $selected = '';
- }
- $k9 = $v9;
- if ($v9 == '请选择') {
- $k9 = '';
- }
- $select .= '<option value="'.$k9.'" '.$selected.'>'.$v9.'</option>';
- }
- $body .= '<td width="30"><select lay-ignore name="'.$k1.'['.$k.']" >'.$select.'</select></td>';
- } else {
- $body .= '<td width="30"><input type="text" class="layui-input" name="'.$k1.'['.$k.']" value="'.$value.'"/></td>';
- }
-
- } else {
- $body .= '<td width="30">'.$value.'</td>';
- }
- }
- if ($update) {
- $body .= '<input type="hidden" name="key['.$k.']" value="'.$key.'"/><textarea style="display:none;" name="attr['.$k.']">'.json_encode($id).'</textarea>';
- }
-
- $body .= '</tr>';
- }
- } else {
- $prefix = $head = $body = '';
- }
- }
- $body .= $input;
-
- $html = $prefix . $head . $body;
- if ($update) {
- $html = '<table class="layui-table goods_table" style="width: 100%;">' . $html . '</table>';
- } else {
- $html = '<table class="layui-table goods_table" style="width: 100%;">' . $html . '</table>';
- }
- if ($single_attr && $sku_value) {
- foreach ($single_attr as $k => $v) {
- $key = $v['info_id'] . '-' . $v['id'];
- if (!isset($sku[$key])) {
- unset($single_attr[$k]);
- } elseif (isset($sku[$key]) && !isset($sku_value[$sku[$key]['id']])) {
- unset($single_attr[$k]);
- }
- }
- }
- if ($single_attr) {
- $html = $html;
- foreach ($single_attr as $k => $v) {
- $id = array();
- $single_body .= '<tr data-row="' .($k+1). '">';
- if ($parent_goods) {
- $single_body .= '<td>'.$parent_goods['name'].'</td>';
- }
- $rows = 1;
- $single_body .= '<td width="100" 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 = $this->getValue($k1, $key, $sku_value, $sku);
-
- if ($update) {
- if (strstr($v1, '|')) {
- $v1 = str_replace('|', '', $v1);
- $single_body .= '<td width="30">'.$value.'</td>';
- } elseif ($k1 == 'unit') {
- $select = '';
- foreach ($this->unit as $k9 => $v9) {
- if ($value == $v9) {
- $selected = 'selected';
- } else {
- $selected = '';
- }
- $k9 = $v9;
- if ($v9 == '请选择') {
- $k9 = '';
- }
- $select .= '<option value="'.$k9.'" '.$selected.'>'.$v9.'</option>';
- }
- $body .= '<td width="30"><select lay-ignore name="single_'.$k1.'['.$k.']" >'.$select.'</select></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 . '[单选规格]:<table class="layui-table">' . $single_head . $single_body . '</table>';
- }
- if ($input_attr && $sku_value) {
- foreach ($input_attr as $k => $v) {
- $key = array();
- foreach ($v['option'] as $k1 => $v1) {
- $key[] = $v1['price_key'];
- }
- $key = implode('_', $key);
- if (!isset($sku[$key])) {
- unset($input_attr[$k]);
- } elseif (isset($sku[$key]) && !isset($sku_value[$sku[$key]['id']])) {
- unset($input_attr[$k]);
- }
- }
- }
- 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 = $this->getValue($k1, $key, $sku_value, $sku);
- if ($update) {
- if (strstr($v1, '|')) {
- $v1 = str_replace('|', '', $v1);
- $input_body .= '<td width="30">'.$value.'</td>';
- } elseif ($k1 == 'unit') {
- $select = '';
- foreach ($this->unit as $k9 => $v9) {
- if ($value == $v9) {
- $selected = 'selected';
- } else {
- $selected = '';
- }
- $k9 = $v9;
- if ($v9 == '请选择') {
- $k9 = '';
- }
- $select .= '<option value="'.$k9.'" '.$selected.'>'.$v9.'</option>';
- }
- $body .= '<td width="30"><select lay-ignore name="input_'.$k1.'['.$k.']" >'.$select.'</select></td>';
- } else {
- $input_body .= '<td width="30"><input type="text" class="layui-input" name="input_'.$k1.'['.$k.']" value="'.$value.'"/></td>';
- }
-
- } else {
- $input_body .= '<td width="30">'.$value.'</td>';
- }
- }
- if ($update) {
- $input_body .= '<input type="hidden" name="input_key['.$k.']" value="'.$key.'"/><textarea style="display:none;" name="input_attr['.$k.']">'.json_encode($id).'</textarea>';
- }
-
- $input_body .= '</tr>';
- }
- $html = $html . '[计算价]:<table class="layui-table">' . $input_head . $input_body . '</table>';
- }
-
- return $html;
- }
- private function create_table($head, $body)
- {
- $html = '<table class="layui-table">';
- }
- private function getValue($k1, $key, $sku_value, $sku)
- {
- $value = '';
- if ($k1 == 'unit' || $k1 == 'weight' || $k1 == 'cunhuo_code') {
- $value = '';
- } elseif ($k1 == 'min') {
- $value = 1;
- } else {
- $value = 0;
- }
-
- if ($key == -1) {
- /*
- if (isset($sku_value[$sku[$key]['id']]) && isset($sku_value[$sku[$key]['id']][$k1])) {
- $value = $sku_value[$sku[$key]['id']][$k1];
- }
- */
- if (isset($sku_value[-1]) && isset($sku_value[-1][$k1])) {
- $value = $sku_value[-1][$k1];
- } elseif (isset($sku[-1]) && isset($sku[-1][$k1])) {
- $value = $sku[-1][$k1];
- }
- } else {
- 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];
- }
- }
- }
-
- return $value;
- }
- }
|