更新商品订单状态
<h3>编写接收付款通知的Web方法</h3>
<pre><code class="language-java">@ApiOperation("接收消息通知")
@RequestMapping("/recieveMessage")
public void recieveMessage(HttpServletRequest request, HttpServletResponse response) throws Exception {
request.setCharacterEncoding("utf-8");
String tradeNo = request.getParameter("trade_no");
String code = request.getParameter("out_trade_no");
String tradeStatus = request.getParameter("trade_status");
if ("TRADE_FINISHED".equals(tradeStatus) || "TRADE_SUCCESS".equals(tradeStatus)) {
UpdateWrapper wrapper = new UpdateWrapper();
wrapper.eq("code", code);
wrapper.set("status", 2);
wrapper.set("payment_type", 2);
orderService.update(wrapper);
}
response.setCharacterEncoding("utf-8");
Writer writer = response.getWriter();
writer.write("success");
writer.close();
}</code></pre>
<h3>编写更新订单状态的Web方法</h3>
<pre><code class="language-java">@Login
@PostMapping("/updateOrderStatus")
@ApiOperation("更新商品订单状态")
public R updateOrderStatus(@RequestBody UpdateOrderStatusForm form,
@RequestHeader HashMap header) {
ValidatorUtils.validateEntity(form);
String token = header.get("token").toString();
int userId = Integer.parseInt(jwtUtils.getClaimByToken(token).getSubject());
int orderId = form.getOrderId();
OrderEntity orderEntity = new OrderEntity();
orderEntity.setUserId(userId);
orderEntity.setId(orderId);
QueryWrapper wrapper = new QueryWrapper(orderEntity);
int count = orderService.count(wrapper);
if (count == 0) {
return R.error("用户与订单不匹配");
}
orderEntity = orderService.getOne(wrapper);
String code = orderEntity.getCode();
try {
AlipayClient client = new DefaultAlipayClient(
gateway,
microApp_appId,
microApp_privateKey,
"json",
"UTF-8",
microApp_publicKey,
"RSA2"
);
AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
request.setBizContent("{" +
"\"out_trade_no\":\"" + code + "\"," +
" \"query_options\":[" +
" \"TRADE_SETTLE_INFO\"" +
" ]" +
" }");
AlipayTradeQueryResponse response = client.execute(request);
if (response.isSuccess()) {
String tradeStatus = response.getTradeStatus();
if ("TRADE_SUCCESS".equals(tradeStatus) || "TRADE_FINISHED".equals(tradeStatus)) {
UpdateWrapper updateWrapper = new UpdateWrapper();
updateWrapper.eq("code", code);
updateWrapper.set("status", 2);
updateWrapper.set("payment_type", 2);
updateWrapper.set("prepay_id", response.getTradeNo());
orderService.update(updateWrapper);
return R.ok("订单状态已修改");
} else {
return R.ok("订单状态未修改");
}
}
return R.ok("订单状态未修改");
} catch (Exception e) {
e.printStackTrace();
return R.error("查询支付订单失败");
}
}</code></pre>
<h3>编写order.vue代码</h3>
<pre><code>uni.request({
url: that.url.zfb.updateOrderStatus,
method: "POST",
header: {
"token":uni.getStorageSync("token")
},
data: {
"orderId": id
},
success: function(resp) {
let pages = getCurrentPages()
let page = pages[pages.length - 1]
page.onShow()
},
fail: function() {
console.log("更新订单状态失败")
}
})</code></pre>