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

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

No related merge requests found
......@@ -11,6 +11,10 @@
#import "ShopcarModel.h"
#import "PromotionalDeductionModel.h"
#import "PromotionalGoodsModel.h"
#import "PromotionLuckyDrawModel.h"
#import "PromotionalGoodsModel.h"
#import "PromotionalDeductionModel.h"
#import "PromotionWeChatCardModel.h"
@interface AllpriceTableViewCell : UITableViewCell
......@@ -48,4 +52,10 @@
*/
@property (nonatomic,copy) NSArray *promotionalArray;
/**
微信卡劵
*/
@property (nonatomic,strong) WeChatCardModel *weChatModel;
@end
......@@ -8,6 +8,7 @@
#import "AllpriceTableViewCell.h"
@implementation AllpriceTableViewCell
- (void)awakeFromNib {
......@@ -36,42 +37,114 @@
_goodsArray = goodsArray;
NSInteger allNumber = 0;//总数量
CGFloat allPrice = 0;//总价格
CGFloat newPrice = 0;//折后价格
CGFloat deductionPrice = 0;//抵扣金额
NSDictionary *deductionPrice = nil;//抵扣金额
NSDictionary *weChatPrice = nil;//微信卡劵
NSDictionary *drawPrice = nil;//转盘抽奖
for (TOOrderdetailEntity *model in _goodsArray) {
allNumber += [model.goodsNum integerValue];
allPrice += [model.goodsPrice floatValue]*[model.goodsNum intValue];
}
newPrice = allPrice;
// 抽奖折扣
if (![BaseViewController isBlankString:self.model.number]) {
newPrice = allPrice * ([self.model.number integerValue]/100.0);
allPrice += [model.goodsPrice floatValue]*[model.goodsNum floatValue];
}
// 全局抵扣
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;
}
//促销列表
for (JSONModel *model in self.promotionalArray) {
//微信卡劵
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;
}
}
NSString *goodsAllPriceString = nil;
if (deductionPrice && newPrice != allPrice) {
goodsAllPriceString = [NSString stringWithFormat:@"¥%.2f (%.2f x %@ - %.2f)",newPrice-deductionPrice,allPrice,self.model.descriptionString,deductionPrice];
}else if (newPrice == allPrice && !deductionPrice){
goodsAllPriceString = [NSString stringWithFormat:@"¥%.2f",newPrice];
}else if (newPrice == allPrice && deductionPrice){
goodsAllPriceString = [NSString stringWithFormat:@"¥%.2f (%.2f - %.2f)",newPrice-deductionPrice,allPrice,deductionPrice];
}else if (newPrice != allPrice && !deductionPrice){
goodsAllPriceString = [NSString stringWithFormat:@"¥%.2f (%.2f x %@)",newPrice-deductionPrice,allPrice,self.model.descriptionString];
}
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];
}
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;
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 ([dict isEqual:weChatPrice]){
CGFloat weChat = [dict[@"price"] floatValue];
newPrice = newPrice - weChat;
[priceString appendString:[NSString stringWithFormat:@" - %.2f",weChat]];
}else if ([dict isEqual:drawPrice]){
CGFloat draw = [self.model.number floatValue]/100.0;
newPrice = newPrice * draw;
[priceString appendString:[NSString stringWithFormat:@" x %@",self.model.descriptionString]];
}
}
//判断促销是否为空
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
This diff is collapsed.
......@@ -16,7 +16,7 @@
//** 类型 */
@property (nonatomic, copy) NSString *type;
//** 抵扣金额 */
// 卡劵面额
@property (nonatomic, assign) NSInteger total;
//** 描述 */
......
......@@ -7,7 +7,7 @@
//
#import <UIKit/UIKit.h>
#import "PromotionLuckDrawResultModel.h"
@interface PromotionalTableViewCell : UITableViewCell
......@@ -22,4 +22,10 @@
*/
@property (nonatomic,copy) JSONModel *promotionModel;
/**
* 抽奖结果
*/
@property (nonatomic,copy) PromotionLuckDrawResultModel *model;
@end
......@@ -25,19 +25,18 @@
//微信卡劵
if ([promotionModel isMemberOfClass:[PromotionWeChatCardModel class]]) {
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]]) {
//抵扣
PromotionalDeductionModel *deductionModel = (PromotionalDeductionModel *)promotionModel;
self.promotionalTitleLabel.text = [NSString stringWithFormat:@"抵扣: %@",deductionModel.descriptionString];
}else if ([promotionModel isMemberOfClass:[PromotionLuckyDrawModel class]]) {
//抽奖
PromotionLuckyDrawModel *drawModel = (PromotionLuckyDrawModel *)promotionModel;
self.promotionalTitleLabel.text = [NSString stringWithFormat:@"转盘抽奖: %@",drawModel.descriptionString];
self.promotionalTitleLabel.text = [NSString stringWithFormat:@"转盘抽奖: %@",self.model.descriptionString];
}else if ([promotionModel isMemberOfClass:[PromotionalGoodsModel class]]) {
//送商品
PromotionalGoodsModel *goodsModel = (PromotionalGoodsModel *)promotionModel;
self.promotionalTitleLabel.text = [NSString stringWithFormat:@"赠送商品: %@",goodsModel.descriptionString];
self.promotionalTitleLabel.text = [NSString stringWithFormat:@"赠送商品: %@",goodsModel.goods.name];
}
self.accessoryType = UITableViewCellAccessoryCheckmark;
}
......
......@@ -24,11 +24,6 @@
*/
@property (nonatomic,strong) NSArray *promotionalArray;
///**
// * 促销信息(京东E卡、抽奖)
// */
//@property (nonatomic,strong) NSArray *luckyDrawAndJDECardArray;
/**
* 商品总数量
*/
......
......@@ -87,32 +87,90 @@
- (void)setGoodsArray
{
NSInteger goodsAllNumber = 0;//总数量
CGFloat goodAllprice = 0;//总价格
for (TOOrderdetailEntity *model in _goodsArray) {
goodsAllNumber += [model.goodsNum integerValue];
goodAllprice += [model.goodsPrice floatValue]*[model.goodsNum integerValue];
}
// 促销金额大于商品金额情况
goodAllprice = (goodAllprice<0)?0:goodAllprice;
// 抽奖结果<打折>
if ([self.resultModel.type isEqualToString:@"discount"]) {
goodAllprice = goodAllprice*([self.resultModel.number integerValue]/100.0);
CGFloat allPrice = 0;//实际支付金额
NSDictionary *deductionPrice = nil;//抵扣金额
NSDictionary *weChatPrice = nil;//微信卡劵
NSDictionary *drawPrice = nil;//转盘抽奖
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.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 -获取经营者支付二维码
- (void)getPayQrCode
......@@ -309,7 +367,6 @@
order.orderNumber = self.orderCode;
order.fnewstate = PAYSUCCESS;
order.oldstate = NOTPAY;
order.drawId = self.resultModel.drawId;
// 查询是否有赠送商品促销
order.realAmount = [NSNumber numberWithFloat:[[self.goodsAllPrice.text substringFromIndex:1] floatValue]];
NSMutableArray *goodsArray = [NSMutableArray array];
......@@ -351,13 +408,16 @@
}
}
order.jdCardDenomation = totalNumber;
// 查询是否有导购抽奖机会
// 查询是否有导购抽奖和客户抽奖
for (id object in self.promotionalArray) {
if ([object isKindOfClass:[PromotionLuckyDrawModel class]]) {
PromotionLuckyDrawModel *model = (PromotionLuckyDrawModel *)object;
if ([model.body isEqualToString:GUIDE]) {
order.lotteryId = model.lottery.uuid;
}
if ([model.body isEqualToString:CONSUMER]) {
order.drawId = self.resultModel.drawId;
}
}
}
// 查询是否有微信卡劵促销
......@@ -394,6 +454,7 @@
}
[self CreateMBProgressHUDLoding];
WS(weakSelf);
NSSLog(@"%@",[order toDictionary]);
[[NetworkRequestClassManager Manager] NetworkRequestWithURL:SERVERREQUESTURL(CONFIRMPAY) WithCallClass:weakSelf WithRequestType:0 WithParameter:order WithReturnValueBlock:^(id returnValue) {
[weakSelf RemoveMBProgressHUDLoding];
......
......@@ -181,7 +181,7 @@
UIImage *image = [[UIImage imageNamed:@"Checkmark"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
hud.customView = [[UIImageView alloc] initWithImage:image];
hud.color = [[UIColor blackColor] colorWithAlphaComponent:0.6];
hud.labelFont = [UIFont systemFontOfSize:12];
hud.labelFont = [UIFont systemFontOfSize:15];
hud.labelText = successString;
[hud hide:YES afterDelay:3];
}
......
......@@ -50,6 +50,8 @@ static NetworkRequestClassManager *manager = nil;
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.requestSerializer.timeoutInterval = 60.0f;
[manager.requestSerializer setValue:@"application/json;charset=utf-8" forHTTPHeaderField: @"Content-Type"];
[manager.requestSerializer setValue:[[[NSBundle mainBundle] infoDictionary]
objectForKey:@"CFBundleShortVersionString"] forHTTPHeaderField: @"version"];
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