| | |
| | | package com.ruoyi.order.service.impl.order; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | import com.github.binarywang.wxpay.service.WxPayService; |
| | | import com.google.common.collect.Lists; |
| | | import com.google.gson.Gson; |
| | | import com.ruoyi.common.core.constant.CacheConstants; |
| | | import com.ruoyi.common.core.constant.Constants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.enums.UserStatus; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.core.text.Convert; |
| | | import com.ruoyi.common.core.utils.DateUtils; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.core.utils.ip.IpUtils; |
| | | import com.ruoyi.common.core.utils.uuid.IdUtils; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.common.security.utils.CodeFactoryUtil; |
| | |
| | | import com.ruoyi.order.service.account.PaymentMessageService; |
| | | import com.ruoyi.order.service.account.ProfitSharingService; |
| | | import com.ruoyi.order.service.order.*; |
| | | import com.ruoyi.order.util.HuiFuTianXiaUtil; |
| | | import com.ruoyi.system.api.constant.AppErrorConstant; |
| | | import com.ruoyi.system.api.constant.DelayTaskEnum; |
| | | import com.ruoyi.system.api.constant.SecurityConstant; |
| | | import com.ruoyi.system.api.domain.dto.*; |
| | | import com.ruoyi.system.api.domain.poji.activity.Activity; |
| | | import com.ruoyi.system.api.domain.poji.activity.ActivityRecord; |
| | | import com.ruoyi.system.api.domain.poji.config.DelayTask; |
| | | import com.ruoyi.system.api.domain.poji.goods.Goods; |
| | |
| | | import com.ruoyi.system.api.domain.poji.shop.Shop; |
| | | import com.ruoyi.system.api.domain.poji.sys.SysUser; |
| | | import com.ruoyi.system.api.domain.vo.*; |
| | | import com.ruoyi.system.api.model.QwH5LoginVo; |
| | | import com.ruoyi.system.api.model.QwUserDetailDto; |
| | | import com.ruoyi.system.api.service.*; |
| | | import io.seata.spring.annotation.GlobalTransactional; |
| | | import lombok.extern.log4j.Log4j2; |
| | | import org.redisson.api.RLock; |
| | | import org.redisson.api.RedissonClient; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.NumberFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | |
| | | @Resource |
| | | private OrderRefundService orderRefundService; |
| | | |
| | | @Value("${wx.pay.callbackPath}") |
| | | private String callbackPath; |
| | | |
| | | |
| | | |
| | | /** |
| | | * @description: buyGoods |
| | |
| | | String goodsId; |
| | | Integer buyNum; |
| | | BigDecimal buyNumBig; |
| | | String memberCouponId; |
| | | Long memberCouponId; |
| | | Goods goods; |
| | | BigDecimal goodsPrice; |
| | | BigDecimal goodsTotalPrice; |
| | |
| | | BigDecimal orderPayDeposit = new BigDecimal("0.00"); |
| | | BigDecimal orderPayMoney = new BigDecimal("0.00"); |
| | | // 遍历购买商品列表 |
| | | HashSet<String> userCouponIdSet = new HashSet<>(); |
| | | HashSet<Long> userCouponIdSet = new HashSet<>(); |
| | | for (AppBuyGoodsDto appBuyGoodsDto : appBuyGoodsDtoList) { |
| | | appSureOrderGoodsVo = new AppSureOrderGoodsVo(); |
| | | discountMoney = BigDecimal.ZERO; |
| | |
| | | goodsTotalPrice = goodsPrice.multiply(buyNumBig); |
| | | goodsRealPrice = goodsTotalPrice; |
| | | // 处理优惠券 |
| | | if (StringUtils.isNotBlank(memberCouponId)) { |
| | | appMemberCouponVo = appMemberCouponVoMap.get(memberCouponId); |
| | | if (null != memberCouponId) { |
| | | appMemberCouponVo = appMemberCouponVoMap.get(memberCouponId.toString()); |
| | | System.err.println(JSON.toJSONString(appMemberCouponVoMap)); |
| | | System.err.println(memberCouponId); |
| | | System.err.println(JSON.toJSONString(appMemberCouponVo)); |
| | | if (StringUtils.isBlank(appMemberCouponVo.getRelGoodsIds()) || appMemberCouponVo.getRelGoodsIds().contains(goodsId)) { |
| | | couponType = appMemberCouponVo.getCouponType(); |
| | | if (couponType == 1 && appMemberCouponVo.getMoneyThreshold() != null && appMemberCouponVo.getDiscountMoney() != null) { |
| | |
| | | goodsRealPrice = goodsTotalPrice.subtract(discountMoney); |
| | | useCoupon = 1; |
| | | userCouponIdSet.add(memberCouponId); |
| | | appSureOrderGoodsVo.setMemberCouponId(memberCouponId); |
| | | appSureOrderGoodsVo.setMemberCouponId(memberCouponId.toString()); |
| | | } |
| | | } else if (couponType == 2 && appMemberCouponVo.getDiscountPercent() != null) { |
| | | discountPercent = appMemberCouponVo.getDiscountPercent(); |
| | |
| | | discountMoney = goodsTotalPrice.subtract(goodsRealPrice); |
| | | useCoupon = 1; |
| | | userCouponIdSet.add(memberCouponId); |
| | | appSureOrderGoodsVo.setMemberCouponId(memberCouponId); |
| | | appSureOrderGoodsVo.setMemberCouponId(memberCouponId.toString()); |
| | | } else if (couponType == 3 && appMemberCouponVo.getDiscountMoney() != null) { |
| | | discountMoney = appMemberCouponVo.getDiscountMoney(); |
| | | if (goodsTotalPrice.compareTo(discountMoney) > 0) { |
| | |
| | | } |
| | | useCoupon = 1; |
| | | userCouponIdSet.add(memberCouponId); |
| | | appSureOrderGoodsVo.setMemberCouponId(memberCouponId); |
| | | appSureOrderGoodsVo.setMemberCouponId(memberCouponId.toString()); |
| | | } |
| | | } |
| | | } |
| | |
| | | sureOrderGoodsVo.setAppMemberCouponVoList(appGoodsMemberCouponVoList); |
| | | } |
| | | } |
| | | /*if (appMemberCouponVoList != null && !appMemberCouponVoList.isEmpty()) { |
| | | // 获取商品关联优惠券 |
| | | appGoodsMemberCouponVoList = new ArrayList<>(); |
| | | for(AppSureOrderGoodsVo sureOrderGoodsVo : appSureOrderGoodsVoList){ |
| | | for (AppMemberCouponVo entity : appMemberCouponVoList) { |
| | | if (StringUtils.isBlank(entity.getRelGoodsIds())) { |
| | | if (entity.getCouponType() == 1 && entity.getMoneyThreshold() != null && entity.getDiscountMoney() != null) { |
| | | moneyThreshold = entity.getMoneyThreshold(); |
| | | if (sureOrderGoodsVo.getGoodsTotalPrice().compareTo(moneyThreshold) >= 0) { |
| | | if(userCouponIdSet==null||!userCouponIdSet.contains(entity.getMemberCouponId())){ |
| | | appGoodsMemberCouponVoList.add(entity); |
| | | }else{ |
| | | if(sureOrderGoodsVo.getMemberCouponId()!=null&&sureOrderGoodsVo.getMemberCouponId().equals(entity.getMemberCouponId())){ |
| | | appGoodsMemberCouponVoList.add(entity); |
| | | } |
| | | } |
| | | } |
| | | }else{ |
| | | if(userCouponIdSet==null||!userCouponIdSet.contains(entity.getMemberCouponId())){ |
| | | appGoodsMemberCouponVoList.add(entity); |
| | | }else{ |
| | | if(sureOrderGoodsVo.getMemberCouponId()!=null&&sureOrderGoodsVo.getMemberCouponId().equals(entity.getMemberCouponId())){ |
| | | appGoodsMemberCouponVoList.add(entity); |
| | | } |
| | | } |
| | | } |
| | | } else if (entity.getRelGoodsIds().contains(sureOrderGoodsVo.getGoodsId())) { |
| | | if (entity.getCouponType() == 1 && entity.getMoneyThreshold() != null && entity.getDiscountMoney() != null) { |
| | | moneyThreshold = entity.getMoneyThreshold(); |
| | | if (sureOrderGoodsVo.getGoodsTotalPrice().compareTo(moneyThreshold) >= 0) { |
| | | if(userCouponIdSet==null||!userCouponIdSet.contains(entity.getMemberCouponId())){ |
| | | appGoodsMemberCouponVoList.add(entity); |
| | | }else{ |
| | | if(sureOrderGoodsVo.getMemberCouponId()!=null&&sureOrderGoodsVo.getMemberCouponId().equals(entity.getMemberCouponId())){ |
| | | appGoodsMemberCouponVoList.add(entity); |
| | | } |
| | | } |
| | | } |
| | | }else{ |
| | | if(userCouponIdSet==null||!userCouponIdSet.contains(entity.getMemberCouponId())){ |
| | | appGoodsMemberCouponVoList.add(entity); |
| | | }else{ |
| | | if(sureOrderGoodsVo.getMemberCouponId()!=null&&sureOrderGoodsVo.getMemberCouponId().equals(entity.getMemberCouponId())){ |
| | | appGoodsMemberCouponVoList.add(entity); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | sureOrderGoodsVo.setAppMemberCouponVoList(appGoodsMemberCouponVoList); |
| | | } |
| | | }*/ |
| | | // 设置订单相关金额 |
| | | appSureOrderVo.setOrderGoodsMoney(orderGoodsMoney); |
| | | appSureOrderVo.setCouponDiscount(couponDiscount); |
| | |
| | | BigDecimal buyNumBig; |
| | | Integer serviceNum; |
| | | Integer goodsNum = 0; |
| | | String memberCouponId; |
| | | Long memberCouponId; |
| | | Goods goods = null; |
| | | GoodsFile goodsFile; |
| | | BigDecimal goodsPrice; |
| | |
| | | goodsRealPrice = goodsTotalPrice; |
| | | // 如果使用了优惠券,计算优惠后的价格 |
| | | if (memberCouponId != null) { |
| | | appMemberCouponVo = appMemberCouponVoMap.get(memberCouponId); |
| | | appMemberCouponVo = appMemberCouponVoMap.get(memberCouponId.toString()); |
| | | if(null == appMemberCouponVo){ |
| | | throw new ServiceException("优惠券已使用"); |
| | | } |
| | | // 如果优惠券适用于该商品 |
| | | if (StringUtils.isBlank(appMemberCouponVo.getRelGoodsIds()) || appMemberCouponVo.getRelGoodsIds().contains(goodsId)) { |
| | | couponType = appMemberCouponVo.getCouponType(); |
| | |
| | | discountMoney = goodsTotalPrice; |
| | | } |
| | | } |
| | | memberCouponSJ.add(memberCouponId); |
| | | memberCouponSJ.add(memberCouponId + ""); |
| | | } |
| | | appSureOrderGoodsVo.setUseCoupon(useCoupon); |
| | | appSureOrderGoodsVo.setGoodsTotalPrice(goodsTotalPrice); |
| | |
| | | if (null != goodsNameList) { |
| | | goodsName = String.join(",", goodsNameList); |
| | | } |
| | | // 小程序微信下单支付 |
| | | createWxPayInfo(appPlaceOrderVo, userId, order.getShopId(), goodsName, outTradeNo, |
| | | // // 小程序微信下单支付 |
| | | // createWxPayInfo(appPlaceOrderVo, userId, order.getShopId(), goodsName, outTradeNo, |
| | | // orderId, order.getPayMoney(), appPlaceOrderDto.getOpenid(), |
| | | // appPlaceOrderDto.getSpbillCreateIp()); |
| | | |
| | | // 小程序微信下单支付 TODO 更换支付渠道(汇付天下) |
| | | createWxPayInfo1(appPlaceOrderVo, userId, order.getShopId(), goodsName, outTradeNo, |
| | | orderId, order.getPayMoney(), appPlaceOrderDto.getOpenid(), |
| | | appPlaceOrderDto.getSpbillCreateIp()); |
| | | //生成自动取消订单延时任务 |
| | |
| | | throw new ServiceException(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 小程序支付下单API |
| | | * @param appPlaceOrderVo |
| | | * @param userId |
| | | * @param shopId |
| | | * @param goodsName |
| | | * @param outTradeNo |
| | | * @param orderId |
| | | * @param payMoney |
| | | * @param openid |
| | | * @param payerClientIp |
| | | */ |
| | | |
| | | private void createWxPayInfo1(AppPlaceOrderVo appPlaceOrderVo, Long userId, Long shopId, |
| | | String goodsName, String outTradeNo, |
| | | String orderId, BigDecimal payMoney, |
| | | String openid, String payerClientIp){ |
| | | try { |
| | | WxPayConfig config = wxService.getConfig(); |
| | | PartnerTransactionsRequest request = new PartnerTransactionsRequest(); |
| | | request.setSpAppid(config.getAppId()); |
| | | request.setSpMchid(config.getMchId()); |
| | | request.setSubMchid(config.getSubMchId()); |
| | | // 商品描述 body |
| | | String description = goodsName + "-商品购买"; |
| | | |
| | | request.setDescription(description); |
| | | request.setOutTradeNo(outTradeNo); |
| | | request.setNotifyUrl(callbackPath + "/order/app/notify/wechatPaymentCallback"); |
| | | |
| | | R<com.alibaba.fastjson.JSONObject> r = HuiFuTianXiaUtil.weixinPayment(outTradeNo, description, payMoney.doubleValue(), openid, request.getNotifyUrl()); |
| | | if(r.getCode() != 200){ |
| | | throw new ServiceException(r.getMsg()); |
| | | }else{ |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); |
| | | int time = 0; |
| | | for (int i = 0; i < 13; i++) { |
| | | try { |
| | | time += (5000 * i); |
| | | Thread.sleep(time); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | R<WeixinPaymentNotifyVo> voR = HuiFuTianXiaUtil.queryPayment(outTradeNo, sdf.format(new Date())); |
| | | if(voR.getCode() == 200){ |
| | | WeixinPaymentNotifyVo data = voR.getData(); |
| | | //P:处理中;S:成功;F:失败;I: 初始(初始状态很罕见,请联系汇付技术人员处理); |
| | | String transStat = data.getTransStat(); |
| | | if("S".equals(transStat)){ |
| | | PartnerTransactionsResult transaction = new PartnerTransactionsResult(); |
| | | transaction.setOutTradeNo(data.getReqSeqId()); |
| | | payBack(transaction, data.getFeeFlag() == 1 ? BigDecimal.ZERO : new BigDecimal(data.getFeeAmount())); |
| | | return; |
| | | } |
| | | if("P".equals(transStat) || "F".equals(transStat)){ |
| | | continue; |
| | | } |
| | | log.error("支付失败,流水号:{}, 状态码:{}", outTradeNo, transStat); |
| | | return; |
| | | }else{ |
| | | log.error("支付查询失败!流水号:{},结果:{}", outTradeNo, voR.getMsg()); |
| | | } |
| | | } |
| | | } |
| | | }).start(); |
| | | } |
| | | com.alibaba.fastjson.JSONObject data = r.getData(); |
| | | String mainMchId = WxPayConfiguration.getPlatformTyMacId(); |
| | | // 支付相关信息返回 |
| | | appPlaceOrderVo.setAppId(data.getString("appId")); |
| | | appPlaceOrderVo.setMchId(config.getMchId()); |
| | | appPlaceOrderVo.setTimeStamp(data.getString("timeStamp")); |
| | | appPlaceOrderVo.setNonceStr(data.getString("nonceStr")); |
| | | appPlaceOrderVo.setPackageStr(data.getString("package")); |
| | | appPlaceOrderVo.setSignType(data.getString("signType")); |
| | | appPlaceOrderVo.setPaySign(data.getString("paySign")); |
| | | |
| | | // 保存支付订单统一下单日志 |
| | | paymentMessageService.savePaymentMessage("1", orderId, JSON.toJSONString(request), data.toJSONString()); |
| | | |
| | | // 保存支付订单统一下单支付记录 |
| | | orderPaymentService.saveOrderPayment(userId, shopId, mainMchId, orderId, outTradeNo, payMoney, |
| | | appPlaceOrderVo.getEndTime(), "Y", openid, |
| | | goodsName, appPlaceOrderVo.getPackageStr()); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | } |
| | | appPlaceOrderVo.setEndTime(DateUtils.addMinutes(order.getCreateTime(), delayTime)); |
| | | // 小程序微信下单支付 |
| | | createWxPayInfo(appPlaceOrderVo, userId, order.getShopId(), orderGoods.getGoodsName(), outTradeNo, |
| | | // createWxPayInfo(appPlaceOrderVo, userId, order.getShopId(), orderGoods.getGoodsName(), outTradeNo, |
| | | // orderId, order.getPayMoney(), appPlaceActivityDto.getOpenid(), |
| | | // appPlaceActivityDto.getSpbillCreateIp()); |
| | | |
| | | // 小程序微信下单支付 TODO 更换支付渠道(汇付天下) |
| | | createWxPayInfo1(appPlaceOrderVo, userId, order.getShopId(), orderGoods.getGoodsName(), outTradeNo, |
| | | orderId, order.getPayMoney(), appPlaceActivityDto.getOpenid(), |
| | | appPlaceActivityDto.getSpbillCreateIp()); |
| | | //生成自动取消订单延时任务 |
| | |
| | | if (appUserOrderPageVoList != null && !appUserOrderPageVoList.isEmpty()) { |
| | | Long shopId; |
| | | String activityId; |
| | | Shop shop; |
| | | HashSet<Long> shopSet = new HashSet<Long>(); |
| | | HashSet<String> activitySet = new HashSet<String>(); |
| | | // 遍历订单列表,获取店铺ID和活动ID |
| | | for (AppUserOrderPageVo appUserOrderPageVo : appUserOrderPageVoList) { |
| | | shopId = appUserOrderPageVo.getShopId(); |
| | | shopSet.add(shopId); |
| | |
| | | activitySet.add(activityId); |
| | | } |
| | | } |
| | | Map<Long, Shop> shopMap = new HashMap<>(); |
| | | shopSet.forEach(shopIdLong -> { |
| | | Shop shopTemp = remoteShopService.getShop(shopIdLong).getData(); |
| | | shopMap.put(shopIdLong, shopTemp); |
| | | }); |
| | | String shopJoinedString = String.join(",", shopSet.stream().map(Object::toString).collect(Collectors.toList())); |
| | | MgtBaseBathDto mgtBaseBathDto = new MgtBaseBathDto(); |
| | | mgtBaseBathDto.setIds(shopJoinedString); |
| | | List<MgtSimpleShopVo> simpleShopVoList = remoteShopService.listShopSimpleVoByIds(mgtBaseBathDto).getData(); |
| | | Map<Long, MgtSimpleShopVo> shopMap = simpleShopVoList.stream() |
| | | .collect(Collectors.toMap(MgtSimpleShopVo::getShopId, Function.identity())); |
| | | MgtSimpleShopVo simpleShopVo; |
| | | Integer delayTime = 30; |
| | | if (redisService.hasKey(SecurityConstant.AUTO_CANCEL_ORDER_TIME)) { |
| | | delayTime = redisService.getCacheObject(SecurityConstant.AUTO_CANCEL_ORDER_TIME); |
| | | } |
| | | //处理订单回显 |
| | | for (AppUserOrderPageVo appUserOrderPageVo : appUserOrderPageVoList) { |
| | | if(member.getBindingFlag()==0&&appUserOrderPageVo.getOrderFrom()==2){ |
| | | appUserOrderPageVo.setShopName("全部店铺"); |
| | | //查询秒杀活动的参与店铺 |
| | | R<Activity> activity = remoteActivityService.getActivity(appUserOrderPageVo.getActivityId()); |
| | | if(activity.getCode() != 200){ |
| | | throw new RuntimeException(activity.getMsg()); |
| | | } |
| | | Activity data = activity.getData(); |
| | | if(data.getAreaFlag() == 1){ |
| | | appUserOrderPageVo.setShopNumber(0); |
| | | appUserOrderPageVo.setShopName("全部店铺"); |
| | | } |
| | | if(data.getAreaFlag() == 2 && data.getShopFlag() == 1){ |
| | | String designatedArea = data.getDesignatedArea(); |
| | | String[] split = designatedArea.split(","); |
| | | List<String> list = Arrays.asList(split); |
| | | R<List<Shop>> listR = remoteShopService.listShopByCityCode(list); |
| | | if(listR.getCode() != 200){ |
| | | throw new RuntimeException(listR.getMsg()); |
| | | } |
| | | List<Shop> data1 = listR.getData(); |
| | | appUserOrderPageVo.setShopNumber(1); |
| | | appUserOrderPageVo.setShopName(JSON.toJSONString(data1)); |
| | | } |
| | | if(data.getShopFlag() == 2){ |
| | | String applicableShop = data.getApplicableShop(); |
| | | String[] split = applicableShop.split(","); |
| | | List<String> list = Arrays.asList(split); |
| | | R<List<Shop>> listR = remoteShopService.listShopByIds(list); |
| | | if(listR.getCode() != 200){ |
| | | throw new RuntimeException(listR.getMsg()); |
| | | } |
| | | List<Shop> data1 = listR.getData(); |
| | | appUserOrderPageVo.setShopNumber(1); |
| | | appUserOrderPageVo.setShopName(JSON.toJSONString(data1)); |
| | | } |
| | | }else if(member.getBindingFlag()==1&&appUserOrderPageVo.getOrderFrom()==2){ |
| | | Long relationShopId = member.getRelationShopId(); |
| | | R<Shop> shop = remoteShopService.getShop(relationShopId); |
| | | if(shop.getCode() != 200){ |
| | | throw new RuntimeException(shop.getMsg()); |
| | | } |
| | | Shop data1 = shop.getData(); |
| | | //查询秒杀活动的参与店铺 |
| | | R<Activity> activity = remoteActivityService.getActivity(appUserOrderPageVo.getActivityId()); |
| | | if(activity.getCode() != 200){ |
| | | throw new RuntimeException(activity.getMsg()); |
| | | } |
| | | Activity data = activity.getData(); |
| | | if(data.getAreaFlag() == 1){ |
| | | appUserOrderPageVo.setShopNumber(2); |
| | | appUserOrderPageVo.setShopName(data1.getShopName()); |
| | | appUserOrderPageVo.setShopServicePhone(data1.getShopServicePhone()); |
| | | } |
| | | if(data.getAreaFlag() == 2 && data.getShopFlag() == 1){ |
| | | String designatedArea = data.getDesignatedArea(); |
| | | String[] split = designatedArea.split(","); |
| | | List<String> list = Arrays.asList(split); |
| | | R<List<Shop>> listR = remoteShopService.listShopByCityCode(list); |
| | | if(listR.getCode() != 200){ |
| | | throw new RuntimeException(listR.getMsg()); |
| | | } |
| | | List<Shop> data2 = listR.getData(); |
| | | List<Long> collect = data2.stream().map(Shop::getShopId).collect(Collectors.toList()); |
| | | if(collect.contains(relationShopId)){ |
| | | appUserOrderPageVo.setShopNumber(2); |
| | | appUserOrderPageVo.setShopName(data1.getShopName()); |
| | | appUserOrderPageVo.setShopServicePhone(data1.getShopServicePhone()); |
| | | }else{ |
| | | appUserOrderPageVo.setShopNumber(1); |
| | | appUserOrderPageVo.setShopName(JSON.toJSONString(data2)); |
| | | } |
| | | } |
| | | if(data.getShopFlag() == 2){ |
| | | String applicableShop = data.getApplicableShop(); |
| | | String[] split = applicableShop.split(","); |
| | | List<String> list = Arrays.asList(split); |
| | | R<List<Shop>> listR = remoteShopService.listShopByIds(list); |
| | | if(listR.getCode() != 200){ |
| | | throw new RuntimeException(listR.getMsg()); |
| | | } |
| | | List<Shop> data2 = listR.getData(); |
| | | List<Long> collect = data2.stream().map(Shop::getShopId).collect(Collectors.toList()); |
| | | if(collect.contains(relationShopId)){ |
| | | appUserOrderPageVo.setShopNumber(2); |
| | | appUserOrderPageVo.setShopName(data1.getShopName()); |
| | | appUserOrderPageVo.setShopServicePhone(data1.getShopServicePhone()); |
| | | }else{ |
| | | appUserOrderPageVo.setShopNumber(1); |
| | | appUserOrderPageVo.setShopName(JSON.toJSONString(data2)); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | }else{ |
| | | shop = shopMap.get(appUserOrderPageVo.getShopId()); |
| | | appUserOrderPageVo.setShopName(shop.getShopName()); |
| | | appUserOrderPageVo.setShopServicePhone(shop.getShopServicePhone()); |
| | | simpleShopVo = shopMap.get(appUserOrderPageVo.getShopId()); |
| | | appUserOrderPageVo.setShopName(simpleShopVo.getShopName()); |
| | | appUserOrderPageVo.setShopServicePhone(simpleShopVo.getShopServicePhone()); |
| | | appUserOrderPageVo.setShopNumber(2); |
| | | if (appUserOrderPageVo.getShopId().equals(appUserOrderPageDto.getShopId())) { |
| | | appUserOrderPageVo.setSameShop(1); |
| | | } else { |
| | |
| | | */ |
| | | @Override |
| | | public MerHomeShopTotalVo getMerHomeTotal(MerHomeShopTotalVo merHomeShopTotalVo) { |
| | | Long shopId = merHomeShopTotalVo.getShopId(); |
| | | // 查询用户信息 |
| | | QwUserDetailDto qwUserDetail = new QwUserDetailDto(); |
| | | Long userId = SecurityUtils.getUserId(); |
| | | qwUserDetail.setUserid(userId.toString()); |
| | | // 查询用户信息 |
| | | R<QwH5LoginVo> userResult = remoteShopService.qwH5Login(qwUserDetail); |
| | | if(userResult==null){ |
| | | throw new ServiceException(AppErrorConstant.USER_NO_SHOP); |
| | | } |
| | | if (R.FAIL == userResult.getCode()) |
| | | { |
| | | throw new ServiceException(userResult.getMsg()); |
| | | } |
| | | if (401 == userResult.getCode()) |
| | | { |
| | | throw new ServiceException("商户已被冻结,请联系管理员",401); |
| | | } |
| | | QwH5LoginVo userInfo = userResult.getData(); |
| | | SysUser user = userInfo.getSysUser(); |
| | | String username = user.getUserName(); |
| | | // IP黑名单校验 |
| | | String blackStr = Convert.toStr(redisService.getCacheObject(CacheConstants.SYS_LOGIN_BLACKIPLIST)); |
| | | if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr())) |
| | | { |
| | | throw new ServiceException("很遗憾,访问IP已被列入系统黑名单"); |
| | | } |
| | | if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) |
| | | { |
| | | throw new ServiceException("对不起,您的账号:" + username + " 已被删除"); |
| | | } |
| | | if (UserStatus.DISABLE.getCode().equals(user.getStatus())) |
| | | { |
| | | throw new ServiceException("对不起,您的账号:" + username + " 已停用"); |
| | | } |
| | | // 查询用户商户 |
| | | R<ShopRelUserVo> shopResult = remoteShopService.getShopByUserId(user.getUserId()); |
| | | if (R.FAIL == userResult.getCode()) { |
| | | throw new ServiceException(userResult.getMsg()); |
| | | } |
| | | ShopRelUserVo shopInfo = shopResult.getData(); |
| | | if(null == shopInfo){ |
| | | throw new ServiceException("未查询到商户信息"); |
| | | } |
| | | Long shopId = shopInfo.getShopId(); |
| | | Shop shop = remoteShopService.getShop(shopId).getData(); |
| | | if(-1 == shop.getShopStatus()){ |
| | | throw new ServiceException("对应商户已删除,请联系管理员"); |
| | | } |
| | | if(0 == shop.getShopStatus()){ |
| | | throw new ServiceException("对应商户已冻结,请联系管理员"); |
| | | } |
| | | if(2 == shop.getShopStatus()){ |
| | | throw new ServiceException("对应商户已终止合作,请联系管理员"); |
| | | } |
| | | |
| | | |
| | | shopId = merHomeShopTotalVo.getShopId(); |
| | | |
| | | //获取今日到店 |
| | | Integer todayShop = userServiceRecordService.countShopServicePerson(shopId); |
| | | //获取待处理订单和营业额 |
| | |
| | | if (order.getOrderStatus() != 2) { |
| | | throw new ServiceException(AppErrorConstant.VERIFY_USED); |
| | | } |
| | | //判断商户是否有分账权限 |
| | | Shop shop = remoteShopService.getShop(shopId).getData(); |
| | | if(shop.getAccountFlag()!=1){ |
| | | throw new ServiceException(AppErrorConstant.SHOP_NO_VERIFY); |
| | | } |
| | | // 根据订单用户ID获取用户信息 |
| | | Member member = remoteMemberService.getMember(order.getUserId()).getData(); |
| | | // 根据订单ID获取订单商品列表 |
| | |
| | | //判断用户是否绑定 |
| | | if(member.getBindingFlag()==1){ |
| | | //绑定用户判断核销商户 |
| | | if(order.getOrderFrom()==2&&order.getUnbindingFlag()==1){ |
| | | if (!member.getRelationShopId().equals(shopId)) { |
| | | throw new ServiceException(AppErrorConstant.VERIFY_SHOP_ERROR); |
| | | } |
| | | //未绑定时下的活动订单只需要判断店铺是否支持 |
| | | String activityId = order.getActivityId(); |
| | | MerActivityShopDto merActivityShopDto = new MerActivityShopDto(); |
| | | merActivityShopDto.setShopId(shopId); |
| | | merActivityShopDto.setActivityId(activityId); |
| | | Boolean judge = remoteActivityService.judgeActivityShop(merActivityShopDto).getData(); |
| | | if(!judge){ |
| | | throw new ServiceException(AppErrorConstant.SHOP_NO_ACTIVITY); |
| | | } |
| | | }else{ |
| | | if (order.getOrderFrom()==2&&!member.getRelationShopId().equals(shopId)) { |
| | | throw new ServiceException(AppErrorConstant.VERIFY_SHOP_ERROR); |
| | | } |
| | | if(order.getOrderFrom() == 1){ |
| | | //商城订单和绑定后活动订单判断核销商户和订单商户和用户关联商户是否统一 |
| | | if (!order.getShopId().equals(shopId)) { |
| | | throw new ServiceException(AppErrorConstant.VERIFY_SHOP_ERROR); |
| | |
| | | //获取核销商户 |
| | | ShopRelUserVo shopRelUserVo = remoteShopService.getShopByUserId(merVerifyOrderDto.getUserId()).getData(); |
| | | Long shopId = shopRelUserVo.getShopId(); |
| | | log.info("当前核销员工【" + shopRelUserVo.getUserName() + "】门店ID:" + shopId); |
| | | //获取订单商品列表 |
| | | List<AppUserOrderGoodsPageVo> appUserOrderGoodsPageVoList = orderGoodsService.listAppVoByOrderId(orderId); |
| | | //绑定用户判断核销商户 |
| | | if(member.getBindingFlag()==1){ |
| | | //未绑定的活动订单只需要判断店铺是否支持 |
| | | if(order.getOrderFrom()==2&&order.getUnbindingFlag()==1){ |
| | | if(order.getOrderFrom()==2 && !member.getRelationShopId().equals(shopId)){ |
| | | throw new ServiceException(AppErrorConstant.VERIFY_SHOP_ERROR); |
| | | } |
| | | if(order.getOrderFrom()==2 && member.getRelationShopId().equals(shopId)){ |
| | | String activityId = order.getActivityId(); |
| | | MerActivityShopDto merActivityShopDto = new MerActivityShopDto(); |
| | | merActivityShopDto.setShopId(shopId); |
| | |
| | | Boolean judge = remoteActivityService.judgeActivityShop(merActivityShopDto).getData(); |
| | | if(!judge){ |
| | | throw new ServiceException(AppErrorConstant.SHOP_NO_ACTIVITY); |
| | | } |
| | | }else{ |
| | | //绑定用户需直接判断商户一致 |
| | | if (!order.getShopId().equals(shopId)) { |
| | | throw new ServiceException(AppErrorConstant.VERIFY_SHOP_ERROR); |
| | | } |
| | | } |
| | | }else{ |
| | |
| | | throw new ServiceException(AppErrorConstant.SHOP_NO_ACTIVITY); |
| | | } |
| | | } |
| | | //未绑定用户需判断核销商城订单判断商品单价和优惠券 |
| | | /*StringJoiner goodsIdSJ = new StringJoiner(","); |
| | | for (AppUserOrderGoodsPageVo appUserOrderGoodsPageVo : appUserOrderGoodsPageVoList) { |
| | | goodsIdSJ.add(appUserOrderGoodsPageVo.getGoodsId()); |
| | | } |
| | | //获取商品列表 |
| | | List<Goods> goodsList = remoteGoodsService.listGoodsByGoodsId(goodsIdSJ.toString()).getData(); |
| | | Map<String, Goods> goodsMap = goodsList.stream() |
| | | .collect(Collectors.toMap(Goods::getGoodsId, Function.identity())); |
| | | Goods goods; |
| | | ShopGoods shopGoods; |
| | | AppShopGoodsGetDto appShopGoodsGetDto; |
| | | for (AppUserOrderGoodsPageVo appUserOrderGoodsPageVo : appUserOrderGoodsPageVoList) { |
| | | appShopGoodsGetDto= new AppShopGoodsGetDto(); |
| | | appShopGoodsGetDto.setShopId(shopId); |
| | | appShopGoodsGetDto.setGoodsId(appUserOrderGoodsPageVo.getGoodsId()); |
| | | shopGoods = remoteGoodsService.getShopGoods(appShopGoodsGetDto).getData(); |
| | | goods = goodsMap.get(appUserOrderGoodsPageVo.getGoodsId()); |
| | | //当商户定制价格不为空时判断商品定制价格否则判断商品价格是否一致 |
| | | if(shopGoods!=null){ |
| | | if(shopGoods.getSalesPrice().compareTo(appUserOrderGoodsPageVo.getGoodsPrice())!=0){ |
| | | throw new ServiceException(AppErrorConstant.VERIFY_SHOP_ERROR); |
| | | } |
| | | if(appUserOrderGoodsPageVo.getCycleNumFlag()==0){ |
| | | if(shopGoods.getServiceNum()!=null){ |
| | | throw new ServiceException(AppErrorConstant.VERIFY_SHOP_ERROR); |
| | | } |
| | | }else{ |
| | | if(shopGoods.getServiceNum()!=appUserOrderGoodsPageVo.getServiceNum()){ |
| | | throw new ServiceException(AppErrorConstant.VERIFY_SHOP_ERROR); |
| | | } |
| | | } |
| | | }else{ |
| | | if(goods.getSalesPrice().compareTo(appUserOrderGoodsPageVo.getGoodsPrice())!=0){ |
| | | throw new ServiceException(AppErrorConstant.VERIFY_SHOP_ERROR); |
| | | } |
| | | if(appUserOrderGoodsPageVo.getCycleNumFlag()==0){ |
| | | if(goods.getServiceNum()!=null){ |
| | | throw new ServiceException(AppErrorConstant.VERIFY_SHOP_ERROR); |
| | | } |
| | | }else{ |
| | | if(goods.getServiceNum()!=appUserOrderGoodsPageVo.getServiceNum()){ |
| | | throw new ServiceException(AppErrorConstant.VERIFY_SHOP_ERROR); |
| | | } |
| | | } |
| | | } |
| | | }*/ |
| | | } |
| | | order.setShopId(shopId); |
| | | order.setOrderStatus(3); |
| | |
| | | } |
| | | this.saveOrUpdate(order); |
| | | // 订单金额大于0时进行分账 |
| | | if (order.getOnlinePayMoney().compareTo(BigDecimal.ZERO)>0) { |
| | | submitProfitSharing(orderId, order.getOrderNo(), order.getShopId(), order.getOnlinePayMoney(),order.getOrderFrom()); |
| | | OrderPayment orderPayment = orderPaymentService.getOne(new QueryWrapper<OrderPayment>() |
| | | .eq("order_id", order.getOrderId()).eq("pay_status", 2) |
| | | .eq("del_flag", 0)); |
| | | BigDecimal bigDecimal = orderPayment.getPayMoney().subtract(orderPayment.getFeeAmount()).setScale(2, BigDecimal.ROUND_HALF_EVEN); |
| | | if (bigDecimal.compareTo(BigDecimal.ZERO)>0) { |
| | | // TODO: 2023/10/17 更换分账渠道(汇付天下) |
| | | // submitProfitSharing(orderId, order.getOrderNo(), order.getShopId(), order.getOnlinePayMoney(),order.getOrderFrom()); |
| | | submitProfitSharing1(orderId, order.getOrderNo(), order.getShopId(), bigDecimal, order.getOrderFrom()); |
| | | } |
| | | //创建支付记录 |
| | | if(merVerifyOrderDto.getRelPayMoney().compareTo(BigDecimal.ZERO)>0){ |
| | |
| | | payRecord.setPayType(merVerifyOrderDto.getPayType()); |
| | | payRecordService.save(payRecord); |
| | | } |
| | | //更新用户消费统计 |
| | | //更新用户积分和消费统计 |
| | | MemberTotalChangeDto memberTotalChangeDto = new MemberTotalChangeDto(); |
| | | memberTotalChangeDto.setUserId(order.getUserId()); |
| | | // 如果存在积分兑换比例,则计算积分 |
| | | if (redisService.hasKey(SecurityConstant.PAY_MONEY_INTEGRAL)) { |
| | | Integer moneyValue = redisService.getCacheObject(SecurityConstant.PAY_MONEY_INTEGRAL); |
| | | BigDecimal moneyValueBig = BigDecimal.valueOf(moneyValue); |
| | | BigDecimal integralBig = moneyValueBig.multiply(order.getOnlinePayMoney()).setScale(0,BigDecimal.ROUND_HALF_UP); |
| | | Integer integral = Integer.valueOf(integralBig.toString()); |
| | | if(integral>0){ |
| | | memberTotalChangeDto.setChangeIntegral(integral); |
| | | memberTotalChangeDto.setTypeIntegral(1); |
| | | memberTotalChangeDto.setOrderId(orderId); |
| | | memberTotalChangeDto.setOrderNo(order.getOrderNo()); |
| | | } |
| | | } |
| | | //更新消费时间 |
| | | memberTotalChangeDto.setConsumeTime(nowTime); |
| | | remoteMemberService.changeMemberTotal(memberTotalChangeDto); |
| | | return merVerifyOrderVo; |
| | |
| | | paymentMessageService.savePaymentMessage("4", orderId, sendMessage, resultMessage); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * @description 分账实现 |
| | | * @author jqs |
| | | * @date 2023/9/8 11:56 |
| | | * @param orderId |
| | | * @param orderNo |
| | | * @param shopId |
| | | * @param orderMoney |
| | | * @param orderFrom |
| | | * @return void |
| | | */ |
| | | private void submitProfitSharing1(String orderId, String orderNo, Long shopId, BigDecimal orderMoney, Integer orderFrom) { |
| | | String sendMessage = ""; |
| | | String resultMessage = ""; |
| | | try { |
| | | // 核销完成 开始分账(平台收取服务费) |
| | | OrderPayment payment = orderPaymentService.getByOrderId(orderId); |
| | | String transactionId = payment.getTransactionId(); |
| | | String outTradeNo = payment.getOutTradeNo(); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); |
| | | String org_req_date = sdf.format(payment.getCreateTime()); |
| | | R<ShopAuthenticationHftxVo> resultMch = remoteShopService.getShopHFTXSubMchId(shopId); |
| | | ShopAuthenticationHftxVo vo = resultMch.getData(); |
| | | if (StringUtils.isEmpty(vo.getHuifuId())) { |
| | | throw new ServiceException("获取商户号失败"); |
| | | } |
| | | // 平台特约商户号,用户平台收取服务费 2023-09-05改变分账方式 |
| | | String platformTyMacId = WxPayConfiguration.getPlatformTyMacId(); |
| | | if (!StringUtils.isEmpty(platformTyMacId)) { |
| | | WxPayConfig config = wxService.getConfig(); |
| | | ShopProportionVo shopProportion = null; |
| | | BigDecimal proportionPercent = null; |
| | | //商户订单获取统一分成 活动订单获取活动分成 |
| | | if(orderFrom==1){ |
| | | if(null == vo.getShareRatio()){ |
| | | proportionPercent = new BigDecimal(redisService.getCacheObject(SecurityConstant.SHOP_COMMON_PROPORTION).toString()); |
| | | }else{ |
| | | proportionPercent = new BigDecimal(vo.getShareRatio()); |
| | | } |
| | | }else{ |
| | | R<ShopProportionVo> resultShopProportion = remoteShopService.getShopProportion(shopId); |
| | | shopProportion = resultShopProportion.getData(); |
| | | proportionPercent = shopProportion.getProportionPercent(); |
| | | } |
| | | if (null != proportionPercent) { |
| | | ProfitSharingRequest request = new ProfitSharingRequest(); |
| | | request.setAppid(config.getAppId()); |
| | | request.setSubMchid(platformTyMacId); |
| | | request.setTransactionId(transactionId); |
| | | request.setOutOrderNo(IdUtils.simpleUUID()); |
| | | List<ProfitSharingRequest.Receiver> receiverList = new ArrayList<>(); |
| | | String description = "订单:" + orderNo + " 平台分账"; |
| | | //商户分成 |
| | | if(proportionPercent.compareTo(BigDecimal.ZERO)>0){ |
| | | PaymentDelaytransHFTXVo result = new PaymentDelaytransHFTXVo(); |
| | | // 计算分成金额 |
| | | int amount = orderMoney.multiply(new BigDecimal(100)).setScale(0, RoundingMode.HALF_EVEN).intValue(); |
| | | BigDecimal multiply = orderMoney.multiply(proportionPercent.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_EVEN); |
| | | log.info("订单分账:{} 分账金额: {}", orderNo, amount); |
| | | if (amount > 0) { |
| | | // 分账创建 |
| | | ProfitSharingRequest.Receiver receiver = new ProfitSharingRequest.Receiver(); |
| | | receiver.setType("MERCHANT_ID"); |
| | | receiver.setReceiverAccount(vo.getHuifuId()); |
| | | receiver.setAmount(amount); |
| | | receiver.setDescription(description); |
| | | receiverList.add(receiver); |
| | | request.setReceivers(receiverList); |
| | | // 分账完成 |
| | | request.setFinish(true); |
| | | |
| | | //分账对象 |
| | | JSONArray acctInfos = new JSONArray(); |
| | | if(multiply.compareTo(BigDecimal.ZERO) > 0){ |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("div_amt", String.format("%.2f", multiply.doubleValue())); |
| | | jsonObject.put("huifu_id", vo.getHuifuId()); |
| | | acctInfos.add(jsonObject); |
| | | } |
| | | //平台商户 |
| | | BigDecimal pt_amount = orderMoney.subtract(multiply).setScale(2, RoundingMode.HALF_EVEN); |
| | | if(pt_amount.compareTo(BigDecimal.ZERO) > 0){ |
| | | JSONObject jsonObject1 = new JSONObject(); |
| | | jsonObject1.put("div_amt", String.format("%.2f", pt_amount.doubleValue())); |
| | | jsonObject1.put("huifu_id", "6666000141216769"); |
| | | acctInfos.add(jsonObject1); |
| | | } |
| | | |
| | | R<PaymentDelaytransHFTXVo> hftxVoR = HuiFuTianXiaUtil.paymentDelaytrans(request.getOutOrderNo(), org_req_date, outTradeNo, acctInfos); |
| | | if(hftxVoR.getCode() != 200){ |
| | | throw new ServiceException(hftxVoR.getMsg()); |
| | | } |
| | | result = hftxVoR.getData(); |
| | | // 创建分账记录 |
| | | profitSharingService.saveProfitSharing1(shopId, orderId, orderMoney, vo.getHuifuId(), multiply.doubleValue(), result); |
| | | } |
| | | // 保存请求信息 |
| | | sendMessage = JSONObject.toJSONString(request); |
| | | resultMessage = JSONObject.toJSONString(result); |
| | | } |
| | | } else { |
| | | resultMessage = String.format("订单分账:%s 获取商户分成失败", orderNo); |
| | | log.info(resultMessage); |
| | | } |
| | | } else { |
| | | resultMessage = String.format("订单分账:%s 获取微信商户号失败", orderNo); |
| | | log.info(resultMessage); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | resultMessage = String.format("订单分账:%s 分账失败:%s", orderNo, e.getMessage()); |
| | | log.info(resultMessage); |
| | | throw new ServiceException(resultMessage); |
| | | } |
| | | |
| | | // 保存分账信息 |
| | | paymentMessageService.savePaymentMessage("4", orderId, sendMessage, resultMessage); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * @param merVerifyCouponDto |
| | | * @return MerVerifyCouponVo |
| | |
| | | @Transactional |
| | | @GlobalTransactional(rollbackFor = Exception.class) |
| | | public MerVerifyCouponVo sureVerifyCoupon(MerVerifyCouponDto merVerifyCouponDto) { |
| | | MerVerifyCouponGetVo verifyCouponGetVo = remoteCouponService.getVerifyCoupon(merVerifyCouponDto.getMemberCouponId()).getData(); |
| | | R<MerVerifyCouponGetVo> verifyCoupon = remoteCouponService.getVerifyCoupon(merVerifyCouponDto.getMemberCouponId()); |
| | | if(verifyCoupon.getCode() != 200){ |
| | | throw new ServiceException(verifyCoupon.getMsg()); |
| | | } |
| | | MerVerifyCouponGetVo verifyCouponGetVo = verifyCoupon.getData(); |
| | | MemberCoupon memberCoupon = verifyCouponGetVo.getMemberCoupon(); |
| | | ShopRelUserVo shopRelUserVo = remoteShopService.getShopByUserId(merVerifyCouponDto.getUserId()).getData(); |
| | | Long userId = verifyCouponGetVo.getUserId(); |
| | |
| | | MerVerifyCouponVo merVerifyCouponVo = new MerVerifyCouponVo(); |
| | | // 调用remoteCouponService的getVerifyCoupon方法获取MerVerifyCouponGetVo对象 |
| | | List<Goods> goodsList = verifyCouponGetVo.getGoodsList(); |
| | | String relGoodsIds = memberCoupon.getRelGoodsIds(); |
| | | String[] relGoodsIdArr = relGoodsIds.split(","); |
| | | if(relGoodsIdArr.length!=goodsList.size()){ |
| | | throw new ServiceException(AppErrorConstant.GOODS_DOWN); |
| | | } |
| | | merVerifyCouponVo.setUserName(member.getRealName()); |
| | | merVerifyCouponVo.setUserMobile(member.getMobile()); |
| | | merVerifyCouponVo.setCouponFrom(verifyCouponGetVo.getCouponFrom()); |
| | | merVerifyCouponVo.setCouponName(memberCoupon.getCouponName()); |
| | | merVerifyCouponVo.setCreateTime(memberCoupon.getReceiveTime()); |
| | | // 将goodsList转换为MerCouponGoodsListVo列表,并设置相应属性 |
| | | List<MerCouponGoodsListVo> merCouponGoodsList = goodsList.stream() |
| | | .map(goods -> { |
| | | MerCouponGoodsListVo merCouponGoods = new MerCouponGoodsListVo(); |
| | | merCouponGoods.setGoodsId(goods.getGoodsId()); |
| | | merCouponGoods.setGoodsName(goods.getGoodsName()); |
| | | if (goods.getGoodsType() == 1) { |
| | | merCouponGoods.setGoodsType("周期"); |
| | | } else if (goods.getGoodsType() == 2) { |
| | | merCouponGoods.setGoodsType("服务"); |
| | | } else if (goods.getGoodsType() == 3) { |
| | | merCouponGoods.setGoodsType("体验"); |
| | | } else if (goods.getGoodsType() == 4) { |
| | | merCouponGoods.setGoodsType("单品"); |
| | | } |
| | | // 设置其他属性 |
| | | return merCouponGoods; |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | List<MerCouponGoodsListVo> merCouponGoodsList = new ArrayList<>(); |
| | | MerCouponGoodsListVo merCouponGoods; |
| | | for(Goods goods : goodsList){ |
| | | if(goods.getGoodsStatus()!=1){ |
| | | throw new ServiceException(AppErrorConstant.GOODS_DOWN); |
| | | } |
| | | merCouponGoods = new MerCouponGoodsListVo(); |
| | | merCouponGoods.setGoodsId(goods.getGoodsId()); |
| | | merCouponGoods.setGoodsName(goods.getGoodsName()); |
| | | if (goods.getGoodsType() == 1) { |
| | | merCouponGoods.setGoodsType("周期"); |
| | | } else if (goods.getGoodsType() == 2) { |
| | | merCouponGoods.setGoodsType("服务"); |
| | | } else if (goods.getGoodsType() == 3) { |
| | | merCouponGoods.setGoodsType("体验"); |
| | | } else if (goods.getGoodsType() == 4) { |
| | | merCouponGoods.setGoodsType("单品"); |
| | | } |
| | | merCouponGoodsList.add(merCouponGoods); |
| | | } |
| | | // 设置merVerifyCouponVo的goodsList属性为merCouponGoodsList |
| | | merVerifyCouponVo.setGoodsList(merCouponGoodsList); |
| | | //生成服务 |
| | |
| | | SysUser sysUser; |
| | | if (member != null) { |
| | | sysUser = remoteUserService.getSysUser(member.getUserId()).getData(); |
| | | if(member.getBindingFlag()==1&&!member.getRelationShopId().equals(merNewOrderDto.getShopId())){ |
| | | throw new ServiceException(AppErrorConstant.USER_BINDING_ERROR); |
| | | } |
| | | } else { |
| | | //创建新用户 |
| | | String memberId = IdUtils.simpleUUID(); |
| | |
| | | BigDecimal buyNumBig; |
| | | Integer serviceNum; |
| | | Integer goodsNum = 0; |
| | | String memberCouponId; |
| | | Long memberCouponId; |
| | | Goods goods; |
| | | BigDecimal goodsPrice; |
| | | BigDecimal goodsTotalPrice; |
| | |
| | | OrderGoods orderGoods; |
| | | String orderGoodsId; |
| | | GoodsFile goodsFile; |
| | | //BigDecimal cycleMoney = new BigDecimal("0.00"); |
| | | //BigDecimal experienceMoney = new BigDecimal("0.00"); |
| | | //BigDecimal serviceMoney = new BigDecimal("0.00"); |
| | | //BigDecimal goodsMoney = new BigDecimal("0.00"); |
| | | List<OrderGoods> orderGoodsList = new ArrayList<>(); |
| | | ConsumerGoods consumerGoods; |
| | | String consumerGoodsId; |
| | |
| | | goodsRealPrice = goodsTotalPrice; |
| | | //优惠券计算 |
| | | if (memberCouponId != null) { |
| | | appMemberCouponVo = appMemberCouponVoMap.get(memberCouponId); |
| | | log.info("使用优惠券:{}", memberCouponId); |
| | | appMemberCouponVo = appMemberCouponVoMap.get(memberCouponId.toString()); |
| | | log.info("匹配的优惠券:{}", JSON.toJSONString(appMemberCouponVo)); |
| | | if (null != appMemberCouponVo && (StringUtils.isBlank(appMemberCouponVo.getRelGoodsIds()) || appMemberCouponVo.getRelGoodsIds().contains(goodsId))) { |
| | | log.info("可以使用优惠券:{}", JSON.toJSONString(appMemberCouponVo)); |
| | | couponType = appMemberCouponVo.getCouponType(); |
| | | couponType = appMemberCouponVo.getCouponType(); |
| | | if (couponType == 1 && appMemberCouponVo.getMoneyThreshold() != null && appMemberCouponVo.getDiscountMoney() != null) { |
| | | moneyThreshold = appMemberCouponVo.getMoneyThreshold(); |
| | |
| | | goodsRealPrice = BigDecimal.ZERO; |
| | | discountMoney = goodsTotalPrice.subtract(goodsRealPrice); |
| | | } |
| | | memberCouponSJ.add(memberCouponId); |
| | | memberCouponSJ.add(memberCouponId + ","); |
| | | } |
| | | } |
| | | goodsDeposit = goods.getSubscription(); |
| | |
| | | consumerGoodsList.add(consumerGoods); |
| | | } |
| | | } |
| | | |
| | | //商户变更计算 |
| | | /*switch (orderGoods.getGoodsType()) { |
| | | case 1: |
| | | cycleMoney = cycleMoney.add(orderGoods.getGoodsReceivableMoney()); |
| | | break; |
| | | case 2: |
| | | serviceMoney = serviceMoney.add(orderGoods.getGoodsReceivableMoney()); |
| | | break; |
| | | case 3: |
| | | experienceMoney = experienceMoney.add(orderGoods.getGoodsReceivableMoney()); |
| | | break; |
| | | case 4: |
| | | goodsMoney = goodsMoney.add(orderGoods.getGoodsReceivableMoney()); |
| | | break; |
| | | default: |
| | | break; |
| | | }*/ |
| | | } |
| | | //创建订单 |
| | | Order order = new Order(); |
| | |
| | | consumerGoodsService.saveBatchConsumerGoods(consumerGoodsList); |
| | | //减去优惠券 |
| | | if (StringUtils.isNotBlank(memberCouponSJ.toString())) { |
| | | log.info("修改优惠券使用状态:{}", JSON.toJSONString(memberCouponSJ)); |
| | | remoteCouponService.useMemberCoupon(memberCouponSJ.toString()); |
| | | } |
| | | //更新会员消费记录 |
| | |
| | | memberTotalChangeDto.setUserId(order.getUserId()); |
| | | memberTotalChangeDto.setConsumeTime(nowTime); |
| | | remoteMemberService.changeMemberTotal(memberTotalChangeDto); |
| | | //更新商户统计 |
| | | /*ShopTotalChangeDto shopTotalChangeDto = new ShopTotalChangeDto(); |
| | | shopTotalChangeDto.setShopId(order.getShopId()); |
| | | shopTotalChangeDto.setOrderType(1); |
| | | shopTotalChangeDto.setCycleMoney(cycleMoney); |
| | | shopTotalChangeDto.setServiceMoney(serviceMoney); |
| | | shopTotalChangeDto.setExperienceMoney(experienceMoney); |
| | | shopTotalChangeDto.setGoodsMoney(goodsMoney); |
| | | remoteShopService.changeShopTotal(shopTotalChangeDto);*/ |
| | | //创建支付记录 |
| | | PayRecord payRecord = new PayRecord(); |
| | | payRecord.setDelFlag(0); |
| | |
| | | // 根据用户ID列表获取用户信息 |
| | | MgtBaseBathDto mgtBaseBathDto = new MgtBaseBathDto(); |
| | | mgtBaseBathDto.setIds(userIdSj.toString()); |
| | | List<MgtSimpleMemberVo> simpleMemberVoList = remoteMemberService.listSimpleVoByIds(mgtBaseBathDto).getData(); |
| | | List<MgtSimpleMemberVo> simpleMemberVoList = remoteMemberService.listSimpleVoByIds(userIdSj.toString()).getData(); |
| | | Map<Long, MgtSimpleMemberVo> userMap = simpleMemberVoList.stream() |
| | | .collect(Collectors.toMap(MgtSimpleMemberVo::getUserId, Function.identity())); |
| | | // 遍历订单列表,设置用户信息 |
| | |
| | | mgtShopOrderPageDto.setUserIds(mgtUserIdByKeywordVo.getUserIds()); |
| | | } |
| | | } |
| | | //数据权限 |
| | | List<Long> userId = remoteUserService.getScopeOfAuthorityUserId(); |
| | | BoardMemberTotalDto boardMemberTotalDto = new BoardMemberTotalDto(); |
| | | boardMemberTotalDto.setUserIds(userId); |
| | | List<Shop> shops = remoteShopService.getShopBySysUserIds(boardMemberTotalDto); |
| | | if (!shops.isEmpty()) { |
| | | List<Long> collect = shops.stream().map(Shop::getShopId).collect(Collectors.toList()); |
| | | String join = collect.stream().map(Object::toString).collect(Collectors.joining(",")); |
| | | String shopIds = mgtShopOrderPageDto.getShopIds(); |
| | | if(StringUtils.isNotEmpty(shopIds)){ |
| | | shopIds = shopIds + "," + join; |
| | | }else{ |
| | | shopIds = join; |
| | | } |
| | | mgtShopOrderPageDto.setShopIds(shopIds); |
| | | } |
| | | |
| | | |
| | | // 从数据库中获取活动订单列表 |
| | | List<MgtActivityOrderPageVo> activityOrderPageVoList = orderMapper.pageMgtActivityOrder(page, mgtShopOrderPageDto); |
| | | // 如果列表不为空 |
| | |
| | | .collect(Collectors.toMap(MgtSimpleShopVo::getShopId, Function.identity())); |
| | | mgtBaseBathDto = new MgtBaseBathDto(); |
| | | mgtBaseBathDto.setIds(userJoinedString); |
| | | List<MgtSimpleMemberVo> simpleMemberVoList = remoteMemberService.listSimpleVoByIds(mgtBaseBathDto).getData(); |
| | | List<MgtSimpleMemberVo> simpleMemberVoList = remoteMemberService.listSimpleVoByIds(userJoinedString).getData(); |
| | | Map<Long, MgtSimpleMemberVo> userMap = simpleMemberVoList.stream() |
| | | .collect(Collectors.toMap(MgtSimpleMemberVo::getUserId, Function.identity())); |
| | | // 遍历列表,设置店铺名称、用户名称和未支付金额 |
| | | for (MgtActivityOrderPageVo mgtActivityOrderPageVo : activityOrderPageVoList) { |
| | | if(mgtActivityOrderPageVo.getShopId()!=null){ |
| | | mgtActivityOrderPageVo.setShopName(shopMap.get(mgtActivityOrderPageVo.getShopId()).getShopName()); |
| | | MgtSimpleShopVo mgtSimpleShopVo = shopMap.get(mgtActivityOrderPageVo.getShopId()); |
| | | mgtActivityOrderPageVo.setShopName(null == mgtSimpleShopVo ? "" : mgtSimpleShopVo.getShopName()); |
| | | |
| | | } |
| | | if (userMap.get(mgtActivityOrderPageVo.getUserId()) != null) { |
| | |
| | | if (StringUtils.isNotBlank(mgtUserIdByKeywordVo.getUserIds())) { |
| | | mgtShopOrderPageDto.setUserIds(mgtUserIdByKeywordVo.getUserIds()); |
| | | } |
| | | } |
| | | //数据权限 |
| | | List<Long> userId = remoteUserService.getScopeOfAuthorityUserId(); |
| | | BoardMemberTotalDto boardMemberTotalDto = new BoardMemberTotalDto(); |
| | | boardMemberTotalDto.setUserIds(userId); |
| | | List<Shop> shops = remoteShopService.getShopBySysUserIds(boardMemberTotalDto); |
| | | if (!shops.isEmpty()) { |
| | | List<Long> collect = shops.stream().map(Shop::getShopId).collect(Collectors.toList()); |
| | | String join = collect.stream().map(Object::toString).collect(Collectors.joining(",")); |
| | | String shopIds = mgtShopOrderPageDto.getShopIds(); |
| | | if(StringUtils.isNotEmpty(shopIds)){ |
| | | shopIds = shopIds + "," + join; |
| | | }else{ |
| | | shopIds = join; |
| | | } |
| | | mgtShopOrderPageDto.setShopIds(shopIds); |
| | | } |
| | | MgtOrderTotal mgtOrderTotal = new MgtOrderTotal(); |
| | | MgtOrderTotal mgtOrderTotalFirst = orderMapper.totalOrderFirst(mgtShopOrderPageDto); |
| | |
| | | mgtShopOrderPageDto.setUserIds(mgtUserIdByKeywordVo.getUserIds()); |
| | | } |
| | | } |
| | | //数据权限 |
| | | List<Long> userId = remoteUserService.getScopeOfAuthorityUserId(); |
| | | BoardMemberTotalDto boardMemberTotalDto = new BoardMemberTotalDto(); |
| | | boardMemberTotalDto.setUserIds(userId); |
| | | List<Shop> shops = remoteShopService.getShopBySysUserIds(boardMemberTotalDto); |
| | | if (!shops.isEmpty()) { |
| | | List<Long> collect = shops.stream().map(Shop::getShopId).collect(Collectors.toList()); |
| | | String join = collect.stream().map(Object::toString).collect(Collectors.joining(",")); |
| | | String shopIds = mgtShopOrderPageDto.getShopIds(); |
| | | if(StringUtils.isNotEmpty(shopIds)){ |
| | | shopIds = shopIds + "," + join; |
| | | }else{ |
| | | shopIds = join; |
| | | } |
| | | mgtShopOrderPageDto.setShopIds(shopIds); |
| | | } |
| | | List<MgtShopOrderPageVo> shopOrderPageVoList = orderMapper.pageMgtShopOrder(page, mgtShopOrderPageDto); |
| | | // 如果列表不为空 |
| | | if (!shopOrderPageVoList.isEmpty()) { |
| | |
| | | String userJoinedString = String.join(",", userIdSet.stream().map(Object::toString).collect(Collectors.toList())); |
| | | MgtBaseBathDto mgtBaseBathDto = new MgtBaseBathDto(); |
| | | mgtBaseBathDto.setIds(userJoinedString); |
| | | List<MgtSimpleMemberVo> simpleMemberVoList = remoteMemberService.listSimpleVoByIds(mgtBaseBathDto).getData(); |
| | | List<MgtSimpleMemberVo> simpleMemberVoList = remoteMemberService.listSimpleVoByIds(userJoinedString).getData(); |
| | | userMap = simpleMemberVoList.stream() |
| | | .collect(Collectors.toMap(MgtSimpleMemberVo::getUserId, Function.identity())); |
| | | } |
| | |
| | | Order order = this.getById(orderId); |
| | | // 获取会员信息 |
| | | Member member = remoteMemberService.getMember(order.getUserId()).getData(); |
| | | // 获取商店信息 |
| | | Shop shop = remoteShopService.getShop(order.getShopId()).getData(); |
| | | // 获取订单商品详细信息 |
| | | List<MgtOrderGoodsDetailVo> orderGoodsDetailVoList = orderGoodsService.listMgtVoByOrderId(orderId); |
| | | // 设置MgtOrderDetailVo属性 |
| | |
| | | } |
| | | // 设置订单编号 |
| | | mgtOrderDetailVo.setOrderNo(order.getOrderNo()); |
| | | mgtOrderDetailVo.setOutTradeNo(order.getOutTradeNo()); |
| | | // 设置订单来源 |
| | | switch (order.getOrderFrom()) { |
| | | case 1: |
| | |
| | | mgtOrderDetailVo.setCancelTime(order.getCancelTime()); |
| | | mgtOrderDetailVo.setOrderRemark(order.getOrderRemark()); |
| | | mgtOrderDetailVo.setShopId(order.getShopId()); |
| | | if (shop != null) { |
| | | if (3 == order.getOrderStatus()) { |
| | | // 获取商店信息 |
| | | Shop shop = remoteShopService.getShop(order.getShopId()).getData(); |
| | | mgtOrderDetailVo.setShopName(shop.getShopName()); |
| | | } else { |
| | | mgtOrderDetailVo.setShopName("商户已被删除"); |
| | | mgtOrderDetailVo.setShopName(""); |
| | | } |
| | | mgtOrderDetailVo.setVerifyTime(order.getUseTime()); |
| | | //获取支付记录 |
| | |
| | | * @date 2023/6/18 17:20 |
| | | */ |
| | | @Override |
| | | public MgtBulletinBoardVo boardOrderTotal() { |
| | | MgtBulletinBoardVo mgtBulletinBoardVo = orderMapper.boardOrderTotal(); |
| | | Integer activityUserTotal = orderMapper.activityUserTotal(); |
| | | public MgtBulletinBoardVo boardOrderTotal(List<Long> userIds) { |
| | | BoardMemberTotalDto boardMemberTotalDto = new BoardMemberTotalDto(); |
| | | boardMemberTotalDto.setUserIds(userIds); |
| | | List<Shop> shopList = remoteShopService.getShopBySysUserIds(boardMemberTotalDto); |
| | | List<Long> collect = shopList.stream().map(Shop::getShopId).collect(Collectors.toList()); |
| | | MgtBulletinBoardVo mgtBulletinBoardVo = orderMapper.boardOrderTotal(collect); |
| | | Integer activityUserTotal = orderMapper.activityUserTotal(collect); |
| | | mgtBulletinBoardVo.setActivityUserTotal(activityUserTotal); |
| | | return mgtBulletinBoardVo; |
| | | } |
| | |
| | | userIdList.add(mgtBasePlatformDto.getUserId()); |
| | | } else { |
| | | MgtUserIdByDept mgtUserIdByDept = new MgtUserIdByDept(); |
| | | mgtUserIdByDept.setDeptId(mgtBasePlatformDto.getUserId()); |
| | | mgtUserIdByDept.setDeptId(mgtBasePlatformDto.getDeptId()); |
| | | mgtUserIdByDept = remoteConfigService.getUserIdByDept(mgtUserIdByDept).getData(); |
| | | userIdList = mgtUserIdByDept.getUserIdList(); |
| | | } |
| | |
| | | mgtBasePlatformDto.setUserIdList(userIdList); |
| | | } |
| | | } |
| | | //数据权限 |
| | | List<Long> userIds = remoteUserService.getScopeOfAuthorityUserId(); |
| | | if(null != userIds){ |
| | | List<Long> userIdList = mgtBasePlatformDto.getUserIdList(); |
| | | if(null != userIdList){ |
| | | userIdList.addAll(userIds); |
| | | }else{ |
| | | userIdList = userIds; |
| | | } |
| | | mgtBasePlatformDto.setUserIdList(userIdList); |
| | | } |
| | | |
| | | |
| | | List<Long> shopIdList = new ArrayList<>(); |
| | | if(mgtBasePlatformDto.getShopId()!=null){ |
| | | shopIdList.add(mgtBasePlatformDto.getShopId()); |
| | |
| | | MgtSimpleShopVo simpleShopVo; |
| | | HashSet<String> set = new HashSet<>(); |
| | | // 遍历MgtMemberOrderPageVoList,获取shopId并添加到set中 |
| | | for (Long entity : shopIdList) { |
| | | set.add(entity.toString()); |
| | | if(null != shopIdList){ |
| | | for (Long entity : shopIdList) { |
| | | set.add(entity.toString()); |
| | | } |
| | | } |
| | | String joinedString = String.join(",", set); |
| | | MgtBaseBathDto mgtBaseBathDto = new MgtBaseBathDto(); |
| | |
| | | if (mgtBasePlatformDto.getUserId() != null) { |
| | | userIdList.add(mgtBasePlatformDto.getUserId()); |
| | | } else { |
| | | MgtUserIdByDept mgtUserIdByDept = new MgtUserIdByDept(); |
| | | mgtUserIdByDept.setDeptId(mgtBasePlatformDto.getUserId()); |
| | | mgtUserIdByDept = remoteConfigService.getUserIdByDept(mgtUserIdByDept).getData(); |
| | | userIdList = mgtUserIdByDept.getUserIdList(); |
| | | List<SysUser> data = remoteUserService.getUsersByDeptId(mgtBasePlatformDto.getDeptId()).getData(); |
| | | userIdList.addAll(data.stream().map(SysUser::getUserId).collect(Collectors.toList())); |
| | | } |
| | | if (!userIdList.isEmpty()) { |
| | | mgtBasePlatformDto.setUserIdList(userIdList); |
| | | } |
| | | } |
| | | //数据权限 |
| | | List<Long> userIdList = mgtBasePlatformDto.getUserIdList(); |
| | | List<Long> userIds = remoteUserService.getScopeOfAuthorityUserId(); |
| | | if(null != userIds){ |
| | | if(null != userIdList){ |
| | | userIdList.addAll(userIds); |
| | | }else{ |
| | | userIdList = userIds; |
| | | } |
| | | mgtBasePlatformDto.setUserIdList(userIdList); |
| | | } |
| | | |
| | | |
| | | MgtTotalOrderTotalVo mgtTotalOrderTotalVo = new MgtTotalOrderTotalVo(); |
| | | mgtTotalOrderTotalVo.setOrderTotal(0); |
| | | mgtTotalOrderTotalVo.setOnlineTotal(0); |
| | |
| | | mgtTotalOrderTotalVo.setCycleTotal(0); |
| | | mgtTotalOrderTotalVo.setExperienceTotal(0); |
| | | mgtTotalOrderTotalVo.setServiceTotal(0); |
| | | mgtTotalOrderTotalVo.setItemTotal(0); |
| | | mgtTotalOrderTotalVo.setOrderMoney(new BigDecimal("0")); |
| | | mgtTotalOrderTotalVo.setOnlineMoney(new BigDecimal("0")); |
| | | mgtTotalOrderTotalVo.setOfflineMoney(new BigDecimal("0")); |
| | |
| | | mgtTotalOrderTotalVo.setCycleMoney(new BigDecimal("0")); |
| | | mgtTotalOrderTotalVo.setExperienceMoney(new BigDecimal("0")); |
| | | mgtTotalOrderTotalVo.setServiceMoney(new BigDecimal("0")); |
| | | mgtTotalOrderTotalVo.setItemMoney(new BigDecimal("0")); |
| | | mgtTotalOrderTotalVo.setOrderTotalKey(new String[0]); |
| | | mgtTotalOrderTotalVo.setOrderTotalValue(new Integer[0]); |
| | | mgtTotalOrderTotalVo.setOrderMoneyValue(new BigDecimal[0]); |
| | |
| | | mgtTotalOrderTotalVo.setGoodsTypeMoneyList(Lists.newArrayList()); |
| | | mgtTotalOrderTotalVo.setGoodsRankList(Lists.newArrayList()); |
| | | mgtTotalOrderTotalVo.setOrderFromRankList(Lists.newArrayList()); |
| | | |
| | | List<Long> shopIdList = remoteShopService.listShopIdByPlTotal(mgtBasePlatformDto).getData(); |
| | | if (mgtBasePlatformDto.getUserId() != null || StringUtils.isNotBlank(mgtBasePlatformDto.getShopProvinceCode()) || StringUtils.isNotBlank(mgtBasePlatformDto.getShopCityCode()) || StringUtils.isNotBlank(mgtBasePlatformDto.getShopAreaCode())) { |
| | | if(shopIdList==null||shopIdList.isEmpty()){ |
| | |
| | | mgtTotalOrderTotalVo.setOrderTotal(totalOrderTotalVo.getOrderTotal()); |
| | | mgtTotalOrderTotalVo.setOnlineTotal(totalOrderTotalVo.getOnlineTotal()); |
| | | mgtTotalOrderTotalVo.setOfflineTotal(totalOrderTotalVo.getOfflineTotal()); |
| | | mgtTotalOrderTotalVo.setActivityTotal(0); |
| | | mgtTotalOrderTotalVo.setActivityTotal(totalOrderTotalVo.getActivityTotal()); |
| | | mgtTotalOrderTotalVo.setOrderMoney(totalOrderTotalVo.getOrderMoney()); |
| | | mgtTotalOrderTotalVo.setOnlineMoney(totalOrderTotalVo.getOnlineMoney()); |
| | | mgtTotalOrderTotalVo.setOfflineMoney(totalOrderTotalVo.getOfflineMoney()); |
| | |
| | | mgtTotalOrderTotalVo.setCycleMoney(BigDecimal.ZERO); |
| | | mgtTotalOrderTotalVo.setServiceTotal(0); |
| | | mgtTotalOrderTotalVo.setServiceMoney(BigDecimal.ZERO); |
| | | mgtTotalOrderTotalVo.setItemTotal(0); |
| | | mgtTotalOrderTotalVo.setItemMoney(BigDecimal.ZERO); |
| | | mgtTotalOrderTotalVo.setExperienceTotal(0); |
| | | mgtTotalOrderTotalVo.setExperienceMoney(BigDecimal.ZERO); |
| | | if (MgtMapIntTotalVoGoodsType != null && MgtMapIntTotalVoGoodsType.size() > 0) { |
| | |
| | | } else if (MgtMapIntTotalVoGoodsType.get(i).getMapKey().equals("4")) { |
| | | mgtMapIntTotalVo.setMapKey("单品"); |
| | | mgtMapBigTotalVo.setMapKey("单品"); |
| | | mgtTotalOrderTotalVo.setItemTotal(mgtTotalOrderTotalVo.getItemTotal() + MgtMapIntTotalVoGoodsType.get(i).getMapValueFirst()); |
| | | mgtTotalOrderTotalVo.setItemMoney(mgtTotalOrderTotalVo.getItemMoney().add(MgtMapIntTotalVoGoodsType.get(i).getMapValueSecond())); |
| | | noGoods = false; |
| | | } |
| | | goodsTypeTotalList.add(mgtMapIntTotalVo); |
| | |
| | | if(mgtBasePlatformDto.getActivityFrom()!=null&&mgtBasePlatformDto.getActivityFrom()==2){ |
| | | return totalActivityTotalVo; |
| | | } |
| | | |
| | | //数据权限 |
| | | List<Long> userIds = remoteUserService.getScopeOfAuthorityUserId(); |
| | | if(null != userIds){ |
| | | List<Long> userIdList = mgtBasePlatformDto.getUserIdList(); |
| | | if(null == userIdList){ |
| | | userIdList = new ArrayList<>(); |
| | | } |
| | | userIdList.addAll(userIds); |
| | | mgtBasePlatformDto.setUserIdList(userIdList); |
| | | } |
| | | |
| | | List<Long> shopIdList = remoteShopService.listShopIdByPlTotal(mgtBasePlatformDto).getData(); |
| | | if (StringUtils.isNotBlank(mgtBasePlatformDto.getShopProvinceCode()) || StringUtils.isNotBlank(mgtBasePlatformDto.getShopCityCode()) || StringUtils.isNotBlank(mgtBasePlatformDto.getShopAreaCode())) { |
| | | if(shopIdList==null||shopIdList.isEmpty()){ |
| | |
| | | shopIdList.add(mgtBasePlatformDto.getShopId()); |
| | | } |
| | | mgtBasePlatformDto.setShopIdList(shopIdList); |
| | | |
| | | //获取基础统计 |
| | | MgtPlTotalActivityTotalVo mgtTotalActivityTotalVo = orderMapper.getPlTotalActivityTotal(mgtBasePlatformDto); |
| | | totalActivityTotalVo.setOrderTotal(mgtTotalActivityTotalVo.getOrderTotal()); |
| | |
| | | } |
| | | HashSet<String> set = new HashSet<>(); |
| | | // 遍历MgtMemberOrderPageVoList,获取shopId并添加到set中 |
| | | for (Long shopId : mgtBasePlatformDto.getShopIdList()) { |
| | | set.add(shopId.toString()); |
| | | if(null != mgtBasePlatformDto.getShopIdList()){ |
| | | for (Long shopId : mgtBasePlatformDto.getShopIdList()) { |
| | | set.add(shopId.toString()); |
| | | } |
| | | } |
| | | // 将set中的shopId转换为逗号分隔的字符串 |
| | | String joinedString = String.join(",", set); |
| | |
| | | totalActivityTotalVo.setOrderTotalValue(orderTotalValue); |
| | | totalActivityTotalVo.setOrderMoneyValue(orderMoneyValue); |
| | | } |
| | | |
| | | //参与人数 2023-09-06 另开接口 |
| | | /*List<MgtMapIntTotalVo> joinList = orderMapper.getMgtActivityMemberTotal(mgtBasePlatformDto); |
| | | // 将查询结果转为Map |
| | | Map<String, Integer> mgtMapIntTotalVoMap = new HashMap<>(); |
| | | if (joinList != null && !joinList.isEmpty()) { |
| | | mgtMapIntTotalVoMap = joinList.stream() |
| | | .collect(Collectors.toMap(MgtMapIntTotalVo::getMapKey, MgtMapIntTotalVo::getMapValue)); |
| | | } |
| | | // 获取日期范围 |
| | | List<String> dateList = getDateRange(mgtBasePlatformDto.getStartDate(), mgtBasePlatformDto.getEndDate()); |
| | | int size = dateList.size(); |
| | | // 创建日期和成员总数的数组 |
| | | String[] joinMemberTotalKey = new String[size]; |
| | | Integer[] joinMemberTotalValue = new Integer[size]; |
| | | // 遍历日期列表,设置日期和成员总数的数组 |
| | | String str; |
| | | Integer value; |
| | | for (int i = 0; i < size; i++) { |
| | | str = dateList.get(i); |
| | | joinMemberTotalKey[i] = str; |
| | | value = mgtMapIntTotalVoMap.get(str); |
| | | joinMemberTotalValue[i] = (value != null) ? value : 0; |
| | | } |
| | | totalActivityTotalVo.setJoinMemberTotalKey(joinMemberTotalKey); |
| | | totalActivityTotalVo.setJoinMemberTotalValue(joinMemberTotalValue); |
| | | //获客人数 |
| | | List<MgtMapIntTotalVo> getList = orderMapper.getMgtActivityGetMemberTotal(mgtBasePlatformDto); |
| | | // 将查询结果转为Map |
| | | Map<String, Integer> getMemberMap = new HashMap<>(); |
| | | if (getList != null && !getList.isEmpty()) { |
| | | getMemberMap = getList.stream() |
| | | .collect(Collectors.toMap(MgtMapIntTotalVo::getMapKey, MgtMapIntTotalVo::getMapValue)); |
| | | } |
| | | // 创建日期和成员总数的数组 |
| | | String[] getMemberTotalKey = new String[size]; |
| | | Integer[] getMemberTotalValue = new Integer[size]; |
| | | // 遍历日期列表,设置日期和成员总数的数组 |
| | | for (int i = 0; i < size; i++) { |
| | | str = dateList.get(i); |
| | | getMemberTotalKey[i] = str; |
| | | value = getMemberMap.get(str); |
| | | getMemberTotalValue[i] = (value != null) ? value : 0; |
| | | } |
| | | totalActivityTotalVo.setGetMemberTotalKey(getMemberTotalKey); |
| | | totalActivityTotalVo.setGetMemberTotalValue(getMemberTotalValue);*/ |
| | | return totalActivityTotalVo; |
| | | } |
| | | |
| | |
| | | if(mgtBasePlatformDto.getActivityFrom()!=null&&mgtBasePlatformDto.getActivityFrom()==2){ |
| | | return totalActivityTotalVo; |
| | | } |
| | | /*if(mgtBasePlatformDto.getActivityType()!=null&&mgtBasePlatformDto.getActivityType()!=1){ |
| | | return new MgtPlTotalActivityTotalVo(); |
| | | }*/ |
| | | //获取需要关联的用户id集合 |
| | | /*if (mgtBasePlatformDto.getDeptId() != null) { |
| | | List<Long> userIdList = new ArrayList<>(); |
| | | if (mgtBasePlatformDto.getUserId() != null) { |
| | | userIdList.add(mgtBasePlatformDto.getUserId()); |
| | | } else { |
| | | MgtUserIdByDept mgtUserIdByDept = new MgtUserIdByDept(); |
| | | mgtUserIdByDept.setDeptId(mgtBasePlatformDto.getUserId()); |
| | | mgtUserIdByDept = remoteConfigService.getUserIdByDept(mgtUserIdByDept).getData(); |
| | | userIdList = mgtUserIdByDept.getUserIdList(); |
| | | } |
| | | if (!userIdList.isEmpty()) { |
| | | mgtBasePlatformDto.setUserIdList(userIdList); |
| | | } |
| | | }*/ |
| | | |
| | | List<Long> shopIdList = remoteShopService.listShopIdByPlTotal(mgtBasePlatformDto).getData(); |
| | | log.info("shopIdList1-----"+shopIdList.toString()); |
| | |
| | | if(mgtBasePlatformDto.getShopId()!=null){ |
| | | shopIdList = new ArrayList<>(); |
| | | shopIdList.add(mgtBasePlatformDto.getShopId()); |
| | | } |
| | | |
| | | List<Long> userIds = remoteUserService.getScopeOfAuthorityUserId(); |
| | | BoardMemberTotalDto boardMemberTotalDto = new BoardMemberTotalDto(); |
| | | boardMemberTotalDto.setUserIds(userIds); |
| | | List<Shop> shopList = remoteShopService.getShopBySysUserIds(boardMemberTotalDto); |
| | | List<Long> collect = shopList.stream().map(Shop::getShopId).collect(Collectors.toList()); |
| | | if(null != shopIdList){ |
| | | shopIdList.addAll(collect); |
| | | }else{ |
| | | shopIdList = collect; |
| | | } |
| | | mgtBasePlatformDto.setShopIdList(shopIdList); |
| | | if(mgtBasePlatformDto.getAgeType()!=null){ |
| | |
| | | if(mgtBasePlatformDto.getActivityFrom()!=null&&mgtBasePlatformDto.getActivityFrom()==2){ |
| | | return totalActivityTotalVo; |
| | | } |
| | | /*if(mgtBasePlatformDto.getActivityType()!=null&&mgtBasePlatformDto.getActivityType()!=1){ |
| | | return new MgtPlTotalActivityTotalVo(); |
| | | }*/ |
| | | //获取需要关联的用户id集合 |
| | | /*if (mgtBasePlatformDto.getDeptId() != null) { |
| | | List<Long> userIdList = new ArrayList<>(); |
| | | if (mgtBasePlatformDto.getUserId() != null) { |
| | | userIdList.add(mgtBasePlatformDto.getUserId()); |
| | | } else { |
| | | MgtUserIdByDept mgtUserIdByDept = new MgtUserIdByDept(); |
| | | mgtUserIdByDept.setDeptId(mgtBasePlatformDto.getUserId()); |
| | | mgtUserIdByDept = remoteConfigService.getUserIdByDept(mgtUserIdByDept).getData(); |
| | | userIdList = mgtUserIdByDept.getUserIdList(); |
| | | } |
| | | if (!userIdList.isEmpty()) { |
| | | mgtBasePlatformDto.setUserIdList(userIdList); |
| | | } |
| | | }*/ |
| | | List<Long> shopIdList = remoteShopService.listShopIdByPlTotal(mgtBasePlatformDto).getData(); |
| | | if (StringUtils.isNotBlank(mgtBasePlatformDto.getShopProvinceCode()) || StringUtils.isNotBlank(mgtBasePlatformDto.getShopCityCode()) || StringUtils.isNotBlank(mgtBasePlatformDto.getShopAreaCode())) { |
| | | if(shopIdList==null||shopIdList.isEmpty()){ |
| | |
| | | if(mgtBasePlatformDto.getShopId()!=null){ |
| | | shopIdList = new ArrayList<>(); |
| | | shopIdList.add(mgtBasePlatformDto.getShopId()); |
| | | } |
| | | //数据权限 |
| | | List<Long> userIds = remoteUserService.getScopeOfAuthorityUserId(); |
| | | BoardMemberTotalDto boardMemberTotalDto = new BoardMemberTotalDto(); |
| | | boardMemberTotalDto.setUserIds(userIds); |
| | | List<Shop> shopList = remoteShopService.getShopBySysUserIds(boardMemberTotalDto); |
| | | List<Long> collect = shopList.stream().map(Shop::getShopId).collect(Collectors.toList()); |
| | | if(null != shopIdList){ |
| | | shopIdList.addAll(collect); |
| | | }else{ |
| | | shopIdList = collect; |
| | | } |
| | | mgtBasePlatformDto.setShopIdList(shopIdList); |
| | | if(mgtBasePlatformDto.getAgeType()!=null){ |
| | |
| | | // 创建MerVerifyCouponVo对象 |
| | | MerVerifyCouponVo merVerifyCouponVo = new MerVerifyCouponVo(); |
| | | // 调用remoteCouponService的getVerifyCoupon方法获取MerVerifyCouponGetVo对象 |
| | | MerVerifyCouponGetVo verifyCouponGetVo = remoteCouponService.getVerifyCoupon(verifyCode).getData(); |
| | | R<MerVerifyCouponGetVo> verifyCoupon = remoteCouponService.getVerifyCoupon(Long.valueOf(verifyCode)); |
| | | if(verifyCoupon.getCode() != 200){ |
| | | throw new ServiceException(verifyCoupon.getMsg()); |
| | | } |
| | | MerVerifyCouponGetVo verifyCouponGetVo = verifyCoupon.getData(); |
| | | MemberCoupon memberCoupon = verifyCouponGetVo.getMemberCoupon(); |
| | | // 检查优惠券状态 |
| | | int couponStatus = memberCoupon.getCouponStatus(); |
| | |
| | | String userJoinedString = String.join(",", userIdSet.stream().map(Object::toString).collect(Collectors.toList())); |
| | | MgtBaseBathDto mgtBaseBathDto = new MgtBaseBathDto(); |
| | | mgtBaseBathDto.setIds(userJoinedString); |
| | | List<MgtSimpleMemberVo> simpleMemberVoList = remoteMemberService.listSimpleVoByIds(mgtBaseBathDto).getData(); |
| | | List<MgtSimpleMemberVo> simpleMemberVoList = remoteMemberService.listSimpleVoByIds(userJoinedString).getData(); |
| | | userMap = simpleMemberVoList.stream() |
| | | .collect(Collectors.toMap(MgtSimpleMemberVo::getUserId, Function.identity())); |
| | | } |
| | |
| | | try { |
| | | redissonLock.lock(30, TimeUnit.SECONDS); |
| | | Integer surpNum = redisService.getCacheObject(SecurityConstant.ACTIVITY_GOODS + "-" + order.getActivityId() + "-" + orderGoods.getGoodsId()); |
| | | if(null == surpNum){ |
| | | surpNum = 0; |
| | | } |
| | | redisService.setCacheObject(SecurityConstant.ACTIVITY_GOODS + "-" + order.getActivityId() + "-" + orderGoods.getGoodsId(), surpNum + orderGoods.getBuyNum()); |
| | | } finally { |
| | | redissonLock.unlock(); |
| | |
| | | @Override |
| | | @Transactional |
| | | @GlobalTransactional(rollbackFor = Exception.class) |
| | | public void payBack(PartnerTransactionsResult transaction) { |
| | | public void payBack(PartnerTransactionsResult transaction, BigDecimal feeAmount) { |
| | | log.info("订单支付回调---"+transaction.toString()); |
| | | // Order order = this.getById(orderId); |
| | | // 更新订单状态 outTradeNo |
| | | String outTradeNo = transaction.getOutTradeNo(); |
| | | Order order = this.getByOutTradeNo(outTradeNo); |
| | | if(order.getOrderStatus() != 1){ |
| | | return; |
| | | } |
| | | String orderId = order.getOrderId(); |
| | | order.setOrderStatus(2); |
| | | order.setPayTime(new Date()); |
| | |
| | | goodsTotalChangeDto.setChangeType(1); |
| | | goodsTotalChangeDto.setChangeNum(orderGoods.getBuyNum()); |
| | | goodsTotalChangeDto.setMoney(orderGoods.getGoodsReceivableMoney()); |
| | | Integer bugGoodsNum = orderMapper.countUserBuyGoodsNum(order.getUserId(), orderGoods.getGoodsId()); |
| | | if (bugGoodsNum == null || bugGoodsNum < 1) { |
| | | goodsTotalChangeDto.setPersonNum(1); |
| | | }else{ |
| | | goodsTotalChangeDto.setPersonNum(0); |
| | | } |
| | | Integer bugGoodsNum = orderMapper.countUserBuyGoodsNum(orderGoods.getGoodsId()); |
| | | goodsTotalChangeDto.setPersonNum(bugGoodsNum); |
| | | goodsTotalChangeDtoList.add(goodsTotalChangeDto); |
| | | } |
| | | //更新商品统计 |
| | | remoteGoodsService.changeGoodsTotal(goodsTotalChangeDtoList); |
| | | // 更新商户统计信息 |
| | | /*ShopTotalChangeDto shopTotalChangeDto = new ShopTotalChangeDto(); |
| | | shopTotalChangeDto.setShopId(order.getShopId()); |
| | | shopTotalChangeDto.setOrderType(1); |
| | | shopTotalChangeDto.setCycleMoney(cycleMoney); |
| | | shopTotalChangeDto.setServiceMoney(serviceMoney); |
| | | shopTotalChangeDto.setExperienceMoney(experienceMoney); |
| | | shopTotalChangeDto.setGoodsMoney(goodsMoney); |
| | | remoteShopService.changeShopTotal(shopTotalChangeDto);*/ |
| | | // 初始化会员统计信息 |
| | | MemberTotalChangeDto memberTotalChangeDto = new MemberTotalChangeDto(); |
| | | memberTotalChangeDto.setUserId(order.getUserId()); |
| | | // 如果存在积分兑换比例,则计算积分 |
| | | if (redisService.hasKey(SecurityConstant.PAY_MONEY_INTEGRAL)) { |
| | | Integer moneyValue = redisService.getCacheObject(SecurityConstant.PAY_MONEY_INTEGRAL); |
| | | BigDecimal moneyValueBig = BigDecimal.valueOf(moneyValue); |
| | | BigDecimal integralBig = moneyValueBig.multiply(order.getPayMoney()).setScale(0,BigDecimal.ROUND_HALF_UP); |
| | | Integer integral = Integer.valueOf(integralBig.toString()); |
| | | memberTotalChangeDto.setChangeIntegral(integral); |
| | | memberTotalChangeDto.setTypeIntegral(1); |
| | | memberTotalChangeDto.setOrderId(orderId); |
| | | memberTotalChangeDto.setOrderNo(order.getOrderNo()); |
| | | } |
| | | // 设置会员支付金额和支付时间 |
| | | memberTotalChangeDto.setPayMoney(order.getPayMoney()); |
| | | memberTotalChangeDto.setPayTime(new Date()); |
| | |
| | | activityTotalChangeDto.setChangeNum(1); |
| | | activityTotalChangeDto.setMoney(order.getPayMoney()); |
| | | Integer userActivityNum = orderMapper.countUserActivityByActivity(order.getUserId(), order.getActivityId()); |
| | | //判断用户是否下过单 如果只有当前订单则为1 |
| | | if (userActivityNum == 1) { |
| | | activityTotalChangeDto.setPersonNum(1); |
| | | } else { |
| | |
| | | profitsSharingService.applyProfitSharing(request);*/ |
| | | } |
| | | //修改支付记录生成支付记录 |
| | | orderPaymentService.updatePaySuccess(transaction.getOutTradeNo(), transaction.getTransactionId()); |
| | | orderPaymentService.updatePaySuccess(transaction.getOutTradeNo(), feeAmount, transaction.getTransactionId()); |
| | | PayRecord payRecord = new PayRecord(); |
| | | payRecord.setDelFlag(0); |
| | | payRecord.setOrderId(orderId); |
| | |
| | | try { |
| | | redissonLock.lock(30, TimeUnit.SECONDS); |
| | | Integer surpNum = redisService.getCacheObject(SecurityConstant.ACTIVITY_GOODS + "-" + order.getActivityId() + "-" + orderGoods.getGoodsId()); |
| | | if(null == surpNum){ |
| | | surpNum = 0; |
| | | } |
| | | redisService.setCacheObject(SecurityConstant.ACTIVITY_GOODS + "-" + order.getActivityId() + "-" + orderGoods.getGoodsId(), surpNum + orderGoods.getBuyNum()); |
| | | } finally { |
| | | redissonLock.unlock(); |
| | |
| | | goodsTotalChangeDto.setChangeType(2); |
| | | goodsTotalChangeDto.setChangeNum(orderGoods.getBuyNum()); |
| | | goodsTotalChangeDto.setMoney(orderGoods.getGoodsReceivableMoney()); |
| | | Integer bugGoodsNum = orderMapper.countUserBuyGoodsNum(order.getUserId(), orderGoods.getGoodsId()); |
| | | if (bugGoodsNum == null || bugGoodsNum <= orderGoods.getBuyNum()) { |
| | | goodsTotalChangeDto.setPersonNum(1); |
| | | }else{ |
| | | goodsTotalChangeDto.setPersonNum(0); |
| | | } |
| | | Integer bugGoodsNum = orderMapper.countUserBuyGoodsNum(orderGoods.getGoodsId()); |
| | | goodsTotalChangeDto.setPersonNum(bugGoodsNum); |
| | | goodsTotalChangeDtoList.add(goodsTotalChangeDto); |
| | | } |
| | | remoteGoodsService.changeGoodsTotal(goodsTotalChangeDtoList); |
| | |
| | | remoteCouponService.backMemberCoupon(memberCouponSJ.toString()); |
| | | } |
| | | } |
| | | // 更新商户统计信息 |
| | | /*ShopTotalChangeDto shopTotalChangeDto = new ShopTotalChangeDto(); |
| | | shopTotalChangeDto.setOrderType(2); |
| | | shopTotalChangeDto.setShopId(order.getShopId()); |
| | | shopTotalChangeDto.setCycleMoney(cycleMoney); |
| | | shopTotalChangeDto.setServiceMoney(serviceMoney); |
| | | shopTotalChangeDto.setExperienceMoney(experienceMoney); |
| | | shopTotalChangeDto.setGoodsMoney(goodsMoney); |
| | | remoteShopService.changeShopTotal(shopTotalChangeDto);*/ |
| | | // 初始化会员统计信息 |
| | | MemberTotalChangeDto memberTotalChangeDto = new MemberTotalChangeDto(); |
| | | memberTotalChangeDto.setUserId(order.getUserId()); |
| | | // 如果存在积分兑换比例,则计算积分 |
| | | /*if (redisService.hasKey(SecurityConstant.PAY_MONEY_INTEGRAL)) { |
| | | Integer moneyValue = redisService.getCacheObject(SecurityConstant.PAY_MONEY_INTEGRAL); |
| | | BigDecimal moneyValueBig = BigDecimal.valueOf(moneyValue); |
| | | BigDecimal integralBig = moneyValueBig.multiply(order.getPayMoney()); |
| | | Integer integral = Integer.valueOf(integralBig.toString()); |
| | | memberTotalChangeDto.setChangeIntegral(integral); |
| | | memberTotalChangeDto.setTypeIntegral(2); |
| | | }*/ |
| | | // 设置会员支付金额和支付时间 |
| | | memberTotalChangeDto.setPayMoney(order.getPayMoney().negate()); |
| | | // 根据商品存在状态,设置会员统计信息 |
| | |
| | | // 更新会员统计信息 |
| | | remoteMemberService.changeMemberTotal(memberTotalChangeDto); |
| | | // 如果订单来源于活动,则更新活动统计信息 |
| | | //TODO 可考虑改成定时任务统一查询后增加 减少服务器压力但会增加延后性 |
| | | if (order.getOrderFrom() == 2) { |
| | | ActivityTotalChangeDto activityTotalChangeDto = new ActivityTotalChangeDto(); |
| | | activityTotalChangeDto.setActivityId(order.getActivityId()); |
| | |
| | | activityTotalChangeDto.setRefundNum(1); |
| | | activityTotalChangeDto.setMoney(order.getPayMoney()); |
| | | Integer userActivityNum = orderMapper.countUserActivityByActivity(order.getUserId(), order.getActivityId()); |
| | | //判断用户是否还有活动订单 无则减少人数 |
| | | if (userActivityNum > 0) { |
| | | activityTotalChangeDto.setPersonNum(1); |
| | | } else { |
| | | activityTotalChangeDto.setPersonNum(0); |
| | | } else { |
| | | activityTotalChangeDto.setPersonNum(1); |
| | | } |
| | | activityTotalChangeDto.setUserId(order.getUserId()); |
| | | remoteActivityService.changeActivityTotal(activityTotalChangeDto); |
| | |
| | | if(BigDecimal.ZERO.compareTo(onlinePayMoney) < 0){ |
| | | log.info("订单支付金额大于0,可发起退款"); |
| | | // 订单支付金额大于0,可发起退款 |
| | | orderWxApplyRefund(orderId, refundId, onlinePayMoney, orderRefund); |
| | | // orderWxApplyRefund(orderId, refundId, onlinePayMoney, orderRefund); |
| | | // 订单支付金额大于0,可发起退款 todo 修改渠道(汇付天下) |
| | | orderWxApplyRefund1(orderId, refundId, onlinePayMoney, orderRefund); |
| | | } |
| | | |
| | | orderRefund.setRefundStatus(1); |
| | |
| | | paymentMessageService.savePaymentMessage("3", orderId, refundRequestJson, refundResponseJson); |
| | | |
| | | } catch (WxPayException e) { |
| | | throw new ServiceException(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 申请退款API |
| | | */ |
| | | private void orderWxApplyRefund1(String orderId, String outRefundNo, BigDecimal payMoney, OrderRefund orderRefund){ |
| | | try { |
| | | // 创建支付订单 |
| | | OrderPayment orderPayment = orderPaymentService.getByOrderId(orderId); |
| | | if (null == orderPayment) { |
| | | return; |
| | | } |
| | | |
| | | log.info("调用微信退款---发起退款"); |
| | | |
| | | String subMchId = orderPayment.getSubMchId(); |
| | | // WxPayConfig config = wxService.getConfig(); |
| | | |
| | | RefundsRequest request = new RefundsRequest(); |
| | | // request.setSpAppid(config.getAppId()); |
| | | request.setSubMchid(subMchId); |
| | | request.setTransactionId(orderPayment.getTransactionId()); |
| | | request.setOutRefundNo(outRefundNo); |
| | | request.setReason("用户取消订单"); |
| | | // 订单金额 |
| | | int total = orderPayment.getPayMoney().multiply(new BigDecimal(100)).intValue(); |
| | | |
| | | RefundsRequest.Amount amount = RefundsRequest.Amount.builder().refund(total).total(total).currency("CNY").build(); |
| | | request.setAmount(amount); |
| | | request.setNotifyUrl(callbackPath + "/order/app/notify/wechatPaymentRefundCallback"); |
| | | |
| | | // RefundsResult result = wxService.getEcommerceService().refunds(request); |
| | | |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); |
| | | String org_req_date = sdf.format(orderPayment.getCreateTime()); |
| | | String outTradeNo = orderPayment.getOutTradeNo(); |
| | | R<String> r = HuiFuTianXiaUtil.weixinPaymentRefund(outRefundNo, orderPayment.getPayMoney().doubleValue(), org_req_date, outTradeNo, request.getNotifyUrl()); |
| | | if(r.getCode() != 200){ |
| | | throw new ServiceException(r.getMsg()); |
| | | } |
| | | |
| | | // 微信退款id |
| | | orderRefund.setWxRefundId(r.getData()); |
| | | |
| | | // 请求参数 |
| | | Gson gson = new Gson(); |
| | | String refundRequestJson = gson.toJson(request); |
| | | // 返回参数 |
| | | // String refundResponseJson = gson.toJson(result); |
| | | |
| | | // log.info("调用微信退款返回参数---{}", refundResponseJson); |
| | | |
| | | // 保存支付订单统一下单日志 |
| | | // paymentMessageService.savePaymentMessage("3", orderId, refundRequestJson, refundResponseJson); |
| | | |
| | | } catch (Exception e) { |
| | | throw new ServiceException(e.getMessage()); |
| | | } |
| | | } |
| | |
| | | try { |
| | | redissonLock.lock(30, TimeUnit.SECONDS); |
| | | Integer surpNum = redisService.getCacheObject(SecurityConstant.ACTIVITY_GOODS + "-" + order.getActivityId() + "-" + orderGoods.getGoodsId()); |
| | | if(null == surpNum){ |
| | | surpNum = 0; |
| | | } |
| | | redisService.setCacheObject(SecurityConstant.ACTIVITY_GOODS + "-" + order.getActivityId() + "-" + orderGoods.getGoodsId(), surpNum + orderGoods.getBuyNum()); |
| | | } finally { |
| | | redissonLock.unlock(); |
| | |
| | | */ |
| | | @Override |
| | | public List<MerOrderPageVo> pageMerMemberPayOrder(Page page,MerMemberNoClearOrderDto merOrderPageDto){ |
| | | // 获取订单列表 |
| | | List<MerOrderPageVo> merOrderPageVoList = orderMapper.pageMerMemberPayOrder(page, merOrderPageDto); |
| | | // 如果订单列表不为空 |
| | | if (merOrderPageVoList != null && !merOrderPageVoList.isEmpty()) { |
| | | Long userId; |
| | | BigDecimal zeroBig = new BigDecimal("0.00"); |
| | | StringJoiner userIdSj = new StringJoiner(","); |
| | | // 遍历订单列表 |
| | | for (MerOrderPageVo merOrderPageVo : merOrderPageVoList) { |
| | | userId = merOrderPageVo.getUserId(); |
| | | userIdSj.add(userId.toString()); |
| | | if(merOrderPageVo.getUnPaidMoney().compareTo(zeroBig)<0){ |
| | | // 如果未支付金额小于零,则设置为零 |
| | | if (merOrderPageVo.getUnPaidMoney().compareTo(zeroBig) < 0) { |
| | | merOrderPageVo.setUnPaidMoney(zeroBig); |
| | | } |
| | | } |
| | | // 获取用户列表 |
| | | MgtBaseBathDto mgtBaseBathDto = new MgtBaseBathDto(); |
| | | mgtBaseBathDto.setIds(userIdSj.toString()); |
| | | List<MgtSimpleMemberVo> simpleMemberVoList = remoteMemberService.listSimpleVoByIds(mgtBaseBathDto).getData(); |
| | | List<MgtSimpleMemberVo> simpleMemberVoList = remoteMemberService.listSimpleVoByIds(userIdSj.toString()).getData(); |
| | | // 将用户列表转换为Map,以便根据用户ID快速查找用户信息 |
| | | Map<Long, MgtSimpleMemberVo> userMap = simpleMemberVoList.stream() |
| | | .collect(Collectors.toMap(MgtSimpleMemberVo::getUserId, Function.identity())); |
| | | // 遍历订单列表 |
| | | for (MerOrderPageVo merOrderPageVo : merOrderPageVoList) { |
| | | if(merOrderPageVo.getUserId()!=null&&userMap.get(merOrderPageVo.getUserId())!=null){ |
| | | // 如果订单的用户ID不为空,并且用户Map中存在对应的用户信息 |
| | | if (merOrderPageVo.getUserId() != null && userMap.get(merOrderPageVo.getUserId()) != null) { |
| | | // 设置订单的用户名、昵称和手机号 |
| | | merOrderPageVo.setUserName(userMap.get(merOrderPageVo.getUserId()).getRealName()); |
| | | merOrderPageVo.setNickName(userMap.get(merOrderPageVo.getUserId()).getNickName()); |
| | | merOrderPageVo.setUserMobile(userMap.get(merOrderPageVo.getUserId()).getUserMobile()); |
| | | }else{ |
| | | log.debug("订单merOrderPageVo"+merOrderPageVo.getOrderId()+"缺少用户"); |
| | | } else { |
| | | log.debug("订单merOrderPageVo" + merOrderPageVo.getOrderId() + "缺少用户"); |
| | | } |
| | | } |
| | | } |
| | |
| | | public ProfitSharingResult queryBill(String orderId) throws WxPayException { |
| | | OrderPayment orderPayment = orderPaymentService.getByOrderId(orderId); |
| | | ProfitSharing profitSharing = profitSharingService.getByOrderId(orderId); |
| | | |
| | | ProfitSharingQueryRequest request = new ProfitSharingQueryRequest(); |
| | | request.setSubMchid("1650744551"); |
| | | request.setTransactionId(orderPayment.getTransactionId()); |
| | |
| | | ProfitSharingResult profitSharingResult = wxService.getEcommerceService().queryProfitSharing(request); |
| | | return profitSharingResult; |
| | | } |
| | | |
| | | @Override |
| | | public List<String> getActivityOrderGoods(String activityId) { |
| | | List<Order> orders = this.baseMapper.selectList(new QueryWrapper<Order>() |
| | | .eq("del_flag", 0) |
| | | .in("order_status", Arrays.asList(1, 2, 3)) |
| | | .eq("activity_id", activityId) |
| | | ); |
| | | if(orders.size() > 0){ |
| | | List<String> collect = orders.stream().map(Order::getOrderId).collect(Collectors.toList()); |
| | | List<OrderGoods> list = orderGoodsService.list(new QueryWrapper<OrderGoods>() |
| | | .eq("del_flag", 0) |
| | | .in("order_id", collect) |
| | | ); |
| | | return list.stream().map(OrderGoods::getGoodsId).collect(Collectors.toList()); |
| | | } |
| | | return new ArrayList<>(); |
| | | } |
| | | } |