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 4903db0b..5f8a9545 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 @@ -58,10 +58,11 @@ public class OrderController { @ApiOperation(value = "微信支付订单", notes = "生成订单") @PostMapping("royalcanin/generateOrderWX") - public ResponseDTO> generateOrderWX(@RequestBody List ordersEntityList) throws Exception { + public ResponseDTO> generateOrderWX(@RequestBody List ordersEntityList){ StringBuffer productId = new StringBuffer(); StringBuffer productName = new StringBuffer(); StringBuffer remark = new StringBuffer(); + Map resultMsg = new HashMap<>(); String memberId = ""; String mobile = ""; int buyCount = 0; @@ -73,7 +74,7 @@ public class OrderController { OrderAddress orderAddress = new OrderAddress(); try { for (OrdersEntity ordersEntitys : ordersEntityList) { -// System.out.println("ordersEntityList.size()"+ordersEntityList.size()); + //删除购物车信息 cartService.cancelProduct(ordersEntitys.getMemberId(), ordersEntity.getProductCode()); //存储orderDetailList OrderDatilListEntity orderDatilListEntity = new OrderDatilListEntity(); @@ -89,6 +90,9 @@ public class OrderController { String couponInfo = couponService.couponGetAll(couponGetAllEntity); JSONObject jsonObject = JSONObject.parseObject(couponInfo); com.alibaba.fastjson.JSONArray jsonArray = JSONObject.parseArray(jsonObject.getString("data")); + if(jsonArray.size() == 0){ + return ResponseDTO.wrap(OrderResponseCodeConst.COUPON_USE_FAIL); + } JSONObject jsonObjectData = (JSONObject) jsonArray.get(0); if (jsonObjectData.getString("udf2") != null){ if (!jsonObjectData.getString("udf2").equals("H5")){ @@ -104,7 +108,6 @@ public class OrderController { total_fee = total_fee + Double.parseDouble(ordersEntitys.getPayAmount()) * ordersEntitys.getBuyCount(); } basePoint = basePoint + ordersEntitys.getBasePoint(); -// System.out.println("basePoint"+basePoint); orderAddress.setAddressCityName(ordersEntitys.getOrderAddress().getAddressCityName()); orderAddress.setAddressCountyName(ordersEntitys.getOrderAddress().getAddressCountyName()); orderAddress.setAddressDetailInfo(ordersEntitys.getOrderAddress().getAddressDetailInfo()); @@ -129,9 +132,8 @@ public class OrderController { ordersEntity.setOrderStatus("0"); ordersEntity.setBasePoint(basePoint); ordersEntity.setRemark(remark.substring(0,remark.length() - 1)); - int result = orderService.generateOrder(ordersEntity, orderDatilListJson); - if (result == 1) { - System.out.println("orderService.generateOrder(ordersEntity, orderDatilListJson) == 1"); + resultMsg = orderService.generateOrder(ordersEntity, orderDatilListJson); + if (resultMsg.get("code").equals("1")) { wxPayEntity.setProduct_id(ordersEntity.getProductCode()); wxPayEntity.setTotal_fee(StringUtil.toString(total_fee)); wxPayEntity.setOut_trade_no(ordersEntity.getOrderNo()); @@ -139,21 +141,22 @@ public class OrderController { returnMap.put("orderNumber", ordersEntity.getOrderNo()); returnMap.put("orderAmount", ordersEntity.getOrderAmount()); return ResponseDTO.succData(returnMap, wxpayService.generateQRCode(wxPayEntity)); - }else if (result == 3){ - return ResponseDTO.wrap(OrderResponseCodeConst.GENERATE_FAIL_COUPONDED); + }else if (resultMsg.get("code").equals("3")){ + return ResponseDTO.wrap(OrderResponseCodeConst.GENERATE_ORDER_ERROR,resultMsg.get("msg")); } }catch (Exception e){ System.out.println(e.getMessage()); } - return ResponseDTO.wrap(OrderResponseCodeConst.GENERATE_ORDER_FAIL); + return ResponseDTO.wrap(OrderResponseCodeConst.GENERATE_ORDER_FAIL,resultMsg.get("msg")); } @ApiOperation(value = "微信支付H5订单", notes = "生成H5订单") @PostMapping("royalcanin/generateOrderWXH5") - public ResponseDTO> generateOrderWXH5(@RequestBody List ordersEntityList) throws Exception { + public ResponseDTO> generateOrderWXH5(@RequestBody List ordersEntityList){ StringBuffer productId = new StringBuffer(); StringBuffer productName = new StringBuffer(); + Map resultMsg = new HashMap<>(); String memberId = ""; String mobile = ""; int buyCount = 0; @@ -163,6 +166,7 @@ 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()); //存储orderDetailList @@ -179,7 +183,15 @@ public class OrderController { String couponInfo = couponService.couponGetAll(couponGetAllEntity); JSONObject jsonObject = JSONObject.parseObject(couponInfo); com.alibaba.fastjson.JSONArray jsonArray = JSONObject.parseArray(jsonObject.getString("data")); - JSONObject jsonObjectData = (JSONObject)jsonArray.get(0); + if(jsonArray.size() == 0){ + return ResponseDTO.wrap(OrderResponseCodeConst.COUPON_USE_FAIL); + } + JSONObject jsonObjectData = (JSONObject) jsonArray.get(0); + if (jsonObjectData.getString("udf2") != null){ + if (!jsonObjectData.getString("udf2").equals("H5")){ + return ResponseDTO.wrap(OrderResponseCodeConst.COUPON_USE_FAIL); + } + } ordersEntity.setCouponAmount(jsonObjectData.getString("couponAmount") == null ?jsonObjectData.getString("discount"):jsonObjectData.getString("couponAmount")); ordersEntity.setCouponCode(jsonObjectData.getString("couponCode")); @@ -213,18 +225,22 @@ public class OrderController { ordersEntity.setOrderStatus("0"); ordersEntity.setBasePoint(basePoint); ordersEntity.setPayType("3"); - - if(orderService.generateOrder(ordersEntity,orderDatilListJson) == 1){ - wxPayEntity.setProduct_id(ordersEntity.getProductCode()); - wxPayEntity.setTotal_fee(StringUtil.toString(total_fee)); - wxPayEntity.setOut_trade_no(ordersEntity.getOrderNo()); - - Map returnMap = new HashMap<>(); - returnMap.put("orderNumber",ordersEntity.getOrderNo()); - returnMap.put("orderAmount",ordersEntity.getOrderAmount()); - return ResponseDTO.succData(returnMap,wxpayService.dounifiedOrder(wxPayEntity)); + resultMsg = orderService.generateOrder(ordersEntity, orderDatilListJson); + if (resultMsg.get("code").equals("1")) { + wxPayEntity.setProduct_id(ordersEntity.getProductCode()); + wxPayEntity.setTotal_fee(StringUtil.toString(total_fee)); + wxPayEntity.setOut_trade_no(ordersEntity.getOrderNo()); + Map returnMap = new HashMap<>(); + returnMap.put("orderNumber", ordersEntity.getOrderNo()); + returnMap.put("orderAmount", ordersEntity.getOrderAmount()); + return ResponseDTO.succData(returnMap,wxpayService.dounifiedOrder(wxPayEntity)); + }else if (resultMsg.get("code").equals("3")){ + return ResponseDTO.wrap(OrderResponseCodeConst.GENERATE_ORDER_ERROR,resultMsg.get("msg")); + } + }catch (Exception e){ + System.out.println(e.getMessage()); } - return ResponseDTO.wrap(OrderResponseCodeConst.GENERATE_ORDER_FAIL); + return ResponseDTO.wrap(OrderResponseCodeConst.GENERATE_ORDER_FAIL,resultMsg.get("msg")); } @ApiOperation(value = "微信支付JSAPI订单", notes = "生成JSAPI订单") @@ -232,6 +248,7 @@ public class OrderController { public ResponseDTO> generateOrderWXJSAPI(@RequestBody List ordersEntityList,String resp) throws Exception { StringBuffer productId = new StringBuffer(); StringBuffer productName = new StringBuffer(); + Map resultMsg = new HashMap<>(); String memberId = ""; String mobile = ""; int buyCount = 0; @@ -241,6 +258,7 @@ 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()); //存储orderDetailList @@ -257,7 +275,15 @@ public class OrderController { String couponInfo = couponService.couponGetAll(couponGetAllEntity); JSONObject jsonObject = JSONObject.parseObject(couponInfo); com.alibaba.fastjson.JSONArray jsonArray = JSONObject.parseArray(jsonObject.getString("data")); - JSONObject jsonObjectData = (JSONObject)jsonArray.get(0); + if(jsonArray.size() == 0){ + return ResponseDTO.wrap(OrderResponseCodeConst.COUPON_USE_FAIL); + } + JSONObject jsonObjectData = (JSONObject) jsonArray.get(0); + if (jsonObjectData.getString("udf2") != null){ + if (!jsonObjectData.getString("udf2").equals("H5")){ + return ResponseDTO.wrap(OrderResponseCodeConst.COUPON_USE_FAIL); + } + } ordersEntity.setCouponAmount(jsonObjectData.getString("couponAmount") == null ?jsonObjectData.getString("discount"):jsonObjectData.getString("couponAmount")); ordersEntity.setCouponCode(jsonObjectData.getString("couponCode")); @@ -291,18 +317,22 @@ public class OrderController { ordersEntity.setOrderStatus("0"); ordersEntity.setBasePoint(basePoint); ordersEntity.setPayType("3"); - - if(orderService.generateOrder(ordersEntity,orderDatilListJson) == 1){ - wxPayEntity.setProduct_id(ordersEntity.getProductCode()); - wxPayEntity.setTotal_fee(StringUtil.toString(total_fee)); - wxPayEntity.setOut_trade_no(ordersEntity.getOrderNo()); - - Map returnMap = new HashMap<>(); - returnMap.put("orderNumber",ordersEntity.getOrderNo()); - returnMap.put("orderAmount",ordersEntity.getOrderAmount()); - return ResponseDTO.succData(returnMap,wxpayService.dounifiedOrderJSAPI(wxPayEntity,resp)); + //判断订单生成状况 + if (resultMsg.get("code").equals("1")) { + wxPayEntity.setProduct_id(ordersEntity.getProductCode()); + wxPayEntity.setTotal_fee(StringUtil.toString(total_fee)); + wxPayEntity.setOut_trade_no(ordersEntity.getOrderNo()); + Map returnMap = new HashMap<>(); + returnMap.put("orderNumber", ordersEntity.getOrderNo()); + returnMap.put("orderAmount", ordersEntity.getOrderAmount()); + return ResponseDTO.succData(returnMap, wxpayService.generateQRCode(wxPayEntity)); + }else if (resultMsg.get("code").equals("3")){ + return ResponseDTO.wrap(OrderResponseCodeConst.GENERATE_ORDER_ERROR,resultMsg.get("msg")); + } + }catch (Exception e){ + System.out.println(e.getMessage()); } - return ResponseDTO.wrap(OrderResponseCodeConst.GENERATE_ORDER_FAIL); + return ResponseDTO.wrap(OrderResponseCodeConst.GENERATE_ORDER_FAIL,resultMsg.get("msg")); } diff --git a/smart-admin-service/smart-admin-api/src/main/java/net/lab1024/smartadmin/module/system/royalcanin/good/service/OrderService.java b/smart-admin-service/smart-admin-api/src/main/java/net/lab1024/smartadmin/module/system/royalcanin/good/service/OrderService.java index 2800e796..23afbcdb 100644 --- a/smart-admin-service/smart-admin-api/src/main/java/net/lab1024/smartadmin/module/system/royalcanin/good/service/OrderService.java +++ b/smart-admin-service/smart-admin-api/src/main/java/net/lab1024/smartadmin/module/system/royalcanin/good/service/OrderService.java @@ -52,8 +52,9 @@ public class OrderService { private String url ; @Transactional - public int generateOrder(OrdersEntity ordersEntity, JSONArray listJson) throws Exception { + public Map generateOrder(OrdersEntity ordersEntity, JSONArray listJson) throws Exception { AddOrSaveEntity addOrSaveEntity = new AddOrSaveEntity(); + MapresultMap = new HashMap<>(); try { if (ordersEntity.getCouponCode() != "" && null != ordersEntity.getCouponCode()) { CouponCosumeEntity couponCosumeEntity = new CouponCosumeEntity(); @@ -64,7 +65,9 @@ public class OrderService { couponCosumeEntity.setRealCouponAmount(realCouponAmount); JSONObject jsonObject = JSONObject.parseObject(couponService.couponCosume(couponCosumeEntity)); if (!jsonObject.getString("code").equals("0")) { - return 3; + resultMap.put("code",jsonObject.getString("code")); + resultMap.put("msg",jsonObject.getString("msg")); + return resultMap; } //coupon json化 OrderCouponEntity orderCouponEntity = new OrderCouponEntity(); @@ -99,18 +102,26 @@ public class OrderService { addOrSaveEntity.setAddressUserName(orderAddress.getAddressUserName()); JSONObject jsonObject = JSONObject.parseObject(addOrSave(addOrSaveEntity)); - if (jsonObject.getString("code").equals("1")) - return 1; - else - return 0; + if (jsonObject.getString("code").equals("1")){ + resultMap.put("code",jsonObject.getString("code")); + resultMap.put("msg",jsonObject.getString("msg")); + return resultMap; + }else{ + resultMap.put("code",jsonObject.getString("code")); + resultMap.put("msg",jsonObject.getString("msg")); + return resultMap; + } } else { - return 0; + resultMap.put("code","0"); + resultMap.put("msg","订单生成有误,请联系管理员!"); + return resultMap; } }catch (Exception e){ - System.out.println(e.getMessage() - ); + System.out.println(e.getMessage()); } - return 0; + resultMap.put("code","0"); + resultMap.put("msg","数据操作有误,请联系管理员!"); + return resultMap; } public int checkNotify(String orderNumber){