From a1a6e227628810259fcba0fff146792e97a80b8a Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期一, 15 十二月 2025 08:56:09 +0800
Subject: [PATCH] 订单业务开发

---
 server/dmmall_service/src/main/java/com/doumee/service/business/impl/GoodsorderServiceImpl.java |  367 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 357 insertions(+), 10 deletions(-)

diff --git a/server/dmmall_service/src/main/java/com/doumee/service/business/impl/GoodsorderServiceImpl.java b/server/dmmall_service/src/main/java/com/doumee/service/business/impl/GoodsorderServiceImpl.java
index ea26131..46ce98d 100644
--- a/server/dmmall_service/src/main/java/com/doumee/service/business/impl/GoodsorderServiceImpl.java
+++ b/server/dmmall_service/src/main/java/com/doumee/service/business/impl/GoodsorderServiceImpl.java
@@ -8,10 +8,7 @@
 import com.doumee.core.model.LoginUserInfo;
 import com.doumee.core.model.PageData;
 import com.doumee.core.model.PageWrap;
-import com.doumee.core.utils.Constants;
-import com.doumee.core.utils.DateUtil;
-import com.doumee.core.utils.RedisUtil;
-import com.doumee.core.utils.Utils;
+import com.doumee.core.utils.*;
 import com.doumee.core.utils.kuaidi100.DeliveryDTO;
 import com.doumee.core.utils.kuaidi100.ExpressUtils;
 import com.doumee.core.wx.SendWxMessage;
@@ -22,17 +19,17 @@
 import com.doumee.dao.business.join.GoodsorderJoinMapper;
 import com.doumee.dao.business.join.PlanorderDetailJoinMapper;
 import com.doumee.dao.business.model.*;
+import com.doumee.dao.web.dto.CouponDTO;
 import com.doumee.dao.web.request.DealIntegralRequest;
 import com.doumee.dao.web.request.OrderPayRequest;
 import com.doumee.dao.web.request.PayDetailRequest;
+import com.doumee.dao.web.request.ShopOrderPayRequest;
 import com.doumee.dao.web.request.goods.MemberOrderRequest;
 import com.doumee.dao.web.request.goods.DealOrderRequest;
 import com.doumee.dao.web.request.goods.OrderCommentRequest;
 import com.doumee.dao.web.request.goods.OrderGoodsCommentRequest;
 import com.doumee.dao.web.response.MyPageResponse;
-import com.doumee.dao.web.response.goods.MemberOrderDetailResponse;
-import com.doumee.dao.web.response.goods.MemberOrderResponse;
-import com.doumee.dao.web.response.goods.PayResponse;
+import com.doumee.dao.web.response.goods.*;
 import com.doumee.service.business.AreasService;
 import com.doumee.service.business.GoodsorderService;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -44,15 +41,16 @@
 import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
 import com.github.binarywang.wxpay.bean.result.WxPayRefundResult;
 import com.github.binarywang.wxpay.exception.WxPayException;
+import com.github.xiaoymin.knife4j.core.util.CollectionUtils;
 import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.shiro.SecurityUtils;
 import org.checkerframework.checker.units.qual.C;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.CollectionUtils;
 import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
 
@@ -61,6 +59,8 @@
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.*;
+import java.util.Date;
+import java.util.stream.Collectors;
 
 /**
  * 鍟嗗搧璁㈠崟淇℃伅琛⊿ervice瀹炵幇
@@ -93,6 +93,9 @@
 
     @Autowired
     private AddrMapper addrMapper;
+
+    @Autowired
+    private ShopMapper shopMapper;
 
     @Autowired
     private MemberCouponMapper memberCouponMapper;
@@ -129,6 +132,9 @@
 
     @Autowired
     private GoodsorderDetailJoinMapper goodsorderDetailJoinMapper;
+
+    @Autowired
+    private IntegralMapper integralMapper;
 
     @Override
     public Integer create(Goodsorder goodsorder) {
@@ -179,6 +185,29 @@
         goodsorder.setEditor(user.getId());
         goodsorderMapper.updateById(goodsorder);
     }
+
+    @Override
+    public IPage<Shop> getShopPage(PageWrap<Shop> pageWrap) {
+        IPage<Shop> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
+        Shop model = pageWrap.getModel();
+        if(Objects.isNull(model.getLatitude())||Objects.isNull(model.getLongitude())){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST);
+        }
+        return shopMapper.selectPage(page,new MPJLambdaWrapper<Shop>()
+                        .selectAll(Shop.class)
+                .select(" case when LONGITUDE IS NULL OR LATITUDE IS NULL THEN 0 " +
+                        " when t.TYPE = 0 then CONVERT( ST_Distance_Sphere ( POINT ( LONGITUDE, LATITUDE ), POINT ( "+model.getLongitude()+", "+model.getLatitude()+" )) /1000,DECIMAL(15,2))  " +
+                        " when t.TYPE = 1 then   CONVERT( ST_Distance_Sphere ( POINT ( LONGITUDE, LATITUDE ), POINT ( "+model.getLongitude()+", "+model.getLatitude()+" )) /1000,DECIMAL(15,2)) " +
+                        " else  CONVERT( ST_Distance_Sphere ( POINT ( LONGITUDE, LATITUDE ), POINT ( "+model.getLongitude()+", "+model.getLatitude()+" )) /1000,DECIMAL(15,2)) end " , Shop::getDistance)
+                        .eq(Shop::getIsdeleted,Constants.ZERO)
+                        .eq(Shop::getStatus,Constants.ZERO)
+                        .like(StringUtils.isNotBlank(model.getAddr()),Shop::getAddr,model.getAddr())
+                        .like(StringUtils.isNotBlank(model.getName()),Shop::getName,model.getName())
+                .orderByAsc(" distance ")
+        );
+    }
+
+
     /**
      * 鍜栬眴 鍟嗗煄璁㈠崟鍙戣揣
      * @param goodsorder
@@ -614,7 +643,7 @@
         goodsorderMapper.insert(goodsorder);
         //鏁版嵁瀛樺偍
         BigDecimal total = Constants.formatBigdecimal(goodsorder.getPrice()).add(Constants.formatBigdecimal(goodsorder.getIntegral())).add(Constants.formatBigdecimal(goodsorder.getCouponPrice()));
-        BigDecimal rate =Constants.formatBigdecimal(goodsorder.getCouponPrice()) .divide(total,4,BigDecimal.ROUND_HALF_UP);
+        BigDecimal rate =Constants.formatBigdecimal(goodsorder.getCouponPrice()).divide(total,4,BigDecimal.ROUND_HALF_UP);
         BigDecimal totalWxMoney = new BigDecimal(0);
         BigDecimal totalIntegral = new BigDecimal(0);
         for (int i =0;i< goodsOrderDetailList.size();i++) {
@@ -630,7 +659,7 @@
                 //褰撳墠鏄庣粏瀹為檯浠锋牸
                 BigDecimal detialTotal = Constants.formatBigdecimal(goodsOrderDetail.getPrice()).multiply(new BigDecimal(Constants.formatIntegerNum(goodsOrderDetail.getGoodsNum())));
                 //鎶樼畻浼樻儬鍒稿悗鏀粯浠锋牸锛堝寘鍚幇閲戝拰浣欓閮ㄥ垎锛�
-                BigDecimal  actDetialTotal = detialTotal .subtract(detialTotal.multiply(rate));
+                BigDecimal  actDetialTotal = detialTotal.subtract(detialTotal.multiply(rate));
                 //鎸夌幇閲戝拰绉垎鏀粯姣斾緥锛屾姌绠楁瘡涓槑缁嗙幇閲戝拰绉垎鏀粯鐨勬暟閲�
                 BigDecimal rate1 = detialTotal .divide(total,4,BigDecimal.ROUND_HALF_UP);
                 //鍙��鐜伴噾閲戦
@@ -676,6 +705,147 @@
         if(goodsorder.getPrice().compareTo(orderPayRequest.getTitlePrice())!=Constants.ZERO){
             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鍟嗗搧浠锋牸鍙戠敓鍙樺寲锛岃鍒锋柊鍚庨噸鏂版敮浠橈紒");
         }
+        return this.wxPay(goodsorder,member);
+    }
+
+
+
+    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
+    public PayResponse orderPay(ShopOrderPayRequest orderPayRequest,MemberCouponServiceImpl memberCouponService){
+        Member member = memberMapper.selectById(orderPayRequest.getMemberId());
+
+        Goodsorder goodsorder = new Goodsorder();
+        goodsorder.setCreator(orderPayRequest.getMemberId());
+        goodsorder.setIntegral(BigDecimal.ZERO);
+        goodsorder.setCreateDate(new Date());
+        goodsorder.setIsdeleted(Constants.ZERO);
+        goodsorder.setMemberInfo(orderPayRequest.getRemark());
+        goodsorder.setMemberId(member.getId());
+        goodsorder.setType(Constants.ZERO);
+        goodsorder.setStatus(Constants.ZERO);
+
+        if(Constants.equalsInteger(orderPayRequest.getReceiveType(),Constants.ZERO)){
+            //鏌ヨ鏀惰揣鍦板潃
+            Addr addr = addrMapper.selectById(orderPayRequest.getAddressId());
+            if(Objects.isNull(addr)){
+                throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌鏀惰揣鍦板潃淇℃伅锛�");
+            }
+            Areas area = areasService.findById(addr.getAreaId(), Constants.TWO);
+            if(Objects.isNull(area)){
+                throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏀惰揣鍦板潃鍖哄垝淇℃伅鍙戠敓鍙樺寲锛岃鏇存柊鍚庝笅鍗曪紒");
+            }
+
+            goodsorder.setAddrId(addr.getId());
+            goodsorder.setLinkaddr(area.getProvinceName()+area.getCityName() + area.getName() + addr.getAddr());
+            goodsorder.setLinkphone(addr.getPhone());
+            goodsorder.setLinkname(addr.getName());
+            if(Objects.nonNull(member.getBindShopId())){
+                goodsorder.setDistributionShopId(member.getBindShopId());
+            }
+        }else{
+            if(Objects.isNull(orderPayRequest.getShopId())){
+                throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"璇烽�夋嫨姝g‘鐨勮嚜鎻愰棬搴楋紒");
+            }
+            Shop shop = shopMapper.selectById(orderPayRequest.getShopId());
+            if(Objects.isNull(shop)){
+                throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"璇烽�夋嫨姝g‘鐨勮嚜鎻愰棬搴楋紒");
+            }
+            goodsorder.setPickUpShopId(shop.getId());
+            goodsorder.setDistributionShopId(shop.getId());
+            if(Objects.isNull(member.getBindShopId())){
+                member.setBindShopId(shop.getId());
+            }
+        }
+        //鍗曟嵁缂栧彿 鑷
+        goodsorder.setCode(getNextInCode());
+        //璁$畻璁㈠崟鎬婚噾棰�
+        BigDecimal sumPrice = BigDecimal.ZERO;
+
+        //瀛樺偍璁板綍鏄庣粏
+        OrderPayConfirmResponse orderPayConfirmResponse = this.orderPayConfirm(orderPayRequest.getReceiveType(),orderPayRequest.getPayDetailRequestList(),orderPayRequest.getAddressId(),memberCouponService,member.getId());
+        if(Objects.isNull(orderPayConfirmResponse)){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"绯荤粺鏀粯閿欒,璇疯仈绯荤鐞嗗憳");
+        }
+        goodsorder.setPrice(orderPayConfirmResponse.getPayAmount());
+        goodsorder.setTotalPrice(orderPayConfirmResponse.getAmount());
+        goodsorder.setUseIntegral(orderPayConfirmResponse.getDeductIntegral());
+        goodsorder.setIntegralPrice(orderPayConfirmResponse.getIntegralAmount());
+
+        if(Objects.nonNull(orderPayConfirmResponse.getMemberCoupon())){
+            MemberCoupon memberCoupon = memberCouponMapper.selectById(orderPayConfirmResponse.getMemberCoupon().getId());
+            if(Objects.isNull(memberCoupon)){
+                throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌浼樻儬鍒镐俊鎭紒");
+            }
+            if(memberCoupon.getStatus().equals(Constants.ONE)){
+                throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"浼樻儬鍒稿凡浣跨敤锛�");
+            }
+            sumPrice = sumPrice.subtract(memberCoupon.getPrice());
+            goodsorder.setCouponId(memberCoupon.getId());
+            goodsorder.setCouponPrice(orderPayConfirmResponse.getMemberCoupon().getValidAmount());
+
+            memberCouponMapper.update(null,new UpdateWrapper<MemberCoupon>().lambda()
+                    .set(MemberCoupon::getStatus,Constants.ONE)
+                    .set(MemberCoupon::getUseDate,DateUtil.getCurrDateTime())
+                    .eq(MemberCoupon::getId,memberCoupon.getId())
+            );
+        }
+
+        goodsorderMapper.insert(goodsorder);
+        List<OrderGoodsCalculateResponse> goodsCalculateList  = orderPayConfirmResponse.getGoodsCalculateList();
+        if(CollectionUtils.isEmpty(goodsCalculateList)){
+            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏃犳槑缁嗘暟鎹�,璇锋鏌ラ�夋嫨鏁版嵁锛�");
+        }
+        List<GoodsorderDetail> goodsOrderDetailList = new ArrayList<>();
+        for (OrderGoodsCalculateResponse payDetailRequest:goodsCalculateList) {
+            //鏌ヨ鍟嗗搧
+            GoodsSku goodsSku = goodsSkuMapper.selectById(payDetailRequest.getSkuId());
+            if(Objects.isNull(goodsSku)){
+                throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌鍟嗗搧SKU淇℃伅锛�");
+            }
+            Goods goods = goodsMapper.selectById(goodsSku.getGoodsId());
+            if(Objects.isNull(goods)){
+                throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌鍟嗗搧淇℃伅锛�");
+            }
+            if(goods.getStatus().equals(Constants.ONE)){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瀛樺湪鍟嗗搧宸插垹闄ゆ垨宸蹭笅鏋讹紝鏃犳硶涓嬪崟");
+            }
+            if(goodsSku.getStock().compareTo(new BigDecimal(Constants.formatIntegerNum(payDetailRequest.getGoodsNum())))<Constants.ZERO){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瀛樺湪鍟嗗搧搴撳瓨涓嶈冻锛屾棤娉曚笅鍗曪紒");
+            }
+            //鍟嗗搧搴撳瓨鎵i櫎
+            goodsSku.setStock(goodsSku.getStock().subtract(new BigDecimal(Constants.formatIntegerNum(payDetailRequest.getGoodsNum()))));
+            goodsSkuMapper.updateById(goodsSku);
+            GoodsorderDetail goodsOrderDetail = new GoodsorderDetail();
+            goodsOrderDetail.setCreator(member.getId());
+            goodsOrderDetail.setCreateDate(new Date());
+            goodsOrderDetail.setImgurl(StringUtils.isBlank(goodsSku.getImgurl())?goods.getImgurl():goodsSku.getImgurl());
+            goodsOrderDetail.setName(goods.getName());
+            goodsOrderDetail.setGoodsSkuId(goodsSku.getId().toString());
+            goodsOrderDetail.setSkuName(goodsSku.getName());
+            goodsOrderDetail.setPrice(goodsSku.getPrice());
+            goodsOrderDetail.setGoodsNum(payDetailRequest.getGoodsNum());
+            goodsOrderDetail.setGoodsWeight(payDetailRequest.getWeight());
+            goodsOrderDetail.setCouponDeduct(payDetailRequest.getCouponDeductCash());
+            goodsOrderDetail.setIntegralDeduct(payDetailRequest.getIntegralDeductCash());
+            goodsOrderDetail.setOrderId(goodsorder.getId());
+            goodsOrderDetailList.add(goodsOrderDetail);
+            //鍒犻櫎璐墿杞﹀晢鍝�
+            shopcartMapper.delete(new QueryWrapper<Shopcart>().lambda()
+                    .eq(Shopcart::getMemberId,member.getId())
+                    .eq(Shopcart::getGoodsSkuId,goodsOrderDetail.getGoodsSkuId())
+            );
+        }
+        //绉垎鍙樺姩璁板綍
+        Integral integral =Integral.createIntegral(member.getId(),Constants.INTEGRAL_TYPE.ORDER_PAY,goodsorder.getId());
+        integral.setNum(goodsorder.getUseIntegral());
+        integral.setTotalNum(member.getIntegral().subtract(goodsorder.getUseIntegral()));
+        integralMapper.insert(integral);
+        //鏇存柊鐢ㄦ埛绉垎
+        memberMapper.subtractIntegral(member.getId(),goodsorder.getUseIntegral());
+        if(goodsorder.getPrice().compareTo(orderPayRequest.getTitlePrice())!=Constants.ZERO){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鍟嗗搧浠锋牸鍙戠敓鍙樺寲锛岃鍒锋柊鍚庨噸鏂版敮浠橈紒");
+        }
+
         return this.wxPay(goodsorder,member);
     }
 
@@ -898,6 +1068,182 @@
             }
         }
     }
+
+    public BigDecimal getDeductAmount(List<PayDetailRequest> requestList){
+        List<MemberCoupon> memberCouponList = new ArrayList<>();
+
+        List<GoodsSku> goodsSkuList = goodsSkuMapper.selectList(new QueryWrapper<GoodsSku>()
+                .lambda()
+                .eq(GoodsSku::getIsdeleted,Constants.ZERO)
+                .in(GoodsSku::getId,requestList.stream().map(i->i.getGoodsSkuId()).collect(Collectors.toList()))
+        );
+        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(goodsSkuList)||!Constants.equalsInteger(goodsSkuList.size(),requestList.size())){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鍟嗗搧SKU淇℃伅閿欒,璇峰埛鏂伴噸璇�");
+        }
+
+        //鏌ヨ鍟嗗搧鍒楄〃
+        List<Goods> goodsList = goodsMapper.selectJoinList(Goods.class,
+                new MPJLambdaWrapper<Goods>()
+                        .selectAs(GoodsSku::getPrice,Goods::getSkuPrice)
+                        .selectAs(GoodsSku::getId,Goods::getSkuId)
+                        .leftJoin(GoodsSku.class,GoodsSku::getGoodsId,Goods::getId)
+                        .in(GoodsSku::getId,requestList.stream().map(i->i.getGoodsSkuId()).collect(Collectors.toList())));
+        if(Objects.isNull(goodsList)){
+            return BigDecimal.ZERO;
+        }
+        //鑾峰彇閫夋嫨鐨勫晢鍝佹�婚噾棰� 涓� 鍗曚釜鍟嗗搧閲戦
+        BigDecimal deductAmount = BigDecimal.ZERO;
+        for (Goods goods:goodsList) {
+            List<PayDetailRequest> request = requestList.stream().filter(i->Constants.equalsInteger(i.getGoodsSkuId(), goods.getSkuId())).collect(Collectors.toList());
+            if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(request)){
+                goods.setSkuAmount(goods.getSkuPrice().multiply(new BigDecimal(request.get(Constants.ZERO).getGoodsNum()+"")));
+                deductAmount = deductAmount.add(goods.getSkuAmount().multiply(goods.getDeductRata()));
+            }
+        }
+        return deductAmount;
+    }
+
+
+    /**
+     * 璁㈠崟纭鎺ュ彛
+     * @param receiveType 0=蹇�掗厤閫� 1=鑷彁
+     * @param requestList
+     * @param addressId
+     * @param memberCouponService
+     * @param memberId
+     */
+    public OrderPayConfirmResponse orderPayConfirm(Integer receiveType,List<PayDetailRequest> requestList,Integer addressId,
+                                MemberCouponServiceImpl memberCouponService,Integer memberId){
+        OrderPayConfirmResponse orderPayConfirmResponse = new OrderPayConfirmResponse();
+        List<Goods> goodsList = goodsMapper.selectJoinList(Goods.class,
+                new MPJLambdaWrapper<Goods>()
+                        .selectAs(GoodsSku::getPrice,Goods::getSkuPrice)
+                        .selectAs(GoodsSku::getId,Goods::getSkuId)
+                        .selectAs(GoodsSku::getIntegralRate,Goods::getDeductRata)
+                        .selectAs(GoodsSku::getWeight,Goods::getWeight)
+                        .selectAs(GoodsSku::getImgurl,Goods::getSkuImg)
+                        .leftJoin(GoodsSku.class,GoodsSku::getGoodsId,Goods::getId)
+                        .in(GoodsSku::getId,requestList.stream().map(i->i.getGoodsSkuId()).collect(Collectors.toList())));
+        if(CollectionUtils.isEmpty(goodsList)){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鏈尮閰嶅埌鍟嗗搧淇℃伅");
+        }
+
+        List<OrderGoodsCalculateResponse> goodsCalculateList = ListUtil.copyProperties(goodsList,OrderGoodsCalculateResponse::new);
+
+        //璁㈠崟鎬婚噾棰�
+        BigDecimal amount = BigDecimal.ZERO;
+        //浼樻儬鍒告姷鎵i噾棰�
+        BigDecimal couponAmount = BigDecimal.ZERO;
+        //绉垎鎶垫墸閲戦
+        BigDecimal integralAmount = BigDecimal.ZERO;
+        //鎶垫墸绉垎鍊�
+        BigDecimal deductIntegral = BigDecimal.ZERO;
+        //閭垂閲戦
+        BigDecimal mailAmount = BigDecimal.ZERO;
+        for (OrderGoodsCalculateResponse response:goodsCalculateList) {
+            List<PayDetailRequest> request = requestList.stream().filter(i->Constants.equalsInteger(i.getGoodsSkuId(), response.getSkuId())).collect(Collectors.toList());
+            if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(request)){
+                PayDetailRequest payDetailRequest = request.get(Constants.ZERO);
+                response.setSkuAmount(response.getSkuPrice().multiply(new BigDecimal(payDetailRequest.getGoodsNum()+"")));
+                response.setGoodsNum(payDetailRequest.getGoodsNum());
+                amount = amount.add(response.getSkuAmount());
+            }
+        }
+        //鑾峰彇浼樻儬鍒镐紭鎯犻噾棰�
+        List<MemberCoupon> memberCouponList = memberCouponService.getApplyCoupon(requestList,memberId);
+        MemberCoupon memberCoupon = new MemberCoupon();
+        if(CollectionUtils.isNotEmpty(memberCouponList)){
+            memberCoupon = memberCouponList.get(Constants.ZERO);
+            couponAmount = memberCoupon.getValidAmount();
+            memberCouponService.calculateCouponRata(memberCoupon,goodsCalculateList,amount);
+            orderPayConfirmResponse.setMemberCoupon(memberCoupon);
+        }
+        //绉垎鎶垫墸閲戦
+        //鏌ヨ鐢ㄦ埛鎬荤Н鍒�
+        Member member = memberMapper.selectById(memberId);
+        //绉垎澶т簬0 涓斿ぇ浜庡彲鐢ㄧН鍒嗛厤缃」 鎵嶅彲浠ヤ娇鐢�
+        if(member.getIntegral().compareTo(BigDecimal.ZERO)>Constants.ZERO){
+            //鏈�浣庡彲鐢ㄥ惎鐢ㄧН鍒�
+            BigDecimal minimumIntegral = new BigDecimal(systemDictDataBiz.queryByCode(Constants.SHOP_CONFIG,Constants.MINIMUM_AVAILABLE_INTEGRAL).getCode());
+            if(member.getIntegral().compareTo(minimumIntegral)>=Constants.ZERO){
+                this.calculateIntegralRata(goodsCalculateList,member.getIntegral());
+            }
+        }
+        //閭垂閲戦
+        if(Constants.equalsInteger(receiveType,Constants.ZERO)){
+            //TODO  鏍规嵁鏀惰揣鍦板潃 鏌ヨ杩愯垂閰嶇疆
+
+            //璁$畻鍟嗗搧淇℃伅鎬婚噸閲�
+            BigDecimal totalWeight = goodsCalculateList.stream().map(i->
+                    i.getWeight().multiply(new BigDecimal(i.getGoodsNum().toString()))
+                    ).reduce(BigDecimal.ZERO,BigDecimal::add);
+            
+        }
+
+        orderPayConfirmResponse.setAmount(amount);
+        orderPayConfirmResponse.setCouponAmount(couponAmount);
+        orderPayConfirmResponse.setDeductIntegral(deductIntegral);
+        orderPayConfirmResponse.setMailAmount(mailAmount);
+        orderPayConfirmResponse.setIntegralAmount(integralAmount);
+        orderPayConfirmResponse.setPayAmount(amount.subtract(couponAmount).subtract(mailAmount).subtract(integralAmount));
+        orderPayConfirmResponse.setGoodsCalculateList(goodsCalculateList);
+        BigDecimal cashToIntegralRata = new BigDecimal(systemDictDataBiz.queryByCode(Constants.SHOP_CONFIG,Constants.CASH_EXCHANGE_INTEGRAL_RATA).getCode());
+        orderPayConfirmResponse.setIntegralBack(
+                orderPayConfirmResponse.getPayAmount().multiply(cashToIntegralRata)
+        );
+
+        return orderPayConfirmResponse;
+    }
+
+    /**
+     *
+     * @param goodsCalculateList 鍟嗗搧闆嗗悎
+     * @param totalIntegral 鐢ㄦ埛鎬荤Н鍒�
+     */
+    public void  calculateIntegralRata(List<OrderGoodsCalculateResponse> goodsCalculateList,BigDecimal totalIntegral){
+        //褰撳墠閫夋嫨鍟嗗搧鏈�澶у彲鐢ㄧН鍒嗘姷鎵g殑閲戦
+        BigDecimal maxDeductionCash =  goodsCalculateList.stream().map(i->i.getSkuAmount().subtract(i.getCouponDeductCash())
+                .multiply(i.getDeductRata())).reduce(BigDecimal.ZERO,BigDecimal::add);
+        //绉垎 - 鐜伴噾 姣斾緥
+        BigDecimal cashToIntegralRata = new BigDecimal(systemDictDataBiz.queryByCode(Constants.SHOP_CONFIG,Constants.INTEGRAL_EXCHANGE_CASH_RATA).getCode());
+        //褰撳墠閫夋嫨鍟嗗搧鎶垫墸闇�瑕佷娇鐢ㄧ殑绉垎
+        BigDecimal maxDeductionIntegral =  maxDeductionCash.multiply(cashToIntegralRata).multiply(new BigDecimal("100"));
+        BigDecimal deductionRata = BigDecimal.ONE;
+        //濡傛灉瀹為檯绉垎灏戜簬鏈�澶ч渶瑕佺Н鍒� 闇�瑕佽绠楁瘮渚嬪崰姣� 鍘诲搴旀坊鍔犺嚦瀵瑰簲鐨勫晢鍝侀噷
+        if(totalIntegral.compareTo(maxDeductionIntegral)<=Constants.ZERO) {
+            deductionRata = totalIntegral.divide(maxDeductionIntegral, 2, BigDecimal.ROUND_HALF_UP);
+        }
+        //鑾峰彇鎬荤殑鎶垫墸閲戦 涓� 姣忎釜鍟嗗搧鍙姷鎵i噾棰�
+        //宸茬敤鍗犳瘮姣斾緥鍊�
+        BigDecimal rata = BigDecimal.ZERO;
+        //鍓╀綑鍙垎閰嶉噾棰�
+        BigDecimal surplusValidAmount = maxDeductionCash;
+        for (int j = 0; j < goodsCalculateList.size(); j++) {
+            if(Constants.equalsInteger(j+1,goodsCalculateList.size())){
+                goodsCalculateList.get(j).setIntegralMaxDeductCash(surplusValidAmount);
+                goodsCalculateList.get(j).setOrderIntegralRata(new BigDecimal("1").subtract(rata));
+            }else{
+                //绉垎鏈�澶у彲鎶垫墸閲戦
+                goodsCalculateList.get(j).setIntegralMaxDeductCash(
+                        goodsCalculateList.get(j).getSkuAmount()
+                                .subtract(goodsCalculateList.get(j).getCouponDeductCash())
+                                .multiply(goodsCalculateList.get(j).getDeductRata()));
+                //璁㈠崟涓Н鍒嗛噾棰濆疄闄呭崰姣�
+                goodsCalculateList.get(j).setOrderIntegralRata(
+                                goodsCalculateList.get(j)
+                                        .getIntegralMaxDeductCash().divide(maxDeductionCash,2,BigDecimal.ROUND_DOWN)
+                        );
+                rata = rata.add(goodsCalculateList.get(j).getOrderIntegralRata());
+                surplusValidAmount = surplusValidAmount.subtract(goodsCalculateList.get(j).getIntegralMaxDeductCash());
+            }
+            //濡傛灉鐢ㄦ埛绉垎澶т簬鏈闇�瑕佷娇鐢ㄧ殑鏈�澶хН鍒� 鍒欑洿鎺ヤ娇鐢ㄥ惁鍒欓渶瑕侀噸鏂拌绠�
+            goodsCalculateList.get(j).setIntegralDeductCash(goodsCalculateList.get(j).getIntegralMaxDeductCash().multiply(deductionRata));
+            goodsCalculateList.get(j).setIntegralDeduct(goodsCalculateList.get(j).getIntegralMaxDeductCash().multiply(cashToIntegralRata).multiply(deductionRata));
+        }
+
+    }
+
+
 
 
     /**
@@ -1175,4 +1521,5 @@
     }
 
 
+
 }

--
Gitblit v1.9.3