Files
real-e-party-iOS/YuMi/Modules/ShoppingMall/MyDressingDataModel.m
edwinQQQ a35a711be6 chore: Initial clean commit
- Removed YuMi/Library/ (138 MB, not tracked)
- Removed YuMi/Resources/ (23 MB, not tracked)
- Removed old version assets (566 files, not tracked)
- Excluded Pods/, xcuserdata/ and other build artifacts
- Clean repository optimized for company server deployment
2025-10-09 16:19:14 +08:00

208 lines
8.8 KiB
Objective-C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// MyDressingDataModel.m
// YuMi
//
// Created by P on 2024/11/19.
//
#import "MyDressingDataModel.h"
@implementation MyDressingDataModel
// JSON 字段映射
+ (NSDictionary *)mj_replacedKeyFromPropertyName {
return @{
@"dressShopId" : @"id"
};
}
//// 自定义转换逻辑
//- (id)mj_newValueFromOldValue:(id)oldValue property:(MJProperty *)property {
// if ([property.name isEqualToString:@"dressShopId"]) {
// if ([oldValue isKindOfClass:[NSNumber class]]) {
// // 将 NSNumber 转换为 NSString
// return [oldValue stringValue];
// }
// }
// return oldValue;
//}
- (NSString *)expiredContent {
if (self.hasExpired) {
return YMLocalizedString(@"XPMineCarTableViewCell1");
} else {
NSString *content = @"";
if (self.expireDays < 1) {
content = YMLocalizedString(@"1.0.30_text_13");
} else {
content = [NSString stringWithFormat:YMLocalizedString(@"1.0.18_8"), @(self.expireDays)];
}
return content;
}
}
- (NSMutableAttributedString *)generateAttributedStringWithIncludeOriginalPrice:(BOOL)includeOriginalPrice {
// 创建一个 NSMutableAttributedString 来存放最终的结果
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] init];
// 1. 添加金币图片
NSTextAttachment *coinAttachment = [[NSTextAttachment alloc] init];
coinAttachment.image = kImage(@"moli_money_icon"); // 替换为你的金币图片名称
coinAttachment.bounds = CGRectMake(0, -2, 18, 18); // 设置图片大小和位置,偏移量适当调整
NSAttributedString *coinString = [NSAttributedString attributedStringWithAttachment:coinAttachment];
[attributedString appendAttributedString:coinString];
// 2. 添加空格
NSAttributedString *spaceString = [[NSAttributedString alloc] initWithString:@" "];
[attributedString appendAttributedString:spaceString];
// 3. 添加 price 文本,字体加粗,颜色 #F8CE1F字体大小 25
NSDictionary *priceAttributes = @{
NSFontAttributeName: kFontSemibold(15),
NSForegroundColorAttributeName: UIColorFromRGB(0xF8CE1F)
};
NSString *formattedPriceString = [self formatPrice: self.vipLevel>0 ? self.discountPrice : self.dressPrice];
NSAttributedString *priceString = [[NSAttributedString alloc] initWithString:formattedPriceString attributes:priceAttributes];
[attributedString appendAttributedString:priceString];
// 4. 添加 day 文本,字体常规,颜色 #F8CE1F字体大小 12
NSDictionary *dayAttributes = @{
NSFontAttributeName: kFontRegular(12),
NSForegroundColorAttributeName: UIColorFromRGB(0xF8CE1F)
};
NSString *formattedDayString = [NSString stringWithFormat:@"/%ldD ", (long)self.dressDay];
NSAttributedString *dayString = [[NSAttributedString alloc] initWithString:formattedDayString attributes:dayAttributes];
[attributedString appendAttributedString:dayString];
// 如果需要添加原始价格
if (includeOriginalPrice && self.vipLevel > 0) {
NSDictionary *originalPriceAttributes = @{
NSFontAttributeName: kFontRegular(12),
NSForegroundColorAttributeName: UIColorRGBAlpha(0xD9E7F7, 0.5f),
NSStrikethroughStyleAttributeName: @(NSUnderlineStyleSingle), // 单条删除线
NSStrikethroughColorAttributeName: UIColorRGBAlpha(0xD9E7F7, 0.5f) // 删除线颜色
};
NSString *originalPriceString = [NSString stringWithFormat:@"%@", [self formatPrice:self.dressPrice]];
NSAttributedString *originalPriceAttributedString = [[NSAttributedString alloc] initWithString:originalPriceString attributes:originalPriceAttributes];
[attributedString appendAttributedString:originalPriceAttributedString];
}
return attributedString;
}
// 辅助方法:格式化价格,支持 0-2 位小数
- (NSString *)formatPrice:(CGFloat)price {
// if (fmod(price, 1.0) == 0.0) {
// // 整数,移除小数部分
// return [NSString stringWithFormat:@"%.0f", price];
// } else if (fmod(price * 10, 1.0) == 0.0) {
// // 保留 1 位小数
// return [NSString stringWithFormat:@"%.1f", price];
// } else {
// // 保留 2 位小数
// return [NSString stringWithFormat:@"%.2f", price];
// }
NSString *priceString = [NSString stringWithFormat:@"%.8f", price]; // 确保保留足够的位数
NSArray<NSString *> *components = [priceString componentsSeparatedByString:@"."]; // 分割整数和小数部分
NSString *integerPart = components[0];
NSString *decimalPart = components.count > 1 ? components[1] : @"";
if (decimalPart.length > 2) {
// 保留最多两位有效小数,直接截断
decimalPart = [decimalPart substringToIndex:2];
}
if ([decimalPart isEqualToString:@"00"]) {
// 如果小数部分为 00只返回整数部分
return integerPart;
} else if ([decimalPart hasSuffix:@"0"]) {
// 如果小数部分以 0 结尾,保留 1 位小数
decimalPart = [decimalPart substringToIndex:1];
}
// 拼接整数和截断后的小数部分
return [NSString stringWithFormat:@"%@.%@", integerPart, decimalPart];
}
+ (MyDressingDataModel *)modelFromVehicle:(CarModel *)model {
MyDressingDataModel *myDressingVehicle = [[MyDressingDataModel alloc] init];
myDressingVehicle.dressId = model.dressShopId;
myDressingVehicle.id = model.carID.integerValue;
myDressingVehicle.pic = model.pic;
myDressingVehicle.name = model.name;
myDressingVehicle.used = model.using;
myDressingVehicle.expireDays = model.expireDate;
myDressingVehicle.hasExpired = (model.status != 3 || model.expireDate<0);
myDressingVehicle.dressType = 1;
myDressingVehicle.discount = model.discount;
myDressingVehicle.discountPrice = model.discountPrice;
myDressingVehicle.dressPrice = model.dressPrice;
myDressingVehicle.vipLevel = model.vipLevel;
myDressingVehicle.dressShopId = model.dressShopId;
myDressingVehicle.effect = model.effect;
return myDressingVehicle;
}
+ (MyDressingDataModel *)modelFromNameplate:(NameplateModel *)model {
MyDressingDataModel *myDressingNameplate = [[MyDressingDataModel alloc] init];
myDressingNameplate.pic = model.nameplateImage;
myDressingNameplate.name = model.nameplateName;
myDressingNameplate.used = model.isUsing;
myDressingNameplate.expireDays = model.expireDays;
myDressingNameplate.expireTime = model.expireTime;
myDressingNameplate.hasExpired = model.isExpired;
myDressingNameplate.id = model.nId.integerValue;
myDressingNameplate.dressId = model.dressShopId;// model.nameplateId;
myDressingNameplate.dressType = 2;
myDressingNameplate.discount = model.discount;
myDressingNameplate.dressDay = model.dressDay;
myDressingNameplate.discountPrice = model.discountPrice;
myDressingNameplate.vipLevel = model.vipLevel;
myDressingNameplate.dressPrice = model.dressPrice;
myDressingNameplate.dressShopId = model.dressShopId;
myDressingNameplate.effect = model.effect;
myDressingNameplate.effectType = model.effectType;
return myDressingNameplate;
}
+ (MyDressingDataModel *)modelFromNobelCard:(NobleCardModel *)model {
MyDressingDataModel *myDressingNobrlCard = [[MyDressingDataModel alloc] init];
myDressingNobrlCard.pic = model.pic;
myDressingNobrlCard.effect = model.effect;
myDressingNobrlCard.name = model.name;
myDressingNobrlCard.used = model.used;
myDressingNobrlCard.expireDays = model.expireDays;
myDressingNobrlCard.expireTime = model.expireTime.integerValue;
myDressingNobrlCard.hasExpired = model.hasExpired;
myDressingNobrlCard.dressId = model.cardId;
myDressingNobrlCard.dressType = 3;
myDressingNobrlCard.discount = model.discount;
myDressingNobrlCard.dressDay = model.dressDay;
myDressingNobrlCard.discountPrice = model.discountPrice;
myDressingNobrlCard.vipLevel = model.vipLevel;
myDressingNobrlCard.dressPrice = model.dressPrice;
myDressingNobrlCard.dressShopId = model.dressShopId;
myDressingNobrlCard.effectType = model.effectType;
return myDressingNobrlCard;
}
+ (MyDressingDataModel *)modelFromChatBubble:(ChatBubbleModel *)model {
MyDressingDataModel *myDressingBubble = [[MyDressingDataModel alloc] init];
myDressingBubble.pic = model.bubbleUrl;
myDressingBubble.dressId = model.bubbleId;
myDressingBubble.expireDays = model.expireDays;
myDressingBubble.name = model.name;
myDressingBubble.used = model.hasUsed;
myDressingBubble.hasExpired = model.hasExpired;
myDressingBubble.dressType = 4;
myDressingBubble.dressShopId = model.bubbleId;
myDressingBubble.effect = model.effect;
myDressingBubble.effectType = model.effectType;
return myDressingBubble;
}
@end