main
parent
60b3eb990c
commit
52a5285b56
|
|
@ -1,14 +1,11 @@
|
||||||
package com.ruoyi.app.controller;
|
package com.ruoyi.app.controller;
|
||||||
|
|
||||||
import com.ruoyi.app.domain.AppDynamicComment;
|
import com.ruoyi.app.domain.*;
|
||||||
import com.ruoyi.app.domain.AppOrder;
|
import com.ruoyi.app.domain.dto.*;
|
||||||
import com.ruoyi.app.domain.AppOrderArg;
|
|
||||||
import com.ruoyi.app.domain.dto.KeyUtil;
|
|
||||||
import com.ruoyi.app.domain.dto.PayConfig;
|
|
||||||
import com.ruoyi.app.domain.dto.PayUtils;
|
|
||||||
import com.ruoyi.app.domain.dto.WeChatPrepayResult;
|
|
||||||
import com.ruoyi.app.domain.vo.AppDynamicCommentVo;
|
import com.ruoyi.app.domain.vo.AppDynamicCommentVo;
|
||||||
import com.ruoyi.app.mapper.AppOrderMapper;
|
import com.ruoyi.app.mapper.AppOrderMapper;
|
||||||
|
import com.ruoyi.app.mapper.AppOrderPayMapper;
|
||||||
|
import com.ruoyi.app.mapper.AppUserMapper;
|
||||||
import com.ruoyi.app.service.IAppDynamicCommentService;
|
import com.ruoyi.app.service.IAppDynamicCommentService;
|
||||||
import com.ruoyi.app.service.IPayService;
|
import com.ruoyi.app.service.IPayService;
|
||||||
import com.ruoyi.common.core.utils.poi.ExcelUtil;
|
import com.ruoyi.common.core.utils.poi.ExcelUtil;
|
||||||
|
|
@ -21,10 +18,15 @@ import com.ruoyi.common.security.annotation.RequiresPermissions;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.dom4j.Document;
|
||||||
|
import org.dom4j.DocumentHelper;
|
||||||
|
import org.dom4j.Element;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.*;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
|
|
@ -48,12 +50,18 @@ public class PayController extends BaseController
|
||||||
@Autowired
|
@Autowired
|
||||||
private AppOrderMapper appOrderMapper;
|
private AppOrderMapper appOrderMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AppOrderPayMapper appOrderPayMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AppUserMapper appUserMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询动态评论列表
|
* 查询动态评论列表
|
||||||
*/
|
*/
|
||||||
@PostMapping("/wechatPrePay")
|
@PostMapping("/wechatPrePay")
|
||||||
@ApiOperation(value = "微信支付", notes = "微信支付", httpMethod = "POST")
|
@ApiOperation(value = "微信支付", notes = "微信支付", httpMethod = "POST")
|
||||||
public AjaxResult wechatPrePay(AppOrderArg appOrderArg) {
|
public AjaxResult wechatPrePay(@RequestBody AppOrderArg appOrderArg) {
|
||||||
Integer price = appOrderArg.getPrice();
|
Integer price = appOrderArg.getPrice();
|
||||||
|
|
||||||
PayConfig payConfig = getPayConfigByAppid();
|
PayConfig payConfig = getPayConfigByAppid();
|
||||||
|
|
@ -112,6 +120,108 @@ public class PayController extends BaseController
|
||||||
return AjaxResult.success(prePayResult);
|
return AjaxResult.success(prePayResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/wechatNotify")
|
||||||
|
public void wechatNotify(HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
log.info("=======>>>开始获取微信支付返回信息");
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
InputStream in;
|
||||||
|
try {
|
||||||
|
in = request.getInputStream();
|
||||||
|
InputStreamReader reader = new InputStreamReader(in);
|
||||||
|
BufferedReader br = new BufferedReader(reader);
|
||||||
|
String s = "";
|
||||||
|
while ((s = br.readLine()) != null) {
|
||||||
|
sb.append(s);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
reader.close();
|
||||||
|
in.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.info("获取返回信息失败");
|
||||||
|
}
|
||||||
|
log.info("微信返回来的字符串" + sb.toString());
|
||||||
|
WeChatPayResult wexinResult = getResultByXml(sb.toString());
|
||||||
|
PrintWriter out;
|
||||||
|
try {
|
||||||
|
out = response.getWriter();
|
||||||
|
if (!("SUCCESS".equals(wexinResult.getResultCode()))) {
|
||||||
|
out.println("fail");
|
||||||
|
}
|
||||||
|
|
||||||
|
String outTradeNo = wexinResult.getOutTradeNo();
|
||||||
|
AppOrder appOrder = appOrderMapper.selectOneByOutTradeNo(outTradeNo);
|
||||||
|
|
||||||
|
AppOrder entity = new AppOrder();
|
||||||
|
entity.setId(appOrder.getId());
|
||||||
|
entity.setTradeNo(wexinResult.getTransactionId());
|
||||||
|
entity.setPayStatus(2);
|
||||||
|
entity.setPayTime(new Date());
|
||||||
|
appOrderMapper.updateAppOrder(entity);
|
||||||
|
|
||||||
|
AppOrderPay miniOrderWechatPay = new AppOrderPay();
|
||||||
|
miniOrderWechatPay.setAppid(wexinResult.getAppid());
|
||||||
|
miniOrderWechatPay.setNoncestr(wexinResult.getNonceStr());
|
||||||
|
miniOrderWechatPay.setOuttradeno(wexinResult.getOutTradeNo());
|
||||||
|
miniOrderWechatPay.setResultcode(wexinResult.getResultCode());
|
||||||
|
miniOrderWechatPay.setTimeend(wexinResult.getTimeEnd());
|
||||||
|
miniOrderWechatPay.setTotalfee(wexinResult.getTotalFee());
|
||||||
|
miniOrderWechatPay.setTransactionid(wexinResult.getTransactionId());
|
||||||
|
appOrderPayMapper.insertAppOrderPay(miniOrderWechatPay);
|
||||||
|
|
||||||
|
// 修改用户信息
|
||||||
|
AppUser appUser = appUserMapper.selectAppUserById(appOrder.getUserId());
|
||||||
|
AppUser userEntity = new AppUser();
|
||||||
|
userEntity.setId(appUser.getId());
|
||||||
|
userEntity.setIsMember(0);
|
||||||
|
userEntity.setOrderId(appOrder.getId());
|
||||||
|
// 开始时间,结束时间
|
||||||
|
Date startDate = appUser.getOrderStartTime();
|
||||||
|
if (null == startDate) {
|
||||||
|
startDate = new Date();
|
||||||
|
}
|
||||||
|
Date endDate = appUser.getEndTime();
|
||||||
|
if (null == endDate) {
|
||||||
|
endDate = startDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
out.println("success");
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info("异常订单:" + wexinResult.toString());
|
||||||
|
log.info("========>PrintWriter fail");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public WeChatPayResult getResultByXml(String response) {
|
||||||
|
WeChatPayResult wexinResult = new WeChatPayResult();
|
||||||
|
Document document;
|
||||||
|
try {
|
||||||
|
document = DocumentHelper.parseText(response);
|
||||||
|
Element root = document.getRootElement();
|
||||||
|
String cashFee = root.element("cash_fee").getText();
|
||||||
|
String totalFee = root.element("total_fee").getText();
|
||||||
|
wexinResult.setAppid(root.element("appid").getText());
|
||||||
|
wexinResult.setBankType(root.element("bank_type").getText());
|
||||||
|
wexinResult.setCashFee(cashFee);
|
||||||
|
wexinResult.setMchId(root.element("mch_id").getText());
|
||||||
|
wexinResult.setNonceStr(root.element("nonce_str").getText());
|
||||||
|
wexinResult.setOpenid(root.element("openid").getText());
|
||||||
|
wexinResult.setOutTradeNo(root.element("out_trade_no").getText());
|
||||||
|
wexinResult.setResultCode(root.element("result_code").getText());
|
||||||
|
wexinResult.setReturnCode(root.element("return_code").getText());
|
||||||
|
wexinResult.setSign(root.element("sign").getText());
|
||||||
|
wexinResult.setTimeEnd(root.element("time_end").getText());
|
||||||
|
wexinResult.setTotalFee(totalFee);
|
||||||
|
wexinResult.setTradeType(root.element("trade_type").getText());
|
||||||
|
wexinResult.setTransactionId(root.element("transaction_id").getText());
|
||||||
|
return wexinResult;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
log.info("解析失败");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public PayConfig getPayConfigByAppid() {
|
public PayConfig getPayConfigByAppid() {
|
||||||
PayConfig payConfig = new PayConfig();
|
PayConfig payConfig = new PayConfig();
|
||||||
payConfig.setAPPID(payConfig.getAPPID());
|
payConfig.setAPPID(payConfig.getAPPID());
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.Data;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
import com.ruoyi.common.core.annotation.Excel;
|
import com.ruoyi.common.core.annotation.Excel;
|
||||||
|
|
@ -15,6 +16,7 @@ import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||||
* @author wyh
|
* @author wyh
|
||||||
* @date 2024-04-23
|
* @date 2024-04-23
|
||||||
*/
|
*/
|
||||||
|
@Data
|
||||||
public class AppUser extends BaseEntity
|
public class AppUser extends BaseEntity
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
@ -151,6 +153,20 @@ public class AppUser extends BaseEntity
|
||||||
|
|
||||||
private int isMember;
|
private int isMember;
|
||||||
|
|
||||||
|
/** 订单记录 */
|
||||||
|
@Excel(name = "订单记录")
|
||||||
|
private Long orderId;
|
||||||
|
|
||||||
|
/** 开始时间 */
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||||
|
@Excel(name = "开始时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||||
|
private Date orderStartTime;
|
||||||
|
|
||||||
|
/** 结束时间 */
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||||
|
@Excel(name = "结束时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||||
|
private Date orderEndTime;
|
||||||
|
|
||||||
public void setId(Long id)
|
public void setId(Long id)
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ public interface AppOrderMapper
|
||||||
* @return 订单
|
* @return 订单
|
||||||
*/
|
*/
|
||||||
public AppOrder selectAppOrderById(Long id);
|
public AppOrder selectAppOrderById(Long id);
|
||||||
|
public AppOrder selectOneByOutTradeNo(String tradeNo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询订单列表
|
* 查询订单列表
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<include refid="selectAppOrderVo"/>
|
<include refid="selectAppOrderVo"/>
|
||||||
where id = #{id}
|
where id = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectOneByOutTradeNo" parameterType="Long" resultMap="AppOrderResult">
|
||||||
|
<include refid="selectAppOrderVo"/>
|
||||||
|
where outTradeNo = #{tradeNo}
|
||||||
|
</select>
|
||||||
|
|
||||||
<insert id="insertAppOrder" parameterType="AppOrder" useGeneratedKeys="true" keyProperty="id">
|
<insert id="insertAppOrder" parameterType="AppOrder" useGeneratedKeys="true" keyProperty="id">
|
||||||
insert into app_order
|
insert into app_order
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<result property="city" column="city" />
|
<result property="city" column="city" />
|
||||||
<result property="other" column="other" />
|
<result property="other" column="other" />
|
||||||
<result property="isMember" column="is_member" />
|
<result property="isMember" column="is_member" />
|
||||||
|
<result property="orderId" column="order_id" />
|
||||||
|
<result property="orderStartTime" column="order_start_time" />
|
||||||
|
<result property="orderEndTime" column="order_end_time" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<sql id="appUserColumns">
|
<sql id="appUserColumns">
|
||||||
a.id as "id",
|
a.id as "id",
|
||||||
|
|
@ -77,7 +80,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<sql id="selectAppUserVo">
|
<sql id="selectAppUserVo">
|
||||||
select id, username, password, nickname, email, phone, address, create_time, update_time, avatar_url, education, school, major, start_time, end_time, experience, company_name, industry, job_time, job_name, job_type, skill_id, job_content, type,is_member from app_user
|
select id, username, password, nickname, email, phone, address, create_time, update_time, avatar_url, education, school, major, start_time, end_time, experience, company_name, industry, job_time, job_name, job_type, skill_id, job_content, type,is_member,
|
||||||
|
order_id, order_start_time, order_end_time from app_user
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<select id="selectAppUserList" parameterType="AppUser" resultMap="AppUserResult">
|
<select id="selectAppUserList" parameterType="AppUser" resultMap="AppUserResult">
|
||||||
|
|
@ -113,6 +117,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<if test="hobby != null and hobby != ''"> and hobby = #{hobby}</if>
|
<if test="hobby != null and hobby != ''"> and hobby = #{hobby}</if>
|
||||||
<if test="city != null and city != ''"> and city = #{city}</if>
|
<if test="city != null and city != ''"> and city = #{city}</if>
|
||||||
<if test="other != null and other != ''"> and other = #{other}</if>
|
<if test="other != null and other != ''"> and other = #{other}</if>
|
||||||
|
<if test="isMember != null "> and is_member = #{isMember}</if>
|
||||||
|
<if test="orderId != null "> and order_id = #{orderId}</if>
|
||||||
|
<if test="orderStartTime != null "> and order_start_time = #{orderStartTime}</if>
|
||||||
|
<if test="orderEndTime != null "> and order_end_time = #{orderEndTime}</if>
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
@ -160,6 +168,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<if test="hobby != null">hobby,</if>
|
<if test="hobby != null">hobby,</if>
|
||||||
<if test="city != null">city,</if>
|
<if test="city != null">city,</if>
|
||||||
<if test="other != null">other,</if>
|
<if test="other != null">other,</if>
|
||||||
|
<if test="isMember != null">is_member,</if>
|
||||||
|
<if test="orderId != null">order_id,</if>
|
||||||
|
<if test="orderStartTime != null">order_start_time,</if>
|
||||||
|
<if test="orderEndTime != null">order_end_time,</if>
|
||||||
</trim>
|
</trim>
|
||||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
<if test="username != null">#{username},</if>
|
<if test="username != null">#{username},</if>
|
||||||
|
|
@ -194,6 +206,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<if test="hobby != null">#{hobby},</if>
|
<if test="hobby != null">#{hobby},</if>
|
||||||
<if test="city != null">#{city},</if>
|
<if test="city != null">#{city},</if>
|
||||||
<if test="other != null">#{other},</if>
|
<if test="other != null">#{other},</if>
|
||||||
|
<if test="isMember != null">#{isMember},</if>
|
||||||
|
<if test="orderId != null">#{orderId},</if>
|
||||||
|
<if test="orderStartTime != null">#{orderStartTime},</if>
|
||||||
|
<if test="orderEndTime != null">#{orderEndTime},</if>
|
||||||
</trim>
|
</trim>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
|
|
@ -232,6 +248,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<if test="hobby != null">hobby = #{hobby},</if>
|
<if test="hobby != null">hobby = #{hobby},</if>
|
||||||
<if test="city != null">city = #{city},</if>
|
<if test="city != null">city = #{city},</if>
|
||||||
<if test="other != null">other = #{other},</if>
|
<if test="other != null">other = #{other},</if>
|
||||||
|
<if test="isMember != null">is_member = #{isMember},</if>
|
||||||
|
<if test="orderId != null">order_id = #{orderId},</if>
|
||||||
|
<if test="orderStartTime != null">order_start_time = #{orderStartTime},</if>
|
||||||
|
<if test="orderEndTime != null">order_end_time = #{orderEndTime},</if>
|
||||||
</trim>
|
</trim>
|
||||||
where id = #{id}
|
where id = #{id}
|
||||||
</update>
|
</update>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue