123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- //
- // FKPurchaseCache.m
- // FirstLink
- //
- // Created by ascii on 15/11/4.
- // Copyright © 2015年 FirstLink. All rights reserved.
- //
- #import "FKPurchaseCache.h"
- @implementation FKPurchaseCache
- - (BOOL)isVIP {
- if (self.userLevel == kUserLevelVIP) {
- return YES;
- }
- return NO;
- }
- - (long)getAllWeight {
- long perWeight = 0;
- if ([self.unitWeight isKindOfClass:[NSString class]]) {
- perWeight = self.unitWeight.integerValue;
- }
- return perWeight * [self getAllAmount];
- }
- - (long)getAllAmount {
- NSInteger allCount = 0;
- for (PindanSpecItem *item in self.specArray) {
- allCount += item.selectedAmount;
- }
- return allCount;
- }
- - (CGFloat)getTotalPrice {
- CGFloat allCount = 0;
- for (NSInteger i = 0; i < self.specArray.count; i++) {
- PindanSpecItem *item = self.specArray[i];
- CGFloat unitPrice = [self getSingleProductPriceForIndex:i];
- if ([self isVIP] && item.vipPrice.length > 0) {
- unitPrice = [self getSingleVipProductPriceForIndex:i];
- }
- CGFloat singleCount = item.selectedAmount * unitPrice;
- allCount += singleCount;
- }
- return allCount;
- }
- - (CGFloat)getSingleProductPriceForIndex:(NSInteger)index{
- PindanSpecItem *item = [self getSpecItemAtIndex:index];
- if (item) {
- CGFloat unitPrice = item.price.floatValue;
- CGFloat nationalPostage = self.internationalPostage.floatValue;
- return (unitPrice + nationalPostage) / 100.0f;
- }
- return 0;
- }
- - (CGFloat)getSingleVipProductPriceForIndex:(NSInteger)index {
- PindanSpecItem *item = [self getSpecItemAtIndex:index];
- if (item && item.vipPrice.length > 0) {
- CGFloat unitPrice = item.vipPrice.floatValue;
- CGFloat nationalPostage = self.internationalPostage.floatValue;
- return (unitPrice + nationalPostage) / 100.0f;
- }
- return 0;
- }
- - (NSAttributedString *)getTotalPriceString {
- NSString *string = [NSString stringWithFormat:@"¥%.2f", [self getTotalPrice]];
- NSMutableAttributedString *attM = [[NSMutableAttributedString alloc] initWithString:string];
- [attM addAttribute:NSForegroundColorAttributeName
- value:UIColorFromRGB(0xff6362)
- range:NSMakeRange(0, string.length)];
- return attM;
- }
- - (NSInteger)getRealAmountLimit {
- NSInteger limiteAmount = self.limiteAmount == 0 ? NSIntegerMax : self.limiteAmount;
- return limiteAmount;
- }
- - (NSInteger)getStockLimitAtIndex:(NSInteger)index{
- PindanSpecItem *item = [self getSpecItemAtIndex:index];
- if (item) {
- return [item.stock isKindOfClass:[NSString class]] ? item.stock.integerValue : NSIntegerMax;
- }
- return 0;
- }
- - (void)changeSpecAmount:(NSInteger)amount AtIndex:(NSInteger)index{
- PindanSpecItem *item = [self getSpecItemAtIndex:index];
- if (item) {
- item.selectedAmount = amount;
- if (amount == 0) [self deleteSpecAtIndex:index];
- }
- }
- - (PindanSpecItem *)getSpecItemAtIndex:(NSInteger)index{
- if (index >= 0 && index < self.specArray.count) {
- return self.specArray[index];
- }
- return nil;
- }
- - (void)deleteSpecAtIndex:(NSUInteger)index{
- if (index < self.specArray.count) {
- NSMutableArray *arrayM = [NSMutableArray arrayWithArray:self.specArray];
- [arrayM removeObjectAtIndex:index];
- self.specArray = arrayM;
- }
- }
- @end
|