Sku.php 2.2 KB

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