Sku.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. <?php
  2. namespace Goods\Lib;
  3. use Dever;
  4. class Sku
  5. {
  6. # 设置sku特殊字段
  7. private $col = array
  8. (
  9. 'code' => '商品条码号',
  10. 's_price' => '市场价',
  11. 'f_price' => '采购价',
  12. 'price' => '销售价',
  13. 'min' => '起购数',
  14. );
  15. # 主要价格字段
  16. private $main = 'price';
  17. public function __construct()
  18. {
  19. # 设置权限
  20. Dever::load('manage/auth.init');
  21. }
  22. public function config()
  23. {
  24. $data['action'] = Dever::url('goods/lib/sku.update');
  25. $data['goods_id'] = Dever::input('goods_id');
  26. $data['other'] = Dever::input('other');
  27. $data['other_id'] = Dever::input('other_id');
  28. if ($data['other']) {
  29. $data['other_col'] = $data['other'] . '_id';
  30. }
  31. $data['attr'] = Dever::input('attr');
  32. $data['key'] = Dever::input('key');
  33. $data['single_attr'] = Dever::input('single_attr');
  34. $data['single_key'] = Dever::input('single_key');
  35. $data['input_attr'] = Dever::input('input_attr');
  36. $data['input_key'] = Dever::input('input_key');
  37. $data['hook'] = Dever::input('hook');
  38. $data['set'] = $this->getSet($data['other']);
  39. return $data;
  40. }
  41. private function getSet($other)
  42. {
  43. if ($other) {
  44. if (Dever::project($other)) {
  45. $set = Dever::load($other . '/lib/sku')->set;
  46. if (!isset($set['price_type'])) {
  47. $set['price_type'] = false;
  48. }
  49. } else {
  50. Dever::alert($other . '不存在');
  51. }
  52. } else {
  53. $set = array('col' => $this->col, 'price_type' => false);
  54. }
  55. return $set;
  56. }
  57. public function show()
  58. {
  59. $config = Dever::load('goods/lib/sku')->config();
  60. return $this->table($config['goods_id'], $config['other'], $config['other_id'], $config['set'], true);
  61. }
  62. public function update_api()
  63. {
  64. $config = Dever::load('goods/lib/sku')->config();
  65. $where = array();
  66. if ($config['other']) {
  67. $where[$config['other_col']] = $config['other_id'];
  68. $where['goods_id'] = $config['goods_id'];
  69. $key = 'sku_id';
  70. $table = $config['other'] . '/goods';
  71. } else {
  72. $where['info_id'] = $config['goods_id'];
  73. $key = 'key';
  74. $table = 'goods/info';
  75. $w['option_info_id'] = $config['goods_id'];
  76. $w['set_state'] = 2;
  77. Dever::db('goods/info_sku')->updates($w);
  78. }
  79. $sku_table = $table . '_sku';
  80. $code = array();
  81. if ($config['key'] == -1) {
  82. if ($config['other']) {
  83. $info = Dever::db($table)->one($where);
  84. } else {
  85. $info = Dever::db($table)->one($config['goods_id']);
  86. }
  87. $update = $where;
  88. foreach ($config['set']['col'] as $k => $v) {
  89. $update[$k] = Dever::input($k);
  90. if ($k == 'code') {
  91. if (!$update[$k]) {
  92. Dever::alert('商品条码号不能为空');
  93. }
  94. if (in_array($update[$k], $code)) {
  95. Dever::alert('商品条码号已重复');
  96. }
  97. $code[] = $update[$k];
  98. }
  99. }
  100. if ($info && $update) {
  101. $update['where_id'] = $info['id'];
  102. Dever::db($table)->update($update);
  103. unset($update['where_id']);
  104. }
  105. $where[$key] = -1;
  106. /*
  107. if ($config['other']) {
  108. $info_sku = Dever::db('goods/info_sku')->one(array('goods_id' => $config['goods_id'], 'key' => -1));
  109. $where[$key] = $info_sku['id'];
  110. }
  111. */
  112. $info = Dever::db($sku_table)->one($where);
  113. $update[$key] = $where[$key];
  114. Dever::config('base')->hook = false;
  115. if (!$info) {
  116. $state = Dever::db($sku_table)->insert($update);
  117. } else {
  118. $update['where_id'] = $info['id'];
  119. $update['state'] = 1;
  120. $state = Dever::db($sku_table)->update($update);
  121. }
  122. } elseif ($config['key']) {
  123. if (!is_array($config['key'])) {
  124. $config['key'] = explode(',', $config['key']);
  125. }
  126. $min = array();
  127. $cur_sku = false;
  128. $sku_id = false;
  129. foreach ($config['key'] as $k => $v) {
  130. $type = 1;
  131. if (strstr($v, '||')) {
  132. $temp = explode('||', $v);
  133. $v = $temp[0];
  134. $type = $temp[1];
  135. }
  136. if (isset($config['attr'][$k])) {
  137. $data = $where;
  138. if ($config['other']) {
  139. $sku = Dever::db('goods/info_sku')->one(array('key' => $v, 'info_id' => $config['goods_id']));
  140. if (!$sku) {
  141. continue;
  142. }
  143. $data[$key] = $sku['id'];
  144. $info = Dever::db($sku_table)->one($data);
  145. } else {
  146. $info = Dever::db('goods/info_sku')->one(array('key' => $v, 'info_id' => $config['goods_id']));
  147. $data['attr'] = $config['attr'][$k];
  148. $data[$key] = $v;
  149. }
  150. $data['type'] = $type;
  151. foreach ($config['set']['col'] as $k1 => $v1) {
  152. $value = Dever::input($k1);
  153. $cur_sku = false;
  154. if (isset($value[$k])) {
  155. $data[$k1] = $value[$k];
  156. if ($k1 == 'code') {
  157. if (!$data[$k1]) {
  158. Dever::alert('商品条码号不能为空');
  159. }
  160. if (in_array($data[$k1], $code)) {
  161. Dever::alert('商品条码号已重复');
  162. }
  163. $code[] = $data[$k1];
  164. }
  165. if ($k1 == $this->main) {
  166. if (!isset($min[$k1])) {
  167. $min = $data;
  168. $cur_sku = true;
  169. } elseif ($min[$k1] > $data[$k1]) {
  170. $min = $data;
  171. $cur_sku = true;
  172. }
  173. }
  174. }
  175. }
  176. Dever::config('base')->hook = false;
  177. if (!$info) {
  178. $temp = Dever::db($sku_table)->insert($data);
  179. if ($cur_sku) {
  180. $sku_id = $temp;
  181. }
  182. } else {
  183. $data['where_id'] = $info['id'];
  184. if ($cur_sku) {
  185. $sku_id = $data['where_id'];
  186. }
  187. $data['state'] = 1;
  188. Dever::db($sku_table)->update($data);
  189. }
  190. }
  191. }
  192. if (!$config['other'] && $min) {
  193. $update = array();
  194. if ($sku_id) {
  195. $update['sku_id'] = $sku_id;
  196. }
  197. foreach ($config['set']['col'] as $k => $v) {
  198. if (isset($min[$k])) {
  199. $update[$k] = $min[$k];
  200. }
  201. }
  202. $update['where_id'] = $config['goods_id'];
  203. Dever::db($table)->update($update);
  204. }
  205. }
  206. if ($config['single_key']) {
  207. if (!is_array($config['single_key'])) {
  208. $config['single_key'] = explode(',', $config['single_key']);
  209. }
  210. foreach ($config['single_key'] as $k => $v) {
  211. $type = 2;
  212. if (strstr($v, '||')) {
  213. $temp = explode('||', $v);
  214. $v = $temp[0];
  215. $type = $temp[1];
  216. }
  217. if (isset($config['single_attr'][$k])) {
  218. $data = $where;
  219. if ($config['other']) {
  220. $sku = Dever::db('goods/info_sku')->one(array('key' => $v, 'info_id' => $config['goods_id']));
  221. if (!$sku) {
  222. continue;
  223. }
  224. $data[$key] = $sku['id'];
  225. $info = Dever::db($sku_table)->one($data);
  226. } else {
  227. $info = Dever::db('goods/info_sku')->one(array('key' => $v, 'info_id' => $config['goods_id']));
  228. $data['attr'] = $config['single_attr'][$k];
  229. $data[$key] = $v;
  230. }
  231. $data['type'] = $type;
  232. foreach ($config['set']['col'] as $k1 => $v1) {
  233. $value = Dever::input('single_' . $k1);
  234. if (isset($value[$k])) {
  235. $data[$k1] = $value[$k];
  236. }
  237. }
  238. Dever::config('base')->hook = false;
  239. if (!$info) {
  240. $temp = Dever::db($sku_table)->insert($data);
  241. } else {
  242. $data['where_id'] = $info['id'];
  243. $data['state'] = 1;
  244. Dever::db($sku_table)->update($data);
  245. }
  246. }
  247. }
  248. }
  249. if ($config['input_key']) {
  250. if (!is_array($config['input_key'])) {
  251. $config['input_key'] = explode(',', $config['input_key']);
  252. }
  253. foreach ($config['input_key'] as $k => $v) {
  254. $type = 3;
  255. if (strstr($v, '||')) {
  256. $temp = explode('||', $v);
  257. $v = $temp[0];
  258. $type = $temp[1];
  259. }
  260. if (isset($config['input_attr'][$k])) {
  261. $data = $where;
  262. if ($config['other']) {
  263. $sku = Dever::db('goods/info_sku')->one(array('key' => $v, 'info_id' => $config['goods_id']));
  264. if (!$sku) {
  265. continue;
  266. }
  267. $data[$key] = $sku['id'];
  268. $info = Dever::db($sku_table)->one($data);
  269. } else {
  270. $info = Dever::db('goods/info_sku')->one(array('key' => $v, 'info_id' => $config['goods_id']));
  271. $data['attr'] = $config['input_attr'][$k];
  272. $data[$key] = $v;
  273. }
  274. $data['type'] = $type;
  275. foreach ($config['set']['col'] as $k1 => $v1) {
  276. $value = Dever::input('input_' . $k1);
  277. if (isset($value[$k])) {
  278. $data[$k1] = $value[$k];
  279. }
  280. }
  281. Dever::config('base')->hook = false;
  282. if (!$info) {
  283. $temp = Dever::db($sku_table)->insert($data);
  284. } else {
  285. $data['where_id'] = $info['id'];
  286. $data['state'] = 1;
  287. Dever::db($sku_table)->update($data);
  288. }
  289. }
  290. }
  291. }
  292. Dever::config('base')->hook = true;
  293. Dever::out('yes');
  294. }
  295. public function table($goods, $other = false, $other_id = false, $set = false, $update = true, $parent_goods = false)
  296. {
  297. if (!$set) {
  298. $set = $this->getSet($other);
  299. }
  300. $info = is_array($goods) ? $goods : Dever::db('goods/info')->one($goods);
  301. $info = Info::init(-1)->info($info, 'view_reorder');
  302. if ($info && $other && isset($set['price_type']) && $set['price_type']) {
  303. $price_type = explode(',', $set['price_type']);
  304. if (in_array($info['price_type'], $price_type)) {
  305. if ($update) {
  306. return '组合商品无法设置库存';
  307. }
  308. if ($info['goods'] && is_array($info['goods'])) {
  309. $html = '';
  310. foreach ($info['goods'] as $k => $v) {
  311. $html .= $this->table($v['id'], $other, $other_id, $set, $update, $v) . '<br />';
  312. }
  313. $html .= '*组合商品的库存为以上商品中的最低库存为准';
  314. return $html;
  315. } else {
  316. return '';
  317. }
  318. }
  319. }
  320. $input = '';
  321. $sku_value = array();
  322. if ($other) {
  323. $other_col = $other . '_id';
  324. $sku_value = Dever::db($other . '/goods_sku')->getData(array('goods_id' => $info['id'], $other_col => $other_id, 'state_1' => 1));
  325. $input = '<input type="hidden" name="goods_id" value="'.$info['id'].'"/><input type="hidden" name="'.$other_col.'" value="'.$other_id.'"/>';
  326. }
  327. $sku = Dever::db('goods/info_sku')->getDataByKeys(array('info_id' => $info['id']));
  328. $group_attr = $single_attr = $input_attr = array();
  329. $head = $single_head = $input_head = '<thead><tr>';
  330. $html = '请先选择属性';
  331. if ($parent_goods) {
  332. $head .= '<th>商品名称</th>';
  333. $single_head .= '<th>商品名称</th>';
  334. $input_head .= '<th>商品名称</th>';
  335. }
  336. if (isset($info['group_attr']) && $info['group_attr']) {
  337. foreach ($info['group_attr'] as $k => $v) {
  338. if (isset($info['attr'][$v]['option'])) {
  339. $group_attr[$k] = $info['attr'][$v]['option'];
  340. $head .= '<th>'.$info['attr'][$v]['name'].'</th>';
  341. }
  342. }
  343. }
  344. if (isset($info['single_attr']) && $info['single_attr']) {
  345. $single_head .= '<th>属性名称</th>';
  346. foreach ($info['single_attr'] as $k => $v) {
  347. if (isset($info['attr'][$v]['option'])) {
  348. $single_attr = array_merge($single_attr, $info['attr'][$v]['option']);
  349. }
  350. }
  351. }
  352. if (isset($info['input_attr']) && $info['input_attr']) {
  353. $input_head .= '<th>属性名称</th>';
  354. $input_head .= '<th>起算</th>';
  355. foreach ($info['input_attr'] as $k => $v) {
  356. if (isset($info['attr'][$v]['option'])) {
  357. $input_attr[$k] = $info['attr'][$v];
  358. }
  359. }
  360. }
  361. $col_num = 0;
  362. foreach ($set['col'] as $k => $v) {
  363. if (!$update && strstr($v, '^')) {
  364. continue;
  365. }
  366. $col_num++;
  367. if (strstr($v, '^')) {
  368. $v = str_replace('^', '', $v);
  369. }
  370. if (strstr($v, '|')) {
  371. $v = str_replace('|', '', $v);
  372. }
  373. $head .= '<th>'.$v.'</th>';
  374. $single_head .= '<th>'.$v.'</th>';
  375. $input_head .= '<th>'.$v.'</th>';
  376. }
  377. $head .= '</tr></thead>';
  378. $single_head .= '</tr></thead>';
  379. $input_head .= '</tr></thead>';
  380. $body = '<tbody>';
  381. $single_body = '<tbody>';
  382. $input_body = '<tbody>';
  383. if (!$group_attr) {
  384. $prefix = '[总价]:';
  385. if (!$update && $col_num <= 1) {
  386. $head = '';
  387. }
  388. if ($update) {
  389. $input .= '<input type="hidden" name="key" value="-1"/>';
  390. }
  391. $body .= '<tr>';
  392. if ($parent_goods) {
  393. $body .= '<td width="10">'.$parent_goods['name'].'</td>';
  394. }
  395. foreach ($set['col'] as $k1 => $v1) {
  396. if (!$update && strstr($v1, '^')) {
  397. continue;
  398. }
  399. $value = $this->getValue($k1, -1, $sku_value, $sku);
  400. if ($update) {
  401. if (strstr($v1, '|')) {
  402. $v1 = str_replace('|', '', $v1);
  403. $body .= '<td width="30">'.$value.'</td>';
  404. } else {
  405. $body .= '<td width="30"><input type="text" class="layui-input" name="'.$k1.'" value="'.$value.'"/></td>';
  406. }
  407. } elseif ($col_num > 1) {
  408. $body .= '<td width="30">'.$value.'</td>';
  409. } else {
  410. $body .= $value;
  411. }
  412. }
  413. $body .= '</tr>';
  414. } else {
  415. $prefix = '[组合价格]:';
  416. $group_attr = Dever::cartesian($group_attr);
  417. if ($sku_value) {
  418. foreach ($group_attr as $k => $v) {
  419. $key = array();
  420. foreach ($v['name'] as $k1 => $v1) {
  421. $key[] = $v['info_id'][$k1] . '-' . $v['id'][$k1];
  422. }
  423. $key = implode('_', $key);
  424. if (!isset($sku[$key])) {
  425. unset($group_attr[$k]);
  426. } elseif (isset($sku[$key]) && !isset($sku_value[$sku[$key]['id']])) {
  427. unset($group_attr[$k]);
  428. }
  429. }
  430. }
  431. $show = false;
  432. if ($group_attr) {
  433. foreach ($group_attr as $k => $v) {
  434. $body .= '<tr data-row="' .($k+1). '">';
  435. if ($parent_goods) {
  436. $body .= '<td>'.$parent_goods['name'].'</td>';
  437. }
  438. $key = $id = array();
  439. foreach ($v['name'] as $k1 => $v1) {
  440. $rows = 1;
  441. $body .= '<td width="50" rowspan="'.$rows.'">'.$v1.'</td>';
  442. $id[] = array
  443. (
  444. 'id' => $v['id'][$k1],
  445. 'attr_id' => $v['info_id'][$k1],
  446. );
  447. $key[] = $v['info_id'][$k1] . '-' . $v['id'][$k1];
  448. }
  449. $key = implode('_', $key);
  450. foreach ($set['col'] as $k1 => $v1) {
  451. if (!$update && strstr($v1, '^')) {
  452. continue;
  453. }
  454. $value = $this->getValue($k1, $key, $sku_value, $sku);
  455. if ($update) {
  456. if (strstr($v1, '|')) {
  457. $v1 = str_replace('|', '', $v1);
  458. $body .= '<td width="30">'.$value.'</td>';
  459. } else {
  460. $body .= '<td width="30"><input type="text" class="layui-input" name="'.$k1.'['.$k.']" value="'.$value.'"/></td>';
  461. }
  462. } else {
  463. $body .= '<td width="30">'.$value.'</td>';
  464. }
  465. }
  466. if ($update) {
  467. $body .= '<input type="hidden" name="key['.$k.']" value="'.$key.'"/><textarea style="display:none;" name="attr['.$k.']">'.json_encode($id).'</textarea>';
  468. }
  469. $body .= '</tr>';
  470. }
  471. } else {
  472. $prefix = $head = $body = '';
  473. }
  474. }
  475. $body .= $input;
  476. $html = $prefix . $head . $body;
  477. if ($update) {
  478. $html = '<table class="layui-table">' . $html . '</table>';
  479. } else {
  480. $html = '<table class="layui-table">' . $html . '</table>';
  481. }
  482. if ($single_attr && $sku_value) {
  483. foreach ($single_attr as $k => $v) {
  484. $key = $v['info_id'] . '-' . $v['id'];
  485. if (!isset($sku[$key])) {
  486. unset($single_attr[$k]);
  487. } elseif (isset($sku[$key]) && !isset($sku_value[$sku[$key]['id']])) {
  488. unset($single_attr[$k]);
  489. }
  490. }
  491. }
  492. if ($single_attr) {
  493. $html = $html;
  494. foreach ($single_attr as $k => $v) {
  495. $id = array();
  496. $single_body .= '<tr data-row="' .($k+1). '">';
  497. if ($parent_goods) {
  498. $single_body .= '<td>'.$parent_goods['name'].'</td>';
  499. }
  500. $rows = 1;
  501. $single_body .= '<td width="100" rowspan="'.$rows.'">'. $v['parent_name'].'->'. $v['name'].'</td>';
  502. $id[] = array
  503. (
  504. 'id' => $v['id'],
  505. 'attr_id' => $v['info_id'],
  506. );
  507. $key = $v['info_id'] . '-' . $v['id'];
  508. foreach ($set['col'] as $k1 => $v1) {
  509. if (!$update && strstr($v1, '^')) {
  510. continue;
  511. }
  512. $value = $this->getValue($k1, $key, $sku_value, $sku);
  513. if ($update) {
  514. if (strstr($v1, '|')) {
  515. $v1 = str_replace('|', '', $v1);
  516. $single_body .= '<td width="30">'.$value.'</td>';
  517. } else {
  518. $single_body .= '<td width="30"><input type="text" class="layui-input" name="single_'.$k1.'['.$k.']" value="'.$value.'"/></td>';
  519. }
  520. } else {
  521. $single_body .= '<td width="30">'.$value.'</td>';
  522. }
  523. }
  524. if ($update) {
  525. $single_body .= '<input type="hidden" name="single_key['.$k.']" value="'.$key.'"/><textarea style="display:none;" name="single_attr['.$k.']">'.json_encode($id).'</textarea>';
  526. }
  527. $single_body .= '</tr>';
  528. }
  529. $html = $html . '[单选价格]:<table class="layui-table">' . $single_head . $single_body . '</table>';
  530. }
  531. if ($input_attr && $sku_value) {
  532. foreach ($input_attr as $k => $v) {
  533. $key = array();
  534. foreach ($v['option'] as $k1 => $v1) {
  535. $key[] = $v1['price_key'];
  536. }
  537. $key = implode('_', $key);
  538. if (!isset($sku[$key])) {
  539. unset($input_attr[$k]);
  540. } elseif (isset($sku[$key]) && !isset($sku_value[$sku[$key]['id']])) {
  541. unset($input_attr[$k]);
  542. }
  543. }
  544. }
  545. if ($input_attr) {
  546. foreach ($input_attr as $k => $v) {
  547. if ($v['sell_compute'] == 2) {
  548. $v['sell_compute_type'] = '+';
  549. } elseif ($v['sell_compute'] == 3) {
  550. $v['sell_compute_type'] = '-';
  551. } else {
  552. $v['sell_compute_type'] = '*';
  553. }
  554. $id = array();
  555. $input_body .= '<tr data-row="' .($k+1). '">';
  556. if ($parent_goods) {
  557. $input_body .= '<td>'.$parent_goods['name'].'</td>';
  558. }
  559. $rows = 1;
  560. $key = $id = $name = array();
  561. foreach ($v['option'] as $k1 => $v1) {
  562. $id[] = array
  563. (
  564. 'id' => $v1['id'],
  565. 'attr_id' => $v1['info_id'],
  566. );
  567. $key[] = $v1['price_key'];
  568. $name[] = $v1['name'];
  569. }
  570. $key = implode('_', $key);
  571. $input_body .= '<td width="100" rowspan="'.$rows.'">'. $v['name'].'->'. implode($v['sell_compute_type'], $name).'</td>';
  572. $input_body .= '<td width="5"> >='.$v['sell_value'].'</td>';
  573. foreach ($set['col'] as $k1 => $v1) {
  574. if (!$update && strstr($v1, '^')) {
  575. continue;
  576. }
  577. $value = $this->getValue($k1, $key, $sku_value, $sku);
  578. if ($update) {
  579. if (strstr($v1, '|')) {
  580. $v1 = str_replace('|', '', $v1);
  581. $input_body .= '<td width="30">'.$value.'</td>';
  582. } else {
  583. $input_body .= '<td width="30"><input type="text" class="layui-input" name="input_'.$k1.'['.$k.']" value="'.$value.'"/></td>';
  584. }
  585. } else {
  586. $input_body .= '<td width="30">'.$value.'</td>';
  587. }
  588. }
  589. if ($update) {
  590. $input_body .= '<input type="hidden" name="input_key['.$k.']" value="'.$key.'"/><textarea style="display:none;" name="input_attr['.$k.']">'.json_encode($id).'</textarea>';
  591. }
  592. $input_body .= '</tr>';
  593. }
  594. $html = $html . '[计算价]:<table class="layui-table">' . $input_head . $input_body . '</table>';
  595. }
  596. return $html;
  597. }
  598. private function create_table($head, $body)
  599. {
  600. $html = '<table class="layui-table">';
  601. }
  602. private function getValue($k1, $key, $sku_value, $sku)
  603. {
  604. $value = '';
  605. if ($k1 == 'min') {
  606. $value = 1;
  607. } else {
  608. $value = 0;
  609. }
  610. if ($key == -1) {
  611. /*
  612. if (isset($sku_value[$sku[$key]['id']]) && isset($sku_value[$sku[$key]['id']][$k1])) {
  613. $value = $sku_value[$sku[$key]['id']][$k1];
  614. }
  615. */
  616. if (isset($sku_value[-1]) && isset($sku_value[-1][$k1])) {
  617. $value = $sku_value[-1][$k1];
  618. } elseif (isset($sku[-1]) && isset($sku[-1][$k1])) {
  619. $value = $sku[-1][$k1];
  620. }
  621. } else {
  622. if (isset($sku[$key])) {
  623. if (isset($sku_value[$sku[$key]['id']][$k1])) {
  624. $value = $sku_value[$sku[$key]['id']][$k1];
  625. } elseif (isset($sku[$key][$k1])) {
  626. $value = $sku[$key][$k1];
  627. }
  628. }
  629. }
  630. return $value;
  631. }
  632. }