Set.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. if ($table == 'agent/order_goods') {
  30. $where_type = Dever::input('type', 1);
  31. if ($where_type) {
  32. $other_where['type'] = $where_type;
  33. }
  34. }
  35. $other = Dever::db($table)->find($other_where);
  36. $result[$i]['id'] = $v['id'];
  37. $result[$i]['name'] = $v['name'];
  38. $result[$i]['price'] = $v['price'];
  39. $result[$i]['price_type'] = $v['price_type'];
  40. $result[$i]['select'] = 2;
  41. $result[$i]['del'] = 1;
  42. if ($type == 'factory_id') {
  43. $result[$i]['total'] = 0;
  44. if ($other) {
  45. $result[$i]['p_price'] = $other['p_price'];
  46. $result[$i]['select'] = $other['state'];
  47. } else {
  48. $result[$i]['p_price'] = $v['price'];
  49. }
  50. } else {
  51. if ($type == 'store_id') {
  52. $result[$i]['price'] = $v['f_price'];
  53. }
  54. if ($other) {
  55. if (isset($other['min'])) {
  56. $result[$i]['min'] = $other['min'];
  57. }
  58. if (isset($other['total_num'])) {
  59. /*
  60. if ($col == 'type_id') {
  61. $result[$i]['total'] = $other['total_num'];
  62. } else {
  63. $result[$i]['total'] = $other['total_num'] - $other['sell_num'];
  64. }
  65. */
  66. if (isset($other['sell_num'])) {
  67. $result[$i]['total'] = $other['total_num'] - $other['sell_num'];
  68. } else {
  69. $result[$i]['total'] = $other['total_num'];
  70. }
  71. } else {
  72. $result[$i]['total'] = $other['num'];
  73. }
  74. $result[$i]['select'] = $other['state'];
  75. } else {
  76. $result[$i]['total'] = 0;
  77. }
  78. }
  79. $result[$i]['total'] = $result[$i]['total'] * $total;
  80. $result[$i]['children'] = array();
  81. $num = count($sku);
  82. if (($num == 1 && $sku[0]['key'] == -1) || !$sku_state) {
  83. //$result[$i]['id'] .= '-' . $sku[0]['id'];
  84. $result[$i]['end'] = true;
  85. } else {
  86. foreach ($sku as $k1 => $v1) {
  87. $v1['sku_name'] = '';
  88. if ($v1['attr']) {
  89. $v1['attr'] = Dever::json_decode($v1['attr']);
  90. if ($v1['attr']) {
  91. $v1['attr'] = Dever::load('attr/api')->getInfoByJson($v1['attr']);
  92. $v1['sku_name'] = $v1['attr']['string'];
  93. }
  94. }
  95. $name = $v['name'];
  96. if ($v1['sku_name']) {
  97. $name .= '-' . $v1['sku_name'];
  98. }
  99. $children = array
  100. (
  101. 'id' => $v['id'] . '-' . $v1['id'],
  102. 'name' => $name,
  103. 'price' => $v1['price'] ? $v1['price'] : 0,
  104. 'price_type' => $v['price_type'],
  105. 'del' => 1,
  106. 'end' => true,
  107. );
  108. $other_sku_where = array($type => $id, $col => $v['id'], 'sku_id' => $v1['id']);
  109. if ($col == 'type_id') {
  110. $other_sku_where['type'] = 1;
  111. }
  112. $give = Dever::input('give');
  113. if ($give) {
  114. $other_sku_where['give'] = $give;
  115. }
  116. if ($table == 'agent/order_goods') {
  117. $where_type = Dever::input('type', 1);
  118. if ($where_type) {
  119. $other_sku_where['type'] = $where_type;
  120. }
  121. }
  122. $other_sku = Dever::db($table)->find($other_sku_where);
  123. $children['select'] = 2;
  124. if ($type == 'factory_id') {
  125. $children['total'] = 0;
  126. $children['p_price'] = $v1['price'];
  127. if ($other_sku) {
  128. $children['p_price'] = $other_sku['p_price'];
  129. $children['select'] = $other_sku['state'];
  130. }
  131. } else {
  132. if ($type == 'store_id') {
  133. $children['price'] = $v1['f_price'];
  134. }
  135. $children['total'] = 0;
  136. if ($other_sku) {
  137. if (isset($other_sku['min'])) {
  138. $children['min'] = $other_sku['min'];
  139. }
  140. if (isset($other_sku['total_num'])) {
  141. /*
  142. if ($col == 'type_id') {
  143. $children['total'] = $other_sku['total_num'];
  144. } else {
  145. $children['total'] = $other_sku['total_num'] - $other_sku['sell_num'];
  146. }
  147. */
  148. if (isset($other_sku['sell_num'])) {
  149. $children['total'] = $other_sku['total_num'] - $other_sku['sell_num'];
  150. } else {
  151. $children['total'] = $other_sku['total_num'];
  152. }
  153. } else {
  154. $children['total'] = $other_sku['num'];
  155. }
  156. $children['select'] = $other_sku['state'];
  157. }
  158. }
  159. $children['total'] = $children['total']*$total;
  160. $result[$i]['children'][] = $children;
  161. }
  162. }
  163. $i++;
  164. }
  165. }
  166. }
  167. return $result;
  168. }
  169. }