Sku.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace Scm_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('scm_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']) {
  20. $where['info_id'] = $info['id'];
  21. if (isset($info['sku_id'])) {
  22. $where['id'] = $info['sku_id'];
  23. }
  24. $sku = Dever::db('scm_product/info_sku')->select($where);
  25. if ($sku) {
  26. foreach ($sku as $k => $v) {
  27. $copy = $info;
  28. $copy['id'] .= '-' . $v['id'];
  29. if (isset($info['servicer_store_id']) && $info['servicer_store_id']) {
  30. $copy['id'] .= '-' . $info['id'];
  31. }
  32. $key = str_replace('-', ',', $v['key']);
  33. $spec = Dever::db('scm_product/info_spec_value')->getGroupData(array('ids' => $key));
  34. $copy['spec'] = '无';
  35. if ($spec) {
  36. $copy['sname'] = $copy['name'];
  37. $copy['spec'] = $spec['name'];
  38. $copy['name'] .= '-' . $spec['name'];
  39. if (isset($copy['value'])) {
  40. $copy['value'] = $copy['id'];
  41. }
  42. }
  43. $data[] = $copy;
  44. }
  45. }
  46. } else {
  47. $data[] = $info;
  48. }
  49. return $data;
  50. }
  51. # 获取基本信息列表
  52. public function getData($info_id, $sku_id = false, $type = 1)
  53. {
  54. $seller_id = Dever::input('seller_id');
  55. if ($seller_id) {
  56. $seller = Dever::db('scm_role/seller')->find($seller_id);
  57. }
  58. $where['info_id'] = $info_id;
  59. if ($sku_id) {
  60. $where['id'] = $sku_id;
  61. }
  62. $sku = Dever::db('scm_product/info_sku')->getData($where);
  63. if ($sku) {
  64. foreach ($sku as $k => $v) {
  65. unset($sku[$k]['key']);
  66. if ($seller_id && $seller) {
  67. list($sku[$k]['price'], $sku[$k]['buy_price']) = Dever::load('scm_product/lib/price')->get($seller['price_id'], $info_id, $v['id'], $sku[$k]['price'], $sku[$k]['buy_price']);
  68. }
  69. if ($type == 1) {
  70. unset($sku[$k]['buy_price']);
  71. unset($sku[$k]['cost_price']);
  72. } elseif ($type == 2) {
  73. unset($sku[$k]['price']);
  74. unset($sku[$k]['un_price']);
  75. }
  76. }
  77. }
  78. return $sku;
  79. }
  80. }