浏览代码

机构付款相关

hgw 3 年之前
父节点
当前提交
02c5b84a07

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

@@ -47,7 +47,7 @@ public class TenantProductInfo implements Serializable {
     private BigDecimal payAmount;
 
     @TableField("pay_date_")
-    @ApiModelProperty(value = "付费/开通 时间")
+    @ApiModelProperty(value = "付费时间")
     private Date payDate;
 
     @TableField("expiry_count_")

+ 4 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/TenantOrderRecordService.java

@@ -5,6 +5,8 @@ import com.ym.mec.biz.dal.dto.TenantOrderRecordDto;
 import com.ym.mec.biz.dal.entity.TenantOrderRecord;
 import com.ym.mec.common.page.PageInfo;
 
+import java.util.Map;
+
 /**
  * 机构付款记录表(TenantOrderRecord)表服务接口
  *
@@ -15,5 +17,7 @@ public interface TenantOrderRecordService extends IService<TenantOrderRecord> {
 
     PageInfo<TenantOrderRecord> queryPage(TenantOrderRecordDto dto);
 
+    Map<String, Object> checkTenantOrder(String orderNo);
+
 }
 

+ 35 - 15
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantInfoServiceImpl.java

@@ -21,6 +21,7 @@ import com.ym.mec.biz.service.*;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.page.PageUtil;
+import com.ym.mec.common.page.WrapperUtil;
 import com.ym.mec.common.service.IdGeneratorService;
 import com.ym.mec.thirdparty.yqpay.Msg;
 import org.apache.commons.collections.CollectionUtils;
@@ -103,11 +104,11 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         //添加机构配置
         setIdByApply(tenantId, dto.getConfig(), dto.getConfig()::setTenantId, tenantConfigService::addConfig);
         //创建一个和机构同名称的“分部”
-        createOrg(tenantInfo,dto.getAreaId());
+        createOrg(tenantInfo, dto.getAreaId());
     }
 
     //创建一个和机构同名称的“分部”
-    private void createOrg(TenantInfo tenantInfo,Integer areaId) {
+    private void createOrg(TenantInfo tenantInfo, Integer areaId) {
         Organization organization = new Organization();
         organization.setName(tenantInfo.getName());
         organization.setDelFlag(YesOrNoEnum.NO);
@@ -255,8 +256,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
             throw new BizException("该机构数正在开通中请勿频繁操作");
         }
         //获取产品信息得到服务id
-        TenantProductInfo productInfo = tenantProductInfoService.getOne(new QueryWrapper<TenantProductInfo>()
-                .eq("tenant_id_", tenantId));
+        TenantProductInfo productInfo = tenantProductInfoService.getOne(new WrapperUtil<TenantProductInfo>()
+                .hasEq("tenant_id_", tenantId).queryWrapper());
         if (Objects.isNull(productInfo)) {
             throw new BizException("开通账号信息异常!未查询到购买的产品信息!");
         }
@@ -349,15 +350,15 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         if (Objects.isNull(organization)) {
             throw new BizException("未查询到机构分部信息!");
         }
-        Map<String, Object> payMap = new HashMap<>();
+        Map<String, Object> result = new HashMap<>();
         int orderState = 0;
         //消费大于0元则拉起支付
         if (productInfo.getPayAmount().compareTo(BigDecimal.ZERO) > 0) {
-            payMap = payService.getPayMap(
+            result = payService.getPayMap(
                     productInfo.getPayAmount(),
                     BigDecimal.ZERO,
                     orderNo,
-                    baseApiUrl + "/WEB-SERVER/tenantInfo/notify",
+                    baseApiUrl + "/api-web/tenantInfo/notify",
                     baseApiUrl + "/api-student/studentOrder/paymentResult?orderNo=" + orderNo,
                     tenantEnum.getMsg(),
                     tenantEnum.getMsg(),
@@ -367,10 +368,14 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         } else {
             //已支付
             orderState = 1;
+            tenantOpen(tenantId);
+            Map<String, Object> payMap = new HashMap<>();
+            payMap.put("orderNo", orderNo);
+            result.put("payMap", payMap);
         }
         createOrderRecord(tenantId, productInfo.getPayAmount(), orderNo, tenantEnum, orderState);
-        log.info("tenant pay >>>>> " + JSON.toJSONString(payMap));
-        return payMap;
+        log.info("tenant pay >>>>> " + JSON.toJSONString(result));
+        return result;
     }
 
     //生成订单
@@ -401,19 +406,21 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         log.info("tenant orderNotify >>>>> " + msg.toString());
         msg.setMsg("fail");
         Map<String, String> notifyMap = JSON.parseObject(msg.getResponseParameters(), Map.class);
-        TenantOrderRecord record = new TenantOrderRecord();
-        record.setOrderNo(notifyMap.get("merMerOrderNo"));
+        String orderNo = notifyMap.get("merMerOrderNo");
+        TenantOrderRecord record = tenantOrderRecordService.getOne(new WrapperUtil<TenantOrderRecord>()
+                .hasEq("order_no_", orderNo).queryWrapper());
         record.setTransNo(notifyMap.get("orderNo"));
         String channelType = notifyMap.get("channelType").equals("1") ? "WXPay" : (notifyMap.get("channelType").equals("2") ? "Alipay" : "quickPay");
         record.setPayChannel(channelType);
-        //支付中订单存在,更新状态
+        //支付中订单存在,更新状态 tradeState 88就是正确的 其他错误的
         if (msg.getResponseType().equals("1") && notifyMap.size() > 0 && msg.getCode().equals("88")) {
-            //tradeState 88就是正确的 其他错误的
-//            DealStatusEnum
-//            notifyMap.put("totalMoney", notifyMap.get("payAmount"));
+            // notifyMap.put("totalMoney", notifyMap.get("payAmount"));
             record.setOrderState(1);
             msg.setCode("000000");
             msg.setMsg("success");
+            if (TenantOrderRecordEnum.TENANT_OPEN.getCode().equals(record.getOrderType())) {
+                tenantOpen(record.getTenantId());
+            }
         } else {
             //支付失败
             record.setOrderState(2);
@@ -480,4 +487,17 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         }
     }
 
+    //修机构相关的改付款时间
+    private void tenantOpen(Integer tenantId) {
+        TenantInfo tenantInfo = new TenantInfo();
+        tenantInfo.setId(tenantId);
+        tenantInfo.setPayState(1);
+        baseMapper.updateById(tenantInfo);
+
+        TenantProductInfo productInfo = new TenantProductInfo();
+        productInfo.setPayDate(new Date());
+        productInfo.setTenantId(tenantId);
+        tenantProductInfoService.updateById(productInfo);
+    }
+
 }

+ 76 - 6
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantOrderRecordServiceImpl.java

@@ -4,15 +4,24 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ym.mec.biz.dal.dao.TenantOrderRecordDao;
 import com.ym.mec.biz.dal.dto.TenantOrderRecordDto;
+import com.ym.mec.biz.dal.entity.PlatformServe;
+import com.ym.mec.biz.dal.entity.PlatformServeDetail;
 import com.ym.mec.biz.dal.entity.TenantOrderRecord;
+import com.ym.mec.biz.dal.entity.TenantProductInfo;
+import com.ym.mec.biz.dal.enums.DealStatusEnum;
+import com.ym.mec.biz.dal.enums.TenantOrderRecordEnum;
+import com.ym.mec.biz.service.PlatformServeDetailService;
+import com.ym.mec.biz.service.PlatformServeService;
 import com.ym.mec.biz.service.TenantOrderRecordService;
+import com.ym.mec.biz.service.TenantProductInfoService;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.page.PageUtil;
-import com.ym.mec.common.page.QueryWrapperUtil;
-import org.apache.commons.collections.CollectionUtils;
+import com.ym.mec.common.page.WrapperUtil;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.Optional;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * 机构付款记录表(TenantOrderRecord)表服务实现类
@@ -23,16 +32,77 @@ import java.util.Optional;
 @Service("tenantOrderRecordService")
 public class TenantOrderRecordServiceImpl extends ServiceImpl<TenantOrderRecordDao, TenantOrderRecord> implements TenantOrderRecordService {
 
+    @Autowired
+    private TenantProductInfoService tenantProductInfoService;
+    @Autowired
+    private PlatformServeService platformServeService;
+    @Autowired
+    private PlatformServeDetailService platformServeDetailService;
+
     @Override
     public PageInfo<TenantOrderRecord> queryPage(TenantOrderRecordDto dto) {
         Page<TenantOrderRecord> pageInfo = PageUtil.getPage(dto.getPage(), dto.getRows());
         pageInfo.setDesc("a.created_time_ ");
-        Optional.ofNullable(dto.getTenantId())
-                .map(QueryWrapperUtil::toList)
-                .filter(CollectionUtils::isNotEmpty)
+        WrapperUtil.toListOptional(dto.getTenantId())
                 .ifPresent(dto::setTenantIdList);
         return PageUtil.pageInfo(baseMapper.queryPage(pageInfo, dto));
     }
 
+    @Override
+    public Map<String, Object> checkTenantOrder(String orderNo) {
+        TenantOrderRecord orderRecord = this.getOne(new WrapperUtil<TenantOrderRecord>()
+                .hasEq("order_no_", orderNo).queryWrapper());
+        //返回
+        Map<String, Object> result = new HashMap<>();
+        result.put("groupType", orderRecord.getOrderType());
+        //订单信息
+        Map<String, Object> order = new HashMap<>();
+        result.put("order", order);
+        order.put("orderNo", orderRecord.getOrderNo());
+        order.put("expectAmount", orderRecord.getExpectAmount());
+        order.put("type", orderRecord.getOrderType());
+        //购买的信息
+        Map<String, Object> detail = new HashMap<>();
+        result.put("detail", detail);
+
+        getOrderState(orderRecord, result);
+        return result;
+    }
+
+    private void getOrderState(TenantOrderRecord orderRecord, Map<String, Object> result) {
+        Map<String, Object> detail = (Map<String, Object>) result.get("detail");
+        Map<String, Object> order = (Map<String, Object>) result.get("order");
+        String code;
+        //订单状态/0待支付、1已支付、2支付失败
+        switch (orderRecord.getOrderState()) {
+            case 1:
+                if (TenantOrderRecordEnum.TENANT_OPEN.getCode().equals(orderRecord.getOrderType())) {
+                    tenantOrderSuccess(orderRecord, detail);
+                }
+                code = DealStatusEnum.SUCCESS.getCode();
+                break;
+            case 2:
+                code = DealStatusEnum.FAILED.getCode();
+                break;
+            default:
+                code = DealStatusEnum.ING.getCode();
+        }
+        order.put("status", code);
+    }
+
+    private void tenantOrderSuccess(TenantOrderRecord orderRecord, Map<String, Object> detail) {
+        //机构产品信息
+        TenantProductInfo productInfo = tenantProductInfoService.getOne(new WrapperUtil<TenantProductInfo>()
+                .hasEq("tenant_id_", orderRecord.getTenantId()).queryWrapper());
+        //获取服务信息
+        PlatformServe platformServe = platformServeService.getOne(new WrapperUtil<PlatformServe>()
+                .hasEq("id_", productInfo.getServeId()).queryWrapper());
+        //获取服务详情
+        PlatformServeDetail serveDetail = platformServeDetailService.getOne(new WrapperUtil<PlatformServeDetail>()
+                .hasEq("id_", productInfo.getServeDetailId()).queryWrapper());
+        detail.put("platformServeName", platformServe.getName());
+        detail.put("mode", serveDetail.getMode());
+    }
+
 }
 

+ 27 - 17
mec-common/common-core/src/main/java/com/ym/mec/common/page/QueryWrapperUtil.java → mec-common/common-core/src/main/java/com/ym/mec/common/page/WrapperUtil.java

@@ -15,13 +15,15 @@ import java.util.stream.Collectors;
  * @author hgw
  * Created by 2021-12-20
  */
-public class QueryWrapperUtil<T> {
+public class WrapperUtil<T> {
 
     private final QueryWrapper<T> queryWrapper;
 
-    private final Predicate<? super Object> predicate = (Predicate<Object>) Objects::nonNull;
+    private final Predicate<? super Object> ObjPredicate = (Predicate<Object>) Objects::nonNull;
 
-    public QueryWrapperUtil() {
+    private final Predicate<? super Object> StrPredicate = (Predicate<Object>) o -> StringUtils.isNotBlank((String) o);
+
+    public WrapperUtil() {
         this.queryWrapper = new QueryWrapper<>();
     }
 
@@ -32,14 +34,13 @@ public class QueryWrapperUtil<T> {
      * @param column 列名称
      * @param val    值
      */
-    public QueryWrapperUtil<T> hasEq(String column, String val) {
-        Predicate<? super Object> predicate = (Predicate<Object>) o -> StringUtils.isNotBlank((String) o);
-        queryWrapper.eq(predicate.test(val), column, val);
+    public WrapperUtil<T> hasEq(String column, String val) {
+        queryWrapper.eq(StrPredicate.test(val), column, val);
         return this;
     }
 
-    public QueryWrapperUtil<T> hasEq(String column, Object val) {
-        queryWrapper.eq(predicate.test(val), column, val);
+    public WrapperUtil<T> hasEq(String column, Object val) {
+        queryWrapper.eq(ObjPredicate.test(val), column, val);
         return this;
     }
 
@@ -49,9 +50,9 @@ public class QueryWrapperUtil<T> {
      * @param column 列名称
      * @param val    逗号分开的值
      */
-    public QueryWrapperUtil<T> hasSplitIn(String column, String val) {
-        if (StringUtils.isNotBlank(val)) {
-            List<String> strings = QueryWrapperUtil.toList(val);
+    public WrapperUtil<T> hasSplitIn(String column, String val) {
+        if (StrPredicate.test(val)) {
+            List<String> strings = WrapperUtil.toList(val);
             if (CollectionUtils.isNotEmpty(strings)) {
                 queryWrapper.in(column, strings);
             }
@@ -60,14 +61,13 @@ public class QueryWrapperUtil<T> {
     }
 
     /**
-     * 可以当作结束语句
-     * 或者获取QueryWrapper类还可以继续拼接其他条件SQL
+     * 返回QueryWrapper
+     * @return QueryWrapper
      */
     public QueryWrapper<T> queryWrapper() {
         return queryWrapper;
     }
 
-
     public static List<String> toList(String key) {
         return toList(key, ",");
     }
@@ -77,15 +77,25 @@ public class QueryWrapperUtil<T> {
                 .orElse(null);
     }
 
-    private static Optional<List<String>> toListOptional(String key, String symbol) {
+    /**
+     * 将用逗号分割的字符串转换为List
+     *
+     * @param key 用逗号分割的字符
+     * @return Optional
+     */
+    public static Optional<List<String>> toListOptional(String key) {
+        return toListOptional(key, ",");
+    }
+
+    public static Optional<List<String>> toListOptional(String key, String symbol) {
         return Optional.ofNullable(key)
                 .filter(StringUtils::isNotBlank)
                 .map(b -> b.split(symbol))
-                .map(QueryWrapperUtil::collectToList)
+                .map(WrapperUtil::collectToList)
                 .filter(CollectionUtils::isNotEmpty);
     }
 
-    private static List<String> collectToList(String[] b) {
+    public static List<String> collectToList(String[] b) {
         return Arrays.stream(b).filter(StringUtils::isNotBlank).collect(Collectors.toList());
     }
 

+ 16 - 53
mec-student/src/main/java/com/ym/mec/student/controller/StudentOrderController.java

@@ -1,47 +1,5 @@
 package com.ym.mec.student.controller;
 
-import com.ym.mec.biz.dal.enums.CourseViewTypeEnum;
-import com.ym.mec.biz.dal.page.StudentPaymentOrderQueryInfo;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiImplicitParams;
-import io.swagger.annotations.ApiOperation;
-
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.net.URLEncoder;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.stream.Collectors;
-
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.http.HttpStatus;
-import org.springframework.scheduling.annotation.EnableScheduling;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.DigestUtils;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.ModelAttribute;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
-
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.ym.mec.auth.api.client.SysUserFeignService;
@@ -53,8 +11,8 @@ import com.ym.mec.biz.dal.enums.CourseViewTypeEnum;
 import com.ym.mec.biz.dal.enums.DealStatusEnum;
 import com.ym.mec.biz.dal.enums.GroupType;
 import com.ym.mec.biz.dal.enums.OrderTypeEnum;
-import com.ym.mec.biz.service.*;
 import com.ym.mec.biz.dal.page.StudentPaymentOrderQueryInfo;
+import com.ym.mec.biz.service.*;
 import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.page.PageInfo;
@@ -138,7 +96,8 @@ public class StudentOrderController extends BaseController {
     private VipGroupActivityDao vipGroupActivityDao;
     @Autowired
     private SellOrderService sellOrderService;
-
+    @Autowired
+    private TenantOrderRecordService tenantOrderRecordService;
 
     @Value("${spring.profiles.active:dev}")
     private String profiles;
@@ -194,6 +153,10 @@ public class StudentOrderController extends BaseController {
         }
         StudentPaymentOrder orderByOrderNo = studentPaymentOrderService.findOrderByOrderNo(orderNo);
         if (Objects.isNull(orderByOrderNo)) {
+            Map<String, Object> tenantOrder = tenantOrderRecordService.checkTenantOrder(orderNo);
+            if (Objects.nonNull(tenantOrder)) {
+                return tenantOrder;
+            }
             return failed("未找到指定订单");
         }
         HashMap<String, Object> orderDetail = new HashMap<>();
@@ -233,7 +196,7 @@ public class StudentOrderController extends BaseController {
                 orderDetail.put("member", cloudTeacherOrderService.queryOrderInfoByOrderId(orderByOrderNo.getId()));
             }
         } else if (orderByOrderNo.getGroupType().equals(GroupType.VIP)) {
-            if(StringUtils.isNotEmpty(orderByOrderNo.getMusicGroupId())){
+            if (StringUtils.isNotEmpty(orderByOrderNo.getMusicGroupId())) {
                 VipBuyResultDto vipBuyResultInfo = vipGroupService.findVipBuyResultInfo(Integer.valueOf(orderByOrderNo.getMusicGroupId()));
                 orderDetail.put("detail", vipBuyResultInfo);
             }
@@ -263,11 +226,11 @@ public class StudentOrderController extends BaseController {
             orderDetail.put("detail", vipGroupActivityDao.queryByIds(orderByOrderNo.getActivityId()));
         } else if (orderByOrderNo.getGroupType().equals(GroupType.MEMBER)) {
             CloudTeacherOrderDto orderDto = cloudTeacherOrderService.queryOrderInfoByOrderId(orderByOrderNo.getId());
-            orderDetail.put("detail",orderDto);
-            if(orderDto != null){
-                Map<String,Object> map = new HashMap<>(1);
-                map.put("paymentOrderId",orderDto.getCloudTeacherOrder().getOrderId());
-                orderDetail.put("couponList",sysCouponCodeDao.querySysCouponUseList(map));
+            orderDetail.put("detail", orderDto);
+            if (orderDto != null) {
+                Map<String, Object> map = new HashMap<>(1);
+                map.put("paymentOrderId", orderDto.getCloudTeacherOrder().getOrderId());
+                orderDetail.put("couponList", sysCouponCodeDao.querySysCouponUseList(map));
             }
         }
         return succeed(orderDetail);
@@ -902,9 +865,9 @@ public class StudentOrderController extends BaseController {
         if (orderDetails.size() > 0) {
             MusicGroup musicGroup = musicGroupService.get(order.getMusicGroupId());
             BigDecimal couponRemitFee = order.getCouponRemitFee();
-            if(couponRemitFee.compareTo(BigDecimal.ZERO) > 0){
+            if (couponRemitFee.compareTo(BigDecimal.ZERO) > 0) {
                 BigDecimal musicFee = orderDetails.stream().filter(o -> o.getType().getCode().equals("MUSICAL")
-                        || o.getType().getCode().equals("ACCESSORIES") || o.getType().getCode().equals("TEACHING"))
+                                || o.getType().getCode().equals("ACCESSORIES") || o.getType().getCode().equals("TEACHING"))
                         .map(o -> o.getPrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
                 BigDecimal expectAmount = order.getExpectAmount();
                 //获取比例
@@ -912,7 +875,7 @@ public class StudentOrderController extends BaseController {
                 //获取分配的减免金额
                 couponRemitFee = couponRemitFee.multiply(ratioAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
             }
-            sellOrders = sellOrderService.addOrderDetail2SellOrder(orderDetails, order, musicGroup,couponRemitFee);
+            sellOrders = sellOrderService.addOrderDetail2SellOrder(orderDetails, order, musicGroup, couponRemitFee);
         }
         return succeed(sellOrders);