| | |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.LinkedMultiValueMap; |
| | | import org.springframework.util.MultiValueMap; |
| | | import org.springframework.web.client.RestTemplate; |
| | |
| | | |
| | | @Override |
| | | public ResultUtil payPrivateCarOrder(Integer payType, Integer orderId, Integer couponId, Integer type) throws Exception { |
| | | String value = redisUtil.getValue(orderId + "_status_1"); |
| | | if(ToolUtil.isNotEmpty(value) && "8".equals(value)){ |
| | | return ResultUtil.error("订单已完成支付,不允许重复支付", ""); |
| | | } |
| | | OrderPrivateCar orderPrivateCar = this.selectById(orderId); |
| | | if(orderPrivateCar.getState() == 8 || orderPrivateCar.getState() == 9){ |
| | | return ResultUtil.error("订单已完成支付,不允许重复支付", ""); |
| | |
| | | if(orderPrivateCar.getState() != 7){ |
| | | return ResultUtil.error("订单不在待支付状态,不允许支付", ""); |
| | | } |
| | | String code = orderId + "_1_" + UUIDUtil.getRandomCode(5); |
| | | PaymentRecord query3 = paymentRecordService.query(1, null, null, orderId, 1, payType, null); |
| | | PaymentRecord query3 = paymentRecordService.query(1, null, null, orderId, 1, null, 1); |
| | | if(null != query3){ |
| | | ResultUtil<Map<String, Object>> resultUtil1 = payMoneyUtil.queryWXOrder("", query3.getSerialNumber(), "JSAPI"); |
| | | if (resultUtil1.getCode() == 200) { |
| | |
| | | String s = resultUtil1.getData().get("trade_state").toString(); |
| | | if ("REFUND".equals(s) || "CLOSED".equals(s) || "REVOKED".equals(s) || "PAYERROR".equals(s)) { |
| | | payMoneyUtil.closeWXOrder(query3.getSerialNumber()); |
| | | paymentRecordService.deleteById(query3.getId()); |
| | | } |
| | | if ("SUCCESS".equals(s) || "ACCEPT".equals(s)) { |
| | | return ResultUtil.error("不允许重复支付"); |
| | | } |
| | | if ("NOTPAY".equals(s) || "USERPAYING".equals(s)) { |
| | | payMoneyUtil.closeWXOrder(query3.getSerialNumber()); |
| | | paymentRecordService.deleteById(query3.getId()); |
| | | } |
| | | } |
| | | } |
| | |
| | | UserCouponRecord userCouponRecord = null; |
| | | if(null != couponId){ |
| | | userCouponRecord = userCouponRecordService.selectById(couponId); |
| | | if(userCouponRecord.getCompanyId() != orderPrivateCar.getCompanyId()){ |
| | | if(userCouponRecord.getCompanyId().compareTo(orderPrivateCar.getCompanyId()) != 0){ |
| | | return ResultUtil.error("优惠券不能用于此订单", ""); |
| | | } |
| | | if(userCouponRecord.getState() == 2){ |
| | |
| | | if(ToolUtil.isEmpty(userInfo.getAppletsOpenId())){ |
| | | return ResultUtil.error("未授权微信,无法完成支付"); |
| | | } |
| | | String code = orderId + "_1_" + UUIDUtil.getRandomCode(5); |
| | | if(payType == 1){//微信支付 |
| | | resultUtil = payMoneyUtil.weixinpay("完成订单",orderId +"", code,orderMoney+"","/base/wxPayOrderTaxi","JSAPI",userInfo.getAppletsOpenId()); |
| | | if(resultUtil.getCode()==200){ |
| | | paymentRecordService.saveData(1, null, null, orderId, 1, 1, orderMoney, null, 1, code);//添加预支付数据 |
| | | paymentRecordService.saveData(1, orderPrivateCar.getUserId(), 1, orderId, 1, 1, orderMoney, null, 1, code);//添加预支付数据 |
| | | new Thread(()->{ |
| | | int num = 1; |
| | | int min = 5000; |
| | | int w = 0; |
| | | while (num <= 10) { |
| | | long time = orderPrivateCar.getInsertTime().getTime(); |
| | | //订单创建后15分钟 |
| | | while (System.currentTimeMillis() - time <= 900000) { |
| | | try { |
| | | w += min * num; |
| | | OrderPrivateCar orderPrivateCar1 = orderPrivateCarMapper.selectById(orderId); |
| | | if (orderPrivateCar1.getState() != 7) { |
| | | String value1 = redisUtil.getValue(orderId + "_status_1"); |
| | | if(ToolUtil.isNotEmpty(value1) && "8".equals(value1)){ |
| | | break; |
| | | } |
| | | ResultUtil<Map<String, Object>> resultUtil2 = payMoneyUtil.queryWXOrder("", code, "JSAPI"); |
| | |
| | | * ACCEPT--已接收,等待扣款 |
| | | */ |
| | | String s = resultUtil2.getData().get("trade_state").toString(); |
| | | if ("REFUND".equals(s) || "CLOSED".equals(s) || "REVOKED".equals(s) || "PAYERROR".equals(s) || num == 10) { |
| | | if ("REFUND".equals(s) || "CLOSED".equals(s) || "REVOKED".equals(s) || "PAYERROR".equals(s)) { |
| | | break; |
| | | } |
| | | if ("SUCCESS".equals(s) || "ACCEPT".equals(s)) { |
| | |
| | | break; |
| | | } |
| | | if ("NOTPAY".equals(s) || "USERPAYING".equals(s)) { |
| | | Thread.sleep(w); |
| | | num++; |
| | | } |
| | | } else { |
| | | Thread.sleep(w); |
| | | num++; |
| | | } |
| | | Thread.sleep(5000); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | String value1 = redisUtil.getValue(orderId + "_status_1"); |
| | | if(ToolUtil.isNotEmpty(value1) && "7".equals(value1)){ |
| | | //关闭订单,不允许支付 |
| | | payMoneyUtil.closeWXOrder(code); |
| | | PaymentRecord paymentRecord = paymentRecordService.selectOne(new EntityWrapper<PaymentRecord>().eq("serialNumber", code)); |
| | | if(null != paymentRecord){ |
| | | paymentRecordService.deleteById(paymentRecord.getId()); |
| | | } |
| | | } |
| | | }).start(); |
| | |
| | | if(payType == 2) {//支付宝支付 |
| | | resultUtil = payMoneyUtil.alipay("完成订单","完成订单", "",code,orderMoney+"","/base/aliPayOrderTaxi"); |
| | | if (resultUtil.getCode()==200) { |
| | | paymentRecordService.saveData(1, null, null, orderId, 1, 2, orderMoney, null, 1, code);//添加预支付数据 |
| | | paymentRecordService.saveData(1, orderPrivateCar.getUserId(), 1, orderId, 1, 2, orderMoney, null, 1, code);//添加预支付数据 |
| | | } else { |
| | | resultUtil = ResultUtil.error("支付失败", ""); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void payOrderPrivateCarCallback(Integer id, String order_id, Integer type) throws Exception { |
| | | OrderPrivateCar orderPrivateCar = this.selectById(id); |
| | | if(orderPrivateCar.getState() != 7){ |
| | | return; |
| | | } |
| | | PaymentRecord query = paymentRecordService.query(1, null, null, Integer.valueOf(id), 1, type, 1); |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public synchronized void payOrderPrivateCarCallback(Integer id, String order_id, Integer type) throws Exception { |
| | | PaymentRecord query = paymentRecordService.query(1, null, null, Integer.valueOf(id), 1, type, null); |
| | | if(null != query){ |
| | | String value = redisUtil.getValue(order_id + "_status_1"); |
| | | if(ToolUtil.isNotEmpty(value) && "8".equals(value)){ |
| | | return; |
| | | } |
| | | //添加交易明细 |
| | | OrderPrivateCar orderPrivateCar = this.selectById(id); |
| | | transactionDetailsService.saveData(orderPrivateCar.getUserId(), "完成订单", query.getAmount(), 2, 1, 1, 1, query.getOrderId()); |
| | | orderPrivateCar.setState(8); |
| | | orderPrivateCar.setPayType(type); |
| | |
| | | userRedPacketRecordService.updateById(userRedPacketRecord); |
| | | } |
| | | |
| | | |
| | | query.setState(2); |
| | | query.setCode(order_id); |
| | | paymentRecordService.updateById(query); |
| | | redisUtil.setStrValue(order_id + "_status_1", "8"); |
| | | |
| | | if(orderPrivateCar.getIsplatPay()==1){ |
| | | //添加已收入明细 |
| | | Company company = companyService.selectById(orderPrivateCar.getCompanyId()); |