From 404d870b7deaec99affd5ecfb4e47da40e9159a3 Mon Sep 17 00:00:00 2001 From: "376654749@qq.com" Date: Mon, 14 Mar 2022 17:22:19 +0800 Subject: [PATCH] adding order logic --- .../royalcanin/good/OrderController.java | 92 ++++++++++++------- 1 file changed, 59 insertions(+), 33 deletions(-) diff --git a/smart-admin-service/smart-admin-api/src/main/java/net/lab1024/smartadmin/module/system/royalcanin/good/OrderController.java b/smart-admin-service/smart-admin-api/src/main/java/net/lab1024/smartadmin/module/system/royalcanin/good/OrderController.java index a4ff8f95..20a2d17a 100644 --- a/smart-admin-service/smart-admin-api/src/main/java/net/lab1024/smartadmin/module/system/royalcanin/good/OrderController.java +++ b/smart-admin-service/smart-admin-api/src/main/java/net/lab1024/smartadmin/module/system/royalcanin/good/OrderController.java @@ -18,7 +18,9 @@ import net.lab1024.smartadmin.module.system.royalcanin.good.constant.OrderRespon import net.lab1024.smartadmin.module.system.royalcanin.good.model.OrderAddress; import net.lab1024.smartadmin.module.system.royalcanin.good.model.OrderEntity; import net.lab1024.smartadmin.module.system.royalcanin.good.model.OrdersEntity; +import net.lab1024.smartadmin.module.system.royalcanin.good.model.ProductMasterQueryEntity; import net.lab1024.smartadmin.module.system.royalcanin.good.service.CartService; +import net.lab1024.smartadmin.module.system.royalcanin.good.service.GoodService; import net.lab1024.smartadmin.module.system.royalcanin.good.service.OrderService; import net.lab1024.smartadmin.module.system.royalcanin.orderMaster.OrderDatilListEntity; import net.lab1024.smartadmin.module.system.royalcanin.orderMaster.QueryEntity; @@ -55,6 +57,9 @@ public class OrderController { @Autowired private CouponService couponService; + @Autowired + private GoodService goodService; + @ApiOperation(value = "微信支付订单", notes = "生成订单") @PostMapping("royalcanin/generateOrderWX") @@ -77,11 +82,17 @@ public class OrderController { //删除购物车信息 cartService.cancelProduct(ordersEntitys.getMemberId(), ordersEntity.getProductCode()); //存储orderDetailList + ProductMasterQueryEntity productMasterQueryEntity = new ProductMasterQueryEntity(); + productMasterQueryEntity.setProductCode(ordersEntitys.getProductCode()); + String goodsStr = goodService.productQuery(productMasterQueryEntity); + + com.alibaba.fastjson.JSONArray jsonGoodsArray = JSONObject.parseArray(goodsStr); + JSONObject goodsObject = (JSONObject)jsonGoodsArray.get(0); OrderDatilListEntity orderDatilListEntity = new OrderDatilListEntity(); - orderDatilListEntity.setProductName(ordersEntitys.getProductName()); + orderDatilListEntity.setProductName(goodsObject.getString("productName")); orderDatilListEntity.setPcs(ordersEntitys.getBuyCount()); - orderDatilListEntity.setProductCode(ordersEntitys.getProductCode()); - orderDatilListEntity.setEcPrice(ordersEntitys.getPayAmount()); + orderDatilListEntity.setProductCode(goodsObject.getString("productCode")); + orderDatilListEntity.setEcPrice(goodsObject.getString("ecPrice")); orderDatilListJson.add(orderDatilListEntity); if (ordersEntitys.getCouponCode() != "" && ordersEntitys.getCouponCode() != null) { CouponGetAllEntity couponGetAllEntity = new CouponGetAllEntity(); @@ -103,9 +114,10 @@ public class OrderController { ordersEntity.setCouponCode(jsonObjectData.getString("couponCode")); ordersEntity.setCouponName(jsonObjectData.getString("couponName")); ordersEntity.setCouponId(jsonObjectData.getString("couponId")); - total_fee = total_fee + orderService.couponTotal(ordersEntitys.getCouponTypeId(), Double.parseDouble(ordersEntitys.getCouponAmount()), Double.parseDouble(ordersEntitys.getPayAmount()), ordersEntitys.getBuyCount()); + ordersEntity.setCouponTypeId(jsonObjectData.getString("couponTypeId")); + total_fee = total_fee + orderService.couponTotal(ordersEntity.getCouponTypeId(), Double.parseDouble(ordersEntity.getCouponAmount()), Double.parseDouble(goodsObject.getString("ecPrice")), ordersEntitys.getBuyCount()); } else { - total_fee = total_fee + Double.parseDouble(ordersEntitys.getPayAmount()) * ordersEntitys.getBuyCount(); + total_fee = total_fee + Double.parseDouble(goodsObject.getString("ecPrice")) * ordersEntitys.getBuyCount(); } basePoint = basePoint + ordersEntitys.getBasePoint(); orderAddress.setAddressCityName(ordersEntitys.getOrderAddress().getAddressCityName()); @@ -170,18 +182,25 @@ public class OrderController { JSONArray orderDatilListJson = new JSONArray(); OrdersEntity ordersEntity = new OrdersEntity(); OrderAddress orderAddress = new OrderAddress(); - try{ - for (OrdersEntity ordersEntitys:ordersEntityList) { - cartService.cancelProduct(ordersEntitys.getMemberId(),ordersEntity.getProductCode()); + try { + for (OrdersEntity ordersEntitys : ordersEntityList) { + //删除购物车信息 + cartService.cancelProduct(ordersEntitys.getMemberId(), ordersEntity.getProductCode()); //存储orderDetailList - OrderDatilListEntity orderDatilListEntity= new OrderDatilListEntity(); - orderDatilListEntity.setProductName(ordersEntitys.getProductName()); + ProductMasterQueryEntity productMasterQueryEntity = new ProductMasterQueryEntity(); + productMasterQueryEntity.setProductCode(ordersEntitys.getProductCode()); + String goodsStr = goodService.productQuery(productMasterQueryEntity); + + com.alibaba.fastjson.JSONArray jsonGoodsArray = JSONObject.parseArray(goodsStr); + JSONObject goodsObject = (JSONObject)jsonGoodsArray.get(0); + OrderDatilListEntity orderDatilListEntity = new OrderDatilListEntity(); + orderDatilListEntity.setProductName(goodsObject.getString("productName")); orderDatilListEntity.setPcs(ordersEntitys.getBuyCount()); - orderDatilListEntity.setProductCode(ordersEntitys.getProductCode()); - orderDatilListEntity.setEcPrice(ordersEntitys.getPayAmount()); + orderDatilListEntity.setProductCode(goodsObject.getString("productCode")); + orderDatilListEntity.setEcPrice(goodsObject.getString("ecPrice")); orderDatilListJson.add(orderDatilListEntity); - if(ordersEntitys.getCouponCode() != "" && ordersEntitys.getCouponCode() != null) { - CouponGetAllEntity couponGetAllEntity = new CouponGetAllEntity (); + if (ordersEntitys.getCouponCode() != "" && ordersEntitys.getCouponCode() != null) { + CouponGetAllEntity couponGetAllEntity = new CouponGetAllEntity(); couponGetAllEntity.setMemberId(ordersEntitys.getMemberId()); couponGetAllEntity.setCouponCode(ordersEntitys.getCouponCode()); String couponInfo = couponService.couponGetAll(couponGetAllEntity); @@ -196,14 +215,14 @@ public class OrderController { return ResponseDTO.wrap(OrderResponseCodeConst.COUPON_USE_FAIL); } } - - ordersEntity.setCouponAmount(jsonObjectData.getString("couponAmount") == null ?jsonObjectData.getString("discount"):jsonObjectData.getString("couponAmount")); + ordersEntity.setCouponAmount(jsonObjectData.getString("couponAmount") == null ? jsonObjectData.getString("discount") : jsonObjectData.getString("couponAmount")); ordersEntity.setCouponCode(jsonObjectData.getString("couponCode")); ordersEntity.setCouponName(jsonObjectData.getString("couponName")); ordersEntity.setCouponId(jsonObjectData.getString("couponId")); - total_fee = total_fee + orderService.couponTotal(ordersEntitys.getCouponTypeId(),Double.parseDouble(ordersEntitys.getCouponAmount()),Double.parseDouble(ordersEntitys.getPayAmount()),ordersEntitys.getBuyCount()); - }else{ - total_fee = total_fee + Double.parseDouble(ordersEntitys.getPayAmount()) * ordersEntitys.getBuyCount() ; + ordersEntity.setCouponTypeId(jsonObjectData.getString("couponTypeId")); + total_fee = total_fee + orderService.couponTotal(ordersEntity.getCouponTypeId(), Double.parseDouble(ordersEntity.getCouponAmount()), Double.parseDouble(goodsObject.getString("ecPrice")), ordersEntitys.getBuyCount()); + } else { + total_fee = total_fee + Double.parseDouble(goodsObject.getString("ecPrice")) * ordersEntitys.getBuyCount(); } basePoint = basePoint + ordersEntitys.getBasePoint(); orderAddress.setAddressCityName(ordersEntitys.getOrderAddress().getAddressCityName()); @@ -266,18 +285,25 @@ public class OrderController { JSONArray orderDatilListJson = new JSONArray(); OrdersEntity ordersEntity = new OrdersEntity(); OrderAddress orderAddress = new OrderAddress(); - try{ - for (OrdersEntity ordersEntitys:ordersEntityList) { - cartService.cancelProduct(ordersEntitys.getMemberId(),ordersEntity.getProductCode()); + try { + for (OrdersEntity ordersEntitys : ordersEntityList) { + //删除购物车信息 + cartService.cancelProduct(ordersEntitys.getMemberId(), ordersEntity.getProductCode()); //存储orderDetailList - OrderDatilListEntity orderDatilListEntity= new OrderDatilListEntity(); - orderDatilListEntity.setProductName(ordersEntitys.getProductName()); + ProductMasterQueryEntity productMasterQueryEntity = new ProductMasterQueryEntity(); + productMasterQueryEntity.setProductCode(ordersEntitys.getProductCode()); + String goodsStr = goodService.productQuery(productMasterQueryEntity); + + com.alibaba.fastjson.JSONArray jsonGoodsArray = JSONObject.parseArray(goodsStr); + JSONObject goodsObject = (JSONObject)jsonGoodsArray.get(0); + OrderDatilListEntity orderDatilListEntity = new OrderDatilListEntity(); + orderDatilListEntity.setProductName(goodsObject.getString("productName")); orderDatilListEntity.setPcs(ordersEntitys.getBuyCount()); - orderDatilListEntity.setProductCode(ordersEntitys.getProductCode()); - orderDatilListEntity.setEcPrice(ordersEntitys.getPayAmount()); + orderDatilListEntity.setProductCode(goodsObject.getString("productCode")); + orderDatilListEntity.setEcPrice(goodsObject.getString("ecPrice")); orderDatilListJson.add(orderDatilListEntity); - if(ordersEntitys.getCouponCode() != "" && ordersEntitys.getCouponCode() != null) { - CouponGetAllEntity couponGetAllEntity = new CouponGetAllEntity (); + if (ordersEntitys.getCouponCode() != "" && ordersEntitys.getCouponCode() != null) { + CouponGetAllEntity couponGetAllEntity = new CouponGetAllEntity(); couponGetAllEntity.setMemberId(ordersEntitys.getMemberId()); couponGetAllEntity.setCouponCode(ordersEntitys.getCouponCode()); String couponInfo = couponService.couponGetAll(couponGetAllEntity); @@ -292,14 +318,14 @@ public class OrderController { return ResponseDTO.wrap(OrderResponseCodeConst.COUPON_USE_FAIL); } } - - ordersEntity.setCouponAmount(jsonObjectData.getString("couponAmount") == null ?jsonObjectData.getString("discount"):jsonObjectData.getString("couponAmount")); + ordersEntity.setCouponAmount(jsonObjectData.getString("couponAmount") == null ? jsonObjectData.getString("discount") : jsonObjectData.getString("couponAmount")); ordersEntity.setCouponCode(jsonObjectData.getString("couponCode")); ordersEntity.setCouponName(jsonObjectData.getString("couponName")); ordersEntity.setCouponId(jsonObjectData.getString("couponId")); - total_fee = total_fee + orderService.couponTotal(ordersEntitys.getCouponTypeId(),Double.parseDouble(ordersEntitys.getCouponAmount()),Double.parseDouble(ordersEntitys.getPayAmount()),ordersEntitys.getBuyCount()); - }else{ - total_fee = total_fee + Double.parseDouble(ordersEntitys.getPayAmount()) * ordersEntitys.getBuyCount() ; + ordersEntity.setCouponTypeId(jsonObjectData.getString("couponTypeId")); + total_fee = total_fee + orderService.couponTotal(ordersEntity.getCouponTypeId(), Double.parseDouble(ordersEntity.getCouponAmount()), Double.parseDouble(goodsObject.getString("ecPrice")), ordersEntitys.getBuyCount()); + } else { + total_fee = total_fee + Double.parseDouble(goodsObject.getString("ecPrice")) * ordersEntitys.getBuyCount(); } basePoint = basePoint + ordersEntitys.getBasePoint(); orderAddress.setAddressCityName(ordersEntitys.getOrderAddress().getAddressCityName());