Set.php 10 KB

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