!203 modify generate order error logic statement

Merge pull request !203 from Admin/sit-Carl-V3
This commit is contained in:
Admin 2022-03-04 10:25:42 +00:00 committed by Gitee
commit d853bede3f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 85 additions and 44 deletions

View File

@ -58,10 +58,11 @@ public class OrderController {
@ApiOperation(value = "微信支付订单", notes = "生成订单")
@PostMapping("royalcanin/generateOrderWX")
public ResponseDTO<Map<String, String>> generateOrderWX(@RequestBody List<OrdersEntity> ordersEntityList) throws Exception {
public ResponseDTO<Map<String, String>> generateOrderWX(@RequestBody List<OrdersEntity> ordersEntityList){
StringBuffer productId = new StringBuffer();
StringBuffer productName = new StringBuffer();
StringBuffer remark = new StringBuffer();
Map<String, String> 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<Map<String, String>> generateOrderWXH5(@RequestBody List<OrdersEntity> ordersEntityList) throws Exception {
public ResponseDTO<Map<String, String>> generateOrderWXH5(@RequestBody List<OrdersEntity> ordersEntityList){
StringBuffer productId = new StringBuffer();
StringBuffer productName = new StringBuffer();
Map<String, String> 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){
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<String, String> returnMap = new HashMap<>();
returnMap.put("orderNumber",ordersEntity.getOrderNo());
returnMap.put("orderAmount",ordersEntity.getOrderAmount());
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"));
}
return ResponseDTO.wrap(OrderResponseCodeConst.GENERATE_ORDER_FAIL);
}catch (Exception e){
System.out.println(e.getMessage());
}
return ResponseDTO.wrap(OrderResponseCodeConst.GENERATE_ORDER_FAIL,resultMsg.get("msg"));
}
@ApiOperation(value = "微信支付JSAPI订单", notes = "生成JSAPI订单")
@ -232,6 +248,7 @@ public class OrderController {
public ResponseDTO<Map<String, String>> generateOrderWXJSAPI(@RequestBody List<OrdersEntity> ordersEntityList,String resp) throws Exception {
StringBuffer productId = new StringBuffer();
StringBuffer productName = new StringBuffer();
Map<String, String> 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){
//判断订单生成状况
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<String, String> returnMap = new HashMap<>();
returnMap.put("orderNumber",ordersEntity.getOrderNo());
returnMap.put("orderAmount",ordersEntity.getOrderAmount());
return ResponseDTO.succData(returnMap,wxpayService.dounifiedOrderJSAPI(wxPayEntity,resp));
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"));
}
return ResponseDTO.wrap(OrderResponseCodeConst.GENERATE_ORDER_FAIL);
}catch (Exception e){
System.out.println(e.getMessage());
}
return ResponseDTO.wrap(OrderResponseCodeConst.GENERATE_ORDER_FAIL,resultMsg.get("msg"));
}

View File

@ -52,8 +52,9 @@ public class OrderService {
private String url ;
@Transactional
public int generateOrder(OrdersEntity ordersEntity, JSONArray listJson) throws Exception {
public Map<String,String> generateOrder(OrdersEntity ordersEntity, JSONArray listJson) throws Exception {
AddOrSaveEntity addOrSaveEntity = new AddOrSaveEntity();
Map<String, String>resultMap = 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){