Set.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace Goods\Lib;
  3. use Dever;
  4. class Set
  5. {
  6. # 获取商品及其属性列表
  7. public function getGoodsList($id, $type, $table)
  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, 'goods_id' => $v['id'], 'sku_id' => -1);
  21. $give = Dever::input('give');
  22. if ($give) {
  23. $other_where['give'] = $give;
  24. }
  25. $other = Dever::db($table)->find($other_where);
  26. $result[$i]['id'] = $v['id'];
  27. $result[$i]['name'] = $v['name'];
  28. $result[$i]['price'] = $v['price'];
  29. $result[$i]['price_type'] = $v['price_type'];
  30. $result[$i]['select'] = 2;
  31. $result[$i]['del'] = 1;
  32. if ($type == 'factory_id') {
  33. if ($other) {
  34. $result[$i]['p_price'] = $other['p_price'];
  35. $result[$i]['select'] = $other['state'];
  36. } else {
  37. $result[$i]['p_price'] = $v['price'];
  38. }
  39. } else {
  40. if ($type == 'store_id') {
  41. $result[$i]['price'] = $v['f_price'];
  42. }
  43. if ($other) {
  44. if (isset($other['min'])) {
  45. $result[$i]['min'] = $other['min'];
  46. }
  47. if (isset($other['total_num'])) {
  48. $result[$i]['total'] = $other['total_num'] - $other['sell_num'];
  49. } else {
  50. $result[$i]['total'] = $other['num'];
  51. }
  52. $result[$i]['select'] = $other['state'];
  53. } else {
  54. $result[$i]['total'] = 0;
  55. }
  56. }
  57. $result[$i]['children'] = array();
  58. $num = count($sku);
  59. if ($num == 1 && $sku[0]['key'] == -1) {
  60. //$result[$i]['id'] .= '-' . $sku[0]['id'];
  61. $result[$i]['end'] = true;
  62. } else {
  63. foreach ($sku as $k1 => $v1) {
  64. $v1['sku_name'] = '';
  65. if ($v1['attr']) {
  66. $v1['attr'] = Dever::json_decode($v1['attr']);
  67. if ($v1['attr']) {
  68. $v1['attr'] = Dever::load('attr/api')->getInfoByJson($v1['attr']);
  69. $v1['sku_name'] = $v1['attr']['string'];
  70. }
  71. }
  72. $name = $v['name'];
  73. if ($v1['sku_name']) {
  74. $name .= '-' . $v1['sku_name'];
  75. }
  76. $children = array
  77. (
  78. 'id' => $v['id'] . '-' . $v1['id'],
  79. 'name' => $name,
  80. 'price' => $v1['price'] ? $v1['price'] : 0,
  81. 'price_type' => $v['price_type'],
  82. 'del' => 1,
  83. 'end' => true,
  84. );
  85. $other_sku_where = array($type => $id, 'goods_id' => $v['id'], 'sku_id' => $v1['id']);
  86. $give = Dever::input('give');
  87. if ($give) {
  88. $other_sku_where['give'] = $give;
  89. }
  90. $other_sku = Dever::db($table)->find($other_sku_where);
  91. $children['select'] = 2;
  92. if ($type == 'factory_id') {
  93. $children['p_price'] = $v1['price'];
  94. if ($other_sku) {
  95. $children['p_price'] = $other_sku['p_price'];
  96. $children['select'] = $other_sku['state'];
  97. }
  98. } else {
  99. if ($type == 'store_id') {
  100. $children['price'] = $v1['f_price'];
  101. }
  102. $children['total'] = 0;
  103. if ($other_sku) {
  104. if (isset($other_sku['min'])) {
  105. $children['min'] = $other_sku['min'];
  106. }
  107. if (isset($other_sku['total_num'])) {
  108. $children['total'] = $other_sku['total_num'] - $other_sku['sell_num'];
  109. } else {
  110. $children['total'] = $other_sku['num'];
  111. }
  112. $children['select'] = $other_sku['state'];
  113. }
  114. }
  115. $result[$i]['children'][] = $children;
  116. }
  117. }
  118. $i++;
  119. }
  120. }
  121. }
  122. return $result;
  123. }
  124. }