Set.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. $where['status'] = 1;
  10. if ($type != 'factory_id') {
  11. //$where['price_type'] = '1,2,3';
  12. }
  13. $data = Dever::db('goods/info')->getData($where);
  14. $result = array();
  15. if ($data) {
  16. $i = 0;
  17. foreach ($data as $k => $v) {
  18. $sku = Dever::db('goods/info_sku')->select(array('info_id' => $v['id']));
  19. if ($sku) {
  20. $other_where = array($type => $id, $col => $v['id'], 'sku_id' => -1);
  21. if ($col == 'type_id') {
  22. $other_where['type'] = 1;
  23. }
  24. $give = Dever::input('give');
  25. if ($give) {
  26. $other_where['give'] = $give;
  27. }
  28. $other = Dever::db($table)->find($other_where);
  29. $result[$i]['id'] = $v['id'];
  30. $result[$i]['name'] = $v['name'];
  31. $result[$i]['price'] = $v['price'];
  32. $result[$i]['price_type'] = $v['price_type'];
  33. $result[$i]['select'] = 2;
  34. $result[$i]['del'] = 1;
  35. if ($type == 'factory_id') {
  36. if ($other) {
  37. $result[$i]['p_price'] = $other['p_price'];
  38. $result[$i]['select'] = $other['state'];
  39. } else {
  40. $result[$i]['p_price'] = $v['price'];
  41. }
  42. } else {
  43. if ($type == 'store_id') {
  44. $result[$i]['price'] = $v['f_price'];
  45. }
  46. if ($other) {
  47. if (isset($other['min'])) {
  48. $result[$i]['min'] = $other['min'];
  49. }
  50. if (isset($other['total_num'])) {
  51. $result[$i]['total'] = $other['total_num'] - $other['sell_num'];
  52. } else {
  53. $result[$i]['total'] = $other['num'];
  54. }
  55. $result[$i]['select'] = $other['state'];
  56. } else {
  57. $result[$i]['total'] = 0;
  58. }
  59. }
  60. $result[$i]['children'] = array();
  61. $num = count($sku);
  62. if ($num == 1 && $sku[0]['key'] == -1) {
  63. //$result[$i]['id'] .= '-' . $sku[0]['id'];
  64. $result[$i]['end'] = true;
  65. } else {
  66. foreach ($sku as $k1 => $v1) {
  67. $v1['sku_name'] = '';
  68. if ($v1['attr']) {
  69. $v1['attr'] = Dever::json_decode($v1['attr']);
  70. if ($v1['attr']) {
  71. $v1['attr'] = Dever::load('attr/api')->getInfoByJson($v1['attr']);
  72. $v1['sku_name'] = $v1['attr']['string'];
  73. }
  74. }
  75. $name = $v['name'];
  76. if ($v1['sku_name']) {
  77. $name .= '-' . $v1['sku_name'];
  78. }
  79. $children = array
  80. (
  81. 'id' => $v['id'] . '-' . $v1['id'],
  82. 'name' => $name,
  83. 'price' => $v1['price'] ? $v1['price'] : 0,
  84. 'price_type' => $v['price_type'],
  85. 'del' => 1,
  86. 'end' => true,
  87. );
  88. $other_sku_where = array($type => $id, $col => $v['id'], 'sku_id' => $v1['id']);
  89. if ($col == 'type_id') {
  90. $other_sku_where['type'] = 1;
  91. }
  92. $give = Dever::input('give');
  93. if ($give) {
  94. $other_sku_where['give'] = $give;
  95. }
  96. $other_sku = Dever::db($table)->find($other_sku_where);
  97. $children['select'] = 2;
  98. if ($type == 'factory_id') {
  99. $children['p_price'] = $v1['price'];
  100. if ($other_sku) {
  101. $children['p_price'] = $other_sku['p_price'];
  102. $children['select'] = $other_sku['state'];
  103. }
  104. } else {
  105. if ($type == 'store_id') {
  106. $children['price'] = $v1['f_price'];
  107. }
  108. $children['total'] = 0;
  109. if ($other_sku) {
  110. if (isset($other_sku['min'])) {
  111. $children['min'] = $other_sku['min'];
  112. }
  113. if (isset($other_sku['total_num'])) {
  114. if ($col == 'type_id') {
  115. $children['total'] = $other_sku['total_num'];
  116. } else {
  117. $children['total'] = $other_sku['total_num'] - $other_sku['sell_num'];
  118. }
  119. } else {
  120. $children['total'] = $other_sku['num'];
  121. }
  122. $children['select'] = $other_sku['state'];
  123. }
  124. }
  125. $result[$i]['children'][] = $children;
  126. }
  127. }
  128. $i++;
  129. }
  130. }
  131. }
  132. return $result;
  133. }
  134. }