Sku.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Product\Lib;
  3. use Dever;
  4. class Sku
  5. {
  6. # 获取当前的规格
  7. public function spec_api()
  8. {
  9. $id = Dever::input('id');
  10. $result = array();
  11. if ($id) {
  12. $result = Dever::db('product/info_spec')->getAll(array('info_id' => $id));
  13. if ($result) {
  14. foreach ($result as $k => $v) {
  15. $result[$k]['child'] = Dever::db('product/info_spec_value')->getAll(array('info_id' => $id, 'spec_id' => $v['id']));
  16. }
  17. }
  18. }
  19. return $result;
  20. }
  21. # 获取当前的sku
  22. public function sku_api()
  23. {
  24. $id = Dever::input('id');
  25. $result = array();
  26. if ($id) {
  27. $result = Dever::db('product/info_sku')->getAll(array('info_id' => $id));
  28. }
  29. return $result;
  30. }
  31. # 获取某个商品的sku
  32. public function getList($info, &$data)
  33. {
  34. if ($info['spec_type'] == 2) {
  35. $where['info_id'] = $info['id'];
  36. $sku = Dever::db('product/info_sku')->select($where);
  37. if ($sku) {
  38. foreach ($sku as $k => $v) {
  39. $copy = $info;
  40. $key = str_replace('-', ',', $v['key']);
  41. $spec = Dever::db('product/info_spec_value')->getData(array('ids' => $key));
  42. if ($spec) {
  43. $copy['name'] .= '-' . $spec['name'];
  44. $copy['id'] .= '-' . $v['key'];
  45. if (isset($copy['value'])) {
  46. $copy['value'] = $copy['id'];
  47. }
  48. }
  49. $data[] = $copy;
  50. }
  51. }
  52. } else {
  53. $data[] = $info;
  54. }
  55. return $data;
  56. }
  57. }