Set.php 7.9 KB

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