Procházet zdrojové kódy

Merge branch 'zx_saas_goods' of http://git.dayaedu.com/yonge/mec into test

zouxuan před 1 rokem
rodič
revize
c2ae2e5ff8
50 změnil soubory, kde provedl 1067 přidání a 500 odebrání
  1. 1 1
      mec-application/src/main/java/com/ym/mec/student/controller/StudentOrderController.java
  2. 3 0
      mec-application/src/main/java/com/ym/mec/web/controller/ReplacementInstrumentActivityController.java
  3. 30 1
      mec-application/src/main/java/com/ym/mec/web/controller/education/EduRepairController.java
  4. 2 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentRepairDao.java
  5. 10 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/dto/ReplacementInstrumentActivityStatDto.java
  6. 4 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/entity/MusicGroupPaymentCalenderAddress.java
  7. 5 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/entity/MusicGroupPaymentCalenderGoods.java
  8. 11 1
      mec-biz/src/main/java/com/ym/mec/biz/dal/entity/ReplacementInstrument.java
  9. 36 1
      mec-biz/src/main/java/com/ym/mec/biz/dal/entity/StudentGoodsSell.java
  10. 4 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/entity/StudentPaymentOrder.java
  11. 56 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/entity/StudentPaymentOrderAddress.java
  12. 27 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/mapper/StudentPaymentOrderAddressMapper.java
  13. 10 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/page/GoodsQuery.java
  14. 63 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/wrapper/StudentPaymentOrderAddressWrapper.java
  15. 3 0
      mec-biz/src/main/java/com/ym/mec/biz/service/GoodsService.java
  16. 43 0
      mec-biz/src/main/java/com/ym/mec/biz/service/StudentPaymentOrderAddressService.java
  17. 12 7
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/GoodsServiceImpl.java
  18. 6 2
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderServiceImpl.java
  19. 20 13
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/ReplacementInstrumentActivityServiceImpl.java
  20. 18 0
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/ReplacementInstrumentServiceImpl.java
  21. 58 22
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/SellOrderServiceImpl.java
  22. 12 7
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentGoodsSellServiceImpl.java
  23. 6 0
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentInstrumentServiceImpl.java
  24. 65 0
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderAddressServiceImpl.java
  25. 0 1
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderDetailServiceImpl.java
  26. 112 116
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderServiceImpl.java
  27. 105 77
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentRouteOrderServiceImpl.java
  28. 33 0
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRepairServiceImpl.java
  29. 35 203
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/SubjectChangeServiceImpl.java
  30. 4 1
      mec-biz/src/main/resources/config/mybatis/GoodsMapper.xml
  31. 2 1
      mec-biz/src/main/resources/config/mybatis/GoodsSubMapper.xml
  32. 11 0
      mec-biz/src/main/resources/config/mybatis/StudentPaymentOrderAddressMapper.xml
  33. 1 0
      mec-biz/src/main/resources/config/mybatis/StudentPaymentOrderDetailMapper.xml
  34. 2 2
      mec-biz/src/main/resources/config/mybatis/StudentPaymentRouteOrderMapper.xml
  35. 7 0
      mec-biz/src/main/resources/config/mybatis/StudentRepairMapper.xml
  36. 4 1
      mec-common/common-core/src/main/java/com/ym/mec/common/dto/OrderCreate.java
  37. 11 0
      mec-common/common-core/src/main/java/com/ym/mec/common/entity/OrderCancelModel.java
  38. 3 0
      mec-common/common-core/src/main/java/com/ym/mec/common/entity/OrderSkuSync.java
  39. 48 16
      mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/controller/OmsOrderController.java
  40. 4 1
      mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/dto/OrderCreate.java
  41. 2 1
      mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/service/OmsOrderService.java
  42. 88 12
      mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/service/impl/OmsOrderServiceImpl.java
  43. 26 0
      mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/wrapper/OmsOrderWrapper.java
  44. 2 0
      mec-mall/mall-mbg/src/main/java/com/yonge/cooleshow/mbg/mapper/PmsProductSkuStockRecordMapper.java
  45. 10 0
      mec-mall/mall-mbg/src/main/java/com/yonge/cooleshow/mbg/model/OmsOrderItem.java
  46. 18 3
      mec-mall/mall-mbg/src/main/resources/config/mybatis/OmsOrderItemMapper.xml
  47. 15 0
      mec-mall/mall-mbg/src/main/resources/config/mybatis/PmsProductSkuStockRecordMapper.xml
  48. 3 2
      mec-mall/mall-portal/src/main/java/com/yonge/cooleshow/portal/service/impl/OmsPortalOrderServiceImpl.java
  49. 7 3
      mec-thirdparty/src/main/java/com/ym/mec/thirdparty/adapay/Payment.java
  50. 9 5
      mec-thirdparty/src/main/java/com/ym/mec/thirdparty/yeepay/YeepayPaymentService.java

+ 1 - 1
mec-application/src/main/java/com/ym/mec/student/controller/StudentOrderController.java

@@ -477,7 +477,7 @@ public class StudentOrderController extends BaseController {
     @GetMapping("/setSuccessStatus")
     public HttpResponseResult setSuccessStatus(String orderNo) throws Exception {
         if (!profiles.equals("dev") && !profiles.equals("test")) {
-            return failed("非法操作");
+//            return failed("非法操作");
         }
         List<StudentPaymentOrder> payingOrders = studentPaymentOrderService.findOrdersByStatus(DealStatusEnum.ING);
 

+ 3 - 0
mec-application/src/main/java/com/ym/mec/web/controller/ReplacementInstrumentActivityController.java

@@ -1,5 +1,6 @@
 package com.ym.mec.web.controller;
 
+import com.beust.jcommander.internal.Lists;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.biz.dal.dao.ReplacementInstrumentActivityDao;
 import com.ym.mec.biz.dal.dao.SysConfigDao;
@@ -89,6 +90,7 @@ public class ReplacementInstrumentActivityController extends BaseController {
         ReplacementInstrumentCooperation byCooperationId = replacementInstrumentCooperationService.get(oldReplacementInstrumentActivity.getReplacementInstrumentCooperationId());
         if (byCooperationId.getOpenPay().equals(YesOrNoEnum.YES) && oldReplacementInstrumentActivity.getInstrumentsId() == null && replacementInstrumentActivity.getInstrumentsId() != null) {
             Goods goods = goodsService.get(replacementInstrumentActivity.getInstrumentsId());
+            goods.setBrand(goodsService.getBrandMap().getOrDefault(goods.getBrand(),goods.getBrand()));
             Map<Integer, String> userMap = new HashMap<>();
             Map<Integer, String> userPhoneMap = new HashMap<>();
             Integer userId = oldReplacementInstrumentActivity.getUserId();
@@ -126,6 +128,7 @@ public class ReplacementInstrumentActivityController extends BaseController {
         }
         if (openFlag == 1) {
             Goods goods = goodsService.get(replacementInstrumentActivity.getInstrumentsId());
+            goods.setBrand(goodsService.getBrandMap().getOrDefault(goods.getBrand(),goods.getBrand()));
             Map<Integer, String> userMap = new HashMap<>();
             Map<Integer, String> userPhoneMap = new HashMap<>();
             Integer userId = replacementInstrumentActivity.getUserId();

+ 30 - 1
mec-application/src/main/java/com/ym/mec/web/controller/education/EduRepairController.java

@@ -1,6 +1,9 @@
 package com.ym.mec.web.controller.education;
 
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dao.EmployeeDao;
 import com.ym.mec.biz.dal.dao.StudentInstrumentDao;
@@ -12,21 +15,26 @@ import com.ym.mec.biz.dal.enums.OrderTypeEnum;
 import com.ym.mec.biz.dal.page.*;
 import com.ym.mec.biz.service.*;
 import com.ym.mec.common.controller.BaseController;
+import com.ym.mec.common.dto.BrandDto;
 import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.page.QueryInfo;
+import com.ym.mec.mall.MallFeignService;
 import com.ym.mec.util.date.DateUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import org.apache.commons.lang.math.NumberUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.web.bind.annotation.*;
 
+import javax.annotation.Resource;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
+import java.util.stream.Collectors;
 
 @RequestMapping("${app-config.url.web:}/eduRepair")
 @Api(tags = "教务维修服务")
@@ -53,6 +61,8 @@ public class EduRepairController extends BaseController {
     private StudentInstrumentService studentInstrumentService;
     @Autowired
     private StudentInstrumentDao studentInstrumentDao;
+    @Resource
+    private MallFeignService mallFeignService;
 
     @ApiOperation("获取学生列表")
     @GetMapping(value = "/getStudents")
@@ -113,7 +123,26 @@ public class EduRepairController extends BaseController {
     public HttpResponseResult getStudentRepairList(RepairStudentQueryInfo queryInfo) {
         queryInfo.setEmployeeId(sysUserService.getUserId());
         queryInfo.setPayStatus(2);
-        return succeed(studentRepairService.queryPage(queryInfo));
+        PageInfo<StudentRepair> repairPageInfo = studentRepairService.queryPage(queryInfo);
+        List<StudentRepair> rows = repairPageInfo.getRows();
+        if (!rows.isEmpty()) {
+            Map<Long, String> brandIdNameMap = mallFeignService.getList().stream().collect(Collectors.toMap(BrandDto::getId, BrandDto::getName));
+            rows.forEach(row -> {
+                String goodsJson = row.getGoodsJson();
+                if (StringUtils.isNotEmpty(goodsJson)) {
+                    JSONArray goods = JSON.parseArray(goodsJson);
+                    for (Object good : goods) {
+                        JSONObject goodObject = (JSONObject) good;
+                        String brand = goodObject.getString("brand");
+                        if (Objects.nonNull(brand) && NumberUtils.isNumber(brand)) {
+                            goodObject.put("brandName", brandIdNameMap.getOrDefault(Long.valueOf(brand), ""));
+                        }
+                    }
+                    row.setGoodsJson(JSON.toJSONString(goods));
+                }
+            });
+        }
+        return succeed(repairPageInfo);
     }
 
     @ApiOperation("获取乐器种类")

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentRepairDao.java

@@ -98,4 +98,6 @@ public interface StudentRepairDao extends com.ym.mec.common.dal.BaseDAO<Integer,
      * @return int
      */
     List<Integer> countStuEducation(@Param("studentId") Integer studentId);
+
+    StudentRepair getByOrderNo(@Param("orderNo") String orderNo);
 }

+ 10 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/ReplacementInstrumentActivityStatDto.java

@@ -19,6 +19,8 @@ public class ReplacementInstrumentActivityStatDto extends ReplacementInstrumentA
     /** 品牌 */
     private String brand;
 
+    private String brandName;
+
     /** 型号 */
     private String specification;
 
@@ -158,4 +160,12 @@ public class ReplacementInstrumentActivityStatDto extends ReplacementInstrumentA
     public void setBalance(BigDecimal balance) {
         this.balance = balance;
     }
+
+    public String getBrandName() {
+        return brandName;
+    }
+
+    public void setBrandName(String brandName) {
+        this.brandName = brandName;
+    }
 }

+ 4 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/MusicGroupPaymentCalenderAddress.java

@@ -58,6 +58,10 @@ public class MusicGroupPaymentCalenderAddress implements Serializable {
     @ApiModelProperty(value = "详细地址")
     private String address;
 
+    @TableField("delivery_detail_")
+    @ApiModelProperty(value = "商品发货明细,用于同步订单的发货信息")
+    private String deliveryDetail;
+
     @TableField("create_time_")
     @ApiModelProperty(value = "创建时间")
     private Date createTime;

+ 5 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/MusicGroupPaymentCalenderGoods.java

@@ -4,6 +4,7 @@ package com.ym.mec.biz.dal.entity;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
+import com.ym.mec.biz.dal.enums.GoodsType;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -30,6 +31,10 @@ public class MusicGroupPaymentCalenderGoods implements Serializable {
     @ApiModelProperty(value = "商品名称")
     private String goodsName;
 
+    @TableField("goods_type_")
+    @ApiModelProperty(value = "商品类型", required = false)
+    private String goodsType;
+
     @TableField("goods_sn_")
     @ApiModelProperty(value = "商品货号")
     private String goodsSn;

+ 11 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/ReplacementInstrument.java

@@ -17,6 +17,8 @@ public class ReplacementInstrument extends BaseEntity {
 	
 	/** 品牌 */
 	private String brand;
+
+	private String brandName;
 	
 	/** 型号 */
 	private String specification;
@@ -129,7 +131,15 @@ public class ReplacementInstrument extends BaseEntity {
 	public java.util.Date getUpdateTime(){
 		return this.updateTime;
 	}
-			
+
+	public String getBrandName() {
+		return brandName;
+	}
+
+	public void setBrandName(String brandName) {
+		this.brandName = brandName;
+	}
+
 	@Override
 	public String toString() {
 		return ToStringBuilder.reflectionToString(this);

+ 36 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/StudentGoodsSell.java

@@ -79,7 +79,42 @@ public class StudentGoodsSell extends BaseEntity {
 	// 商品来源类型 MALL商城
 	private String goodsType;
 
-	public String getGoodsType() {
+    // contactName ,contactMobile,address
+
+    // 收货人
+    private String contactName;
+
+    // 收货人手机号
+    private String contactMobile;
+
+    // 详细地址
+    private String address;
+
+    public String getContactName() {
+        return contactName;
+    }
+
+    public void setContactName(String contactName) {
+        this.contactName = contactName;
+    }
+
+    public String getContactMobile() {
+        return contactMobile;
+    }
+
+    public void setContactMobile(String contactMobile) {
+        this.contactMobile = contactMobile;
+    }
+
+    public String getAddress() {
+        return address;
+    }
+
+    public void setAddress(String address) {
+        this.address = address;
+    }
+
+    public String getGoodsType() {
 		return goodsType;
 	}
 

+ 4 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/StudentPaymentOrder.java

@@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModelProperty;
 
 import java.math.BigDecimal;
 import java.util.Date;
+import java.util.List;
 
 import lombok.Data;
 import org.apache.commons.lang3.builder.ToStringBuilder;
@@ -139,4 +140,7 @@ public class StudentPaymentOrder extends BaseEntity {
 	private Long calenderId;
 
 	private Integer cooperationId;
+
+	// 需要关闭的订单号
+	private List<String> closeOrderNoList;
 }

+ 56 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/StudentPaymentOrderAddress.java

@@ -0,0 +1,56 @@
+package com.ym.mec.biz.dal.entity;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.IdType;
+import lombok.Data;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+
+
+/**
+ * 学生订单收货地址
+ * 2024-03-01 12:05:41
+ */
+@Data
+@ApiModel(" StudentPaymentOrderAddress-学生订单收货地址")
+@TableName("student_payment_order_address")
+public class StudentPaymentOrderAddress implements Serializable {
+
+    @ApiModelProperty("id") 
+	    @TableId(value = "id_")
+	    private Long id;
+
+    @ApiModelProperty("订单号") 
+	@TableField(value = "order_no_")
+    private String orderNo;
+
+    @ApiModelProperty("收货人") 
+	@TableField(value = "contact_name_")
+    private String contactName;
+
+    @ApiModelProperty("收货人手机号") 
+	@TableField(value = "contact_mobile_")
+    private String contactMobile;
+
+    @ApiModelProperty("详细地址") 
+	@TableField(value = "address_")
+    private String address;
+
+    @ApiModelProperty("省") 
+	@TableField(value = "province_id_")
+    private Integer provinceId;
+
+    @ApiModelProperty("市") 
+	@TableField(value = "city_id_")
+    private Integer cityId;
+
+    @ApiModelProperty("县/街道") 
+	@TableField(value = "county_id_")
+    private Integer countyId;
+
+}

+ 27 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/mapper/StudentPaymentOrderAddressMapper.java

@@ -0,0 +1,27 @@
+package com.ym.mec.biz.dal.mapper;
+
+import java.util.List;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+import com.ym.mec.biz.dal.entity.StudentPaymentOrderAddress;
+import com.ym.mec.biz.dal.wrapper.StudentPaymentOrderAddressWrapper;
+
+/**
+ * 学生订单收货地址
+ * 2024-03-01 12:05:41
+ */
+@Repository
+public interface StudentPaymentOrderAddressMapper extends BaseMapper<StudentPaymentOrderAddress> {
+
+	/**
+	 * 分页查询
+	 * @param page IPage<StudentPaymentOrderAddressWrapper.StudentPaymentOrderAddress>
+	 * @param param StudentPaymentOrderAddressWrapper.StudentPaymentOrderAddressQuery
+	 * @return List<StudentPaymentOrderAddressWrapper.StudentPaymentOrderAddress>
+	 */
+	List<StudentPaymentOrderAddress> selectPage(@Param("page") IPage<StudentPaymentOrderAddress> page, @Param("param") StudentPaymentOrderAddressWrapper.StudentPaymentOrderAddressQuery param);
+	
+}

+ 10 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/page/GoodsQuery.java

@@ -27,6 +27,8 @@ public class GoodsQuery {
 
     private Integer subjectId;
 
+    private Boolean delFlag;
+
     public String getType() {
         return type;
     }
@@ -90,4 +92,12 @@ public class GoodsQuery {
     public void setReplacementShowOrganId(Integer replacementShowOrganId) {
         this.replacementShowOrganId = replacementShowOrganId;
     }
+
+    public Boolean getDelFlag() {
+        return delFlag;
+    }
+
+    public void setDelFlag(Boolean delFlag) {
+        this.delFlag = delFlag;
+    }
 }

+ 63 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/wrapper/StudentPaymentOrderAddressWrapper.java

@@ -0,0 +1,63 @@
+package com.ym.mec.biz.dal.wrapper;
+
+import com.alibaba.fastjson.JSON;
+import com.microsvc.toolkit.common.response.paging.QueryInfo;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import java.util.Optional;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.apache.commons.lang3.StringUtils;
+
+/**
+ * 学生订单收货地址
+ * 2024-03-01 12:05:41
+ */
+@ApiModel(value = "StudentPaymentOrderAddressWrapper对象", description = "学生订单收货地址查询对象")
+public class StudentPaymentOrderAddressWrapper {
+
+    @Data
+	@Builder
+    @NoArgsConstructor
+    @AllArgsConstructor
+    @ApiModel(" StudentPaymentOrderAddressQuery-学生订单收货地址")
+    public static class StudentPaymentOrderAddressQuery implements QueryInfo {
+    
+    	@ApiModelProperty("当前页")
+        private Integer page;
+        
+        @ApiModelProperty("分页行数")
+        private Integer rows;
+        
+        @ApiModelProperty("关键字匹配")
+		private String keyword;
+        
+        public String getKeyword() {
+            return Optional.ofNullable(keyword).filter(StringUtils::isNotBlank).orElse(null);
+        }
+        
+        public String jsonString() {
+            return JSON.toJSONString(this);
+        }
+
+        public static StudentPaymentOrderAddressQuery from(String json) {
+            return JSON.parseObject(json, StudentPaymentOrderAddressQuery.class);
+        }
+    }  
+
+	@ApiModel(" StudentPaymentOrderAddress-学生订单收货地址")
+    public static class StudentPaymentOrderAddress {
+        
+        public String jsonString() {
+            return JSON.toJSONString(this);
+        }
+
+        public static StudentPaymentOrderAddress from(String json) {
+            return JSON.parseObject(json, StudentPaymentOrderAddress.class);
+        }
+	}
+
+}

+ 3 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/GoodsService.java

@@ -1,6 +1,7 @@
 package com.ym.mec.biz.service;
 
 import java.util.List;
+import java.util.Map;
 
 import com.ym.mec.biz.dal.page.GoodsQueryInfo;
 import com.ym.mec.biz.dal.wrapper.GoodsWrapper;
@@ -161,4 +162,6 @@ public interface GoodsService extends BaseService<Integer, Goods> {
     List<BrandDto> queryGoodsBrandList();
 
     List<ProductCategoryDto> queryGoodsCategoryList();
+
+    Map<String,String> getBrandMap();
 }

+ 43 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/StudentPaymentOrderAddressService.java

@@ -0,0 +1,43 @@
+package com.ym.mec.biz.service;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ym.mec.biz.dal.wrapper.StudentPaymentOrderAddressWrapper;
+import com.ym.mec.biz.dal.entity.StudentPaymentOrderAddress;
+
+/**
+ * 学生订单收货地址
+ * 2024-03-01 12:05:41
+ */
+public interface StudentPaymentOrderAddressService extends IService<StudentPaymentOrderAddress>  {
+
+	/**
+     * 查询详情
+     * @param id 详情ID
+     * @return StudentPaymentOrderAddress
+     */
+	StudentPaymentOrderAddress detail(Long id);
+
+    /**
+     * 分页查询
+     * @param page IPage<StudentPaymentOrderAddress>
+     * @param query StudentPaymentOrderAddressWrapper.StudentPaymentOrderAddressQuery
+     * @return IPage<StudentPaymentOrderAddress>
+     */
+    IPage<StudentPaymentOrderAddress> selectPage(IPage<StudentPaymentOrderAddress> page, StudentPaymentOrderAddressWrapper.StudentPaymentOrderAddressQuery query);
+	
+    /**
+     * 添加
+     * @param studentPaymentOrderAddress StudentPaymentOrderAddressWrapper.StudentPaymentOrderAddress
+     * @return Boolean
+     */
+     Boolean add(StudentPaymentOrderAddressWrapper.StudentPaymentOrderAddress studentPaymentOrderAddress);   
+
+    /**
+     * 更新
+     * @param studentPaymentOrderAddress StudentPaymentOrderAddressWrapper.StudentPaymentOrderAddress
+     * @return Boolean
+     */
+     Boolean update(StudentPaymentOrderAddressWrapper.StudentPaymentOrderAddress studentPaymentOrderAddress);
+     
+}

+ 12 - 7
mec-biz/src/main/java/com/ym/mec/biz/service/impl/GoodsServiceImpl.java

@@ -15,18 +15,14 @@ import com.ym.mec.biz.dal.dto.BasicUserDto;
 import com.ym.mec.biz.dal.dto.GoodsSellDto;
 import com.ym.mec.biz.dal.entity.Goods;
 import com.ym.mec.biz.dal.entity.GoodsCategory;
-import com.ym.mec.biz.dal.entity.GoodsProcurement;
 import com.ym.mec.biz.dal.entity.GoodsSub;
 import com.ym.mec.biz.dal.entity.Organization;
 import com.ym.mec.biz.dal.entity.SellOrder;
 import com.ym.mec.biz.dal.enums.AccountType;
 import com.ym.mec.biz.dal.enums.GoodsType;
 import com.ym.mec.biz.dal.enums.MessageTypeEnum;
-import com.ym.mec.biz.dal.enums.SellStatus;
-import com.ym.mec.biz.dal.enums.StockType;
 import com.ym.mec.biz.dal.enums.TemplateTypeEnum;
 import com.ym.mec.biz.dal.enums.YesOrNoEnum;
-import com.ym.mec.biz.dal.mapper.GoodsSubMapper;
 import com.ym.mec.biz.dal.page.GoodsCategoryQueryInfo;
 import com.ym.mec.biz.dal.page.GoodsQuery;
 import com.ym.mec.biz.dal.page.GoodsQueryInfo;
@@ -40,7 +36,6 @@ import com.ym.mec.common.dto.ProductAttributeCategoryDto;
 import com.ym.mec.common.dto.ProductCategoryDto;
 import com.ym.mec.common.entity.GoodsSubModel;
 import com.ym.mec.common.entity.GoodsSubStockModel;
-import com.ym.mec.common.entity.UploadReturnBean;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.page.QueryInfo;
@@ -61,7 +56,6 @@ import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.usermodel.WorkbookFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.system.ApplicationHome;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.stereotype.Service;
@@ -79,7 +73,6 @@ import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.text.SimpleDateFormat;
 import java.util.*;
-import java.util.concurrent.atomic.AtomicInteger;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
@@ -1525,4 +1518,16 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 		}
 		return "";
 	}
+
+    @Override
+    public Map<String,String> getBrandMap(){
+
+        try {
+            return mallFeignService.getList().stream().collect(Collectors.toMap(o ->o.getId().toString(), BrandDto::getName));
+
+        }catch (Exception e){
+            log.error("获取品牌信息失败",e);
+        }
+        return new HashMap<>();
+    }
 }

+ 6 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderServiceImpl.java

@@ -29,6 +29,7 @@ import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.page.WrapperUtil;
 import com.ym.mec.common.service.IdGeneratorService;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
+import com.ym.mec.common.tenant.TenantContextHolder;
 import com.ym.mec.mall.MallFeignService;
 import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
 import com.ym.mec.util.collection.MapUtil;
@@ -462,6 +463,8 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
                     e.setTotalPrice(goods.getDiscountPrice().multiply(new BigDecimal(e.getNum())));
                     e.setSinglePrice(goods.getDiscountPrice());
                     e.setCalenderId(calenderId);
+                    e.setGoodsType(goods.getType().getCode());
+                    e.setGoodsName(goods.getName());
                     List<ComplementGoodsDto> childGoods = goodsSubService.getBaseMapper().queryChildGoods(e.getGoodsId());
                     if(CollectionUtils.isEmpty(childGoods)){
                         throw new BizException("商品{}没有子商品",goods.getName());
@@ -491,7 +494,7 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
         Organization organization = organizationDao.get(musicGroup.getOrganId());
         sendSeoMessageSource.sendSeoMessage(musicGroup.getOrganId(), new SysUserRoleEnum[]{ORGAN_MANAGER},
                 null, null, MessageTypeEnum.BACKSTAGE_PAYMENT_CALENDER_AUDIT, organization.getName(), musicGroup.getName());
-        
+        TenantContextHolder.setTenantId(organization.getTenantId());
         if (musicGroupPaymentCalender.getPaymentType() == PaymentType.ADD_STUDENT && musicGroupPaymentCalender.getStatus() != AUDITING ){
             addStudent(musicGroupPaymentCalender, musicGroup);
             //将0元未缴费学员缴费状态更新为已缴费
@@ -513,6 +516,7 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
         }
         ModelMap map = new ModelMap(1);
         map.put("musicGroupPaymentCalenderBatchNo", batchNo);
+        TenantContextHolder.clearTenantId();
         return BaseController.succeed(map);
     }
 
@@ -1003,7 +1007,7 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
         Date date = new Date();
         for (String batchNo : split) {
             List<MusicGroupPaymentCalender> musicGroupPaymentCalenders = musicGroupPaymentCalenderDao.findByBatchNo(batchNo);
-            if (musicGroupPaymentCalenders == null || musicGroupPaymentCalenders.size() == 0) {
+            if (CollectionUtils.isEmpty(musicGroupPaymentCalenders)) {
                 throw new BizException("缴费项目不存在");
             }
             MusicGroupPaymentCalender calender = musicGroupPaymentCalenders.get(0);

+ 20 - 13
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ReplacementInstrumentActivityServiceImpl.java

@@ -8,7 +8,11 @@ import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
 
+import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.service.*;
+import com.ym.mec.common.dto.BrandDto;
+import com.ym.mec.mall.MallFeignService;
+import org.apache.commons.lang.math.NumberUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -33,19 +37,6 @@ import com.ym.mec.biz.dal.dto.ReplacementInstrumentActivityDto;
 import com.ym.mec.biz.dal.dto.ReplacementInstrumentActivityStatDto;
 import com.ym.mec.biz.dal.dto.ReplacementInstrumentActivityStatHead;
 import com.ym.mec.biz.dal.dto.ReplacementPayDto;
-import com.ym.mec.biz.dal.entity.CooperationOrgan;
-import com.ym.mec.biz.dal.entity.Goods;
-import com.ym.mec.biz.dal.entity.QuestionnaireQuestion;
-import com.ym.mec.biz.dal.entity.QuestionnaireQuestionItem;
-import com.ym.mec.biz.dal.entity.QuestionnaireTopic;
-import com.ym.mec.biz.dal.entity.QuestionnaireUserResult;
-import com.ym.mec.biz.dal.entity.ReplacementInstrumentActivity;
-import com.ym.mec.biz.dal.entity.ReplacementInstrumentCooperation;
-import com.ym.mec.biz.dal.entity.SellOrder;
-import com.ym.mec.biz.dal.entity.Student;
-import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
-import com.ym.mec.biz.dal.entity.SysUserCashAccount;
-import com.ym.mec.biz.dal.entity.SysUserCashAccountDetail;
 import com.ym.mec.biz.dal.enums.AccountType;
 import com.ym.mec.biz.dal.enums.DealStatusEnum;
 import com.ym.mec.biz.dal.enums.GoodsType;
@@ -68,6 +59,8 @@ import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
 import com.ym.mec.util.collection.MapUtil;
 import com.ym.mec.util.http.HttpUtil;
 
+import javax.annotation.Resource;
+
 @Service
 public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<Integer, ReplacementInstrumentActivity> implements ReplacementInstrumentActivityService {
 
@@ -121,6 +114,8 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
     private QuestionnaireQuestionItemDao questionnaireQuestionItemDao;
     @Autowired
     private SysCouponCodeService sysCouponCodeService;
+    @Resource
+    private MallFeignService mallFeignService;
 
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
@@ -172,6 +167,7 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
         if (sendPush && replacementInstrumentActivity.getOpenFlag().equals(1) && replacementInstrumentActivity.getInstrumentsId() != null) {
             //换成商品列表中商品4.25
             Goods goods = goodsDao.get(replacementInstrumentActivity.getGoodsId());
+            goods.setBrand(goodsService.getBrandMap().getOrDefault(goods.getBrand(),goods.getBrand()));
             Map<Integer, String> userMap = new HashMap<>();
             Map<Integer, String> userPhoneMap = new HashMap<>();
             Integer userId = replacementInstrumentActivity.getUserId();
@@ -255,6 +251,7 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
         if (sendPush && replacementInstrumentActivity.getOpenFlag().equals(1) && replacementInstrumentActivity.getInstrumentsId() != null) {
             //换成商品列表中商品4.25
             Goods goods = goodsDao.get(replacementInstrumentActivity.getGoodsId());
+            goods.setBrand(goodsService.getBrandMap().getOrDefault(goods.getBrand(),goods.getBrand()));
             Map<Integer, String> userMap = new HashMap<>();
             Map<Integer, String> userPhoneMap = new HashMap<>();
             Integer userId = replacementInstrumentActivity.getUserId();
@@ -553,6 +550,16 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
                     replacementInstrumentActivityStatDto.setBalance(activityOrders.get(0).getBalancePaymentAmount());
                 }
             }
+            List<String> brandIdList = dataList.stream().map(ReplacementInstrumentActivityStatDto::getBrand).filter(StringUtils::isNotEmpty).distinct().collect(Collectors.toList());
+            if (!brandIdList.isEmpty()) {
+                Map<Long, String> idNameMap = mallFeignService.getList().stream().collect(Collectors.toMap(BrandDto::getId, BrandDto::getName));
+                for (ReplacementInstrumentActivityStatDto statDto : dataList) {
+                    String brand = statDto.getBrand();
+                    if (StringUtils.isNotEmpty(brand) && NumberUtils.isNumber(brand)) {
+                        statDto.setBrandName(idNameMap.getOrDefault(Long.valueOf(brand), ""));
+                    }
+                }
+            }
         }
         pageInfo.setRows(dataList);
         return pageInfo;

+ 18 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ReplacementInstrumentServiceImpl.java

@@ -4,19 +4,25 @@ import com.ym.mec.biz.dal.dao.GoodsDao;
 import com.ym.mec.biz.dal.entity.Goods;
 import com.ym.mec.biz.dal.page.ReplacementInstrumentQueryInfo;
 import com.ym.mec.common.dal.BaseDAO;
+import com.ym.mec.common.dto.BrandDto;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
+import com.ym.mec.mall.MallFeignService;
 import com.ym.mec.util.collection.MapUtil;
+import org.apache.commons.lang.math.NumberUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import com.ym.mec.biz.dal.entity.ReplacementInstrument;
 import com.ym.mec.biz.service.ReplacementInstrumentService;
 import com.ym.mec.biz.dal.dao.ReplacementInstrumentDao;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 @Service
 public class ReplacementInstrumentServiceImpl extends BaseServiceImpl<Integer, ReplacementInstrument> implements ReplacementInstrumentService {
@@ -25,6 +31,8 @@ public class ReplacementInstrumentServiceImpl extends BaseServiceImpl<Integer, R
     private ReplacementInstrumentDao replacementInstrumentDao;
     @Autowired
     private GoodsDao goodsDao;
+    @Resource
+    private MallFeignService mallFeignService;
 
     @Override
     public BaseDAO<Integer, ReplacementInstrument> getDAO() {
@@ -44,6 +52,16 @@ public class ReplacementInstrumentServiceImpl extends BaseServiceImpl<Integer, R
             pageInfo.setTotal(count);
             params.put("offset", pageInfo.getOffset());
             dataList = goodsDao.getReplacementGoodsPage(params);
+            List<String> brandIdList = dataList.stream().map(ReplacementInstrument::getBrand).filter(StringUtils::isNotEmpty).distinct().collect(Collectors.toList());
+            if (!brandIdList.isEmpty()) {
+                Map<Long, String> idNameMap = mallFeignService.getList().stream().collect(Collectors.toMap(BrandDto::getId, BrandDto::getName));
+                for (ReplacementInstrument instrument : dataList) {
+                    String brand = instrument.getBrand();
+                    if (StringUtils.isNotEmpty(brand) && NumberUtils.isNumber(brand)) {
+                        instrument.setBrandName(idNameMap.getOrDefault(Long.valueOf(brand), ""));
+                    }
+                }
+            }
         }
         pageInfo.setRows(dataList);
         return pageInfo;

+ 58 - 22
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SellOrderServiceImpl.java

@@ -85,6 +85,15 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
     @Autowired
     private MusicGroupShippingAddressService musicGroupShippingAddressService;
 
+    @Autowired
+    private SysAreaService sysAreaService;
+
+    @Autowired
+    private StudentRepairDao studentRepairDao;
+
+
+    @Autowired
+    private StudentPaymentOrderAddressService studentPaymentOrderAddressService;
     @Override
     public BaseDAO<Integer, SellOrder> getDAO() {
         return sellOrderDao;
@@ -276,30 +285,21 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
     @Transactional(rollbackFor = Exception.class)
     public void addOrderDetail2SellOrder(List<StudentPaymentOrderDetail> orderDetails,
                                                     StudentPaymentOrder studentPaymentOrder, String musicGroupId) {
-        //过非商品详情
+        //过非商品详情
         List<StudentPaymentOrderDetail> goodsOrderDetails = orderDetails.stream().filter(e -> StringUtils.isNotEmpty(e.getGoodsIdList())).collect(Collectors.toList());
         if(CollectionUtils.isEmpty(goodsOrderDetails)){
             return;
         }
         //获取总金额
         BigDecimal detailTotalPrice = goodsOrderDetails.stream().map(StudentPaymentOrderDetail::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
-        BigDecimal balancePaymentAmount = studentPaymentOrder.getBalancePaymentAmount();
-        if (balancePaymentAmount.compareTo(BigDecimal.ZERO) > 0) {
-            BigDecimal expectAmount = studentPaymentOrder.getExpectAmount();
-            BigDecimal organShareProfit = orderDetails.stream().filter(o -> o.getType() == ORGAN_SHARE_PROFIT).map(StudentPaymentOrderDetail::getPrice)
-                    .reduce(BigDecimal.ZERO, BigDecimal::add);
-            if(organShareProfit != null){
-                expectAmount = expectAmount.subtract(organShareProfit);
-            }
-            //获取比例
-            BigDecimal ratioAmount = BigDecimal.ZERO;
-            if(expectAmount.compareTo(BigDecimal.ZERO) > 0){
-                ratioAmount = balancePaymentAmount.divide(expectAmount, 6, BigDecimal.ROUND_HALF_UP);
-            }
-            //获取分配的减免金额
-            balancePaymentAmount = balancePaymentAmount.multiply(ratioAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
+        //获取比例
+        BigDecimal totalRatioAmount = BigDecimal.ZERO;
+        if(studentPaymentOrder.getExpectAmount().compareTo(BigDecimal.ZERO) > 0){
+            totalRatioAmount = detailTotalPrice.divide(studentPaymentOrder.getExpectAmount(), 6, BigDecimal.ROUND_HALF_UP);
         }
-        //获取总减免金额
+        //获取分配的余额
+        BigDecimal balancePaymentAmount = studentPaymentOrder.getBalancePaymentAmount().multiply(totalRatioAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
+        //获取总优惠券金额
         BigDecimal detailTotalRemitPrice = goodsOrderDetails.stream().map(StudentPaymentOrderDetail::getRemitFee).reduce(BigDecimal.ZERO, BigDecimal::add);
 
         List<SellOrder> sellOrders = new ArrayList<>();
@@ -309,7 +309,8 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
         //剩余待分配的优惠券金额
         BigDecimal subDetailCouponRemitFee = detailTotalRemitPrice;
         //剩余待分配现金
-        BigDecimal subDetailActualAmount = detailTotalPrice.subtract(balancePaymentAmount);
+        BigDecimal totalDetailActualAmount = detailTotalPrice.subtract(balancePaymentAmount);
+        BigDecimal subDetailActualAmount = totalDetailActualAmount;
         for (int i = 0; i < goodsOrderDetails.size(); i++) {
             StudentPaymentOrderDetail orderDetail = goodsOrderDetails.get(i);
             //获取支付金额比例
@@ -340,10 +341,10 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
                 detailBalance = balancePaymentAmount.multiply(ratioAmount).setScale(2, BigDecimal.ROUND_DOWN);
                 subDetailBalance = subDetailBalance.subtract(detailBalance);
                 //获取分配的优惠券金额
-                couponRemitFee = orderDetail.getRemitFee().multiply(ratioCouponAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
+                couponRemitFee = detailTotalRemitPrice.multiply(ratioCouponAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
                 subDetailCouponRemitFee = subDetailCouponRemitFee.subtract(couponRemitFee);
                 //获取剩余待分配的现金
-                detailActualAmount = orderDetail.getPrice().subtract(detailBalance);
+                detailActualAmount = totalDetailActualAmount.multiply(ratioAmount).setScale(2, BigDecimal.ROUND_DOWN);
                 subDetailActualAmount = subDetailActualAmount.subtract(detailActualAmount);
             }
             List<Integer> goodsIds = Arrays.asList(orderDetail.getGoodsIdList().split(",")).stream().map(Integer::parseInt).collect(Collectors.toList());
@@ -492,7 +493,7 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
     }
 
     @Override
-    @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
+    @Transactional(rollbackFor = Exception.class)
     public List<SellOrder> refund(List<SellOrder> sellOrders, Boolean reBackFee) {
         Date nowDate = new Date();
         for (SellOrder sellOrder : sellOrders) {
@@ -641,7 +642,8 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
         mallOrder.setSourceType(1);
 
         // 乐团学生报名默认收货地址
-        if (studentPaymentOrder.getType() == OrderTypeEnum.APPLY && StringUtils.isNotBlank(mallOrder.getOrchestraId())) {
+        if ((studentPaymentOrder.getType() == OrderTypeEnum.APPLY || studentPaymentOrder.getType() == OrderTypeEnum.SUBJECT_CHANGE)
+            && StringUtils.isNotBlank(mallOrder.getOrchestraId())) {
 
             // 查询乐团默认收货地址
             MusicGroupShippingAddressQueryInfo queryInfo = new MusicGroupShippingAddressQueryInfo();
@@ -658,6 +660,40 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
                 mallOrder.setReceiverRegion(address.getRegionCounty());
                 mallOrder.setReceiverDetailAddress(address.getDetailAddress());
             }
+        } else if(studentPaymentOrder.getType() == OrderTypeEnum.GOODS_SELL) {
+            StudentPaymentOrderAddress one = studentPaymentOrderAddressService.lambdaQuery()
+                .eq(StudentPaymentOrderAddress::getOrderNo, studentPaymentOrder.getOrderNo())
+                .last("limit 1")
+                .one();
+            if(one != null) {
+                // 查询地区信息
+                List<String> areaIds = new ArrayList<>();
+                areaIds.add(one.getProvinceId()==null?null:one.getProvinceId().toString());
+                areaIds.add(one.getCityId()==null?null:one.getCityId().toString());
+                areaIds.add(one.getCountyId()==null?null:one.getCountyId().toString());
+                areaIds = areaIds.stream().filter(StringUtils::isNotBlank).distinct().collect(Collectors.toList());
+                Map<String, String> nameMapByIds = sysAreaService.getNameMapByIds(areaIds);
+                mallOrder.setReceiverName(one.getContactName());
+                mallOrder.setReceiverPhone(one.getContactMobile());
+                if (one.getProvinceId() != null) {
+                    mallOrder.setReceiverProvince(nameMapByIds.getOrDefault(one.getProvinceId().toString(), ""));
+                }
+                if (one.getCityId() != null) {
+                    mallOrder.setReceiverCity(nameMapByIds.getOrDefault(one.getCityId().toString(), ""));
+                }
+                if (one.getCountyId() != null) {
+                    mallOrder.setReceiverRegion(nameMapByIds.getOrDefault(one.getCountyId().toString(), ""));
+                }
+                mallOrder.setReceiverDetailAddress(one.getAddress());
+
+            }
+        } else if (studentPaymentOrder.getType() == OrderTypeEnum.REPAIR) {
+            StudentRepair studentRepair = studentRepairDao.getByOrderNo(studentPaymentOrder.getOrderNo());
+            if (studentRepair != null) {
+                mallOrder.setReceiverName(studentRepair.getContactName());
+                mallOrder.setReceiverPhone(studentRepair.getContactMobile());
+                mallOrder.setReceiverDetailAddress(studentRepair.getAddress());
+            }
         }
 
         CommonResult<Boolean> result = mallFeignService.productOrderCreate(mallOrder);

+ 12 - 7
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentGoodsSellServiceImpl.java

@@ -3,16 +3,16 @@ package com.ym.mec.biz.service.impl;
 
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.ym.mec.biz.dal.dao.*;
+import com.ym.mec.biz.dal.dao.GoodsDao;
+import com.ym.mec.biz.dal.dao.StudentGoodsSellDao;
+import com.ym.mec.biz.dal.dao.StudentInstrumentDao;
+import com.ym.mec.biz.dal.dao.SysCouponCodeDao;
 import com.ym.mec.biz.dal.dto.GoodsSellDto;
 import com.ym.mec.biz.dal.dto.StudentGoodsSellDto;
 import com.ym.mec.biz.dal.dto.StudentPaymentOrderDto;
 import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.page.GoodsSellQueryInfo;
-import com.ym.mec.biz.service.StudentGoodsSellService;
-import com.ym.mec.biz.service.SysConfigService;
-import com.ym.mec.biz.service.SysTenantConfigService;
-import com.ym.mec.biz.service.TenantInfoService;
+import com.ym.mec.biz.service.*;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
@@ -33,8 +33,6 @@ public class StudentGoodsSellServiceImpl extends BaseServiceImpl<Integer, Studen
     @Autowired
     private StudentGoodsSellDao studentGoodsSellDao;
     @Autowired
-    private SysConfigDao sysConfigDao;
-    @Autowired
     private SysTenantConfigService sysTenantConfigService;
     @Autowired
     private TenantInfoService tenantInfoService;
@@ -45,6 +43,9 @@ public class StudentGoodsSellServiceImpl extends BaseServiceImpl<Integer, Studen
     @Autowired
     private SysCouponCodeDao sysCouponCodeDao;
 
+    @Autowired
+    private GoodsService goodsService;
+
     @Override
     public BaseDAO<Integer, StudentGoodsSell> getDAO() {
         return studentGoodsSellDao;
@@ -146,6 +147,10 @@ public class StudentGoodsSellServiceImpl extends BaseServiceImpl<Integer, Studen
             return null;
         }
         List<Goods> goodies = goodsDao.getGoodiesAndCate(goodsIds);
+        Map<String, String> brandMap = goodsService.getBrandMap();
+        for (Goods goody : goodies) {
+            goody.setBrand(brandMap.getOrDefault(goody.getBrand(),goody.getBrand()));
+        }
         List<StudentInstrument> studentInstruments = new ArrayList<>();
         for (Goods goods : goodies) {
             StudentInstrument studentInstrument = new StudentInstrument();

+ 6 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentInstrumentServiceImpl.java

@@ -306,6 +306,8 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
     @Override
     public StudentInstrument addStudentInstrument(StudentInstrument studentInstrument) {
         Goods goods = goodsService.get(studentInstrument.getGoodsId());
+
+        goods.setBrand(goodsService.getBrandMap().getOrDefault(goods.getBrand(),goods.getBrand()));
         GoodsCategory goodsCategory = goodsCategoryService.get(goods.getGoodsCategoryId());
         studentInstrument.setGoodsCategoryId(goods.getGoodsCategoryId());
         studentInstrument.setGoodsCategoryName(goodsCategory.getName());
@@ -352,6 +354,8 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
     @Override
     public StudentInstrument updateStudentInstrument(StudentInstrument studentInstrument) {
         Goods goods = goodsService.get(studentInstrument.getGoodsId());
+
+        goods.setBrand(goodsService.getBrandMap().getOrDefault(goods.getBrand(),goods.getBrand()));
         GoodsCategory goodsCategory = goodsCategoryService.get(goods.getGoodsCategoryId());
         studentInstrument.setGoodsCategoryId(goods.getGoodsCategoryId());
         studentInstrument.setGoodsCategoryName(goodsCategory.getName());
@@ -395,6 +399,8 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
         }
         
         Goods goods = goodsService.get(studentInstrument.getGoodsId());
+
+        goods.setBrand(goodsService.getBrandMap().getOrDefault(goods.getBrand(),goods.getBrand()));
         GoodsCategory goodsCategory = goodsCategoryService.get(goods.getGoodsCategoryId());
         studentInstrument.setGoodsCategoryId(goods.getGoodsCategoryId());
         studentInstrument.setGoodsCategoryName(goodsCategory.getName());

+ 65 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderAddressServiceImpl.java

@@ -0,0 +1,65 @@
+package com.ym.mec.biz.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+import lombok.extern.slf4j.Slf4j;
+import com.ym.mec.biz.dal.entity.StudentPaymentOrderAddress;
+import com.ym.mec.biz.dal.wrapper.StudentPaymentOrderAddressWrapper;
+import com.ym.mec.biz.dal.mapper.StudentPaymentOrderAddressMapper;
+import com.ym.mec.biz.service.StudentPaymentOrderAddressService;
+
+/**
+ * 学生订单收货地址
+ * 2024-03-01 12:05:41
+ */
+@Slf4j
+@Service
+public class StudentPaymentOrderAddressServiceImpl extends ServiceImpl<StudentPaymentOrderAddressMapper, StudentPaymentOrderAddress> implements StudentPaymentOrderAddressService {
+
+	/**
+     * 查询详情
+     * @param id 详情ID
+     * @return StudentPaymentOrderAddress
+     */
+	@Override
+    public StudentPaymentOrderAddress detail(Long id) {
+        
+        return baseMapper.selectById(id);
+    }
+    
+    /**
+     * 分页查询
+     * @param page IPage<StudentPaymentOrderAddress>
+     * @param query StudentPaymentOrderAddressWrapper.StudentPaymentOrderAddressQuery
+     * @return IPage<StudentPaymentOrderAddress>
+     */
+    @Override
+    public IPage<StudentPaymentOrderAddress> selectPage(IPage<StudentPaymentOrderAddress> page, StudentPaymentOrderAddressWrapper.StudentPaymentOrderAddressQuery query) {
+        
+        return page.setRecords(baseMapper.selectPage(page, query));
+    }
+	
+    /**
+     * 添加
+     * @param studentPaymentOrderAddress StudentPaymentOrderAddressWrapper.StudentPaymentOrderAddress
+     * @return Boolean
+     */
+    @Override
+    public Boolean add(StudentPaymentOrderAddressWrapper.StudentPaymentOrderAddress studentPaymentOrderAddress) {    	
+        
+        return this.save(JSON.parseObject(studentPaymentOrderAddress.jsonString(), StudentPaymentOrderAddress.class));
+    }
+
+    /**
+     * 更新
+     * @param studentPaymentOrderAddress StudentPaymentOrderAddressWrapper.StudentPaymentOrderAddress
+     * @return Boolean
+     */
+    @Override
+    public Boolean update(StudentPaymentOrderAddressWrapper.StudentPaymentOrderAddress studentPaymentOrderAddress){
+
+        return this.updateById(JSON.parseObject(studentPaymentOrderAddress.jsonString(), StudentPaymentOrderAddress.class));       
+    }
+}

+ 0 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderDetailServiceImpl.java

@@ -689,7 +689,6 @@ public class StudentPaymentOrderDetailServiceImpl extends BaseServiceImpl<Long,
         //销售订单详情
         if (allDetails.size() > 0 && (detailTypeEnums.contains(MUSICAL) || detailTypeEnums.contains(ACCESSORIES) || detailTypeEnums.contains(TEACHING))) {
             sellOrderService.addOrderDetail2SellOrder(allDetails, studentPaymentOrder, musicGroup.getId());
-
         }
 
         //活动小课包处理

+ 112 - 116
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderServiceImpl.java

@@ -19,8 +19,10 @@ import java.util.Optional;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
+import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.service.*;
 import com.ym.mec.common.entity.OrderSkuSync;
+import com.ym.mec.thirdparty.exception.ThirdpartyException;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
@@ -56,21 +58,6 @@ import com.ym.mec.biz.dal.dto.SporadicChargeInfoDto;
 import com.ym.mec.biz.dal.dto.StudentGoodsSellDto;
 import com.ym.mec.biz.dal.dto.StudentPaymentOrderDto;
 import com.ym.mec.biz.dal.dto.StudentPaymentOrderExportDto;
-import com.ym.mec.biz.dal.entity.ActivityUserMapper;
-import com.ym.mec.biz.dal.entity.CloudTeacherOrder;
-import com.ym.mec.biz.dal.entity.Goods;
-import com.ym.mec.biz.dal.entity.GoodsProcurement;
-import com.ym.mec.biz.dal.entity.MusicGroup;
-import com.ym.mec.biz.dal.entity.MusicGroupSubjectPlan;
-import com.ym.mec.biz.dal.entity.SellOrder;
-import com.ym.mec.biz.dal.entity.StudentGoodsSell;
-import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
-import com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail;
-import com.ym.mec.biz.dal.entity.StudentPaymentRouteOrder;
-import com.ym.mec.biz.dal.entity.StudentRegistration;
-import com.ym.mec.biz.dal.entity.SysUserCashAccount;
-import com.ym.mec.biz.dal.entity.SysUserCashAccountDetail;
-import com.ym.mec.biz.dal.entity.VipGroupActivity;
 import com.ym.mec.biz.dal.enums.AccountType;
 import com.ym.mec.biz.dal.enums.CourseViewTypeEnum;
 import com.ym.mec.biz.dal.enums.DealStatusEnum;
@@ -115,92 +102,104 @@ import com.ym.mec.thirdparty.yqpay.YqPayUtil;
 import com.ym.mec.util.collection.MapUtil;
 import com.ym.mec.util.date.DateUtil;
 
+import javax.annotation.Resource;
+
 @Service
 public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, StudentPaymentOrder> implements StudentPaymentOrderService {
 
-    @Autowired
+    @Resource
     private StudentPaymentOrderDao studentPaymentOrderDao;
-    @Autowired
+    @Resource
     private YqPayFeignService yqPayFeignService;
-    @Autowired
+    @Resource
     private StudentRegistrationService studentRegistrationService;
-    @Autowired
+    @Resource
     @Lazy
     private VipGroupService vipGroupService;
-    @Autowired
+    @Resource
     private MusicGroupService musicGroupService;
-    @Autowired
+    @Resource
     private SporadicChargeInfoService sporadicChargeInfoService;
-    @Autowired
+    @Resource
     private PracticeGroupService practiceGroupService;
-    @Autowired
+    @Resource
     private SysUserCashAccountDao sysUserCashAccountDao;
-    @Autowired
+    @Resource
     private StudentRepairService studentRepairService;
-    @Autowired
+    @Resource
     private SysUserCashAccountService sysUserCashAccountService;
-    @Autowired
+    @Resource
     private SubjectChangeService subjectChangeService;
-    @Autowired
+    @Resource
     private DegreeRegistrationService degreeRegistrationService;
-    @Autowired
+    @Resource
     private StudentPaymentRouteOrderDao studentPaymentRouteOrderDao;
-    @Autowired
+    @Resource
     private StudentPaymentOrderDetailService studentPaymentOrderDetailService;
-    @Autowired
+    @Resource
     private IdGeneratorService idGeneratorService;
-    @Autowired
+    @Resource
     private SysConfigDao sysConfigDao;
-    @Autowired
+    @Resource
     private GoodsDao goodsDao;
-    @Autowired
+    @Resource
     private GoodsService goodsService;
-    @Autowired
+    @Resource
     private StudentInstrumentService studentInstrumentService;
-    @Autowired
+    @Resource
     private ReplacementInstrumentActivityService replacementInstrumentActivityService;
-    @Autowired
+    @Resource
     private ChildrenDayReserveService childrenDayReserveService;
-    @Autowired
+    @Resource
     private MemberRankSettingService memberRankSettingService;
-    @Autowired
+    @Resource
     private PayService payService;
-    @Autowired
+    @Resource
     private StudentPaymentRouteOrderService studentPaymentRouteOrderService;
-    @Autowired
+    @Resource
     private CloudTeacherOrderService cloudTeacherOrderService;
-    @Autowired
+    @Resource
     private SysCouponCodeService sysCouponCodeService;
-    @Autowired
+    @Resource
     private VipGroupActivityService vipGroupActivityService;
-    @Autowired
+    @Resource
     private ActivityUserMapperService activityUserMapperService;
-    @Autowired
+    @Resource
     private MusicGroupSubjectPlanService musicGroupSubjectPlanService;
-    @Autowired
+    @Resource
     private SysUserFeignService sysUserFeignService;
-    @Autowired
+    @Resource
     private TenantConfigService tenantConfigService;
-    @Autowired
+    @Resource
     private GoodsProcurementDao goodsProcurementDao;
-    @Autowired
+    @Resource
     private SysPaymentConfigService sysPaymentConfigService;
-    @Autowired
+    @Resource
     private SellOrderDao sellOrderDao;
     @Lazy
-    @Autowired
+    @Resource
     private ContractService contractService;
-    @Autowired
+    @Resource
     private HfMerchantConfigService hfMerchantConfigService;
-    @Autowired
+    @Resource
     private StudentDao studentDao;
-    @Autowired
+    @Resource
     private SysUserCashAccountDetailService sysUserCashAccountDetailService;
-    
-    @Autowired
+    @Resource
     private YeepayPaymentService yeepayPaymentService;
-    @Autowired
+    @Resource
     private CourseScheduleStudentPaymentDao courseScheduleStudentPaymentDao;
+    @Resource
+    private MusicGroupPaymentCalenderAddressService musicGroupPaymentCalenderAddressService;
+    @Resource
+    private StudentRepairDao studentRepairDao;
+    @Resource
+    private MusicGroupDao musicGroupDao;
+    @Resource
+    private StudentGoodsSellDao studentGoodsSellDao;
+
+    @Autowired
+    private StudentPaymentOrderService studentPaymentOrderService;
 
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
     @Override
@@ -485,11 +484,11 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void updateOrder(Map<String, String> rpMap) throws Exception {
-        DealStatusEnum status = "1".equals(rpMap.get("tradeState")) ? DealStatusEnum.SUCCESS : DealStatusEnum.FAILED;
+        DealStatusEnum status = "1".equals(rpMap.get("tradeState")) ? SUCCESS : DealStatusEnum.FAILED;
         StudentPaymentOrder order = findOrderByOrderNo(rpMap.get("merOrderNo"));
         //关闭或失败的订单查询订单成功,订单改成成功,钱退到余额
-        if (order != null && (order.getStatus().equals(DealStatusEnum.CLOSE) || order.getStatus().equals(DealStatusEnum.FAILED)) && status.equals(DealStatusEnum.SUCCESS)) {
-            String memo = order.getStatus().equals(DealStatusEnum.CLOSE) ? "关闭订单" : "失败订单";
+        if (order != null && (order.getStatus().equals(CLOSE) || order.getStatus().equals(DealStatusEnum.FAILED)) && status.equals(SUCCESS)) {
+            String memo = order.getStatus().equals(CLOSE) ? "关闭订单" : "失败订单";
             memo = memo + ",实际支付成功,退到用户余额";
             //更新订单状态
             order.setStatus(status);
@@ -516,7 +515,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
             return;
         }
 
-        if (status.equals(DealStatusEnum.SUCCESS)) {
+        if (status.equals(SUCCESS)) {
             order.setPayTime(new Date());
         } else {
             order.setMemo(rpMap.get("remarks"));
@@ -534,7 +533,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
 
         callOrderCallBack(order);
 
-        if (status.equals(DealStatusEnum.SUCCESS)
+        if (status.equals(SUCCESS)
                 && StringUtils.isNotBlank(order.getPaymentChannel())
                 && (order.getPaymentChannel().equals(PaymentChannelEnum.ADAPAY.getCode()) || order.getPaymentChannel().equals(PaymentChannelEnum.YEEPAY.getCode()))
                 && !rpMap.containsKey("simulation")) {
@@ -734,7 +733,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
                 memberRankSettingService.liveBuyOrderCallback(order);
             } else if (order.getType().equals(OrderTypeEnum.MALL_BUY)) {
                 // 商城购买订单回调
-                this.mallBuyOrderCallback(order);
+                studentPaymentOrderService.mallBuyOrderCallback(order);
             }
         }
     }
@@ -897,7 +896,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
         List<StudentPaymentOrderExportDto> orders = studentPaymentOrderDao.getUserApplyOrders(studentId, musicGroupId);
         StudentRegistration studentRegister = studentRegistrationService.getStudentRegister(musicGroupId, studentId);
         for (StudentPaymentOrderExportDto order : orders) {
-            if ((DealStatusEnum.ING.equals(order.getStatus()) || DealStatusEnum.SUCCESS.equals(order.getStatus())) &&
+            if ((DealStatusEnum.ING.equals(order.getStatus()) || SUCCESS.equals(order.getStatus())) &&
                     studentRegister.getPayingStatus().equals(2)) {
                 order.setPayingStatus(2);
             }
@@ -1142,7 +1141,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
             return BaseController.failed(HttpStatus.CONTINUE, "您有支付中的订单,是否继续支付");
         }
         //处理关闭订单
-        order.setStatus(DealStatusEnum.CLOSE);
+        order.setStatus(CLOSE);
         order.setMemo("关闭订单");
 
         
@@ -1215,7 +1214,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
             StudentRegistration studentRegistration = studentRegistrationService.getStudentRegister(musicGroupId, userId);
             //获取学员在乐团的状态,如果是在读,那么不处理人数
             if (studentRegistration.getMusicGroupStatus() == StudentMusicGroupStatusEnum.APPLY) {
-                List<StudentPaymentOrder> oldStudentPaymentOrderList = this.queryByCondition(GroupType.MUSIC, musicGroupId, userId, DealStatusEnum.SUCCESS, OrderTypeEnum.APPLY);
+                List<StudentPaymentOrder> oldStudentPaymentOrderList = this.queryByCondition(GroupType.MUSIC, musicGroupId, userId, SUCCESS, OrderTypeEnum.APPLY);
                 //判断是否有成功的订单,如果有,表示已经处理过人数
                 if (oldStudentPaymentOrderList == null || oldStudentPaymentOrderList.size() == 0) {
                     List<StudentPaymentOrderDetail> orderDetail = studentPaymentOrderDetailService.getOrderDetail(order.getId());
@@ -1305,14 +1304,6 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
         return studentPaymentOrderDao.getMemberIngOrder(member, status);
     }
 
-    @Autowired
-    private StudentRepairDao studentRepairDao;
-    @Autowired
-    private MusicGroupDao musicGroupDao;
-
-    @Autowired
-    private StudentGoodsSellDao studentGoodsSellDao;
-
     @Override
     @Transactional
     public Map createOrder(MallCreateOrderModel model) throws Exception {
@@ -1382,7 +1373,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
 
         studentPaymentOrder.setStatus(DealStatusEnum.ING);
         if (studentPaymentOrder.getActualAmount().compareTo(BigDecimal.ZERO) == 0) {
-            studentPaymentOrder.setStatus(DealStatusEnum.SUCCESS);
+            studentPaymentOrder.setStatus(SUCCESS);
         }
         studentPaymentOrder.setGroupType(GroupType.MALL_SELL);
         studentPaymentOrder.setUserId(model.getUserId());
@@ -1503,7 +1494,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
         Map<Integer, String> map = new HashMap<>();
         map.put(userId, userId.toString());
 
-        if (studentPaymentOrder.getStatus() == DealStatusEnum.SUCCESS) {
+        if (studentPaymentOrder.getStatus() == SUCCESS) {
             try {
                 contractService.transferProduceContract(userId, null, studentPaymentOrder.getType());
             } catch (Exception e) {
@@ -1627,7 +1618,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
             rechargeDetail.setAmount(amount);
             rechargeDetail.setBalance(cashAccount.getBalance().add(amount));
             rechargeDetail.setComment("缴费前充值");
-            rechargeDetail.setStatus(DealStatusEnum.SUCCESS);
+            rechargeDetail.setStatus(SUCCESS);
             rechargeDetail.setTransNo(studentPaymentOrder.getTransNo());
             rechargeDetail.setType(PlatformCashAccountDetailTypeEnum.RECHARGE);
             rechargeDetail.setUserId(userId);
@@ -1642,12 +1633,12 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
             paymentDetail.setAmount(amount.negate());
             paymentDetail.setBalance(cashAccount.getBalance());
             paymentDetail.setComment("商品销售");
-            paymentDetail.setStatus(DealStatusEnum.SUCCESS);
+            paymentDetail.setStatus(SUCCESS);
             paymentDetail.setTransNo(studentPaymentOrder.getTransNo());
             paymentDetail.setType(PlatformCashAccountDetailTypeEnum.GOODS_SELL);
             paymentDetail.setUserId(userId);
             sysUserCashAccountDetailService.insert(paymentDetail);
-        } else if (studentPaymentOrder.getStatus() == DealStatusEnum.CLOSE || studentPaymentOrder.getStatus() == DealStatusEnum.FAILED) {
+        } else if (studentPaymentOrder.getStatus() == CLOSE || studentPaymentOrder.getStatus() == DealStatusEnum.FAILED) {
 
             if (studentPaymentOrder.getBalancePaymentAmount() != null && studentPaymentOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
                 sysUserCashAccountService.updateBalance(studentPaymentOrder.getUserId(), studentPaymentOrder.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "商城购买支付失败");
@@ -1795,6 +1786,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
     @Transactional
     public OrderCancelModel cancelOrder(StudentPaymentOrder order, String reason) {
         OrderCancelModel model = new OrderCancelModel();
+        model.setSuccess(true);
         try {
             HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(order.getTenantId(), order.getPaymentChannel());
             if(hfMerchantConfig == null){
@@ -1831,22 +1823,28 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
                 model.setStatus(false);
                 order.setStatus(CLOSE);
                 order.setMemo(reason);
-            } else {
+            } else if (status.equals("pending")){
                 // 执行关单操作
+                Map<String, String> closeInfo = new HashMap<>();
                 if(StringUtils.equals(order.getPaymentChannel(), PaymentChannelEnum.ADAPAY.getCode())) {
-                    Payment.closeWithKey(order.getTransNo(),"", hfMerchantConfig.getMerKey());
+                    closeInfo = Payment.closeWithKey(order.getTransNo(), "", hfMerchantConfig.getMerKey());
                 }else if(StringUtils.equals(order.getPaymentChannel(), PaymentChannelEnum.YEEPAY.getCode())) {
-                    yeepayPaymentService.close(hfMerchantConfig, order.getTransNo(),"", order.getOrderNo());
+                    closeInfo = yeepayPaymentService.close(hfMerchantConfig, order.getTransNo(), "", order.getOrderNo());
                 }
+                boolean success = "success".equals(closeInfo.get("status"));
                 model.setStatus(false);
                 order.setStatus(CLOSE);
+                model.setSuccess(success);
+                model.setMessage(closeInfo.get("msg"));
+            }
+            if (model.getSuccess()) {
+                TenantContextHolder.setTenantId(order.getTenantId());
+                callOrderCallBack(order);
+                TenantContextHolder.clearTenantId();
             }
-            TenantContextHolder.setTenantId(order.getTenantId());
-            callOrderCallBack(order);
-            TenantContextHolder.clearTenantId();
-            model.setSuccess(true);
-        } catch (Exception e) {
+        }catch (Exception e) {
             model.setSuccess(false);
+            model.setMessage(e.getMessage());
             logger.error("订单[{}]取消失败", order.getTransNo(), e);
         }
         return model;
@@ -2218,50 +2216,48 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
             return;
         }
         List<String> orderNos = orderSkuSyncs.stream().map(e -> e.getOrderNo()).collect(Collectors.toList());
+        Map<String, List<OrderSkuSync.SkuSync>> skuMap = orderSkuSyncs.stream().collect(Collectors.toMap(OrderSkuSync::getOrderNo, OrderSkuSync::getSkuSyncList));
         List<SellOrder> sellOrders = sellOrderDao.queryByOrganNos(orderNos);
+        //检查学校商品采购订单
+        List<MusicGroupPaymentCalenderAddress> calenderAddresses = musicGroupPaymentCalenderAddressService.lambdaQuery().
+                in(MusicGroupPaymentCalenderAddress::getOrderNo, orderNos).
+                eq(MusicGroupPaymentCalenderAddress::getDeliveryFlag, false).list();
+        if (CollectionUtils.isNotEmpty(calenderAddresses)) {
+            Map<String, MusicGroupPaymentCalenderAddress> addressMap = calenderAddresses.stream().
+                    collect(Collectors.toMap(MusicGroupPaymentCalenderAddress::getOrderNo, e -> e));
+            List<String> addressOrders = calenderAddresses.stream().map(MusicGroupPaymentCalenderAddress::getOrderNo).collect(Collectors.toList());
+            for (String addressOrder : addressOrders) {
+                MusicGroupPaymentCalenderAddress address = addressMap.get(addressOrder);
+                address.setDeliveryDetail(JSON.toJSONString(skuMap.get(addressOrder)));
+                address.setDeliveryFlag(true);
+            }
+            musicGroupPaymentCalenderAddressService.updateBatchById(calenderAddresses);
+        }
         if (CollectionUtils.isEmpty(sellOrders)) {
-            throw new BizException("订单不存在");
+            return;
         }
         sellOrders = sellOrders.stream().filter(e -> e.getDeliveryTime() == null).collect(Collectors.toList());
         if(CollectionUtils.isEmpty(sellOrders)){
             return;
         }
+        String format = DateUtil.format(new Date(), DateUtil.ISO_EXPANDED_DATE_FORMAT);
         Map<String,List<SellOrder>> sellOrderMap = sellOrders.stream().collect(Collectors.groupingBy(SellOrder::getOrderNo));
-        Map<String,Map<Long,BigDecimal>> skuCostMap = new HashMap<>(orderSkuSyncs.size());
         for (OrderSkuSync orderSkuSync : orderSkuSyncs) {
             List<SellOrder> dtos = sellOrderMap.get(orderSkuSync.getOrderNo());
             if(CollectionUtils.isEmpty(dtos)){
                 continue;
             }
-            //获取sku平均成本价
-            Map<Long,List<OrderSkuSync.SkuSync>> skuMap = orderSkuSync.getSkuSyncList().stream().collect(Collectors.groupingBy(OrderSkuSync.SkuSync::getSku));
-            Map<Long,BigDecimal> costMap = new HashMap<>(skuMap.keySet().size());
-            for (Long skuId : skuMap.keySet()) {
-                List<OrderSkuSync.SkuSync> skuSyncs = skuMap.get(skuId);
-                //汇总成本价
-                BigDecimal costPrice = skuSyncs.stream().map(e -> e.getPrice().multiply(new BigDecimal(e.getCount()))).reduce(BigDecimal.ZERO, BigDecimal::add);
-                //获取总数
-                int count = skuSyncs.stream().mapToInt(e -> e.getCount()).sum();
-                BigDecimal avgCostPrice = costPrice;
-                if (count > 1) {
-                    avgCostPrice = costPrice.divide(new BigDecimal(count), 2, BigDecimal.ROUND_HALF_UP);
-                }
-                costMap.put(skuId,avgCostPrice);
-            }
-            skuCostMap.put(orderSkuSync.getOrderNo(),costMap);
-        }
-        Date now = new Date();
-        String format = DateUtil.format(now, DateUtil.ISO_EXPANDED_DATE_FORMAT);
-        for (String orderNo : sellOrderMap.keySet()) {
-            List<SellOrder> sellOrderList = sellOrderMap.get(orderNo);
-            Map<Long,BigDecimal> costMap = skuCostMap.get(orderNo);
-            for (SellOrder sellOrder : sellOrderList) {
-                BigDecimal costPrice = costMap.get(sellOrder.getGoodsSkuId().longValue());
-                if(costPrice == null){
-                    throw new BizException("商品[{}]成本价不存在",sellOrder.getGoodsSkuId());
+            Map<Long,List<SellOrder>> goodsSkuMap = dtos.stream().collect(Collectors.groupingBy(e->e.getGoodsSkuId().longValue()));
+            for (OrderSkuSync.SkuSync skuSync : orderSkuSync.getSkuSyncList()) {
+                List<SellOrder> sellOrderList = goodsSkuMap.get(skuSync.getSku());
+                for (int i = 0; i < skuSync.getCount(); i++) {
+                    SellOrder sellOrder = sellOrderList.get(i);
+                    if (sellOrder != null) {
+                        sellOrder.setDeliveryTime(format);
+                        sellOrder.setSellCost(skuSync.getPrice());
+                        sellOrder.setStockType(StringUtils.equalsIgnoreCase(skuSync.getType(),"INTERNAL")?StockType.INTERNAL:StockType.EXTERNAL);
+                    }
                 }
-                sellOrder.setSellCost(costPrice);
-                sellOrder.setDeliveryTime(format);
             }
         }
         sellOrderDao.batchUpdate(sellOrders);

+ 105 - 77
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentRouteOrderServiceImpl.java

@@ -11,12 +11,14 @@ import com.alibaba.fastjson.JSONArray;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dao.*;
+import com.ym.mec.biz.dal.dto.ComplementGoodsDto;
 import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.enums.*;
-import com.ym.mec.biz.service.MusicGroupCalenderRefundPeriodService;
+import com.ym.mec.biz.service.*;
 import com.ym.mec.common.api.CommonResult;
 import com.ym.mec.common.dto.OrderCreate;
 import com.ym.mec.common.entity.HttpResponseResult;
+import com.ym.mec.common.entity.OrderSkuSync;
 import com.ym.mec.common.tenant.TenantContextHolder;
 import com.ym.mec.mall.MallFeignService;
 import com.ym.mec.util.date.DateUtil;
@@ -35,9 +37,6 @@ import com.alibaba.fastjson.JSONObject;
 import com.ym.mec.biz.dal.dto.PageInfoOrder;
 import com.ym.mec.biz.dal.dto.StudentPaymentRouteOrderDto;
 import com.ym.mec.biz.dal.page.StudentPaymentOrderQueryInfo;
-import com.ym.mec.biz.service.GoodsService;
-import com.ym.mec.biz.service.SellOrderService;
-import com.ym.mec.biz.service.StudentPaymentRouteOrderService;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
@@ -56,7 +55,7 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
     @Autowired
     private SysUserCashAccountDao sysUserCashAccountDao;
     @Autowired
-    private StudentPaymentOrderDao studentPaymentOrderDao;
+    private StudentPaymentOrderService studentPaymentOrderService;
     @Autowired
     private IdGeneratorService idGeneratorService;
     @Autowired
@@ -64,8 +63,6 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
     @Autowired
     private GoodsDao goodsDao;
     @Autowired
-    private GoodsService goodsService;
-    @Autowired
     private SellOrderService sellOrderService;
     @Autowired
     private SysUserFeignService sysUserFeignService;
@@ -79,6 +76,14 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
     private MusicGroupCalenderRefundPeriodService musicGroupCalenderRefundPeriodService;
     @Autowired
     private MallFeignService mallFeignService;
+    @Autowired
+    private MusicGroupPaymentCalenderAddressService musicGroupPaymentCalenderAddressService;
+    @Autowired
+    private MusicGroupPaymentCalenderGoodsService musicGroupPaymentCalenderGoodsService;
+    @Autowired
+    private SysPaymentConfigService sysPaymentConfigService;
+    @Autowired
+    private MusicGroupDao musicGroupDao;
 
     @Override
     public BaseDAO<Long, StudentPaymentRouteOrder> getDAO() {
@@ -151,6 +156,11 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
             if (musicGroupPaymentCalender == null) {
                 throw new BizException("学校缴费单号(审核通过)不存在,请核查");
             }
+            if(musicGroupPaymentCalender.getPaymentType() == MusicGroupPaymentCalender.PaymentType.GOODS_PURCHASE){
+                studentPaymentRouteOrder.setSaleAmount(studentPaymentRouteOrder.getRouteAmount());
+            }else {
+                studentPaymentRouteOrder.setServiceAmount(studentPaymentRouteOrder.getRouteAmount());
+            }
         }
         Date nowDate = new Date();
         String orderNo = idGeneratorService.generatorId("payment") + "";
@@ -200,12 +210,28 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
         studentPaymentRouteOrder.setUpdateTime(nowDate);
         studentPaymentRouteOrder.setAuditComment(memo);
         studentPaymentRouteOrder.setAuditStatus(auditStatus);
+        MusicGroupPaymentCalender musicGroupPaymentCalender = null;
+        MusicGroupPaymentCalenderAddress address = null;
+        MusicGroup musicGroup = null;
+        //是否同步过商城的发货数据
+        Boolean syncFlag = true;
         if (auditStatus == AuditStatusEnum.PASS) {
+            if (studentPaymentRouteOrder.getCalenderId() != null) {
+                musicGroupPaymentCalender = musicGroupPaymentCalenderDao.get(studentPaymentRouteOrder.getCalenderId());
+                musicGroup = musicGroupDao.get(musicGroupPaymentCalender.getMusicGroupId());
+                if(musicGroupPaymentCalender.getPaymentType() == MusicGroupPaymentCalender.PaymentType.GOODS_PURCHASE){
+                    address = musicGroupPaymentCalenderAddressService.lambdaQuery().
+                            eq(MusicGroupPaymentCalenderAddress::getCalenderId, studentPaymentRouteOrder.getCalenderId()).one();
+                    StudentPaymentOrder addressOrder = studentPaymentOrderService.findOrderByOrderNo(address.getOrderNo());
+                    syncFlag = Objects.nonNull(addressOrder);
+                    if (!syncFlag){
+                        orderNo = address.getOrderNo();
+                    }
+                }
+            }
             studentPaymentRouteOrder.setOrderNo(orderNo);
         }
-
         studentPaymentRouteOrderDao.update(studentPaymentRouteOrder);
-
         if (auditStatus == AuditStatusEnum.PASS) {
             StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
             studentPaymentOrder.setActualAmount(studentPaymentRouteOrder.getRouteAmount());
@@ -236,7 +262,6 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
             studentPaymentRouteOrderDao.insertOrder(studentPaymentOrder);
 
             if (StringUtils.isNoneBlank(studentPaymentRouteOrder.getGoodsJson())) {
-                BigDecimal hasRouteAmount = BigDecimal.ZERO;
                 BigDecimal goodsTotalPrice = BigDecimal.ZERO;
 
                 List<Integer> goodsIdList = new ArrayList<>();
@@ -250,70 +275,8 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
                         goodsIdList.add(goodsId);
                     }
                 }
-//                List<SellOrder> sellOrderList = goodsService.subtractStock(goodsIdList, AccountType.INTERNAL);
-                List<SellOrder> sellOrders = sellOrderService.initSellOrder(studentPaymentOrder, null, goodsIdList, null, false);
+                List<SellOrder> sellOrders = sellOrderService.initSellOrder(studentPaymentOrder, musicGroup==null?null:musicGroup.getId(), goodsIdList, null, false);
                 sellOrderService.batchInsert(sellOrders);
-                /*int i = 1;
-                for (Entry<String, Object> goodsMap : jsonObj.entrySet()) {
-                    Integer goodsId = Integer.parseInt(goodsMap.getKey());
-                    Integer nums = Integer.parseInt(goodsMap.getValue().toString());
-                    Goods goods = goodsDao.get(goodsId);
-
-                    BigDecimal actualAmount = BigDecimal.ZERO;
-                    if (goodsTotalPrice.compareTo(BigDecimal.ZERO) != 0) {
-                        actualAmount = studentPaymentRouteOrder.getSaleAmount().multiply(goods.getGroupPurchasePrice().multiply(new BigDecimal(nums))).divide(goodsTotalPrice, 2, BigDecimal.ROUND_DOWN);
-                    }
-                    if (i == jsonObj.entrySet().size()) {
-                        actualAmount = studentPaymentRouteOrder.getSaleAmount().subtract(hasRouteAmount);
-                    }
-                    hasRouteAmount = hasRouteAmount.add(actualAmount);
-                    i++;
-
-                    int complementNum = goods.getComplementGoodsIdList() == null ? 1 : goods.getComplementGoodsIdList().split(",").length;
-                    int goodsNum = nums * complementNum;
-                    BigDecimal complementPrice = goods.getGroupPurchasePrice().multiply(new BigDecimal(nums));
-                    Map<Integer, BigDecimal> complementGoodsPrice = new HashMap<>();
-                    complementGoodsPrice.put(goods.getId(), goods.getGroupPurchasePrice());
-                    if (goods.getComplementGoodsIdList() != null) {
-                        List<Goods> complementGoodies = goodsDao.findGoodsByIds(goods.getComplementGoodsIdList());
-                        complementGoodsPrice = complementGoodies.stream().collect(Collectors.toMap(Goods::getId, Goods::getGroupPurchasePrice));
-                        complementPrice = complementGoodies.stream().map(Goods::getGroupPurchasePrice).reduce(BigDecimal.ZERO, BigDecimal::add).multiply(new BigDecimal(nums));
-                    }
-
-                    BigDecimal hasRouteSellOrderActualAmount = BigDecimal.ZERO;
-                    for (SellOrder sellOrder : sellOrderList) {
-                        if (!Integer.valueOf(goodsMap.getKey()).equals(sellOrder.getParentGoodsId()) && !Integer.valueOf(goodsMap.getKey()).equals(sellOrder.getGoodsId())) {
-                            continue;
-                        }
-                        BigDecimal sellOrderActualAmount = BigDecimal.ZERO;
-                        if (complementPrice.compareTo(BigDecimal.ZERO) > 0) {
-                            sellOrderActualAmount = complementGoodsPrice.get(sellOrder.getGoodsId()).multiply(new BigDecimal(sellOrder.getNum())).multiply(actualAmount).divide(complementPrice, 2, BigDecimal.ROUND_DOWN);
-                        }
-                        goodsNum = goodsNum - sellOrder.getNum();
-                        if (goodsNum <= 0) {
-                            sellOrderActualAmount = actualAmount.subtract(hasRouteSellOrderActualAmount);
-                        }
-                        hasRouteSellOrderActualAmount = hasRouteSellOrderActualAmount.add(sellOrderActualAmount);
-
-                        sellOrder.setSellTime(studentPaymentRouteOrder.getPayTime());
-                        sellOrder.setOrganId(studentPaymentRouteOrder.getRouteOrganId());
-                        sellOrder.setCooperationOrganId(studentPaymentRouteOrder.getSchoolId());
-                        sellOrder.setTransNo(studentPaymentRouteOrder.getTransNo());
-                        sellOrder.setOrderId(studentPaymentOrder.getId());
-                        sellOrder.setOrderNo(studentPaymentRouteOrder.getOrderNo());
-                        sellOrder.setActualAmount(sellOrderActualAmount);
-                        sellOrder.setBalanceAmount(BigDecimal.ZERO);
-                        sellOrder.setExpectAmount(sellOrderActualAmount);
-                        sellOrder.setUserId(studentPaymentRouteOrder.getUserId());
-                        sellOrder.setPaymentChannel(studentPaymentOrder.getPaymentChannel());
-                        sellOrder.setMerNo(studentPaymentRouteOrder.getMerNo());
-                        sellOrder.setSellTime(studentPaymentRouteOrder.getCreateTime());
-                        sellOrder.setCreateIme(nowDate);
-                        sellOrder.setUpdateTime(nowDate);
-                        sellOrder.setType(SellTypeEnum.SCHOOL_BUY);
-                    }
-                }
-                sellOrderDao.batchInsert(sellOrderList);*/
                 if(calender == null || calender.getPaymentType() != MusicGroupPaymentCalender.PaymentType.GOODS_PURCHASE){
                     OrderCreate mallOrder = new OrderCreate();
                     mallOrder.setOrchestraId(studentPaymentOrder.getMusicGroupId());
@@ -352,6 +315,73 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
             if (studentPaymentRouteOrder.getCalenderId() == null) {
                 return true;
             }
+            //同步商城的发货数据
+            if(!syncFlag){
+                List<MusicGroupPaymentCalenderGoods> calenderGoods = musicGroupPaymentCalenderGoodsService.lambdaQuery()
+                        .eq(MusicGroupPaymentCalenderGoods::getCalenderId, studentPaymentRouteOrder.getCalenderId()).list();
+                List<SellOrder> sellOrderList = new ArrayList<>();
+                for (MusicGroupPaymentCalenderGoods calenderGood : calenderGoods) {
+                    //待分配金额
+                    for (Integer i = 0; i < calenderGood.getNum(); i++) {
+                        List<ComplementGoodsDto> goodsDtoList = JSON.parseArray(calenderGood.getChildGoodsJson(), ComplementGoodsDto.class);
+                        //获取总成本
+                        BigDecimal totalCostPrice = goodsDtoList.stream().map(e->e.getOrganCostPrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
+                        //待分配金额
+                        BigDecimal totalAmount = calenderGood.getSinglePrice();
+                        BigDecimal waitAmount = totalAmount;
+                        for (int j = 0; j < goodsDtoList.size(); j++) {
+                            ComplementGoodsDto goodsDto = goodsDtoList.get(j);
+                            //获取比例
+                            BigDecimal proportion = BigDecimal.ZERO;
+                            if (totalCostPrice.compareTo(BigDecimal.ZERO) > 0) {
+                                proportion = goodsDto.getOrganCostPrice().divide(totalCostPrice, 2, BigDecimal.ROUND_HALF_UP);
+                            }
+                            SellOrder sellOrder = new SellOrder();
+                            sellOrder.setGoodsSkuId(goodsDto.getSkuStockId());
+                            sellOrder.setOrganSellCost(goodsDto.getOrganCostPrice());
+                            sellOrder.setOrderId(studentPaymentOrder.getOrganId().longValue());
+                            sellOrder.setType(StringUtils.endsWithIgnoreCase("INSTRUMENT", calenderGood.getGoodsType()) ? SellTypeEnum.INSTRUMENT
+                                    : StringUtils.endsWithIgnoreCase("ACCESSORIES", calenderGood.getGoodsType()) ? SellTypeEnum.ACCESSORIES
+                                    : StringUtils.endsWithIgnoreCase("TEACHING", calenderGood.getGoodsType()) ? SellTypeEnum.TEACHING
+                                    : StringUtils.endsWithIgnoreCase("STAFF", calenderGood.getGoodsType()) ? SellTypeEnum.STAFF
+                                    : SellTypeEnum.OTHER);
+                            sellOrder.setOrderNo(orderNo);
+                            if (j == goodsDtoList.size() - 1) {
+                                sellOrder.setOrderAmount(waitAmount);
+                            } else {
+                                BigDecimal amount = totalAmount.multiply(proportion);
+                                waitAmount = waitAmount.subtract(amount);
+                                sellOrder.setOrderAmount(amount);
+                            }
+                            sellOrder.setActualAmount(sellOrder.getOrderAmount());
+                            sellOrder.setExpectAmount(sellOrder.getOrderAmount());
+                            sellOrder.setCouponRemitAmount(BigDecimal.ZERO);
+                            sellOrder.setBalanceAmount(BigDecimal.ZERO);
+                            sellOrder.setParentGoodsId(calenderGood.getGoodsId());
+                            sellOrder.setNum(1);
+                            sellOrder.setGoodsName(calenderGood.getGoodsName());
+                            sellOrder.setAccountType(AccountType.INTERNAL);
+                            sellOrder.setCooperationOrganId(musicGroup.getCooperationOrganId());
+                            sellOrder.setEduTeacherId(musicGroup.getEducationalTeacherId());
+                            sellOrder.setTransNo(studentPaymentOrder.getTransNo());
+                            sellOrder.setPaymentChannel(studentPaymentOrder.getPaymentChannel());
+                            sellOrder.setMerNo(studentPaymentOrder.getMerNos());
+                            sellOrder.setSellTime(studentPaymentOrder.getCreateTime());
+                            sellOrder.setTenantId(studentPaymentOrder.getTenantId());
+                            sellOrderList.add(sellOrder);
+                        }
+                    }
+                }
+                sellOrderService.batchInsert(sellOrderList);
+                if(address.getDeliveryFlag()){
+                    OrderSkuSync orderSkuSync = new OrderSkuSync();
+                    orderSkuSync.setOrderNo(orderNo);
+                    orderSkuSync.setSkuSyncList(JSONArray.parseArray(address.getAddress(), OrderSkuSync.SkuSync.class));
+                    List<OrderSkuSync> orderSkuSyncs = new ArrayList<>();
+                    orderSkuSyncs.add(orderSkuSync);
+                    studentPaymentOrderService.updateShippedStatus(orderSkuSyncs);
+                }
+            }
 
             //根据学校缴费项id,确定缴费状态
 //            BigDecimal amount = studentPaymentRouteOrderDao.sumAmountByCalenderId(studentPaymentRouteOrder.getCalenderId());
@@ -361,8 +391,6 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
             //是否已完成回款
             if(aBoolean){
                 List<MusicGroupPaymentCalenderDetail> calenderDetails = musicGroupPaymentCalenderDetailDao.getCalenderDetailWithCalender(studentPaymentRouteOrder.getCalenderId());
-                MusicGroupPaymentCalender musicGroupPaymentCalender = musicGroupPaymentCalenderDao.get(studentPaymentRouteOrder.getCalenderId());
-
                 if (studentPaymentRouteOrder.getRouteAmount().compareTo(musicGroupPaymentCalender.getCurrentTotalAmount()) >= 0) {
                     musicGroupPaymentCalender.setActualNum(musicGroupPaymentCalender.getExpectNum());
                     musicGroupPaymentCalender.setStatus(MusicGroupPaymentCalender.PaymentCalenderStatusEnum.PAID);
@@ -398,11 +426,11 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Boolean deleteRouteOrder(Long orderId) {
-        StudentPaymentOrder studentPaymentOrder = studentPaymentOrderDao.get(orderId);
+        StudentPaymentOrder studentPaymentOrder = studentPaymentOrderService.get(orderId);
         if (studentPaymentOrder == null) {
             throw new BizException("订单不存在,请核查");
         }
-        studentPaymentOrderDao.delete(orderId);
+        studentPaymentOrderService.delete(orderId);
         studentPaymentRouteOrderDao.deleteByOrderNo(studentPaymentOrder.getOrderNo());
         //归还库存
         List<SellOrder> sellOrders = sellOrderService.getSellOrderByParentGoodsId(orderId, null);

+ 33 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRepairServiceImpl.java

@@ -14,7 +14,10 @@ import java.util.stream.Collectors;
 
 import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.service.*;
+import com.ym.mec.common.dto.BrandDto;
+import com.ym.mec.mall.MallFeignService;
 import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang.math.NumberUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -99,6 +102,9 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
     @Autowired
     private GoodsProcurementDao goodsProcurementDao;
 
+    @Autowired
+    private StudentPaymentOrderAddressService studentPaymentOrderAddressService;
+
     @Lazy
     @Autowired
     private ContractService contractService;
@@ -112,6 +118,8 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
     private SysCouponCodeService sysCouponCodeService;
     @Autowired
     private TeacherService teacherService;
+    @Autowired
+    private MallFeignService mallFeignService;
 
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
@@ -172,6 +180,14 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
     public Map addGoodsSellOrder(StudentGoodsSell studentGoodsSell) throws Exception {
         //关闭老订单
+        StudentPaymentOrderAddress studentPaymentOrderAddress = null;
+        if (StringUtils.isNotBlank(studentGoodsSell.getAddress())) {
+            studentPaymentOrderAddress = new StudentPaymentOrderAddress();
+            studentPaymentOrderAddress.setAddress(studentGoodsSell.getAddress());
+            studentPaymentOrderAddress.setContactMobile(studentGoodsSell.getContactMobile());
+            studentPaymentOrderAddress.setContactName(studentGoodsSell.getContactName());
+        }
+
         if (StringUtils.isNotEmpty(studentGoodsSell.getOrderNo())) {
             StudentPaymentOrder orderByOrderNo = studentPaymentOrderService.findOrderByOrderNo(studentGoodsSell.getOrderNo());
             if (orderByOrderNo.getBalancePaymentAmount() != null && orderByOrderNo.getBalancePaymentAmount().longValue() != 0l) {
@@ -336,6 +352,10 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         }
         studentGoodsSell.setTenantId(student.getTenantId());
         studentGoodsSellDao.insert(studentGoodsSell);
+        if (studentPaymentOrderAddress !=null) {
+            studentPaymentOrderAddress.setOrderNo(orderNo);
+            studentPaymentOrderAddressService.save(studentPaymentOrderAddress);
+        }
 
         if (studentGoodsSell.getType() == 1) {
             Map<String, Object> repairInfoMap = new HashMap<>();
@@ -871,6 +891,19 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
             List<Integer> collect = Arrays.stream(couponIds.split(",")).map(e -> Integer.valueOf(e)).collect(Collectors.toList());
             repairInfo.setCouponCodeDtos(sysCouponCodeService.findByIdList(collect));
         }
+        String goodsJson = repairInfo.getGoodsJson();
+        if (StringUtils.isNotEmpty(goodsJson)) {
+            JSONArray goods = JSON.parseArray(repairInfo.getGoodsJson());
+            Map<Long, String> brandIdNameMap = mallFeignService.getList().stream().collect(Collectors.toMap(BrandDto::getId, BrandDto::getName));
+            for (Object good : goods) {
+                JSONObject goodObject = (JSONObject) good;
+                String brand = goodObject.getString("brand");
+                if (Objects.nonNull(brand) && NumberUtils.isNumber(brand)) {
+                    goodObject.put("brandName", brandIdNameMap.getOrDefault(Long.valueOf(brand), ""));
+                }
+            }
+            repairInfo.setGoodsJson(JSON.toJSONString(goods));
+        }
         return repairInfo;
     }
 

+ 35 - 203
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SubjectChangeServiceImpl.java

@@ -446,11 +446,6 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
             throw new BizException("已有未支付的声部更改,请勿重复创建");
         }
 
-        /*studentWaitPay = subjectChangeDao.getStudentLastChange(subjectChange.getStudentId(), musicGroupId);
-        if (studentWaitPay != null) {
-            throw new BizException("声部更换只能操作一次,请勿重复操作");
-        }*/
-
         Set<String> musicGroupIds = new HashSet<String>();
         musicGroupIds.add(musicGroupId);
 
@@ -527,15 +522,8 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
         } else {
             subjectChange.setChangeAccessories(null);
         }
-        BigDecimal goodsPrice = BigDecimal.ZERO;
         List<Goods> goodies = goodsDao.findGoodsByIds(goodsIds);
-        for (Goods goods : goodies) {
-            goodsPrice = goodsPrice.add(goods.getDiscountPrice());
-        }
-        subjectChange.setChangeCost(goodsPrice);
-        
-        Map<Integer,Goods> goodsMap = goodies.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
-        
+        subjectChange.setChangeCost(goodies.stream().map(Goods::getDiscountPrice).reduce(BigDecimal.ZERO, BigDecimal::add));
         subjectChange.setCostMargin(subjectChange.getChangeCost().subtract(subjectChange.getOriginalCost()));
         //差价 <= 0
         BigDecimal amountMargin = subjectChange.getGoodsMargin().add(subjectChange.getCourseMargin());
@@ -552,7 +540,6 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
         subjectChangeDao.insert(subjectChange);
         //差价小于0退到余额
         if (amountMargin.compareTo(BigDecimal.ZERO) <= 0) {
-            //sysUserCashAccountService.updateBalance(subjectChange.getStudentId(), amountMargin.negate(), PlatformCashAccountDetailTypeEnum.REFUNDS, "声部更换退还");
             if (amountMargin.compareTo(BigDecimal.ZERO) < 0) {
                 SysUserCashAccountLog sysUserCashAccountLog = new SysUserCashAccountLog();
                 sysUserCashAccountLog.setUserId(subjectChange.getStudentId());
@@ -592,205 +579,50 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
 
             //添加订单详情
             List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<StudentPaymentOrderDetail>();
-            StudentPaymentOrderDetail studentPaymentOrderDetail = null;
-        	Goods goods = null;
-			List<Integer> minuendStockGoodsIdList = null;
-			GoodsProcurement goodsProcurement = null;
-			Map<Long, GoodsProcurement> goodsProcurementMap = new HashMap<Long, GoodsProcurement>();
-			Map<Integer, Goods> batchUpdateGoodsMap = new HashMap<Integer, Goods>();
-			
-            for(String goodsIdStr : goodsIds.split(",")){
-        		if(StringUtils.isBlank(goodsIdStr)){
-					continue;
-				}
-				goods = goodsMap.get(Integer.parseInt(goodsIdStr));
-				
-				if(goods != null){
-					studentPaymentOrderDetail = new StudentPaymentOrderDetail();
-	                studentPaymentOrderDetail.setCreateTime(nowDate);
-	                if(goods.getType() == GoodsType.INSTRUMENT){
-	                	studentPaymentOrderDetail.setType(OrderDetailTypeEnum.MUSICAL);
-	                	studentPaymentOrderDetail.setKitGroupPurchaseType(subjectChange.getKitGroupPurchaseType());
-	                }else if(goods.getType() == GoodsType.ACCESSORIES){
-	                	studentPaymentOrderDetail.setType(OrderDetailTypeEnum.ACCESSORIES);
-	                }else if(goods.getType() == GoodsType.TEACHING || goods.getType() == GoodsType.STAFF){
-	                	studentPaymentOrderDetail.setType(OrderDetailTypeEnum.TEACHING);
-	                }else{
-	                	studentPaymentOrderDetail.setType(OrderDetailTypeEnum.OTHER);
-	                }
-	                studentPaymentOrderDetail.setGoodsIdList(goodsIdStr);
-                	studentPaymentOrderDetail.setPrice(BigDecimal.ZERO);
-	                studentPaymentOrderDetail.setUpdateTime(nowDate);
-	                studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
-	              
-	                //忽略的分部
-	        		List<Integer> ignoreOrganList = Arrays.asList(4, 55, 59);
-	        		
-	        		//查询商品收款账户配置
-	                String goodsSellReceiptMerNo = sysConfigDao.findConfigValue("goodsSellReceiptMerNo");
-	                
-	                if(!ignoreOrganList.contains(subjectChange.getOrganId()) && StringUtils.isNotBlank(goodsSellReceiptMerNo)){
-	                	//扣减库存
-						
-						BigDecimal totalGroupPurchaseAmount = BigDecimal.ZERO;
-						
-						BigDecimal groupPurchaseAmount = BigDecimal.ZERO;
-						
-						minuendStockGoodsIdList = new ArrayList<Integer>();
-						
-						// 是否是组合商品
-						if(StringUtils.isNotBlank(goods.getComplementGoodsIdList())){
-							List<Goods> goodsList = goodsService.getGoodsWithLocked(goods.getComplementGoodsIdList());
-							totalGroupPurchaseAmount =  totalGroupPurchaseAmount.add(goodsList.stream().map(Goods :: getGroupPurchasePrice).reduce(BigDecimal.ZERO,BigDecimal :: add));
-							
-							for(Goods subGoods : goodsList){
-								
-								if(batchUpdateGoodsMap.get(subGoods.getId()) != null){
-									subGoods = batchUpdateGoodsMap.get(subGoods.getId());
-								}
-								//判断是否有内部库存
-								if(subGoods.getStockCount() > 0){
-									
-									groupPurchaseAmount = groupPurchaseAmount.add(subGoods.getGroupPurchasePrice());
-									subGoods.setStockCount(new AtomicInteger(subGoods.getStockCount()).decrementAndGet());
-									subGoods.setSellCount(new AtomicInteger(subGoods.getSellCount()).incrementAndGet());
-									subGoods.setUpdateTime(nowDate);
-									
-									batchUpdateGoodsMap.put(subGoods.getId(), subGoods);
-									
-									minuendStockGoodsIdList.add(subGoods.getId());
-									
-									goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(subGoods.getId());
-									if(goodsProcurement != null){
-										if(goodsProcurementMap.get(goodsProcurement.getId()) != null){
-											goodsProcurement = goodsProcurementMap.get(goodsProcurement.getId());
-										}
-										goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).incrementAndGet());
-										goodsProcurement.setUpdateTime(nowDate);
-										goodsProcurementMap.put(goodsProcurement.getId(), goodsProcurement);
-									}
-								}
-							}
-						}else{
-							totalGroupPurchaseAmount = totalGroupPurchaseAmount.add(goods.getGroupPurchasePrice());
-							
-							if(batchUpdateGoodsMap.get(goods.getId()) != null){
-								goods = batchUpdateGoodsMap.get(goods.getId());
-							}
-							
-							//判断是否有内部库存
-							if(goods.getStockCount() > 0){
-								
-								groupPurchaseAmount = groupPurchaseAmount.add(goods.getGroupPurchasePrice());
-								goods.setStockCount(new AtomicInteger(goods.getStockCount()).decrementAndGet());
-								goods.setSellCount(new AtomicInteger(goods.getSellCount()).incrementAndGet());
-								goods.setUpdateTime(nowDate);
-								batchUpdateGoodsMap.put(goods.getId(), goods);
-								
-								minuendStockGoodsIdList.add(goods.getId());
-								
-								goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(goods.getId());
-								if(goodsProcurement != null){
-									if(goodsProcurementMap.get(goodsProcurement.getId()) != null){
-										goodsProcurement = goodsProcurementMap.get(goodsProcurement.getId());
-									}
-									goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).incrementAndGet());
-									goodsProcurement.setUpdateTime(nowDate);
-									goodsProcurementMap.put(goodsProcurement.getId(), goodsProcurement);
-								}
-							}
-						}
-						
-						if (minuendStockGoodsIdList.size() > 0) {
-							studentPaymentOrderDetail.setIncomeItem(OrderDetailTypeEnum.CLOUD_TEACHER.name());
-							studentPaymentOrderDetail.setIncome(BigDecimal.ZERO);
-							studentPaymentOrderDetail.setBalanceIncome(BigDecimal.ZERO);
-							if(minuendStockGoodsIdList.size() > 0){
-								studentPaymentOrderDetail.setMinuendStockGoodsIdList(minuendStockGoodsIdList.stream().map(t -> t.toString()).collect(Collectors.joining(",")));
-							}
-						}
-	                }
-	                studentPaymentOrderDetail.setTenantId(studentPaymentOrder.getTenantId());
-	                
-	                studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
-	                
-	                //分部分润
-	                if(subjectChange.getChangeCourseFee().compareTo(BigDecimal.ZERO) > 0 && studentPaymentOrderDetail.getKitGroupPurchaseType() == KitGroupPurchaseTypeEnum.GROUP) {
-	                	StudentPaymentOrderDetail spod = new StudentPaymentOrderDetail();
-	                    spod.setType(OrderDetailTypeEnum.ORGAN_SHARE_PROFIT);
-	                    spod.setPrice(subjectChange.getChangeCourseFee());
-	                    spod.setRemitFee(BigDecimal.ZERO);
-	                    spod.setCreateTime(nowDate);
-	                    spod.setUpdateTime(nowDate);
-	                    spod.setPaymentOrderId(studentPaymentOrder.getId());
-	                    spod.setTenantId(studentPaymentOrder.getTenantId());
-	                    studentPaymentOrderDetailList.add(spod);
-	                }
-				}
+            for (Goods goods : goodies) {
+                StudentPaymentOrderDetail studentPaymentOrderDetail = new StudentPaymentOrderDetail();
+                studentPaymentOrderDetail.setCreateTime(nowDate);
+                if(goods.getType() == GoodsType.INSTRUMENT){
+                    studentPaymentOrderDetail.setType(OrderDetailTypeEnum.MUSICAL);
+                    studentPaymentOrderDetail.setKitGroupPurchaseType(subjectChange.getKitGroupPurchaseType());
+                }else if(goods.getType() == GoodsType.ACCESSORIES){
+                    studentPaymentOrderDetail.setType(OrderDetailTypeEnum.ACCESSORIES);
+                }else if(goods.getType() == GoodsType.TEACHING || goods.getType() == GoodsType.STAFF){
+                    studentPaymentOrderDetail.setType(OrderDetailTypeEnum.TEACHING);
+                }else{
+                    studentPaymentOrderDetail.setType(OrderDetailTypeEnum.OTHER);
+                }
+                studentPaymentOrderDetail.setGoodsIdList(goods.getId().toString());
+                studentPaymentOrderDetail.setPrice(BigDecimal.ZERO);
+                studentPaymentOrderDetail.setUpdateTime(nowDate);
+                studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
+                studentPaymentOrderDetail.setTenantId(studentPaymentOrder.getTenantId());
+                studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
+                //分部分润
+                if(subjectChange.getChangeCourseFee().compareTo(BigDecimal.ZERO) > 0 && studentPaymentOrderDetail.getKitGroupPurchaseType() == KitGroupPurchaseTypeEnum.GROUP) {
+                    StudentPaymentOrderDetail spod = new StudentPaymentOrderDetail();
+                    spod.setType(OrderDetailTypeEnum.ORGAN_SHARE_PROFIT);
+                    spod.setPrice(subjectChange.getChangeCourseFee());
+                    spod.setRemitFee(BigDecimal.ZERO);
+                    spod.setCreateTime(nowDate);
+                    spod.setUpdateTime(nowDate);
+                    spod.setPaymentOrderId(studentPaymentOrder.getId());
+                    spod.setTenantId(studentPaymentOrder.getTenantId());
+                    studentPaymentOrderDetailList.add(spod);
+                }
         	}
-            
-            //原始订单的库存要归还
-            List<StudentPaymentOrderDetail> originalStudentPaymentOrderDetailList = new ArrayList<StudentPaymentOrderDetail>();
-            if(subjectChange.getOriginalOrderId() != null){
-            	originalStudentPaymentOrderDetailList = studentPaymentOrderDetailService.queryOrderDetail(subjectChange.getOriginalOrderId().longValue());
-            }
-            String originalGoodsIds = originalStudentPaymentOrderDetailList.stream().filter(t -> StringUtils.isNotBlank(t.getMinuendStockGoodsIdList())).map(t -> t.getMinuendStockGoodsIdList()).collect(Collectors.joining(","));
-            if(StringUtils.isNotBlank(originalGoodsIds)){
-            	List<Goods> goodsList = goodsService.getGoodsWithLocked(originalGoodsIds);
-            	goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
-            	
-            	for(String goodsIdStr : originalGoodsIds.split(",")){
-            		if(StringUtils.isBlank(goodsIdStr)){
-						continue;
-					}
-					goods = goodsMap.get(Integer.parseInt(goodsIdStr));
-					if(batchUpdateGoodsMap.get(goods.getId()) != null){
-						goods = batchUpdateGoodsMap.get(goods.getId());
-					}
-					goods.setStockCount(new AtomicInteger(goods.getStockCount()).incrementAndGet());
-					goods.setSellCount(new AtomicInteger(goods.getSellCount()).decrementAndGet());
-					goods.setUpdateTime(nowDate);
-					
-					batchUpdateGoodsMap.put(goods.getId(), goods);
-					
-					// 进货清单
-					goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(goods.getId());
-					if(goodsProcurement != null){
-						if(goodsProcurementMap.get(goodsProcurement.getId()) != null){
-							goodsProcurement = goodsProcurementMap.get(goodsProcurement.getId());
-						}
-						goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).decrementAndGet());
-						goodsProcurement.setUpdateTime(nowDate);
-						goodsProcurementMap.put(goodsProcurement.getId(), goodsProcurement);
-					}
-					
-            	}
-            }
-            
-            if(studentPaymentOrderDetailList.size() > 0){
+            if(!CollectionUtils.isEmpty(studentPaymentOrderDetailList)){
             	studentPaymentOrderDetailService.batchAdd(studentPaymentOrderDetailList);
             }
-			
-			if(goodsProcurementMap.size() > 0){
-				goodsProcurementDao.batchUpdate(new ArrayList<GoodsProcurement>(goodsProcurementMap.values()));
-			}
-    		
-    		if(batchUpdateGoodsMap.size() > 0){
-    			goodsService.batchUpdate(new ArrayList<Goods>(batchUpdateGoodsMap.values()));
-    		}
-
             //退原订单商品
     		if(subjectChange.getOriginalOrderId() != null) {
     			sellOrderService.refundByOrderId(subjectChange.getOriginalOrderId().longValue(), false);
     		}
 
             if (StringUtils.isNotBlank(goodsIds)) {
-                List<Integer> goodsIdList = Arrays.stream(goodsIds.split(",")).map(Integer::parseInt).collect(Collectors.toList());
+                List<Integer> goodsIdList = goodies.stream().map(Goods::getId).collect(Collectors.toList());
                 //添加新订单
-                this.addSellOrder(studentPaymentOrder,
-                        subjectChange.getMusicGroupId(),
-                        goodsIdList,
-                        subjectChange.getKitGroupPurchaseType());
+                sellOrderService.initSellOrder(studentPaymentOrder,musicGroupId,goodsIdList,subjectChange.getKitGroupPurchaseType(),true);
             }
             //乐保处理
             studentInstrumentService.subjectChangeUpdateInstrument(subjectChange);

+ 4 - 1
mec-biz/src/main/resources/config/mybatis/GoodsMapper.xml

@@ -405,7 +405,10 @@
 
     <sql id="queryOrganIdSql">
         <where>
-            AND g.status_ != 0 and g.tenant_id_ = #{goodsQuery.tenantId} and g.del_flag_ = 0
+            AND g.status_ != 0 and g.tenant_id_ = #{goodsQuery.tenantId}
+            <if test="goodsQuery.delFlag != null">
+                AND g.del_flag_ = #{goodsQuery.delFlag}
+            </if>
             <if test="goodsQuery.subjectId != null">
                 AND sgm.subject_id_ = #{goodsQuery.subjectId}
             </if>

+ 2 - 1
mec-biz/src/main/resources/config/mybatis/GoodsSubMapper.xml

@@ -17,6 +17,7 @@
         </foreach>
     </update>
     <select id="queryChildGoods" resultType="com.ym.mec.biz.dal.dto.ComplementGoodsDto">
-        select sku_ skuStockId,goods_id_ goodsId,goods_price_ organCostPrice from goods_sub where goods_id_ = #{goodsId}
+        select sku_ skuStockId,goods_id_ goodsId,goods_price_ organCostPrice,
+        from goods_sub where goods_id_ = #{goodsId}
     </select>
 </mapper>

+ 11 - 0
mec-biz/src/main/resources/config/mybatis/StudentPaymentOrderAddressMapper.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE  mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.ym.mec.biz.dal.mapper.StudentPaymentOrderAddressMapper">
+    
+    <select id="selectPage" resultType="com.ym.mec.biz.dal.entity.StudentPaymentOrderAddress">
+		SELECT         
+        	t.*
+		FROM student_payment_order_address t
+	</select>
+    
+</mapper>

+ 1 - 0
mec-biz/src/main/resources/config/mybatis/StudentPaymentOrderDetailMapper.xml

@@ -25,6 +25,7 @@
         <result column="minuend_stock_goods_id_list_" property="minuendStockGoodsIdList"/>
         <result column="user_id_" property="userId"/>
         <result column="delivery_batch_no_" property="deliveryBatchNo"/>
+        <result column="remit_fee_" property="remitFee"/>
         <collection property="goodsList" ofType="com.ym.mec.biz.dal.entity.Goods">
             <result column="goods_id_" property="id"/>
             <result column="goods_name_" property="name"/>

+ 2 - 2
mec-biz/src/main/resources/config/mybatis/StudentPaymentRouteOrderMapper.xml

@@ -373,7 +373,7 @@ calender_id_,create_time_,create_by_,update_time_,update_by_,tenant_id_,type_
          per_amount_,
          balance_payment_amount_, remit_fee_, course_remit_fee_, trans_no_,
          status_, memo_, create_time_, update_time_, payment_channel_, payment_business_channel_,
-         payment_account_no_, mer_nos_, order_no_, music_group_id_, class_group_id_, pay_time_,tenant_id_,cooperation_id_)
+         payment_account_no_, mer_nos_, order_no_, music_group_id_, class_group_id_, pay_time_,tenant_id_,cooperation_id_,calender_id_)
         VALUES (#{id}, #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
                 #{userId}, #{organId}, #{routingOrganId},
                 #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
@@ -382,7 +382,7 @@ calender_id_,create_time_,create_by_,update_time_,update_by_,tenant_id_,type_
                 #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}, #{memo}, #{createTime}, now(),
                 #{paymentChannel}, #{paymentBusinessChannel}, #{paymentAccountNo}, #{merNos}, #{orderNo},
                 #{musicGroupId},
-                #{classGroupId}, #{payTime},#{tenantId},#{cooperationId})
+                #{classGroupId}, #{payTime},#{tenantId},#{cooperationId},#{calenderId})
     </insert>
 
     <select id="queryAuditCount" parameterType="map" resultType="int">

+ 7 - 0
mec-biz/src/main/resources/config/mybatis/StudentRepairMapper.xml

@@ -338,4 +338,11 @@
         SELECT pg.educational_teacher_id_ FROM practice_group pg
         WHERE pg.student_id_ = #{studentId}) sid
     </select>
+
+    <select id="getByOrderNo" resultMap="StudentRepair">
+        SELECT * FROM student_repair
+        WHERE
+            trans_no_ = #{orderNo}
+        limit 1
+    </select>
 </mapper>

+ 4 - 1
mec-common/common-core/src/main/java/com/ym/mec/common/dto/OrderCreate.java

@@ -27,7 +27,7 @@ public class OrderCreate {
 //    @ApiModelProperty("订单总金额")
     private BigDecimal totalAmount;
 
-//    @ApiModelProperty("支付类型  1->支付宝;2->微信")
+//    @ApiModelProperty("支付类型  1->支付宝;2->微信  3余额")
     private Integer payType;
 
 //    @ApiModelProperty(value = "收货人姓名")
@@ -68,6 +68,9 @@ public class OrderCreate {
 
 //    @ApiModelProperty(value = "订单状态:0->待付款;1->待发货;2->已发货;3->已完成;4->已关闭;5->无效订单")
     private Integer status;
+
+    // 需要关闭的订单号
+    private List<String> closeOrderNoList;
     @Data
     public static class OrderItem implements Serializable {
 

+ 11 - 0
mec-common/common-core/src/main/java/com/ym/mec/common/entity/OrderCancelModel.java

@@ -17,6 +17,17 @@ public class OrderCancelModel {
     // 调用状态  true:成功  false 失败
     private Boolean success;
 
+    private String message;
+
+
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+
     public String getPayChannel() {
         return payChannel;
     }

+ 3 - 0
mec-common/common-core/src/main/java/com/ym/mec/common/entity/OrderSkuSync.java

@@ -33,5 +33,8 @@ public class OrderSkuSync {
 
         // 批次号
         private Long recordId;
+
+        // 内部库存 INTERNAL, 税务库存 TAX
+        private String type;
     }
 }

+ 48 - 16
mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/controller/OmsOrderController.java

@@ -1,20 +1,23 @@
 package com.yonge.cooleshow.admin.controller;
 
+import com.yonge.cooleshow.admin.wrapper.OmsOrderWrapper;
 import com.yonge.cooleshow.mall.common.api.CommonPage;
 import com.yonge.cooleshow.mall.common.api.CommonResult;
 import com.yonge.cooleshow.admin.dto.*;
-import com.yonge.cooleshow.mbg.model.OmsOrder;
 import com.yonge.cooleshow.admin.service.OmsOrderService;
+import com.yonge.cooleshow.mall.common.enums.OrderCacheEnum;
 import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.redisson.api.RLock;
+import org.redisson.api.RedissonClient;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
-import java.util.Map;
+import java.util.concurrent.TimeUnit;
 
 /**
  * 订单管理Controller
@@ -23,10 +26,13 @@ import java.util.Map;
 @Controller
 @Api(tags = "OmsOrderController", description = "订单管理")
 @RequestMapping("/order")
+@Slf4j
 public class OmsOrderController {
     @Autowired
     private OmsOrderService orderService;
 
+    @Autowired
+    private RedissonClient redissonClient;
     @ApiOperation("查询订单")
     @RequestMapping(value = "/list", method = RequestMethod.GET)
     @ResponseBody
@@ -41,10 +47,24 @@ public class OmsOrderController {
     @RequestMapping(value = "/update/delivery", method = RequestMethod.POST)
     @ResponseBody
     public CommonResult delivery(@RequestBody List<OmsOrderDeliveryParam> deliveryParamList) {
-        int count = orderService.delivery(deliveryParamList);
-        if (count > 0) {
-            return CommonResult.success(count);
+
+        RLock lock = redissonClient.getLock(OrderCacheEnum.LOCK_REFUND_ORDER_MALL + ":delivery");
+        try {
+            boolean b = lock.tryLock(60, 60, TimeUnit.SECONDS);
+            if (b) {
+                int count = orderService.delivery(deliveryParamList);
+                if (count > 0) {
+                    return CommonResult.success(count);
+                }
+            }
+        } catch (InterruptedException e) {
+            log.error("批量发货异常", e);
+        } finally {
+            if (lock.getHoldCount() >0) {
+                lock.unlock();
+            }
         }
+
         return CommonResult.failed();
     }
 
@@ -53,7 +73,7 @@ public class OmsOrderController {
     @ResponseBody
     public CommonResult close(@RequestParam("ids") List<Long> ids, @RequestParam String note) {
 
-        // int count = orderService.close(ids, note);
+//         int count = orderService.close(ids, note);
         // if (count > 0) {
         //     return CommonResult.success(count);
         // }
@@ -61,16 +81,28 @@ public class OmsOrderController {
     }
 
 
-    @ApiOperation("批量完成订单")
+    @ApiOperation("批量修改订单")
     @RequestMapping(value = "/update/success", method = RequestMethod.POST)
     @ResponseBody
-    public CommonResult success(@RequestBody List<Long> ids) {
-
-         int count = orderService.success(ids);
-        // if (count > 0) {
-        //     return CommonResult.success(count);
-        // }
-        return CommonResult.success(true);
+    public CommonResult success(@RequestBody @Validated OmsOrderWrapper.OrderStatusUpdate orderStatusUpdate) {
+
+        RLock lock = redissonClient.getLock(OrderCacheEnum.LOCK_REFUND_ORDER_MALL + ":delivery");
+        try {
+            boolean b = lock.tryLock(60, 60, TimeUnit.SECONDS);
+            if (b) {
+                int count = orderService.updateStatus(orderStatusUpdate);
+                if (count > 0) {
+                    return CommonResult.success(count);
+                }
+            }
+        } catch (InterruptedException e) {
+            log.error("批量修改订单", e);
+        } finally {
+            if (lock.getHoldCount() >0) {
+                lock.unlock();
+            }
+        }
+        return CommonResult.success(false);
     }
 
 

+ 4 - 1
mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/dto/OrderCreate.java

@@ -28,7 +28,7 @@ public class OrderCreate {
     @ApiModelProperty("订单总金额")
     private BigDecimal totalAmount;
 
-    @ApiModelProperty("支付类型  1->支付宝;2->微信")
+    @ApiModelProperty("支付类型  1->支付宝;2->微信 3余额")
     private Integer payType;
 
     @ApiModelProperty(value = "收货人姓名")
@@ -68,6 +68,9 @@ public class OrderCreate {
     @ApiModelProperty("商品详情")
     private List<OrderItem> orderItemList;
 
+    // 需要关闭的订单号
+    private List<String> closeOrderNoList;
+
     @Data
     public static class OrderItem implements Serializable {
 

+ 2 - 1
mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/service/OmsOrderService.java

@@ -3,6 +3,7 @@ package com.yonge.cooleshow.admin.service;
 import com.yonge.cooleshow.admin.dto.*;
 import com.yonge.cooleshow.admin.dto.search.OrderStatisticalSearch;
 import com.yonge.cooleshow.admin.dto.search.UserStatisticalSearch;
+import com.yonge.cooleshow.admin.wrapper.OmsOrderWrapper;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
@@ -101,5 +102,5 @@ public interface OmsOrderService {
     // 同步订单状态,
     boolean productUpdateOrderStatus(String orderNo, Integer status);
 
-    int success(List<Long> ids);
+    int updateStatus(OmsOrderWrapper.OrderStatusUpdate orderStatusUpdate);
 }

+ 88 - 12
mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/service/impl/OmsOrderServiceImpl.java

@@ -1,6 +1,7 @@
 package com.yonge.cooleshow.admin.service.impl;
 
 import cn.hutool.core.collection.CollUtil;
+import com.alibaba.fastjson.JSON;
 import com.github.pagehelper.PageHelper;
 import com.google.common.collect.Lists;
 import com.ym.mec.common.dto.SchoolDto;
@@ -17,6 +18,7 @@ import com.yonge.cooleshow.admin.dto.search.OrderStatisticalSearch;
 import com.yonge.cooleshow.admin.dto.search.UserStatisticalSearch;
 import com.yonge.cooleshow.admin.enums.OrderStatisticalEnum;
 import com.yonge.cooleshow.admin.service.*;
+import com.yonge.cooleshow.admin.wrapper.OmsOrderWrapper;
 import com.yonge.cooleshow.mbg.mapper.*;
 import com.yonge.cooleshow.mbg.model.*;
 import lombok.extern.slf4j.Slf4j;
@@ -24,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
 
 import java.math.BigDecimal;
 import java.time.LocalDate;
@@ -175,6 +178,9 @@ public class OmsOrderServiceImpl implements OmsOrderService {
         if (CollectionUtils.isEmpty(omsOrderItems)) {
             throw new BizException("订单详情不存在");
         }
+        // skuID 商品名称 map
+        Map<Long,String > skuMap = omsOrderItems.stream().collect(Collectors.toMap(OmsOrderItem::getProductSkuId, OmsOrderItem::getProductName,(o1, o2)->o1));
+
         // skuID集合
         List<Long> skuIds = omsOrderItems.stream().map(OmsOrderItem::getProductSkuId).distinct().collect(Collectors.toList());
         // 查询库存
@@ -182,7 +188,8 @@ public class OmsOrderServiceImpl implements OmsOrderService {
         stockRecordExample.createCriteria().andProductSkuIdIn(skuIds);
         List<PmsProductSkuStockRecord> productSkuStockRecords = pmsProductSkuStockRecordMapper.selectByExample(stockRecordExample);
         if (CollectionUtils.isEmpty(productSkuStockRecords)) {
-            throw new BizException("库存不足");
+            ArrayList<String> list = new ArrayList<>(skuMap.values());
+            throw new BizException(list.get(0) +"库存不足");
         }
         //id 集合
         List<Long> stockRecordIds = productSkuStockRecords.stream().map(PmsProductSkuStockRecord::getId).collect(Collectors.toList());
@@ -197,16 +204,19 @@ public class OmsOrderServiceImpl implements OmsOrderService {
         List<PmsProductSkuStockRecord> updateList = new ArrayList<>();
         Map<String, List<OmsOrderItem>> map = omsOrderItems.stream().collect(Collectors.groupingBy(o -> o.getOrderSn()));
         List<OrderSkuSync> skuSyncList = new ArrayList<>();
+        List<OmsOrderItem> updateItems = new ArrayList<>();
         map.forEach((sn,v) -> {
             OrderSkuSync skuSync = new OrderSkuSync();
             skuSync.setOrderNo(sn);
             List<OrderSkuSync.SkuSync> skuSyncs = new ArrayList<>();
             skuSync.setSkuSyncList(skuSyncs);
             v.stream().forEach(o -> {
+
                 List<PmsProductSkuStockRecord> skuStockRecords = skuStockRecordMap.get(o.getProductSkuId());
                 if (CollectionUtils.isEmpty(skuStockRecords)) {
-                    throw new BizException("库存不足");
+                    throw new BizException(skuMap.get(o.getProductSkuId()) +"库存不足");
                 }
+                List<OrderSkuSync.SkuSync> itemSkus = new ArrayList<>();
                 int count1 = o.getProductQuantity();
                 // 扣减内部库存
                 for (PmsProductSkuStockRecord skuStockRecord : skuStockRecords) {
@@ -216,6 +226,7 @@ public class OmsOrderServiceImpl implements OmsOrderService {
                     if (skuStockRecord.getInternalStock() > 0) {
                         OrderSkuSync.SkuSync sync = new OrderSkuSync.SkuSync();
                         sync.setSku(skuStockRecord.getProductSkuId());
+                        sync.setType("INTERNAL");
 
 
                         int stock = skuStockRecord.getInternalStock() - skuStockRecord.getInternalSaleStock();
@@ -236,6 +247,7 @@ public class OmsOrderServiceImpl implements OmsOrderService {
                             }
                             updateList.add(record);
                             skuSyncs.add(sync);
+                            itemSkus.add(sync);
                         }
                     }
                 }
@@ -250,6 +262,7 @@ public class OmsOrderServiceImpl implements OmsOrderService {
                         sync.setSku(skuStockRecord.getProductSkuId());
                         sync.setPrice(skuStockRecord.getPrice());
                         sync.setRecordId(skuStockRecord.getId());
+                        sync.setType("TAX");
 
                         int stock = skuStockRecord.getTaxStock() - skuStockRecord.getTaxSaleStock();
                         if (stock > 0) {
@@ -266,11 +279,19 @@ public class OmsOrderServiceImpl implements OmsOrderService {
                             }
                             updateList.add(record);
                             skuSyncs.add(sync);
+                            itemSkus.add(sync);
                         }
                     }
                 }
                 if (count1 > 0) {
-                    throw new BizException("库存不足");
+                    throw new BizException(skuMap.get(o.getProductSkuId())+"库存不足");
+                }
+                if (CollUtil.isNotEmpty(itemSkus)) {
+
+                    OmsOrderItem orderItem = new OmsOrderItem();
+                    orderItem.setId(o.getId());
+                    orderItem.setStockJson(JSON.toJSONString(itemSkus));
+                    updateItems.add(orderItem);
                 }
             });
             skuSyncList.add(skuSync);
@@ -278,15 +299,18 @@ public class OmsOrderServiceImpl implements OmsOrderService {
         for (PmsProductSkuStockRecord pmsProductSkuStockRecord : updateList) {
             pmsProductSkuStockRecordMapper.updateByPrimaryKeySelective(pmsProductSkuStockRecord);
         }
+        // 更新订单详情
+        for (OmsOrderItem updateItem : updateItems) {
+            omsOrderItemMapper.updateByPrimaryKeySelective(updateItem);
+        }
 
         // 调用三方发货通知接口
         OmsOrderExample orderExample = new OmsOrderExample();
         orderExample.createCriteria().andIdIn(orderIds);
-        List<OmsOrder> omsOrders = orderMapper.selectByExample(orderExample);
         try {
             HttpResponseResult httpResponseResult = webFeignService.updateShippedStatus(skuSyncList);
             if (httpResponseResult.getCode() != 200 && !httpResponseResult.getStatus()) {
-                throw new BizException("发货通知失败");
+                throw new BizException("发货通知失败:"+httpResponseResult.getMsg());
             }
         } catch (Exception e) {
             throw new BizException("发货通知失败");
@@ -763,6 +787,16 @@ public class OmsOrderServiceImpl implements OmsOrderService {
         if (!CollectionUtils.isEmpty(orderItemList)) {
             omsOrderItemMapper.insertList(orderItemList);
         }
+
+        // 关闭需要关闭的订单
+        if(!CollectionUtils.isEmpty(order.getCloseOrderNoList())) {
+            OmsOrderExample example = new OmsOrderExample();
+            example.createCriteria().andOrderSnIn(order.getCloseOrderNoList());
+            OmsOrder record = new OmsOrder();
+            record.setStatus(4);
+            orderMapper.updateByExampleSelective(record, example);
+        }
+
         // 如果订单状态是已发货,扣减库存
         if (order.getStatus() ==2 || order.getStatus() == 3) {
 
@@ -794,23 +828,65 @@ public class OmsOrderServiceImpl implements OmsOrderService {
     // 直接修改订单状态为完成
     @Override
     @Transactional
-    public int success(List<Long> ids) {
+    public int updateStatus(OmsOrderWrapper.OrderStatusUpdate orderStatusUpdate) {
+
+
+        // 如果时关单 并且 是已发货状态 则需要退回库存
+        OmsOrderExample orderExample = new OmsOrderExample();
+        orderExample.createCriteria().andIdIn(orderStatusUpdate.getIds());
+        List<OmsOrder> omsOrders = orderMapper.selectByExample(orderExample);
+        List<Long> orderIds = omsOrders.stream().filter(o -> o.getStatus() == 2 || o.getStatus() == 3)
+            .map(OmsOrder::getId).collect(Collectors.toList());
+        if (orderStatusUpdate.getStatus() ==4 && !CollectionUtils.isEmpty(orderIds)) {
+            OmsOrderItemExample orderItemExample = new OmsOrderItemExample();
+            orderItemExample.createCriteria().andOrderIdIn(orderIds);
+            List<OmsOrderItem> omsOrderItems = omsOrderItemMapper.selectByExample(orderItemExample);
+            List<String> stockJsons = omsOrderItems.stream().map(OmsOrderItem::getStockJson)
+                .filter(o ->!StringUtils.isEmpty(o)).collect(Collectors.toList());
+            List<OrderSkuSync.SkuSync> skuSyncList = new ArrayList<>();
+            for (String stockJson : stockJsons) {
+                List<OrderSkuSync.SkuSync> skuSyncs = JSON.parseArray(stockJson, OrderSkuSync.SkuSync.class);
+                skuSyncList.addAll(skuSyncs);
+            }
+            Map<Long, Integer> internalMap = skuSyncList.stream().filter(o -> "INTERNAL".equals(o.getType()))
+                .collect(Collectors.groupingBy(OrderSkuSync.SkuSync::getRecordId, Collectors.summingInt(OrderSkuSync.SkuSync::getCount)));
+            Map<Long, Integer> taxMap = skuSyncList.stream().filter(o -> "TAX".equals(o.getType()))
+                .collect(Collectors.groupingBy(OrderSkuSync.SkuSync::getRecordId, Collectors.summingInt(OrderSkuSync.SkuSync::getCount)));
+            List<PmsProductSkuStockRecord> updateList = new ArrayList<>();
+            for (Map.Entry<Long, Integer> entry : internalMap.entrySet()) {
+                PmsProductSkuStockRecord skuStockRecord = new PmsProductSkuStockRecord();
+                skuStockRecord.setId(entry.getKey());
+                skuStockRecord.setInternalSaleStock(entry.getValue());
+                updateList.add(skuStockRecord);
+            }
+            for (Map.Entry<Long, Integer> entry : taxMap.entrySet()) {
+                PmsProductSkuStockRecord skuStockRecord = new PmsProductSkuStockRecord();
+                skuStockRecord.setId(entry.getKey());
+                skuStockRecord.setTaxSaleStock(entry.getValue());
+                updateList.add(skuStockRecord);
+            }
+            for (PmsProductSkuStockRecord pmsProductSkuStockRecord : updateList) {
+                pmsProductSkuStockRecordMapper.updateStock(pmsProductSkuStockRecord);
+            }
+
+
+        }
+
         OmsOrder record = new OmsOrder();
-        record.setStatus(3);
+        record.setStatus(orderStatusUpdate.getStatus());
         OmsOrderExample example = new OmsOrderExample();
-        example.createCriteria().andDeleteStatusEqualTo(0).andIdIn(ids);
+        example.createCriteria().andIdIn(orderStatusUpdate.getIds());
         orderMapper.updateByExampleSelective(record, example);
 
-
         //添加操作记录
-        List<OmsOrderOperateHistory> operateHistoryList = ids.stream()
+        List<OmsOrderOperateHistory> operateHistoryList = orderStatusUpdate.getIds().stream()
             .map(id -> {
                 OmsOrderOperateHistory history = new OmsOrderOperateHistory();
                 history.setOrderId(id);
                 history.setCreateTime(new Date());
                 history.setOperateMan("后台管理员");
-                history.setOrderStatus(3);
-                history.setNote("订单完成");
+                history.setOrderStatus(orderStatusUpdate.getStatus());
+                history.setNote("修改订单状态");
                 return history;
             }).collect(Collectors.toList());
         return orderOperateHistoryDao.insertList(operateHistoryList);

+ 26 - 0
mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/wrapper/OmsOrderWrapper.java

@@ -0,0 +1,26 @@
+package com.yonge.cooleshow.admin.wrapper;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+import java.util.List;
+
+public class OmsOrderWrapper {
+
+    @Data
+    public static class OrderStatusUpdate {
+
+        // 订单ID集合
+        @ApiModelProperty("订单ID集合")
+        @NotNull(message = "订单ID集合不能为空")
+        @NotEmpty(message = "订单ID集合不能为空")
+        private List<Long> ids;
+
+        // 状态
+        @ApiModelProperty("订单状态:0->待付款;1->待发货;2->已发货;3->已完成;4->已关闭;5->无效订单")
+        @NotNull(message = "订单状态不能为空")
+        private Integer status;
+    }
+}

+ 2 - 0
mec-mall/mall-mbg/src/main/java/com/yonge/cooleshow/mbg/mapper/PmsProductSkuStockRecordMapper.java

@@ -32,4 +32,6 @@ public interface PmsProductSkuStockRecordMapper {
     int lockStock(@Param("stockRecordIds") List<Long> stockRecordIds);
 
     int updateByIdAndStockSelective( PmsProductSkuStockRecord pmsProductSkuStockRecord);
+
+    void updateStock(@Param("record") PmsProductSkuStockRecord pmsProductSkuStockRecord);
 }

+ 10 - 0
mec-mall/mall-mbg/src/main/java/com/yonge/cooleshow/mbg/model/OmsOrderItem.java

@@ -71,6 +71,16 @@ public class OmsOrderItem implements Serializable {
 
     private BigDecimal precisionAmount;
 
+    private String stockJson;
+
+    public String getStockJson() {
+        return stockJson;
+    }
+
+    public void setStockJson(String stockJson) {
+        this.stockJson = stockJson;
+    }
+
     private static final long serialVersionUID = 1L;
 
     public BigDecimal getPrecisionAmount() {

+ 18 - 3
mec-mall/mall-mbg/src/main/resources/config/mybatis/OmsOrderItemMapper.xml

@@ -27,6 +27,7 @@
     <result column="promoter_id" jdbcType="INTEGER" property="promoterId" />
     <result column="share_proportion_" jdbcType="INTEGER" property="shareProportion" />
     <result column="precision_amount" jdbcType="INTEGER" property="precisionAmount" />
+    <result column="stock_json" jdbcType="VARCHAR" property="stockJson" />
   </resultMap>
   <sql id="Example_Where_Clause">
     <where>
@@ -90,7 +91,7 @@
     id, order_id, order_sn, product_id, product_pic, product_name, product_brand, product_sn, 
     product_price, product_quantity, product_sku_id, product_sku_code, product_category_id, 
     promotion_name, promotion_amount, coupon_amount, integration_amount, real_amount, 
-    gift_integration, gift_growth, product_attr,promoter_id,share_proportion_,precision_amount
+    gift_integration, gift_growth, product_attr,promoter_id,share_proportion_,precision_amount,stock_json
   </sql>
   <select id="selectByExample" parameterType="com.yonge.cooleshow.mbg.model.OmsOrderItemExample" resultMap="BaseResultMap">
     select a.*,if(oora.status is null,-1,oora.status) as returnStatus from  (
@@ -134,14 +135,14 @@
       product_sku_id, product_sku_code, product_category_id, 
       promotion_name, promotion_amount, coupon_amount, 
       integration_amount, real_amount, gift_integration, 
-      gift_growth, product_attr,promoter_id,share_proportion_,precision_amount)
+      gift_growth, product_attr,promoter_id,share_proportion_,precision_amount,stock_json)
     values (#{orderId,jdbcType=BIGINT}, #{orderSn,jdbcType=VARCHAR}, #{productId,jdbcType=BIGINT}, 
       #{productPic,jdbcType=VARCHAR}, #{productName,jdbcType=VARCHAR}, #{productBrand,jdbcType=VARCHAR}, 
       #{productSn,jdbcType=VARCHAR}, #{productPrice,jdbcType=DECIMAL}, #{productQuantity,jdbcType=INTEGER}, 
       #{productSkuId,jdbcType=BIGINT}, #{productSkuCode,jdbcType=VARCHAR}, #{productCategoryId,jdbcType=BIGINT}, 
       #{promotionName,jdbcType=VARCHAR}, #{promotionAmount,jdbcType=DECIMAL}, #{couponAmount,jdbcType=DECIMAL}, 
       #{integrationAmount,jdbcType=DECIMAL}, #{realAmount,jdbcType=DECIMAL}, #{giftIntegration,jdbcType=INTEGER}, 
-      #{giftGrowth,jdbcType=INTEGER}, #{productAttr,jdbcType=VARCHAR},#{promoterId},#{shareProportion},#{precisionAmount})
+      #{giftGrowth,jdbcType=INTEGER}, #{productAttr,jdbcType=VARCHAR},#{promoterId},#{shareProportion},#{precisionAmount},#{stockJson})
   </insert>
   <insert id="insertSelective" parameterType="com.yonge.cooleshow.mbg.model.OmsOrderItem">
     <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
@@ -218,6 +219,9 @@
       <if test="precisionAmount != null">
         precision_amount,
       </if>
+        <if test="stockJson != null">
+        stock_json,
+        </if>
     </trim>
     <trim prefix="values (" suffix=")" suffixOverrides=",">
       <if test="orderId != null">
@@ -289,6 +293,9 @@
       <if test="precisionAmount != null">
         #{precisionAmount},
       </if>
+        <if test="stockJson != null">
+        #{stockJson,jdbcType=VARCHAR},
+        </if>
     </trim>
   </insert>
   <select id="countByExample" parameterType="com.yonge.cooleshow.mbg.model.OmsOrderItemExample" resultType="java.lang.Long">
@@ -372,6 +379,9 @@
       <if test="record.precisionAmount != null">
         precision_amount = #{record.precisionAmount,jdbcType=VARCHAR},
       </if>
+        <if test="record.stockJson != null">
+        stock_json = #{record.stockJson,jdbcType=VARCHAR},
+        </if>
     </set>
     <if test="_parameter != null">
       <include refid="Update_By_Example_Where_Clause" />
@@ -402,6 +412,7 @@
       promoter_id = #{record.promoterId,jdbcType=INTEGER},
       share_proportion_ = #{record.shareProportion},
       precision_amount = #{record.precisionAmount},
+        stock_json = #{record.stockJson},
       product_attr = #{record.productAttr,jdbcType=VARCHAR}
     <if test="_parameter != null">
       <include refid="Update_By_Example_Where_Clause" />
@@ -479,6 +490,9 @@
       <if test="precisionAmount != null">
         precision_amount = #{precisionAmount,jdbcType=VARCHAR},
       </if>
+        <if test="stockJson != null">
+        stock_json = #{stockJson,jdbcType=VARCHAR},
+        </if>
     </set>
     where id = #{id,jdbcType=BIGINT}
   </update>
@@ -506,6 +520,7 @@
       promoter_id = #{promoterId,jdbcType=INTEGER},
     share_proportion_ = #{shareProportion},
     precision_amount = #{precisionAmount},
+    stock_json = #{stockJson},
       product_attr = #{productAttr,jdbcType=VARCHAR}
     where id = #{id,jdbcType=BIGINT}
   </update>

+ 15 - 0
mec-mall/mall-mbg/src/main/resources/config/mybatis/PmsProductSkuStockRecordMapper.xml

@@ -361,4 +361,19 @@
       </set>
       where id = #{id,jdbcType=BIGINT} and internal_sale_stock = 0 and tax_sale_stock = 0
     </update>
+
+  <update id="updateStock">
+
+        update pms_product_sku_stock_record
+        <set>
+            <if test="record.internalSaleStock != null">
+                internal_sale_stock = internal_sale_stock - #{record.internalSaleStock},
+            </if>
+            <if test="record.taxSaleStock != null">
+                tax_sale_stock = tax_sale_stock -#{record.taxSaleStock}
+            </if>
+        </set>
+
+        where id = #{record.id}
+    </update>
 </mapper>

+ 3 - 2
mec-mall/mall-portal/src/main/java/com/yonge/cooleshow/portal/service/impl/OmsPortalOrderServiceImpl.java

@@ -595,12 +595,13 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
                     cancelOrder.getOrderSn());
             if (userOrderPayment != null) {
                 HttpResponseResult<OrderCancelModel> responseResult = webFeignService.cancelOrder(userOrderPayment.getAdapayNo(),message);
+                LOG.info("管乐迷取消订单返回结果:{}",JSON.toJSONString(responseResult));
                 if (!responseResult.getStatus()) {
-                    throw new BizException("远程取消失败");
+                    throw new BizException("订单取消失败");
                 }
                 OrderCancelModel data = responseResult.getData();
                 if (!data.getSuccess()) {
-                    throw new BizException("远程取消失败");
+                    throw new BizException("订单取消失败:"+data.getMessage());
                 }
                 if (data.getStatus() !=null && data.getStatus()) {
                     LOG.info("订单支付成功,修改订单状态");

+ 7 - 3
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/adapay/Payment.java

@@ -217,10 +217,10 @@ public class Payment {
      * @param merchantKey 商户Key
      * @return Map<String, Object>
      */
-    public static Map<String ,Object> closeWithKey(String transNo, String reason, String merchantKey) {
+    public static Map<String ,String> closeWithKey(String transNo, String reason, String merchantKey) {
 
 
-        Map<String, Object> result = new HashMap<>();
+        Map<String, String> result = new HashMap<>();
 
         Map<String, Object> params = new HashMap<>();
 
@@ -234,6 +234,7 @@ public class Payment {
         } catch (BaseAdaPayException e) {
             LOGGER.info("请求汇付[关单]接口失败:{}", e.getMessage());
             result.put("status", "failed");
+            result.put ("msg",e.getMessage());
             return result;
         }
         if (StringUtils.equals(paymentClose.get("status").toString(), "failed")) {
@@ -248,10 +249,13 @@ public class Payment {
                 LOGGER.warn("调用汇付[关单]接口同步返回,出现异常:{}", paymentClose);
 
                 result.put("status", "success");
+                return result;
             }
             result.put("status", "failed");
-            // throw new PaymentException(paymentClose.get("error_msg").toString());
+            result.put ("msg",paymentClose.get("error_msg").toString());
+            return result;
         }
+        result.put("status", "success");
 
         return result;
     }

+ 9 - 5
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/yeepay/YeepayPaymentService.java

@@ -113,11 +113,11 @@ public class YeepayPaymentService {
      * @param reason 原因
      * @return Map<String, Object>
      */
-    public Map<String,Object> close(HfMerchantConfig hfMerchantConfig,String transNo, String reason, String outTransNo) {
+    public Map<String,String> close(HfMerchantConfig hfMerchantConfig,String transNo, String reason, String outTransNo) {
 
 
-        Map<String, Object> result = new HashMap<>();
-        result.put("status", "failed");
+        Map<String, String> result = new HashMap<>();
+        result.put("status", "success");
         try {
 
             // 订单参数
@@ -135,12 +135,15 @@ public class YeepayPaymentService {
 
             // 关闭订单异常消息
             if (Objects.nonNull(ret.getError())) {
-                LOGGER.error("易宝[关闭订单]接口失败:transNo={}, reason={}", transNo, reason, ret.getError());
-                result.put("status", "failed");
+                LOGGER.error("易宝[关闭订单]接口失败:transNo={}, reason={}", transNo, ret.getError());
+                result.put("msg", ret.getError().getSubMessage());
+                result.put("status","failed");
             }
 
             JSONObject jsonObject = JSON.parseObject(ret.getStringResult());
 
+            // 响应参数
+
             // 关闭订单成功
             // OPR00000	成功
             // OPR18015	已拒绝支付,不必关闭订单
@@ -153,6 +156,7 @@ public class YeepayPaymentService {
         } catch (Exception e) {
             LOGGER.error("易宝[关闭订单]接口失败:transNo={}, reason={}", transNo, reason, e);
             result.put("status", "failed");
+            result.put("msg", e.getMessage());
 
         }