Info.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. namespace Product\Lib;
  3. use Dever;
  4. class Info
  5. {
  6. # 获取商品列表
  7. public function getList()
  8. {
  9. }
  10. # 获取商品详情
  11. public function getInfo($id)
  12. {
  13. $info = Dever::db('product/info')->find($id);
  14. $info = $this->get($info);
  15. return $info;
  16. }
  17. private function get($info)
  18. {
  19. # 获取属性
  20. # 获取规格
  21. # 获取其他
  22. }
  23. # 获取商品及其属性列表
  24. public function getSetList($table, $other_where, $cate_id = false, $col = 'goods_id')
  25. {
  26. $total = Dever::input('total', 1);
  27. if ($cate_id) {
  28. $where['top_category_id'] = $cate_id;
  29. }
  30. $where['status'] = 1;
  31. $data = Dever::db('product/info')->getData($where);
  32. $result = array();
  33. if ($data) {
  34. $i = 0;
  35. foreach ($data as $k => $v) {
  36. $sku = Dever::db('product/info_sku')->select(array('info_id' => $v['id']));
  37. if ($sku) {
  38. $other_where[$col] = $v['id'];
  39. $other_where['sku_id'] = -1;
  40. $other = Dever::db($table)->find($other_where);
  41. $result[$i]['id'] = $v['id'];
  42. $result[$i]['name'] = $v['name'];
  43. $result[$i]['type'] = $v['type'];
  44. $result[$i]['stock'] = $v['stock'];
  45. $result[$i]['commission'] = $v['commission'];
  46. $result[$i]['price'] = 0;
  47. $result[$i]['select'] = 2;
  48. $result[$i]['del'] = 1;
  49. if ($other) {
  50. if (isset($other['commission'])) {
  51. $result[$i]['commission'] = $other['commission'];
  52. }
  53. if (isset($other['price'])) {
  54. $result[$i]['price'] = $other['price'];
  55. }
  56. if (isset($other['min'])) {
  57. $result[$i]['min'] = $other['min'];
  58. }
  59. if (isset($other['total_num'])) {
  60. if (isset($other['sell_num'])) {
  61. $result[$i]['total'] = $other['total_num'] - $other['sell_num'];
  62. } else {
  63. $result[$i]['total'] = $other['total_num'];
  64. }
  65. } else {
  66. $result[$i]['total'] = $other['num'];
  67. }
  68. $result[$i]['select'] = $other['state'];
  69. } else {
  70. $result[$i]['total'] = 0;
  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. if ($result[$i]['price'] <= 0) {
  77. $result[$i]['price'] = $sku[0]['price'];
  78. }
  79. $result[$i]['id'] .= '-' . $sku[0]['id'];
  80. $result[$i]['end'] = true;
  81. } else {
  82. foreach ($sku as $k1 => $v1) {
  83. $v1['sku_name'] = '';
  84. if ($v1['key']) {
  85. $key = str_replace('-', ',', $v1['key']);
  86. $spec = Dever::db('product/info_spec_value')->getData(array('ids' => $key));
  87. $v1['sku_name'] = $spec['name'];
  88. }
  89. $name = $v['name'];
  90. if ($v1['sku_name']) {
  91. $name .= '-' . $v1['sku_name'];
  92. }
  93. $children = array
  94. (
  95. 'id' => $v['id'] . '-' . $v1['id'],
  96. 'name' => $name,
  97. 'stock' => $v['stock'],
  98. 'commission' => $v['commission'],
  99. 'price' => $v1['price'] ? $v1['price'] : 0,
  100. 'type' => $v['type'],
  101. 'del' => 1,
  102. 'end' => true,
  103. );
  104. $other_where['sku_id'] = $v1['id'];
  105. $other_sku = Dever::db($table)->find($other_where);
  106. $children['select'] = 2;
  107. $children['total'] = 0;
  108. if ($other_sku) {
  109. if (isset($other_sku['commission'])) {
  110. $children['commission'] = $other_sku['commission'];
  111. }
  112. if (isset($other_sku['price'])) {
  113. $children['price'] = $other_sku['price'];
  114. }
  115. if (isset($other_sku['min'])) {
  116. $children['min'] = $other_sku['min'];
  117. }
  118. if (isset($other_sku['total_num'])) {
  119. if (isset($other_sku['sell_num'])) {
  120. $children['total'] = $other_sku['total_num'] - $other_sku['sell_num'];
  121. } else {
  122. $children['total'] = $other_sku['total_num'];
  123. }
  124. } else {
  125. $children['total'] = $other_sku['num'];
  126. }
  127. $children['select'] = $other_sku['state'];
  128. }
  129. $children['total'] = $children['total']*$total;
  130. $result[$i]['children'][] = $children;
  131. }
  132. }
  133. $i++;
  134. }
  135. }
  136. }
  137. return $result;
  138. }
  139. }