!165 2022-2-15Carl

Merge pull request !165 from Admin/sit-Carl-V3
This commit is contained in:
Admin 2022-02-15 03:43:22 +00:00 committed by Gitee
commit 04ac3899df
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 146 additions and 0 deletions

View File

@ -29,6 +29,7 @@ public class AliPayService {
bizContent.put("total_amount",aliPayEntity.getTotal_amount()); bizContent.put("total_amount",aliPayEntity.getTotal_amount());
bizContent.put("out_trade_no",aliPayEntity.getOut_trade_no()); bizContent.put("out_trade_no",aliPayEntity.getOut_trade_no());
bizContent.put("goods_detail", aliPayEntity.getGoodsDetail()); bizContent.put("goods_detail", aliPayEntity.getGoodsDetail());
bizContent.put("product_code", aliPayEntity.getProduct_code());
AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
request.setBizContent(bizContent.toString()); request.setBizContent(bizContent.toString());
request.setNotifyUrl(AlipayConfig.notify_url); request.setNotifyUrl(AlipayConfig.notify_url);
@ -49,6 +50,7 @@ public class AliPayService {
bizContent.put("total_amount",aliPayEntity.getTotal_amount()); bizContent.put("total_amount",aliPayEntity.getTotal_amount());
bizContent.put("out_trade_no",aliPayEntity.getOut_trade_no()); bizContent.put("out_trade_no",aliPayEntity.getOut_trade_no());
bizContent.put("goods_detail", aliPayEntity.getGoodsDetail()); bizContent.put("goods_detail", aliPayEntity.getGoodsDetail());
bizContent.put("product_code", aliPayEntity.getProduct_code());
AlipayTradePagePayRequest request = new AlipayTradePagePayRequest (); AlipayTradePagePayRequest request = new AlipayTradePagePayRequest ();
request.setBizContent(bizContent.toString()); request.setBizContent(bizContent.toString());
request.setNotifyUrl(AlipayConfig.notify_url); request.setNotifyUrl(AlipayConfig.notify_url);

View File

@ -220,6 +220,85 @@ public class OrderController {
return ResponseDTO.wrap(OrderResponseCodeConst.GENERATE_ORDER_FAIL); return ResponseDTO.wrap(OrderResponseCodeConst.GENERATE_ORDER_FAIL);
} }
@ApiOperation(value = "微信支付JSAPI订单", notes = "生成JSAPI订单")
@PostMapping("royalcanin/generateOrderWXJSAPI")
public ResponseDTO<Map<String, String>> generateOrderWXJSAPI(@RequestBody List<OrdersEntity> ordersEntityList) throws Exception {
StringBuffer productId = new StringBuffer();
StringBuffer productName = new StringBuffer();
String memberId = "";
String mobile = "";
int buyCount = 0;
double total_fee = 0 ;
double basePoint = 0 ;
WxPayEntity wxPayEntity = new WxPayEntity();
JSONArray orderDatilListJson = new JSONArray();
OrdersEntity ordersEntity = new OrdersEntity();
OrderAddress orderAddress = new OrderAddress();
for (OrdersEntity ordersEntitys:ordersEntityList) {
cartService.cancelProduct(ordersEntitys.getMemberId(),ordersEntity.getProductCode());
//存储orderDetailList
OrderDatilListEntity orderDatilListEntity= new OrderDatilListEntity();
orderDatilListEntity.setProductName(ordersEntitys.getProductName());
orderDatilListEntity.setPcs(ordersEntitys.getBuyCount());
orderDatilListEntity.setProductCode(ordersEntitys.getProductCode());
orderDatilListEntity.setEcPrice(ordersEntitys.getPayAmount());
orderDatilListJson.add(orderDatilListEntity);
if(ordersEntitys.getCouponCode() != "" && ordersEntitys.getCouponCode() != null) {
CouponGetAllEntity couponGetAllEntity = new CouponGetAllEntity ();
couponGetAllEntity.setMemberId(ordersEntitys.getMemberId());
couponGetAllEntity.setCouponCode(ordersEntitys.getCouponCode());
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);
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() ;
}
basePoint = basePoint + ordersEntitys.getBasePoint();
orderAddress.setAddressCityName(ordersEntitys.getOrderAddress().getAddressCityName());
orderAddress.setAddressCountyName(ordersEntitys.getOrderAddress().getAddressCountyName());
orderAddress.setAddressDetailInfo(ordersEntitys.getOrderAddress().getAddressDetailInfo());
orderAddress.setAddressPhoneNumber(ordersEntitys.getOrderAddress().getAddressPhoneNumber());
orderAddress.setAddressUserName(ordersEntitys.getOrderAddress().getAddressUserName());
orderAddress.setAddressProvinceName(ordersEntitys.getOrderAddress().getAddressProvinceName());
productId.append(ordersEntitys.getProductCode()+",");
productName.append(ordersEntitys.getProductName()+",");
memberId = ordersEntitys.getMemberId();
mobile = ordersEntitys.getPhoneNumber();
buyCount = buyCount + ordersEntitys.getBuyCount();
}
ordersEntity.setOrderAddress(orderAddress);
ordersEntity.setProductCode(productId.substring(0,productId.length()-1));
ordersEntity.setProductName(productName.substring(0,productName.length()-1));
ordersEntity.setOrderAmount(StringUtil.toString(total_fee));
ordersEntity.setMemberId(memberId);
ordersEntity.setPhoneNumber(mobile);
ordersEntity.setBuyCount(buyCount);
ordersEntity.setOrderNo(GenerateSequenceUtil.generateSequenceNo());
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<String, String> returnMap = new HashMap<>();
returnMap.put("orderNumber",ordersEntity.getOrderNo());
returnMap.put("orderAmount",ordersEntity.getOrderAmount());
return ResponseDTO.succData(returnMap,wxpayService.dounifiedOrderJSAPI(wxPayEntity));
}
return ResponseDTO.wrap(OrderResponseCodeConst.GENERATE_ORDER_FAIL);
}
@ApiOperation(value = "重新支付(二维码)", notes = "重新支付(二维码)") @ApiOperation(value = "重新支付(二维码)", notes = "重新支付(二维码)")
@PostMapping("royalcanin/repayOrderWX") @PostMapping("royalcanin/repayOrderWX")
public ResponseDTO<String> repayOrderWX(String orderNo) throws Exception { public ResponseDTO<String> repayOrderWX(String orderNo) throws Exception {
@ -277,6 +356,30 @@ public class OrderController {
} }
} }
@ApiOperation(value = "重新支付JSAPI", notes = "重新支付JSAPI")
@PostMapping("royalcanin/repayOrderWXH5")
public ResponseDTO<String> repayOrderWXJSAPI(String orderNo) throws Exception {
OrderEntity ordersEntity = orderService.findByOrderId(orderNo);
if(ordersEntity != null){
QueryEntity queryEntity = new QueryEntity();
queryEntity.setOrderNumber(ordersEntity.getOrderNo());
String orderInfo = orderService.query(queryEntity);
com.alibaba.fastjson.JSONArray jsonArray = JSONObject.parseArray(orderInfo);
JSONObject jsonObject = (JSONObject)jsonArray.get(0);
if(jsonObject.getString("status").equals("0")) {
WxPayEntity wxPayEntity = new WxPayEntity();
wxPayEntity.setProduct_id(ordersEntity.getProductCode());
wxPayEntity.setTotal_fee(jsonObject.getString("salesAmount"));
wxPayEntity.setOut_trade_no(ordersEntity.getOrderNo());
return ResponseDTO.succData(wxpayService.dounifiedOrderJSAPI(wxPayEntity));
}else {
return ResponseDTO.wrap(OrderResponseCodeConst.GENERATE_ORDER_ERROR,orderInfo);
}
}else {
return ResponseDTO.wrap(OrderResponseCodeConst.WITHOUT_ORDER);
}
}

View File

@ -250,7 +250,48 @@ public class WxpayService {
} }
/**
* /H5微信支付(预下单)
* @return
* @throws Exception
*/
public String dounifiedOrderJSAPI(WxPayEntity wxPayEntity) throws Exception {
//返回参数
Map<String, String> returnMap = new HashMap<>();
WXPay wxpay = new WXPay(config);
//请求参数封装
Map<String, String> data = new HashMap<>();
data.put("out_trade_no",wxPayEntity.getOut_trade_no());
data.put("notify_url",config.notify_url);
data.put("fee_type","CNY");
data.put("total_fee",getMoney(wxPayEntity.getTotal_fee()));
data.put("spbill_create_ip", SmartIPUtil.getLocalHostIP());
data.put("trade_type", "JSAPI"); // 此处指定为H5支付
data.put("body","皇家宠物食品官方商城");
data.put("nonce_str", WXPayUtil.generateNonceStr());
data.put("product_id",wxPayEntity.getProduct_id());
String s = WXPayUtil.generateSignature(data, config.getKey()); //签名
data.put("sign", s);//签名
try {
//使用官方API请求预付订单
Map<String, String> response = wxpay.unifiedOrder(data);
String returnCode = response.get("return_code");//获取返回码
//若返回码为SUCCESS则会返回一个result_code,再对该result_code进行判断
if (returnCode.equals("SUCCESS")) {
net.sf.json.JSONObject jsonResponse = net.sf.json.JSONObject.fromObject(response);
return jsonResponse.toString();
} else {
returnMap.put("ok", "201");
return "";
}
} catch (Exception e) {
System.out.println(e);
return "ERROR!";
//系统等其他错误的时候
}
}
/** /**

Binary file not shown.

Before

Width:  |  Height:  |  Size: 214 KiB

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB