Manage.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. namespace factory\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. /**
  7. * 更新信息
  8. *
  9. * @return mixed
  10. */
  11. public function infoUpdate($id, $name, $data)
  12. {
  13. $update = array();
  14. $area = Dever::param('area', $data);
  15. if ($area) {
  16. $temp = is_string($area) ? explode(',', $area) : $area;
  17. $update['province'] = $temp[0];
  18. $update['city'] = $temp[1];
  19. }
  20. $map = Dever::param('map', $data);
  21. if ($map) {
  22. $temp = is_string($map) ? explode(',', $map) : $map;
  23. $update['lng'] = $temp[1];
  24. $update['lat'] = $temp[2];
  25. }
  26. if (isset($update) && $update) {
  27. $update['where_id'] = $id;
  28. Dever::db('factory/info')->update($update);
  29. }
  30. }
  31. /**
  32. * 更新商品信息
  33. *
  34. * @return mixed
  35. */
  36. public function goodsUpdate($id, $name, $data)
  37. {
  38. $update = array();
  39. $goods_id = Dever::param('goods_id', $data);
  40. if ($goods_id) {
  41. $info = Dever::db('goods/info')->find($goods_id);
  42. $update['price_type'] = $info['price_type'];
  43. }
  44. if (isset($update) && $update) {
  45. $update['where_id'] = $id;
  46. Dever::db('factory/goods')->update($update);
  47. }
  48. }
  49. public function skuConfig()
  50. {
  51. $data['action'] = Dever::url('factory/lib/manage.skuUp');
  52. $data['info_id'] = Dever::input('search_option_factory_goods_id');
  53. return $data;
  54. }
  55. public function skuUp_api()
  56. {
  57. $factory_goods_id = Dever::input('info_id');
  58. $key = Dever::input('key');
  59. $c_price = Dever::input('c_price');
  60. $factory_goods = Dever::db('factory/goods')->one($factory_goods_id);
  61. if ($key) {
  62. foreach ($key as $k => $v) {
  63. if (isset($c_price[$k]) && $c_price[$k]) {
  64. $info = Dever::db('goods/info_sku')->one(array('key' => $v));
  65. $data = array();
  66. $data['factory_id'] = $factory_goods['factory_id'];
  67. $data['goods_id'] = $factory_goods['goods_id'];
  68. $data['factory_goods_id'] = $factory_goods_id;
  69. $data['sku_id'] = $info['id'];
  70. $factory_info = Dever::db('factory/goods_sku')->one($data);
  71. $data['c_price'] = $c_price[$k];
  72. if (!$factory_info) {
  73. Dever::db('factory/goods_sku')->insert($data);
  74. } else {
  75. $data['where_id'] = $info['id'];
  76. Dever::db('factory/goods_sku')->update($data);
  77. }
  78. }
  79. }
  80. }
  81. Dever::out('yes');
  82. }
  83. public function skuInput()
  84. {
  85. $id = Dever::input('search_option_factory_goods_id');
  86. $factory_goods = Dever::db('factory/goods')->one($id);
  87. $sku = Dever::db('goods/info_sku')->getData(array('info_id' => $factory_goods['goods_id']));
  88. $sku_num = Dever::db('factory/goods_sku')->getData(array('factory_goods_id' => $id));
  89. $info = Dever::db('goods/info')->one($factory_goods['goods_id']);
  90. $info = \Goods\Lib\Info::init(-1)->info($info, 'list_reorder');
  91. $html = '请先选择属性';
  92. if ($info['sell_attr']) {
  93. $head = '<thead><tr>';
  94. $body = '<tbody>';
  95. $option = array();
  96. foreach ($info['sell_attr'] as $k => $v) {
  97. $head .= '<th>'.$v['name'].'</th>';
  98. if (isset($v['option_sku'])) {
  99. $option[$k] = $v['option_sku'];
  100. }
  101. }
  102. $head .= '<th>出厂价</th>';
  103. $head .= '</tr></thead>';
  104. if ($option) {
  105. $option = Dever::cartesian($option);
  106. foreach ($option as $k => $v) {
  107. $body .= '<tr data-row="' .($k+1). '">';
  108. $key = $id = array();
  109. foreach ($v['name'] as $k1 => $v1) {
  110. $rows = 1;
  111. $body .= '<td width="50" rowspan="'.$rows.'">'.$v1.'</td>';
  112. $id[] = array
  113. (
  114. 'id' => $v['id'][$k1],
  115. 'attr_id' => $v['info_id'][$k1],
  116. );
  117. $key[] = $v['info_id'][$k1] . '-' . $v['id'][$k1];
  118. }
  119. $key = implode('_', $key);
  120. $c_price = '';
  121. if (isset($sku[$key]) && isset($sku_num[$sku[$key]['id']])) {
  122. $c_price = $sku_num[$sku[$key]['id']]['c_price'];
  123. }
  124. $body .= '<td width="30"><input type="text" class="layui-input" name="c_price['.$k.']" value="'.$c_price.'"/></td>';
  125. $body .= '<input type="hidden" name="key['.$k.']" value="'.$key.'"/>';
  126. $body .= '</tr>';
  127. }
  128. }
  129. $body .= '</tbody>';
  130. $html = $head . $body;
  131. }
  132. return $html;
  133. }
  134. }