瀏覽代碼

保存订单逻辑

lijun 5 年之前
父節點
當前提交
39a80d171e

+ 19 - 16
src/main/java/com/caimei/controller/order/OrderController.java

@@ -15,6 +15,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Controller;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 
@@ -127,7 +128,7 @@ public class OrderController {
     /**
      * 提交订单接口
      *
-     * @return code:1000=用户账户异常,1001=数据异常
+     * @return code:-1=(用户账户异常,数据异常,操作异常等),1提交成功(msg=1支付完成,2未完成支付)
      * @Param params参数格式:
      * 参数1=userId用户ID
      * 参数2=organizeID组织ID,
@@ -143,9 +144,10 @@ public class OrderController {
      * 参数6=balanceDeductionFlag是否使用余额抵扣(1使用,2不使用)
      * 参数7=orderShouldPayFee订单应付金额(商品总金额 - 余额抵扣 - 经理折扣默认为0)
      */
+    @Transactional
     @ResponseBody
     @RequestMapping("/submitOrder")
-    public WxJsonModel submitOrder(String params, HttpServletRequest request) {
+    public synchronized WxJsonModel submitOrder(String params, HttpServletRequest request) {
         WxJsonModel wxJsonModel = WxJsonModel.newInstance();
         logger.info(">>>>>>订单信息params:" + params);
         //检查用户是否登入
@@ -153,55 +155,56 @@ public class OrderController {
         HttpSession session = request.getSession();
         String openid = (String) session.getAttribute("openid");
         Integer organizeID1 = (Integer) session.getAttribute("organizeID");
+//        CmOperationUser currentUser = loginService.doLogin("oEjHd4gCC7SO5Eo3ogt5g4pj2mNU", 1);
         CmOperationUser currentUser = loginService.doLogin(openid, organizeID1);
         if (null == currentUser) {
-            return wxJsonModel.error("1000", "用户账户异常");
+            return wxJsonModel.error("-1", "用户账户异常");
         }
         Integer cmOperationID = currentUser.getId();//当前操作者ID
         if (StringUtils.isBlank(params)) {
-            return wxJsonModel.error("1001", "数据异常");
+            return wxJsonModel.error("-1", "数据异常");
         }
         Map<String, Object> map = new HashMap<String, Object>();
         try {
             map = (Map<String, Object>) JsonMapper.getInstance().fromJsonString(params, Map.class);
             if (null == map) {
                 logger.info(">>>>>数据异常,参数不能为空");
-                return wxJsonModel.error("1001", "数据异常");
+                return wxJsonModel.error("-1", "数据异常");
             }
             Integer userId = (Integer) map.get("userId");
             Integer organizeID = (Integer) map.get("organizeID");
-            String cartType = (String) map.get("cartType");
+            String cartType = String.valueOf(map.get("cartType")) ;
             Integer addressID = (Integer) map.get("addressID");
             Object orderInfo = map.get("orderInfo");
-            String balanceDeductionFlag = (String) map.get("balanceDeductionFlag");
-            Double orderShouldPayFee = (Double) map.get("orderShouldPayFee");//此金额为前端计算,适用于后端计算金额复查
+            String balanceDeductionFlag = String.valueOf(map.get("balanceDeductionFlag"));
+            Double orderShouldPayFee = Double.parseDouble(String.valueOf(map.get("orderShouldPayFee")));//此金额为前端计算,适用于后端计算金额复查
             //校验传入参数的正确性
             if (null == userId) {
-                return wxJsonModel.error("1001", "用户数据异常");
+                return wxJsonModel.error("-1", "用户数据异常");
             }
             if (null == organizeID) {
-                return wxJsonModel.error("1001", "组织数据异常");
+                return wxJsonModel.error("-1", "组织数据异常");
             }
             if (StringUtils.isEmpty(cartType)) {
-                return wxJsonModel.error("1001", "购买类型数据异常");
+                return wxJsonModel.error("-1", "购买类型数据异常");
             }
             if (null == addressID) {
-                return wxJsonModel.error("1001", "地址数据异常");
+                return wxJsonModel.error("-1", "地址数据异常");
             }
             if (null == orderInfo) {
-                return wxJsonModel.error("1001", "订单数据异常");
+                return wxJsonModel.error("-1", "订单数据异常");
             }
             if (StringUtils.isEmpty(balanceDeductionFlag)) {
-                return wxJsonModel.error("1001", "余额抵扣数据异常");
+                return wxJsonModel.error("-1", "余额抵扣数据异常");
             }
             if (null == orderShouldPayFee) {
-                return wxJsonModel.error("1001", "订单应付金额数据异常");
+                return wxJsonModel.error("-1", "订单应付金额数据异常");
             }
             //保存订单信息
             return orderService.saveOrderInfo(wxJsonModel, userId, organizeID, cartType, addressID, orderInfo, balanceDeductionFlag, orderShouldPayFee, cmOperationID);
         } catch (Exception e) {
             logger.info(">>>>>系统异常" + e.getMessage());
-            return wxJsonModel.error("1001", "数据异常");
+            return wxJsonModel.error("-1", "数据异常");
 
         }
     }

+ 9 - 0
src/main/java/com/caimei/entity/CmOrder.java

@@ -60,6 +60,7 @@ public class CmOrder implements Serializable {
     private String sendOutStatus;//发货状态:1待发货、2部分发货、3已发货
     private String refundType;//退货退款类型:1部分退、2全部退
     private List<CmShopOrder> shopOrderList; //子订单集合
+    private Long autoCloseTimeMills; //订单自动取消时间 毫秒
 
     public Integer getOrderID() {
         return orderID;
@@ -508,6 +509,14 @@ public class CmOrder implements Serializable {
     public void setShopOrderList(List<CmShopOrder> shopOrderList) {
         this.shopOrderList = shopOrderList;
     }
+
+    public Long getAutoCloseTimeMills() {
+        return autoCloseTimeMills;
+    }
+
+    public void setAutoCloseTimeMills(Long autoCloseTimeMills) {
+        this.autoCloseTimeMills = autoCloseTimeMills;
+    }
 }
 
 

+ 18 - 0
src/main/java/com/caimei/entity/CmShopOrder.java

@@ -76,6 +76,8 @@ public class CmShopOrder implements Serializable {
     private String buyStatus;
     private Integer useBeanAmount;
     private Integer useBeanFlag;
+    private Integer townID;
+    private Double fee;
 
 
 
@@ -583,4 +585,20 @@ public class CmShopOrder implements Serializable {
     public void setUseBeanFlag(Integer useBeanFlag) {
         this.useBeanFlag = useBeanFlag;
     }
+
+    public Integer getTownID() {
+        return townID;
+    }
+
+    public void setTownID(Integer townID) {
+        this.townID = townID;
+    }
+
+    public Double getFee() {
+        return fee;
+    }
+
+    public void setFee(Double fee) {
+        this.fee = fee;
+    }
 }

+ 8 - 0
src/main/java/com/caimei/entity/WxJsonModel.java

@@ -44,6 +44,14 @@ public class WxJsonModel implements Serializable {
         return this;
     }
 
+    public WxJsonModel success(String code, Object data, String msg) {
+        this.code = code;
+        this.msg = msg;
+        this.data = data;
+        return this;
+    }
+
+
     public WxJsonModel error() {
         this.code = "-1";
         this.msg = "操作失败";

+ 21 - 7
src/main/java/com/caimei/service/order/impl/OrderServiceImpl.java

@@ -20,6 +20,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
 import java.math.BigDecimal;
@@ -224,17 +225,19 @@ public class OrderServiceImpl implements OrderService {
     }
 
     @Override
+    @Transactional
     public WxJsonModel saveOrderInfo(WxJsonModel wxJsonModel, Integer userId, Integer organizeID, String cartType, Integer addressID, Object orderInfo, String balanceDeductionFlag, Double orderShouldPayFee, Integer cmOperationID) {
         /**获取用户信息*/
         User user = userMapper.findUserById(userId);
         /**获取用户包邮卡*/
         FreePostageCard freePostageCard = orderMapper.queryFree(userId);
         if (null == user) {
-            return wxJsonModel.error("1000", "用户账户异常");
+            return wxJsonModel.error("-1", "用户账户异常");
         }
         Integer clubID = user.getClubID();
         boolean isIncludedInstruments = false;//是否包含仪器(默认不包含仪器)
         boolean isIncludedProduct = false;//是否包含商品(默认不包含仪器)
+        boolean isPaySuccessFlag = false;//是完成支付(默认不是,只有余额抵扣才算)
         CmOrder cmOrder = new CmOrder();
         List<CmOrderProduct> orderProductList = new ArrayList<>();//整理订单商品列表
 //        List<Integer> shopIDs = new ArrayList<>();//整理子订单列表
@@ -256,8 +259,8 @@ public class OrderServiceImpl implements OrderService {
                 Integer shopId = (Integer) shopOrderInfo.get("shopId");
                 String note = (String) shopOrderInfo.get("note");
                 Object productInfo = shopOrderInfo.get("productInfo");//一个子订单对应的商品信息
-                if (null == shopId) return wxJsonModel.error("1001", "供应商数据异常");
-                if (null == productInfo) return wxJsonModel.error("1001", "订单商品数据异常");
+                if (null == shopId) return wxJsonModel.error("-1", "供应商数据异常");
+                if (null == productInfo) return wxJsonModel.error("-1", "订单商品数据异常");
 //                shopIDs.add(shopId);
                 shopIDs.put(shopId,note);
 
@@ -271,8 +274,8 @@ public class OrderServiceImpl implements OrderService {
                         productCount += productCount;
                         //获取商品信息
                         CmOrganizeProducts cmOrganizeProducts = organizeProductsMapper.selectProductById(productId);
-                        if (null == cmOrganizeProducts) return wxJsonModel.error("1001", "订单商品数据异常");
-                        if (null == productNum || productNum == 0) return wxJsonModel.error("1001", "商品购买数量异常");
+                        if (null == cmOrganizeProducts) return wxJsonModel.error("-1", "订单商品数据异常");
+                        if (null == productNum || productNum == 0) return wxJsonModel.error("-1", "商品购买数量异常");
                         Product cmProduct = organizeProductsMapper.selectCmProductById(cmOrganizeProducts.getProductID());
                         Double retailPrice = cmOrganizeProducts.getRetailPrice();//售价
                         Integer classifyID = cmOrganizeProducts.getClassifyID();
@@ -388,6 +391,7 @@ public class OrderServiceImpl implements OrderService {
                         cmOrder.setStatus(31);//已收款待发货
                         cmOrder.setReceiptStatus("3");
                         cmOrder.setPayFlag("1");
+                        isPaySuccessFlag = true;
                     } else if (payTotalFee == userMoney) {//刚好抵扣完
                         balancePayFee = payTotalFee;
                         user.setAbleUserMoney(new BigDecimal(0));
@@ -397,6 +401,7 @@ public class OrderServiceImpl implements OrderService {
                         cmOrder.setStatus(31);//已收款待发货
                         cmOrder.setReceiptStatus("3");
                         cmOrder.setPayFlag("1");
+                        isPaySuccessFlag = true;
                     }
                     cmOrder.setPayTime(dateStr);//支付时间
 
@@ -592,8 +597,17 @@ public class OrderServiceImpl implements OrderService {
 
             }
         }
-
-        return wxJsonModel.success();
+        Map<String,String> info = new HashMap<>();
+        info.put("orderID", String.valueOf(cmOrder.getOrderID()));
+        info.put("orderNo", String.valueOf(cmOrder.getOrderNo()));
+        info.put("orderMark", "#"+String.valueOf(cmOrder.getOrderID())+"#");
+        info.put("payTotalFee", String.valueOf(cmOrder.getPayTotalFee()));//应付订单金额
+        info.put("payableAmount", String.valueOf(cmOrder.getPayableAmount()));//真实需要付款金额
+        if(isPaySuccessFlag){//余额抵扣成功
+            return wxJsonModel.success("1",info,"提交成功且已支付");//1提交成功[且支付完成]
+        }else{
+            return wxJsonModel.success("2",info,"提交成功但未支付");
+        }
     }
 
 

+ 0 - 19
src/main/resources/mapper/CmShopOrderMapper.xml

@@ -15,7 +15,6 @@
 		a.presentNum AS "presentNum",
 		IFNULL(a.outStoreNum, 0) AS "outStoreNum",
 		IFNULL(a.outStoreTimes, 0) AS "outStoreTimes",
-		a.townID AS "townID",
 		a.note AS "note",
 		a.productAmount AS "productAmount",
 		a.fee AS "fee",
@@ -145,7 +144,6 @@
 			orderTime,
 			payTime,
 			finishTime,
-			status,
 			refundStatus,
 			receiveGoodsTime,
 			deliveryTimeMills,
@@ -155,15 +153,10 @@
 			clubID,
 			spID,
 			mainSpID,
-			orderBeanAmount,
-			useBeanAmount,
 			useBeanFlag,
 			canRefundFlag,
 			useBalanceFlag,
-			canRefundBeans,
 			orderDeliveryID,
-			freePostageFee,
-			freePostageTicketID,
 			brokerage,
 			delFlag,
 			refundsAmount,
@@ -200,7 +193,6 @@
 			#{orderTime},
 			#{payTime},
 			#{finishTime},
-			#{status},
 			#{refundStatus},
 			#{receiveGoodsTime},
 			#{deliveryTimeMills},
@@ -210,15 +202,10 @@
 			#{clubID},
 			#{spID},
 			#{mainSpID},
-			#{orderBeanAmount},
-			#{useBeanAmount},
 			#{useBeanFlag},
 			#{canRefundFlag},
 			#{useBalanceFlag},
-			#{canRefundBeans},
 			#{orderDeliveryID},
-			#{freePostageFee},
-			#{freePostageTicketID},
 			#{brokerage},
 			#{delFlag},
 			#{refundsAmount},
@@ -261,7 +248,6 @@
 			orderTime = #{orderTime},
 			payTime = #{payTime},
 			finishTime = #{finishTime},
-			status = #{status},
 			refundStatus = #{refundStatus},
 			receiveGoodsTime = #{receiveGoodsTime},
 			deliveryTimeMills = #{deliveryTimeMills},
@@ -271,15 +257,10 @@
 			clubID = #{clubID},
 			spID = #{spID},
 			mainSpID = #{mainSpID},
-			orderBeanAmount = #{orderBeanAmount},
-			useBeanAmount = #{useBeanAmount},
 			useBeanFlag = #{useBeanFlag},
 			canRefundFlag = #{canRefundFlag},
 			useBalanceFlag = #{useBalanceFlag},
-			canRefundBeans = #{canRefundBeans},
 			orderDeliveryID = #{orderDeliveryID},
-			freePostageFee = #{freePostageFee},
-			freePostageTicketID = #{freePostageTicketID},
 			brokerage = #{brokerage},
 			delFlag = #{delFlag},
 			refundsAmount = #{refundsAmount},

+ 58 - 58
src/main/resources/mapper/OrganizeProductsMapper.xml

@@ -59,7 +59,7 @@
         shopID,
         productID,
         organizeProductID,
-        organizeID
+        organizeID,
         num,
         presentNum,
         outStoreType,
@@ -170,62 +170,62 @@
 
 
     <update id="update">
-        UPDATE cm_order_product SET
-        orderNo = #{orderNo},
-        orderID = #{orderID},
-        shopOrderID = #{shopOrderID},
-        shopOrderNo = #{shopOrderNo},
-        shopID = #{shopID},
-        productID = #{productID},
-        organizeProductID = #{organizeProductID},
-        organizeID = #{organizeID},
-        num = #{num},
-        presentNum = #{presentNum},
-        outStoreType = #{outStoreType},
-        skuID = #{skuID},
-        props = #{props},
-        propName = #{propName},
-        productNo = #{productNo},
-        price = #{price},
-        normalPrice = #{normalPrice},
-        price0 = #{price0},
-        price1 = #{price1},
-        totalAmount = #{totalAmount},
-        discount = #{discount},
-        discountPrice = #{discountPrice},
-        taxRate = #{taxRate},
-        addedValueTax = #{addedValueTax},
-        totalAddedValueTax = #{totalAddedValueTax},
-        shouldPayTotalTax = #{shouldPayTotalTax,jdbcType=DECIMAL},
-        shopFee = #{shopFee},
-        otherFee = #{otherFee},
-        cmFee = #{cmFee},
-        singleShopFee = #{singleShopFee},
-        singleOtherFee = #{singleOtherFee},
-        singleCmFee = #{singleCmFee},
-        shouldPayFee = #{shouldPayFee},
-        commentFlag = #{commentFlag},
-        totalFee = #{totalFee},
-        totalBeans = #{totalBeans},
-        useBalanceAmount = #{useBalanceAmount},
-        useBeanAmount = #{useBeanAmount},
-        notOutStore = #{notOutStore},
-        cmbeanPrice = #{cmbeanPrice},
-        isGiftProduct = #{isGiftProduct},
-        productActInfo = #{productActInfo},
-        buyAgainFlag = #{buyAgainFlag},
-        confirmProductFlag = #{confirmProductFlag},
-        payStatus = #{payStatus},
-        shopName = #{shopName},
-        name = #{name},
-        discountFee = #{discountFee},
-        isActProduct = #{isActProduct},
-        preferential = #{preferential},
-        actPreferential = #{actPreferential},
-        actType = #{actType},
-        productImage = #{productImage},
-        productUnit = #{productUnit}
-        WHERE orderProductID = #{orderProductID}
-    </update>
+			UPDATE cm_order_product SET
+			orderNo = #{orderNo},
+			orderID = #{orderID},
+			shopOrderID = #{shopOrderID},
+			shopOrderNo = #{shopOrderNo},
+			shopID = #{shopID},
+			productID = #{productID},
+			organizeProductID = #{organizeProductID},
+			organizeID = #{organizeID},
+			num = #{num},
+			presentNum = #{presentNum},
+			outStoreType = #{outStoreType},
+			skuID = #{skuID},
+			props = #{props},
+			propName = #{propName},
+			productNo = #{productNo},
+			price = #{price},
+			normalPrice = #{normalPrice},
+			price0 = #{price0},
+			price1 = #{price1},
+			totalAmount = #{totalAmount},
+			discount = #{discount},
+			discountPrice = #{discountPrice},
+			taxRate = #{taxRate},
+			addedValueTax = #{addedValueTax},
+			totalAddedValueTax = #{totalAddedValueTax},
+			shouldPayTotalTax = #{shouldPayTotalTax,jdbcType=DECIMAL},
+			shopFee = #{shopFee},
+			otherFee = #{otherFee},
+			cmFee = #{cmFee},
+			singleShopFee = #{singleShopFee},
+			singleOtherFee = #{singleOtherFee},
+			singleCmFee = #{singleCmFee},
+			shouldPayFee = #{shouldPayFee},
+			commentFlag = #{commentFlag},
+			totalFee = #{totalFee},
+			totalBeans = #{totalBeans},
+			useBalanceAmount = #{useBalanceAmount},
+			useBeanAmount = #{useBeanAmount},
+			notOutStore = #{notOutStore},
+			cmbeanPrice = #{cmbeanPrice},
+			isGiftProduct = #{isGiftProduct},
+			productActInfo = #{productActInfo},
+			buyAgainFlag = #{buyAgainFlag},
+			confirmProductFlag = #{confirmProductFlag},
+			payStatus = #{payStatus},
+			shopName = #{shopName},
+			name = #{name},
+			discountFee = #{discountFee},
+			isActProduct = #{isActProduct},
+			preferential = #{preferential},
+			actPreferential = #{actPreferential},
+			actType = #{actType},
+			productImage = #{productImage},
+			productUnit = #{productUnit}
+			WHERE orderProductID = #{orderProductID}
+		</update>
 	
 </mapper>