Set.php 9.2 KB

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