添加键盘里的充值界面
This commit is contained in:
43
CustomKeyboard/Model/KBKeyboardSubscriptionProduct.h
Normal file
43
CustomKeyboard/Model/KBKeyboardSubscriptionProduct.h
Normal file
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// KBKeyboardSubscriptionProduct.h
|
||||
// CustomKeyboard
|
||||
//
|
||||
// 订阅商品模型(键盘扩展专用),用于展示与主 App 相同的订阅列表。
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface KBKeyboardSubscriptionProduct : NSObject
|
||||
/// 主键 id
|
||||
@property (nonatomic, assign) NSInteger identifier;
|
||||
/// Apple 商品编号
|
||||
@property (nonatomic, copy, nullable) NSString *productId;
|
||||
/// 商品名称,如 Monthly
|
||||
@property (nonatomic, copy, nullable) NSString *name;
|
||||
/// 单位,如 Subscription
|
||||
@property (nonatomic, copy, nullable) NSString *unit;
|
||||
/// 商品描述
|
||||
@property (nonatomic, copy, nullable) NSString *productDescription;
|
||||
/// 货币符号
|
||||
@property (nonatomic, copy, nullable) NSString *currency;
|
||||
/// 现价
|
||||
@property (nonatomic, assign) double price;
|
||||
/// 原价(如接口未返回,则回退为 price 的 1.25 倍)
|
||||
@property (nonatomic, assign) double originPrice;
|
||||
/// 有效期数值
|
||||
@property (nonatomic, assign) NSInteger durationValue;
|
||||
/// 有效期单位
|
||||
@property (nonatomic, copy, nullable) NSString *durationUnit;
|
||||
|
||||
/// 标题(描述 > name+unit > name > unit)
|
||||
- (NSString *)displayTitle;
|
||||
/// 当前价格文本
|
||||
- (NSString *)priceDisplayText;
|
||||
/// 划线价文本
|
||||
- (nullable NSString *)strikePriceDisplayText;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
55
CustomKeyboard/Model/KBKeyboardSubscriptionProduct.m
Normal file
55
CustomKeyboard/Model/KBKeyboardSubscriptionProduct.m
Normal file
@@ -0,0 +1,55 @@
|
||||
//
|
||||
// KBKeyboardSubscriptionProduct.m
|
||||
// CustomKeyboard
|
||||
//
|
||||
|
||||
#import "KBKeyboardSubscriptionProduct.h"
|
||||
#import <MJExtension/MJExtension.h>
|
||||
#import "KBLocalizationManager.h"
|
||||
|
||||
@implementation KBKeyboardSubscriptionProduct
|
||||
|
||||
+ (NSDictionary *)mj_replacedKeyFromPropertyName {
|
||||
return @{
|
||||
@"identifier": @"id",
|
||||
@"productDescription": @"description",
|
||||
};
|
||||
}
|
||||
|
||||
- (NSString *)displayTitle {
|
||||
if (self.productDescription.length > 0) {
|
||||
return self.productDescription;
|
||||
}
|
||||
NSString *name = self.name ?: @"";
|
||||
NSString *unit = self.unit ?: @"";
|
||||
if (name.length && unit.length) {
|
||||
return [NSString stringWithFormat:@"%@ %@", name, unit];
|
||||
}
|
||||
if (name.length) { return name; }
|
||||
if (unit.length) { return unit; }
|
||||
if (self.durationValue > 0 && self.durationUnit.length > 0) {
|
||||
return [NSString stringWithFormat:@"%ld %@", (long)self.durationValue, self.durationUnit];
|
||||
}
|
||||
return KBLocalized(@"Subscription");
|
||||
}
|
||||
|
||||
- (NSString *)priceDisplayText {
|
||||
double priceValue = self.price;
|
||||
if (priceValue <= 0) {
|
||||
return @"$0.00";
|
||||
}
|
||||
NSString *currency = self.currency.length ? self.currency : @"$";
|
||||
return [NSString stringWithFormat:@"%@%.2f", currency, priceValue];
|
||||
}
|
||||
|
||||
- (nullable NSString *)strikePriceDisplayText {
|
||||
double rawValue = self.originPrice;
|
||||
if (rawValue <= 0 && self.price > 0) {
|
||||
rawValue = self.price * 1.25;
|
||||
}
|
||||
if (rawValue <= 0) { return nil; }
|
||||
NSString *currency = self.currency.length ? self.currency : @"$";
|
||||
return [NSString stringWithFormat:@"%@%.2f", currency, rawValue];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user