Set.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. namespace Goods\Lib;
  3. use Dever;
  4. class Set
  5. {
  6. # 获取商品及其属性列表
  7. public function getGoodsList($id, $type, $table, $col = 'goods_id', $sku_state = true)
  8. {
  9. $total = Dever::input('total', 1);
  10. $where['status'] = 1;
  11. if ($type != 'factory_id') {
  12. //$where['price_type'] = '1,2,3';
  13. }
  14. $data = Dever::db('goods/info')->getData($where);
  15. $result = array();
  16. if ($data) {
  17. $i = 0;
  18. foreach ($data as $k => $v) {
  19. $sku = Dever::db('goods/info_sku')->select(array('info_id' => $v['id']));
  20. if ($sku) {
  21. $other_where = array($type => $id, $col => $v['id'], 'sku_id' => -1);
  22. if ($col == 'type_id') {
  23. $other_where['type'] = 1;
  24. }
  25. $give = Dever::input('give');
  26. if ($give) {
  27. $other_where['give'] = $give;
  28. }
  29. $other = Dever::db($table)->find($other_where);
  30. $result[$i]['id'] = $v['id'];
  31. $result[$i]['name'] = $v['name'];
  32. $result[$i]['price'] = $v['price'];
  33. $result[$i]['price_type'] = $v['price_type'];
  34. $result[$i]['select'] = 2;
  35. $result[$i]['del'] = 1;
  36. if ($type == 'factory_id') {
  37. $result[$i]['total'] = 0;
  38. if ($other) {
  39. $result[$i]['p_price'] = $other['p_price'];
  40. $result[$i]['select'] = $other['state'];
  41. } else {
  42. $result[$i]['p_price'] = $v['price'];
  43. }
  44. } else {
  45. if ($type == 'store_id') {
  46. $result[$i]['price'] = $v['f_price'];
  47. }
  48. if ($other) {
  49. if (isset($other['min'])) {
  50. $result[$i]['min'] = $other['min'];
  51. }
  52. if (isset($other['total_num'])) {
  53. /*
  54. if ($col == 'type_id') {
  55. $result[$i]['total'] = $other['total_num'];
  56. } else {
  57. $result[$i]['total'] = $other['total_num'] - $other['sell_num'];
  58. }
  59. */
  60. if (isset($other['sell_num'])) {
  61. $result[$i]['total'] = $other['total_num'] - $other['sell_num'];
  62. } else {
  63. $result[$i]['total'] = $other['total_num'];
  64. }
  65. } else {
  66. $result[$i]['total'] = $other['num'];
  67. }
  68. $result[$i]['select'] = $other['state'];
  69. } else {
  70. $result[$i]['total'] = 0;
  71. }
  72. }
  73. $result[$i]['total'] = $result[$i]['total'] * $total;
  74. $result[$i]['children'] = array();
  75. $num = count($sku);
  76. if (($num == 1 && $sku[0]['key'] == -1) || !$sku_state) {
  77. //$result[$i]['id'] .= '-' . $sku[0]['id'];
  78. $result[$i]['end'] = true;
  79. } else {
  80. foreach ($sku as $k1 => $v1) {
  81. $v1['sku_name'] = '';
  82. if ($v1['attr']) {
  83. $v1['attr'] = Dever::json_decode($v1['attr']);
  84. if ($v1['attr']) {
  85. $v1['attr'] = Dever::load('attr/api')->getInfoByJson($v1['attr']);
  86. $v1['sku_name'] = $v1['attr']['string'];
  87. }
  88. }
  89. $name = $v['name'];
  90. if ($v1['sku_name']) {
  91. $name .= '-' . $v1['sku_name'];
  92. }
  93. $children = array
  94. (
  95. 'id' => $v['id'] . '-' . $v1['id'],
  96. 'name' => $name,
  97. 'price' => $v1['price'] ? $v1['price'] : 0,
  98. 'price_type' => $v['price_type'],
  99. 'del' => 1,
  100. 'end' => true,
  101. );
  102. $other_sku_where = array($type => $id, $col => $v['id'], 'sku_id' => $v1['id']);
  103. if ($col == 'type_id') {
  104. $other_sku_where['type'] = 1;
  105. }
  106. $give = Dever::input('give');
  107. if ($give) {
  108. $other_sku_where['give'] = $give;
  109. }
  110. $other_sku = Dever::db($table)->find($other_sku_where);
  111. $children['select'] = 2;
  112. if ($type == 'factory_id') {
  113. $children['total'] = 0;
  114. $children['p_price'] = $v1['price'];
  115. if ($other_sku) {
  116. $children['p_price'] = $other_sku['p_price'];
  117. $children['select'] = $other_sku['state'];
  118. }
  119. } else {
  120. if ($type == 'store_id') {
  121. $children['price'] = $v1['f_price'];
  122. }
  123. $children['total'] = 0;
  124. if ($other_sku) {
  125. if (isset($other_sku['min'])) {
  126. $children['min'] = $other_sku['min'];
  127. }
  128. if (isset($other_sku['total_num'])) {
  129. /*
  130. if ($col == 'type_id') {
  131. $children['total'] = $other_sku['total_num'];
  132. } else {
  133. $children['total'] = $other_sku['total_num'] - $other_sku['sell_num'];
  134. }
  135. */
  136. if (isset($other_sku['sell_num'])) {
  137. $children['total'] = $other_sku['total_num'] - $other_sku['sell_num'];
  138. } else {
  139. $children['total'] = $other_sku['total_num'];
  140. }
  141. } else {
  142. $children['total'] = $other_sku['num'];
  143. }
  144. $children['select'] = $other_sku['state'];
  145. }
  146. }
  147. $children['total'] = $children['total']*$total;
  148. $result[$i]['children'][] = $children;
  149. }
  150. }
  151. $i++;
  152. }
  153. }
  154. }
  155. return $result;
  156. }
  157. }