licailing 5 лет назад
Родитель
Сommit
fea627b720

+ 4 - 1
src/main/java/com/izouma/dingdong/domain/OrderRefundApply.java

@@ -83,7 +83,10 @@ public class OrderRefundApply extends BaseEntity {
     //private Long feeId;
 
 
-    @ApiModelProperty(value = "商家是否同意")
+    @ApiModelProperty(value = "商家是否同意", name = "merchantAgree")
     private Boolean merchantAgree;
 
+    @ApiModelProperty(value = "平台是否同意", name = "platformAgree")
+    private Boolean platformAgree;
+
 }

+ 12 - 1
src/main/java/com/izouma/dingdong/domain/PlatformFlow.java

@@ -1,10 +1,21 @@
 package com.izouma.dingdong.domain;
 
 import com.izouma.dingdong.enums.FlowType;
+import io.swagger.annotations.ApiModel;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
 
+import javax.persistence.Entity;
 import java.math.BigDecimal;
 
-public class PlatformFlow {
+@Entity
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@ApiModel(value = "平台流水")
+public class PlatformFlow extends BaseEntity {
+
     private Long userId;
 
     private FlowType type;

+ 7 - 2
src/main/java/com/izouma/dingdong/enums/FlowType.java

@@ -2,8 +2,13 @@ package com.izouma.dingdong.enums;
 
 public enum FlowType {
     //用户下单
-
+    USER_ORDER,
+    //抽佣
+    
     //提现
-
+    WITHDRAW,
     //用户退款
+    USER_REFUND,
+    //奖励
+    REWARD
 }

+ 38 - 29
src/main/java/com/izouma/dingdong/service/OrderInfoService.java

@@ -262,8 +262,7 @@ public class OrderInfoService {
         if (next) {
 
             OrderInfo orderInfo = orderInfoRepo.findById(orderId).orElseThrow(new BusinessException("无订单"));
-            //按商户Id找出用户
-            User userMer = userRepo.findById(merchantRepo.findUserIdById(orderInfo.getMerchantId())).orElseThrow(new BusinessException("无用户"));
+
 
             if (OrderStatus.CANCELLED.equals(orderInfo.getStatus())) {
                 throw new BusinessException("订单已取消");
@@ -282,35 +281,8 @@ public class OrderInfoService {
                         orderInfo.setRiderStatus(RiderStatus.CARRY_OUT);
                         orderInfo.setUserReceivedTime(LocalDateTime.now());
                         orderInfo.setStatus(OrderStatus.RATED);
-                        //添加销量数据
-                        salesService.addSale(orderInfo);
-
-
-                        //扣除金额
-                        SysConfig sysConfig = sysConfigRepo.findByName("commission").orElseThrow(new BusinessException("无设置"));
-                        //平台抽成
-                        BigDecimal platform = orderInfo.getRealAmount().multiply(new BigDecimal(sysConfig.getValue()));
-                        //商家应得 = 减去骑手应得,减去平台抽成
-                        userMer.setMoney(userMer.getMoney().add(orderInfo.getRealAmount().subtract(orderInfo.getDeliveryAmount()).subtract(platform)));
-                        userRepo.save(userMer);
-
-                        //购买的user
-                        User user = userRepo.findById(orderInfo.getUserId()).orElseThrow(new BusinessException("无商户"));
-                        //记录到对账单
-                        moneyRecordRepo.save(
-                                MoneyRecord.builder()
-                                        .avatar(user.getAvatar())
-                                        .name(user.getNickname() + "购买")
-                                        .type(FinancialType.INCOME)
-                                        .time(LocalDateTime.now())
-                                        .amount(orderInfo.getRealAmount())
-                                        .userId(merchantRepo.findUserIdById(orderInfo.getMerchantId()))
-                                        .build()
-                        );
 
 
-                        //骑手应得
-
 
                         break;
                 }
@@ -408,4 +380,41 @@ public class OrderInfoService {
         orderInfo.setStatus(OrderStatus.CANCELLED);
         orderInfoRepo.save(orderInfo);
     }
+
+    public void orderCarryOut(Long orderId){
+        OrderInfo orderInfo = orderInfoRepo.findById(orderId).orElseThrow(new BusinessException("无订单"));
+
+        //按商户Id找出用户
+        User userMer = userRepo.findById(merchantRepo.findUserIdById(orderInfo.getMerchantId())).orElseThrow(new BusinessException("无用户"));
+
+        //添加销量数据
+        salesService.addSale(orderInfo);
+
+        //扣除金额
+        SysConfig sysConfig = sysConfigRepo.findByName("commission").orElseThrow(new BusinessException("无设置"));
+        //平台抽成
+        BigDecimal platform = orderInfo.getRealAmount().multiply(new BigDecimal(sysConfig.getValue()));
+        //商家应得 = 减去骑手应得,减去平台抽成
+        userMer.setMoney(userMer.getMoney().add(orderInfo.getRealAmount().subtract(orderInfo.getDeliveryAmount()).subtract(platform)));
+        userRepo.save(userMer);
+
+        //购买的user
+        User user = userRepo.findById(orderInfo.getUserId()).orElseThrow(new BusinessException("无商户"));
+        //记录到对账单
+        moneyRecordRepo.save(
+                MoneyRecord.builder()
+                        .avatar(user.getAvatar())
+                        .name(user.getNickname() + "购买")
+                        .type(FinancialType.INCOME)
+                        .time(LocalDateTime.now())
+                        .amount(orderInfo.getRealAmount())
+                        .userId(merchantRepo.findUserIdById(orderInfo.getMerchantId()))
+                        .build()
+        );
+
+
+
+
+        //骑手应得
+    }
 }

+ 26 - 2
src/main/java/com/izouma/dingdong/service/OrderRefundApplyService.java

@@ -1,5 +1,6 @@
 package com.izouma.dingdong.service;
 
+import cn.hutool.core.util.ObjectUtil;
 import com.izouma.dingdong.domain.OrderInfo;
 import com.izouma.dingdong.domain.OrderRefundApply;
 import com.izouma.dingdong.domain.User;
@@ -152,12 +153,35 @@ public class OrderRefundApplyService {
     //商家同意 商家不同意
 
     //平台
-    public void platformAudit(Long applyId, Boolean agree, BigDecimal merchantLiability, BigDecimal riderLiability, BigDecimal platformLiability) {
+    public void platformAudit(Long applyId, Boolean agree, BigDecimal merchantLiability, BigDecimal riderLiability,Boolean isCarryOut) {
+
         OrderRefundApply apply = orderRefundApplyRepo.findById(applyId).orElseThrow(new BusinessException("无记录"));
+        if (ObjectUtil.isNull(merchantLiability)) {
+            merchantLiability = BigDecimal.ZERO;
+        }
+        if (ObjectUtil.isNull(riderLiability)) {
+            riderLiability = BigDecimal.ZERO;
+        }
         if (agree) {
+            apply.setPlatformAgree(true);
+            apply.setPlatformLiability(BigDecimal.ONE.subtract(riderLiability).subtract(merchantLiability));
+            apply.setRiderLiability(riderLiability);
+            apply.setMerchantLiability(merchantLiability);
+
+            if (!merchantLiability.equals(BigDecimal.ZERO)) {
+                //按商户Id找出用户
+                User userMer = userRepo.findById(merchantRepo.findUserIdById(apply.getMerchantId())).orElseThrow(new BusinessException("无用户"));
+                //商家所赔金额
+                BigDecimal merAmount = apply.getOrderInfo().getRealAmount().multiply(merchantLiability);
+                userMer.setMoney(userMer.getMoney().subtract(merAmount));
+            }
 
-        } else {
+            if (!riderLiability.equals(BigDecimal.ZERO)) {
+                //骑手赔付金额
+            }
 
+        } else {
+            apply.setPlatformAgree(false);
         }
 
     }

+ 19 - 0
src/main/java/com/izouma/dingdong/service/merchant/GoodsSpecificationService.java

@@ -1,16 +1,35 @@
 package com.izouma.dingdong.service.merchant;
 
 import com.izouma.dingdong.domain.merchant.GoodsSpecification;
+import com.izouma.dingdong.exception.BusinessException;
+import com.izouma.dingdong.repo.merchant.GoodsRepo;
 import com.izouma.dingdong.repo.merchant.GoodsSpecificationRepo;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+
 @Service
 @AllArgsConstructor
 public class GoodsSpecificationService {
 
     private GoodsSpecificationRepo goodsSpecificationRepo;
 
+    private GoodsRepo goodsRepo;
+
+    public List<GoodsSpecification> saveAll(List<GoodsSpecification> spec) {
+        List<GoodsSpecification> all = new ArrayList<>();
+        spec.forEach(s -> {
+            goodsRepo.findById(s.getGoodsId()).orElseThrow(new BusinessException("商品不存在"));
+            if (s.getAmount().compareTo(BigDecimal.ZERO) < 0) {
+                throw new BusinessException("规格价钱不得小于零");
+            }
+            all.add(goodsSpecificationRepo.save(s));
+        });
 
+        return all;
+    }
 
 }

+ 8 - 1
src/main/java/com/izouma/dingdong/web/merchant/GoodsSpecificationController.java

@@ -77,8 +77,15 @@ public class GoodsSpecificationController extends BaseController {
 
     @GetMapping("/parent")
     @ApiOperation("按商品ID查出规格分类")
-    public List<GoodsSpecification> parent(Long goodsId){
+    public List<GoodsSpecification> parent(Long goodsId) {
         return goodsSpecificationRepo.findAllByGoodsIdAndParentIsNull(goodsId);
     }
+
+
+    @GetMapping("/saveAll")
+    @ApiOperation("批量保存规格")
+    public List<GoodsSpecification> saveAll(List<GoodsSpecification> spec) {
+        return goodsSpecificationService.saveAll(spec);
+    }
 }