Browse Source

余额支付,优惠券

liujunchi 2 years ago
parent
commit
4791796f5e

+ 3 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderServiceImpl.java

@@ -1102,7 +1102,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
 
 
         Date date = new Date();
-        StudentPaymentOrder studentPaymentOrder = sysCouponCodeService.use(model.getCouponIdList(), model.getAmount(),false);
+        StudentPaymentOrder studentPaymentOrder = sysCouponCodeService.use(model.getCouponIdList(), model.getAmount(),true);
 
         studentPaymentOrder.setStatus(DealStatusEnum.ING);
         if (studentPaymentOrder.getActualAmount().compareTo(BigDecimal.ZERO) == 0) {
@@ -1124,6 +1124,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
         studentPaymentOrder.setRoutingOrganId(student.getOrganId());
         studentPaymentOrder.setTenantId(student.getTenantId());
         studentPaymentOrderService.insert(studentPaymentOrder);
+        studentPaymentOrder.setVersion(0);
 
         // 余额支付
         BigDecimal amount = studentPaymentOrder.getActualAmount();
@@ -1171,8 +1172,8 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
 
         //  receiver类型
         payMap = payService.getPayMap(
-                studentPaymentOrder.getExpectAmount(),
                 studentPaymentOrder.getActualAmount(),
+                studentPaymentOrder.getBalancePaymentAmount(),
                 model.getOrderNo(),
                 baseApiUrl + "/api-mall-portal/payment/callback",
                 baseApiUrl + "/api-student/studentOrder/paymentResult?type=edu&orderNo=" + model.getOrderNo(),

+ 6 - 5
mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/controller/OmsOrderController.java

@@ -52,11 +52,12 @@ public class OmsOrderController {
     @RequestMapping(value = "/update/close", method = RequestMethod.POST)
     @ResponseBody
     public CommonResult close(@RequestParam("ids") List<Long> ids, @RequestParam String note) {
-        int count = orderService.close(ids, note);
-        if (count > 0) {
-            return CommonResult.success(count);
-        }
-        return CommonResult.failed();
+
+        // int count = orderService.close(ids, note);
+        // if (count > 0) {
+        //     return CommonResult.success(count);
+        // }
+        return CommonResult.failed("当前状态不可关闭");
     }
 
     @ApiOperation("批量删除订单")

+ 1 - 0
mec-mall/mall-mbg/src/main/resources/config/mybatis/PmsSkuStockMapper.xml

@@ -307,4 +307,5 @@
   <update id="lockStock">
     update pms_sku_stock set lock_stock = lock_stock + #{quantity} where  id = #{productSkuId} and stock &gt;= ( lock_stock + #{quantity})
     </update>
+
 </mapper>

+ 14 - 15
mec-mall/mall-portal/src/main/java/com/yonge/cooleshow/portal/controller/open/OpenShareController.java

@@ -1,36 +1,28 @@
 package com.yonge.cooleshow.portal.controller.open;
 
-import com.ym.mec.auth.api.client.SysUserFeignService;
-import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.common.controller.BaseController;
-import com.ym.mec.common.entity.HttpResponseResult;
-import com.yonge.cooleshow.mall.common.api.CommonResult;
-import com.yonge.cooleshow.mall.common.util.StringUtil;
-import com.yonge.cooleshow.portal.dto.ShareProductVo;
-import com.yonge.cooleshow.portal.dto.ShareProfitParam;
+import com.yonge.cooleshow.portal.dto.StockOperateModel;
 import com.yonge.cooleshow.portal.service.PmsPortalProductService;
 import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
 
-import javax.annotation.Resource;
+import java.util.List;
 
 @RestController
 @RequestMapping("/open")
-@Api(tags = "开放权限接口-分享")
+@Api(tags = "开放权限接口")
 public class OpenShareController extends BaseController {
     private final static Logger log = LoggerFactory.getLogger(OpenShareController.class);
 
     @Autowired
-    private SysUserFeignService sysUserFeignService;
-
-    @Autowired
     private PmsPortalProductService portalProductService;
 
-
     // @ApiOperation(value = "老师商品分享分润")
     // @PostMapping(value="/productProfit")
     // @ResponseBody
@@ -49,4 +41,11 @@ public class OpenShareController extends BaseController {
     //     }
     //     return CommonResult.failed("分享功能暂未开放");
     // }
+
+    public void updateStock(@RequestBody List<StockOperateModel> model, @RequestParam String stockType) {
+        // 库存操作 stockType  add:添加   reduce:减少  lock:锁定  unlock:解锁
+        portalProductService.reduceStock(model,stockType);
+
+
+    }
 }

+ 17 - 0
mec-mall/mall-portal/src/main/java/com/yonge/cooleshow/portal/dao/PortalProductDao.java

@@ -4,6 +4,7 @@ import com.yonge.cooleshow.mbg.model.SmsCoupon;
 import com.yonge.cooleshow.portal.domain.CartProduct;
 import com.yonge.cooleshow.portal.domain.ProductStock;
 import com.yonge.cooleshow.portal.domain.PromotionProduct;
+import com.yonge.cooleshow.portal.dto.StockOperateModel;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -32,4 +33,20 @@ public interface PortalProductDao {
      * 改库存
      */
     void updateProductStock(@Param("itemList") List<ProductStock> productStockList);
+
+    /**
+     * 释放sku锁定库存
+     */
+    void unlockSku(@Param("itemList") List<StockOperateModel> model);
+
+    /**
+     * 释放商品锁定库存
+     */
+    void unlockProduct(@Param("itemList") List<ProductStock> productList);
+
+    /**
+     * 扣减sku库存
+     */
+    void reduceSku(@Param("itemList") List<StockOperateModel> model);
+
 }

+ 46 - 0
mec-mall/mall-portal/src/main/java/com/yonge/cooleshow/portal/dto/StockOperateModel.java

@@ -0,0 +1,46 @@
+package com.yonge.cooleshow.portal.dto;
+
+/**
+ * Description
+ *
+ * @author liujunchi
+ * @date 2022-09-26
+ */
+public class StockOperateModel {
+
+    // 商品id
+    private Long productId;
+
+    // 商品sku id
+    private Long productSkuId;
+
+    // 数量
+    private Integer count;
+
+
+
+    public Long getProductId() {
+        return productId;
+    }
+
+    public void setProductId(Long productId) {
+        this.productId = productId;
+    }
+
+    public Long getProductSkuId() {
+        return productSkuId;
+    }
+
+    public void setProductSkuId(Long productSkuId) {
+        this.productSkuId = productSkuId;
+    }
+
+    public Integer getCount() {
+        return count;
+    }
+
+    public void setCount(Integer count) {
+        this.count = count;
+    }
+
+}

+ 9 - 0
mec-mall/mall-portal/src/main/java/com/yonge/cooleshow/portal/service/PmsPortalProductService.java

@@ -6,6 +6,7 @@ import com.yonge.cooleshow.portal.domain.PmsPortalProductDetail;
 import com.yonge.cooleshow.portal.domain.PmsProductCategoryNode;
 import com.yonge.cooleshow.portal.dto.ProductSearchConditionVo;
 import com.yonge.cooleshow.portal.dto.ShareProductVo;
+import com.yonge.cooleshow.portal.dto.StockOperateModel;
 
 import java.util.List;
 
@@ -43,4 +44,12 @@ public interface PmsPortalProductService {
      * @param productId 商品id
      */
     ShareProductVo shareProductProfit(SysUser sysUser, Long productId);
+
+    /**
+     * 同步修改商品库存
+     *
+     * @param model
+     * @param stockType
+     */
+    void reduceStock(List<StockOperateModel> model, String stockType);
 }

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

@@ -153,7 +153,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
                 userOrderPaymentService.saveOrUpdate(userOrderPayment);
 
                 return feignMecCreateOrder(order.getCouponId(), oldOrderNo, orderSn, null, detail.getMemberId().intValue(), detail.getTotalAmount(),
-                                           JSON.toJSONString(detail));
+                                           JSON.toJSONString(detail),detail.getPayType() == 3);
             } else {
                 throw new BizException("订单信息获取失败");
             }
@@ -203,11 +203,12 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
         if (!hasStock(cartPromotionItemList)) {
             Asserts.fail("库存不足,无法下单");
         }
-
+        BigDecimal couponAmount = BigDecimal.ZERO;
         BigDecimal amount = calcTotalAmount(orderItemList);
-        Map data = feignMecCouponAmount(orderParam.getCouponId(), orderParam.getOrderAmount());
-
-        BigDecimal couponAmount = MapUtil.get(data, "mallCouponAmount", BigDecimal.class);
+        if (!StringUtil.isEmpty(orderParam.getCouponId())) {
+            Map data = feignMecCouponAmount(orderParam.getCouponId(), amount);
+            couponAmount = MapUtil.get(data, "mallCouponAmount", BigDecimal.class);
+        }
         if (couponAmount == null) {
             couponAmount = BigDecimal.ZERO;
         }
@@ -298,8 +299,12 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
         order.setMemberId(currentMember.getId());
         order.setCreateTime(new Date());
         order.setMemberUsername(currentMember.getUsername());
-        //支付方式:0->未支付;1->支付宝;2->微信
-        order.setPayType(orderParam.getPayType());
+        //支付方式:0->未支付;1->支付宝;2->微信 3:余额
+        if (orderParam.isUseBalance()) {
+            order.setPayType(3);
+        } else {
+            order.setPayType(orderParam.getPayType());
+        }
         //订单来源:0->PC订单;1->app订单
         order.setSourceType(1);
         //订单状态:0->待付款;1->待发货;2->已发货;3->已完成;4->已关闭;5->无效订单 6 -> 未支付
@@ -377,7 +382,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
         // 生成订单
         // 保存商品信息到管乐迷
         OmsOrderDetail detail = detail(order.getOrderSn());
-        data = feignMecCreateOrder(orderParam.getCouponId(),orderParam.getOrderNo(), orderSn,
+        Map data = feignMecCreateOrder(orderParam.getCouponId(),orderParam.getOrderNo(), orderSn,
                                        orderParam.getTeacherId()==null?null:orderParam.getTeacherId().intValue(),
                                        currentMember.getId().intValue(), amount,JSON.toJSONString(detail),orderParam.isUseBalance());
         if ("1".equals(MapUtil.getStr(data, "tradeState"))) {

+ 64 - 0
mec-mall/mall-portal/src/main/java/com/yonge/cooleshow/portal/service/impl/PmsPortalProductServiceImpl.java

@@ -4,14 +4,17 @@ import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.StrUtil;
 import com.github.pagehelper.PageHelper;
 import com.ym.mec.auth.api.entity.SysUser;
+import com.yonge.cooleshow.mall.common.exception.Asserts;
 import com.yonge.cooleshow.mbg.mapper.*;
 import com.yonge.cooleshow.mbg.model.*;
 import com.yonge.cooleshow.portal.dao.PortalProductDao;
 import com.yonge.cooleshow.portal.domain.PmsPortalProductDetail;
 import com.yonge.cooleshow.portal.domain.PmsProductCategoryNode;
+import com.yonge.cooleshow.portal.domain.ProductStock;
 import com.yonge.cooleshow.portal.dto.ProductCategorySmallVo;
 import com.yonge.cooleshow.portal.dto.ProductSearchConditionVo;
 import com.yonge.cooleshow.portal.dto.ShareProductVo;
+import com.yonge.cooleshow.portal.dto.StockOperateModel;
 import com.yonge.cooleshow.portal.service.PmsPortalProductService;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -19,6 +22,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -48,6 +52,8 @@ public class PmsPortalProductServiceImpl implements PmsPortalProductService {
     @Autowired
     private PortalProductDao portalProductDao;
 
+    @Autowired
+    private PmsProductMapper pmsProductMapper;
 
     @Autowired
     private PmsProductAttributeCategoryMapper productAttributeCategoryMapper;
@@ -209,6 +215,64 @@ public class PmsPortalProductServiceImpl implements PmsPortalProductService {
         return shareProductVo;
     }
 
+    @Override
+    public void reduceStock(List<StockOperateModel> model, String stockType) {
+
+        // 商品库存变动
+        List<ProductStock> productList = new ArrayList<>();
+        Map<Long, List<StockOperateModel>> collect = model.stream().collect(Collectors.groupingBy(
+                StockOperateModel::getProductId));
+        for (Map.Entry<Long, List<StockOperateModel>> entry : collect.entrySet()) {
+            ProductStock productStock = new ProductStock();
+            List<StockOperateModel> value = entry.getValue();
+            if (CollectionUtils.isEmpty(value)) {
+                continue;
+            }
+            int sum = value.stream().mapToInt(StockOperateModel::getCount).sum();
+            productStock.setProductId(entry.getKey());
+            productStock.setStock(sum);
+            productList.add(productStock);
+        }
+        switch (stockType) {
+            case "lock" :
+                // sku库存锁定
+                for (StockOperateModel stockOperateModel : model) {
+                    int i = skuStockMapper.lockStock(stockOperateModel.getProductSkuId(), stockOperateModel.getCount());
+                    if (i ==0) {
+                        Asserts.fail("库存不足");
+                    }
+                }
+                // 商品扣减锁定
+                for (ProductStock product : productList) {
+                    if (product.getStock() > 0) {
+                        int i = pmsProductMapper.lockStock(product.getProductId(), product.getStock());
+                        if (i == 0) {
+                            Asserts.fail("库存不足");
+                        }
+                    }
+                }
+                break;
+            case "unlock" :
+                // 解锁sku库存
+                portalProductDao.unlockSku(model);
+
+                // 解锁商品库存
+                portalProductDao.unlockProduct(productList);
+                break;
+            case "reduce" :
+                // 扣减sku库存
+                portalProductDao.reduceSku(model);
+
+                // 扣减商品库存
+                portalProductDao.updateProductStock(productList);
+                break;
+            default: break;
+
+        }
+
+
+    }
+
 
     private  List<PmsProductAttributeCategory>  getHomeProductAttributeCategory() {
         PmsProductAttributeCategoryExample example = new PmsProductAttributeCategoryExample();

+ 56 - 0
mec-mall/mall-portal/src/main/resources/config/mybatis/PortalProductDao.xml

@@ -120,4 +120,60 @@
             #{item.productId}
         </foreach>
     </update>
+
+    <update id="unlockSku">
+        UPDATE pms_sku_stock
+        SET
+        lock_stock = CASE id
+        <foreach collection="itemList" item="item">
+            WHEN #{item.productSkuId} THEN lock_stock - #{item.count}
+        </foreach>
+        END
+        WHERE
+        id IN
+        <foreach collection="itemList" item="item" separator="," open="(" close=")">
+            #{item.productSkuId}
+        </foreach>
+    </update>
+
+    <update id="unlockProduct">
+        UPDATE pms_product
+        SET
+        lock_stock = CASE id
+        <foreach collection="itemList" item="item">
+            WHEN #{item.productId} THEN lock_stock - #{item.stock}
+        </foreach>
+        END
+        WHERE
+        id IN
+        <foreach collection="itemList" item="item" separator="," open="(" close=")">
+            #{item.productId}
+        </foreach>
+    </update>
+
+    <update id="reduceSku">
+        UPDATE pms_sku_stock
+        SET
+        stock = CASE id
+        <foreach collection="itemList" item="item">
+            WHEN #{item.productSkuId} THEN stock - #{item.count}
+        </foreach>
+        END,
+        sale = CASE id
+        <foreach collection="itemList" item="item">
+            WHEN #{item.productSkuId} THEN pms_sku_stock.sale + #{item.count}
+        </foreach>
+        END,
+        lock_stock = CASE id
+        <foreach collection="itemList" item="item">
+            WHEN #{item.productSkuId} THEN lock_stock - #{item.count}
+        </foreach>
+        END
+        WHERE
+        id IN
+        <foreach collection="itemList" item="item" separator="," open="(" close=")">
+            #{item.productSkuId}
+        </foreach>
+    </update>
+
 </mapper>