Commit 3a578a82 authored by 曹云霄's avatar 曹云霄

修改项说明:完成微信卡劵促销,完成促销优先级,完成促销冲突判定

parent 2cda6688
...@@ -11,6 +11,10 @@ ...@@ -11,6 +11,10 @@
#import "ShopcarModel.h" #import "ShopcarModel.h"
#import "PromotionalDeductionModel.h" #import "PromotionalDeductionModel.h"
#import "PromotionalGoodsModel.h" #import "PromotionalGoodsModel.h"
#import "PromotionLuckyDrawModel.h"
#import "PromotionalGoodsModel.h"
#import "PromotionalDeductionModel.h"
#import "PromotionWeChatCardModel.h"
@interface AllpriceTableViewCell : UITableViewCell @interface AllpriceTableViewCell : UITableViewCell
...@@ -48,4 +52,10 @@ ...@@ -48,4 +52,10 @@
*/ */
@property (nonatomic,copy) NSArray *promotionalArray; @property (nonatomic,copy) NSArray *promotionalArray;
/**
微信卡劵
*/
@property (nonatomic,strong) WeChatCardModel *weChatModel;
@end @end
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#import "AllpriceTableViewCell.h" #import "AllpriceTableViewCell.h"
@implementation AllpriceTableViewCell @implementation AllpriceTableViewCell
- (void)awakeFromNib { - (void)awakeFromNib {
...@@ -36,42 +37,114 @@ ...@@ -36,42 +37,114 @@
_goodsArray = goodsArray; _goodsArray = goodsArray;
NSInteger allNumber = 0;//总数量 NSInteger allNumber = 0;//总数量
CGFloat allPrice = 0;//总价格 CGFloat allPrice = 0;//总价格
CGFloat newPrice = 0;//折后价格 NSDictionary *deductionPrice = nil;//抵扣金额
CGFloat deductionPrice = 0;//抵扣金额 NSDictionary *weChatPrice = nil;//微信卡劵
NSDictionary *drawPrice = nil;//转盘抽奖
for (TOOrderdetailEntity *model in _goodsArray) { for (TOOrderdetailEntity *model in _goodsArray) {
allNumber += [model.goodsNum integerValue]; allNumber += [model.goodsNum integerValue];
allPrice += [model.goodsPrice floatValue]*[model.goodsNum intValue]; allPrice += [model.goodsPrice floatValue]*[model.goodsNum floatValue];
} }
newPrice = allPrice; //促销列表
// 抽奖折扣 for (JSONModel *model in self.promotionalArray) {
if (![BaseViewController isBlankString:self.model.number]) { //微信卡劵
newPrice = allPrice * ([self.model.number integerValue]/100.0); if ([model isMemberOfClass:[PromotionWeChatCardModel class]]) {
PromotionWeChatCardModel *newWeChatModel = (PromotionWeChatCardModel *)model;
weChatPrice = @{@"price":[NSString stringWithFormat:@"%ld",self.weChatModel.wxcardDenomation],@"priority":@(newWeChatModel.priority)};
}else if ([model isMemberOfClass:[PromotionalDeductionModel class]]) {
//抵扣
PromotionalDeductionModel *deductionModel = (PromotionalDeductionModel *)model;
deductionPrice = @{@"price":[NSString stringWithFormat:@"%ld",deductionModel.total],@"priority":@(deductionModel.priority)};
}else if ([model isMemberOfClass:[PromotionLuckyDrawModel class]]) {
//抽奖
PromotionLuckyDrawModel *drawModel = (PromotionLuckyDrawModel *)model;
drawPrice = @{@"price":[NSString stringWithFormat:@"%@",self.model.number],@"priority":@(drawModel.priority)};
}else if ([model isMemberOfClass:[PromotionalGoodsModel class]]) {
//送商品
// PromotionalGoodsModel *goodsModel = (PromotionalGoodsModel *)model;
} }
// 全局抵扣
for (id object in self.promotionalArray) {
if ([object isKindOfClass:[PromotionalDeductionModel class]]) {
PromotionalDeductionModel *model = (PromotionalDeductionModel *)object;
if ([model.type isEqualToString:@"deductionAction"] && model.isSelected) {
deductionPrice = model.total;
} }
NSString *goodsAllPriceString = [self promotionSorting:deductionPrice andWeChatPrice:weChatPrice andDrawPrice:drawPrice andAllPrice:allPrice];
self.goodsAllNumber.text = [NSString stringWithFormat:@"%ld",allNumber];
self.goodsAllPrice.text = goodsAllPriceString;
}
#pragma mark - 通过优先级排列促销项
- (NSString *)promotionSorting:(NSDictionary *)deductionPrice andWeChatPrice:(NSDictionary *)weChatPrice andDrawPrice:(NSDictionary *)drawPrice andAllPrice:(CGFloat)allPrice
{
NSMutableArray *array = [NSMutableArray array];
if (deductionPrice) {
[array addObject:deductionPrice];
} }
if (weChatPrice) {
[array addObject:weChatPrice];
} }
NSString *goodsAllPriceString = nil; if (drawPrice) {
if (deductionPrice && newPrice != allPrice) { [array addObject:drawPrice];
goodsAllPriceString = [NSString stringWithFormat:@"¥%.2f (%.2f x %@ - %.2f)",newPrice-deductionPrice,allPrice,self.model.descriptionString,deductionPrice]; }
//安装权限降序排列
}else if (newPrice == allPrice && !deductionPrice){ NSArray *chooseArray = [array sortedArrayUsingComparator:^NSComparisonResult(NSDictionary *obj1, NSDictionary *obj2) {
goodsAllPriceString = [NSString stringWithFormat:@"¥%.2f",newPrice]; if (obj1[@"priority"] < obj2[@"priority"]) {
return NSOrderedAscending;
}
if (obj1[@"priority"] < obj2[@"priority"]) {
return NSOrderedDescending;
}
return NSOrderedSame;
}];
//计算促销后的价格
CGFloat newPrice = allPrice;
NSMutableString *priceString = [NSMutableString string];
for (NSDictionary *dict in chooseArray) {
if ([dict isEqual:deductionPrice]) {
CGFloat deduction = [dict[@"price"] floatValue];
newPrice = newPrice - deduction;
[priceString appendString:[NSString stringWithFormat:@" - %.2f",deduction]];
}else if (newPrice == allPrice && deductionPrice){ }else if ([dict isEqual:weChatPrice]){
goodsAllPriceString = [NSString stringWithFormat:@"¥%.2f (%.2f - %.2f)",newPrice-deductionPrice,allPrice,deductionPrice]; CGFloat weChat = [dict[@"price"] floatValue];
newPrice = newPrice - weChat;
[priceString appendString:[NSString stringWithFormat:@" - %.2f",weChat]];
}else if (newPrice != allPrice && !deductionPrice){ }else if ([dict isEqual:drawPrice]){
goodsAllPriceString = [NSString stringWithFormat:@"¥%.2f (%.2f x %@)",newPrice-deductionPrice,allPrice,self.model.descriptionString]; CGFloat draw = [self.model.number floatValue]/100.0;
newPrice = newPrice * draw;
[priceString appendString:[NSString stringWithFormat:@" x %@",self.model.descriptionString]];
} }
self.goodsAllNumber.text = [NSString stringWithFormat:@"%ld",allNumber]; }
self.goodsAllPrice.text = goodsAllPriceString; //判断促销是否为空
if (chooseArray.count) {
if (newPrice < 0) {
newPrice = 0;
}
[priceString insertString:[NSString stringWithFormat:@"¥%.2f(%.2f",newPrice,allPrice] atIndex:0];
[priceString appendString:@")"];
}else{
priceString = [NSMutableString stringWithString:[NSString stringWithFormat:@"¥%.2f",allPrice]];
}
return priceString;
} }
@end @end
//
// OrderdetailsViewController.m // OrderdetailsViewController.m
// Lighting // Lighting
// //
...@@ -73,10 +73,6 @@ NSString *const PROMOTIONALSTRING = @"促销信息"; ...@@ -73,10 +73,6 @@ NSString *const PROMOTIONALSTRING = @"促销信息";
*/ */
@property (nonatomic,strong) NSMutableArray *customerPromotionArray; @property (nonatomic,strong) NSMutableArray *customerPromotionArray;
/**
消费者促销列表<原始>
*/
@property (nonatomic,strong) NSMutableArray *originalCustomerPromotionArray;
/** /**
微信卡劵 微信卡劵
...@@ -85,19 +81,12 @@ NSString *const PROMOTIONALSTRING = @"促销信息"; ...@@ -85,19 +81,12 @@ NSString *const PROMOTIONALSTRING = @"促销信息";
@end @end
@implementation OrderdetailsViewController @implementation OrderdetailsViewController
#pragma mark - lazy #pragma mark - lazy
- (NSMutableArray *)originalCustomerPromotionArray
{
if (!_originalCustomerPromotionArray) {
_originalCustomerPromotionArray = [NSMutableArray array];
}
return _originalCustomerPromotionArray;
}
- (NSMutableArray *)sectionTitle - (NSMutableArray *)sectionTitle
{ {
if (!_sectionTitle) { if (!_sectionTitle) {
...@@ -166,14 +155,14 @@ NSString *const PROMOTIONALSTRING = @"促销信息"; ...@@ -166,14 +155,14 @@ NSString *const PROMOTIONALSTRING = @"促销信息";
{ {
self.orderDetailsTableview.dataSource = self; self.orderDetailsTableview.dataSource = self;
self.orderDetailsTableview.delegate = self; self.orderDetailsTableview.delegate = self;
if (self.isShowHeaderView) {
[self CreateTableviewHeaderView];
}
//附加信息cell //附加信息cell
[self.orderDetailsTableview registerNib:[UINib nibWithNibName:@"AdditionalTableViewCell" bundle:nil] forCellReuseIdentifier:@"fifthcell"]; [self.orderDetailsTableview registerNib:[UINib nibWithNibName:@"AdditionalTableViewCell" bundle:nil] forCellReuseIdentifier:@"fifthcell"];
if (self.isShowPayButton) { if (self.isShowPayButton) {
[self CreateTableviewFooterView]; [self CreateTableviewFooterView];
} }
if (self.isShowHeaderView) {
[self CreateTableviewHeaderView];
}
} }
...@@ -211,33 +200,29 @@ NSString *const PROMOTIONALSTRING = @"促销信息"; ...@@ -211,33 +200,29 @@ NSString *const PROMOTIONALSTRING = @"促销信息";
dispatch_group_leave(group); dispatch_group_leave(group);
[weakSelf RemoveMBProgressHUDLoding]; [weakSelf RemoveMBProgressHUDLoding];
if ([returnValue[@"code"] isEqualToNumber:@0]) { if ([returnValue[@"code"] isEqualToNumber:@0]) {
[weakSelf.promotionInformationArray removeAllObjects];
NSArray *promotionalArray = returnValue[@"data"][@"actions"]; NSArray *promotionalArray = returnValue[@"data"][@"actions"];
for (NSDictionary *dict in promotionalArray) { for (NSDictionary *dict in promotionalArray) {
NSString *type = dict[@"type"]; NSString *type = dict[@"type"];
// 折扣金额 // 折扣金额
if ([type isEqualToString:deductionAction]) { if ([type isEqualToString:deductionAction]) {
PromotionalDeductionModel *deductionModel = [[PromotionalDeductionModel alloc]initWithDictionary:dict error:nil]; PromotionalDeductionModel *deductionModel = [[PromotionalDeductionModel alloc]initWithDictionary:dict error:nil];
[weakSelf.originalCustomerPromotionArray addObject:deductionModel];
[weakSelf getConsumerAllPromotion:deductionModel withBody:deductionModel.body]; [weakSelf getConsumerAllPromotion:deductionModel withBody:deductionModel.body];
// 赠送商品 // 赠送商品
}else if ([type isEqualToString:goodsAction]){ }else if ([type isEqualToString:goodsAction]){
PromotionalGoodsModel *goodsModel = [[PromotionalGoodsModel alloc]initWithDictionary:dict error:nil]; PromotionalGoodsModel *goodsModel = [[PromotionalGoodsModel alloc]initWithDictionary:dict error:nil];
[weakSelf.originalCustomerPromotionArray addObject:goodsModel];
[weakSelf getConsumerAllPromotion:goodsModel withBody:goodsModel.body]; [weakSelf getConsumerAllPromotion:goodsModel withBody:goodsModel.body];
// 京东E卡 // 京东E卡
}else if ([type isEqualToString:JDECardAction]){ }else if ([type isEqualToString:JDECardAction]){
PromotionJDECardModel *JDECardModel = [[PromotionJDECardModel alloc]initWithDictionary:dict error:nil]; PromotionJDECardModel *JDECardModel = [[PromotionJDECardModel alloc]initWithDictionary:dict error:nil];
[weakSelf.originalCustomerPromotionArray addObject:JDECardModel];
[weakSelf getConsumerAllPromotion:JDECardModel withBody:JDECardModel.body]; [weakSelf getConsumerAllPromotion:JDECardModel withBody:JDECardModel.body];
// 转盘抽奖 // 转盘抽奖
}else if ([type isEqualToString:lotteryAction]){ }else if ([type isEqualToString:lotteryAction]){
PromotionLuckyDrawModel *drawModel = [[PromotionLuckyDrawModel alloc]initWithDictionary:dict error:nil]; PromotionLuckyDrawModel *drawModel = [[PromotionLuckyDrawModel alloc]initWithDictionary:dict error:nil];
[weakSelf.originalCustomerPromotionArray addObject:drawModel];
[weakSelf getConsumerAllPromotion:drawModel withBody:drawModel.body]; [weakSelf getConsumerAllPromotion:drawModel withBody:drawModel.body];
}else if ([type isEqualToString:WeChatCard]){ }else if ([type isEqualToString:WeChatCard]){
// 微信卡劵 // 微信卡劵
PromotionWeChatCardModel *weChatModel = [[PromotionWeChatCardModel alloc]initWithDictionary:dict error:nil]; PromotionWeChatCardModel *weChatModel = [[PromotionWeChatCardModel alloc]initWithDictionary:dict error:nil];
[weakSelf.originalCustomerPromotionArray addObject:weChatModel];
[weakSelf getConsumerAllPromotion:weChatModel withBody:weChatModel.body]; [weakSelf getConsumerAllPromotion:weChatModel withBody:weChatModel.body];
} }
} }
...@@ -264,7 +249,6 @@ NSString *const PROMOTIONALSTRING = @"促销信息"; ...@@ -264,7 +249,6 @@ NSString *const PROMOTIONALSTRING = @"促销信息";
[weakSelf RemoveMBProgressHUDLoding]; [weakSelf RemoveMBProgressHUDLoding];
if ([returnValue[@"code"] isEqualToNumber:@0]) { if ([returnValue[@"code"] isEqualToNumber:@0]) {
[weakSelf.promotionInformationArray removeAllObjects]; [weakSelf.promotionInformationArray removeAllObjects];
[weakSelf.originalCustomerPromotionArray removeAllObjects];
NSArray *promotion = returnValue[@"data"]; NSArray *promotion = returnValue[@"data"];
for (NSDictionary *dict in promotion) { for (NSDictionary *dict in promotion) {
TOOrderPromotionEntity *oldPromotion = [[TOOrderPromotionEntity alloc]initWithDictionary:dict error:nil]; TOOrderPromotionEntity *oldPromotion = [[TOOrderPromotionEntity alloc]initWithDictionary:dict error:nil];
...@@ -311,9 +295,16 @@ NSString *const PROMOTIONALSTRING = @"促销信息"; ...@@ -311,9 +295,16 @@ NSString *const PROMOTIONALSTRING = @"促销信息";
model.descriptionString = [oldPromotion.discountRate stringValue]; model.descriptionString = [oldPromotion.discountRate stringValue];
model.body = CONSUMER; model.body = CONSUMER;
[weakSelf.promotionInformationArray addObject:model]; [weakSelf.promotionInformationArray addObject:model];
} else if (![BaseViewController isBlankString:oldPromotion.wxcardNumber]) {
// 微信卡劵
PromotionWeChatCardModel *model = [[PromotionWeChatCardModel alloc]init];
model.total = [oldPromotion.wxcardDenomation integerValue];
[weakSelf.promotionInformationArray addObject:model];
self.weChatModel.wxcardNumber = oldPromotion.wxcardNumber;
self.weChatModel.wxcardDenomation = [oldPromotion.wxcardDenomation integerValue];
} }
} }
if (self.promotionInformationArray.count) { if (self.promotionInformationArray.count && ![self.sectionTitle containsObject:@"促销信息"]) {
[self.sectionTitle addObject:@"促销信息"]; [self.sectionTitle addObject:@"促销信息"];
} }
} }
...@@ -429,7 +420,7 @@ NSString *const PROMOTIONALSTRING = @"促销信息"; ...@@ -429,7 +420,7 @@ NSString *const PROMOTIONALSTRING = @"促销信息";
} }
} }
} }
if (self.promotionInformationArray.count) { if (self.promotionInformationArray.count && ![self.sectionTitle containsObject:@"促销信息"]) {
[self.sectionTitle addObject:@"促销信息"]; [self.sectionTitle addObject:@"促销信息"];
} }
[self promotionInformationExecutionOrder]; [self promotionInformationExecutionOrder];
...@@ -438,8 +429,8 @@ NSString *const PROMOTIONALSTRING = @"促销信息"; ...@@ -438,8 +429,8 @@ NSString *const PROMOTIONALSTRING = @"促销信息";
#pragma mark - 促销信息执行顺序 #pragma mark - 促销信息执行顺序
- (void)promotionInformationExecutionOrder - (void)promotionInformationExecutionOrder
{ {
PromotionLuckyDrawModel *drawModel; PromotionLuckyDrawModel *drawModel = nil;
PromotionWeChatCardModel *weChatModel; PromotionWeChatCardModel *weChatModel = nil;
for (JSONModel *model in self.promotionInformationArray) { for (JSONModel *model in self.promotionInformationArray) {
// 抽奖 // 抽奖
if ([model isMemberOfClass:[PromotionLuckyDrawModel class]]) { if ([model isMemberOfClass:[PromotionLuckyDrawModel class]]) {
...@@ -455,6 +446,7 @@ NSString *const PROMOTIONALSTRING = @"促销信息"; ...@@ -455,6 +446,7 @@ NSString *const PROMOTIONALSTRING = @"促销信息";
} }
//通过促销优先级决定调用顺序 //通过促销优先级决定调用顺序
if (drawModel.priority > weChatModel.priority) { if (drawModel.priority > weChatModel.priority) {
if (!drawModel.isUsed && drawModel) { if (!drawModel.isUsed && drawModel) {
drawModel.isUsed = YES; drawModel.isUsed = YES;
[self queryConsumerLuckyDrawChance:drawModel]; [self queryConsumerLuckyDrawChance:drawModel];
...@@ -464,7 +456,9 @@ NSString *const PROMOTIONALSTRING = @"促销信息"; ...@@ -464,7 +456,9 @@ NSString *const PROMOTIONALSTRING = @"促销信息";
}else{ }else{
[self payButtonClickAction]; [self payButtonClickAction];
} }
}else if (drawModel.priority < weChatModel.priority) { }else if (drawModel.priority < weChatModel.priority) {
if (!weChatModel.isUsed && weChatModel) { if (!weChatModel.isUsed && weChatModel) {
weChatModel.isUsed = YES; weChatModel.isUsed = YES;
[self scanWeChatCardNumber:weChatModel];; [self scanWeChatCardNumber:weChatModel];;
...@@ -474,7 +468,9 @@ NSString *const PROMOTIONALSTRING = @"促销信息"; ...@@ -474,7 +468,9 @@ NSString *const PROMOTIONALSTRING = @"促销信息";
}else{ }else{
[self payButtonClickAction]; [self payButtonClickAction];
} }
}else if (drawModel.priority == weChatModel.priority && drawModel && weChatModel) { }else if (drawModel.priority == weChatModel.priority && drawModel && weChatModel) {
if (!drawModel.isUsed && drawModel) { if (!drawModel.isUsed && drawModel) {
drawModel.isUsed = YES; drawModel.isUsed = YES;
[self queryConsumerLuckyDrawChance:drawModel]; [self queryConsumerLuckyDrawChance:drawModel];
...@@ -486,6 +482,11 @@ NSString *const PROMOTIONALSTRING = @"促销信息"; ...@@ -486,6 +482,11 @@ NSString *const PROMOTIONALSTRING = @"促销信息";
} }
} }
[self.orderDetailsTableview reloadData]; [self.orderDetailsTableview reloadData];
[self.orderDetailsTableview layoutIfNeeded];
//赠送商品或抵扣情况
if (!drawModel && !weChatModel) {
[self payButtonClickAction];
}
} }
...@@ -512,6 +513,7 @@ NSString *const PROMOTIONALSTRING = @"促销信息"; ...@@ -512,6 +513,7 @@ NSString *const PROMOTIONALSTRING = @"促销信息";
[[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:USEWECHATCARD,number,orderNumber,orderTotal] WithCallClass:weakSelf WithRequestType:ZERO WithParameter:nil WithReturnValueBlock:^(id returnValue) { [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:USEWECHATCARD,number,orderNumber,orderTotal] WithCallClass:weakSelf WithRequestType:ZERO WithParameter:nil WithReturnValueBlock:^(id returnValue) {
[weakSelf RemoveMBProgressHUDLoding]; [weakSelf RemoveMBProgressHUDLoding];
NSLog(@"%@",returnValue);
if ([returnValue[@"code"] isEqualToNumber:@0]) { if ([returnValue[@"code"] isEqualToNumber:@0]) {
weakSelf.weChatModel.wxcardDenomation = [returnValue[@"data"][@"denomation"] integerValue]; weakSelf.weChatModel.wxcardDenomation = [returnValue[@"data"][@"denomation"] integerValue];
weakSelf.weChatModel.payNo = returnValue[@"data"][@"payNo"]; weakSelf.weChatModel.payNo = returnValue[@"data"][@"payNo"];
...@@ -686,7 +688,6 @@ NSString *const PROMOTIONALSTRING = @"促销信息"; ...@@ -686,7 +688,6 @@ NSString *const PROMOTIONALSTRING = @"促销信息";
PromotionLuckyDrawModel *model = (PromotionLuckyDrawModel *)object; PromotionLuckyDrawModel *model = (PromotionLuckyDrawModel *)object;
if ([model.body isEqualToString:GUIDE]) { if ([model.body isEqualToString:GUIDE]) {
finish(); finish();
// [self.promotionInformationArray removeObject:object];
break; break;
} }
} }
...@@ -761,6 +762,7 @@ NSString *const PROMOTIONALSTRING = @"促销信息"; ...@@ -761,6 +762,7 @@ NSString *const PROMOTIONALSTRING = @"促销信息";
complete(result); complete(result);
}]; }];
[wkWebView setDismissLuckyDrawController:^{ [wkWebView setDismissLuckyDrawController:^{
[weakSelf payButtonClickAction]; [weakSelf payButtonClickAction];
}]; }];
[self presentViewController:wkWebView animated:YES completion:nil]; [self presentViewController:wkWebView animated:YES completion:nil];
...@@ -825,6 +827,7 @@ NSString *const PROMOTIONALSTRING = @"促销信息"; ...@@ -825,6 +827,7 @@ NSString *const PROMOTIONALSTRING = @"促销信息";
//商品总计 //商品总计
AllpriceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"sixthcell" forIndexPath:indexPath]; AllpriceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"sixthcell" forIndexPath:indexPath];
cell.model = self.customerDrawModel; cell.model = self.customerDrawModel;
cell.weChatModel = self.weChatModel;
cell.promotionalArray = self.promotionInformationArray; cell.promotionalArray = self.promotionInformationArray;
cell.goodsArray = self.orderDetails.orderdetailList; cell.goodsArray = self.orderDetails.orderdetailList;
cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.selectionStyle = UITableViewCellSelectionStyleNone;
...@@ -851,6 +854,7 @@ NSString *const PROMOTIONALSTRING = @"促销信息"; ...@@ -851,6 +854,7 @@ NSString *const PROMOTIONALSTRING = @"促销信息";
{ {
PromotionalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PromotionalTableViewCell" forIndexPath:indexPath]; PromotionalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PromotionalTableViewCell" forIndexPath:indexPath];
cell.userInteractionEnabled = self.isUserInteractionEnabled; cell.userInteractionEnabled = self.isUserInteractionEnabled;
cell.model = self.customerDrawModel;
cell.promotionModel = self.promotionInformationArray[indexPath.row]; cell.promotionModel = self.promotionInformationArray[indexPath.row];
return cell; return cell;
} }
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
//** 类型 */ //** 类型 */
@property (nonatomic, copy) NSString *type; @property (nonatomic, copy) NSString *type;
//** 抵扣金额 */ // 卡劵面额
@property (nonatomic, assign) NSInteger total; @property (nonatomic, assign) NSInteger total;
//** 描述 */ //** 描述 */
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
// //
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "PromotionLuckDrawResultModel.h"
@interface PromotionalTableViewCell : UITableViewCell @interface PromotionalTableViewCell : UITableViewCell
...@@ -22,4 +22,10 @@ ...@@ -22,4 +22,10 @@
*/ */
@property (nonatomic,copy) JSONModel *promotionModel; @property (nonatomic,copy) JSONModel *promotionModel;
/**
* 抽奖结果
*/
@property (nonatomic,copy) PromotionLuckDrawResultModel *model;
@end @end
...@@ -25,19 +25,18 @@ ...@@ -25,19 +25,18 @@
//微信卡劵 //微信卡劵
if ([promotionModel isMemberOfClass:[PromotionWeChatCardModel class]]) { if ([promotionModel isMemberOfClass:[PromotionWeChatCardModel class]]) {
PromotionWeChatCardModel *weChatModel = (PromotionWeChatCardModel *)promotionModel; PromotionWeChatCardModel *weChatModel = (PromotionWeChatCardModel *)promotionModel;
self.promotionalTitleLabel.text = [NSString stringWithFormat:@"微信卡劵: %@",weChatModel.descriptionString]; self.promotionalTitleLabel.text = [NSString stringWithFormat:@"微信卡劵: %ld",weChatModel.total];
}else if ([promotionModel isMemberOfClass:[PromotionalDeductionModel class]]) { }else if ([promotionModel isMemberOfClass:[PromotionalDeductionModel class]]) {
//抵扣 //抵扣
PromotionalDeductionModel *deductionModel = (PromotionalDeductionModel *)promotionModel; PromotionalDeductionModel *deductionModel = (PromotionalDeductionModel *)promotionModel;
self.promotionalTitleLabel.text = [NSString stringWithFormat:@"抵扣: %@",deductionModel.descriptionString]; self.promotionalTitleLabel.text = [NSString stringWithFormat:@"抵扣: %@",deductionModel.descriptionString];
}else if ([promotionModel isMemberOfClass:[PromotionLuckyDrawModel class]]) { }else if ([promotionModel isMemberOfClass:[PromotionLuckyDrawModel class]]) {
//抽奖 //抽奖
PromotionLuckyDrawModel *drawModel = (PromotionLuckyDrawModel *)promotionModel; self.promotionalTitleLabel.text = [NSString stringWithFormat:@"转盘抽奖: %@",self.model.descriptionString];
self.promotionalTitleLabel.text = [NSString stringWithFormat:@"转盘抽奖: %@",drawModel.descriptionString];
}else if ([promotionModel isMemberOfClass:[PromotionalGoodsModel class]]) { }else if ([promotionModel isMemberOfClass:[PromotionalGoodsModel class]]) {
//送商品 //送商品
PromotionalGoodsModel *goodsModel = (PromotionalGoodsModel *)promotionModel; PromotionalGoodsModel *goodsModel = (PromotionalGoodsModel *)promotionModel;
self.promotionalTitleLabel.text = [NSString stringWithFormat:@"赠送商品: %@",goodsModel.descriptionString]; self.promotionalTitleLabel.text = [NSString stringWithFormat:@"赠送商品: %@",goodsModel.goods.name];
} }
self.accessoryType = UITableViewCellAccessoryCheckmark; self.accessoryType = UITableViewCellAccessoryCheckmark;
} }
......
...@@ -24,11 +24,6 @@ ...@@ -24,11 +24,6 @@
*/ */
@property (nonatomic,strong) NSArray *promotionalArray; @property (nonatomic,strong) NSArray *promotionalArray;
///**
// * 促销信息(京东E卡、抽奖)
// */
//@property (nonatomic,strong) NSArray *luckyDrawAndJDECardArray;
/** /**
* 商品总数量 * 商品总数量
*/ */
......
...@@ -87,32 +87,90 @@ ...@@ -87,32 +87,90 @@
- (void)setGoodsArray - (void)setGoodsArray
{ {
NSInteger goodsAllNumber = 0;//总数量 NSInteger goodsAllNumber = 0;//总数量
CGFloat goodAllprice = 0;//总价格
for (TOOrderdetailEntity *model in _goodsArray) { for (TOOrderdetailEntity *model in _goodsArray) {
goodsAllNumber += [model.goodsNum integerValue]; goodsAllNumber += [model.goodsNum integerValue];
goodAllprice += [model.goodsPrice floatValue]*[model.goodsNum integerValue];
} }
// 促销金额大于商品金额情况 CGFloat allPrice = 0;//实际支付金额
goodAllprice = (goodAllprice<0)?0:goodAllprice; NSDictionary *deductionPrice = nil;//抵扣金额
// 抽奖结果<打折> NSDictionary *weChatPrice = nil;//微信卡劵
if ([self.resultModel.type isEqualToString:@"discount"]) { NSDictionary *drawPrice = nil;//转盘抽奖
goodAllprice = goodAllprice*([self.resultModel.number integerValue]/100.0); for (TOOrderdetailEntity *model in _goodsArray) {
} allPrice += [model.goodsPrice floatValue]*[model.goodsNum floatValue];
//** 促销金额 */
NSInteger totalNumber = 0;
for (id object in self.promotionalArray) {
if ([object isKindOfClass:[PromotionalDeductionModel class]]) {
PromotionalDeductionModel *model = (PromotionalDeductionModel *)object;
if (model.isSelected) {
totalNumber += model.total;
} }
//促销列表
for (JSONModel *model in self.promotionalArray) {
//微信卡劵
if ([model isMemberOfClass:[PromotionWeChatCardModel class]]) {
PromotionWeChatCardModel *weChatModel = (PromotionWeChatCardModel *)model;
weChatPrice = @{@"price":[NSString stringWithFormat:@"%ld",self.weChatModel.wxcardDenomation],@"priority":@(weChatModel.priority)};
}else if ([model isMemberOfClass:[PromotionalDeductionModel class]]) {
//抵扣
PromotionalDeductionModel *deductionModel = (PromotionalDeductionModel *)model;
deductionPrice = @{@"price":[NSString stringWithFormat:@"%ld",deductionModel.total],@"priority":@(deductionModel.priority)};
}else if ([model isMemberOfClass:[PromotionLuckyDrawModel class]]) {
//抽奖
PromotionLuckyDrawModel *drawModel = (PromotionLuckyDrawModel *)model;
drawPrice = @{@"price":[NSString stringWithFormat:@"%@",self.resultModel.number],@"priority":@(drawModel.priority)};
}else if ([model isMemberOfClass:[PromotionalGoodsModel class]]) {
//送商品
// PromotionalGoodsModel *goodsModel = (PromotionalGoodsModel *)model;
} }
} }
goodAllprice -= totalNumber; CGFloat goodsAllPrice = [self promotionSorting:deductionPrice andWeChatPrice:weChatPrice andDrawPrice:drawPrice andAllPrice:allPrice];
self.goodsAllNumber.text = [NSString stringWithFormat:@"%ld",goodsAllNumber]; self.goodsAllNumber.text = [NSString stringWithFormat:@"%ld",goodsAllNumber];
self.goodsAllPrice.text = [NSString stringWithFormat:@"¥%.2f",goodAllprice]; self.goodsAllPrice.text = [NSString stringWithFormat:@"¥%.2f",goodsAllPrice];
} }
#pragma mark - 通过优先级排列促销项
- (CGFloat)promotionSorting:(NSDictionary *)deductionPrice andWeChatPrice:(NSDictionary *)weChatPrice andDrawPrice:(NSDictionary *)drawPrice andAllPrice:(CGFloat)allPrice
{
NSMutableArray *array = [NSMutableArray array];
if (deductionPrice) {
[array addObject:deductionPrice];
}
if (weChatPrice) {
[array addObject:weChatPrice];
}
if (drawPrice) {
[array addObject:drawPrice];
}
//安装权限降序排列
NSArray *chooseArray = [array sortedArrayUsingComparator:^NSComparisonResult(NSDictionary *obj1, NSDictionary *obj2) {
if (obj1[@"priority"] < obj2[@"priority"]) {
return NSOrderedAscending;
}
if (obj1[@"priority"] < obj2[@"priority"]) {
return NSOrderedDescending;
}
return NSOrderedSame;
}];
//计算促销后的价格
CGFloat newPrice = allPrice;
for (NSDictionary *dict in chooseArray) {
if ([dict isEqual:deductionPrice]) {
CGFloat deduction = [dict[@"price"] floatValue];
newPrice = newPrice - deduction;
}else if ([dict isEqual:weChatPrice]){
CGFloat weChat = [dict[@"price"] floatValue];
newPrice = newPrice - weChat;
}else if ([dict isEqual:drawPrice]){
CGFloat draw = [self.resultModel.number floatValue]/100.0;
newPrice = newPrice * draw;
}
}
//判断促销是否为空
if (chooseArray.count) {
if (newPrice < 0) {
newPrice = 0;
}
}
return newPrice;
}
#pragma mark -获取经营者支付二维码 #pragma mark -获取经营者支付二维码
- (void)getPayQrCode - (void)getPayQrCode
...@@ -309,7 +367,6 @@ ...@@ -309,7 +367,6 @@
order.orderNumber = self.orderCode; order.orderNumber = self.orderCode;
order.fnewstate = PAYSUCCESS; order.fnewstate = PAYSUCCESS;
order.oldstate = NOTPAY; order.oldstate = NOTPAY;
order.drawId = self.resultModel.drawId;
// 查询是否有赠送商品促销 // 查询是否有赠送商品促销
order.realAmount = [NSNumber numberWithFloat:[[self.goodsAllPrice.text substringFromIndex:1] floatValue]]; order.realAmount = [NSNumber numberWithFloat:[[self.goodsAllPrice.text substringFromIndex:1] floatValue]];
NSMutableArray *goodsArray = [NSMutableArray array]; NSMutableArray *goodsArray = [NSMutableArray array];
...@@ -351,13 +408,16 @@ ...@@ -351,13 +408,16 @@
} }
} }
order.jdCardDenomation = totalNumber; order.jdCardDenomation = totalNumber;
// 查询是否有导购抽奖机会 // 查询是否有导购抽奖和客户抽奖
for (id object in self.promotionalArray) { for (id object in self.promotionalArray) {
if ([object isKindOfClass:[PromotionLuckyDrawModel class]]) { if ([object isKindOfClass:[PromotionLuckyDrawModel class]]) {
PromotionLuckyDrawModel *model = (PromotionLuckyDrawModel *)object; PromotionLuckyDrawModel *model = (PromotionLuckyDrawModel *)object;
if ([model.body isEqualToString:GUIDE]) { if ([model.body isEqualToString:GUIDE]) {
order.lotteryId = model.lottery.uuid; order.lotteryId = model.lottery.uuid;
} }
if ([model.body isEqualToString:CONSUMER]) {
order.drawId = self.resultModel.drawId;
}
} }
} }
// 查询是否有微信卡劵促销 // 查询是否有微信卡劵促销
...@@ -394,6 +454,7 @@ ...@@ -394,6 +454,7 @@
} }
[self CreateMBProgressHUDLoding]; [self CreateMBProgressHUDLoding];
WS(weakSelf); WS(weakSelf);
NSSLog(@"%@",[order toDictionary]);
[[NetworkRequestClassManager Manager] NetworkRequestWithURL:SERVERREQUESTURL(CONFIRMPAY) WithCallClass:weakSelf WithRequestType:0 WithParameter:order WithReturnValueBlock:^(id returnValue) { [[NetworkRequestClassManager Manager] NetworkRequestWithURL:SERVERREQUESTURL(CONFIRMPAY) WithCallClass:weakSelf WithRequestType:0 WithParameter:order WithReturnValueBlock:^(id returnValue) {
[weakSelf RemoveMBProgressHUDLoding]; [weakSelf RemoveMBProgressHUDLoding];
......
...@@ -181,7 +181,7 @@ ...@@ -181,7 +181,7 @@
UIImage *image = [[UIImage imageNamed:@"Checkmark"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; UIImage *image = [[UIImage imageNamed:@"Checkmark"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
hud.customView = [[UIImageView alloc] initWithImage:image]; hud.customView = [[UIImageView alloc] initWithImage:image];
hud.color = [[UIColor blackColor] colorWithAlphaComponent:0.6]; hud.color = [[UIColor blackColor] colorWithAlphaComponent:0.6];
hud.labelFont = [UIFont systemFontOfSize:12]; hud.labelFont = [UIFont systemFontOfSize:15];
hud.labelText = successString; hud.labelText = successString;
[hud hide:YES afterDelay:3]; [hud hide:YES afterDelay:3];
} }
......
...@@ -50,6 +50,8 @@ static NetworkRequestClassManager *manager = nil; ...@@ -50,6 +50,8 @@ static NetworkRequestClassManager *manager = nil;
manager.requestSerializer = [AFJSONRequestSerializer serializer]; manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.requestSerializer.timeoutInterval = 60.0f; manager.requestSerializer.timeoutInterval = 60.0f;
[manager.requestSerializer setValue:@"application/json;charset=utf-8" forHTTPHeaderField: @"Content-Type"]; [manager.requestSerializer setValue:@"application/json;charset=utf-8" forHTTPHeaderField: @"Content-Type"];
[manager.requestSerializer setValue:[[[NSBundle mainBundle] infoDictionary]
objectForKey:@"CFBundleShortVersionString"] forHTTPHeaderField: @"version"];
return manager; return manager;
} }
......
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