| @@ -116,7 +116,7 @@ public class WxPayOrderController extends BaseController { | |||
| payOrder.setFailReason(reasonStr); | |||
| try { | |||
| wxPayOrderService.handlePayOrderStatusUpdate(payOrder); | |||
| return new ResultData(200, "支付状态更新成功"); | |||
| return new ResultData(Result.SUCCESS, "支付状态更新成功"); | |||
| } catch (MallinkException e) { | |||
| logger.error("支付状态更新失败2: " + payOrder.toString() + ", e:" + e.getMessage()); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| @@ -16,7 +16,7 @@ public class WxPayOrder implements Serializable { | |||
| protected Long id; | |||
| @Transient | |||
| protected List<String> ids; | |||
| protected List<Long> ids; | |||
| @Transient | |||
| protected String sortColumns; | |||
| @@ -32,17 +32,18 @@ public class WxPayOrder implements Serializable { | |||
| return sortColumns; | |||
| } | |||
| public List<String> getIds() { | |||
| public List<Long> getIds() { | |||
| return ids; | |||
| } | |||
| public void setIds(List<String> ids) { | |||
| public void setIds(List<Long> ids) { | |||
| this.ids = ids; | |||
| } | |||
| /***/ | |||
| @io.swagger.annotations.ApiModelProperty(value="",name="tenantId") | |||
| /*租户ID**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | |||
| private String tenantId; | |||
| /*创建时间**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createTime") | |||
| @@ -62,12 +63,12 @@ public class WxPayOrder implements Serializable { | |||
| /*支付金额(分)**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="支付金额(分)",name="payAmount") | |||
| private Integer payAmount; | |||
| /*支付发起时间(秒)**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="支付发起时间(秒)",name="payTimeStart") | |||
| private Integer payTimeStart; | |||
| /*支付结束时间(秒)**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="支付结束时间(秒)",name="payTimeEnd") | |||
| private Integer payTimeEnd; | |||
| /*支付发起时间**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="支付发起时间",name="payTimeStart") | |||
| private Date payTimeStart; | |||
| /*支付结束时间**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="支付结束时间",name="payTimeEnd") | |||
| private Date payTimeEnd; | |||
| /*微信生成的订单号**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="微信生成的订单号",name="transactionId") | |||
| private String transactionId; | |||
| @@ -125,16 +126,16 @@ public class WxPayOrder implements Serializable { | |||
| public void setPayAmount(Integer _payAmount) { | |||
| payAmount = _payAmount; | |||
| } | |||
| public Integer getPayTimeStart() { | |||
| public Date getPayTimeStart() { | |||
| return payTimeStart; | |||
| } | |||
| public void setPayTimeStart(Integer _payTimeStart) { | |||
| public void setPayTimeStart(Date _payTimeStart) { | |||
| payTimeStart = _payTimeStart; | |||
| } | |||
| public Integer getPayTimeEnd() { | |||
| public Date getPayTimeEnd() { | |||
| return payTimeEnd; | |||
| } | |||
| public void setPayTimeEnd(Integer _payTimeEnd) { | |||
| public void setPayTimeEnd(Date _payTimeEnd) { | |||
| payTimeEnd = _payTimeEnd; | |||
| } | |||
| public String getTransactionId() { | |||
| @@ -71,10 +71,10 @@ public class WxRefundOrder implements Serializable { | |||
| private Integer refundFee; | |||
| /*退款发起时间(秒)**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="退款发起时间(秒)",name="refundTimeStart") | |||
| private Integer refundTimeStart; | |||
| private Date refundTimeStart; | |||
| /*退款结束时间(秒)**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="退款结束时间(秒)",name="refundTimeEnd") | |||
| private Integer refundTimeEnd; | |||
| private Date refundTimeEnd; | |||
| /*支付渠道: 0-微信 1-支付宝 2-银联 **/ | |||
| @io.swagger.annotations.ApiModelProperty(value="支付渠道: 0-微信 1-支付宝 2-银联 ",name="refundVendor") | |||
| private Integer refundVendor; | |||
| @@ -141,16 +141,16 @@ public class WxRefundOrder implements Serializable { | |||
| public void setRefundFee(Integer _refundFee) { | |||
| refundFee = _refundFee; | |||
| } | |||
| public Integer getRefundTimeStart() { | |||
| public Date getRefundTimeStart() { | |||
| return refundTimeStart; | |||
| } | |||
| public void setRefundTimeStart(Integer _refundTimeStart) { | |||
| public void setRefundTimeStart(Date _refundTimeStart) { | |||
| refundTimeStart = _refundTimeStart; | |||
| } | |||
| public Integer getRefundTimeEnd() { | |||
| public Date getRefundTimeEnd() { | |||
| return refundTimeEnd; | |||
| } | |||
| public void setRefundTimeEnd(Integer _refundTimeEnd) { | |||
| public void setRefundTimeEnd(Date _refundTimeEnd) { | |||
| refundTimeEnd = _refundTimeEnd; | |||
| } | |||
| public Integer getRefundVendor() { | |||
| @@ -5,7 +5,7 @@ import com.simple.common.CommonMapper; | |||
| import org.apache.ibatis.annotations.Param; | |||
| import com.simple.domain.po.WxPayOrder; | |||
| public interface WxPayOrderMapper extends CommonMapper<WxPayOrder, String> { | |||
| public interface WxPayOrderMapper extends CommonMapper<WxPayOrder, Long> { | |||
| List<WxPayOrder> findList(WxPayOrder wxPayOrder); | |||
| @@ -1,5 +1,6 @@ | |||
| package com.simple.service.impl; | |||
| import java.text.ParseException; | |||
| import java.util.*; | |||
| import com.alibaba.fastjson.JSON; | |||
| @@ -7,6 +8,7 @@ import com.alibaba.fastjson.JSONObject; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.simple.common.ErrorCode; | |||
| import com.simple.common.Result; | |||
| import com.simple.common.ResultData; | |||
| import com.simple.domain.po.*; | |||
| import com.simple.enums.EnumOrderStatus; | |||
| @@ -86,7 +88,6 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| } | |||
| // 2. check 是否有支付订单 | |||
| Date currentDate = new Date(); | |||
| int currentTime = Utility.convertDate2TimeStamp(currentDate); | |||
| List<WxPayOrder> list = wxPayOrderMapper.findList(record); | |||
| String payOrderNo = ""; | |||
| if (list.size() <= 0) { | |||
| @@ -98,8 +99,8 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| record.setCUserId(user.getId()); | |||
| record.setCreateTime(currentDate); | |||
| record.setUpdateTime(currentDate); | |||
| record.setPayTimeStart(currentTime); | |||
| record.setPayTimeEnd(currentTime); | |||
| record.setPayTimeStart(currentDate); | |||
| record.setPayTimeEnd(currentDate); | |||
| // 支付单号 | |||
| record.setPayOrderNo(payOrderNo); | |||
| record.setPayAmount(order.getPayment()); | |||
| @@ -132,8 +133,10 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| wxPayOrderP.setNotify_url(payAccount.getPayNotifyUrl()); | |||
| wxPayOrderP.setTrade_type(WxPay.TradeType.JSAPI.name()); // 终端类型 | |||
| wxPayOrderP.setProduct_id(String.valueOf(order.getId())); // 订单ID | |||
| wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentTime)); | |||
| wxPayOrderP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(currentTime + 15 * 60)); // 15分钟结束 | |||
| wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | |||
| Date futureDate = new Date(); | |||
| futureDate.setTime(currentDate.getTime() + 15*60*1000); | |||
| wxPayOrderP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||
| wxPayOrderP.setSign(WxPayment.createSign(BeanUtils.toStringMap(wxPayOrderP), payAccount.getApiKey())); | |||
| String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayOrderP)); | |||
| logger.info("pay order, wechat pushOrder, " + wxPayOrderP.toString() + ", response: " + response.toString()); | |||
| @@ -165,7 +168,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| returnMap.put("package", "prepay_id=" + prepay_id); | |||
| returnMap.put("paySign", signAgent); | |||
| logger.info("back to UI: " +returnMap.toString()); | |||
| return new ResultData(200, "创建支付订单成功", returnMap); | |||
| return new ResultData(Result.SUCCESS, "创建支付订单成功", returnMap); | |||
| } else { | |||
| JSONObject errObj = errorMap.getJSONObject(result_code); | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errObj.toJSONString(), returnMap); | |||
| @@ -220,6 +223,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| } | |||
| String payOrderNo = paramMap.get("out_trade_no"); | |||
| String timEndStr = paramMap.get("time_end"); | |||
| Long payOrderId = Long.valueOf(payOrderNo); | |||
| WxPayOrder payOrder = wxPayOrderMapper.selectByPrimaryKey(payOrderId); | |||
| if (payOrder == null) { | |||
| @@ -238,6 +242,16 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| return XmlUtil.parseDto2Xml(resultMap, ""); | |||
| } | |||
| Date timeEnd = null; | |||
| try { | |||
| timeEnd = Utility.getDateFromString(timEndStr); | |||
| } catch (ParseException e) { | |||
| logger.error("解析timeEnd失败"); | |||
| timeEnd = new Date(); | |||
| } | |||
| payOrder.setPayTimeEnd(timeEnd); | |||
| // 处理支付成功 | |||
| handleOrderPaySuccess(payOrder, paramMap.get("transaction_id")); | |||
| logger.info("notify order, wxpay checksign success, paramMap:{}, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); | |||
| @@ -348,6 +362,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| updateOrder.setOrderId(record.getOrderId()); | |||
| updateOrder.setUpdateTime(currentDate); | |||
| updateOrder.setPayOrderStatus(record.getPayOrderStatus()); | |||
| updateOrder.setPayTimeEnd(currentDate); | |||
| updateOrder.setFailReason(record.getFailReason()); | |||
| wxPayOrderMapper.updateByPrimaryKeySelective(updateOrder); | |||
| } catch (Exception e) { | |||
| @@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONObject; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.simple.common.ErrorCode; | |||
| import com.simple.common.Result; | |||
| import com.simple.common.ResultData; | |||
| import com.simple.domain.po.*; | |||
| import com.simple.enums.EnumOrderStatus; | |||
| @@ -270,7 +271,7 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||
| record.setCUserId(payOrder.getCUserId()); | |||
| record.setTotalFee(payOrder.getPayAmount()); | |||
| record.setRefundFee(payOrder.getPayAmount()); | |||
| record.setRefundTimeStart((int)(currentDate.getTime()/1000)); | |||
| record.setRefundTimeStart(currentDate); | |||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_WAIT.getCode()); | |||
| int sqlRow = wxRefundOrderMapper.insertSelective(record); | |||
| if(sqlRow != 1) { | |||
| @@ -315,7 +316,7 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||
| try { | |||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||
| wxRefundOrderMapper.updateByPrimaryKey(record); | |||
| return new ResultData(200, "退款订单申请成功", returnMap); | |||
| return new ResultData(Result.SUCCESS, "退款订单申请成功", returnMap); | |||
| } catch (Exception e) { | |||
| logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | |||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR); | |||
| @@ -350,7 +351,7 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||
| String result_no = returnMap.get("result_code"); | |||
| if ("SUCCESS".equals(result_no)) { | |||
| String refund_id = returnMap.get("refund_id"); | |||
| return new ResultData(200, "退款", returnMap); | |||
| return new ResultData(Result.SUCCESS, "退款", returnMap); | |||
| } else { | |||
| wxRefundOrderMapper.updateByPrimaryKey(record); | |||
| JSONObject errObj = errorRefundReqMap.getJSONObject(result_no); | |||
| @@ -526,6 +526,16 @@ public final class Utility { | |||
| return sf.format(((long) currentSec) * 1000); | |||
| } | |||
| public static String getDataFormatStringYYYYMMDDHHmmss(Date currentDate) { | |||
| SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss"); | |||
| return sf.format(currentDate); | |||
| } | |||
| public static Date getDateFromString(String timeEnd) throws ParseException { | |||
| SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); | |||
| return sdf.parse(timeEnd); | |||
| } | |||
| public static String getOrderNo() { | |||
| SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |||
| String dateStr = sdf.format(new Date()); | |||
| @@ -3,15 +3,15 @@ | |||
| <mapper namespace="com.simple.mapper.WxPayOrderMapper"> | |||
| <resultMap id="BaseResultMap" type="com.simple.domain.po.WxPayOrder"> | |||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||
| <result column="tenant_id" jdbcType="BIGINT" property="tenantId" /> | |||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | |||
| <result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> | |||
| <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> | |||
| <result column="order_id" jdbcType="BIGINT" property="orderId" /> | |||
| <result column="c_user_id" jdbcType="BIGINT" property="cUserId" /> | |||
| <result column="ip" jdbcType="VARCHAR" property="ip" /> | |||
| <result column="pay_amount" jdbcType="INTEGER" property="payAmount" /> | |||
| <result column="pay_time_start" jdbcType="INTEGER" property="payTimeStart" /> | |||
| <result column="pay_time_end" jdbcType="INTEGER" property="payTimeEnd" /> | |||
| <result column="pay_time_start" jdbcType="TIMESTAMP" property="payTimeStart" /> | |||
| <result column="pay_time_end" jdbcType="TIMESTAMP" property="payTimeEnd" /> | |||
| <result column="transaction_id" jdbcType="VARCHAR" property="transactionId" /> | |||
| <result column="pay_vendor" jdbcType="INTEGER" property="payVendor" /> | |||
| <result column="pay_order_no" jdbcType="VARCHAR" property="payOrderNo" /> | |||
| @@ -32,7 +32,7 @@ | |||
| </if> | |||
| <if test=" null != tenantId "> | |||
| and `tenant_id` = #{tenantId} | |||
| and `tenant_id` like concat('%', #{tenantId},'%') | |||
| </if> | |||
| @@ -12,8 +12,8 @@ | |||
| <result column="c_user_id" jdbcType="BIGINT" property="cUserId" /> | |||
| <result column="total_fee" jdbcType="INTEGER" property="totalFee" /> | |||
| <result column="refund_fee" jdbcType="INTEGER" property="refundFee" /> | |||
| <result column="refund_time_start" jdbcType="INTEGER" property="refundTimeStart" /> | |||
| <result column="refund_time_end" jdbcType="INTEGER" property="refundTimeEnd" /> | |||
| <result column="refund_time_start" jdbcType="TIMESTAMP" property="refundTimeStart" /> | |||
| <result column="refund_time_end" jdbcType="TIMESTAMP" property="refundTimeEnd" /> | |||
| <result column="refund_vendor" jdbcType="INTEGER" property="refundVendor" /> | |||
| <result column="refund_order_status" jdbcType="INTEGER" property="refundOrderStatus" /> | |||
| <result column="refund_id" jdbcType="VARCHAR" property="refundId" /> | |||