谈论了两天的需求,最终改需求了。不忍心删

本文详细描述了在删除客户会员卡后,如何处理与该卡关联的所有赠送项目及预存商品,确保订单信息准确更新,涉及商品匹配、数量调整及订单状态维护。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

		//删卡之后获取到所有的赠送项目
				List<CustomerGiveGood> customerGiveGoodList  = new ArrayList<>();
				CustomerClubCard customerClubCard = new CustomerClubCard();
				//1有效 2无效
				customerClubCard.setStatus(1);
				CustomerDoc customerDoc = new CustomerDoc();
				customerDoc.setId(customerDocId);
				customerClubCard.setCustomerDoc(customerDoc);
				List<CustomerClubCard> list = customerClubCardService.findList(customerClubCard);
				for (CustomerClubCard card :list){
					CustomerGiveGood customerGiveGood = new CustomerGiveGood();
					customerGiveGood.setCustomerClubCardId(Long.parseLong(card.getId()));
					//所有跟这个卡项关联的商品
					List<CustomerGiveGood> giveGoods = customerGiveGoodService.findListHisGoodsNotNull(customerGiveGood);
					if (giveGoods != null && giveGoods.size() > 0) {
						customerGiveGoodList.addAll(giveGoods);
					}
				}

				CustomerBill customerBill = new CustomerBill();
				CustomerOrderDoc orderDoc = new CustomerOrderDoc();
				orderDoc.setId(customerOrderDocId);
				customerBill.setCustomerOrderDoc(orderDoc);
				customerBill.setGiveStatus(1);
				customerBill.setStatus(1);
				//当前订单的有效的预存项
				Response<List<CustomerBill>> bills = customerBillBusinessService.findList(customerBill);
				HashMap<CustomerGiveGood,Integer> goodsMap = new HashMap<>();
				if (bills.getData()!=null&&bills.getData().size()>0){
					List<CustomerBill> haveIdBill = new ArrayList<>();
					List<CustomerBill> notHaveIdBill = new ArrayList<>();
					//将开单分成老数据和新数据 有id的为新数据
					for (CustomerBill Bill :bills.getData()){
						if (StringUtils.isNotEmpty(Bill.getGiveGoodsId())){
							haveIdBill.add(Bill);
						}else {
							notHaveIdBill.add(Bill);
						}
					}
					//分别处理
					for (CustomerBill haveBill:haveIdBill){
						CustomerGiveGood customerGiveGood = customerGiveGoodService.get(haveBill.getGiveGoodsId());
						//卡被删除
						if (customerGiveGood==null){
							if (customerGiveGoodList.size()>0&&haveBill.getHisGoods()!=null){
								for (CustomerGiveGood giveGood : customerGiveGoodList){
									if (giveGood.getGoodId().equals(haveBill.getHisGoods().getId())&&giveGood.getNum()>0){
										haveBill.setGiveGoodsId(giveGood.getId());
										customerBillBusinessService.save(haveBill);
										giveGood.setNum(giveGood.getNum()-1);
										break;
									}
									if (giveGood==customerGiveGoodList.get(customerGiveGoodList.size()-1)){
										Response<HisGoods> hisGoodsResponse = hisGoodsBusinessService.get(haveBill.getHisGoods().getId());
										if (hisGoodsResponse.isSuccess()&&hisGoodsResponse.getData()!=null){
											haveBill.setGiveStatus(0);
											haveBill.setPrice(new BigDecimal(hisGoodsResponse.getData().getPrice()));
											//加入金额
											customerBillBusinessService.save(haveBill);
										}
									}
								}
								//没有预存项 将金额变回去
							}else {
								Response<HisGoods> hisGoodsResponse = hisGoodsBusinessService.get(haveBill.getHisGoods().getId());
								if (hisGoodsResponse.isSuccess()&&hisGoodsResponse.getData()!=null){
									haveBill.setGiveStatus(0);
									haveBill.setPrice(new BigDecimal(hisGoodsResponse.getData().getPrice()));
									//加入金额
									customerBillBusinessService.save(haveBill);
								}
							}
						}else {
							//卡没删,但是得判断数量是否充足
						}
					}
					for (CustomerBill notHaveBill:notHaveIdBill){
					//老数据只有标记  用hisgoods
						if (customerGiveGoodList.size()>0&&notHaveBill.getHisGoods()!=null){
							for (CustomerGiveGood giveGood : customerGiveGoodList){
								if (giveGood.getGoodId().equals(notHaveBill.getHisGoods().getId())&&giveGood.getNum()>0){
									notHaveBill.setGiveGoodsId(giveGood.getId());
									customerBillBusinessService.save(notHaveBill);
									giveGood.setNum(giveGood.getNum()-1);
									break;

								}
								if (giveGood==customerGiveGoodList.get(customerGiveGoodList.size()-1)){
									Response<HisGoods> hisGoodsResponse = hisGoodsBusinessService.get(notHaveBill.getHisGoods().getId());
									if (hisGoodsResponse.isSuccess()&&hisGoodsResponse.getData()!=null){
										notHaveBill.setGiveStatus(0);
										notHaveBill.setPrice(new BigDecimal(hisGoodsResponse.getData().getPrice()));
										//加入金额
										customerBillBusinessService.save(notHaveBill);
									}
								}
							}
						}
					}
				}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值