package com.hx.phip.util.api; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.hx.common.service.CommonService; import com.hx.exception.TipsException; import com.hx.mybatisTool.SqlSentence; import com.hx.phiappt.common.*; import com.hx.phiappt.constants.enums.GroupTypeEnum; import com.hx.phiappt.constants.tool.order.OrderNewUtil; import com.hx.phiappt.constants.tool.order.OrderUtil; import com.hx.phiappt.constants.tool.user.UserChannelTool; import com.hx.phiappt.dao.mapper.*; import com.hx.phiappt.model.*; import com.hx.phiappt.model.activity.ActivityAction; import com.hx.phiappt.model.activity.ActivityRule; import com.hx.phiappt.model.cardItem.CardEquity; import com.hx.phiappt.model.cardItem.CardItem; import com.hx.phiappt.model.cardItem.CardItemInfo; import com.hx.phiappt.model.channels.Channels; import com.hx.phiappt.model.consumables.Consumables; import com.hx.phiappt.model.consumables.ConsumablesAssoc; import com.hx.phiappt.model.guide.VisitRecord; import com.hx.phiappt.model.limit.LimitTotal; import com.hx.phiappt.model.order.*; import com.hx.phiappt.model.project.ProjectInfo; import com.hx.phiappt.model.project.ProjectShopPrice; import com.hx.phiappt.model.project.ProjectSpecValue; import com.hx.phiappt.model.promotion.Promotion; import com.hx.phiappt.model.promotion.PromotionInfo; import com.hx.phiappt.model.specification.Specification; import com.hx.phiappt.model.specification.SpecificationValue; import com.hx.phiappt.model.system.ResendRecord; import com.hx.phip.config.CustomParameter; import com.hx.phip.service.CreateNoService; import com.hx.phip.service.OrdersTotalService; import com.hx.phip.service.ProjectService; import com.hx.phip.tool.AppealTypeTool; import com.hx.phip.tool.user.UserCardTool; import com.hx.phip.vo.AppealTypeVo; import com.hx.phip.vo.user.UserCardItemInfoVo; import com.hx.resultTool.Result; import com.hx.util.DateUtil; import com.hx.util.SimpleTool; import com.hx.util.StringUtils; import com.hz.his.dto.marketing.OrderDiscountDto; import com.hz.his.dto.marketing.OrderPayMarketingDto; import com.hz.his.dto.marketing.RefundProjectDto; import com.hz.his.dto.order.OrderPHisDto; import com.hz.his.dto.order.OrderRiseDto; import com.hz.his.dto.order.OrdersTotalDto; import com.hz.his.feign.service.marketing.MOrderService; import com.platform.constants.PlatformPattern; import com.platform.exception.PlatTipsException; import com.platform.resultTool.PlatformCode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.*; import java.util.stream.Collectors; import static com.hx.phiappt.constants.enums.GroupTypeEnum.PROJECT; /** * 开单接口工具类 * * @Author: zhouxiang * @Date: 2022/09/19/11:57 * @Description: */ public class OrderCreateUtil { private static final Logger logger = LoggerFactory.getLogger(OrderCreateUtil.class); /** * 开单-总订单参数校验 请求时 * * @param orderTotal 总订单 * @return */ public static OrdersTotal checkOrderTotalParam(OrdersTotal orderTotal) { if (StringUtils.isEmpty(orderTotal.getType())) { throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "订单类型为空"); } if (StringUtils.isEmpty(orderTotal.getUserId())) { throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "用户Id为空"); } if (StringUtils.isEmpty(orderTotal.getDeveloperShopId())) { throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "开发人门店id为空"); } if (orderTotal.getOrderClassify() == null) { orderTotal.setOrderClassify(OrderTotalConstants.ORDER_CLASSIFY_STANDARD); }else{ if(!OrderTotalConstants.orderClassifyCheck(orderTotal.getOrderClassify())){ throw new PlatTipsException(PlatformCode.ERROR_TIPS, "订单分类不存在!"); } } return orderTotal; } /** * 开单-默认总订单参数 请求时 * * @param orderTotal 总订单 */ public static void setDefaultOrderTotal(OrdersTotal orderTotal, String appId, String code,User user, CommonService commonService) { SqlSentence sqlSentence = new SqlSentence(); Map map = new HashMap<>(); sqlSentence.setM(map); map.put("isDel", BaseEntity.NO); map.put("isUp", BaseEntity.YES); //处理默认销售平台名称 if (StringUtils.noNull(orderTotal.getSourceCode()) && StringUtils.isEmpty(orderTotal.getSourceName())) { map.put("sourceCode", orderTotal.getSourceCode()); sqlSentence.setSqlSentence("select id,name from platform_application where code = #{m.sourceCode} and isUp=#{m.isUp} and isDel=#{m.isDel} "); List platformApplications = commonService.selectList(PlatformApplicationMapper.class, sqlSentence); if (platformApplications == null || platformApplications.size() == 0) { throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "销售平台编码错误,根据销售平台编码未找到平台信息!"); } else if (platformApplications.size() > 1) { throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "查找出多条平台信息,根据销售平台编码找到多条平台信息!"); } else if (platformApplications.size() == 1) { PlatformApplication platformApplication = platformApplications.get(0); orderTotal.setSourceName(platformApplication == null ? "" : platformApplication.getName()); } } //处理默认开单人名称 if (StringUtils.noNull(orderTotal.getDeveloperId()) && StringUtils.isEmpty(orderTotal.getDeveloperName())) { Employee employee = commonService.selectOneByKeyBlob(EmployeeMapper.class, orderTotal.getDeveloperId()); if (employee == null) { User developerUser = commonService.selectOneByKeyBlob(UserMapper.class, orderTotal.getDeveloperId()); if (developerUser == null) { SysAdmin sysAdmin = commonService.selectOneByKey(SysAdminMapper.class, orderTotal.getDeveloperId()); if (sysAdmin == null) { logger.info("该开单人标识错误,未找到员工、用户、管理员信息,用户标识:{},开单人标识:{}", orderTotal.getUserId(), orderTotal.getDeveloperId()); } else { orderTotal.setDeveloperName(sysAdmin.getName()); } } else { orderTotal.setDeveloperName(developerUser.getName()); } } else { orderTotal.setDeveloperName(employee.getCnName()); } } //处理默认订单渠道标识 if (StringUtils.noNull(orderTotal.getCommonId()) && StringUtils.isEmpty(orderTotal.getCommonName())) { Channels channels = commonService.selectOneByKeyBlob(ChannelsMapper.class, orderTotal.getCommonId()); if (channels == null) { logger.info("订单渠道标识错误,未找到订单渠道标识信息,用户标识:{},开单人标识:{}", orderTotal.getUserId(), orderTotal.getCommonId()); } else { orderTotal.setCommonName(channels.getName()); } } // 处理默认订单推荐标识 if (StringUtils.noNull(orderTotal.getInviteeId())) { // 用户推荐人处理 if (orderTotal.getInviteeType() == null || UserChannelType.CATEGORY_MEMBERS.equals(orderTotal.getInviteeType())) { orderTotal.setInviteeType(UserChannelType.CATEGORY_MEMBERS); User inviteeUser = commonService.selectOneByKeyBlob(UserMapper.class, orderTotal.getInviteeId()); if (inviteeUser == null) { logger.info("订单推荐标识错误,未找到推荐人(用户)信息,用户标识:{},开单人标识:{}", orderTotal.getUserId(), orderTotal.getInviteeId()); } else { orderTotal.setInviteeName(inviteeUser.getName()); } } else { // 员工推荐人处理 orderTotal.setInviteeType(UserChannelType.CATEGORY_EMPLOYEE); Employee inviteeEmployee = commonService.selectOneByKeyBlob(EmployeeMapper.class, orderTotal.getInviteeId()); if (inviteeEmployee == null) { logger.info("订单推荐标识错误,未找到推荐人(员工)信息,用户标识:{},开单人标识:{}", orderTotal.getUserId(), orderTotal.getInviteeId()); } else { orderTotal.setInviteeName(inviteeEmployee.getCnName()); } } } //处理默认订单其他信息 if (orderTotal.getOrderInfo() == null) { OrderInfo orderInfo = new OrderInfo(); orderInfo.setIsEmployeeDiscount(BaseEntity.NO); orderInfo.setIsWholeDiscount(BaseEntity.NO); orderInfo.setDiscount(new BigDecimal(100)); orderTotal.setOrderInfo(orderInfo); } //设置平台标识和平台编码 orderTotal.setAppId(appId); orderTotal.setAppIdCode(code); if(orderTotal.getActivityIds()==null || orderTotal.getActivityIds().size()==0){ orderTotal.setActivityIds(new ArrayList<>()); } //设置用户名称 orderTotal.setUserName(user.getName()); /** * 判断是否是转疗 * 1、用户的所属门店和这张订单的门店不一致就是转疗,user:shopId字段,shopId为空不是转疗(禅道327) */ if(StringUtils.noNull(user.getShopId()) && !user.getShopId().equals(orderTotal.getDeveloperShopId())){ orderTotal.setIsSwitch(BaseEntity.YES); } /** * 客户成交标签(首次成交、复购),只有这两种情况,用string类型存文字形式(和爷说) */ //判断该用户是否结账成功的订单数 map.clear(); map.put("userId",user.getId()); map.put("isDel", BaseEntity.NO); map.put("payStatus", OrderTotalConstants.PAY_STATUS_SUC); sqlSentence.setSqlSentence(" userId=#{m.userId} and payStatus=#{m.payStatus} and isDel=#{m.isDel}"); int paySucNum = commonService.selectCount(OrdersTotalMapper.class, sqlSentence); if(paySucNum==0){ orderTotal.setCjLabel(OrderTotalConstants.LABEL_FIRST); }else if(paySucNum >0){ orderTotal.setCjLabel(OrderTotalConstants.LABEL_AFTER); } } /** * 开单-子订单参数校验 请求时 * * @param orderItem 一级子订单 * @return */ public static List checkOrderItem(List orderItem, String type) { if ((orderItem == null || orderItem.size() == 0) && !OrderItemConstants.TYPE_RECHARGE.equals(type)) { throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "订单的子订单不能为空"); } orderItem.forEach(o -> { if (StringUtils.isEmpty(o.getType())) { throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "订单的子订单商品类型为空"); } if (o.getBuyNum() == null) { throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "订单的子订单购买数量为空"); } if (StringUtils.isEmpty(o.getCommonId())) { throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "订单的子订单项目id/商品id为空"); } if (o.getDiscount() == null) { throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "折扣为空,默认:100"); } }); return orderItem; } /** * 开单-业务逻辑判断(限制、订单重复等判断) * * @param ordersTotal */ public static void businessJudge(OrdersTotal ordersTotal,PlatformApplication platformApplication, List items, User user, Shop shop, OrdersTotalService ordersTotalService, CommonService commonService) { //判断应用来源appId和订单编号是否重复 List ordersTotals = ordersTotalService.selectAppIdAndNumber(ordersTotal.getOrderNo(), ordersTotal.getAppId()); if (ordersTotals != null && ordersTotals.size() > 0) { throw new PlatTipsException("997", "来源应用appId重复:" + ordersTotal.getAppId() + ",请检查"); } //判断第三方订单号是否为空,如果销售平台不是p-his、his、guide订单标号抛错 List platformType = Arrays.asList(PlatformConstants.TYPE_PLATFORM_HIS, PlatformConstants.TYPE_PLATFORM_PHIS, PlatformConstants.TYPE_PLATFORM_GUIDE); if(!platformType.contains(ordersTotal.getAppIdCode()) && StringUtils.isEmpty(ordersTotal.getSourceCode())){ throw new PlatTipsException(PlatformCode.ERROR_TIPS, "创建订单:请传销售平台的订单编号!" ); } //判断第三方订单号是否重复 if (StringUtils.noNull(ordersTotal.getSourceOrderNo())) { List list = ordersTotalService.selectCheckSourceNo(ordersTotal); if (list != null && list.size() > 0) { throw new PlatTipsException("998", "第三方订单号重复:" + ordersTotal.getSourceOrderNo() + ",请检查"); } } //判断康博佳订单是否重复 List koapOrder = ordersTotalService.selectKoapOrder(ordersTotal.getKoapOrderId()); if (koapOrder != null && koapOrder.size() > 0) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "创建订单:不能重复创建康博佳订单,康博佳订单标识:" + ordersTotal.getKoapOrderId()); } //查询开发门店 Shop developerShop = commonService.selectOneByKey(ShopMapper.class,ordersTotal.getDeveloperShopId()); if (developerShop ==null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "业务逻辑判断:未找到开单门店信息!" + ordersTotal.getDeveloperShopId()); } SqlSentence sqlSentence; Map objectMap; for (OrderItem vo : items) { switch (vo.getType()){ case OrderItemConstants.TYPE_PROJECT: sqlSentence = new SqlSentence(); objectMap=new HashMap<>(); sqlSentence.setM(objectMap); //限制项目 limitProject(user, developerShop, commonService, sqlSentence, objectMap, vo); break; case OrderItemConstants.TYPE_RETAIL: sqlSentence = new SqlSentence(); objectMap=new HashMap<>(); sqlSentence.setM(objectMap); //限制商品 limitConsumables(user, developerShop, commonService, sqlSentence, objectMap, vo); break; case OrderItemConstants.TYPE_CARD: sqlSentence = new SqlSentence(); objectMap=new HashMap<>(); sqlSentence.setM(objectMap); //限制卡项 limitCard(user, developerShop,platformApplication, commonService, sqlSentence, objectMap, vo); break; case OrderItemConstants.TYPE_PROMOTION: sqlSentence = new SqlSentence(); objectMap=new HashMap<>(); sqlSentence.setM(objectMap); //限制促销 limitPromotion(user, developerShop, platformApplication, commonService, sqlSentence, objectMap, vo); break; case OrderItemConstants.CARD_BAG:break; //限制卡包,暂时不处理 case OrderItemConstants.TYPE_INTEGRAL: sqlSentence = new SqlSentence(); objectMap=new HashMap<>(); sqlSentence.setM(objectMap); //限制项目 limitProject(user, developerShop, commonService, sqlSentence, objectMap, vo); break; default:break; } } } /** * 开单-获取平台平台应用信息 * * @param ordersTotal 总订单信息 * @param commonService * @return */ public static PlatformApplication getPlatformApplication(OrdersTotal ordersTotal, CommonService commonService) { SqlSentence sqlSentence=new SqlSentence(); Map appIdMap = new HashMap<>(); sqlSentence.setM(appIdMap); PlatformApplication platformApplication ; if (StringUtils.isEmpty(ordersTotal.getSourceCode())) { appIdMap.put("appId", ordersTotal.getAppId()); sqlSentence.setSqlSentence("SELECT * FROM platform_application WHERE appId =#{m.appId} and isDel=0 and isUp=1"); platformApplication = commonService.selectOne(PlatformApplicationMapper.class, sqlSentence); } else { appIdMap.put("isDel", BaseEntity.NO); appIdMap.put("isUp", BaseEntity.YES); appIdMap.put("sourceCode", ordersTotal.getSourceCode()); sqlSentence.setSqlSentence("select * from platform_application where appId = #{m.sourceCode} and isUp=#{m.isUp} and isDel=#{m.isDel} "); platformApplication = commonService.selectOne(PlatformApplicationMapper.class, sqlSentence); } return platformApplication; } /** * 根据请求参数一级子订单,处理项目、商品、卡项、卡包、促销操作,生成一级子订单,计算总订单金额信息 * @param ordersTotal 总订单 * @param items 一级子订单 * @param totalPrice 订单总金额 * @param shouldOrderTotal 订单应付总金额 * @param discountTotal 订单折扣总金额 * @param commonService 映射 * @param discountAlgorithm 折扣算法 * @param createNoService 映射 * @return 数据 */ public static Map handOrderItem(OrdersTotal ordersTotal,Shop shop,String opShopId, List items,BigDecimal totalPrice,BigDecimal shouldOrderTotal, BigDecimal discountTotal,BigDecimal oriTotal,int discountAlgorithm,CommonService commonService,CreateNoService createNoService) { BigDecimal buyNum; //用来封装规格json集合 JSONArray jsonObject ; //一级子订单规格的map Map map=new HashMap<>(); BigDecimal preferentialTotalAll = BigDecimal.ZERO; //根据请求参数一级子订单,处理项目、商品、卡项、卡包、促销等操作,生成一级子订单,计算总订单金额信息 for(OrderItem vo:items){ jsonObject = new JSONArray(); buyNum=new BigDecimal(vo.getBuyNum()); //生成子订单编号,并设置值 String orderNum = createNoService.createOrderNo("SO", 16, "yyyyMMdd");//订单编号 vo.setOrderNo(orderNum); //折扣方式 vo.setDiscountAlgorithm(discountAlgorithm); //根据请求参数子订单根据类型做出对应处理 if(OrderItemConstants.TYPE_PROJECT.equals(vo.getType())){ //处理项目 Map bigDecimalMap = handleProject(jsonObject, map, vo, discountTotal, buyNum,commonService); discountTotal=bigDecimalMap.get("discountTotal"); }else if(OrderItemConstants.TYPE_RETAIL.equals(vo.getType())){ //处理商品 Map bigDecimalMap =handleConsumables(shop,null,jsonObject, map, vo, discountTotal, buyNum,commonService); discountTotal=bigDecimalMap.get("discountTotal"); }else if(OrderItemConstants.TYPE_CARD.equals(vo.getType()) ){ //处理卡项 Map bigDecimalMap =handleCardItem(vo, discountTotal, buyNum,commonService); discountTotal=bigDecimalMap.get("discountTotal"); }else if(OrderItemConstants.TYPE_PROMOTION.equals(vo.getType())){ //处理促销 Map bigDecimalMap =handlePromotion(vo, discountTotal, buyNum, commonService); discountTotal=bigDecimalMap.get("discountTotal"); }else if(OrderItemConstants.CARD_BAG.equals(vo.getType())){ //处理卡包 Map bigDecimalMap =handleCardBag(vo, commonService); discountTotal=bigDecimalMap.get("discountTotal"); }else if(OrderItemConstants.TYPE_INTEGRAL.equals(vo.getType())){ //处理积分 Map bigDecimalMap =handleIntegral(jsonObject, map, vo, discountTotal, buyNum,commonService); discountTotal=bigDecimalMap.get("discountTotal"); }else if(OrderItemConstants.TYPE_DRUG.equals(vo.getType())){ //处理药品 Map bigDecimalMap =handleConsumables(shop,opShopId,jsonObject, map, vo, discountTotal, buyNum,commonService); discountTotal=bigDecimalMap.get("discountTotal"); }else if(OrderItemConstants.TYPE_COUPON.equals(vo.getType())) { //处理优惠券商品 Map bigDecimalMap = handleConsumables(shop,null, jsonObject, map, vo, discountTotal, buyNum, commonService); discountTotal = bigDecimalMap.get("discountTotal"); }else if(OrderItemConstants.TYPE_TRANSITION_GOODS.equals(vo.getType())) { //过渡商品,没有商品存储,只生成数据 transitionGoodsHandle(vo); } //-----积分处理注意,这是第三方传参,如果有传值,那么就以这个为主 if(vo.getOrderItemIntegral() != null){ if(vo.getOrderItemIntegral().getSaleIntegral() == null && vo.getOrderItemIntegral().getSaleIntegral().compareTo(BigDecimal.ZERO) < 0){ throw new TipsException("售价积分必传或者数据有误!"); } if(vo.getOrderItemIntegral().getOriginalIntegral() == null && vo.getOrderItemIntegral().getOriginalIntegral().compareTo(BigDecimal.ZERO) < 0){ throw new TipsException("原价积分必传或者数据有误!"); } if(vo.getOrderItemIntegral().getSaleTotal() == null && vo.getOrderItemIntegral().getSaleTotal().compareTo(BigDecimal.ZERO) < 0){ throw new TipsException("售价总积分必传或者数据有误!"); } if(vo.getOrderItemIntegral().getOriginalTotal() == null && vo.getOrderItemIntegral().getOriginalTotal().compareTo(BigDecimal.ZERO) < 0){ throw new TipsException("原价总积分必传或者数据有误!"); } vo.setOriginalIntegral(vo.getOrderItemIntegral().getOriginalIntegral()); vo.setProIntegral(vo.getOrderItemIntegral().getSaleIntegral()); vo.setSellPoints(vo.getOrderItemIntegral().getSaleIntegral()); vo.setOriIntegralTotal(vo.getOrderItemIntegral().getOriginalTotal()); vo.setProIntegralTotal(vo.getOrderItemIntegral().getSaleTotal()); vo.setTotalPoints(vo.getOrderItemIntegral().getSaleTotal()); vo.setShouldTotalPoints(vo.getOrderItemIntegral().getSaleTotal()); vo.setActualTotalPoints(vo.getOrderItemIntegral().getSaleTotal()); } //累加总订单售价总金额 totalPrice=totalPrice.add(vo.getTotal()).setScale(2,RoundingMode.HALF_UP); //订单原价总金额 oriTotal= oriTotal.add(vo.getOriPrice().multiply(new BigDecimal(vo.getBuyNum()))).setScale(2,RoundingMode.HALF_UP); //累加总订单实付金额 shouldOrderTotal=shouldOrderTotal.add(vo.getActualTotal()).setScale(2,RoundingMode.HALF_UP); //累加总订单优惠福利总金额 preferentialTotalAll = preferentialTotalAll.add(vo.getPreferentialTotal()).setScale(2,RoundingMode.HALF_UP); //----总订单的值计算 //--积分值赋值 ordersTotal.setDiscountIntegral(ordersTotal.getDiscountIntegral().add(vo.getDiscountIntegral())); ordersTotal.setOriIntegralTotal(ordersTotal.getOriIntegralTotal().add(vo.getOriIntegralTotal())); ordersTotal.setProIntegralTotal(ordersTotal.getProIntegralTotal().add(vo.getProIntegralTotal())); ordersTotal.setTotalPoints(ordersTotal.getTotalPoints().add(vo.getTotalPoints())); ordersTotal.setShouldTotalPoints(ordersTotal.getShouldTotalPoints().add(vo.getShouldTotalPoints())); ordersTotal.setActualTotalPoints(ordersTotal.getActualTotalPoints().add(vo.getActualTotalPoints())); } ordersTotal.setTotal(totalPrice); ordersTotal.setPreferentialTotal(preferentialTotalAll); ordersTotal.setDiscountPrice(ordersTotal.getPreferentialTotal()); //返回数据 map.clear(); // map.put("items",items); map.put("totalPrice",totalPrice); map.put("shouldOrderTotal",shouldOrderTotal); map.put("discountTotal",discountTotal); map.put("oriTotal",oriTotal); return map; } /** * 开单-处理项目方法 * @param jsonObject 规格json * @param map 参数集合 * @param vo 一级子订单 * @param discountTotal 折扣总金额 * @param buyNum 购买次数 * @return */ public static Map handleProject(JSONArray jsonObject, Map map, OrderItem vo, BigDecimal discountTotal, BigDecimal buyNum, CommonService commonService) { SqlSentence sqlSentence=new SqlSentence(); Map objectMap=new HashMap<>(); sqlSentence.setM(objectMap); objectMap.put("commonId",vo.getCommonId()); objectMap.put("isDel",BaseEntity.NO); Project project=commonService.selectOneByKeyBlob(ProjectMapper.class,vo.getCommonId()); if(project==null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"找不到项目:"+vo.getCommonId()); } //计算项目价格,如果总订单有康博佳标识代表是康博佳订单不需要任何处理直接拿去康博佳的总金额,每个门店价格不一样,如果没有设置门店价格就使用项目售价 // BigDecimal price=priceJudge(ordersTotal, commonService,project.getId(),shopId); // project.setPrice(BigDecimal.ZERO.compareTo(price)==0?project.getPrice():price); if(project.getPrice()==null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"项目:"+project.getName()+",没有销售价格,请填写销售单价再进行创建订单"); } if(project.getIsUp()==BaseEntity.NO){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"项目:"+project.getName()+",该项目已下架"); } if(project.getIsDel()==BaseEntity.YES){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"项目:"+project.getName()+",该项目已删除"); } //计算订单金额信息 //一级子订单:售价=项目售价*折扣 BigDecimal actualTotal; //折扣方式 if(vo.getDiscountAlgorithm() == OrderItemConstants.DISCOUNT_ALGORITHM_TOTAL){ actualTotal = project.getPrice(); }else{ actualTotal = project.getPrice().multiply(vo.getDiscount().divide(new BigDecimal(100),15,RoundingMode.HALF_UP)).setScale(2,RoundingMode.HALF_UP); } //一级子订单金额信息设值 //设置原价,原价=项目的销售价格 vo.setOriPrice(project.getOriginalPrice()); //设置项目、商品、促销、卡项现价的售价 vo.setProPrice(project.getPrice()); //设置订单售价, 售价=项目的销售价格*折扣 vo.setCurPrice(actualTotal); if(vo.getDiscountAlgorithm() == OrderItemConstants.DISCOUNT_ALGORITHM_TOTAL){ //设置优惠前小计,优惠前小计=售价* 商品数量 vo.setTotal(vo.getCurPrice().multiply(buyNum)); vo.setTotal(vo.getTotal().multiply(vo.getDiscount().divide(new BigDecimal(100),15,RoundingMode.HALF_UP)).setScale(2,RoundingMode.HALF_UP)); vo.setDiscountMoney(vo.getTotal().divide(buyNum,4,RoundingMode.HALF_UP)); }else{ //设置优惠前小计,优惠前小计=售价* 商品数量 vo.setTotal(vo.getCurPrice().multiply(buyNum)); vo.setDiscountMoney(vo.getCurPrice()); } //计算折扣金额 vo.setDiscountOrderPrice(vo.getProPrice().multiply(BigDecimal.valueOf(vo.getBuyNum()).setScale(2,RoundingMode.HALF_UP)).subtract(vo.getTotal())); //折扣金额汇总 discountTotal=discountTotal.add(vo.getDiscountOrderPrice()).setScale(2,RoundingMode.HALF_UP); //设置子订单优惠券抵扣金额,开单不知道是否使用优惠券,默认为0 vo.setCouponTotal(BigDecimal.ZERO); //优惠福利总金额 if(vo.getPreferentialTotal() == null){ vo.setPreferentialTotal(BigDecimal.ZERO); } //后续复购活动开单会先算优惠,所以可能不是0 vo.setDiscountPrice(vo.getCouponTotal().add(vo.getPreferentialTotal()).setScale(2, RoundingMode.HALF_UP)); //设置子订单优惠后小计,优惠后小计=优惠前小计-优惠券抵扣金额 vo.setActualTotal(vo.getTotal().subtract(vo.getDiscountPrice())); //设置用户已支付总金额,开单默认为0 vo.setUserPaidTotal(BigDecimal.ZERO); //设置item总积分 vo.setTotalPoints(BigDecimal.ZERO); //设置售价积分 vo.setSellPoints(BigDecimal.ZERO); sqlSentence.setSqlSentence("select * from project_info where projectId=#{m.commonId} and isDel=#{m.isDel} "); ProjectInfo projectInfo=commonService.selectOne(ProjectInfoMapper.class,sqlSentence); //一级子订单商品信息设值 //设置一级子订单规格,如果项目规格json没有值,则自动封装json规格(内容默认:规格值、单位、身体部位、医生资质),否则就采用项目规格json sqlSentence.setSqlSentence("select * from project_spec_value where projectId=#{m.commonId} and isDel=#{m.isDel} "); List projectSpecValues = commonService.selectList(ProjectSpecValueMapper.class, sqlSentence); if(projectSpecValues!=null && projectSpecValues.size()>0){ for (ProjectSpecValue projectSpecValue : projectSpecValues) { Map specMap=new HashMap<>(); SpecificationValue specificationValue=commonService.selectOneByKeyBlob(SpecificationValueMapper.class,projectSpecValue.getSpecValue()); if(specificationValue!=null){ Specification specification=commonService.selectOneByKeyBlob(SpecificationMapper.class,specificationValue.getSpecificationId()); if(specification!=null){ specMap.put("specsTitle",specification.getSpecName()); } specMap.put("specsValue",specificationValue.getSpecValueName()); specMap.put("specsId",specificationValue.getId()); specMap.put("unit",""); } jsonObject.add(specMap); } }else{ map.put("specsTitle","规格"); map.put("specsValue",project==null?"":StringUtils.isEmpty(project.getSpecification())?"":project.getSpecification()); map.put("unit",project==null?"":StringUtils.isEmpty(project.getUnit())?"":project.getUnit()); map.put("bodyPartName",projectInfo==null?"":StringUtils.isEmpty(projectInfo.getBodyPartName())?"":projectInfo.getBodyPartName()); map.put("doctorQualification",projectInfo==null?"":StringUtils.isEmpty(projectInfo.getDoctorQualification())?"":projectInfo.getDoctorQualification()); jsonObject.add(map); } //设置一级子订单规格信息 vo.setSpecs(jsonObject.isEmpty()?"[]":jsonObject.toJSONString()); vo.setSpecsName(StringUtils.isEmpty(project.getSpecification())?"":project.getSpecification()); if(projectInfo!=null){ if(StringUtils.noNull(projectInfo.getBodyPartId())){ vo.setBodyPartsId(projectInfo.getBodyPartId()); } if(StringUtils.noNull(projectInfo.getBodyPartName())){ vo.setBodyPartsName(projectInfo.getBodyPartName()); } if(StringUtils.noNull(projectInfo.getExecutiveQualificationCode())){ vo.setAptitudeNo(projectInfo.getExecutiveQualificationCode()); } if(StringUtils.noNull(projectInfo.getExecutiveQualificationName())){ vo.setAptitudeName(projectInfo.getExecutiveQualificationName()); } if(StringUtils.noNull(projectInfo.getDoctorQualification())){ vo.setDoctorQualification(projectInfo.getDoctorQualification()); } } //设置项目编号 vo.setGoodsNo(project.getCoding()); //设置项目名称 vo.setGoodsName(project.getName()); //设置项目主图,目前没有项目图片,默认为空字符串 vo.setGoodsImage(""); //一级子订单疗程次数设值 //荣爷说项目疗程次数为空值,默认为1 //设置一级子订单单次疗程数量,该值获取的是项目的疗程次数(为了计算订单的总疗程次数) if(project.getIsExecutable()!=null && project.getIsExecutable()==BaseEntity.YES){ Integer useredTotal= project.getTreatmentItemsNum() == null ?1: project.getTreatmentItemsNum() == 0 ?1:project.getTreatmentItemsNum(); vo.setSingle(useredTotal);//订单单次疗程数量 }else if(project.getIsExecutable()!=null && project.getIsExecutable()==BaseEntity.NO){ Integer useredTotal= project.getTreatmentItemsNum() == null ?0:project.getTreatmentItemsNum(); vo.setSingle(useredTotal);//订单单次疗程数量 }else{ vo.setSingle(0);//订单单次疗程数量 } //设置总次疗程次数,单次疗程次数*购买的总量(结账完成未执行划口剩余次数就是获取该总疗程次数字段),疗程总次数=订单单次疗程数量* 订单购买数量 vo.setUsedTotal(vo.getSingle()*vo.getBuyNum()); Map moneyMap=new HashMap<>(); moneyMap.put("discountTotal",discountTotal); return moneyMap; } /** * 开单-处理商品方法 * @param jsonObject 规格json * @param map 参数集合 * @param vo 一级子订单 * @param discountTotal 折扣总金额TYPE_VIRTUAL_GOODS * @param buyNum 购买次数 * @return */ public static Map handleConsumables(Shop shop,String opShopId,JSONArray jsonObject, Map map, OrderItem vo, BigDecimal discountTotal,BigDecimal buyNum, CommonService commonService) { Consumables consumables = commonService.selectOneByKey(ConsumablesMapper.class,vo.getCommonId()); if(consumables==null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"找不到商品:"+vo.getCommonId()); } if(consumables.getPrice()==null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"商品:["+consumables.getName()+"]没有销售价格,请填写销售单价在进行创建订单"); } if(consumables.getIsUp()==BaseEntity.NO){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"该商品:["+consumables.getName()+"]已下架"); } if(consumables.getIsDel()==BaseEntity.YES){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"该商品:["+consumables.getName()+"]已删除"); } if(OrderItemConstants.TYPE_DRUG.equals(vo.getType())){ //获取门店价格 SqlSentence sqlSentence = new SqlSentence(); Map sqlMap = new HashMap<>(); StringBuilder sql = new StringBuilder(); sqlMap.put("consumableId",vo.getCommonId()); sqlMap.put("shopId",opShopId); sqlMap.put("isUp",ProjectShopPrice.YES); sqlMap.put("isDel",ProjectShopPrice.NO); sql.append(" SELECT id,price FROM project_shop_price WHERE isDel = #{m.isDel} "); sql.append(" AND isUp = #{m.isUp} AND commonId = #{m.consumableId} AND shopId = #{m.shopId} "); sqlSentence.sqlSentence(sql.toString(), sqlMap); List priceList = commonService.selectList(ProjectShopPriceMapper.class, sqlSentence); if (priceList != null && priceList.size() > 0){ if (priceList.size() > 1){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"当前处方药品列表中存在多个门店价格信息!"); } ProjectShopPrice projectShopPrice = priceList.get(0); consumables.setPrice(projectShopPrice.getPrice()); } } //计算订单金额信息 //一级子订单:售价=商品售价*购买数量*折扣 BigDecimal actualTotal; if(vo.getDiscountAlgorithm() == OrderItemConstants.DISCOUNT_ALGORITHM_TOTAL){ actualTotal = consumables.getPrice(); }else{ actualTotal = consumables.getPrice().multiply(vo.getDiscount().divide(new BigDecimal(100),15,RoundingMode.HALF_UP)).setScale(2,RoundingMode.HALF_UP); } //一级子订单金额信息设值 //设置原价,原价=商品的销售价格 vo.setOriPrice(consumables.getPrice()); //设置项目、商品、促销、卡项现价的售价 vo.setProPrice(consumables.getPrice()); //设置售价, 售价=项目的销售价格*购买数量*折扣 vo.setCurPrice(actualTotal); if(vo.getDiscountAlgorithm() == OrderItemConstants.DISCOUNT_ALGORITHM_TOTAL){ //设置优惠前小计,优惠前小计=售价* 商品数量 vo.setTotal(vo.getCurPrice().multiply(buyNum)); vo.setTotal(vo.getTotal().multiply(vo.getDiscount().divide(new BigDecimal(100),15,RoundingMode.HALF_UP)).setScale(2,RoundingMode.HALF_UP)); vo.setDiscountMoney(vo.getTotal().divide(buyNum,4,RoundingMode.HALF_UP)); }else{ //设置优惠前小计,优惠前小计=售价* 商品数量 vo.setTotal(vo.getCurPrice().multiply(buyNum)); vo.setDiscountMoney(vo.getCurPrice()); } //计算折扣金额 vo.setDiscountOrderPrice(vo.getProPrice().multiply(BigDecimal.valueOf(vo.getBuyNum()).setScale(2,RoundingMode.HALF_UP)).subtract(vo.getTotal())); //折扣金额汇总 discountTotal=discountTotal.add(vo.getDiscountOrderPrice()).setScale(2,RoundingMode.HALF_UP); //设置子订单优惠券抵扣金额,开单不知道是否使用优惠券,默认为0 vo.setCouponTotal(BigDecimal.ZERO); //优惠福利总金额 if(vo.getPreferentialTotal() == null){ vo.setPreferentialTotal(BigDecimal.ZERO); } //后续复购活动开单会先算优惠,所以可能不是0 vo.setDiscountPrice(vo.getCouponTotal().add(vo.getPreferentialTotal()).setScale(2, RoundingMode.HALF_UP)); //设置子订单优惠后小计,优惠后小计=优惠前小计-优惠券抵扣金额 vo.setActualTotal(vo.getTotal().subtract(vo.getDiscountPrice())); //设置用户已支付总金额,开单默认为0 vo.setUserPaidTotal(BigDecimal.ZERO); //设置item总积分 //如果为空则使用商品售价积分乘以购买数量,不为空则使用已有值 if(vo.getTotalPoints() == null){ vo.setTotalPoints(consumables.getIntegral().multiply(buyNum)); } //应付积分 = 总积分 vo.setShouldTotalPoints(vo.getTotalPoints()); //设置售价积分 vo.setSellPoints(consumables.getIntegral()); //一级子订单商品信息设值 //设置一级子订单商品规格 if(StringUtils.noNull(consumables.getSpec())){ Map specMap=new HashMap<>(); specMap.put("specsId",""); specMap.put("specsTitle","规格"); specMap.put("specsValue",consumables.getSpec()); specMap.put("unit",""); jsonObject.add(specMap); } if(StringUtils.noNull(consumables.getPackSpec())){ Map packSpecMap=new HashMap<>(); packSpecMap.put("specsId",""); packSpecMap.put("specsTitle","包装规格"); packSpecMap.put("specsValue",consumables.getPackSpec()); packSpecMap.put("unit",""); jsonObject.add(packSpecMap); } if(StringUtils.noNull(consumables.getzSpec())){ Map zSpecMap=new HashMap<>(); zSpecMap.put("specsId",""); zSpecMap.put("specsTitle","中药规格"); zSpecMap.put("specsValue",consumables.getzSpec()); zSpecMap.put("unit",""); jsonObject.add(zSpecMap); } if(StringUtils.noNull(consumables.getUnitIdCode())){ Map unitIdCodeSpecMap=new HashMap<>(); unitIdCodeSpecMap.put("specsId",""); unitIdCodeSpecMap.put("specsTitle","单位(字典编码)"); unitIdCodeSpecMap.put("specsValue",consumables.getUnitIdCode()); unitIdCodeSpecMap.put("unit",""); jsonObject.add(unitIdCodeSpecMap); } if(StringUtils.noNull(consumables.getUnitName())){ Map unitNameSpecMap=new HashMap<>(); unitNameSpecMap.put("specsId",""); unitNameSpecMap.put("specsTitle","单位名称"); unitNameSpecMap.put("specsValue",consumables.getUnitName()); unitNameSpecMap.put("unit",""); jsonObject.add(unitNameSpecMap); } if(StringUtils.noNull(consumables.getzUnitName())){ Map zUnitNameSpecMap=new HashMap<>(); zUnitNameSpecMap.put("specsId",""); zUnitNameSpecMap.put("specsTitle","中药单位"); zUnitNameSpecMap.put("specsValue",consumables.getzUnitName()); zUnitNameSpecMap.put("unit",""); jsonObject.add(zUnitNameSpecMap); } if(StringUtils.noNull(consumables.getPeruseUnit())){ Map peruseUnitSpecMap=new HashMap<>(); peruseUnitSpecMap.put("specsId",""); peruseUnitSpecMap.put("specsTitle","每次用药单位"); peruseUnitSpecMap.put("specsValue",consumables.getPeruseUnit()); peruseUnitSpecMap.put("unit",""); jsonObject.add(peruseUnitSpecMap); } if(consumables.getPeruseCount()!=null){ Map peruseCountSpecMap=new HashMap<>(); peruseCountSpecMap.put("specsId",""); peruseCountSpecMap.put("specsTitle","每次用药数量"); peruseCountSpecMap.put("specsValue",consumables.getPeruseCount()); peruseCountSpecMap.put("unit",""); jsonObject.add(peruseCountSpecMap); } if(consumables.getUsageDays()!=null){ Map usageDaysSpecMap=new HashMap<>(); usageDaysSpecMap.put("specsId",""); usageDaysSpecMap.put("specsTitle","用药天数"); usageDaysSpecMap.put("specsValue",consumables.getUsageDays()); usageDaysSpecMap.put("unit",""); jsonObject.add(usageDaysSpecMap); } if(consumables.getTerm()!=null){ Map termSpecMap=new HashMap<>(); termSpecMap.put("specsId",""); termSpecMap.put("specsTitle","保质期,单位月"); termSpecMap.put("specsValue",consumables.getTerm()); termSpecMap.put("unit",""); jsonObject.add(termSpecMap); } vo.setSpecs(jsonObject.isEmpty()?"[]":jsonObject.toJSONString()); vo.setSpecsName(StringUtils.isEmpty(consumables.getSpec())?"":consumables.getSpec()); //设置一级子订单商品编号 vo.setGoodsNo(consumables.getSerialNumber()); //设置一级子订单商品名称 vo.setGoodsName(consumables.getName()); //设置一级子订单商品项目主图 vo.setGoodsImage(""); //设置一级子订单商品单次疗程数量,默认为0,商品没有单次疗程数量 //一级子订单商品疗程次数信息设值 vo.setSingle(0); //设置一级子订单商品总次疗程次数,单次疗程次数*购买的总量,商品没有单次疗程数量 vo.setUsedTotal(vo.getSingle()*vo.getBuyNum()); Map moneyMap=new HashMap<>(); moneyMap.put("discountTotal",discountTotal); return moneyMap; } /** * 开单-处理过渡商品方法 * @param orderItem 子订单信息 */ public static void transitionGoodsHandle(OrderItem orderItem) { if(orderItem.getOrderTransitionGoods() == null){ throw new TipsException("过渡商品信息必填!"); } if(StringUtils.isNull(orderItem.getOrderTransitionGoods().getGoodsId())){ throw new TipsException("过渡商品标识必填!"); } if(StringUtils.isNull(orderItem.getOrderTransitionGoods().getGoodsNo())){ throw new TipsException("过渡商品编号必填!"); } if(StringUtils.isNull(orderItem.getOrderTransitionGoods().getGoodsName())){ throw new TipsException("过渡商品名称必填!"); } if(orderItem.getOrderTransitionGoods().getOriPrice() == null && orderItem.getOrderTransitionGoods().getOriPrice().compareTo(BigDecimal.ZERO) < 0){ throw new TipsException("过渡商品原价必填或者数据有误!"); } if(orderItem.getOrderTransitionGoods().getCurPrice() == null && orderItem.getOrderTransitionGoods().getCurPrice().compareTo(BigDecimal.ZERO) < 0){ throw new TipsException("过渡商品售价必填或者数据有误!"); } if(orderItem.getOrderTransitionGoods().getOriTotal() == null && orderItem.getOrderTransitionGoods().getOriTotal().compareTo(BigDecimal.ZERO) < 0){ throw new TipsException("过渡商品原价总价必填或者数据有误!"); } if(orderItem.getOrderTransitionGoods().getCurTotal() == null && orderItem.getOrderTransitionGoods().getCurTotal().compareTo(BigDecimal.ZERO) < 0){ throw new TipsException("过渡商品售价总价必填或者数据有误!"); } //一级子订单金额信息设值 //设置原价,原价=商品的销售价格 orderItem.setOriPrice(orderItem.getOrderTransitionGoods().getOriPrice()); //设置项目、商品、促销、卡项现价的售价 orderItem.setProPrice(orderItem.getOrderTransitionGoods().getCurPrice()); //设置售价, 售价=项目的销售价格*购买数量*折扣 orderItem.setCurPrice(orderItem.getOrderTransitionGoods().getCurPrice()); //设置优惠前小计,优惠前小计=售价* 商品数量 orderItem.setTotal(orderItem.getOrderTransitionGoods().getCurTotal()); //设置子订单优惠券抵扣金额,开单不知道是否使用优惠券,默认为0 orderItem.setCouponTotal(BigDecimal.ZERO); //优惠福利总金额 if(orderItem.getPreferentialTotal() == null){ orderItem.setPreferentialTotal(BigDecimal.ZERO); } //后续复购活动开单会先算优惠,所以可能不是0 orderItem.setDiscountPrice(orderItem.getCouponTotal().add(orderItem.getPreferentialTotal()).setScale(2, RoundingMode.HALF_UP)); //设置子订单优惠后小计,优惠后小计=优惠前小计-优惠券抵扣金额 orderItem.setActualTotal(orderItem.getOrderTransitionGoods().getCurTotal()); //设置用户已支付总金额,开单默认为0 orderItem.setUserPaidTotal(BigDecimal.ZERO); //设置一级子订单商品编号 orderItem.setGoodsNo(orderItem.getOrderTransitionGoods().getGoodsNo()); //设置一级子订单商品名称 orderItem.setGoodsName(orderItem.getOrderTransitionGoods().getGoodsName()); //设置一级子订单商品项目主图 orderItem.setGoodsImage(""); //设置一级子订单商品单次疗程数量,默认为0,商品没有单次疗程数量 //一级子订单商品疗程次数信息设值 orderItem.setSingle(0); //设置一级子订单商品总次疗程次数,单次疗程次数*购买的总量,商品没有单次疗程数量 orderItem.setUsedTotal(orderItem.getSingle()*orderItem.getBuyNum()); } /** * 开单-计算促销金额 * @param vo 一级子订单 * @param discountTotal 折扣总金额 * @param buyNum 购买次数 * @return */ public static Map handlePromotion( OrderItem vo, BigDecimal discountTotal, BigDecimal buyNum, CommonService commonService) { SqlSentence sqlSentence = new SqlSentence(); Map sqlMp=new HashMap<>(); sqlSentence.setM(sqlMp); sqlMp.put("status",Promotion.IN_PROGRESS); sqlMp.put("isUp",BaseEntity.YES); sqlMp.put("isDel",BaseEntity.NO); sqlMp.put("commonId",vo.getCommonId()); sqlSentence.setSqlSentence("select * from promotion where id=#{m.commonId} and status=#{m.status} and isUp=#{m.isUp} and isDel=#{m.isDel}"); Promotion promotion=commonService.selectOne(PromotionMapper.class,sqlSentence); if(promotion==null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"找不到该促销,请确保促销状态必须是销售中并且是上架状态,促销标识:"+vo.getCommonId()); } if(promotion.getTotal()==null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"促销:"+promotion.getName()+",没有销售价格,请填写销售单价在进行创建订单"); } //计算订单金额信息 //一级子订单:售价=促销销售价格*折扣 BigDecimal actualTotal; if(vo.getDiscountAlgorithm() == OrderItemConstants.DISCOUNT_ALGORITHM_TOTAL){ actualTotal = promotion.getTotal(); }else{ actualTotal = promotion.getTotal().multiply(vo.getDiscount().divide(new BigDecimal(100),15,BigDecimal.ROUND_HALF_UP)).setScale(2,BigDecimal.ROUND_HALF_UP); } //一级子订单金额信息设值 //设置原价,原价=促销的销售价格 vo.setOriPrice(promotion.getTotal()); //设置项目、商品、促销、卡项现价的售价 vo.setProPrice(promotion.getTotal()); //设置一级子订单售价, 售价=项目的销售价格*购买数量*折扣 vo.setCurPrice(actualTotal); if(vo.getDiscountAlgorithm() == OrderItemConstants.DISCOUNT_ALGORITHM_TOTAL){ //设置优惠前小计,优惠前小计=售价* 商品数量 vo.setTotal(vo.getCurPrice().multiply(buyNum)); vo.setTotal(vo.getTotal().multiply(vo.getDiscount().divide(new BigDecimal(100),15,RoundingMode.HALF_UP)).setScale(2,RoundingMode.HALF_UP)); vo.setDiscountMoney(vo.getTotal().divide(buyNum,4,RoundingMode.HALF_UP)); }else{ //设置优惠前小计,优惠前小计=售价* 商品数量 vo.setTotal(vo.getCurPrice().multiply(buyNum)); vo.setDiscountMoney(vo.getCurPrice()); } //计算折扣金额 vo.setDiscountOrderPrice(vo.getProPrice().multiply(BigDecimal.valueOf(vo.getBuyNum()).setScale(2,RoundingMode.HALF_UP)).subtract(vo.getTotal())); //折扣金额汇总 discountTotal=discountTotal.add(vo.getDiscountOrderPrice()).setScale(2,RoundingMode.HALF_UP); //设置一级子订单优惠券抵扣金额,开单不知道是否使用优惠券,默认为0 vo.setCouponTotal(BigDecimal.ZERO); //优惠福利总金额 if(vo.getPreferentialTotal() == null){ vo.setPreferentialTotal(BigDecimal.ZERO); } //后续复购活动开单会先算优惠,所以可能不是0 vo.setDiscountPrice(vo.getCouponTotal().add(vo.getPreferentialTotal()).setScale(2, RoundingMode.HALF_UP)); //设置一级子订单优惠后小计,优惠后小计=优惠前小计-优惠券抵扣金额 vo.setActualTotal(vo.getTotal().subtract(vo.getDiscountPrice())); //设置一级子订单用户已支付总金额,开单默认为0 vo.setUserPaidTotal(BigDecimal.ZERO); //设置item总积分 vo.setTotalPoints(BigDecimal.ZERO); //设置售价积分 vo.setSellPoints(BigDecimal.ZERO); //一级子订单促销规格信息设值 //设置一级子订单促销规格 vo.setSpecs("[]"); //设置一级子订单促销编号 vo.setGoodsNo(promotion.getCode()); //设置一级子订单促销名称 vo.setGoodsName(promotion.getName()); //设置一级子订单促销主图 vo.setGoodsImage(""); //一级子订单促销疗程次数设值 //设置一级子订单促销单次疗程数量 vo.setSingle(0); //设置一级子订单促销总次疗程次数,单次疗程次数*购买的总量 vo.setUsedTotal(vo.getSingle()*vo.getBuyNum()); Map moneyMap=new HashMap<>(); moneyMap.put("discountTotal",discountTotal); return moneyMap; } /** * 开单-计算卡项金额 * @param vo 一级子订单 * @param discountTotal 折扣总金额 * @param buyNum 购买次数 * @return */ public static Map handleCardItem(OrderItem vo, BigDecimal discountTotal, BigDecimal buyNum, CommonService commonService) { SqlSentence sqlSentence = new SqlSentence(); Map sqlMp=new HashMap<>(); sqlSentence.setM(sqlMp); sqlMp.put("status",CardItem.SALES); sqlMp.put("isUp",BaseEntity.YES); sqlMp.put("isDel",BaseEntity.NO); sqlMp.put("commonId",vo.getCommonId()); sqlSentence.setSqlSentence("select * from card_item where id = #{m.commonId} and status=#{m.status} and isDel=#{m.isDel}"); CardItem cardItem=commonService.selectOne(CardItemMapper.class,sqlSentence); if(cardItem==null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"购买的卡项不存在"); } //判断卡项是否下架 if(cardItem.getIsUp().equals(CardItem.NO)){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"卡项:"+cardItem.getName()+"已下架!"); } //判断卡项是否销售 if(!CardItem.SALES.equals(cardItem.getStatus())){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"卡项:"+cardItem.getName()+"未开放销售!"); } if(cardItem.getTotal()==null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"卡项:"+cardItem.getName()+"无法下单购买!"); } //获取限制表 sqlMp.clear(); sqlMp.put("cardId", cardItem.getId()); sqlSentence.setSqlSentence("select * from limit_total where isDel= 0 and foreignKey=#{m.cardId} order by createTime desc limit 1"); LimitTotal limitTotal=commonService.selectOne(LimitTotalMapper.class,sqlSentence); if(limitTotal != null){ Date date = new Date(); if(limitTotal.getStartTime() != null){ //判断销售购买时间 if(date.before(limitTotal.getStartTime())){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"卡项:"+cardItem.getName()+"未到销售时间!"); } } if(limitTotal.getEndTime() != null){ //判断销售购买时间 if(date.after(limitTotal.getEndTime())){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"卡项:"+cardItem.getName()+"已过销售时间!"); } } } //计算订单卡项金额信息 //一级子订单:售价=卡项售价*折扣 BigDecimal actualTotal; if(vo.getDiscountAlgorithm() == OrderItemConstants.DISCOUNT_ALGORITHM_TOTAL){ actualTotal = cardItem.getTotal(); }else{ actualTotal = cardItem.getTotal().multiply(vo.getDiscount().divide(new BigDecimal(100),15,RoundingMode.HALF_UP)).setScale(2,RoundingMode.HALF_UP); } //一级子订单卡项金额信息设值 //设置原价,原价=卡项的销售价格 vo.setOriPrice(cardItem.getTotal()); //设置项目、商品、促销、卡项现价的售价 vo.setProPrice(cardItem.getTotal()); //设置一级子订单售价 vo.setCurPrice(actualTotal); if(vo.getDiscountAlgorithm() == OrderItemConstants.DISCOUNT_ALGORITHM_TOTAL){ //设置优惠前小计,优惠前小计=售价* 商品数量 vo.setTotal(vo.getCurPrice().multiply(buyNum)); vo.setTotal(vo.getTotal().multiply(vo.getDiscount().divide(new BigDecimal(100),15,RoundingMode.HALF_UP)).setScale(2,RoundingMode.HALF_UP)); vo.setDiscountMoney(vo.getTotal().divide(buyNum,4,RoundingMode.HALF_UP)); }else{ //设置优惠前小计,优惠前小计=售价* 商品数量 vo.setTotal(vo.getCurPrice().multiply(buyNum)); vo.setDiscountMoney(vo.getCurPrice()); } //计算折扣金额 vo.setDiscountOrderPrice(vo.getProPrice().multiply(BigDecimal.valueOf(vo.getBuyNum()).setScale(2,RoundingMode.HALF_UP)).subtract(vo.getTotal())); //折扣金额汇总 discountTotal=discountTotal.add(vo.getDiscountOrderPrice()).setScale(2,RoundingMode.HALF_UP); //设置一级子订单优惠券抵扣金额,开单不知道是否使用优惠券,默认为0 vo.setCouponTotal(BigDecimal.ZERO); //优惠福利总金额 if(vo.getPreferentialTotal() == null){ vo.setPreferentialTotal(BigDecimal.ZERO); } //后续复购活动开单会先算优惠,所以可能不是0 vo.setDiscountPrice(vo.getCouponTotal().add(vo.getPreferentialTotal()).setScale(2, RoundingMode.HALF_UP)); //设置一级子订单优惠后小计,优惠后小计=优惠前小计-优惠券抵扣金额 vo.setActualTotal(vo.getTotal().subtract(vo.getDiscountPrice())); //设置一级子订单用户已支付总金额,开单默认为0 vo.setUserPaidTotal(BigDecimal.ZERO); //设置item总积分 vo.setTotalPoints(BigDecimal.ZERO); //设置售价积分 vo.setSellPoints(BigDecimal.ZERO); //一级子订单卡项规格信息设值 //设置一级子订单卡项编号 vo.setGoodsNo(cardItem.getCode()); //设置一级子订单卡项名称 vo.setGoodsName(cardItem.getName()); //设置一级子订单卡项规格(卡项没有规格,默认 []) vo.setSpecs("[]"); //设置一级子订单卡项主图 vo.setGoodsImage(""); //一级子订单卡项疗程次数设值 //设置一级子订单卡项单次疗程数量 vo.setSingle(0); //设置一级子订单卡项总次疗程次数,单次疗程次数*购买的总量 vo.setUsedTotal(vo.getSingle()*vo.getBuyNum()); Map moneyMap=new HashMap<>(); moneyMap.put("actualTotal",actualTotal); moneyMap.put("discountTotal",discountTotal); return moneyMap; } /** * 开单-计算积分金额 * @param jsonObject * @param map * @param vo * @param discountTotal * @param buyNum * @param commonService * @return */ private static Map handleIntegral(JSONArray jsonObject, Map map, OrderItem vo, BigDecimal discountTotal, BigDecimal buyNum, CommonService commonService) { SqlSentence sqlSentence=new SqlSentence(); Map objectMap=new HashMap<>(); sqlSentence.setM(objectMap); objectMap.put("commonId",vo.getCommonId()); objectMap.put("isDel",BaseEntity.NO); Project project=commonService.selectOneByKeyBlob(ProjectMapper.class,vo.getCommonId()); if(project==null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"找不到项目:"+vo.getCommonId()); } //计算项目价格,如果总订单有康博佳标识代表是康博佳订单不需要任何处理直接拿去康博佳的总金额,每个门店价格不一样,如果没有设置门店价格就使用项目售价 // BigDecimal price=priceJudge(ordersTotal, commonService,project.getId(),shopId); // project.setPrice(BigDecimal.ZERO.compareTo(price)==0?project.getPrice():price); if(project.getPrice()==null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"积分项目:"+project.getName()+",没有销售价格,请填写销售单价再进行创建订单"); } if(project.getIsUp()==BaseEntity.NO){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"积分项目:"+project.getName()+",该项目已下架"); } if(project.getIsDel()==BaseEntity.YES){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"积分项目:"+project.getName()+",该项目已删除"); } sqlSentence.setSqlSentence("select * from project_info where projectId=#{m.commonId} and isDel=#{m.isDel} "); ProjectInfo projectInfo=commonService.selectOne(ProjectInfoMapper.class,sqlSentence); //计算订单金额信息 //一级子订单:售价=项目售价*折扣 BigDecimal actualTotal = project.getPrice().multiply(vo.getDiscount().divide(new BigDecimal(100))); //总订单:订单优惠总金额=项目的销售单价*数量减去一级子订单售价; discountTotal=discountTotal.add(project.getPrice().multiply(buyNum).subtract(actualTotal.multiply(buyNum))); //一级子订单金额信息设值 //设置原价,原价=促销的销售价格 vo.setOriPrice(project.getOriginalPrice()); //设置项目、商品、促销、卡项现价的售价 vo.setProPrice(project.getPrice()); //设置售价, 售价=项目的销售价格*购买数量*折扣 vo.setCurPrice(actualTotal); //设置优惠前小计,优惠前小计=售价* 商品数量 vo.setTotal(vo.getCurPrice().multiply(buyNum)); //设置子订单优惠券抵扣金额,开单不知道是否使用优惠券,默认为0 vo.setCouponTotal(BigDecimal.ZERO); //优惠福利总金额 if(vo.getPreferentialTotal() == null){ vo.setPreferentialTotal(BigDecimal.ZERO); } //后续复购活动开单会先算优惠,所以可能不是0 vo.setDiscountPrice(vo.getCouponTotal().add(vo.getPreferentialTotal()).setScale(2, RoundingMode.HALF_UP)); //设置子订单优惠后小计,优惠后小计=优惠前小计-优惠券抵扣金额 vo.setActualTotal(vo.getTotal().subtract(vo.getDiscountPrice())); //设置用户已支付总金额,开单默认为0 vo.setUserPaidTotal(BigDecimal.ZERO); //设置item总积分 vo.setTotalPoints(BigDecimal.ZERO); //设置售价积分 vo.setSellPoints(BigDecimal.ZERO); //一级子订单商品信息设值 //设置一级子订单规格,如果项目规格json没有值,则自动封装json规格(内容默认:规格值、单位、身体部位、医生资质),否则就采用项目规格json sqlSentence.setSqlSentence("select * from project_spec_value where projectId=#{m.commonId} and isDel=#{m.isDel} "); List projectSpecValues = commonService.selectList(ProjectSpecValueMapper.class, sqlSentence); if(projectSpecValues!=null && projectSpecValues.size()>0){ for (ProjectSpecValue projectSpecValue : projectSpecValues) { Map specMap=new HashMap<>(); SpecificationValue specificationValue=commonService.selectOneByKeyBlob(SpecificationValueMapper.class,projectSpecValue.getSpecValue()); if(specificationValue!=null){ Specification specification=commonService.selectOneByKeyBlob(SpecificationMapper.class,specificationValue.getSpecificationId()); if(specification!=null){ specMap.put("specsTitle",specification.getSpecName()); } specMap.put("specsValue",specificationValue.getSpecValueName()); specMap.put("specsId",specificationValue.getId()); specMap.put("unit",""); } jsonObject.add(specMap); } }else{ map.put("specsTitle","规格"); map.put("specsValue",project==null?"":StringUtils.isEmpty(project.getSpecification())?"":project.getSpecification()); map.put("unit",project==null?"":StringUtils.isEmpty(project.getUnit())?"":project.getUnit()); map.put("bodyPartName",projectInfo==null?"":StringUtils.isEmpty(projectInfo.getBodyPartName())?"":projectInfo.getBodyPartName()); map.put("doctorQualification",projectInfo==null?"":StringUtils.isEmpty(projectInfo.getDoctorQualification())?"":projectInfo.getDoctorQualification()); jsonObject.add(map); } //设置一级子订单规格信息 vo.setSpecs(jsonObject.isEmpty()?"[]":jsonObject.toJSONString()); vo.setSpecsName(StringUtils.isEmpty(project.getSpecification())?"":project.getSpecification()); if(projectInfo!=null){ if(StringUtils.noNull(projectInfo.getBodyPartId())){ vo.setBodyPartsId(projectInfo.getBodyPartId()); } if(StringUtils.noNull(projectInfo.getBodyPartName())){ vo.setBodyPartsName(projectInfo.getBodyPartName()); } if(StringUtils.noNull(projectInfo.getExecutiveQualificationCode())){ vo.setAptitudeNo(projectInfo.getExecutiveQualificationCode()); } if(StringUtils.noNull(projectInfo.getExecutiveQualificationName())){ vo.setAptitudeName(projectInfo.getExecutiveQualificationName()); } if(StringUtils.noNull(projectInfo.getDoctorQualification())){ vo.setDoctorQualification(projectInfo.getDoctorQualification()); } } vo.setGoodsNo(project.getCoding());//项目编号 vo.setGoodsName(project.getName());//项目名称 vo.setGoodsImage("");//项目主图 //一级子订单疗程次数设值OrderServiceImpl //荣爷说项目疗程次数为空值,默认为1 //设置一级子订单单次疗程数量,该值获取的是项目的疗程次数(为了计算订单的总疗程次数) if(project.getIsExecutable()!=null && project.getIsExecutable()==BaseEntity.YES){ Integer useredTotal=project==null?0:project.getTreatmentItemsNum()==null?1:project.getTreatmentItemsNum()==0?1:project.getTreatmentItemsNum(); vo.setSingle(useredTotal);//订单单次疗程数量 }else if(project.getIsExecutable()!=null && project.getIsExecutable()==BaseEntity.NO){ Integer useredTotal=project==null?0:project.getTreatmentItemsNum()==null?0:project.getTreatmentItemsNum(); vo.setSingle(useredTotal);//订单单次疗程数量 }else{ vo.setSingle(0);//订单单次疗程数量 } //设置总次疗程次数,单次疗程次数*购买的总量(结账完成未执行划口剩余次数就是获取该总疗程次数字段),疗程总次数=订单单次疗程数量* 订单购买数量 vo.setUsedTotal(vo.getSingle()*vo.getBuyNum()); Map moneyMap=new HashMap<>(); moneyMap.put("discountTotal",discountTotal); return moneyMap; } /** * 开单-处理卡包方法 * @param vo 一级子订单 * @return */ public static Map handleCardBag(OrderItem vo, CommonService commonService) { if(StringUtils.isEmpty(vo.getUserCardId())){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"下单:开卡包订单需要卡包标识!"); } SqlSentence sqlSentence = new SqlSentence(); Map sqlMp=new HashMap<>(); sqlSentence.setM(sqlMp); sqlMp.put("status",CardItem.SALES); sqlMp.put("isUp",BaseEntity.YES); sqlMp.put("isDel",BaseEntity.NO); sqlMp.put("commonId",vo.getCommonId()); //已有卡项放开卡项是否上架判断,只要购买了卡项都能使用除非过期了,and isUp=#{m.isUp},and status=#{m.status} sqlSentence.setSqlSentence("select * from card_item where id=#{m.commonId} and isDel=#{m.isDel}"); CardItem cardItem=commonService.selectOne(CardItemMapper.class,sqlSentence); if(cardItem==null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"卡包:找不到该卡项,请确保卡项状态必须是销售中并且是上架状态,卡项标识:"+vo.getCommonId()); } if(cardItem.getTotal()==null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"卡包:"+cardItem.getName()+",没有销售价格,请填写销售单价在进行创建订单"); } //计算一级子订单和总订单售价,卡包比较特殊,售价=未执行划扣金额,未执行划扣金额=(卡项明细分摊金额 除以 卡项明细分摊次数 )乘以 用户划扣次数 //一级子订单未执行划扣金额 BigDecimal sumCardBagMoney =BigDecimal.ZERO; //单次划扣金额 BigDecimal everySnapNum = null; //总次数 Integer usedNum; CardEquity cardEquity; UserCardItemInfoVo userCardItemInfoVo; CardItemInfo cardItemInfo; //判断次卡抵扣次数的问题 Map sequenceMap = new HashMap<>(); Integer surplusNum; if(vo.getCardItemInfoIds()!=null && vo.getCardItemInfoIds().size()>0){ for(CardItemInfo info:vo.getCardItemInfoIds()){ if(info.getUserNum() == null || info.getUserNum() < 0){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"卡包开单提示:购买的卡项的条目数量错误!"); } cardItemInfo = commonService.selectOneByKey(CardItemInfoMapper.class,info.getId()); //-----校验抵扣次数 cardEquity = commonService.selectOneByKey(CardEquityMapper.class,cardItemInfo.getCardEquityId()); //获取当前需要抵扣的总次数 usedNum = UserCardTool.countUsedNumber(info.getUserNum(),cardItemInfo,cardEquity); userCardItemInfoVo = UserCardTool.getSurplusNumber(vo.getUserCardId(),cardItemInfo,cardEquity,commonService); if(!userCardItemInfoVo.isNumByNum()){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"卡包开单提示:不符合N选M规则,请重试"); } if(userCardItemInfoVo.getSurplusNum() <= 0 ||usedNum > userCardItemInfoVo.getSurplusNum()){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"卡包开单提示:卡项的次卡使用次数不够"); } if(CardEquity.EQUITY_TYPE_TIME_CARD.equals(cardEquity.getEquityType())){ surplusNum = sequenceMap.get(cardEquity.getId()); if(surplusNum != null){ if(usedNum > surplusNum){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"卡包开单提示:卡项的次卡使用次数不够"); } }else{ surplusNum = userCardItemInfoVo.getSurplusNum(); } surplusNum = surplusNum - usedNum; sequenceMap.put(cardEquity.getId(),surplusNum); } if(CardEquity.EQUITY_TYPE_TIME_CARD.equals(cardEquity.getEquityType())){ //-----次卡 //每次划扣金额 if(cardItemInfo.getEveryDrawNum()>0){ everySnapNum = cardItemInfo.getEveryShareMoney().divide(BigDecimal.valueOf(cardItemInfo.getEveryDrawNum()),10,RoundingMode.HALF_UP); }else{ everySnapNum = BigDecimal.ZERO; } }else{ //-----N选M/固定项目/其他 //每次划扣金额 if(cardItemInfo.getMaxNum()>0){ everySnapNum = cardItemInfo.getShareMoney().divide(BigDecimal.valueOf(cardItemInfo.getMaxNum()),10,RoundingMode.HALF_UP); }else{ everySnapNum = BigDecimal.ZERO; } } sumCardBagMoney=sumCardBagMoney.add(everySnapNum.multiply(BigDecimal.valueOf(usedNum))).setScale(2,RoundingMode.HALF_UP); } } //设置一级子订单原价(卡包:划扣项目的未执行划扣金额) vo.setOriPrice(sumCardBagMoney); //设置一级子订单售价 vo.setCurPrice(sumCardBagMoney); //设置一级子订单优惠前小计,优惠前小计=一级子订单未执行划扣金额 vo.setTotal(BigDecimal.ZERO); //设置一级子订单优惠券抵扣金额,开单不知道是否使用优惠券,默认为0 vo.setCouponTotal(BigDecimal.ZERO); //优惠福利总金额 if(vo.getPreferentialTotal() == null){ vo.setPreferentialTotal(BigDecimal.ZERO); } //后续复购活动开单会先算优惠,所以可能不是0 vo.setDiscountPrice(vo.getCouponTotal().add(vo.getPreferentialTotal()).setScale(2, RoundingMode.HALF_UP)); //设置一级子订单优惠后小计,优惠后小计=一级子订单未执行划扣金额 vo.setActualTotal(BigDecimal.ZERO); //设置一级子订单用户已支付总金额,开单默认为0 vo.setUserPaidTotal(BigDecimal.ZERO); //设置item总积分 vo.setTotalPoints(BigDecimal.ZERO); //设置售价积分 vo.setSellPoints(BigDecimal.ZERO); //设置一级子订单规格信息 vo.setSpecs("[]");//规格 vo.setGoodsNo(cardItem.getCode());//卡项编号 vo.setGoodsName(cardItem.getName());//卡项名称 vo.setGoodsImage("");//卡项主图 //设置一级子订单疗程信息 vo.setSingle(0);//单次疗程数量 vo.setUsedTotal(vo.getSingle()*vo.getBuyNum());//总次疗程次数,单次疗程次数*购买的总量 Map moneyMap=new HashMap<>(); moneyMap.put("actualTotal",vo.getActualTotal()); moneyMap.put("discountTotal",BigDecimal.ZERO); return moneyMap; } /** * 开单-构建总订单实体 实现类 * * @param ordersTotal 总订单 * @param shop 门店 * @param shouldOrderTotal 订单应付总金额 * @param discountTotal 订单折扣金额 * @param operatorId 操作人 * @param operatorName 操作人名称 * @param operatorType 操作类型 * @param platformApplication 平台实体 */ public static void setOrderTotal(OrdersTotal ordersTotal, Shop shop,BigDecimal shouldOrderTotal, BigDecimal discountTotal, String operatorId, String operatorName, Integer operatorType, BigDecimal oriTotal, Integer type, User user, CreateNoService createNoService, PlatformApplication platformApplication, CommonService commonService) { //type:0:草稿 1:提交 2:结账 if (type == 0) { ordersTotal.setStatus(OrderTotalConstants.STATUS_DRAFT);//订单状态:草稿 } String totalNum = createNoService.createOrderNo("S", 8, "yyyyMMdd");//总订单编号 ordersTotal.setOrderNo(totalNum);//总订单编号 ordersTotal.setOrderNo(ordersTotal.getOrderNo());//订单编号 ordersTotal.setOperatorType(operatorType);//操作类型(0:系统管理员,1:员工) ordersTotal.setOperatorId(operatorId);//下单操作人标识 ordersTotal.setOperatorName(operatorName);//下单操作人名称 ordersTotal.setPayTotal(BigDecimal.ZERO);//支付现金金额 ordersTotal.setPayRecharge(BigDecimal.ZERO);//支付储值金金额 ordersTotal.setPayIncrement(BigDecimal.ZERO);//支付增值金金额 ordersTotal.setShouldTotal(shouldOrderTotal);//订单应付支付总金额 ordersTotal.setDiscountTotal(discountTotal);//优惠金额,以元为存储 ordersTotal.setShopId(shop.getId());//操作人门店标识 ordersTotal.setShopName(shop.getName());//操作人门店名称 ordersTotal.setActualTotal(BigDecimal.ZERO);//用户实际支付的总金额 ordersTotal.setChannelType(OrderTotalConstants.CHANNEL_TYPE_NOTHING);//暂定用没有渠道类型 ordersTotal.setSourceCode(platformApplication == null ? ordersTotal.getAppId() : platformApplication.getAppId());//没有传就默认是请求的appId ordersTotal.setSourceName(platformApplication == null ? ordersTotal.getAppId() : platformApplication.getName());//没有传就默认是请求的appId ordersTotal.setOriTotal(oriTotal); //判断第三方订单号是否为空,如果是则用订单编号 List platformType = Arrays.asList(PlatformConstants.TYPE_PLATFORM_HIS, PlatformConstants.TYPE_PLATFORM_PHIS, PlatformConstants.TYPE_PLATFORM_GUIDE); if(platformType.contains(ordersTotal.getAppIdCode()) && StringUtils.isEmpty(ordersTotal.getSourceOrderNo())){ ordersTotal.setSourceOrderNo(ordersTotal.getOrderNo()); } //所属美容师 if(StringUtils.noNull(user.getBeauticianCorpUserId())){ Employee employee=commonService.selectOneByKeyBlob(EmployeeMapper.class,user.getBeauticianCorpUserId()); if(employee!=null){ //所属美容师:用户所属美容师 ordersTotal.setBeauticianCorpUserId(employee.getId()); ordersTotal.setBeauticianCorpUserName(StringUtils.isEmpty(employee.getCnName())?"":employee.getCnName()); } } logger.info("【设置总订单参数】ordersTotal: {}", JSON.toJSONString(ordersTotal)); } /** * 设置订单的开发人信息 * @param ordersTotal * @return */ public static void handUserDeveloper(OrdersTotal ordersTotal,User user,List orderTypeList,CommonService commonService){ //如果开发人集合为空,那么默认用户的所属顾问 SqlSentence sqlSentence = new SqlSentence(); Map map = new HashMap<>(); sqlSentence.setM(map); map.put("shopId", ordersTotal.getDeveloperShopId()); if (StringUtils.noNull(user.getHisCorpUserId()) && !orderTypeList.contains(ordersTotal.getType()) && !PlatformConstants.TYPE_PLATFORM_CRM.equals(ordersTotal.getAppIdCode())) { map.put("hisCorpUserId", user.getHisCorpUserId()); // sqlSentence.setSqlSentence("SELECT s.* FROM employee_role er LEFT JOIN shop s ON er.shopId = s.id WHERE er.isDel=0 and er.employeeId = #{m.hisCorpUserId} AND er.roleUniqueStr ='adviser_leader' and s.id=#{m.shopId}"); //荣爷说放开所有权限,顾问可以开任意一个门店的单 sqlSentence.setSqlSentence("SELECT id,name FROM shop WHERE id=#{m.shopId}"); Shop userShop = commonService.selectOne(ShopMapper.class, sqlSentence); if (userShop == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "用户绑定的顾问不在该门店"); } Employee userAdiver = commonService.selectOneByKey(EmployeeMapper.class, user.getHisCorpUserId()); //开发人门店标识(用户绑定的销售顾问) ordersTotal.setDeveloperShopId(userShop.getId()); //开发人门店名称 ordersTotal.setDeveloperShopName(userShop.getName()); ordersTotal.setDeveloperId(userAdiver.getId()); ordersTotal.setDeveloperName(userAdiver.getCnName()); } else if (StringUtils.noNull(user.getHisCorpUserId()) && !orderTypeList.contains(ordersTotal.getType()) && !PlatformConstants.TYPE_PLATFORM_CRM.equals(ordersTotal.getAppIdCode())) { //该操作支持crm开单 sqlSentence.setSqlSentence("SELECT id,name FROM shop WHERE id=#{m.shopId}"); Shop userShop = commonService.selectOne(ShopMapper.class, sqlSentence); //开发人门店标识(用户绑定的销售顾问) ordersTotal.setDeveloperShopId(ordersTotal.getDeveloperShopId()); //开发人门店名称 ordersTotal.setDeveloperShopName(userShop == null ? "" : userShop.getName()); ordersTotal.setDeveloperId(ordersTotal.getDeveloperId()); ordersTotal.setDeveloperName(ordersTotal.getDeveloperName()); } //荣爷说开发人必填此处不需要默认用户的咨询师 22-05-27 // else if(!orderTypeList.contains(ordersTotal.getType())){ // throw new PlatTipsException(PlatformCode.ERROR_TIPS,"请填写好开发人或者用户绑定一个销售顾问在重试"); // } } /** * 判断是否是老带新 用新工具类 OrderUtil 复制代码过去统一管理 * * @param ordersTotal 总订单 * @param commonService 公共方法 * @return 返回 */ public static Integer checkOldBringNew(OrdersTotal ordersTotal, CommonService commonService) { User user = commonService.selectOneByKeyBlob(UserMapper.class, ordersTotal.getUserId()); if (user != null) { if (StringUtils.isEmpty(user.getInviteeId())) { //没有推荐人则不是老带新,说明客户是自来的 return BaseEntity.NO; } else { SqlSentence sqlSentence = new SqlSentence(); Map map = new HashMap<>(); sqlSentence.setM(map); //判断推荐人是否有支付记录 map.put("inviteeId", user.getInviteeId()); map.put("isDel", BaseEntity.NO); map.put("status", OrderTotalConstants.STATUS_PAY); sqlSentence.setSqlSentence(" userId=#{m.inviteeId} and status=#{m.status} and isDel=#{m.isDel} "); int count = commonService.selectCount(OrdersTotalMapper.class, sqlSentence); if (count > 0) { map.clear(); map.put("userId", ordersTotal.getUserId()); map.put("isDel", BaseEntity.NO); sqlSentence.setSqlSentence("SELECT * FROM v_visit_record WHERE userId =#{m.userId} and isDel=#{m.isDel} and arrivalTime is not NULL ORDER BY arrivalTime LIMIT 1"); VisitRecord visitRecord = commonService.selectOne(VisitRecordMapper.class, sqlSentence); if (visitRecord != null) { //订单时间在到访时间之后则不算老带新 if (DateUtil.timeEqual(visitRecord.getArrivalTime(), ordersTotal.getCreateTime())) { logger.info("老带新提示:该订单用户订单创建时间和到访时间是当天算老带新,用户标识:{},总订单标识:{}", user.getId(), ordersTotal.getId()); return BaseEntity.YES; }else if (ordersTotal.getCreateTime().before(visitRecord.getArrivalTime())) { logger.info("老带新提示:该订单用户订单创建时间在到访时间之前算老带新,用户标识:{},总订单标识:{}", user.getId(), ordersTotal.getId()); return BaseEntity.YES; //订单时间和到访时间是同一天则算老带新 }else if (ordersTotal.getCreateTime().after(visitRecord.getArrivalTime())) { logger.info("老带新提示:该订单用户订单创建时间在到访时间之后不算老带新,用户标识:{},总订单标识:{}", user.getId(), ordersTotal.getId()); return BaseEntity.NO; //订单时间在到访时间之前则算老带新 }else { logger.info("老带新提示:以上情况都不符合,默认不算老带新,用户标识:{},总订单标识:{}", user.getId(), ordersTotal.getId()); //否则默认不算老带新 return BaseEntity.NO; } } else { logger.info("老带新提示:该订单用户没有找到预约信息,算老带新,用户标识:{},总订单标识:{}", user.getId(), ordersTotal.getId()); //没有找到该用户的预约,该用户推荐人又不为空,那么算是老带新,老带新:在该用户到访前和到访当天开的单都是老带新 return BaseEntity.YES; } } else { logger.info("老带新提示:该订单用户的推荐人没有支付订单不算老客,推荐人:{},总订单标识:{}", user.getInviteeId(), ordersTotal.getId()); return BaseEntity.NO; } } } else { logger.info("老带新提示:未找到该用户信息!"); return BaseEntity.NO; } } /** * 判断是否是初诊单 用新工具类 OrderUtil 复制代码过去统一管理 * @param ordersTotal 总订单 * @param commonService 公共方法 * @return 返回 */ public static Integer checkIsBothTheOne(OrdersTotal ordersTotal, CommonService commonService) { User user = commonService.selectOneByKeyBlob(UserMapper.class, ordersTotal.getUserId()); if (user != null) { SqlSentence sqlSentence = new SqlSentence(); Map map = new HashMap<>(); sqlSentence.setM(map); //判断推荐人是否有支付记录 map.put("userId", ordersTotal.getUserId()); map.put("isDel", BaseEntity.NO); sqlSentence.setSqlSentence("SELECT * FROM v_visit_record WHERE userId =#{m.userId} and isDel=#{m.isDel} and arrivalTime is not NULL ORDER BY arrivalTime LIMIT 1"); VisitRecord visitRecord = commonService.selectOne(VisitRecordMapper.class, sqlSentence); if (visitRecord != null) { //订单时间在到访时间之后则不算老带新 if (DateUtil.timeEqual(visitRecord.getArrivalTime(), ordersTotal.getCreateTime())) { logger.info("初诊单提示:该订单用户订单创建时间和到访时间是当天算初诊单,用户标识:{},总订单标识:{}", user.getId(), ordersTotal.getId()); return BaseEntity.YES; //订单时间在到访时间之前则算老带新 } else if (ordersTotal.getCreateTime().before(visitRecord.getArrivalTime())) { logger.info("初诊单提示:该订单用户订单创建时间在到访时间之前算初诊单,用户标识:{},总订单标识:{}", user.getId(), ordersTotal.getId()); return BaseEntity.YES; //订单时间和到访时间是同一天则算老带新 } else if (ordersTotal.getCreateTime().after(visitRecord.getArrivalTime())) { logger.info("初诊单提示:该订单用户订单创建时间在到访时间之后不算初诊单,用户标识:{},总订单标识:{}", user.getId(), ordersTotal.getId()); return BaseEntity.NO; } else { logger.info("初诊单提示:以上情况都不符合,默认不算初诊单,用户标识:{},总订单标识:{}", user.getId(), ordersTotal.getId()); //否则默认不算老带新 return BaseEntity.NO; } } else { logger.info("初诊单提示:该订单用户没有找到预约信息,算初诊单,用户标识:{},总订单标识:{}", user.getId(), ordersTotal.getId()); //没有找到该用户的预约,该用户推荐人又不为空,那么算是老带新,老带新:在该用户到访前和到访当天开的单都是老带新 return BaseEntity.YES; } } else { logger.info("初诊单提示:未找到该用户信息!"); return BaseEntity.NO; } } /** * 保存orderInfo信息 * * @param ordersTotal 总订单 * @param user 用户信息 * @param commonService * @param isOldBringNew 是否老带新(0:否,1:是) */ public static String saveOrderInfo(OrdersTotal ordersTotal, User user, CustomParameter customParameter, Integer isOldBringNew, Integer isBothTheOne , OrderPHisDto orderPHisDto, CommonService commonService) { String activityName = ""; OrderInfo orderInfo = ordersTotal.getOrderInfo(); logger.info("接收的orderInfo:"+JSON.toJSONString(orderInfo)); BigDecimal defaultDiscount = new BigDecimal(100); if (ordersTotal.getOrderInfo() == null) { orderInfo = new OrderInfo(); orderInfo.setIsWholeDiscount(0); orderInfo.setIsEmployeeDiscount(0); orderInfo.setDiscount(defaultDiscount); } else { orderInfo.setIsEmployeeDiscount(StringUtils.noNull(ordersTotal.getKoapOrderId()) ? BaseEntity.NO : ordersTotal.getOrderInfo().getIsEmployeeDiscount()); orderInfo.setIsWholeDiscount(StringUtils.noNull(ordersTotal.getKoapOrderId()) ? BaseEntity.NO : ordersTotal.getOrderInfo().getIsWholeDiscount()); if (StringUtils.noNull(ordersTotal.getKoapOrderId())) { orderInfo.setDiscount(defaultDiscount); } else { // if (ordersTotal.getOrderInfo().getDiscount() == null) { // throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "整单折扣/员工折扣参数为空,默认为100!"); // } orderInfo.setDiscount(ordersTotal.getOrderInfo().getDiscount()==null?new BigDecimal(100):ordersTotal.getOrderInfo().getDiscount()); } } orderInfo.setOrderId(ordersTotal.getId()); //如果有用活动规则将活动规则保存在orderInfo if (ordersTotal.getActivityIds() != null && ordersTotal.getActivityIds().size() > 0) { //查询活动规则基础信息 ActivityRule activityRule = commonService.selectOneByKey(ActivityRuleMapper.class, ordersTotal.getActivityIds().get(0)); if (activityRule != null) { orderInfo.setActivityId(activityRule.getId()); orderInfo.setActivityName(activityRule.getName()); activityName = activityRule.getName(); } } //用户推荐人处理 if (StringUtils.noNull(user.getInviteeId())) { orderInfo.setInviteeId(user.getInviteeId()); User userInviteeName = commonService.selectOneByKeyBlob(UserMapper.class, user.getInviteeId()); SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); if(userInviteeName != null){ //推荐人是用户,获取其unionId values.put("userId",userInviteeName.getId()); values.put("fromCode",customParameter.getCrmMpAppId()); sqlSentence.sqlSentence("SELECT * FROM user_union_his WHERE isDel = 0 AND userId = #{m.userId} AND fromCode = #{m.fromCode} ORDER BY createTime DESC LIMIT 1",values); UserUnionHis userUnionHis = commonService.selectOne(UserUnionHisMapper.class,sqlSentence); if(userUnionHis != null){ //查找员工 values.clear(); values.put("crmUnionId",userUnionHis.getUnionId()); sqlSentence.sqlSentence("SELECT * FROM employee WHERE isDel = 0 AND isJob = 1 AND unionId = #{m.crmUnionId} ORDER BY createTime DESC LIMIT 1",values); Employee comEmployee = commonService.selectOne(EmployeeMapper.class,sqlSentence); if(comEmployee != null){ //判断是不是医生 values.clear(); values.put("employeeId",comEmployee.getId()); values.put("roleUniqueStr",customParameter.getDoctorRoleCode()); sqlSentence.sqlSentence("SELECT * FROM employee_role WHERE isDel = 0 AND employeeId = #{m.employeeId} AND roleUniqueStr = #{m.roleUniqueStr}",values); List employeeRoleList = commonService.selectList(EmployeeRoleMapper.class,sqlSentence); if(employeeRoleList.size() > 0){ orderInfo.setInviteeType(OrderInfo.INVITEE_TYPE_USER_DOCTOR); }else{ orderInfo.setInviteeType(OrderInfo.INVITEE_TYPE_USER_STAFF); } orderInfo.setInviteeNo(comEmployee.getEmployeeNo()); orderInfo.setInviteeName(comEmployee.getCnName()); }else{ orderInfo.setInviteeType(OrderInfo.INVITEE_TYPE_USER); orderInfo.setInviteeNo(userInviteeName.getMemberNO()); orderInfo.setInviteeName(userInviteeName.getName()); } }else{ orderInfo.setInviteeType(OrderInfo.INVITEE_TYPE_USER); orderInfo.setInviteeNo(userInviteeName.getMemberNO()); orderInfo.setInviteeName(userInviteeName.getName()); } orderInfo.setInviteeCIQ(userInviteeName.getCIQ()); }else{ Employee employeeInviteeName = commonService.selectOneByKeyBlob(EmployeeMapper.class, user.getInviteeId()); if(employeeInviteeName != null){ //判断是不是医生 values.clear(); values.put("employeeId",employeeInviteeName.getId()); values.put("roleUniqueStr",customParameter.getDoctorRoleCode()); sqlSentence.sqlSentence("SELECT * FROM employee_role WHERE isDel = 0 AND employeeId = #{m.employeeId} AND roleUniqueStr = #{m.roleUniqueStr}",values); List employeeRoleList = commonService.selectList(EmployeeRoleMapper.class,sqlSentence); if(employeeRoleList.size() > 0){ orderInfo.setInviteeType(OrderInfo.INVITEE_TYPE_STAFF_DOCTOR); }else{ orderInfo.setInviteeType(OrderInfo.INVITEE_TYPE_STAFF_STAFF); } orderInfo.setInviteeName(employeeInviteeName.getCnName()); orderInfo.setInviteeNo(employeeInviteeName.getEmployeeNo()); }else{ orderInfo.setInviteeType(OrderInfo.INVITEE_TYPE_UNKNOW); } } } else { orderInfo.setInviteeType(OrderInfo.INVITEE_TYPE_UNKNOW); } orderInfo.setChannelId(user.getChannelId()); orderInfo.setChannelName(user.getChannelType()); orderInfo.setChannel2Id(user.getChannel2Id()); orderInfo.setChannelName2(user.getChannelType2()); orderInfo.setChannelCategory(user.getChannelCategory()); //副渠道信息 orderInfo.setChannelAssistId(user.getChannelAssistId()); orderInfo.setChannelAssistName(user.getChannelAssistName()); orderInfo.setChannelAssist2Id(user.getChannelAssist2Id()); orderInfo.setChannelAssist2Name(user.getChannelAssist2Name()); orderInfo.setChannelAssist2Json(UserChannelTool.getChannelJsonInfo(commonService, user.getChannelAssist2Id())); //收件地址 if(orderPHisDto.getDeliveryAddress() != null){ orderInfo.setLinkMan(orderPHisDto.getDeliveryAddress().getLinkMan()); orderInfo.setLinkTel(orderPHisDto.getDeliveryAddress().getLinkTel()); orderInfo.setProvince(orderPHisDto.getDeliveryAddress().getProvince()); orderInfo.setCity(orderPHisDto.getDeliveryAddress().getCity()); orderInfo.setArea(orderPHisDto.getDeliveryAddress().getArea()); orderInfo.setStreet(orderPHisDto.getDeliveryAddress().getStreet()); orderInfo.setAddrDetail(orderPHisDto.getDeliveryAddress().getAddrDetail()); } orderInfo.setSnapPayTotal(BigDecimal.ZERO); orderInfo.setIsOldBringNew(isOldBringNew); orderInfo.setIsBothTheOne(isBothTheOne); // 处理初复诊到店时间 if (isBothTheOne != null && (OrderInfo.FIRST_VISIT == isBothTheOne || OrderInfo.CONSULTATION == isBothTheOne)){ // 获取下单当天离下单时间最近的到访时间 Date arrivalTime = OrderUtil.getNearOrderArrivalTime(commonService, VisitRecordMapper.class, ordersTotal.getCreateTime(), ordersTotal.getUserId()); if (arrivalTime != null){ orderInfo.setBothTheOneTime(arrivalTime); } } //设置用户状态 orderInfo.setUserStatus(user.getUserStatus()); //设置用户所属顾问 if(StringUtils.noNull(user.getHisCorpUserId())){ Employee hisCorpEmployee=commonService.selectOneByKeyBlob(EmployeeMapper.class,user.getHisCorpUserId()); if(hisCorpEmployee!=null){ orderInfo.setHisCorpUserId(hisCorpEmployee.getId()); orderInfo.setHisCorpUserName(StringUtils.isEmpty(hisCorpEmployee.getCnName())?"":hisCorpEmployee.getCnName()); } } //设置用户所属门店 if(StringUtils.noNull(user.getShopId())){ Shop userShop=commonService.selectOneByKey(ShopMapper.class,user.getShopId()); if(userShop!=null){ orderInfo.setUserShopId(userShop.getId()); orderInfo.setUserShopNo(userShop.getCode()); orderInfo.setUserShopName(userShop.getName()); } } //设置用户所属分诊医生:用户所属医生 if(StringUtils.noNull(user.getDoctorCorpUserId())){ Employee doctorCorpEmployee=commonService.selectOneByKeyBlob(EmployeeMapper.class,user.getDoctorCorpUserId()); if(doctorCorpEmployee!=null){ orderInfo.setDoctorCorpUserId(doctorCorpEmployee.getId()); orderInfo.setDoctorCorpUserName(StringUtils.isEmpty(doctorCorpEmployee.getCnName())?"":doctorCorpEmployee.getCnName()); } } //设置用户所属护士:用户所属护士 if(StringUtils.noNull(user.getNurseCorpUserId())){ Employee nurseCorpEmployee=commonService.selectOneByKeyBlob(EmployeeMapper.class,user.getNurseCorpUserId()); if(nurseCorpEmployee!=null){ orderInfo.setNurseCorpUserId(nurseCorpEmployee.getId()); orderInfo.setNurseCorpUserName(StringUtils.isEmpty(nurseCorpEmployee.getCnName())?"":nurseCorpEmployee.getCnName()); } } //设置用户所属电网咨询师(tmk):用户所属电网咨询师 if(StringUtils.noNull(user.getInternetCorpUserId())){ Employee internetCorpEmployee=commonService.selectOneByKeyBlob(EmployeeMapper.class,user.getInternetCorpUserId()); if(internetCorpEmployee!=null){ orderInfo.setInternetCorpUserId(internetCorpEmployee.getId()); orderInfo.setInternetCorpUserName(StringUtils.isEmpty(internetCorpEmployee.getCnName())?"":internetCorpEmployee.getCnName()); } } // 会员信息填充 orderInfo.setMemberLevelId(user.getMemberLevelId()); orderInfo.setMemberLevelName(user.getUserLevel()); commonService.insert(OrderInfoMapper.class, orderInfo); return activityName; } /** * 创建总订单 * * @param ordersTotal 总订单信息 * @param operator 操作人map * @param user 用户资料 * @param userMoney 用户资金信息 * @param commonService 公共方法 */ public static OrdersTotal createOrder(OrdersTotal ordersTotal, Map operator, User user, UserMoney userMoney, CommonService commonService) { if (ordersTotal != null && StringUtils.noNull(ordersTotal.getInviteeId())) { if (ordersTotal.getInviteeType() == null || UserChannelType.CATEGORY_MEMBERS.equals(ordersTotal.getInviteeType())) { User users = commonService.selectOneByKeyBlob(UserMapper.class, ordersTotal.getInviteeId()); if (users != null) { ordersTotal.setUserBelongingType(users.getUserBelongingType()); } } } if (StringUtils.noNull(ordersTotal.getKoapOrderId())) { BigDecimal koapItemMoney = SynOrderUtil.koapItemMoney(ordersTotal.getKoapOrderId(), commonService); ordersTotal.setShouldTotal(koapItemMoney); ordersTotal.setTotal(koapItemMoney); } ordersTotal.setUserLevel(user == null ? "" : user.getUserLevel()); ordersTotal.setCIQ(user == null ? "" : user.getCIQ()); ordersTotal.setStoredValueFund(userMoney == null ? "" : userMoney.getStoredValueFund()); ordersTotal.setValueAddedFund(userMoney == null ? "" : userMoney.getValueAddedFund()); ordersTotal.setIntegral(userMoney == null ? "" : userMoney.getIntegral()); //用户所属门店 if(user != null && StringUtils.noNull(user.getShopId())){ Shop shop = commonService.selectOneByKey(ShopMapper.class,user.getShopId()); if(shop != null){ ordersTotal.setUserShopId(shop.getId()); ordersTotal.setUserShopNo(shop.getCode()); ordersTotal.setUserShopName(shop.getName()); } } // 是否拼团 if (ordersTotal.getIsGroupBuy() == null){ ordersTotal.setIsGroupBuy(BaseEntity.NO); } //创建总订单 commonService.insert(OrdersTotalMapper.class, ordersTotal); return ordersTotal; } /** * 开单-创建一级子订单 实现类 * * @param ordersTotal 总订单 * @param items 一级子订单集合 */ public static void createOrderItem(OrdersTotal ordersTotal, List items, ProjectService projectService, CommonService commonService, SqlSentence sqlSentence, Map map) { map.clear(); for (OrderItem vo : items) { //保存一级子订单 Map bodyPartMap = projectService.selectBodyPart(vo.getCommonId()); vo.setBodyPartsId(bodyPartMap == null ? "" : (String) bodyPartMap.get("bodyPartId")); vo.setBodyPartsName(bodyPartMap == null ? "" : (String) bodyPartMap.get("bodyPartName")); //计算折扣金额 vo.setDiscountOrderPrice(vo.getProPrice().multiply(BigDecimal.valueOf(vo.getBuyNum()).setScale(2,RoundingMode.HALF_UP)).subtract(vo.getTotal())); vo.setOrderId(ordersTotal.getId()); //诉求分类 List appealTypeVoList = null; if (OrderItemConstants.TYPE_PROJECT.equals(vo.getType())) { //获取诉求分类列表 appealTypeVoList = AppealTypeTool.getAppealTypeListByIdList(vo.getAppealTypeIdList(), commonService); } if (appealTypeVoList != null && appealTypeVoList.size() > 0) { String str = AppealTypeTool.getStr(appealTypeVoList); logger.info("拼接的诉求分类:"+str); if (StringUtils.noNull(str)) { String[] split = str.split("-"); for (int i = 0; i < split.length; i++) { if (i == 0) { vo.setAppealSecond(split[i]); } else if (i == 1) { vo.setAppealThird(split[i]); } } } } commonService.insert(OrderItemMapper.class, vo); //述求分类生成,目前项目 if (appealTypeVoList != null && appealTypeVoList.size() > 0){ //生成关联关系 AppealTypeTool.orderProjectInsert(ordersTotal.getId(), vo.getId(), appealTypeVoList, commonService); } map.put("commonId", vo.getCommonId()); map.put("isDel", BaseEntity.NO); //处理一级子订单卡项 if (OrderItemConstants.TYPE_CARD.equals(vo.getType())) { sqlSentence.setSqlSentence("select * from card_item_info where cardItemId=#{m.commonId} and isDel=#{m.isDel}"); List cardItemInfoList = commonService.selectList(CardItemInfoMapper.class, sqlSentence); for (CardItemInfo cardItemInfo : cardItemInfoList) { //生成卡项二级子订单 OrderCreateUtil.createOrderItemSonCard(ordersTotal.getId(), vo, cardItemInfo, 0, commonService); } //处理一级子订单促销 } else if (OrderItemConstants.TYPE_PROMOTION.equals(vo.getType())) { sqlSentence.setSqlSentence("select * from promotion_info where promotionId=#{m.commonId} and isDel=#{m.isDel}"); List promotionInfoList = commonService.selectList(PromotionInfoMapper.class, sqlSentence); //生成促销二级子订单 OrderCreateUtil.createOrderItemProm(ordersTotal, vo,promotionInfoList, commonService); //处理一级子订单卡包 } else if (OrderItemConstants.CARD_BAG.equals(vo.getType())) { if (vo.getCardItemInfoIds() != null && vo.getCardItemInfoIds().size() > 0) { for (CardItemInfo info : vo.getCardItemInfoIds()) { map.clear(); map.put("id", info.getId()); map.put("isDel", BaseEntity.NO); sqlSentence.setSqlSentence("select * from card_item_info where id =#{m.id} and isDel=#{m.isDel} "); CardItemInfo cardItemInfo = commonService.selectOne(CardItemInfoMapper.class, sqlSentence); if (cardItemInfo != null) { cardItemInfo.setUserNum(info.getUserNum()); //生成卡包二级子订单 OrderCreateUtil.createOrderItemSonCard(ordersTotal.getId(), vo, cardItemInfo, 1, commonService); } } } } //虚拟商品 else if (OrderItemConstants.TYPE_COUPON.equals(vo.getType())){ //查询关联中间表数据 map.clear(); map.put("consumablesId", vo.getCommonId()); sqlSentence.setSqlSentence("select * from consumables_assoc where isDel = 0 and consumablesId = #{m.consumablesId} "); List assocList = commonService.selectList(ConsumablesAssocMapper.class, sqlSentence); createOrderItemAssocToVirtualGoods(commonService, vo, assocList); } //创建订单子单的优惠福利中间表数据 createOrderItemPreferential(commonService, vo); //保存子订单商品规格表 OrderGoodsSpecs orderGoodsSpecs; JSONArray objects = JSONArray.parseArray(vo.getSpecs()); for (int i = 0; i < objects.size(); i++) { JSONObject object = objects.getJSONObject(i); orderGoodsSpecs = new OrderGoodsSpecs(); setOrderGoodsSpecs(ordersTotal, orderGoodsSpecs, vo, object); commonService.insert(OrderGoodsSpecsMapper.class, orderGoodsSpecs); } } } /** * 开单-创建卡项的二级子订单 * @param ordersId 总订单标识 * @param vo * @param */ public static void createOrderItemSonCard(String ordersId, OrderItem vo,CardItemInfo cardItemInfo,Integer type,CommonService commonService) { if(cardItemInfo.getPrice()==null){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"开单:卡项组合项目价格为空,组合项标识:"+cardItemInfo.getId()); } if(cardItemInfo.getMaxNum()==null && cardItemInfo.getEveryDrawNum()==null){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"开单:卡项组合项目最大次数或者每次划扣的扣减次数为空,组合项标识:"+cardItemInfo.getId()); } CardEquity cardEquity = commonService.selectOneByKey(CardEquityMapper.class,cardItemInfo.getCardEquityId()); //卡项明细分摊金额 BigDecimal shareMoney=cardItemInfo.getShareMoney()==null?cardItemInfo.getEveryShareMoney():cardItemInfo.getShareMoney(); BigDecimal pro2Price; BigDecimal curPrice; //每次划扣金额 BigDecimal everySnapMoney; OrderItemSon orderItemSon=new OrderItemSon(); //卡项明细最大次数或者每次划扣次数 Integer cardNum=cardItemInfo.getMaxNum() ==null ?cardItemInfo.getEveryDrawNum():cardItemInfo.getMaxNum(); //数量 orderItemSon.setBuyNum(OrderItemConstants.CARD_BAG.equals(vo.getType())?cardItemInfo.getUserNum():cardNum); if(OrderItemConstants.CARD_BAG.equals(vo.getType())){ if(CardEquity.EQUITY_TYPE_TIME_CARD.equals(cardEquity.getEquityType())){ //-----次卡 //每次划扣金额 if(cardItemInfo.getEveryDrawNum()>0){ everySnapMoney = cardItemInfo.getEveryShareMoney().divide(BigDecimal.valueOf(cardItemInfo.getEveryDrawNum()),10,RoundingMode.HALF_UP); }else{ everySnapMoney = BigDecimal.ZERO; } pro2Price = cardItemInfo.getEveryShareMoney(); }else{ //-----N选M/固定项目/其他 //每次划扣金额 if(cardItemInfo.getMaxNum()>0){ everySnapMoney = cardItemInfo.getShareMoney().divide(BigDecimal.valueOf(cardItemInfo.getMaxNum()),2,RoundingMode.HALF_UP); }else{ everySnapMoney = BigDecimal.ZERO; } pro2Price = everySnapMoney; } curPrice = pro2Price; }else{ pro2Price = shareMoney; curPrice = pro2Price; } BigDecimal originalPrice=BigDecimal.ZERO; if(OrderTotalConstants.TYPE_PROJECT.equals(cardItemInfo.getCommonType())){ Project project=commonService.selectOneByKeyBlob(ProjectMapper.class,cardItemInfo.getCommonId()); BigDecimal proPrice=BigDecimal.ZERO; if(project!=null&&project.getOriginalPrice()!=null){ originalPrice=project.getOriginalPrice(); } if(project!=null&&project.getPrice()!=null){ proPrice=project.getPrice(); } SqlSentence sqlSentence = new SqlSentence(); Map objectMap=new HashMap<>(); sqlSentence.setM(objectMap); objectMap.put("commonId",vo.getCommonId()); objectMap.put("isDel",BaseEntity.NO); sqlSentence.setSqlSentence("select * from project_info where projectId=#{m.commonId} and isDel=#{m.isDel} "); ProjectInfo projectInfo=commonService.selectOne(ProjectInfoMapper.class,sqlSentence); JSONArray jsonObject=new JSONArray(); sqlSentence.setSqlSentence("select * from project_spec_value where projectId=#{m.commonId} and isDel=#{m.isDel} "); List projectSpecValues = commonService.selectList(ProjectSpecValueMapper.class, sqlSentence); if(projectSpecValues!=null && projectSpecValues.size()>0){ for (ProjectSpecValue projectSpecValue : projectSpecValues) { Map specMap=new HashMap<>(); SpecificationValue specificationValue=commonService.selectOneByKeyBlob(SpecificationValueMapper.class,projectSpecValue.getSpecValue()); if(specificationValue!=null){ Specification specification=commonService.selectOneByKeyBlob(SpecificationMapper.class,specificationValue.getSpecificationId()); if(specification!=null){ specMap.put("specsTitle",specification.getSpecName()); } specMap.put("specsValue",specificationValue.getSpecValueName()); specMap.put("specsId",specificationValue.getId()); specMap.put("unit",""); } jsonObject.add(specMap); } }else{ Map map=new HashMap<>(); map.put("specsTitle","规格"); map.put("specsValue",project==null?"":StringUtils.isEmpty(project.getSpecification())?"":project.getSpecification()); map.put("unit",project==null?"":StringUtils.isEmpty(project.getUnit())?"":project.getUnit()); map.put("bodyPartName",projectInfo==null?"":StringUtils.isEmpty(projectInfo.getBodyPartName())?"":projectInfo.getBodyPartName()); map.put("doctorQualification",projectInfo==null?"":StringUtils.isEmpty(projectInfo.getDoctorQualification())?"":projectInfo.getDoctorQualification()); jsonObject.add(map); } //荣爷说项目疗程次数为空值,默认为1 if(project.getIsExecutable()!=null && project.getIsExecutable()==BaseEntity.YES){ Integer useredTotal=project==null?0:project.getTreatmentItemsNum()==null?1:project.getTreatmentItemsNum()==0?1:project.getTreatmentItemsNum(); orderItemSon.setUsedOne(useredTotal);//订单单次疗程数量 }else if(project.getIsExecutable()!=null && project.getIsExecutable()==BaseEntity.NO){ Integer useredTotal=project==null?0:project.getTreatmentItemsNum()==null?0:project.getTreatmentItemsNum(); orderItemSon.setUsedOne(useredTotal);//订单单次疗程数量 }else{ orderItemSon.setUsedOne(0);//订单单次疗程数量 } //疗程总次数=订单单次疗程数量* 订单购买数量 orderItemSon.setUsedTotal(orderItemSon.getUsedOne()*orderItemSon.getBuyNum()); orderItemSon.setSpecs(jsonObject.isEmpty()?"[]":jsonObject.toJSONString()); orderItemSon.setSpecsName(StringUtils.isEmpty(project.getSpecification())?"":project.getSpecification()); if(projectInfo!=null){ if(StringUtils.noNull(projectInfo.getBodyPartId())){ orderItemSon.setBodyPartsId(projectInfo.getBodyPartId()); } if(StringUtils.noNull(projectInfo.getBodyPartName())){ orderItemSon.setBodyPartsName(projectInfo.getBodyPartName()); } if(StringUtils.noNull(projectInfo.getExecutiveQualificationCode())){ orderItemSon.setAptitudeNo(projectInfo.getExecutiveQualificationCode()); } if(StringUtils.noNull(projectInfo.getExecutiveQualificationName())){ orderItemSon.setAptitudeName(projectInfo.getExecutiveQualificationName()); } if(StringUtils.noNull(projectInfo.getDoctorQualification())){ orderItemSon.setDoctorQualification(projectInfo.getDoctorQualification()); } } }else if(OrderTotalConstants.TYPE_RETAIL.equals(cardItemInfo.getCommonType())){ JSONArray jsonArray = new JSONArray(); Consumables consumables=commonService.selectOneByKeyBlob(ConsumablesMapper.class,cardItemInfo.getCommonId()); if(consumables!=null){ if(consumables.getBuyPrice()!=null){ originalPrice=consumables.getBuyPrice(); } if(StringUtils.noNull(consumables.getSpec())){ Map specMap=new HashMap<>(); specMap.put("specsId",""); specMap.put("specsTitle","规格"); specMap.put("specsValue",consumables.getSpec()); specMap.put("unit",""); jsonArray.add(specMap); } if(StringUtils.noNull(consumables.getPackSpec())){ Map packSpecMap=new HashMap<>(); packSpecMap.put("specsId",""); packSpecMap.put("specsTitle","包装规格"); packSpecMap.put("specsValue",consumables.getPackSpec()); packSpecMap.put("unit",""); jsonArray.add(packSpecMap); } if(StringUtils.noNull(consumables.getzSpec())){ Map zSpecMap=new HashMap<>(); zSpecMap.put("specsId",""); zSpecMap.put("specsTitle","中药规格"); zSpecMap.put("specsValue",consumables.getzSpec()); zSpecMap.put("unit",""); jsonArray.add(zSpecMap); } if(StringUtils.noNull(consumables.getUnitIdCode())){ Map unitIdCodeSpecMap=new HashMap<>(); unitIdCodeSpecMap.put("specsId",""); unitIdCodeSpecMap.put("specsTitle","单位(字典编码)"); unitIdCodeSpecMap.put("specsValue",consumables.getUnitIdCode()); unitIdCodeSpecMap.put("unit",""); jsonArray.add(unitIdCodeSpecMap); } if(StringUtils.noNull(consumables.getUnitName())){ Map unitNameSpecMap=new HashMap<>(); unitNameSpecMap.put("specsId",""); unitNameSpecMap.put("specsTitle","单位名称"); unitNameSpecMap.put("specsValue",consumables.getUnitName()); unitNameSpecMap.put("unit",""); jsonArray.add(unitNameSpecMap); } if(StringUtils.noNull(consumables.getzUnitName())){ Map zUnitNameSpecMap=new HashMap<>(); zUnitNameSpecMap.put("specsId",""); zUnitNameSpecMap.put("specsTitle","中药单位"); zUnitNameSpecMap.put("specsValue",consumables.getzUnitName()); zUnitNameSpecMap.put("unit",""); jsonArray.add(zUnitNameSpecMap); } if(StringUtils.noNull(consumables.getPeruseUnit())){ Map peruseUnitSpecMap=new HashMap<>(); peruseUnitSpecMap.put("specsId",""); peruseUnitSpecMap.put("specsTitle","每次用药单位"); peruseUnitSpecMap.put("specsValue",consumables.getPeruseUnit()); peruseUnitSpecMap.put("unit",""); jsonArray.add(peruseUnitSpecMap); } if(consumables.getPeruseCount()!=null){ Map peruseCountSpecMap=new HashMap<>(); peruseCountSpecMap.put("specsId",""); peruseCountSpecMap.put("specsTitle","每次用药数量"); peruseCountSpecMap.put("specsValue",consumables.getPeruseCount()); peruseCountSpecMap.put("unit",""); jsonArray.add(peruseCountSpecMap); } if(consumables.getUsageDays()!=null){ Map usageDaysSpecMap=new HashMap<>(); usageDaysSpecMap.put("specsId",""); usageDaysSpecMap.put("specsTitle","用药天数"); usageDaysSpecMap.put("specsValue",consumables.getUsageDays()); usageDaysSpecMap.put("unit",""); jsonArray.add(usageDaysSpecMap); } if(consumables.getTerm()!=null){ Map termSpecMap=new HashMap<>(); termSpecMap.put("specsId",""); termSpecMap.put("specsTitle","保质期,单位月"); termSpecMap.put("specsValue",consumables.getTerm()); termSpecMap.put("unit",""); jsonArray.add(termSpecMap); } orderItemSon.setSpecsName(StringUtils.isEmpty(consumables.getSpec())?"":consumables.getSpec()); //荣爷说商品没有疗程次数,默认为0 orderItemSon.setUsedTotal(0);//商品没有疗程次数 orderItemSon.setUsedOne(0);//商品没有疗程次数 }else{ orderItemSon.setUsedTotal(0);//暂定为0 orderItemSon.setUsedOne(0);//暂定为0 } } orderItemSon.setType(cardItemInfo.getCommonType()); orderItemSon.setGoodsNo(cardItemInfo.getCommonCode()); orderItemSon.setGoodsId(cardItemInfo.getCommonId()); orderItemSon.setGoodsName(cardItemInfo.getCommonName()); orderItemSon.setGoodsImage("");//暂定为空 //项目原价 orderItemSon.setOriPrice(originalPrice); //项目售价(卡项的分摊金额/卡包就是卡项分摊金额除以使用次数) orderItemSon.setProPrice(pro2Price); //售价 orderItemSon.setCurPrice(curPrice); //折扣=上级item填写的商品折扣 orderItemSon.setDiscount(vo.getDiscount()); //订单售价=项目售价*订单折扣 if(orderItemSon.getDiscount().compareTo(BigDecimal.ZERO)> 0){ orderItemSon.setCurPrice(orderItemSon.getCurPrice().multiply(orderItemSon.getDiscount().divide(new BigDecimal(100),10,RoundingMode.HALF_UP)).setScale(2,RoundingMode.HALF_UP)); }else{ orderItemSon.setCurPrice(BigDecimal.ZERO); } //总金额 BigDecimal total = BigDecimal.ZERO; if(!OrderItemConstants.CARD_BAG.equals(vo.getType())){ total = orderItemSon.getCurPrice().multiply(new BigDecimal(orderItemSon.getBuyNum())); } //优惠前小计=订单售价*数量 orderItemSon.setTotal(total); //优惠券抵扣金额 orderItemSon.setDiscountPrice(BigDecimal.ZERO); //优惠后小计=优惠前小计-优惠券抵扣金额 orderItemSon.setActualTotal(orderItemSon.getTotal().subtract(orderItemSon.getDiscountPrice())); orderItemSon.setOrderId(ordersId); orderItemSon.setOrderItemId(vo.getId()); orderItemSon.setCardItemInfoId(cardItemInfo.getId()); orderItemSon.setCardEquityId(cardItemInfo.getCardEquityId()); orderItemSon.setIsCardBag(type==0?0:1); commonService.insert(OrderItemSonMapper.class,orderItemSon); } /** * 开单-创建二级子订单 * @param ordersTotal 总订单 * @param vo 一级子订单 * @param promotionInfoList 促销详情集合 */ public static void createOrderItemProm(OrdersTotal ordersTotal, OrderItem vo, List promotionInfoList, CommonService commonService) { //升序排序,因为有按照比例算积分 promotionInfoList = promotionInfoList.stream().sorted(Comparator.comparing(PromotionInfo::getDiscountAfterPrice)) .collect(Collectors.toList()); OrderItemSon orderItemSon; SqlSentence sqlSentence; JSONArray jsonArray; //已付积分 BigDecimal integralTotal = vo.getShouldTotalPoints(); //比例 BigDecimal proportion; PromotionInfo promotionInfo; for(int i= 0;i objectMap=new HashMap<>(); sqlSentence.setM(objectMap); objectMap.put("commonId",vo.getCommonId()); objectMap.put("isDel",BaseEntity.NO); sqlSentence.setSqlSentence("select * from project_info where projectId=#{m.commonId} and isDel=#{m.isDel} "); ProjectInfo projectInfo=commonService.selectOne(ProjectInfoMapper.class,sqlSentence); Integer useredTotal=0; //荣爷说项目疗程次数为空值,默认为1 if(project.getIsExecutable()!=null && project.getIsExecutable()==BaseEntity.YES){ useredTotal=project==null?0:project.getTreatmentItemsNum()==null?1:project.getTreatmentItemsNum()==0?1:project.getTreatmentItemsNum(); }else if(project.getIsExecutable()!=null && project.getIsExecutable()==BaseEntity.NO){ useredTotal=project==null?0:project.getTreatmentItemsNum()==null?0:project.getTreatmentItemsNum(); } orderItemSon.setUsedOne(useredTotal);//订单单次疗程数量 logger.info("useredTotal:{},orderUsedOne:{},bueNum:{}",useredTotal,orderItemSon.getUsedOne(),orderItemSon.getBuyNum()); //疗程总次数=订单单次疗程数量* 订单购买数量*促销项目数量 orderItemSon.setUsedTotal(orderItemSon.getUsedOne()*orderItemSon.getBuyNum()); sqlSentence.setSqlSentence("select * from project_spec_value where projectId = #{m.commonId} and isDel=#{m.isDel} "); List projectSpecValues = commonService.selectList(ProjectSpecValueMapper.class, sqlSentence); if(projectSpecValues!=null && projectSpecValues.size()>0){ for (ProjectSpecValue projectSpecValue : projectSpecValues) { Map specMap=new HashMap<>(); SpecificationValue specificationValue=commonService.selectOneByKeyBlob(SpecificationValueMapper.class,projectSpecValue.getSpecValue()); if(specificationValue!=null){ Specification specification=commonService.selectOneByKeyBlob(SpecificationMapper.class,specificationValue.getSpecificationId()); if(specification!=null){ specMap.put("specsTitle",specification.getSpecName()); } specMap.put("specsValue",specificationValue.getSpecValueName()); specMap.put("specsId",specificationValue.getId()); specMap.put("unit",""); } jsonArray.add(specMap); } }else{ Map map=new HashMap<>(); map.put("specsTitle","规格"); map.put("specsValue",project==null?"":StringUtils.isEmpty(project.getSpecification())?"":project.getSpecification()); map.put("unit",project==null?"":StringUtils.isEmpty(project.getUnit())?"":project.getUnit()); map.put("bodyPartName",projectInfo==null?"":StringUtils.isEmpty(projectInfo.getBodyPartName())?"":projectInfo.getBodyPartName()); map.put("doctorQualification",projectInfo==null?"":StringUtils.isEmpty(projectInfo.getDoctorQualification())?"":projectInfo.getDoctorQualification()); jsonArray.add(map); } orderItemSon.setSpecsName(StringUtils.isEmpty(project.getSpecification())?"":project.getSpecification()); if(projectInfo!=null){ if(StringUtils.noNull(projectInfo.getBodyPartId())){ orderItemSon.setBodyPartsId(projectInfo.getBodyPartId()); } if(StringUtils.noNull(projectInfo.getBodyPartName())){ orderItemSon.setBodyPartsName(projectInfo.getBodyPartName()); } if(StringUtils.noNull(projectInfo.getExecutiveQualificationCode())){ orderItemSon.setAptitudeNo(projectInfo.getExecutiveQualificationCode()); } if(StringUtils.noNull(projectInfo.getExecutiveQualificationName())){ orderItemSon.setAptitudeName(projectInfo.getExecutiveQualificationName()); } if(StringUtils.noNull(projectInfo.getDoctorQualification())){ orderItemSon.setDoctorQualification(projectInfo.getDoctorQualification()); } } } }else if(GroupTypeEnum.RETAIL.equals(GroupTypeEnum.getCode(promotionInfo.getType()))){ Consumables consumables=commonService.selectOneByKeyBlob(ConsumablesMapper.class,promotionInfo.getCommonId()); if(consumables!=null){ if(StringUtils.noNull(consumables.getSpec())){ Map specMap=new HashMap<>(); specMap.put("specsId",""); specMap.put("specsTitle","规格"); specMap.put("specsValue",consumables.getSpec()); specMap.put("unit",""); jsonArray.add(specMap); } if(StringUtils.noNull(consumables.getPackSpec())){ Map packSpecMap=new HashMap<>(); packSpecMap.put("specsId",""); packSpecMap.put("specsTitle","包装规格"); packSpecMap.put("specsValue",consumables.getPackSpec()); packSpecMap.put("unit",""); jsonArray.add(packSpecMap); } if(StringUtils.noNull(consumables.getzSpec())){ Map zSpecMap=new HashMap<>(); zSpecMap.put("specsId",""); zSpecMap.put("specsTitle","中药规格"); zSpecMap.put("specsValue",consumables.getzSpec()); zSpecMap.put("unit",""); jsonArray.add(zSpecMap); } if(StringUtils.noNull(consumables.getUnitIdCode())){ Map unitIdCodeSpecMap=new HashMap<>(); unitIdCodeSpecMap.put("specsId",""); unitIdCodeSpecMap.put("specsTitle","单位(字典编码)"); unitIdCodeSpecMap.put("specsValue",consumables.getUnitIdCode()); unitIdCodeSpecMap.put("unit",""); jsonArray.add(unitIdCodeSpecMap); } if(StringUtils.noNull(consumables.getUnitName())){ Map unitNameSpecMap=new HashMap<>(); unitNameSpecMap.put("specsId",""); unitNameSpecMap.put("specsTitle","单位名称"); unitNameSpecMap.put("specsValue",consumables.getUnitName()); unitNameSpecMap.put("unit",""); jsonArray.add(unitNameSpecMap); } if(StringUtils.noNull(consumables.getzUnitName())){ Map zUnitNameSpecMap=new HashMap<>(); zUnitNameSpecMap.put("specsId",""); zUnitNameSpecMap.put("specsTitle","中药单位"); zUnitNameSpecMap.put("specsValue",consumables.getzUnitName()); zUnitNameSpecMap.put("unit",""); jsonArray.add(zUnitNameSpecMap); } if(StringUtils.noNull(consumables.getPeruseUnit())){ Map peruseUnitSpecMap=new HashMap<>(); peruseUnitSpecMap.put("specsId",""); peruseUnitSpecMap.put("specsTitle","每次用药单位"); peruseUnitSpecMap.put("specsValue",consumables.getPeruseUnit()); peruseUnitSpecMap.put("unit",""); jsonArray.add(peruseUnitSpecMap); } if(consumables.getPeruseCount()!=null){ Map peruseCountSpecMap=new HashMap<>(); peruseCountSpecMap.put("specsId",""); peruseCountSpecMap.put("specsTitle","每次用药数量"); peruseCountSpecMap.put("specsValue",consumables.getPeruseCount()); peruseCountSpecMap.put("unit",""); jsonArray.add(peruseCountSpecMap); } if(consumables.getUsageDays()!=null){ Map usageDaysSpecMap=new HashMap<>(); usageDaysSpecMap.put("specsId",""); usageDaysSpecMap.put("specsTitle","用药天数"); usageDaysSpecMap.put("specsValue",consumables.getUsageDays()); usageDaysSpecMap.put("unit",""); jsonArray.add(usageDaysSpecMap); } if(consumables.getTerm()!=null){ Map termSpecMap=new HashMap<>(); termSpecMap.put("specsId",""); termSpecMap.put("specsTitle","保质期,单位月"); termSpecMap.put("specsValue",consumables.getTerm()); termSpecMap.put("unit",""); jsonArray.add(termSpecMap); } orderItemSon.setSpecsName(StringUtils.isEmpty(consumables.getSpec())?"":consumables.getSpec()); orderItemSon.setUsedTotal(usedTotal);//暂定为0 orderItemSon.setUsedOne(usedOne);//暂定为0 } }else{ orderItemSon.setUsedTotal(usedTotal);//暂定为0 orderItemSon.setUsedOne(usedOne);//暂定为0 } orderItemSon.setType(promotionInfo.getType()); orderItemSon.setGoodsNo(promotionInfo.getCommonCode()); orderItemSon.setGoodsId(promotionInfo.getCommonId()); orderItemSon.setGoodsName(promotionInfo.getCommonName()); orderItemSon.setGoodsImage("");//暂定为空 orderItemSon.setSpecs(jsonArray.isEmpty()?"[]":jsonArray.toJSONString()); //项目单价 orderItemSon.setOriPrice(promotionInfo.getPrice()); //促销单价 orderItemSon.setProPrice(promotionInfo.getDiscountPrice()); //上级item填写的商品折扣 orderItemSon.setDiscount(vo.getDiscount()); //订单售价=促销单价*订单折扣 orderItemSon.setCurPrice(orderItemSon.getProPrice().multiply(orderItemSon.getDiscount().divide(new BigDecimal(100),15,RoundingMode.HALF_UP)).setScale(2,RoundingMode.HALF_UP)); BigDecimal total = promotionInfo.getDiscountAfterPrice().multiply(new BigDecimal(vo.getBuyNum())).setScale(2,RoundingMode.HALF_UP); //优惠前小计=订单售价*数量 orderItemSon.setTotal(total.multiply(orderItemSon.getDiscount().divide(new BigDecimal(100),15,RoundingMode.HALF_UP)).setScale(2,RoundingMode.HALF_UP)); //折扣金额 orderItemSon.setDiscountOrderPrice(total.subtract(orderItemSon.getTotal())); //优惠券抵扣金额 orderItemSon.setDiscountPrice(BigDecimal.ZERO); //优惠后小计=优惠前小计-优惠券抵扣金额 orderItemSon.setActualTotal(orderItemSon.getTotal().subtract(orderItemSon.getDiscountPrice()).setScale(2, RoundingMode.HALF_UP)); //可算积分 if(integralTotal.compareTo(BigDecimal.ZERO) > 0){ if(i == promotionInfoList.size()-1){ orderItemSon.setTotalPoints(integralTotal); }else{ //计算金额比例 if(vo.getTotal().compareTo(BigDecimal.ZERO) > 0){ proportion = orderItemSon.getTotal().divide(vo.getTotal(),15,RoundingMode.HALF_UP); }else{ proportion = BigDecimal.ZERO; } //根据比例算出积分 orderItemSon.setTotalPoints(vo.getShouldTotalPoints().multiply(proportion).setScale(0,RoundingMode.HALF_UP)); if(orderItemSon.getTotalPoints().compareTo(integralTotal) > 0){ orderItemSon.setTotalPoints(integralTotal); } } orderItemSon.setShouldTotalPoints(orderItemSon.getTotalPoints()); if(orderItemSon.getBuyNum() > 0){ //这里保留两位小数,可能有除不尽的问题 orderItemSon.setOriginalIntegral(orderItemSon.getTotalPoints().divide(BigDecimal.valueOf(orderItemSon.getBuyNum()),2,RoundingMode.HALF_UP)); } orderItemSon.setProIntegral(orderItemSon.getOriginalIntegral()); orderItemSon.setSellPoints(orderItemSon.getOriginalIntegral()); orderItemSon.setOriIntegralTotal(orderItemSon.getTotalPoints()); orderItemSon.setProIntegralTotal(orderItemSon.getTotalPoints()); //减去已经分配的 integralTotal = integralTotal.subtract(orderItemSon.getTotalPoints()); } orderItemSon.setOrderId(ordersTotal.getId()); orderItemSon.setOrderItemId(vo.getId()); commonService.insert(OrderItemSonMapper.class,orderItemSon); } } /** * 处理整单折扣或者员工折扣 * * @param ordersTotal * @param commonService * @param operator * @param sqlSentence * @param appIdMap * @param user */ public static void handAllAndEmployee(OrdersTotal ordersTotal, CommonService commonService, Map operator, SqlSentence sqlSentence, Map appIdMap, User user, CustomParameter customParameter) { if (PlatformPattern.TEST.equals(customParameter.getPlatformPattern()) && StringUtils.isEmpty(ordersTotal.getKoapOrderId()) && ordersTotal.getOrderInfo() != null) { if (ordersTotal.getOrderInfo().getIsEmployeeDiscount() == BaseEntity.YES && ordersTotal.getOrderInfo().getIsWholeDiscount() == BaseEntity.YES) { appIdMap.put("tel", user.getTel()); appIdMap.put("isDel", BaseEntity.NO); appIdMap.put("isJob", BaseEntity.YES); sqlSentence.setSqlSentence(" tel=#{m.tel} and isDel=#{m.isDel} and isJob=#{m.isJob}"); int count = commonService.selectCount(EmployeeMapper.class, sqlSentence); // logger.info("员工折扣:sql:{},m:{},结果(count):{}", sqlSentence.getSqlSentence(), sqlSentence.getM(), count); if (count <= 0) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "创建订单:该用户不是员工,不能享受员工折扣!"); } else { JbpmParamUtil.wholeEmployeeApproval(ordersTotal, operator, sqlSentence, appIdMap, ordersTotal.getDiscountTotal(), commonService, customParameter, 1); } } if (ordersTotal.getOrderInfo().getIsWholeDiscount() == BaseEntity.YES) { JbpmParamUtil.wholeEmployeeApproval(ordersTotal, operator, sqlSentence, appIdMap, ordersTotal.getDiscountTotal(), commonService, customParameter, 0); } } } /** * 开单-创建领建订单 实现类 * * @param ordersTotal 总订单标识 * @param customParameter * @param commonService * @return */ public static String syncOrder(OrdersTotal ordersTotal, Map operator,String orderNo, CustomParameter customParameter, CommonService commonService) { String hisOrderId = null; if (ordersTotal != null) { if (OrderTotalConstants.TYPE_RECHARGE.equals(ordersTotal.getType())) { //创建领建储值金订单 hisOrderId = SynOrderUtil.synPrepaidOrder(operator, ordersTotal,orderNo, customParameter, commonService); } else { //创建领建销售订单 hisOrderId = SynOrderUtil.synSalesOrder(operator, ordersTotal,orderNo, customParameter, commonService); } } else { throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "同步订单操作未找到订单信息"); } return hisOrderId; } /** * 开单-构建订单商品规格 * * @param ordersTotal 总订单实体 * @param orderGoodsSpecs 订单商品规格标识 * @param vo 一级子订单 * @param object */ public static void setOrderGoodsSpecs(OrdersTotal ordersTotal, OrderGoodsSpecs orderGoodsSpecs, OrderItem vo, JSONObject object) { orderGoodsSpecs.setType(vo.getType()); orderGoodsSpecs.setGoodsId(vo.getCommonId()); orderGoodsSpecs.setGoodsNo(vo.getGoodsNo()); orderGoodsSpecs.setOrderId(ordersTotal.getId()); orderGoodsSpecs.setOrderItemId(vo.getId()); orderGoodsSpecs.setSpecsTitle("规格"); orderGoodsSpecs.setSpecsValue(StringUtils.isEmpty(object.getString("specsValue"))?"":object.getString("specsValue")); orderGoodsSpecs.setSpecsId(vo.getCommonId()); orderGoodsSpecs.setUnit(object.getString("unit")); } /** * 开单-限制项目 * @param user 用户信息 * @param shop 操作人门店信息 * @param commonService * @param sqlSentence * @param objectMap * @param vo 一级子订单 */ public static void limitProject(User user, Shop shop, CommonService commonService, SqlSentence sqlSentence, Map objectMap, OrderItem vo) { objectMap.clear(); objectMap.put("commonId", vo.getCommonId()); sqlSentence.setSqlSentence("SELECT p.* FROM project p WHERE p.id=#{m.commonId} and p.isDel =0 and p.isUp =1"); Project project = commonService.selectOne(ProjectMapper.class, sqlSentence); if (project == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "找不到项目:" + vo.getCommonId()); } if (project.getPrice() == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "项目:" + project.getName() + ",没有销售价格,请填写销售单价再进行创建订单"); } objectMap.clear(); objectMap.put("isDel", BaseEntity.NO); //限制会员等级购买 objectMap.put("foreignKey", project.getId()); OrderAddUtil.checkMemberLevel(sqlSentence, user, OrderItemConstants.TYPE_CARD, commonService); JSONObject param = new JSONObject(); param.put("commonId", project.getId()); param.put("commonName",project.getName()); param.put("userId", user.getId()); param.put("shopId", shop.getId()); //限制项目 LimitPlatformUtil.limitMethod(commonService, param.toJSONString(),vo.getBuyNum()); } /** * 限制商品 * @param user 用户信息 * @param shop 操作人门店信息 * @param commonService * @param sqlSentence * @param objectMap * @param vo 一级子订单 */ public static void limitConsumables(User user, Shop shop, CommonService commonService, SqlSentence sqlSentence, Map objectMap, OrderItem vo) { Consumables consumables = commonService.selectOneByKey(ConsumablesMapper.class, vo.getCommonId()); if (consumables == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "找不到项目:" + vo.getCommonId()); } if (consumables.getPrice() == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "商品:" + consumables.getName() + ",没有销售价格,请填写销售单价在进行创建订单"); } objectMap.clear(); objectMap.put("isDel", BaseEntity.NO); //限制会员等级购买 objectMap.put("foreignKey", consumables.getId()); OrderAddUtil.checkMemberLevel(sqlSentence, user, OrderItemConstants.TYPE_CARD, commonService); JSONObject param = new JSONObject(); param.put("commonId", consumables.getId()); param.put("commonName",consumables.getName()); param.put("userId", user.getId()); param.put("shopId", shop.getId()); //限制商品 LimitPlatformUtil.limitMethod(commonService, param.toJSONString(),vo.getBuyNum()); } /** * 限制卡项 * @param user 用户信息 * @param shop 操作人门店信息 * @param commonService * @param sqlSentence * @param objectMap * @param vo 一级子订单 */ public static void limitCard(User user, Shop shop,PlatformApplication platformApplication, CommonService commonService, SqlSentence sqlSentence, Map objectMap, OrderItem vo) { //处理卡项 objectMap.clear(); objectMap.put("status", CardItem.SALES); objectMap.put("isUp", BaseEntity.YES); objectMap.put("isDel", BaseEntity.NO); objectMap.put("commonId", vo.getCommonId()); sqlSentence.setSqlSentence("select * from card_item where id=#{m.commonId} and status=#{m.status} and isUp=#{m.isUp} and isDel=#{m.isDel}"); CardItem cardItem = commonService.selectOne(CardItemMapper.class, sqlSentence); if (cardItem == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "找不到该卡项,请确保卡项状态必须是销售中并且是上架状态,卡项标识:" + vo.getCommonId()); } if (cardItem.getTotal() == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "卡项:" + cardItem.getName() + ",没有销售价格,请填写销售单价在进行创建订单"); } objectMap.clear(); objectMap.put("isDel", BaseEntity.NO); //限制会员等级购买 objectMap.put("foreignKey", cardItem.getId()); OrderAddUtil.checkMemberLevel(sqlSentence, user, OrderItemConstants.TYPE_CARD, commonService); JSONObject param = new JSONObject(); param.put("commonId", cardItem.getId()); param.put("commonName",cardItem.getName()); param.put("userId", user.getId()); param.put("shopId", shop.getId()); param.put("platformApplication", JSON.toJSON(platformApplication)); //限制卡项 LimitPlatformUtil.limitMethod(commonService, param.toJSONString(),vo.getBuyNum()); } /** * 限制促销 * @param user 用户信息 * @param shop 操作人门店信息 * @param commonService * @param sqlSentence * @param objectMap * @param vo 一级子订单 */ public static void limitPromotion(User user, Shop shop,PlatformApplication platformApplication, CommonService commonService, SqlSentence sqlSentence, Map objectMap, OrderItem vo) { objectMap.clear(); objectMap.put("status", Promotion.IN_PROGRESS); objectMap.put("isUp", BaseEntity.YES); objectMap.put("isDel", BaseEntity.NO); objectMap.put("commonId", vo.getCommonId()); sqlSentence.setSqlSentence("select * from promotion where id=#{m.commonId} and status=#{m.status} and isUp=#{m.isUp} and isDel=#{m.isDel}"); Promotion promotion = commonService.selectOne(PromotionMapper.class, sqlSentence); if (promotion == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "找不到该促销,请确保促销状态必须是销售中并且是上架状态,促销标识:" + vo.getCommonId()); } if (promotion.getTotal() == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "促销:" + promotion.getName() + ",没有销售价格,请填写销售单价在进行创建订单"); } objectMap.clear(); objectMap.put("isDel", BaseEntity.NO); objectMap.put("foreignKey", promotion.getId()); //限制会员等级购买 OrderAddUtil.checkMemberLevel(sqlSentence, user, OrderItemConstants.TYPE_PROMOTION, commonService); JSONObject param = new JSONObject(); param.put("commonId", promotion.getId()); param.put("commonName",promotion.getName()); param.put("userId", user.getId()); param.put("shopId", shop.getId()); param.put("platformApplication",JSON.toJSON(platformApplication)); //限制促销 LimitPlatformUtil.limitMethod(commonService, param.toJSONString(),vo.getBuyNum()); } /** * 保存订单的活动规则 * @param activityIds */ public static void insertActivity(List activityIds,OrdersTotal ordersTotal,CommonService commonService) { OrdersActivityInfo ordersActivityInfo; OrdersActivityInfoItem ordersActivityInfoItem; SqlSentence sqlSentence; Map map; for (String activityId : activityIds) { //查询活动规则基础信息 ActivityRule activityRule=commonService.selectOneByKey(ActivityRuleMapper.class,activityId); if(activityRule!=null){ //保存订单活动规则表 ordersActivityInfo=new OrdersActivityInfo(); ordersActivityInfo.setOrderId(ordersTotal.getId()); ordersActivityInfo.setActivityId(activityRule.getId()); ordersActivityInfo.setActivityName(activityRule.getName()); commonService.insert(OrdersActivityInfoMapper.class,ordersActivityInfo); //保存订单活动规则子表 sqlSentence = new SqlSentence(); map=new HashMap<>(); sqlSentence.setM(map); map.put("isDel",BaseEntity.NO); map.put("activityRuleId",activityRule.getId()); sqlSentence.setSqlSentence("select * from activity_action where activityRuleId=#{m.activityRuleId} and isDel=#{m.isDel}"); //根据活动组来查询活动的条件集合,同时满足才能进行满减金额或者满减折扣 List activityActions = commonService.selectList(ActivityActionMapper.class, sqlSentence); if(activityActions!=null && activityActions.size()>0){ for (ActivityAction activityAction : activityActions) { ordersActivityInfoItem=new OrdersActivityInfoItem(); ordersActivityInfoItem.setOrderId(ordersTotal.getId()); ordersActivityInfoItem.setActivityInfoId(ordersActivityInfo.getId()); ordersActivityInfoItem.setActivityRuleId(activityRule.getId()); ordersActivityInfoItem.setType(activityAction.getType()); ordersActivityInfoItem.setWorth(activityAction.getWorth()); ordersActivityInfoItem.setWorthName(activityAction.getWorthName()); ordersActivityInfoItem.setActivityGroupId(activityAction.getActivityGroupId()); ordersActivityInfoItem.setActivityRuleId(activityAction.getActivityRuleId()); ordersActivityInfoItem.setActivityActionId(activityAction.getId()); ordersActivityInfoItem.setCrmCouponId(activityAction.getCrmCouponId()); ordersActivityInfoItem.setCrmCouponName(activityAction.getCrmCouponName()); ordersActivityInfoItem.setPlatformType(activityAction.getPlatformType()); ordersActivityInfoItem.setPerformStatus(OrdersActivityInfoItem.STATUS_PERFORM_NONE); if(ActivityAction.TYPE_FULL_REDUCE.equals(ordersActivityInfoItem.getType()) || ActivityAction.TYPE_DISCOUNT.equals(ordersActivityInfoItem.getType())){ if(ordersTotal.getActivityTotal() != null && ordersTotal.getActivityTotal().compareTo(BigDecimal.ZERO) > 0){ ordersActivityInfoItem.setPerformStatus(OrdersActivityInfoItem.STATUS_PERFORM_SEND_OUT); ordersActivityInfoItem.setHandleStatus(OrdersActivityInfoItem.HANDLE_STATUS_SUCCESS); } } commonService.insert(OrdersActivityInfoItemMapper.class,ordersActivityInfoItem); } } } } } /** * 结账-订单异常发送企业通知和保存重发记录 * @param ordersTotal 总订单 * @param e 异常 * @param object 请求参数 * @param interfaceName 接口名称 * @param remarks 备注 * @param commonService * @param customParameter */ public static void orderSendNoticeResendRecord(OrdersTotal ordersTotal, Exception e, JSONObject object,String interfaceName,String remarks,Integer synHisOrderType, CommonService commonService,CustomParameter customParameter) { //构建重发实体对象 ResendRecord resendRecord = ResendUtil.saveOrResend(JSONObject.toJSONString(object), "", e.getMessage(), interfaceName, StringUtils.isEmpty(ordersTotal.getKoapOrderId())?ResendRecord.TYPE_SOURCE_ORDER_SYN_PHISKIN:ResendRecord.TYPE_SOURCE_ORDER_SYN_KOAP, ResendRecord.TYPE_SYN,remarks ,ordersTotal.getId(),ResendRecord.TYPE_COMMONTYPE_ORDER, null,ordersTotal.getAppIdCode(),commonService); resendRecord.setIsResend(BaseEntity.YES); resendRecord.setIsSuccess(BaseEntity.NO); resendRecord.setNodeType(synHisOrderType); //新增或更新重发记录 commonService.insert(ResendRecordMapper.class,resendRecord); } /** * 折扣审批-营销助手审批 * @param ordersTotal 总订单 * @param mOrderService 营销助手service * @param commonService */ public static void approvalMarketing(OrdersTotal ordersTotal, MOrderService mOrderService, CommonService commonService) { //荣爷说订单是crm那边的订单不走营销助手审批 if(!PlatformConstants.TYPE_PLATFORM_CRM.equals(ordersTotal.getAppIdCode()) && ordersTotal.getOrderInfo() !=null &&ordersTotal.getOrderInfo().getDiscount()!=null && ordersTotal.getOrderInfo().getDiscount().compareTo(new BigDecimal(100))==-1){ //查看订单操作人信息 Employee employee = commonService.selectOneByKeyBlob(EmployeeMapper.class, ordersTotal.getOperatorId()); if(employee==null){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"营销助手审批:未找到操作人员工信息!"); } SqlSentence sqlSentence = new SqlSentence(); Map sqlMap = new HashMap<>(); sqlMap.put("id",employee.getRoleId()); sqlSentence.sqlSentence(" SELECT er.*,s.name AS shopName FROM employee_role AS er " + " LEFT JOIN shop AS s ON s.id = er.shopId WHERE er.id = #{m.id}",sqlMap); EmployeeRole employeeRole = commonService.selectOne(EmployeeRoleMapper.class,sqlSentence); OrdersTotalDto ordersTotalDto=new OrdersTotalDto(); ordersTotalDto.setTotal(ordersTotal.getShouldTotal().add(ordersTotal.getDiscountTotal())); ordersTotalDto.setOrderNo(ordersTotal.getOrderNo()); ordersTotalDto.setId(ordersTotal.getId()); ordersTotalDto.setDisTotal(ordersTotal.getShouldTotal()); //走审批流程,封装对象 OrderDiscountDto orderDiscountDto = new OrderDiscountDto(); orderDiscountDto.setDiscountNum(ordersTotal.getOrderInfo().getDiscount()); orderDiscountDto.setOrdersTotalDto(ordersTotalDto); orderDiscountDto.setOperatorId(ordersTotal.getOperatorId()); orderDiscountDto.setOpName(ordersTotal.getOperatorName()); orderDiscountDto.setShopId(employeeRole.getShopId()); orderDiscountDto.setShopName(employeeRole.getShopName()); orderDiscountDto.setRoleId(employeeRole.getRoleTypeId()); orderDiscountDto.setRoleUniqueStr(employeeRole.getRoleUniqueStr()); orderDiscountDto.setUserId(ordersTotal.getUserId()); orderDiscountDto.setRemark(ordersTotal.getRemarks()); //调用营销助手审批 logger.info("请求营销助手审批接口,参数:{}", JSONObject.toJSONString(orderDiscountDto)); Result result = mOrderService.applyOrderDiscount(orderDiscountDto); logger.info("营销助手审批接口,返回:{}",JSONObject.toJSONString(result)); if (result != null) { result.checkTips(); JSONObject object = JSONObject.parseObject(JSONObject.toJSONString(result.getData())); if(!object.isEmpty()){ String applyId = object.getString("applyId"); SqlSentence sql = new SqlSentence(); Map objectMap=new HashMap<>(); sql.setM(objectMap); //保存营销助手的审批标识 objectMap.put("applyId",applyId); objectMap.put("id",ordersTotal.getOrderInfo().getId()); sql.setSqlSentence(" applyId=#{m.applyId} where id=#{m.id}"); commonService.updateWhere(OrderInfoMapper.class,sql); //更新总订单状态 objectMap.clear(); objectMap.put("status", OrderTotalConstants.STATUS_APPLE_PENDING); objectMap.put("oldStatus", OrderTotalConstants.STATUS_APPLE_NONE); objectMap.put("id",ordersTotal.getId()); sql.setSqlSentence(" applyStatus=#{m.status} where id=#{m.id} AND applyStatus=#{m.oldStatus}"); commonService.updateWhere(OrdersTotalMapper.class,sql); ordersTotal.setApplyStatus(OrderTotalConstants.STATUS_APPLE_PENDING); }else{ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"请求营销助手审批接口报错,data返回为空!"); } } else { throw new PlatTipsException(PlatformCode.ERROR_TIPS,"请求营销助手审批接口报错,返回为空!"); } } } /** * 订单支付审批-营销助手审批 * @param ordersTotal 总订单 * @param mOrderService 营销助手service * @param commonService */ public static void approvalPayMarketing(OrdersTotal ordersTotal,List orderItemList, MOrderService mOrderService, CommonService commonService) { //荣爷说订单是crm那边的订单不走营销助手审批 if(!PlatformConstants.TYPE_PLATFORM_CRM.equals(ordersTotal.getAppIdCode()) && ordersTotal.getOrderInfo() !=null && orderItemList != null && orderItemList.size() > 0){ //查看订单操作人信息 Employee employee = commonService.selectOneByKeyBlob(EmployeeMapper.class, ordersTotal.getOperatorId()); if(employee==null){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"营销助手审批:未找到操作人员工信息!"); } EmployeeRole employeeRole = commonService.selectOneByKeyBlob(EmployeeRoleMapper.class, employee.getRoleId()); OrdersTotalDto ordersTotalDto=new OrdersTotalDto(); ordersTotalDto.setTotal(ordersTotal.getShouldTotal().add(ordersTotal.getDiscountTotal())); ordersTotalDto.setOrderNo(ordersTotal.getOrderNo()); ordersTotalDto.setId(ordersTotal.getId()); ordersTotalDto.setDisTotal(ordersTotal.getShouldTotal()); //走审批流程,封装对象 OrderPayMarketingDto orderPayMarketingDto = new OrderPayMarketingDto(); orderPayMarketingDto.setOrdersTotalDto(ordersTotalDto); orderPayMarketingDto.setDiscountNum(ordersTotal.getOrderInfo().getDiscount()); orderPayMarketingDto.setOperatorId(ordersTotal.getOperatorId()); orderPayMarketingDto.setOpName(ordersTotal.getOperatorName()); orderPayMarketingDto.setShopId(ordersTotal.getShopId()); orderPayMarketingDto.setShopName(ordersTotal.getShopName()); orderPayMarketingDto.setRoleId(employeeRole.getRoleTypeId()); orderPayMarketingDto.setRoleUniqueStr(employeeRole.getRoleUniqueStr()); orderPayMarketingDto.setUserId(ordersTotal.getUserId()); orderPayMarketingDto.setRemark(ordersTotal.getRemarks()); List projectDtoList = new ArrayList<>(); for (OrderItem orderItem : orderItemList) { RefundProjectDto refundProjectDto = new RefundProjectDto(); refundProjectDto.setProjectId(orderItem.getCommonId()); refundProjectDto.setProjectNo(orderItem.getGoodsNo()); refundProjectDto.setProjectName(orderItem.getGoodsName()); //传到退款数量字段 refundProjectDto.setBuyNum(orderItem.getBuyNum()); projectDtoList.add(refundProjectDto); } orderPayMarketingDto.setProjectDtoList(projectDtoList); //调用营销助手审批 logger.info("请求营销助手审批接口,参数:{}", JSONObject.toJSONString(orderPayMarketingDto)); Result result = mOrderService.orderPay(orderPayMarketingDto); logger.info("营销助手审批接口,返回:{}",JSONObject.toJSONString(result)); if (result != null) { result.checkTips(); JSONObject object = JSONObject.parseObject(JSONObject.toJSONString(result.getData())); if(!object.isEmpty()){ String applyId = object.getString("applyId"); SqlSentence sql = new SqlSentence(); Map objectMap=new HashMap<>(); sql.setM(objectMap); //保存营销助手的审批标识 objectMap.put("applyId",applyId); objectMap.put("id",ordersTotal.getOrderInfo().getId()); sql.setSqlSentence(" applyId=#{m.applyId} where id=#{m.id}"); commonService.updateWhere(OrderInfoMapper.class,sql); //更新总订单状态 objectMap.clear(); objectMap.put("status", OrderTotalConstants.STATUS_APPLE_PENDING); objectMap.put("oldStatus", OrderTotalConstants.STATUS_APPLE_NONE); objectMap.put("id",ordersTotal.getId()); sql.setSqlSentence(" applyStatus=#{m.status} where id=#{m.id} AND applyStatus=#{m.oldStatus}"); commonService.updateWhere(OrdersTotalMapper.class,sql); ordersTotal.setApplyStatus(OrderTotalConstants.STATUS_APPLE_PENDING); }else{ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"请求营销助手审批接口报错,data返回为空!"); } } else { throw new PlatTipsException(PlatformCode.ERROR_TIPS,"请求营销助手审批接口报错,返回为空!"); } } } /** 创建一级订单关联表数据 to 虚拟商品 */ public static void createOrderItemAssocToVirtualGoods(CommonService commonService, OrderItem orderItem, List assocList){ if(assocList != null && assocList.size() > 0){ OrderItemAssoc orderItemAssoc; for(ConsumablesAssoc assoc : assocList){ orderItemAssoc = new OrderItemAssoc(); orderItemAssoc.setOrderItemId(orderItem.getId()); orderItemAssoc.setQuantity(assoc.getQuantity()); orderItemAssoc.setSourceId(assoc.getId()); orderItemAssoc.setSourceType(OrderItemAssocConstants.SOURCE_TYPE_VIRTUAL_GOODS); commonService.insert(OrderItemAssocMapper.class, orderItemAssoc); } } } /** 开单-校验升单关联信息参数 */ public static List checkOrderRise(CommonService commonService, List orderRiseList){ if(orderRiseList == null || orderRiseList.size() < 1){ return null; } //遍历升单关联的订单 List riseList = new ArrayList<>(); OrdersTotal ordersTotal; OrderRise orderRise; for(OrderRiseDto orderRiseDto : orderRiseList){ if(StringUtils.isEmpty(orderRiseDto.getAssocOrderId())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "升单关联的订单标识不能为空!"); } try{ ordersTotal = OrderNewUtil.checkOrderCanRise(commonService, orderRiseDto.getAssocOrderId()); } catch (TipsException e){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"开单失败,检查升单逻辑时:" + e.getMessage()); } catch (Exception e){ logger.error("开单失败,检查升单异常!{}", SimpleTool.getExceptionMsg(e)); throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "开单失败,检查升单异常!"); } orderRise = new OrderRise(orderRiseDto.getAssocOrderId()); orderRise.setShouldTotal(ordersTotal.getShouldTotal()); riseList.add(orderRise); } return riseList; } /** 创建订单升单关联的信息 */ public static void createOrderRiseInfo(CommonService commonService, OrdersTotal ordersTotal, List orderRiseList){ if(orderRiseList == null || orderRiseList.size() < 1){ return; } //汇总原订单应付金额,判断是否可以升单 BigDecimal oriShouldTotal = orderRiseList.stream().map(s->s.getShouldTotal()).reduce(BigDecimal.ZERO,BigDecimal::add); if(ordersTotal.getShouldTotal().compareTo(oriShouldTotal) == -1){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "开单失败,升单订单的应付金额不能小于原订单应付金额!"); } String orderId = ordersTotal.getId(); for(OrderRise orderRise : orderRiseList){ orderRise.setOrderId(orderId); commonService.insert(OrderRiseMapper.class, orderRise); } } /**获取用户所属顾问的门店 * @param employeeId 员工标识 * @param commonService 映射 * @return 门店 */ public static Shop getUserConsultShop(String employeeId,CommonService commonService){ SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); values.put("employeeId",employeeId); sqlSentence.sqlSentence("SELECT s.* FROM employee_role er" + " JOIN shop s ON s.id = er.shopId" + " WHERE er.isDel = 0 AND er.isMainProfessional = 1 AND er.employeeId = #{m.employeeId} LIMIT 1",values); return commonService.selectOne(ShopMapper.class,sqlSentence); } /** 创建订单子单的优惠福利中间表数据 */ public static void createOrderItemPreferential(CommonService commonService, OrderItem orderItem){ if(orderItem.getOrderItemPreferentialList() == null || orderItem.getOrderItemPreferentialList().size() < 1){ return; } for(OrderItemPreferential orderItemPreferential : orderItem.getOrderItemPreferentialList()){ orderItemPreferential.setOrderId(orderItem.getOrderId()); orderItemPreferential.setOrderItemId(orderItem.getId()); commonService.insert(OrderItemPreferentialMapper.class, orderItemPreferential); } } }