AvailableTimeInfo.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import json
  4. from alipay.aop.api.constant.ParamConstants import *
  5. class AvailableTimeInfo(object):
  6. def __init__(self):
  7. self._available_days = None
  8. self._from_time = None
  9. self._limit_period_unit = None
  10. self._to_time = None
  11. @property
  12. def available_days(self):
  13. return self._available_days
  14. @available_days.setter
  15. def available_days(self, value):
  16. if isinstance(value, list):
  17. self._available_days = list()
  18. for i in value:
  19. self._available_days.append(i)
  20. @property
  21. def from_time(self):
  22. return self._from_time
  23. @from_time.setter
  24. def from_time(self, value):
  25. self._from_time = value
  26. @property
  27. def limit_period_unit(self):
  28. return self._limit_period_unit
  29. @limit_period_unit.setter
  30. def limit_period_unit(self, value):
  31. self._limit_period_unit = value
  32. @property
  33. def to_time(self):
  34. return self._to_time
  35. @to_time.setter
  36. def to_time(self, value):
  37. self._to_time = value
  38. def to_alipay_dict(self):
  39. params = dict()
  40. if self.available_days:
  41. if isinstance(self.available_days, list):
  42. for i in range(0, len(self.available_days)):
  43. element = self.available_days[i]
  44. if hasattr(element, 'to_alipay_dict'):
  45. self.available_days[i] = element.to_alipay_dict()
  46. if hasattr(self.available_days, 'to_alipay_dict'):
  47. params['available_days'] = self.available_days.to_alipay_dict()
  48. else:
  49. params['available_days'] = self.available_days
  50. if self.from_time:
  51. if hasattr(self.from_time, 'to_alipay_dict'):
  52. params['from_time'] = self.from_time.to_alipay_dict()
  53. else:
  54. params['from_time'] = self.from_time
  55. if self.limit_period_unit:
  56. if hasattr(self.limit_period_unit, 'to_alipay_dict'):
  57. params['limit_period_unit'] = self.limit_period_unit.to_alipay_dict()
  58. else:
  59. params['limit_period_unit'] = self.limit_period_unit
  60. if self.to_time:
  61. if hasattr(self.to_time, 'to_alipay_dict'):
  62. params['to_time'] = self.to_time.to_alipay_dict()
  63. else:
  64. params['to_time'] = self.to_time
  65. return params
  66. @staticmethod
  67. def from_alipay_dict(d):
  68. if not d:
  69. return None
  70. o = AvailableTimeInfo()
  71. if 'available_days' in d:
  72. o.available_days = d['available_days']
  73. if 'from_time' in d:
  74. o.from_time = d['from_time']
  75. if 'limit_period_unit' in d:
  76. o.limit_period_unit = d['limit_period_unit']
  77. if 'to_time' in d:
  78. o.to_time = d['to_time']
  79. return o