Commit 5c5c8b12 by houweibin

1,更换图片Domain

2,调整图片链接处理方式(原:商品id=>图片链接   现:原cdn图片=>图片链接)
3,订单页面添加商品数据api请求(订单API没有返回cdn图片链接,需要请求数据拿到.)
parent 3c1a8678
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#import "KWMBaseModel.h" #import "KWMBaseModel.h"
//旧获取图片api所用到的modal,已废弃
@interface KWMImage : KWMBaseModel @interface KWMImage : KWMBaseModel
//服务器图片域名,与APP无关 //服务器图片域名,与APP无关
......
...@@ -13,16 +13,19 @@ ...@@ -13,16 +13,19 @@
@implementation KWMImage @implementation KWMImage
-(NSString *)getSmallImage{ -(NSString *)getSmallImage{
return [KWMImageUtil getProductImageUrl2:self.value ImageSize:SmallImage]; //return [KWMImageUtil getProductImageUrl2:self.value ImageSize:SmallImage];
return @"";
} }
-(NSString *)getNormalImage{ -(NSString *)getNormalImage{
return [KWMImageUtil getProductImageUrl2:self.value ImageSize:NormalImage]; //return [KWMImageUtil getProductImageUrl2:self.value ImageSize:NormalImage];
return @"";
} }
//200*200 //200*200
-(NSString *)getBigImage{ -(NSString *)getBigImage{
return [KWMImageUtil getProductImageUrl2:self.value ImageSize:BigImage]; //return [KWMImageUtil getProductImageUrl2:self.value ImageSize:BigImage];
return @"";
} }
......
...@@ -244,7 +244,7 @@ ...@@ -244,7 +244,7 @@
self.lbBrandLeft.text = leftDataProduct.vendor; self.lbBrandLeft.text = leftDataProduct.vendor;
} }
NSString *imageUrl = [KWMImageUtil getProductImageUrl:leftDataProduct.id ImageSize:NormalImage]; NSString *imageUrl = [KWMImageUtil getProductImageUrl:leftDataProduct ImageSize:NormalImage];
NSURL *imageURL = [NSURL URLWithString:imageUrl]; NSURL *imageURL = [NSURL URLWithString:imageUrl];
[self.ivIconLeft sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"ic_loading"]]; [self.ivIconLeft sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"ic_loading"]];
...@@ -262,7 +262,7 @@ ...@@ -262,7 +262,7 @@
if(self.isShowBrandTitle){ if(self.isShowBrandTitle){
self.lbBrandRight.text = rightDataProduct.vendor; self.lbBrandRight.text = rightDataProduct.vendor;
} }
NSString *imageUrl = [KWMImageUtil getProductImageUrl:rightDataProduct.id ImageSize:NormalImage]; NSString *imageUrl = [KWMImageUtil getProductImageUrl:rightDataProduct ImageSize:NormalImage];
NSURL *imageURL = [NSURL URLWithString:imageUrl]; NSURL *imageURL = [NSURL URLWithString:imageUrl];
[self.ivIconRight sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"ic_loading"]]; [self.ivIconRight sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"ic_loading"]];
...@@ -290,7 +290,7 @@ ...@@ -290,7 +290,7 @@
if(self.isShowBrandTitle){ if(self.isShowBrandTitle){
self.lbBrandLeft.text = leftProduct.vendor; self.lbBrandLeft.text = leftProduct.vendor;
} }
NSString *imageUrl = [KWMImageUtil getProductImageUrl:leftProduct.identifier ImageSize:NormalImage]; NSString *imageUrl = [KWMImageUtil getProductImageUrl:leftProduct ImageSize:NormalImage];
NSURL *imageURL = [NSURL URLWithString:imageUrl]; NSURL *imageURL = [NSURL URLWithString:imageUrl];
[self.ivIconLeft sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"ic_loading"]]; [self.ivIconLeft sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"ic_loading"]];
BUYProductVariant *productVariant = leftProduct.variants.firstObject; BUYProductVariant *productVariant = leftProduct.variants.firstObject;
...@@ -307,7 +307,7 @@ ...@@ -307,7 +307,7 @@
if(self.isShowBrandTitle){ if(self.isShowBrandTitle){
self.lbBrandRight.text = rightProduct.vendor; self.lbBrandRight.text = rightProduct.vendor;
} }
NSString *imageUrl = [KWMImageUtil getProductImageUrl:rightProduct.identifier ImageSize:NormalImage]; NSString *imageUrl = [KWMImageUtil getProductImageUrl:rightProduct ImageSize:NormalImage];
NSURL *imageURL = [NSURL URLWithString:imageUrl]; NSURL *imageURL = [NSURL URLWithString:imageUrl];
[self.ivIconRight sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"ic_loading"]]; [self.ivIconRight sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"ic_loading"]];
BUYProductVariant *productVariant= rightProduct.variants.firstObject; BUYProductVariant *productVariant= rightProduct.variants.firstObject;
......
...@@ -41,10 +41,11 @@ ...@@ -41,10 +41,11 @@
@property (weak, nonatomic) IBOutlet UILabel *lbTotalPrice; @property (weak, nonatomic) IBOutlet UILabel *lbTotalPrice;
@property (nonatomic) NSInteger allProduct; @property (nonatomic) NSInteger lineCount;
@property (nonatomic) NSInteger markSection; @property (nonatomic) NSInteger markSection;
@property (nonatomic) NSString *imageUrl;
@property(nonatomic,weak) id<KWMOrderCellDelegate> delegate; @property(nonatomic,weak) id<KWMOrderCellDelegate> delegate;
...@@ -52,7 +53,7 @@ ...@@ -52,7 +53,7 @@
@property (nonatomic) BUYOrder *order; @property (nonatomic) BUYOrder *order;
-(void)setData:(NSInteger)position productCount:(NSInteger)productCount showAll:(bool)showAll; -(void)updateUI:(NSInteger)position productCount:(NSInteger)productCount showAll:(bool)showAll;
-(IBAction)onClickShowOther:(id)sender; -(IBAction)onClickShowOther:(id)sender;
......
...@@ -40,9 +40,14 @@ ...@@ -40,9 +40,14 @@
_markSection = markSection; _markSection = markSection;
} }
- (void)setAllProduct:(NSInteger)allProduct{ - (void)setLineCount:(NSInteger)lineCount{
_allProduct = allProduct; _lineCount = lineCount;
[self.btnFooter setTitle:[NSString stringWithFormat:@"共%ld件商品,查看剩余%ld件商品",(long)allProduct,(allProduct - 4)] forState:UIControlStateNormal]; [self.btnFooter setTitle:[NSString stringWithFormat:@"共%ld件商品,查看剩余%ld件商品",(long)lineCount,(lineCount - 4)] forState:UIControlStateNormal];
}
- (void)setImageUrl:(NSString *)imageUrl{
NSURL *imageURL = [NSURL URLWithString:imageUrl];
[self.ivImage sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"ic_loading"]];
} }
- (void)setOrder:(BUYOrder *)order{ - (void)setOrder:(BUYOrder *)order{
...@@ -56,14 +61,9 @@ ...@@ -56,14 +61,9 @@
- (void)setLineItem:(BUYLineItem *)lineItem{ - (void)setLineItem:(BUYLineItem *)lineItem{
if (lineItem != nil) { if (lineItem != nil) {
_lineItem = lineItem; _lineItem = lineItem;
if(lineItem.productId!=nil){ self.lbPrice.text = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:lineItem.price]];
NSString *imageUrl = [KWMImageUtil getProductImageUrl:lineItem.productId ImageSize:NormalImage]; self.lbName.text = lineItem.title;
NSURL *imageURL = [NSURL URLWithString:imageUrl]; self.lbSize.text = [NSString stringWithFormat:@"x%@/%@",lineItem.quantity,lineItem.variantTitle];
[self.ivImage sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"ic_loading"]];
}
_lbPrice.text = [NSString stringWithFormat:@"¥%@",[KWMStringUtil getEUR2CNYstring:lineItem.price]];
_lbName.text = lineItem.title;
_lbSize.text = [NSString stringWithFormat:@"x%@/%@",lineItem.quantity,lineItem.variantTitle];
} }
} }
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
// Configure the view for the selected state // Configure the view for the selected state
} }
-(void)setData:(NSInteger)position productCount:(NSInteger)productCount showAll:(bool)showAll{ -(void)updateUI:(NSInteger)position productCount:(NSInteger)productCount showAll:(bool)showAll{
isShow = showAll;//记录是否展开 isShow = showAll;//记录是否展开
if(position == 0){ if(position == 0){
self.vHeader.hidden = NO; self.vHeader.hidden = NO;
...@@ -93,8 +93,8 @@ ...@@ -93,8 +93,8 @@
//设置展开收起的订单footerView的title //设置展开收起的订单footerView的title
if (!showAll && productCount > 4) { if (!showAll && productCount > 4) {
if (_allProduct) { if (self.lineCount) {
[self.btnFooter setTitle:[NSString stringWithFormat:@"共%ld件商品,查看剩余%ld件商品",(long)_allProduct,(_allProduct - 4)] forState:UIControlStateNormal]; [self.btnFooter setTitle:[NSString stringWithFormat:@"共%ld件商品,查看剩余%ld件商品",(long)self.lineCount,(self.lineCount - 4)] forState:UIControlStateNormal];
[self.btnFooter setImage:nil forState:UIControlStateNormal]; [self.btnFooter setImage:nil forState:UIControlStateNormal];
} }
}else if(showAll && productCount > 4){ }else if(showAll && productCount > 4){
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
@interface KWMOrderVC () @interface KWMOrderVC ()
@property (nonatomic) NSMutableArray<BUYOrder *> *orderList;//订单列表 @property (nonatomic) NSMutableArray<BUYOrder *> *orderList;//订单列表
@property (nonatomic) NSMutableArray *iconList;//订单商品列表 @property (nonatomic) NSMutableArray *productList;//订单商品列表
@end @end
...@@ -36,7 +36,8 @@ ...@@ -36,7 +36,8 @@
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
// Do any additional setup after loading the view. // Do any additional setup after loading the view.
_orderList = [NSMutableArray array]; self.orderList = [NSMutableArray array];
self.productList = [NSMutableArray array];
sectionArr = [NSMutableArray array]; sectionArr = [NSMutableArray array];
[self requestOrderAPI]; [self requestOrderAPI];
} }
...@@ -46,42 +47,26 @@ ...@@ -46,42 +47,26 @@
// Dispose of any resources that can be recreated. // Dispose of any resources that can be recreated.
} }
//获取订单API
- (void)requestOrderAPI{
[self showLoading];
self.client.customerToken = [BUYCustomerToken customerTokenWithJSONDictionary:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"]];
[self.client getOrdersForCustomerCallback:^(NSArray<BUYOrder *> * _Nullable orders, NSError * _Nullable error) {
[self hideLoading];
if (error == nil && orders != nil ) {
[_orderList removeAllObjects];
[_orderList addObjectsFromArray:orders];
[_tbvOrder reloadData];
}else if (error != nil){
[self showError:error];
}
}];
}
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{ - (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
return _orderList.count; return self.orderList.count;
} }
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
BUYOrder *order = [_orderList objectAtIndex:section]; BUYOrder *order = [self.orderList objectAtIndex:section];
NSArray<BUYLineItem *> *lineItems = [order.lineItems array]; NSArray<BUYLineItem *> *lineItems = [order.lineItems array];
bool isShowOther = [sectionArr containsObject:[NSString stringWithFormat:@"%ld",(long)section]]; bool isShowOther = [sectionArr containsObject:[NSString stringWithFormat:@"%ld",(long)section]];
if(!lineItems){ if(!lineItems){
return 0; return 0;
} }
if(!isShowOther && lineItems.count >= 4){ if(!isShowOther && lineItems.count >= 4){
return 4; return 4;
} }
return lineItems.count; return lineItems.count;
} }
//每一个section有多少行 //每一个section有多少行
- (NSInteger)returnSectionRow:(NSInteger)section{ - (NSInteger)returnSectionRow:(NSInteger)section{
BUYOrder *order = [_orderList objectAtIndex:section]; BUYOrder *order = [self.orderList objectAtIndex:section];
NSArray<BUYLineItem *> *arr = [order.lineItems array]; NSArray<BUYLineItem *> *arr = [order.lineItems array];
return arr?arr.count:0; return arr?arr.count:0;
} }
...@@ -122,7 +107,7 @@ ...@@ -122,7 +107,7 @@
orderCell.markSection = indexPath.section; orderCell.markSection = indexPath.section;
bool isShowOther = [sectionArr containsObject:[NSString stringWithFormat:@"%ld",(long)indexPath.section]]; bool isShowOther = [sectionArr containsObject:[NSString stringWithFormat:@"%ld",(long)indexPath.section]];
BUYOrder *order = [_orderList objectAtIndex:indexPath.section]; BUYOrder *order = [self.orderList objectAtIndex:indexPath.section];
NSArray<BUYLineItem *> *arr = [order.lineItems array]; NSArray<BUYLineItem *> *arr = [order.lineItems array];
if(!arr){ if(!arr){
return orderCell; return orderCell;
...@@ -131,11 +116,12 @@ ...@@ -131,11 +116,12 @@
BUYLineItem *lineItem = [arr objectAtIndex:indexPath.row]; BUYLineItem *lineItem = [arr objectAtIndex:indexPath.row];
orderCell.lineItem = lineItem; orderCell.lineItem = lineItem;
//当前section行数 //当前section行数
orderCell.allProduct = [self returnSectionRow:indexPath.section]; orderCell.lineCount = [self returnSectionRow:indexPath.section];
orderCell.order = [_orderList objectAtIndex:indexPath.section]; orderCell.order = [self.orderList objectAtIndex:indexPath.section];
orderCell.markSection = indexPath.section; orderCell.markSection = indexPath.section;
orderCell.imageUrl = [self getProductImage:lineItem.productId];
[orderCell setData:indexPath.row productCount:arr.count showAll:isShowOther]; [orderCell updateUI:indexPath.row productCount:arr.count showAll:isShowOther];
orderCell.delegate = self; orderCell.delegate = self;
return orderCell; return orderCell;
} }
...@@ -168,6 +154,108 @@ ...@@ -168,6 +154,108 @@
} }
} }
-(NSString *)getProductImage:(NSNumber *)productId{
NSString *productImage = @"";
if(productId){
for(BUYProduct *product in self.productList){
if([product.identifier isEqualToNumber:productId]){
productImage = [KWMImageUtil getProductImageUrl:product ImageSize:LowImage];
if([product.identifier isEqualToNumber:@9690154060]){
NSLog(@"11111111%@",@"lalal");
}
}
}
}
return productImage;
}
-(BOOL)isContainId:(NSArray *)productIds productId:(NSNumber *)productId{
for(NSNumber *mProductId in productIds){
if([mProductId isEqualToNumber:productId]){
return YES;
}
}
return NO;
}
-(NSArray *)splitArray:(NSArray *)array withSubSize:(NSInteger)subSize{
//拆分后的数组个数
NSInteger count = array.count % subSize == 0?(array.count /subSize): (array.count / subSize + 1);
NSMutableArray *arr = [NSMutableArray array];
for (int i = 0; i < count; i ++) {
//数组下标
NSInteger index = i * subSize;
//保存拆分的固定长度的数组元素的可变数组
NSMutableArray *arr1 = [[NSMutableArray alloc] init];
//移除子数组的所有元素
[arr1 removeAllObjects];
NSInteger j = index;
//将数组下标乘以1、2、3,得到拆分时数组的最大下标值,但最大不能超过数组的总大小
while (j < subSize*(i + 1) && j < array.count) {
[arr1 addObject:[array objectAtIndex:j]];
j += 1;
}
//将子数组添加到保存子数组的数组中
[arr addObject:[arr1 copy]];
}
return [arr copy];
}
//获取订单API
- (void)requestOrderAPI{
[self showLoading];
__weak KWMOrderVC *weakSelf = self;
self.client.customerToken = [BUYCustomerToken customerTokenWithJSONDictionary:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"]];
[self.client getOrdersForCustomerCallback:^(NSArray<BUYOrder *> * _Nullable orders, NSError * _Nullable error) {
[weakSelf hideLoading];
if (error == nil && orders != nil ) {
[weakSelf.orderList removeAllObjects];
[weakSelf.orderList addObjectsFromArray:orders];
[weakSelf.tbvOrder reloadData];
[weakSelf requestProductsApi];
}else if (error != nil){
[weakSelf showError:error];
}
}];
}
//获取订单商品列表,从而拿到图片(因为订单api返回的订单数据中没有商品图片数据)
-(void)requestProductsApi{
if(!self.orderList){
return;
}
NSMutableArray *productIds = [NSMutableArray array];
for(BUYOrder *order in self.orderList){
NSArray *lineItems = order.lineItemsArray;
if(lineItems){
for(BUYLineItem *lineItem in lineItems){
//当该商品被删除后,productId有可能为空
if(lineItem.productId && ![self isContainId:productIds productId:lineItem.productId]){
[productIds addObject:lineItem.productId];
}
}
}
}
if(productIds.count == 0){
return;
}
__weak KWMOrderVC *weakSelf = self;
NSArray *productIdsArray = [self splitArray:productIds withSubSize:50];
for(NSArray *mProductIds in productIdsArray){
//经过测试,该api一次最多返回50个product,所以如果有100个商品,需要分成两次请求
[self.client getProductsByIds:mProductIds completion:^(NSArray<BUYProduct *> * _Nullable products, NSError * _Nullable error) {
if (!error && products != nil && products.count>0) {
[weakSelf.productList addObjectsFromArray:products];
[weakSelf.tbvOrder reloadData];
}else if (error != nil){
[weakSelf showError:error];
}
}];
}
}
-(void)requestCancelOrder:(NSNumber *)orderId{ -(void)requestCancelOrder:(NSNumber *)orderId{
if(orderId == nil){ if(orderId == nil){
return; return;
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
if(product!=nil){ if(product!=nil){
self.product = product; self.product = product;
self.lbBrand.text = product.title; self.lbBrand.text = product.title;
NSString *imageUrl = [KWMImageUtil getProductImageUrl:product.identifier ImageSize:SmallImage]; NSString *imageUrl = [KWMImageUtil getProductImageUrl:product ImageSize:SmallImage];
NSURL *imageURL = [NSURL URLWithString:imageUrl]; NSURL *imageURL = [NSURL URLWithString:imageUrl];
[self.ivCollectionCell sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"ic_loading"]]; [self.ivCollectionCell sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"ic_loading"]];
......
...@@ -148,7 +148,7 @@ ...@@ -148,7 +148,7 @@
imageView.tag = i; imageView.tag = i;
imageView.contentMode = UIViewContentModeScaleAspectFit; imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.clipsToBounds = YES; imageView.clipsToBounds = YES;
NSString *imageUrl = [KWMImageUtil getProductImageUrl3:self.product.identifier ImageSize:BigImage Position:(i+1)]; NSString *imageUrl = [KWMImageUtil getProductImageUrlByPosition:self.product ImageSize:BigImage Position:i];
[self.imageArr addObject:imageUrl]; [self.imageArr addObject:imageUrl];
NSURL *imageURL = [NSURL URLWithString:imageUrl]; NSURL *imageURL = [NSURL URLWithString:imageUrl];
UITapGestureRecognizer *imageTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onClickImage:)]; UITapGestureRecognizer *imageTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onClickImage:)];
......
...@@ -305,7 +305,7 @@ static NSString * idStr = @"KWMDetailCell"; ...@@ -305,7 +305,7 @@ static NSString * idStr = @"KWMDetailCell";
vWatch.tagId = i; vWatch.tagId = i;
vWatch.delegate = self; vWatch.delegate = self;
[self.sclDetail addSubview:vWatch]; [self.sclDetail addSubview:vWatch];
NSString *imageUrl = [KWMImageUtil getProductImageUrl3:self.product.identifier ImageSize:BigImage Position:(i+1)]; NSString *imageUrl = [KWMImageUtil getProductImageUrlByPosition:self.product ImageSize:BigImage Position:i];
[vWatch setImage:imageUrl]; [vWatch setImage:imageUrl];
[_imageArr addObject:imageUrl]; [_imageArr addObject:imageUrl];
} }
......
...@@ -120,7 +120,7 @@ ...@@ -120,7 +120,7 @@
CGSize size = [UIScreen mainScreen].bounds.size; CGSize size = [UIScreen mainScreen].bounds.size;
[self showPresentation:shareVC size:size tapOutsideClose:YES style:MZFormSheetPresentationTransitionStyleFade]; [self showPresentation:shareVC size:size tapOutsideClose:YES style:MZFormSheetPresentationTransitionStyleFade];
shareVC.shareUrl = [NSString stringWithFormat:@"https://www.cemarose.com/products/%@",self.product.handle]; shareVC.shareUrl = [NSString stringWithFormat:@"https://www.cemarose.com/products/%@",self.product.handle];
shareVC.imageUrl = [KWMImageUtil getProductImageUrl3:self.product.identifier ImageSize:SmallImage Position:1]; shareVC.imageUrl = [KWMImageUtil getProductImageUrl:self.product ImageSize:SmallImage];
shareVC.productName = self.product.title; shareVC.productName = self.product.title;
} }
......
...@@ -169,7 +169,7 @@ ...@@ -169,7 +169,7 @@
_shopCartModel.name = _product.title; _shopCartModel.name = _product.title;
_shopCartModel.brand = _product.vendor; _shopCartModel.brand = _product.vendor;
NSString *imageUrl = [KWMImageUtil getProductImageUrl:_product.identifier ImageSize:NormalImage]; NSString *imageUrl = [KWMImageUtil getProductImageUrl:_product ImageSize:NormalImage];
_shopCartModel.imageStr = imageUrl; _shopCartModel.imageStr = imageUrl;
_shopCartModel.shopCartDict = _product.JSONDictionary; _shopCartModel.shopCartDict = _product.JSONDictionary;
......
...@@ -44,10 +44,15 @@ ...@@ -44,10 +44,15 @@
//传入图片需为kwmimage类型 //传入图片需为kwmimage类型
+ (NSArray *)checkImage:(NSArray *)imagesArray; + (NSArray *)checkImage:(NSArray *)imagesArray;
+ (NSString *)getProductImageUrl:(NSNumber *)productId ImageSize:(NSInteger)ImageSize; //获取商品图片列表
+ (NSArray *)getProductImageUrls:(id)product ImageSize:(NSInteger)ImageSize;
//获取商品首张图片
+ (NSString *)getProductImageUrl:(id)product ImageSize:(NSInteger)ImageSize;
//获取商品第(position+1)张图片
+ (NSString *)getProductImageUrlByPosition:(NSNumber *)productId ImageSize:(NSInteger)ImageSize Position:(NSInteger)Position;
+ (NSString *)getProductImageUrl2:(NSString *)content ImageSize:(NSInteger)ImageSize;
+ (NSString *)getProductImageUrl3:(NSNumber *)productId ImageSize:(NSInteger)ImageSize Position:(NSInteger)Position;
@end @end
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "KWMImageUtil.h" #import "KWMImageUtil.h"
#import "KWMStringUtil.h" #import "KWMStringUtil.h"
#import "Buy/Buy.h"
@implementation KWMImageUtil { @implementation KWMImageUtil {
...@@ -147,88 +148,117 @@ ...@@ -147,88 +148,117 @@
} }
+ (NSString *)getProductImageUrl:(NSNumber *)productId ImageSize:(NSInteger)ImageSize{ +(NSArray *)getOriginalImages1:(BUYProduct *)product{
if(productId == nil){ NSMutableArray *productImages = [[NSMutableArray alloc]init];
return nil; if(!product){
return productImages;
} }
NSArray *imageLinks = product.imagesArray;
//https://og95hd6ay.qnssl.com/5411820230-1.jpg if(!imageLinks || imageLinks.count == 0){
NSString *domain = Image_Domain; return productImages;
NSString *imageUrl = [NSString stringWithFormat:@"https://%@/%@-1.jpg",domain,productId.stringValue]; }
NSLog(@"1-----%@", imageUrl); for(BUYImageLink *imageLink in imageLinks){
if(ImageSize == BigImage){ NSString *productImage = [imageLink.sourceURL.absoluteString stringByReplacingOccurrencesOfString:@"cdn.shopify.com" withString:@"o42yton8r.qnssl.com"];
return [self getImage:1080 height:1080 image:imageUrl]; [productImages addObject:productImage];
}else if(ImageSize == SmallImage){
return [self getImage:300 height:300 image:imageUrl];
}else{
return [self getImage:500 height:500 image:imageUrl];
} }
return productImages;
} }
//content:5411820230-1.jpg 商品详细获取图片的方法
+ (NSString *)getProductImageUrl2:(NSString *)content ImageSize:(NSInteger)ImageSize{ +(NSArray *)getOriginalImages2:(KWMDataProduct *)product{
if([KWMStringUtil isEmpty:content]){ NSMutableArray *productImages = [[NSMutableArray alloc]init];
return nil; if(!product){
return productImages;
} }
NSArray *imageLinks = product.images;
//https://og95hd6ay.qnssl.com/5411820230-1.jpg if(!imageLinks || imageLinks.count == 0){
NSString *domain = Image_Domain; return productImages;
NSString *imageUrl = [NSString stringWithFormat:@"https://%@/%@",domain,content];
NSLog(@"2-----%@", imageUrl);
if(ImageSize == BigImage){
return [self getImage:1000 height:1000 image:imageUrl];
}else if(ImageSize == SmallImage){
return [self getImage:300 height:300 image:imageUrl];
}else{
return [self getImage:500 height:500 image:imageUrl];
} }
for(NSDictionary *imageLink in imageLinks){
if(imageLink[@"src"]){
NSString *originalImage = imageLink[@"src"];
NSString *productImage = [originalImage stringByReplacingOccurrencesOfString:@"cdn.shopify.com" withString:Image_Domain];
[productImages addObject:productImage];
}
}
return productImages;
} }
+ (NSString *)getProductImageUrl3:(NSNumber *)productId ImageSize:(NSInteger)ImageSize Position:(NSInteger)Position{
if(productId == nil){ +(NSArray *)getImageArrayBySize:(id)product ImageSize:(NSInteger)ImageSize{
return nil; NSArray *imageArray = nil;
if([product isKindOfClass:[BUYProduct class]]){
imageArray = [self getOriginalImages1:product];
} }
//https://og95hd6ay.qnssl.com/5411820230-1.jpg if([product isKindOfClass:[KWMDataProduct class]]){
NSString *domain = Image_Domain; imageArray = [self getOriginalImages2:product];
NSString *imageUrl = [NSString stringWithFormat:@"https://%@/%@-%ld.jpg",domain,productId.stringValue,(long)Position]; }
NSLog(@"3-----%@", imageUrl); NSMutableArray *newImageArray = [[NSMutableArray alloc]init];
//https://cdn.shopify.com/s/files/1/1089/5284/products/5413_1.jpg?v==1459708223 转换为
//https://o42yton8r.qnssl.com/s/files/1/1089/5284/products/5413_1.jpg?imageView2/1/w/300/h/300/v==1459708223
if(imageArray && imageArray.count>0){
for(NSString *imageUrl in imageArray){
NSRange startRange = [imageUrl rangeOfString:@"?"];
if (startRange.location != NSNotFound) {
NSMutableString* newImageUrl=[[NSMutableString alloc]initWithString:imageUrl];
NSArray<NSString *> *imageWH = [self getImageWH:ImageSize];
NSString *size = [NSString stringWithFormat:@"imageView2/1/w/%@/h/%@/",imageWH[0],imageWH[1]];
[newImageUrl insertString:size atIndex:startRange.location+1];
[newImageArray addObject:newImageUrl];
}
}
}
return newImageArray;
}
+(NSArray *)getImageWH:(NSInteger)ImageSize{
if(ImageSize == BigImage){ if(ImageSize == BigImage){
return [self getImage:1080 height:1080 image:imageUrl]; return @[@"1000", @"1000"];
}else if(ImageSize == SmallImage){ }else if(ImageSize == SmallImage){
return [self getImage:300 height:300 image:imageUrl]; return @[@"300", @"300"];
}else if(ImageSize == LowImage){
return @[@"150", @"150"];
}else{ }else{
return [self getImage:500 height:500 image:imageUrl]; return @[@"500", @"500"];
} }
} }
+(NSString *)getImage:(NSInteger)width height:(NSInteger)height image:(NSString*)image{ + (NSArray *)getProductImageUrls:(id)product ImageSize:(NSInteger)ImageSize{
NSArray *imageUrls = nil;
if(product){
imageUrls = [self getImageArrayBySize:product ImageSize:ImageSize];
}
return nil;
}
+ (NSString *)getProductImageUrl:(id)product ImageSize:(NSInteger)ImageSize{
NSString *imageUrl = @""; NSString *imageUrl = @"";
if(product){
// NSArray *imageArray = [self getImageArrayBySize:product ImageSize:ImageSize];
// NSCalendar *calendar = [NSCalendar currentCalendar]; if(imageArray && imageArray.count>0){
// NSDate *now = [NSDate date]; imageUrl = imageArray.firstObject;
// NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:now]; }
// NSDate *startDate = [calendar dateFromComponents:components];
// long long time = [startDate timeIntervalSince1970];
if([KWMStringUtil isEmpty:image]){
return imageUrl;
} }
if([product isKindOfClass:[BUYProduct class]]){
NSDateFormatter *dateformat = [[NSDateFormatter alloc] init]; BUYProduct *aaa = (BUYProduct *)product;
[dateformat setDateFormat:@"YYYY-MM-dd"];
NSString *today = [dateformat stringFromDate:[NSDate date]];
[dateformat setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSDate *date = [dateformat dateFromString:[NSString stringWithFormat:@"%@ 00:00:00",today]];
NSTimeInterval interval = [date timeIntervalSince1970]/100;
long long time = interval;
imageUrl = [[NSString alloc] initWithFormat:@"%@?imageView2/1/w/%ld/h/%ld&_=%llu",image,(long)width,(long)height,time];
NSLog(@"---4--%@", imageUrl);
}
return imageUrl; return imageUrl;
} }
+ (NSString *)getProductImageUrlByPosition:(id)product ImageSize:(NSInteger)ImageSize Position:(NSInteger)Position{
NSString *imageUrl = @"";
if(product){
NSArray *imageArray = [self getImageArrayBySize:product ImageSize:ImageSize];
if(imageArray && imageArray.count>Position){
return imageArray[Position];
}
}
return imageUrl;
}
@end @end
...@@ -83,7 +83,9 @@ ...@@ -83,7 +83,9 @@
#define ALPHA @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" #define ALPHA @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
#define ALPHANUM @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" #define ALPHANUM @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
#define Image_Domain @"og95hd6ay.qnssl.com" #define Image_Domain @"o42yton8r.qnssl.com"
#define LowImage 0
#define SmallImage 1 #define SmallImage 1
...@@ -91,8 +93,8 @@ ...@@ -91,8 +93,8 @@
#define BigImage 3 #define BigImage 3
//1欧元等于7.2699人民币 2017年02月27日 //默认欧元汇率,如果安装后第一次请求最新汇率数据失败,会使用该汇率显示价格
#define ExchangeRate 7.2699 #define ExchangeRate 7.6625
//品牌图片url //品牌图片url
#define Burberry @"https://cdn.shopify.com/s/files/1/1089/5284/collections/Burberry_Childrenswear_Campaign_July_2016_001.jpg?v=1473238213" #define Burberry @"https://cdn.shopify.com/s/files/1/1089/5284/collections/Burberry_Childrenswear_Campaign_July_2016_001.jpg?v=1473238213"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment