package com.hx.phip.controller.order; /** * 订单控制器 * * @Author: zhouxiang * @Date: 2022/09/19/11:53 * @Description: */ import com.alibaba.fastjson.JSONObject; import com.hx.common.BaseController; import com.hx.common.service.CommonService; import com.hx.exception.TipsException; import com.hx.mybatisTool.SqlSentence; import com.hx.phiappt.common.OrderTotalConstants; import com.hx.phiappt.common.PlatformConstants; import com.hx.phiappt.common.UserStatusConstants; import com.hx.phiappt.constants.tool.PerformanceInfoTool; import com.hx.phiappt.constants.tool.UserStatusTool; import com.hx.phiappt.dao.mapper.*; import com.hx.phiappt.model.*; import com.hx.phiappt.model.coupon.Coupon; import com.hx.phiappt.model.coupon.CouponNumber; import com.hx.phiappt.model.market.system.MarketSystem; import com.hx.phiappt.model.order.*; import com.hx.phiappt.model.performance.PerformanceInfo; import com.hx.phiappt.model.userStatus.UserStatusLog; import com.hx.phiappt.util.TimerHandleItemTool; import com.hx.phip.config.CustomParameter; import com.hx.phip.config.PlatformConfig; import com.hx.phip.service.ShopService; import com.hx.phip.service.SystemParameterService; import com.hx.phip.service.UserMoneyService; import com.hx.phip.service.UserService; import com.hx.phip.service.init.OrderInitService; import com.hx.phip.service.order.OrderServiceV2; import com.hx.phip.service.tool.OrderGeneralServiceTool; import com.hx.phip.service.tool.club.UserCluebMemberServiceTool; import com.hx.phip.util.api.ApiOrderUtil; import com.hx.phip.util.api.OrderCreateUtil; import com.hx.phip.util.api.OrderPayMoneyUtil; import com.hx.phip.util.api.SendNoticeUtil; import com.hx.util.StringUtils; import com.hx.util.thread.ExecutorServiceTool; import com.hz.crm.dto.oldBrinNew.OldBrinNewDto; import com.hz.crm.feign.FOldBrinNewService; import com.hz.his.dto.order.*; import com.platform.constants.LoginConstant; import com.platform.entity.ThirtApplication; import com.platform.exception.PlatTipsException; import com.platform.resultTool.PlatformCode; import com.platform.resultTool.PlatformResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; import java.util.*; /** * 订单控制器 * @USER: zhouxiang * @DATE: 2021/12/03 */ @RestController @RequestMapping("/order") public class OrderControllerV2 extends BaseController { //log4j日志 private static Logger logger = LoggerFactory.getLogger(OrderControllerV2.class.getName()); //订单类型集合(充值,转增充值) private static List orderTypeList= Arrays.asList(OrderTotalConstants.TYPE_RECHARGE,OrderTotalConstants.TYPE_TURN_RECHARGE); @Resource private OrderServiceV2 orderServiceV2; @Resource private ShopService shopService; @Resource private UserMoneyService userMoneyService; @Resource private CustomParameter customParameter; @Resource private UserService userService; @Resource private OrderInitService orderInitService; @Resource private SystemParameterService systemParameterService; @Resource private PlatformConfig platformConfig; @Resource private FOldBrinNewService fOldBrinNewService; @Resource private UserCluebMemberServiceTool userCluebMemberServiceTool; @Resource private OrderGeneralServiceTool orderGeneralServiceTool; /**固定线程池-改*/ public static ExecutorServiceTool threadPool = new ExecutorServiceTool(5,100); /** * 开单接口 */ @RequestMapping(value = "/create",method = RequestMethod.POST) public PlatformResult orderCreate(HttpServletRequest request, @RequestBody OrderPHisDto dto) { //校验请求参数是否为空 if(dto==null){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"请传订单参数"); } //校验签名 ThirtApplication thirtApplication= (ThirtApplication) request.getSession().getAttribute(LoginConstant.LOGIN_APPLY); if(thirtApplication==null){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"签名失败,请检查签名!"); } //打印请求参数 logger.info("前打印新开单接口请求所有参数:{}", JSONObject.toJSONString(dto)); //解析请求参数,并校验参数必填值,赋予默认值等操作 JSONObject object = JSONObject.parseObject(JSONObject.toJSONString(dto)); //解析总订单对象 //OrdersTotal orderTotal = new OrdersTotal(); //BeanUtils.copyProperties(dto.getOrderTotal(),orderTotal); OrdersTotal orderTotal = JSONObject.parseObject(object.getString("orderTotal"), OrdersTotal.class); //校验总订单参数 orderTotal = OrderCreateUtil.checkOrderTotalParam(orderTotal); //获取订单的子订单 List orderItem = JSONObject.parseArray(object.getString("orderItem"), OrderItem.class); //校验子订单参数 orderItem=OrderCreateUtil.checkOrderItem(orderItem,orderTotal.getType(), customParameter, orderTotal.getAppIdCode()); //校验升单关联信息 List orderRiseList = OrderCreateUtil.checkOrderRise(commonService, dto.getOrderRiseList()); //获取开发人员集合 List orderDeveloperList = JSONObject.parseArray(object.getString("orderDeveloper"), OrderDeveloper.class); //操作人id,没有默认填订单用户标识 String operatorId = StringUtils.isEmpty(object.getString("operatorId"))?orderTotal.getUserId():object.getString("operatorId"); //操作类型,0:草稿 1:创建订单 2:创建订单+结账(目前结账和创建是分开的),默认1 Integer type =object.getInteger("type")==null?1:object.getInteger("type"); //获取操作人门店标识 String shopId = object.getString("shopId");//操作人的门店id //查询需求要的信息,并且判空(例如查询门店、用户、用户资金等信息) //获取用户信息 User user = commonService.selectOneByKey(UserMapper.class,orderTotal.getUserId()); if(user==null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找用户信息,订单用户标识:{}"+orderTotal.getUserId()); } //获取操作人信息 Map operator = ApiOrderUtil.getOperator(commonService, operatorId); //获取订单销售平台信息 PlatformApplication platformApplication = OrderCreateUtil.getPlatformApplication(orderTotal, commonService); //是否使用传值数据 if(BaseEntity.YES.equals(dto.getOrderTotal().getUsedTransmitApp())){ if(StringUtils.isEmpty(orderTotal.getAppId())){ throw new TipsException("平台来源必传!"); } if(StringUtils.isEmpty(orderTotal.getAppIdCode())){ throw new TipsException("平台来源编码必传!"); } SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); values.put("appId", orderTotal.getAppId()); sqlSentence.sqlWhere("appId =#{m.appId} and isDel=0 and isUp=1",values); if(commonService.selectCount(PlatformApplicationMapper.class, sqlSentence) != 1){ throw new TipsException("平台来源错误!"); } }else{ orderTotal.setAppId(thirtApplication.getAppId()); orderTotal.setAppIdCode(thirtApplication.getAppIdCode()); } //默认总订单参数 OrderCreateUtil.setDefaultOrderTotal(orderTotal,orderTotal.getAppId(),orderTotal.getAppIdCode(),user,commonService); //查询操作人门店信息 Shop shop = null; if(PlatformConstants.TYPE_PLATFORM_CRM.equals(orderTotal.getAppIdCode())){ //艾芯荟 shop = shopService.selectOneByKey(shopId); } else { //用户咨询师门店 //2023-9-6,员工咨询师的用户拿用户所属门店 if (StringUtils.noNull(user.getHisCorpUserId()) ){ String empId = customParameter.getEmpId(); if (StringUtils.noNull(empId) && Arrays.stream(empId.split(",")).anyMatch(a -> a.equals(user.getHisCorpUserId()))){ shop = shopService.selectOneByKey(user.getShopId()); } } if (shop == null){ shop = OrderCreateUtil.getUserConsultShop(user.getHisCorpUserId(),commonService); if(shop == null){ //操作人门店 shop = OrderCreateUtil.getUserConsultShop(operatorId,commonService); } } } if(shop==null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到门店信息,操作人门店标识"); } //获取用户资金信息,用于订单快照存储用户资金信息 UserMoney userMoney = userMoneyService.selectUserId(orderTotal.getUserId()); if(userMoney==null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找用户资金信息,订单用户标识:{}"+orderTotal.getUserId()); } //原定义的操作人门店(处方开单获取门店价格) String opShopId = shopId; //执行开单方法 Map map = orderServiceV2.orderCreate(orderTotal, orderItem, type, orderDeveloperList , operator, shop,opShopId,userMoney,user,platformApplication, orderRiseList,dto, commonService); //返回phis订单号、phis订单id return PlatformResult.success(map); } /** * 结账 */ @RequestMapping(value = "/payMoney",method = RequestMethod.POST) public PlatformResult orderPayMoney(HttpServletRequest request,@RequestBody PayDto payDto) { //校验签名 ThirtApplication thirtApplication= (ThirtApplication) request.getSession().getAttribute(LoginConstant.LOGIN_APPLY); if(thirtApplication==null){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"签名失败,请检查签名!"); } //打印请求参数 logger.info("前打印新结账订单请求所有参数:{}",JSONObject.toJSONString(payDto)); if (payDto == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "结账失败,结账参数无效!"); } //优惠券id集合 List userCouponIds = new ArrayList<>(); //兼容旧版的单个优惠券 if(StringUtils.noNull(payDto.getUserCouponId())){ userCouponIds.add(payDto.getUserCouponId()); } if(payDto.getUserCouponIds()!=null && payDto.getUserCouponIds().size()>0){ userCouponIds.addAll(payDto.getUserCouponIds()); } if (StringUtils.isEmpty(payDto.getOrderId())){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"结账失败,请选择要结账的订单!"); } // 查询需求要的信息,并且判空(例如查询门店、订单信息、一级子订单、用户资金等信息) OrdersTotal ordersTotal = commonService.selectOneByKeyBlob(OrdersTotalMapper.class, payDto.getOrderId()); if (ordersTotal == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "结账失败,订单信息查询失败!"); } // 判断艾芯荟的订单 if (ordersTotal.getAppId().equals(platformConfig.getCrmAppId())) { if (!thirtApplication.getAppId().equals(platformConfig.getCrmAppId())) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "结账失败,小程序订单请到小程序进行结账!"); } } User user = userService.selectOneByKey(ordersTotal.getUserId()); UserMoney userMoney=userMoneyService.selectUserId(ordersTotal.getUserId()); Shop shop = shopService.selectOneByKey(ordersTotal.getDeveloperShopId()); //判断订单状态是否正确 if(OrderTotalConstants.STATUS_WAIT_PAY!=ordersTotal.getStatus()){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"订单总状态不正确,只有待支付才能进行结账!"); } SqlSentence sqlSentence = new SqlSentence(); Map objectMap=new HashMap<>(); sqlSentence.setM(objectMap); objectMap.put("id",payDto.getOrderId()); //获取订单其他信息(orderInfo) sqlSentence.setSqlSentence("SELECT * FROM orders_info where orderId=#{m.id}"); OrderInfo info = commonService.selectOne(OrderInfoMapper.class,sqlSentence); //获取一级子订单信息,注意:充值和转增充值订单没有一级子订单集合 sqlSentence.setSqlSentence("select * from order_item where isDel=0 and orderId=#{m.id}"); List orderItemList=commonService.selectList(OrderItemMapper.class,sqlSentence); //判断优惠券叠加使用,项目券或者现金券+生日券 if(userCouponIds.size()>0){ //旧版本校验优惠券的多张券使用 if (payDto.getCouponCheckVersion() == null || payDto.getCouponCheckVersion() == 0){ checkCoupon(userCouponIds,commonService); } } //判断是否非空,订单、用户、用户资金、门店、订单其他信息(orderInfo)、订单标识、应付总金额、用户支付金额、操作人标识信息是否为空 checkIsNull(ordersTotal, user, userMoney, shop,info,payDto.getOperatorId(),payDto); //获取操作人信息map Map operator = ApiOrderUtil.getOperator(commonService, payDto.getOperatorId()); //存放一下操作人角色,以便后面使用 operator.put("opRoleId", payDto.getOpRoleId()); // 结账报错图片识别参数 if (info != null){ info.setOtherOrderNo(payDto.getOtherOrderNo()); info.setRedemptionCode(payDto.getRedemptionCode()); info.setOrderOCRImageUrl(payDto.getOrderOCRImageUrl()); ordersTotal.setConversionCode(payDto.getRedemptionCode()); } ordersTotal.setOrderInfo(info); //收银员id String cashier = payDto.getCashier(); if(PlatformConstants.TYPE_PLATFORM_CRM.equals(ordersTotal.getAppIdCode())){ cashier=ordersTotal.getUserId(); } if(StringUtils.noNull(cashier)){ Employee employee=commonService.selectOneByKeyBlob(EmployeeMapper.class,cashier); if(employee!=null){ ordersTotal.setCashierId(employee.getId()); ordersTotal.setCashierName(StringUtils.isEmpty(employee.getCnName())?"":employee.getCnName()); }else{ User cashierUser=commonService.selectOneByKeyBlob(UserMapper.class,cashier); if(cashierUser!=null){ ordersTotal.setCashierId(cashierUser.getId()); ordersTotal.setCashierName(StringUtils.isEmpty(cashierUser.getName())?"":cashierUser.getName()); } } } //收银员门店 String cashierShopId = payDto.getCashierShopId(); if(PlatformConstants.TYPE_PLATFORM_CRM.equals(ordersTotal.getAppIdCode())){ //CRM平台,结账,那么就使用用户的所属门店 if(StringUtils.noNull(user.getShopId())){ cashierShopId = user.getShopId(); }else{ cashierShopId=ordersTotal.getDeveloperShopId(); } } if(StringUtils.noNull(cashierShopId)){ Shop cashierShop=commonService.selectOneByKeyBlob(ShopMapper.class,cashierShopId); if(cashierShop!=null){ ordersTotal.setCashierShopId(cashierShop.getId()); ordersTotal.setCashierShopName(StringUtils.isEmpty(cashierShop.getName())?"":cashierShop.getName()); } } User payUser = null; //支付用户 if(StringUtils.noNull(payDto.getPayUserId())){ payUser = userService.selectOneByKey(payDto.getPayUserId()); if(payUser == null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"支付人标识错误!"); } } if(payUser == null){ payUser = user; } //执行结账方法,结账成功要注意运行重新算订单部分金额信息方法 Map map = orderServiceV2.orderPayMoney(payDto.getCouponCheckVersion(), ordersTotal,user,payUser,shop,info,orderItemList,operator,userMoney,userCouponIds,payDto,thirtApplication); if(map!=null && map.containsKey("orderId")){ OrdersTotal sucOrdersTotal=commonService.selectOneByKey(OrdersTotalMapper.class,map.get("orderId")); if(OrderTotalConstants.PAY_STATUS_SUC==sucOrdersTotal.getPayStatus()){ //处理再生俱乐部会员 threadPool.getThreadPool().execute(() -> userCluebMemberServiceTool.orderChekMember(ordersTotal.getId(),null,null,MarketSystem.TYPE_REGENERATION)); //赠送增值金 if(payDto.getGiveIncrease() != null && payDto.getGiveIncrease().compareTo(BigDecimal.ZERO) > 0){ threadPool.getThreadPool().execute(() -> orderGeneralServiceTool.giveIncreaseByActivity(payDto,ordersTotal)); } //处理老带新 JSONObject commissionObject = handOrderOldNew(ordersTotal, user); //更新用户最后下单时间 updateUserLastTime(ordersTotal, user); //需求: 1.HIS助手结账成功:要通知客户所属顾问,发送企业微信通知 ,如果没有所属顾问发送给门店运营客服(三少说目前不处理crm已处理) -异步 try { orderServiceV2.sendUserConsultant(ordersTotal.getUserId(),ordersTotal.getOrderNo(),ordersTotal.getId(),commissionObject,commonService); }catch (TipsException|PlatTipsException e){ logger.info("要通知客户所属顾问,发送企业微信通知异常 -异步:{}",e.getMessage()); }catch (Exception e){ logger.info("要通知客户所属顾问,发送企业微信通知异常 -异步:{}",e.getMessage(),e); } //记录收入确认表 try{ orderServiceV2.statementPerformanceInfo((String) map.get("orderId")); }catch (Exception e) { logger.info("记录收入确认表,异常:{}", e.getMessage(), e); // 添加错误日志 PerformanceInfoTool.addErrorLog(commonService, map.get("orderId").toString(), PerformanceInfo.ASSOCIATION_TYPE_GOODS_ORDER, e.getMessage()); } //咨询师现金业绩报表 try{ orderServiceV2.statementConsultantCash((String) map.get("orderId")); }catch (Exception e){ logger.info("咨询师现金业绩报表,异常:{}",e.getMessage(),e); } } // 结账成功发送公众号通知给用户 -异步 try { orderServiceV2.sendPublicNoV2(ordersTotal, commonService); } catch (Exception e){ logger.info("结账成功发送公众号通知给用户异常 -异步:{}", e.getMessage(),e); } } // //结账成功发送公众号通知给用户 // threadPool.execute(() -> orderServiceV2.sendPublicNo(ordersTotal.getId(),commonService)); // //需求: 1.HIS助手结账成功:要通知客户所属顾问,发送企业微信通知 // threadPool.execute(() -> orderService.sendUserConsultant(ordersTotal.getUserId(),ordersTotal.getOrderNo(),ordersTotal.getId(),commonService)); threadPool.getThreadPool().execute(()->{ try { //系统消费赠送积分 TimerHandleItemTool.addTimer(TimerHandleItem.CONSUME_GIVE_INTEGRAL,ordersTotal.getId(),commonService); //系统消费赠送积分-老带新 TimerHandleItemTool.addTimer(TimerHandleItem.CONSUME_OLD_GIVE_INTEGRAL,ordersTotal.getId(),commonService); }catch (Exception e){ logger.info("处理消费送积分出错:{}",e.getMessage(),e); } }); /*threadPool.getThreadPool().execute(()->{ //返回phis订单号、phis订单id、领建订单号、领建订单id //新客后续每次新产生的现金消费(任意金额),老客按照新客现金消费的10%积累积分(仅计算1年内新客的消费) try { OldBrinNewDto oldBrinNewDto = new OldBrinNewDto(); oldBrinNewDto.setOrderId(ordersTotal.getId()); oldBrinNewDto.setUserId(ordersTotal.getUserId()); //查询现金支付金额 SqlSentence sqlSentence1 = new SqlSentence(); Map objectMap1 = new HashMap<>(); objectMap1.put("orderId",ordersTotal.getId()); sqlSentence1.sqlSentence("SELECT * FROM orders_info WHERE orderId = #{m.orderId} AND isDel = 0 ORDER BY createTime DESC LIMIT 1",objectMap1); OrderInfo orderInfo = commonService.selectOne(OrderInfoMapper.class,sqlSentence1); if (null != orderInfo){ oldBrinNewDto.setPayTotal(orderInfo.getSnapPayTotal()); fOldBrinNewService.giveIntegral(oldBrinNewDto); } }catch (Exception e){ logger.info("处理新客后续每次新产生的现金消费老客按照新客现金消费的10%积累积分出错:{}",e.getMessage(),e); } });*/ return PlatformResult.success(map); } /** * 初始化订单的金额 * 根据支付记录去重新算各种金额 */ @RequestMapping(value = "/init/order-money",method = RequestMethod.POST) public PlatformResult initOrderMoney(HttpServletRequest request,@RequestBody OrderInitVo orderInitVo) { ThirtApplication thirtApplication= (ThirtApplication) request.getSession().getAttribute(LoginConstant.LOGIN_APPLY); if(StringUtils.isEmpty(orderInitVo.getOrderId())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"订单标识错误!"); } orderInitService.initOrder(new ArrayList<>(),orderInitVo.getOrderId(),thirtApplication.getAppId(),true,false); return PlatformResult.success(); } /** * 结账判断是否为空 * @param ordersTotal 总订单标识 * @param user 用户信息 * @param userMoney 用户资金 * @param shop 门店信息 * @param info 订单其他信息(orderInfo) * @param operatorId 操作人标识 */ private void checkIsNull(OrdersTotal ordersTotal, User user, UserMoney userMoney, Shop shop, OrderInfo info , String operatorId,PayDto payDto) { if(StringUtils.isEmpty(payDto.getTotal())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"请传应付的总金额"); } if(payDto.getAmount() ==null){ payDto.setAmount(new ArrayList<>()); } for(PayAmountDto payAmountDto:payDto.getAmount()){ if(StringUtils.isEmpty(payAmountDto.getMethod())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"支付方式为空!"); } if(payAmountDto.getAmount() == null || payAmountDto.getAmount().compareTo(BigDecimal.ZERO) < 0){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"支付金额必填或者不能小于0!"); } } if(StringUtils.isEmpty(operatorId)){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"请传用户操作人标识"); } if(ordersTotal==null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"订单不存在"); } if(user==null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"结账:未找到该用户信息"); } if(userMoney ==null ){ //没有用户资金信息,抛错,资金全部交给用户资金全权处理 throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到用户资金信息!"); } if(shop==null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"结账时:订单门店不存在"); } if(info==null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"根据总订单未找到订单其他信息"); } //20240730 彭程需求:订单结账可支持其他文件上传 if(payDto.getOtherInfoFiles()!=null && payDto.getOtherInfoFiles().size()!=0){ for (OrderOtherFilesDto dto: payDto.getOtherInfoFiles()) { if(StringUtils.isEmpty(dto.getFileType())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"文件类型为空!"); } if(StringUtils.isEmpty(dto.getFileUrl())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"文件为空!"); } } } } /** * 检查优惠券是否符合一张项目券或者一张现金券+生日优惠券 * 判断思路说明: * 1、只要统计用户使用优惠券集合的项目券或者现金券的张数 * 2、如果项目或者现金券大于1张肯定是不给使用的 * 3、如果都没有项目券或者现金券,代表专门使用生日优惠券,生日优惠券不进行判断限制,无限使用 @param userCouponIds */ public static void checkCoupon(List userCouponIds, CommonService commonService) { CouponNumber couponNumber=null; Coupon coupon=null; //统计项目券张数 Integer projectCoupon=0; //统计现金券张数 Integer cashCoupon=0; for(String couponId:userCouponIds){ //查看用户是否有优惠券 couponNumber = commonService.selectOneByKey(CouponNumberMapper.class, couponId); if(couponNumber==null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"优惠卷:该用户没有该优惠券"); } //查看用户是否有优惠券 coupon = commonService.selectOneByKey(CouponMapper.class, couponNumber.getCouponId()); if(coupon==null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"优惠卷:未找到优惠券信息"); } if(coupon.getIsBirthday().equals(BaseEntity.NO) && (coupon.getUseProjectType().equals(Coupon.USE_TYPE_PROJECT) || coupon.getUseProjectType()==Coupon.USE_TYPE_PROJECT_CLASSIFY)){ projectCoupon=projectCoupon+1; }else if(coupon.getIsBirthday().equals(BaseEntity.NO) &&(coupon.getUseGoodsType().equals(Coupon.USE_TYPE_GOODS) || coupon.getUseGoodsType()==Coupon.USE_TYPE_GOODS_CLASSIFY)){ projectCoupon=projectCoupon+1; }else if(coupon.getIsBirthday().equals(BaseEntity.NO) &&(coupon.getUsePromotionType().equals(Coupon.USE_TYPE_PROMOTION) || coupon.getUsePromotionType()==Coupon.USE_TYPE_PROMOTION_CLASSIFY)){ projectCoupon=projectCoupon+1; }else if(coupon.getIsBirthday().equals(BaseEntity.NO) &&(coupon.getUseCardType().equals(Coupon.USE_TYPE_CARD) || coupon.getUseCardType()==Coupon.USE_TYPE_CARD_CLASSIFY)){ projectCoupon=projectCoupon+1; }else if(coupon.getIsBirthday().equals(BaseEntity.NO) && coupon.getCommodityType().equals(Coupon.USE_TYPE_TYPE_COMMODITY)){ }else if(coupon.getIsBirthday().equals(BaseEntity.NO) && coupon.getIntegralType().equals(Coupon.USE_TYPE_CRM_GOODS)){ }else if(coupon.getIsBirthday().equals(BaseEntity.NO) &&(coupon.getUseProjectType().equals(Coupon.USE_TYPE_PROJECT_ALL) || coupon.getUseGoodsType()==Coupon.USE_TYPE_GOODS_ALL|| coupon.getUsePromotionType().equals(Coupon.USE_TYPE_PROMOTION_ALL) || coupon.getUseCardType().equals(Coupon.USE_TYPE_CARD_ALL) || coupon.getCommodityType()==Coupon.USE_TYPE_COMMODITY_ALL || coupon.getIntegralType().equals(Coupon.USE_TYPE_CRM_GOODS_ALL))){ cashCoupon=cashCoupon+1; } } if(cashCoupon>1){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"叠加优惠卷提示:一张订单只能使用一张现金券"); } if(projectCoupon>1){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"叠加优惠卷提示:一张订单只能使用一张项目券"); } } /** * 更新用户最后一次下单时间 * @param ordersTotal * @param user */ public void updateUserLastTime(OrdersTotal ordersTotal, User user) { try { SqlSentence sqlSentence = new SqlSentence(); Map sqlValues = new HashMap<>(); sqlValues.put("lastPayOrderTime", new Date()); sqlValues.put("editTime", new Date()); sqlValues.put("isLoss", BaseEntity.NO); sqlValues.put("isDel", BaseEntity.NO); sqlValues.put("id", user.getId()); StringBuilder sql = new StringBuilder(); sql.append(" lastPayOrderTime=#{m.lastPayOrderTime},editTime=#{m.editTime},isLoss=#{m.isLoss}"); // 会员有消费和执行就是活跃会员同时也是非流失会员 String status = null; if (!UserStatusConstants.USER_STATUS_NON_MEMBER.equals(user.getUserStatus())) { status = UserStatusConstants.USER_STATUS_ACTIVE_MEMBER; sqlValues.put("isLoss", BaseEntity.NO); sqlValues.put("userStatus", status); sql.append(",isLoss=#{m.isLoss},userStatus=#{m.userStatus}"); } sql.append(" WHERE id=#{m.id} AND isDel=#{m.isDel}"); sqlSentence.sqlSentence(sql.toString(), sqlValues); commonService.updateWhere(UserMapper.class, sqlSentence); // 添加调整用户状态日志 调整了用户等级在写入日志 if (!StringUtils.isEmpty(status)) { // 记录编号 String recordNo = systemParameterService.createUSLGNo(user.getId(), user.getCIQ()); // 添加用户日志 UserStatusTool.addUserStatusLog(commonService, ordersTotal.getAppIdCode(), user, UserStatusLog.CHANGE_STATUS_TYPE_ORDER, ordersTotal.getId(), UserStatusConstants.USER_STATUS_ACTIVE_MEMBER, recordNo); } } catch (Exception e) { logger.info("更新用户最后下单时间,异常:{}", e.getMessage(), e); } } /** * 处理老带新 * @param ordersTotal * @param user * @return */ private JSONObject handOrderOldNew(OrdersTotal ordersTotal, User user) { JSONObject commissionObject = null; StringBuilder orderNodeBuilder = new StringBuilder(); try { commissionObject = OrderPayMoneyUtil.handPayOldNew(orderNodeBuilder,ordersTotal,user,commonService); if(commissionObject == null){ orderNodeBuilder.reverse(); } }catch (Exception e){ String snapshot="处理老带新失败"; orderNodeBuilder.append("-处理老带新失败,异常原因:"+e.getMessage()); logger.error("处理老带新失败:" + e.getMessage(),e); //发送企业微信通知给工作人员 SendNoticeUtil.failOrderSendNotice(ordersTotal,e.getMessage(),snapshot,commonService,customParameter); } //有需要保存的日志再去处理 if(orderNodeBuilder.length()>0){ SqlSentence sql = new SqlSentence(); Map paramMap=new HashMap<>(); sql.setM(paramMap); paramMap.put("orderId",ordersTotal.getId()); sql.setSqlSentence("select * from orders_node_log where orderId=#{m.orderId} and isDel=0 order by createTime desc LIMIT 1"); OrdersNodeLog ordersNodeLog=commonService.selectOne(OrdersNodeLogMapper.class,sql); if(ordersNodeLog!=null ){ String concat = ordersNodeLog.getContent().concat(orderNodeBuilder.toString()); paramMap.put("concat",concat); paramMap.put("id",ordersNodeLog.getId()); sql.setSqlSentence(" content=#{m.concat} where id=#{m.id} "); commonService.updateWhere(OrdersNodeLogMapper.class,sql); } } return commissionObject; } }