Set.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 = Dever::db($table)->find(array($type => $id, 'goods_id' => $v['id'], 'key' => -1));
  21. $result[$i]['id'] = $v['id'];
  22. $result[$i]['name'] = $v['name'];
  23. $result[$i]['price'] = $v['price'];
  24. $result[$i]['price_type'] = $v['price_type'];
  25. $result[$i]['select'] = 2;
  26. $result[$i]['del'] = 1;
  27. if ($type == 'factory_id') {
  28. if ($other) {
  29. $result[$i]['p_price'] = $other['p_price'];
  30. $result[$i]['select'] = $other['state'];
  31. } else {
  32. $result[$i]['p_price'] = $v['price'];
  33. }
  34. } else {
  35. if ($other) {
  36. $result[$i]['total'] = $other['total_num'] - $other['sell_num'];
  37. $result[$i]['select'] = $other['state'];
  38. } else {
  39. $result[$i]['total'] = 0;
  40. }
  41. }
  42. $result[$i]['children'] = array();
  43. $num = count($sku);
  44. if ($num == 1 && $sku[0]['key'] == -1) {
  45. $result[$i]['end'] = true;
  46. } else {
  47. foreach ($sku as $k1 => $v1) {
  48. $v1['sku_name'] = '';
  49. if ($v1['attr']) {
  50. $v1['attr'] = Dever::json_decode($v1['attr']);
  51. if ($v1['attr']) {
  52. $v1['attr'] = Dever::load('attr/api')->getInfoByJson($v1['attr']);
  53. $v1['sku_name'] = $v1['attr']['string'];
  54. }
  55. }
  56. $name = $v['name'];
  57. if ($v1['sku_name']) {
  58. $name .= '-' . $v1['sku_name'];
  59. }
  60. $children = array
  61. (
  62. 'id' => $v['id'] . '-' . $v1['id'],
  63. 'name' => $name,
  64. 'price' => $v1['price'] ? $v1['price'] : 0,
  65. 'price_type' => $v['price_type'],
  66. 'del' => 1,
  67. 'end' => true,
  68. );
  69. $other_sku = Dever::db($table)->find(array($type => $id, 'goods_id' => $v['id'], 'sku_id' => $v1['id']));
  70. $children['select'] = 2;
  71. if ($type == 'factory_id') {
  72. $children['p_price'] = $v1['price'];
  73. if ($other_sku) {
  74. $children['p_price'] = $other_sku['p_price'];
  75. $children['select'] = $other_sku['state'];
  76. }
  77. } else {
  78. $children['total'] = 0;
  79. if ($other_sku) {
  80. $children['total'] = $other_sku['total_num'] - $other_sku['sell_num'];
  81. $children['select'] = $other_sku['state'];
  82. }
  83. }
  84. $result[$i]['children'][] = $children;
  85. }
  86. }
  87. $i++;
  88. }
  89. }
  90. }
  91. return $result;
  92. }
  93. }