SPSBDiscountCouponModel.m 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // SPSBDiscountCouponModel.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/5/24.
  6. //
  7. #import "SPSBDiscountCouponModel.h"
  8. #import <JXHSystemShortcut.h>
  9. typedef NS_ENUM(NSUInteger, SPSBDiscountCouponStatus) {
  10. SPSBDiscountCouponStatusUnuse = 1,
  11. SPSBDiscountCouponStatusUsed
  12. };
  13. typedef NS_ENUM(NSUInteger, SPSBDiscountCouponExpired) {
  14. SPSBDiscountCouponExpiredNo = 0,
  15. SPSBDiscountCouponExpiredYes
  16. };
  17. @implementation SPSBDiscountCouponModel
  18. - (bool)handleAdditionalProperty {
  19. [super handleAdditionalProperty];
  20. NSString *endDate;
  21. if (_spsb_end_time.length > 10) {
  22. endDate = [_spsb_end_time substringToIndex:10];
  23. } else {
  24. endDate = [[jxh_dateFormatter() stringFromDate:[NSDate new]] substringToIndex:10];
  25. }
  26. if (_spsb_status.integerValue == SPSBDiscountCouponStatusUsed) {
  27. _spsba_status = @"已使用";
  28. _spsba_canUse = false;
  29. } else if (_spsb_expired.integerValue == SPSBDiscountCouponExpiredYes) {
  30. _spsba_status = @"已过期";
  31. _spsba_canUse = false;
  32. } else {
  33. NSString *today = [jxh_dateFormatter() stringFromDate:[NSDate new]];
  34. NSString *todayDate = [today substringToIndex:10];
  35. if ([todayDate isEqualToString:endDate]) {
  36. _spsba_status = @"今天过期";
  37. } else {
  38. NSString *tempToday = [NSString stringWithFormat:@"%@ 00:00:00", todayDate];
  39. NSDate *tempTodayTime = [jxh_dateFormatter() dateFromString:tempToday];
  40. NSString *tempEndDate = [NSString stringWithFormat:@"%@ 00:00:00", endDate];
  41. NSDate *tempEndTime = [jxh_dateFormatter() dateFromString:tempEndDate];
  42. NSInteger diff = (NSInteger)([tempEndTime timeIntervalSinceDate:tempTodayTime] / 3600 / 24);
  43. if ([_spsb_end_time isEqualToString: tempEndDate]) {
  44. diff --;
  45. }
  46. if (diff == 0) {
  47. _spsba_status = @"今天过期";
  48. } else {
  49. _spsba_status = [NSString stringWithFormat:@"还有%ld天过期", (long)diff];
  50. }
  51. }
  52. _spsba_canUse = true;
  53. }
  54. _spsb_end_time = endDate;
  55. return true;
  56. }
  57. @end