|
@@ -69,6 +69,7 @@ import java.net.URLDecoder;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
@Service("orderService")
|
|
@@ -159,6 +160,11 @@ public class OrderServiceImpl implements OrderService {
|
|
|
@Autowired
|
|
|
private MkActivitiesCouponService mkActivitiesCouponService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OrderRefundService orderRefundService;
|
|
|
+ @Autowired
|
|
|
+ private OrderExceptionRecordService orderExceptionRecordService;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public OrderEntity queryObject(Long id) {
|
|
@@ -1672,8 +1678,8 @@ public class OrderServiceImpl implements OrderService {
|
|
|
String machineCode = (String) param.get("machineCode");
|
|
|
try {
|
|
|
machineCode = URLDecoder.decode(machineCode,"UTF-8");
|
|
|
- } catch (UnsupportedEncodingException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
|
|
@@ -1817,7 +1823,7 @@ public class OrderServiceImpl implements OrderService {
|
|
|
}else if(taxObject instanceof String){
|
|
|
tax = new BigDecimal((String) taxObject) ;
|
|
|
}
|
|
|
- totalTax = totalTax.add(tax); // 计算总的税额
|
|
|
+ totalTax = totalTax.add(tax).setScale(2,BigDecimal.ROUND_HALF_DOWN); // 计算总的税额
|
|
|
|
|
|
if(goodsDto.get("actualPaymentAmount") instanceof Double){
|
|
|
goodsEntity.setStoreRetailPrice(new BigDecimal((Double)goodsDto.get("actualPaymentAmount")));
|
|
@@ -1942,10 +1948,21 @@ public class OrderServiceImpl implements OrderService {
|
|
|
processRecordEntity.setPaymentStartTime(new Date());
|
|
|
|
|
|
|
|
|
- // 微信支付
|
|
|
-// wxPay(user, parCode, resultObj, order, processRecordEntity, orderWXPayRecordCurrent, store);
|
|
|
+ // 判断是微信的支付码还是支付宝的支付码
|
|
|
+ if (parCode.startsWith("28")) {
|
|
|
// 支付宝支付
|
|
|
// AliPay(user, parCode , order, processRecordEntity, orderWXPayRecordCurrent, store);
|
|
|
+
|
|
|
+ }else{
|
|
|
+ // 微信支付
|
|
|
+// try {
|
|
|
+// wxPay(user, parCode, resultObj, order, processRecordEntity, orderWXPayRecordCurrent, store);
|
|
|
+// } catch (ParseException e) {
|
|
|
+// throw e;
|
|
|
+// }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
OrderEntity orderEntity = queryObject(order.getId());
|
|
|
// orderEntity.setOrderStatus(Integer.parseInt(Dict.orderStatus.item_201.getItem()));
|
|
|
// orderEntity.setPayStatus(Integer.parseInt(Dict.payStatus.item_2.getItem()));
|
|
@@ -2232,7 +2249,7 @@ public class OrderServiceImpl implements OrderService {
|
|
|
R r;
|
|
|
WechatMicropayApiResult wechatMicropayApiResult = WechatUtil
|
|
|
.wxMicropay(store.getMerchName() + "-" + store.getStoreName(), order.getOrderBizType(), null,
|
|
|
- orderWXPayRecordCurrent.getOutTradeNoWX(), order.getActual_price().doubleValue(),
|
|
|
+ orderWXPayRecordCurrent.getOutTradeNoWX(), 0.01d/*order.getActual_price().doubleValue()*/,
|
|
|
"127.0.0.1", parCode);
|
|
|
orderWXPayRecordService.updateRecord(orderWXPayRecordCurrent.getId(), wechatMicropayApiResult);
|
|
|
|
|
@@ -2278,6 +2295,26 @@ public class OrderServiceImpl implements OrderService {
|
|
|
//用户支付中
|
|
|
} else if (WechatUtil.WXTradeState.USERPAYING.getCode().equals(wechatMicropayApiResult.getTrade_state())) {
|
|
|
r = R.error(WechatUtil.WXTradeState.USERPAYING.getCodeZn() + ",稍等片刻后请刷新页面重新查看订单状态");
|
|
|
+ int times = 0;
|
|
|
+ // 查询是否支付了
|
|
|
+ while(true){
|
|
|
+ boolean flag = orderQuery(order, processRecordEntity);
|
|
|
+ if(flag ){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Thread.currentThread().sleep(1000);
|
|
|
+
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if(times >= 30){
|
|
|
+ throw new RuntimeException("超过30s未支付,订单下单失败");
|
|
|
+ }
|
|
|
+ times++;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
//用户支付失败
|
|
|
} else if (WechatUtil.WXTradeState.PAYERROR.getCode().equals(wechatMicropayApiResult.getTrade_state())) {
|
|
|
WechatReverseApiResult wechatReverseApiResult =
|
|
@@ -2300,6 +2337,85 @@ public class OrderServiceImpl implements OrderService {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean orderQuery(OrderVo order, OrderProcessRecordEntity processRecordEntity) {
|
|
|
+ LOGGER.info(">>>>>>>>>>>>>>>>>>>>wxOrderQuery 微信查询接口调用");
|
|
|
+ String merchOrderSn = order.getMerchOrderSn();
|
|
|
+ String orderId = order.getId() + "";
|
|
|
+ String orderSn = order.getOrder_sn();
|
|
|
+ WechatRefundApiResult result = WechatUtil.wxOrderQuery(orderSn);
|
|
|
+ if (result.getReturn_code().equalsIgnoreCase(WechatUtil.WXTradeState.SUCCESS.getCode())) {
|
|
|
+ if (result.getResult_code().equalsIgnoreCase(WechatUtil.WXTradeState.SUCCESS.getCode()) ){
|
|
|
+ if(result.getTrade_state().equalsIgnoreCase(Dict.tradeState.item_SUCCESS.getItem())) {
|
|
|
+ Date successTime = DateUtils.convertStringToDate(result.getTime_end(),
|
|
|
+ DateUtils.DATE_TIME_PATTERN_YYYY_MM_DD_HH_MM_SS);
|
|
|
+ Map orderRaram = Maps.newHashMap();
|
|
|
+ orderRaram.put("payStatus", Dict.payStatus.item_2.getItem());//已支付
|
|
|
+ orderRaram.put("orderStatus", Dict.orderStatus.item_201.getItem());//已支付
|
|
|
+ orderRaram.put("payTransactionId", result.getTransaction_id());
|
|
|
+ orderRaram.put("payTime", successTime);
|
|
|
+ orderRaram.put("orderId", orderId);
|
|
|
+ orderRaram.put("payFlag",Dict.payFlag.item_weixin.getItem());
|
|
|
+ orderDao.updateOrderInfo(orderRaram);
|
|
|
+ Map processParam = Maps.newHashMap();
|
|
|
+ processParam.put("payTime", successTime);
|
|
|
+ processParam.put("orderSn", orderSn);
|
|
|
+ orderDao.updateOrderProcessRecord(processParam);
|
|
|
+
|
|
|
+
|
|
|
+ // 设置支付单完成时间
|
|
|
+ processRecordEntity.setPaymentSuccTimeStr(result.getTime_end());
|
|
|
+ processRecordEntity.setPaymentSuccTime(successTime);
|
|
|
+ processRecordEntity.setPayTransactionId(result.getTransaction_id());
|
|
|
+ return true;
|
|
|
+
|
|
|
+ } else if (result.getTrade_state().equalsIgnoreCase(Dict.tradeState.item_NOTPAY.getItem())) {//订单未支付
|
|
|
+ Map orderRaram = Maps.newHashMap();
|
|
|
+
|
|
|
+ orderRaram.put("payStatus", Dict.payStatus.item_0.getItem());//支付状态未支付
|
|
|
+ orderRaram.put("orderStatus", Dict.orderStatus.item_0.getItem());//订单状态未支付
|
|
|
+
|
|
|
+ orderRaram.put("orderId", orderId);
|
|
|
+ orderDao.updateOrderInfo(orderRaram);
|
|
|
+ } else if (result.getTrade_state().equalsIgnoreCase(Dict.tradeState.item_CLOSED.getItem())) {
|
|
|
+ Map orderRaram = Maps.newHashMap();
|
|
|
+ orderRaram.put("payStatus", Dict.payStatus.item_7.getItem());
|
|
|
+ orderRaram.put("orderStatus", Dict.orderStatus.item_500.getItem());
|
|
|
+ orderRaram.put("orderId", orderId);
|
|
|
+ orderDao.updateOrderInfo(orderRaram);
|
|
|
+ LOGGER.info(">>>>>>>>>>>>>>>>>>>>wxOrderByTransactionIdQueryUpdFail 根据支付单查询微信接口返回信息:state 【" + result.getTrade_state() +
|
|
|
+ "】,des【" + result.getTrade_state_desc() + "】");
|
|
|
+ } else if (result.getTrade_state().equalsIgnoreCase(Dict.tradeState.item_PAYERROR.getItem())) {
|
|
|
+ Map orderRaram = Maps.newHashMap();
|
|
|
+ orderRaram.put("payStatus", Dict.payStatus.item_8.getItem());
|
|
|
+ orderRaram.put("orderStatus", Dict.orderStatus.item_501.getItem());
|
|
|
+ orderRaram.put("orderId", orderId);
|
|
|
+ orderDao.updateOrderInfo(orderRaram);
|
|
|
+ LOGGER.info(">>>>>>>>>>>>>>>>>>>>wxOrderByTransactionIdQueryUpdFail 根据支付单查询微信接口返回信息:state 【" + result.getTrade_state() +
|
|
|
+ "】,des【" + result.getTrade_state_desc() + "】");
|
|
|
+ } else if (result.getTrade_state().equalsIgnoreCase(Dict.tradeState.item_USERPAYING.getItem())) {
|
|
|
+ Map orderRaram = Maps.newHashMap();
|
|
|
+ orderRaram.put("payStatus", Dict.payStatus.item_1.getItem());
|
|
|
+ orderRaram.put("orderStatus", Dict.orderStatus.item_100.getItem());
|
|
|
+ orderRaram.put("orderId", orderId);
|
|
|
+ orderDao.updateOrderInfo(orderRaram);
|
|
|
+ LOGGER.info(">>>>>>>>>>>>>>>>>>>>wxOrderByTransactionIdQueryUpdFail 根据支付单查询微信接口返回信息:state 【" + result.getTrade_state() +
|
|
|
+ "】,des【" + result.getTrade_state_desc() + "】");
|
|
|
+ } else if (result.getTrade_state().equalsIgnoreCase(Dict.tradeState.item_REVOKED.getItem())) {
|
|
|
+ LOGGER.info(">>>>>>>>>>>>>>>>>>>>wxOrderByTransactionIdQueryUpdFail 根据支付单查询微信接口返回信息:state 【" + result.getTrade_state() +
|
|
|
+ "】,des【" + result.getTrade_state_desc() + "】");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ LOGGER.info(">>>>>>>>>>>>>>>>>>>>wxOrderQuery 微信查询接口返回失败信息:code 【" + result.getErr_code() +
|
|
|
+ "】,des【" + result.getErr_code_des() + "】");
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ LOGGER.info(">>>>>>>>>>>>>>>>>>>>wxOrderQuery 微信查询接口调用失败: " + result.getReturn_msg());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -2307,21 +2423,57 @@ public class OrderServiceImpl implements OrderService {
|
|
|
return orderDao.queryObjectByOrderSn(orderSn);
|
|
|
}
|
|
|
|
|
|
+ // TODO 退款的代码
|
|
|
@Override
|
|
|
- public void orderRefund(OrderEntity order, String sessionId) throws Exception {
|
|
|
+ @Transactional
|
|
|
+ public R orderRefund(OrderEntity order, String sessionId) throws Exception {
|
|
|
+ String payFlag = order.getPayFlag();
|
|
|
+
|
|
|
boolean needUpdateStock = true;
|
|
|
- if (order.getOrderStatus() == Integer.parseInt(Dict.orderStatus.item_201.getItem())) {
|
|
|
- order.setOrderStatus(Integer.parseInt(Dict.orderStatus.item_401.getItem()));
|
|
|
- }
|
|
|
- if (Dict.payFlag.item_cash.getItem().equals(order.getPayFlag())) {
|
|
|
+ if (Dict.payFlag.item_cash.getItem().equals(payFlag)) {
|
|
|
order.setPayStatus(Integer.parseInt(Dict.payStatus.item_4.getItem()));
|
|
|
- }else{
|
|
|
+ // TODO 微信的退款代码
|
|
|
+ } else if(Dict.payFlag.item_weixin.getItem().equals(payFlag)){
|
|
|
+ OrderEntity orderInfo = order;
|
|
|
+ if (null == orderInfo) {
|
|
|
+ return R.error("订单不存在");
|
|
|
+ }
|
|
|
+ if (orderInfo.getOrderStatus() == Integer.parseInt(Dict.orderStatus.item_401.getItem()) ||
|
|
|
+ orderInfo.getOrderStatus() == Integer.parseInt(Dict.orderStatus.item_402.getItem())) {
|
|
|
+ return R.error("订单已退款");
|
|
|
+ }
|
|
|
+ Double totalActualPrice = orderDao.getTotalActualPrice(orderInfo.getMerchOrderSn());
|
|
|
+ if (totalActualPrice == null) {
|
|
|
+ totalActualPrice = 0d;
|
|
|
+ }
|
|
|
+ String refundResult = "";
|
|
|
+ if (orderInfo.getOrderStatus() != Integer.parseInt(Dict.orderStatus.item_0.getItem())) {
|
|
|
+// if (orderInfo.getPayFlag().equalsIgnoreCase(Dict.payFlag.item_wxglobalpay.getItem())) {
|
|
|
+// refundResult = wxGlobalRefund(orderInfo, totalActualPrice);
|
|
|
+// if (org.apache.commons.lang3.StringUtils.isNotBlank(refundResult)) {
|
|
|
+// return R.error(refundResult);
|
|
|
+// }
|
|
|
+// } else if (orderInfo.getPayFlag().equalsIgnoreCase(Dict.payFlag.item_pingan.getItem())) {
|
|
|
+// refundResult = pinganRefund(orderInfo, refundId);
|
|
|
+// if (org.apache.commons.lang3.StringUtils.isNotBlank(refundResult)) {
|
|
|
+// return R.error(refundResult);
|
|
|
+// }
|
|
|
+// } else{
|
|
|
+ refundResult = wxRefund(orderInfo,totalActualPrice);
|
|
|
+ if(org.apache.commons.lang3.StringUtils.isNotBlank(refundResult)){
|
|
|
+ return R.error(refundResult);
|
|
|
+ }
|
|
|
+// }
|
|
|
+ }
|
|
|
+ // 支付宝的退款代码
|
|
|
+ } else if(Dict.payFlag.item_alipay.getItem().equals(payFlag)) {
|
|
|
|
|
|
AliPayMicropayApiResult userRefund = AliPayUtil.aliTradeRefund(order.getOrderSn(), order.getActualPrice().toString(),
|
|
|
"用户退款", order.getStoreId() + "");
|
|
|
|
|
|
LOGGER.info(userRefund.getSubMsg());
|
|
|
order.setPayStatus(Integer.parseInt(Dict.payStatus.item_3.getItem()));
|
|
|
+ order.setOrderStatus(Integer.parseInt(Dict.orderStatus.item_401.getItem()));
|
|
|
OrderRefundEntity orderRefund = new OrderRefundEntity();
|
|
|
orderRefund.setRefundId(userRefund.getTradeNo());
|
|
|
orderRefund.setOutRefundNo(userRefund.getOutTradeNo());
|
|
@@ -2348,7 +2500,39 @@ public class OrderServiceImpl implements OrderService {
|
|
|
pickUpCodeService.update(pickUpCodeEntity);
|
|
|
// WebSocketServer.delete(sessionId,order.getStoreId(),pickUpCodeEntity);
|
|
|
updateStock(order, "收银端退款");
|
|
|
+ return R.ok("退款成功");
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
+ private String wxRefund(OrderEntity orderInfo,Double totalActualPrice){
|
|
|
+ WechatRefundApiResult result = WechatUtil.wxRefund(orderInfo.getOrderSn().toString(), totalActualPrice,
|
|
|
+ orderInfo.getActualPrice().doubleValue());
|
|
|
+ if (result.getResult_code().equals(WechatUtil.WXTradeState.SUCCESS.getCode())) {
|
|
|
+ refund(orderInfo, result);
|
|
|
+ } else {
|
|
|
+ OrderRefundEntity mallOrderRefund = orderRefundService.queryObjectByOrderId(orderInfo.getId());
|
|
|
+ OrderRefundEntity orderRefund = new OrderRefundEntity();
|
|
|
+ orderRefund.setRefundType(Integer.parseInt(Dict.RefundType.item_1.getItem()));
|
|
|
+ orderRefund.setRefundMoney(BigDecimal.valueOf(orderInfo.getActualPrice().doubleValue()));
|
|
|
+ orderRefund.setRefundStatus(Integer.parseInt(Dict.RefundStatus.item_4.getItem()));
|
|
|
+ SysUserEntity user = ShiroUtils.getUserEntity();
|
|
|
+ orderRefund.setModerSn(user.getUsername());
|
|
|
+ orderRefund.setModTime(new Date());
|
|
|
+// orderRefund.setOutRefundNo(result.getOut_refund_no());
|
|
|
+ if (mallOrderRefund != null) {
|
|
|
+ orderRefund.setId(mallOrderRefund.getId());
|
|
|
+ orderRefundService.update(orderRefund);//退款记录
|
|
|
+ }
|
|
|
+ OrderExceptionRecordEntity mallOrderExceptionRecord = new OrderExceptionRecordEntity();
|
|
|
+ mallOrderExceptionRecord.setOrderSn(orderInfo.getOrderSn());
|
|
|
+ mallOrderExceptionRecord.setUserId(Integer.parseInt(orderInfo.getUserId() + ""));
|
|
|
+ mallOrderExceptionRecord.setExceptionStatus(Dict.exceptionStatus.item_03.getItem());
|
|
|
+ mallOrderExceptionRecord.setExceptionContent("退款失败" + result.getErr_code_des());
|
|
|
+ mallOrderExceptionRecord.setCreateTime(new Date());
|
|
|
+ orderExceptionRecordService.save(mallOrderExceptionRecord);
|
|
|
+ return result.getErr_code_des();
|
|
|
+ }
|
|
|
+ return "";
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -2409,7 +2593,7 @@ public class OrderServiceImpl implements OrderService {
|
|
|
fullCutCouponDec = fullCutCouponDec
|
|
|
.add(goodsEntity.getDiscountedPrice()).setScale(2,RoundingMode.HALF_UP);
|
|
|
actualPrice = actualPrice
|
|
|
- .add(goodsEntity.getActualPaymentAmount().multiply(new BigDecimal(goodsEntity.getGoodsNumber()))).setScale(2,RoundingMode.HALF_UP);
|
|
|
+ .add(goodsEntity.getActualPaymentAmount()).setScale(2,RoundingMode.HALF_UP);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -2508,7 +2692,7 @@ public class OrderServiceImpl implements OrderService {
|
|
|
orderGoodsVo.setSku(goodsDto.getSku());
|
|
|
|
|
|
BigDecimal number = new BigDecimal(Long.valueOf(goodsDto.getGoodsNumber()));
|
|
|
- BigDecimal goodsTotal = goodsDto.getStoreRetailPrice().multiply(number);//单商品总价
|
|
|
+ BigDecimal goodsTotal = goodsDto.getRetailPrice().multiply(number);//单商品总价
|
|
|
BigDecimal rate = goodsTotal.divide(orderInfo.getGoods_price(),2, BigDecimal.ROUND_HALF_UP);//当前商品总价/订单总价(不含运费、不含优惠券)
|
|
|
BigDecimal freightPrice = BigDecimal.valueOf(orderInfo.getFreight_price());
|
|
|
BigDecimal settlePrice = Constant.ZERO; // ccnet 取的这个而价格
|