Manage.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. namespace Goods\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. /**
  7. * 更新信息
  8. *
  9. * @return mixed
  10. */
  11. public function infoUpdate($id, $name, $data)
  12. {
  13. # 更新分类id
  14. $category = Dever::param('category', $data);
  15. if ($category) {
  16. if (is_array($category)) {
  17. $category_id = end($category);
  18. $top_category_id = $category[0];
  19. if (isset($category[1])) {
  20. $second_category_id = $category[1];
  21. } else {
  22. $second_category_id = $category[0];
  23. }
  24. } else {
  25. $category_id = $category;
  26. $top_category_id = $category;
  27. $second_category_id = $category;
  28. }
  29. $update['top_category_id'] = $top_category_id;
  30. $update['second_category_id'] = $second_category_id;
  31. $update['category_id'] = $category_id;
  32. }
  33. $pic = Dever::param('pic', $data);
  34. $pic_cover = Dever::param('pic_cover', $data);
  35. if ($pic && !$pic_cover) {
  36. if (is_string($pic)) {
  37. $pic = explode(',', $pic);
  38. }
  39. $update['pic_cover'] = $pic[0];
  40. }
  41. if (isset($update)) {
  42. $update['where_id'] = $id;
  43. Dever::db('goods/info')->update($update);
  44. }
  45. }
  46. /**
  47. * 更新需求属性信息
  48. *
  49. * @return mixed
  50. */
  51. public function attrUpdate($id, $name, $data)
  52. {
  53. print_r($data);die;
  54. foreach ($data as $k => $v) {
  55. }
  56. }
  57. /**
  58. * 显示信息
  59. *
  60. * @return mixed
  61. */
  62. public function info($id)
  63. {
  64. $info = Dever::db('goods/info')->one($id);
  65. if ($info) {
  66. $table['编号'] = $info['id'];
  67. $table['标题'] = $info['name'];
  68. $table['分类'] = Dever::load("category/api.string", $info['category']);
  69. if ($info['pic_cover']) {
  70. $table['封面图'] = '<img src="'.$info['pic_cover'].'" width="150" />';
  71. }
  72. if ($info['shop_id'] > 0) {
  73. $shop = Dever::load('goods/shop-one', $info['shop_id']);
  74. $table['所属店铺'] = $shop['name'];
  75. }
  76. if ($info['brand_id'] > 0) {
  77. $brand = Dever::load('goods/brand-one', $info['brand_id']);
  78. $table['所属品牌'] = $brand['name'];
  79. }
  80. //$table['属性'] = $this->attrInfo($info);
  81. if ($info['cdate']) {
  82. $table['发布时间'] = date("Y-m-d H:i:s", $info['cdate']);
  83. }
  84. }
  85. return Dever::table($table);
  86. }
  87. private function attrInfo($info)
  88. {
  89. $table = array();
  90. $info = Info::init($info['top_category_id']);
  91. if ($info) {
  92. $info = $info->info($info, 'id');
  93. if ($info && isset($info['attr'])) {
  94. foreach ($info['attr'] as $k => $v) {
  95. $table[$v['name']] = $v['value_string'];
  96. }
  97. }
  98. }
  99. return Dever::table($table);
  100. }
  101. public function area($id, $name, $data)
  102. {
  103. # 不再执行syncone等后续操作
  104. Dever::config('base')->after = 1;
  105. $type = Dever::input('type');
  106. $area = Dever::param('area', $data);
  107. if ($area) {
  108. if (isset($area[2])) {
  109. $update['district_id'] = $area[2];
  110. }
  111. if (isset($area[1])) {
  112. $update['city_id'] = $area[1];
  113. }
  114. if (isset($area[0])) {
  115. $update['province_id'] = $area[0];
  116. }
  117. if (isset($update)) {
  118. $update['where_id'] = $id;
  119. Dever::db($type . '/info')->update($update);
  120. }
  121. }
  122. }
  123. public function skuInput()
  124. {
  125. $id = Dever::input('search_option_info_id');
  126. $info = Dever::db('goods/info')->one($id);
  127. $info = Info::init(-1)->info($info, 'list_reorder');
  128. if ($info['attr']) {
  129. $head = '<thead><tr>';
  130. $body = '<tbody>';
  131. foreach ($info['attr'] as $k => $v) {
  132. $head .= '<th>'.$v['name'].'</th>';
  133. }
  134. $head .= '<th>原价</th>';
  135. $head .= '<th>现价</th>';
  136. $head .= '<th>库存</th>';
  137. $head .= '</tr></thead>';
  138. }
  139. $data = array(
  140. array('白色','银色','玫瑰金'),
  141. array('64G','128G'),
  142. array('移动','电信','联通'),
  143. array('国行','港版')
  144. );
  145. //打印结果
  146. $result = $this->Cartesian($info['attr']);
  147. print_r($result);die;
  148. // print_r($option);die;
  149. $html = $head . $body;
  150. return $html;
  151. }
  152. function Cartesian($data){
  153. $len = count($data);
  154. // 取第一个集合数组值
  155. $result = $data[0]['option'];
  156. for ($i = 0; $i< $len-1; $i++) {
  157. $arr1 = $result;
  158. $result = [];
  159. // 数组第一个值和第二个值组合
  160. foreach ($arr1 as $res) {
  161. //数组第二个值...$i+1
  162. foreach($data[$i+1] as $k => $v){
  163. if(!is_array($res)) {
  164. $res = array($res);
  165. }
  166. if(!is_array($v)){
  167. $sec = array($v['option']);
  168. }
  169. $result[] = array_merge_recursive($res,$sec);
  170. }
  171. }
  172. }
  173. return $result;
  174. }
  175. }