Goods.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Factory\Lib;
  3. use Dever;
  4. class Goods
  5. {
  6. # 获取店铺的商品SKU列表
  7. public function getSkuList($factory)
  8. {
  9. $table = 'factory/goods_sku';
  10. $where['factory_id'] = isset($factory['id']) ? $factory['id'] : $factory;
  11. $method = 'getDataPage';
  12. $name = Dever::input('name');
  13. if ($name) {
  14. $where['name'] = $name;
  15. }
  16. $where['status'] = 1;
  17. $where['state'] = 1;
  18. $where['state_1'] = 1;
  19. $data = Dever::db($table)->$method($where);
  20. $result = array();
  21. if ($data) {
  22. foreach ($data as $k => $v) {
  23. $data[$k] = Dever::load('goods/lib/info')->getPayInfo($v['goods_id'], $v['sku_id']);
  24. if ($data[$k]['status'] == 1) {
  25. if (!isset($result[$v['id']])) {
  26. $result[$v['id']]['id'] = $v['id'];
  27. $result[$v['id']]['name'] = $v['name'];
  28. $result[$v['id']]['min'] = $data[$k]['min'];
  29. $result[$v['id']]['price'] = $v['p_price'] ? $v['p_price'] : 0;
  30. $result[$v['id']]['c_price'] = $data[$k]['c_price'] ? $data[$k]['c_price'] : 0;
  31. $result[$v['id']]['children'] = array();
  32. }
  33. if (isset($data[$k]['attr']) && $data[$k]['attr']) {
  34. $result[$v['id']]['children'][] = array
  35. (
  36. 'id' => $v['id'] . '-' . $data[$k]['sku_id'],
  37. 'name' => $v['name'] . '-' . $data[$k]['sku_name'],
  38. 'min' => $data[$k]['min'],
  39. 'price' => $v['p_price'] ? $v['p_price'] : 0,
  40. 'c_price' => $data[$k]['c_price'] ? $data[$k]['c_price'] : 0,
  41. 'end' => true,
  42. );
  43. }
  44. if (!$result[$v['id']]['children']) {
  45. $result[$v['id']]['end'] = true;
  46. }
  47. }
  48. }
  49. }
  50. return array_values($result);
  51. }
  52. }