| | |
| | | import com.hx.phip.service.order.impl.OrderRefundServiceImpl; |
| | | import com.hx.phip.tool.user.UserProjectTool; |
| | | import com.hx.phip.util.api.UserMoneyUtil; |
| | | import com.hx.phip.vo.order.refund.RefundCarryVo; |
| | | import com.hx.phip.vo.user.UserProjectDeductionVo; |
| | | import com.hx.util.StringUtils; |
| | | import com.platform.exception.PlatTipsException; |
| | | import com.platform.resultTool.PlatformCode; |
| | |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | * @param commonService 映射 |
| | | */ |
| | | public static void rechargeHandle(OrdersTotal ordersTotal, RefundRecord refundRecord,int optType, CommonService commonService){ |
| | | |
| | | if(!OrderTotalConstants.TYPE_RECHARGE.equals(ordersTotal.getType())){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"操作失败,不是充值单!"); |
| | | } |
| | |
| | | } |
| | | }else if(ActivityAction.TYPE_VALUEADDEDFUND.equals(activityAction.getType())){ |
| | | //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
| | | if(new BigDecimal(activityAction.getWorth()).compareTo(BigDecimal.ZERO) ==0 ){ |
| | | if(new BigDecimal(activityAction.getWorth()).compareTo(BigDecimal.ZERO) == 0 ){ |
| | | continue; |
| | | } |
| | | if(optType == 0){ |
| | |
| | | } |
| | | }else if(ActivityAction.TYPE_VALUEADDEDFUND.equals(ordersActivityInfoItem.getType())){ |
| | | //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
| | | if(new BigDecimal(ordersActivityInfoItem.getWorth()).compareTo(BigDecimal.ZERO) ==0 ){ |
| | | if(new BigDecimal(ordersActivityInfoItem.getWorth()).compareTo(BigDecimal.ZERO) == 0 ){ |
| | | continue; |
| | | } |
| | | if(optType == 0){ |
| | |
| | | //商品类型判断 |
| | | switch (refundRecordItem.getType()){ |
| | | case OrderItemConstants.TYPE_RETAIL: |
| | | //商品/药品 |
| | | rerailHandleOne(refundRecordItem,commonService); |
| | | break; |
| | | case OrderItemConstants.TYPE_DRUG: |
| | | //处方单药品 |
| | | rerailHandleOne(refundRecordItem,commonService); |
| | | break; |
| | | case OrderItemConstants.TYPE_PROJECT: |
| | | //项目 |
| | | projectHandleOne(refundRecordItem,refundRecord,commonService); |
| | | break; |
| | | case OrderItemConstants.TYPE_PROMOTION: |
| | | //促销 |
| | | handRefundPromotion( refundRecordItem, refundRecord, commonService); |
| | | break; |
| | | case OrderItemConstants.TYPE_CARD: |
| | | //卡项 |
| | | cardHandleOne( refundRecord, refundRecordItem, commonService); |
| | | break; |
| | | case OrderItemConstants.CARD_BAG: |
| | | //卡包 |
| | | handRefundPromotion( refundRecordItem, refundRecord, commonService); |
| | | break; |
| | | default:break; |
| | |
| | | |
| | | //剩余可退款数量 |
| | | if(refundRecordItem.getRefundNum() > orderItem.getHasReNum()){ |
| | | throw new TipsException("作废退款数量不能大于已退款数量!"); |
| | | throw new TipsException(orderItem.getGoodsName()+"["+orderItem.getGoodsNo()+"]"+"作废退款数量不能大于已退款数量!"); |
| | | } |
| | | |
| | | //变更退款子项信息 |
| | |
| | | if (orderItem==null){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到子订单信息"); |
| | | } |
| | | //计算子单是否还有剩余的可扣疗程数 |
| | | if(refundRecordItem.getRefundNum() > orderItem.getHasReNum()){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,orderItem.getGoodsName()+"["+orderItem.getGoodsNo()+"]"+"退款次数大于可退次数[54]!"); |
| | | } |
| | | |
| | | //找到用户项目 |
| | | UserProjectItem userProjectItem = PartialRefundUtil.getUserProject(refundRecordItem.getId(),commonService); |
| | | if (userProjectItem == null) { |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到用户子项项目信息"); |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,orderItem.getGoodsName()+"["+orderItem.getGoodsNo()+"]"+"未找到用户子项项目信息"); |
| | | } |
| | | |
| | | if(userProjectItem.getCancelNum() < refundRecordItem.getRefundNum()){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"作废退款次数大于已退次数!"); |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,orderItem.getGoodsName()+"["+orderItem.getGoodsNo()+"]"+"作废退款次数大于用户项目已退次数!"); |
| | | } |
| | | |
| | | //用户项目操作 |
| | | UserProjectDeductionVo userProjectDeductionVo = UserProjectTool.userProjectDeduction(userProjectItem, UserProjectUsedCon.USED_METHOD_ORDER_REFUND,UserProjectUsedCon.USED_TYPE_RETURN,refundRecordItem.getDeductionTotalUser() |
| | | ,refundRecordItem.getId(),refundRecordItem.getRefundNum(),refundRecord.getInvalidId(),refundRecord.getInvalidName(),refundRecord.getRefundShopId(),refundRecord.getRefundShopName(),"员工备注:"+refundRecord.getInvalidRemarks(),commonService); |
| | | |
| | | //计算子单是否还有剩余的可扣疗程数 |
| | | if(refundRecordItem.getRefundNum() > orderItem.getHasReNum()){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"退款次数大于子单可退次数[54]!"); |
| | | } |
| | | UserProjectTool.userProjectDeduction(userProjectItem, UserProjectUsedCon.USED_METHOD_ORDER_REFUND,UserProjectUsedCon.USED_TYPE_RETURN,refundRecordItem.getDeductionTotalUser() |
| | | ,refundRecordItem.getId(),refundRecordItem.getRealRefundNum(),refundRecord.getInvalidAppId(),refundRecord.getInvalidAppName(),refundRecord.getRefundShopId(),refundRecord.getRefundShopName(),"员工备注:"+refundRecord.getInvalidRemarks(),commonService); |
| | | |
| | | int refundStatus; |
| | | if(refundRecordItem.getRefundNum().equals(orderItem.getHasReNum())){ |
| | |
| | | if (orderItemSon==null){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到二级子订单信息[02]"); |
| | | } |
| | | //计算子单是否还有剩余的可扣疗程数 |
| | | if(refundRecordItemSource.getRefundNum() > orderItemSon.getHasReNum()){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,orderItemSon.getGoodsName()+"["+orderItemSon.getGoodsNo()+"]"+"作废退款次数大于已退次数[56]!"); |
| | | } |
| | | |
| | | UserProjectItem userProjectItem = PartialRefundUtil.getUserProject(orderItemSon.getId(),commonService); |
| | | if(userProjectItem == null){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"用户项目获取失败[06]!"); |
| | | } |
| | | |
| | | //计算子单是否还有剩余的可扣疗程数 |
| | | //比较作废退款数量 |
| | | if(refundRecordItemSource.getRefundNum() > userProjectItem.getCancelNum()){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"作废退款次数大于已退次数[56]!"); |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,orderItemSon.getGoodsName()+"["+orderItemSon.getGoodsNo()+"]"+"作废退款次数大于用户项目已退次数[56]!"); |
| | | } |
| | | |
| | | //处理用户项目,减去用户项目数量 |
| | | UserProjectDeductionVo userProjectDeductionVo= UserProjectTool.userProjectDeduction(userProjectItem,UserProjectUsedCon.USED_METHOD_ORDER_REFUND,UserProjectUsedCon.USED_TYPE_RETURN,refundRecordItemSource.getDeductionTotalUser() |
| | | ,refundRecordItemSource.getId(),refundRecordItemSource.getRefundNum(),refundRecord.getOperatorAppId(),refundRecord.getOperatorAppName(),refundRecord.getRefundShopId(),refundRecord.getRefundShopName(),"员工备注:"+refundRecord.getInvalidRemarks(),commonService); |
| | | UserProjectTool.userProjectDeduction(userProjectItem,UserProjectUsedCon.USED_METHOD_ORDER_REFUND,UserProjectUsedCon.USED_TYPE_RETURN,refundRecordItemSource.getDeductionTotalUser() |
| | | ,refundRecordItemSource.getId(),refundRecordItemSource.getRealRefundNum(),refundRecord.getInvalidAppId(),refundRecord.getInvalidAppName(),refundRecord.getRefundShopId(),refundRecord.getRefundShopName(),"员工备注:"+refundRecord.getInvalidRemarks(),commonService); |
| | | |
| | | int refundStatus; |
| | | if(userProjectItem.getCancelNum().equals(refundRecordItemSource.getRefundNum())){ |
| | | if(orderItemSon.getHasReNum().equals(refundRecordItemSource.getRefundNum())){ |
| | | refundStatus=OrderTotalConstants.STATUS_REFUND_NONE; |
| | | }else{ |
| | | refundStatus=OrderTotalConstants.STATUS_REFUND_PART; |
| | | } |
| | | |
| | | //更新子单信息 |
| | | PartialRefundUtil.updateOrderItemTwo(orderItemSon,refundStatus,refundRecordItemSource.getRealRefundTotal().negate(),-refundRecordItemSource.getRefundNum(),commonService); |
| | | PartialRefundUtil.updateOrderItemTwo(orderItemSon,refundStatus,refundRecordItemSource.getRealRefundTotal().negate(),-refundRecordItemSource.getRealRefundNum(),commonService); |
| | | |
| | | if(refundRecordItem.getType().equals(OrderItemConstants.CARD_BAG)){ |
| | | //是卡包的,刪除卡包使用 |
| | | //是卡包的,找回卡包使用记录 |
| | | userCardUsedHandle(userCardId,orderItemSon.getCardItemInfoId(),orderItemSon.getId(),orderItemSon.getOrderId(),refundRecordItemSource.getRefundNum(),commonService); |
| | | } |
| | | |
| | |
| | | ,CommonService commonService){ |
| | | |
| | | //查出用户,commonId:卡项的组合项标识 |
| | | CardItemInfo cardItemInfo=commonService.selectOneByKey(CardItemInfoMapper.class,cardItemInfoId); |
| | | if(cardItemInfo ==null){ |
| | | CardItemInfo cardItemInfo = commonService.selectOneByKey(CardItemInfoMapper.class,cardItemInfoId); |
| | | if(cardItemInfo == null){ |
| | | logger.error("未找到该卡包的组合项-卡包作废退款失败,userCardId:{},cardItemInfoId:{},sourceId:{},orderId:{},refundNum:{}",userCardId,cardItemInfoId,sourceId,orderId,refundNum); |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到该卡包的组合项"); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | //计算退回的卡次 |
| | | //计算卡次 |
| | | int returnNum; |
| | | //因为有些是算次数抵扣的,所以要算 |
| | | if(CardEquity.EQUITY_TYPE_TIME_CARD.equals(cardEquity.getEquityType())){ |
| | | //次卡:总次数=开单的总次数*每次划扣的次数 |
| | | //次卡:当前需要使用总次数 = 开单的购买数量*每次划扣的次数 |
| | | returnNum= refundNum * cardItemInfo.getEveryDrawNum(); |
| | | }else if(CardEquity.EQUITY_TYPE_N_M.equals(cardEquity.getEquityType())){ |
| | | returnNum = refundNum; |
| | |
| | | if(returnNum > userCardUsedList.size()){ |
| | | logger.error("卡包可退数量错误-卡包作废退款失败,查询语句:{},传入参数:{}",sqlSentence.getSqlSentence(), JSON.toJSONString(sqlSentence.getM())); |
| | | logger.error("卡包可退数量错误-卡包作废退款失败,userCardId:{},cardItemInfoId:{},sourceId:{},orderId:{},refundNum:{},returnNum:{}",userCardId,cardItemInfoId,sourceId,orderId,refundNum,returnNum); |
| | | throw new TipsException("卡包可退数量错误!"); |
| | | throw new TipsException("卡包作废退款次数量大于可退次数!"); |
| | | } |
| | | |
| | | //已经操作数量 |