Info.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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', $set = array())
  25. {
  26. $price = Dever::input('price', 0);
  27. $buy_price = Dever::input('buy_price', 0);
  28. $total = Dever::input('total', 1);
  29. if ($cate_id) {
  30. $where['top_category_id'] = $cate_id;
  31. }
  32. $where['status'] = 1;
  33. $data = Dever::db('product/info')->getData($where);
  34. $result = array();
  35. if ($data) {
  36. $i = 0;
  37. foreach ($data as $k => $v) {
  38. $sku = Dever::db('product/info_sku')->select(array('info_id' => $v['id']));
  39. if ($sku) {
  40. $other_where[$col] = $v['id'];
  41. $other_where['sku_id'] = -1;
  42. $other = Dever::db($table)->find($other_where);
  43. if ($set) {
  44. $result[$i]['set'] = $set;
  45. }
  46. $result[$i]['id'] = $v['id'];
  47. $result[$i]['name'] = $v['name'];
  48. $result[$i]['type'] = $v['type'];
  49. $result[$i]['stock'] = $v['stock'];
  50. $result[$i]['commission'] = $v['commission'];
  51. $result[$i]['old_price'] = 0;
  52. $result[$i]['old_buy_price'] = 0;
  53. $result[$i]['price'] = $price;
  54. $result[$i]['buy_price'] = $buy_price;
  55. $result[$i]['select'] = 2;
  56. $result[$i]['del'] = 1;
  57. $result[$i]['total'] = 0;
  58. if ($other) {
  59. if (isset($other['commission']) && $other['commission']) {
  60. $result[$i]['commission'] = $other['commission'];
  61. }
  62. if (isset($other['price']) && $other['price']) {
  63. $result[$i]['price'] = $other['price'];
  64. }
  65. if (isset($other['buy_price']) && $other['buy_price']) {
  66. $result[$i]['buy_price'] = $other['buy_price'];
  67. }
  68. if (isset($other['min']) && $other['min']) {
  69. $result[$i]['min'] = $other['min'];
  70. }
  71. if (isset($other['total_num'])) {
  72. if (isset($other['sell_num'])) {
  73. $result[$i]['total'] = $other['total_num'] - $other['sell_num'];
  74. } else {
  75. $result[$i]['total'] = $other['total_num'];
  76. }
  77. } elseif (isset($other['num'])) {
  78. $result[$i]['total'] = $other['num'];
  79. }
  80. $result[$i]['select'] = $other['state'];
  81. }
  82. $result[$i]['total'] = $result[$i]['total'] * $total;
  83. $result[$i]['children'] = array();
  84. $num = count($sku);
  85. if ($sku[0]['key'] == -1) {
  86. $result[$i]['old_price'] = $sku[0]['price'];
  87. $result[$i]['old_buy_price'] = $sku[0]['buy_price'];
  88. if (!$price && $result[$i]['price'] <= 0) {
  89. $result[$i]['price'] = $sku[0]['price'];
  90. }
  91. if (!$buy_price && $result[$i]['buy_price'] <= 0) {
  92. $result[$i]['buy_price'] = $sku[0]['buy_price'];
  93. }
  94. //$result[$i]['id'] .= '-' . $sku[0]['id'];
  95. $result[$i]['end'] = true;
  96. } else {
  97. foreach ($sku as $k1 => $v1) {
  98. $v1['sku_name'] = '';
  99. if ($v1['key']) {
  100. $key = str_replace('-', ',', $v1['key']);
  101. $spec = Dever::db('product/info_spec_value')->getData(array('ids' => $key));
  102. $v1['sku_name'] = $spec['name'];
  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. 'stock' => $v['stock'],
  113. 'commission' => $v['commission'],
  114. 'old_price' => $v1['price'] ? $v1['price'] : 0,
  115. 'old_buy_price' => $v1['buy_price'] ? $v1['buy_price'] : 0,
  116. 'price' => $price ? $price : $v1['price'],
  117. 'buy_price' => $buy_price ? $buy_price : $v1['buy_price'],
  118. 'type' => $v['type'],
  119. 'del' => 1,
  120. 'end' => true,
  121. 'total' => 0,
  122. );
  123. $other_where['sku_id'] = $v1['id'];
  124. $other_sku = Dever::db($table)->find($other_where);
  125. $children['select'] = 2;
  126. $children['total'] = 0;
  127. if ($set) {
  128. $children['set'] = $set;
  129. }
  130. if ($other_sku) {
  131. if (isset($other_sku['commission']) && $other_sku['commission']) {
  132. $children['commission'] = $other_sku['commission'];
  133. }
  134. if (isset($other_sku['price']) && $other_sku['price']) {
  135. $children['price'] = $other_sku['price'];
  136. }
  137. if (isset($other_sku['buy_price']) && $other_sku['buy_price']) {
  138. $children['buy_price'] = $other_sku['buy_price'];
  139. }
  140. if (isset($other_sku['min']) && $other_sku['min']) {
  141. $children['min'] = $other_sku['min'];
  142. }
  143. if (isset($other_sku['total_num'])) {
  144. if (isset($other_sku['sell_num'])) {
  145. $children['total'] = $other_sku['total_num'] - $other_sku['sell_num'];
  146. } else {
  147. $children['total'] = $other_sku['total_num'];
  148. }
  149. } elseif (isset($other_sku['num'])) {
  150. $children['total'] = $other_sku['num'];
  151. }
  152. $children['select'] = $other_sku['state'];
  153. }
  154. $children['total'] = $children['total']*$total;
  155. $result[$i]['children'][] = $children;
  156. }
  157. }
  158. $i++;
  159. }
  160. }
  161. }
  162. return $result;
  163. }
  164. }