ItemSkuCreateInfo.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import json
  4. from alipay.aop.api.constant.ParamConstants import *
  5. from alipay.aop.api.domain.ItemExtInfo import ItemExtInfo
  6. class ItemSkuCreateInfo(object):
  7. def __init__(self):
  8. self._cost_price = None
  9. self._ext_info = None
  10. self._external_sku_id = None
  11. self._inventory = None
  12. self._original_price = None
  13. self._price = None
  14. @property
  15. def cost_price(self):
  16. return self._cost_price
  17. @cost_price.setter
  18. def cost_price(self, value):
  19. self._cost_price = value
  20. @property
  21. def ext_info(self):
  22. return self._ext_info
  23. @ext_info.setter
  24. def ext_info(self, value):
  25. if isinstance(value, list):
  26. self._ext_info = list()
  27. for i in value:
  28. if isinstance(i, ItemExtInfo):
  29. self._ext_info.append(i)
  30. else:
  31. self._ext_info.append(ItemExtInfo.from_alipay_dict(i))
  32. @property
  33. def external_sku_id(self):
  34. return self._external_sku_id
  35. @external_sku_id.setter
  36. def external_sku_id(self, value):
  37. self._external_sku_id = value
  38. @property
  39. def inventory(self):
  40. return self._inventory
  41. @inventory.setter
  42. def inventory(self, value):
  43. self._inventory = value
  44. @property
  45. def original_price(self):
  46. return self._original_price
  47. @original_price.setter
  48. def original_price(self, value):
  49. self._original_price = value
  50. @property
  51. def price(self):
  52. return self._price
  53. @price.setter
  54. def price(self, value):
  55. self._price = value
  56. def to_alipay_dict(self):
  57. params = dict()
  58. if self.cost_price:
  59. if hasattr(self.cost_price, 'to_alipay_dict'):
  60. params['cost_price'] = self.cost_price.to_alipay_dict()
  61. else:
  62. params['cost_price'] = self.cost_price
  63. if self.ext_info:
  64. if isinstance(self.ext_info, list):
  65. for i in range(0, len(self.ext_info)):
  66. element = self.ext_info[i]
  67. if hasattr(element, 'to_alipay_dict'):
  68. self.ext_info[i] = element.to_alipay_dict()
  69. if hasattr(self.ext_info, 'to_alipay_dict'):
  70. params['ext_info'] = self.ext_info.to_alipay_dict()
  71. else:
  72. params['ext_info'] = self.ext_info
  73. if self.external_sku_id:
  74. if hasattr(self.external_sku_id, 'to_alipay_dict'):
  75. params['external_sku_id'] = self.external_sku_id.to_alipay_dict()
  76. else:
  77. params['external_sku_id'] = self.external_sku_id
  78. if self.inventory:
  79. if hasattr(self.inventory, 'to_alipay_dict'):
  80. params['inventory'] = self.inventory.to_alipay_dict()
  81. else:
  82. params['inventory'] = self.inventory
  83. if self.original_price:
  84. if hasattr(self.original_price, 'to_alipay_dict'):
  85. params['original_price'] = self.original_price.to_alipay_dict()
  86. else:
  87. params['original_price'] = self.original_price
  88. if self.price:
  89. if hasattr(self.price, 'to_alipay_dict'):
  90. params['price'] = self.price.to_alipay_dict()
  91. else:
  92. params['price'] = self.price
  93. return params
  94. @staticmethod
  95. def from_alipay_dict(d):
  96. if not d:
  97. return None
  98. o = ItemSkuCreateInfo()
  99. if 'cost_price' in d:
  100. o.cost_price = d['cost_price']
  101. if 'ext_info' in d:
  102. o.ext_info = d['ext_info']
  103. if 'external_sku_id' in d:
  104. o.external_sku_id = d['external_sku_id']
  105. if 'inventory' in d:
  106. o.inventory = d['inventory']
  107. if 'original_price' in d:
  108. o.original_price = d['original_price']
  109. if 'price' in d:
  110. o.price = d['price']
  111. return o