Aucune description

FKPurchaseCache.m 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //
  2. // FKPurchaseCache.m
  3. // FirstLink
  4. //
  5. // Created by ascii on 15/11/4.
  6. // Copyright © 2015年 FirstLink. All rights reserved.
  7. //
  8. #import "FKPurchaseCache.h"
  9. @implementation FKPurchaseCache
  10. - (BOOL)isVIP {
  11. if (self.userLevel == kUserLevelVIP) {
  12. return YES;
  13. }
  14. return NO;
  15. }
  16. - (long)getAllWeight {
  17. long perWeight = 0;
  18. if ([self.unitWeight isKindOfClass:[NSString class]]) {
  19. perWeight = self.unitWeight.integerValue;
  20. }
  21. return perWeight * [self getAllAmount];
  22. }
  23. - (long)getAllAmount {
  24. NSInteger allCount = 0;
  25. for (PindanSpecItem *item in self.specArray) {
  26. allCount += item.selectedAmount;
  27. }
  28. return allCount;
  29. }
  30. - (CGFloat)getTotalPrice {
  31. CGFloat allCount = 0;
  32. for (NSInteger i = 0; i < self.specArray.count; i++) {
  33. PindanSpecItem *item = self.specArray[i];
  34. CGFloat unitPrice = [self getSingleProductPriceForIndex:i];
  35. if ([self isVIP] && item.vipPrice.length > 0) {
  36. unitPrice = [self getSingleVipProductPriceForIndex:i];
  37. }
  38. CGFloat singleCount = item.selectedAmount * unitPrice;
  39. allCount += singleCount;
  40. }
  41. return allCount;
  42. }
  43. - (CGFloat)getSingleProductPriceForIndex:(NSInteger)index{
  44. PindanSpecItem *item = [self getSpecItemAtIndex:index];
  45. if (item) {
  46. CGFloat unitPrice = item.price.floatValue;
  47. CGFloat nationalPostage = self.internationalPostage.floatValue;
  48. return (unitPrice + nationalPostage) / 100.0f;
  49. }
  50. return 0;
  51. }
  52. - (CGFloat)getSingleVipProductPriceForIndex:(NSInteger)index {
  53. PindanSpecItem *item = [self getSpecItemAtIndex:index];
  54. if (item && item.vipPrice.length > 0) {
  55. CGFloat unitPrice = item.vipPrice.floatValue;
  56. CGFloat nationalPostage = self.internationalPostage.floatValue;
  57. return (unitPrice + nationalPostage) / 100.0f;
  58. }
  59. return 0;
  60. }
  61. - (NSAttributedString *)getTotalPriceString {
  62. NSString *string = [NSString stringWithFormat:@"¥%.2f", [self getTotalPrice]];
  63. NSMutableAttributedString *attM = [[NSMutableAttributedString alloc] initWithString:string];
  64. [attM addAttribute:NSForegroundColorAttributeName
  65. value:UIColorFromRGB(0xff6362)
  66. range:NSMakeRange(0, string.length)];
  67. return attM;
  68. }
  69. - (NSInteger)getRealAmountLimit {
  70. NSInteger limiteAmount = self.limiteAmount == 0 ? NSIntegerMax : self.limiteAmount;
  71. return limiteAmount;
  72. }
  73. - (NSInteger)getStockLimitAtIndex:(NSInteger)index{
  74. PindanSpecItem *item = [self getSpecItemAtIndex:index];
  75. if (item) {
  76. return [item.stock isKindOfClass:[NSString class]] ? item.stock.integerValue : NSIntegerMax;
  77. }
  78. return 0;
  79. }
  80. - (void)changeSpecAmount:(NSInteger)amount AtIndex:(NSInteger)index{
  81. PindanSpecItem *item = [self getSpecItemAtIndex:index];
  82. if (item) {
  83. item.selectedAmount = amount;
  84. if (amount == 0) [self deleteSpecAtIndex:index];
  85. }
  86. }
  87. - (PindanSpecItem *)getSpecItemAtIndex:(NSInteger)index{
  88. if (index >= 0 && index < self.specArray.count) {
  89. return self.specArray[index];
  90. }
  91. return nil;
  92. }
  93. - (void)deleteSpecAtIndex:(NSUInteger)index{
  94. if (index < self.specArray.count) {
  95. NSMutableArray *arrayM = [NSMutableArray arrayWithArray:self.specArray];
  96. [arrayM removeObjectAtIndex:index];
  97. self.specArray = arrayM;
  98. }
  99. }
  100. @end