diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/wx/CreateOrderReq.java b/ruoyi-common/src/main/java/com/ruoyi/common/wx/CreateOrderReq.java index 4f17656..c71ae83 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/wx/CreateOrderReq.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/wx/CreateOrderReq.java @@ -19,6 +19,8 @@ public class CreateOrderReq { private Long points; + private Long resourceId; + public Long getUserId() { return userId; } @@ -42,4 +44,12 @@ public class CreateOrderReq { public void setPoints(Long points) { this.points = points; } + + public Long getResourceId() { + return resourceId; + } + + public void setResourceId(Long resourceId) { + this.resourceId = resourceId; + } } \ No newline at end of file diff --git a/ruoyi-system/src/main/java/com/ruoyi/app/domain/AppBlogArticle.java b/ruoyi-system/src/main/java/com/ruoyi/app/domain/AppBlogArticle.java index fb6f6f3..e6a9d2a 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/app/domain/AppBlogArticle.java +++ b/ruoyi-system/src/main/java/com/ruoyi/app/domain/AppBlogArticle.java @@ -79,6 +79,17 @@ public class AppBlogArticle extends BaseEntity private List picList; + /** 关联的资源对象 */ + private AppResource appResource; + + public AppResource getAppResource() { + return appResource; + } + + public void setAppResource(AppResource appResource) { + this.appResource = appResource; + } + public String getOrderType() { return orderType; } diff --git a/ruoyi-system/src/main/java/com/ruoyi/app/domain/AppPayOrder.java b/ruoyi-system/src/main/java/com/ruoyi/app/domain/AppPayOrder.java index 2a8cfa5..8c4b6d2 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/app/domain/AppPayOrder.java +++ b/ruoyi-system/src/main/java/com/ruoyi/app/domain/AppPayOrder.java @@ -32,6 +32,10 @@ public class AppPayOrder extends BaseEntity @Excel(name = "用户ID") private Long userId; + /** 资源ID */ + @Excel(name = "资源ID") + private Long resourceId; + /** openid */ @Excel(name = "openid") private String openId; @@ -135,6 +139,14 @@ public class AppPayOrder extends BaseEntity return payTime; } + public Long getResourceId() { + return resourceId; + } + + public void setResourceId(Long resourceId) { + this.resourceId = resourceId; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) @@ -142,6 +154,7 @@ public class AppPayOrder extends BaseEntity .append("orderNo", getOrderNo()) .append("tradeNo", getTradeNo()) .append("userId", getUserId()) + .append("resourceId", getResourceId()) .append("openId", getOpenId()) .append("amount", getAmount()) .append("points", getPoints()) diff --git a/ruoyi-system/src/main/java/com/ruoyi/app/service/impl/WxMiniappPayServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/app/service/impl/WxMiniappPayServiceImpl.java index c79c7f6..0f86513 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/app/service/impl/WxMiniappPayServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/app/service/impl/WxMiniappPayServiceImpl.java @@ -4,8 +4,10 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.ruoyi.app.domain.AppIntegralRecord; import com.ruoyi.app.domain.AppPayOrder; +import com.ruoyi.app.domain.AppResource; import com.ruoyi.app.mapper.AppIntegralRecordMapper; import com.ruoyi.app.mapper.AppPayOrderMapper; +import com.ruoyi.app.mapper.AppResourceMapper; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.utils.OrderNoGenerator; import com.ruoyi.common.wx.*; @@ -59,6 +61,8 @@ public class WxMiniappPayServiceImpl implements WxMiniappPayService { @Autowired private SysUserMapper sysUserMapper; @Autowired + private AppResourceMapper appResourceMapper; + @Autowired private AppPayOrderMapper appPayOrderMapper; @Autowired private AppIntegralRecordMapper appIntegralRecordMapper; @@ -72,13 +76,21 @@ public class WxMiniappPayServiceImpl implements WxMiniappPayService { @Override public Response createOrder(CreateOrderReq req) { SysUser sysUser = sysUserMapper.selectUserById(req.getUserId()); + AppResource appResource = null; + if (!Objects.isNull(req.getResourceId())) { + appResource = appResourceMapper.selectAppResourceById(req.getResourceId()); + } String openId = sysUser.getUserName(); String orderNo = OrderNoGenerator.generatePayOrderNo(); // 创建本地订单 // 这里做本地业务相关的处理,包括生成一个订单号传递给微信,等于通过这个值来形成两边的数据对应。后续微信那边会返回他们的订单编号,也建议存在自己这边的数据库里。 PayOrderInfo order = new PayOrderInfo(); order.setOutTradeNo(orderNo); - order.setDescription("积分充值"); + if (Objects.isNull(appResource)) { + order.setDescription("积分充值"); + } else { + order.setDescription("购买资源:" + appResource.getResourceTitle()); + } order.setAmount(new BigDecimal(req.getAmount())); // 请求微信支付相关配置 @@ -127,19 +139,20 @@ public class WxMiniappPayServiceImpl implements WxMiniappPayService { } // 保存订单信息 - saveOrder(orderNo, req.getAmount(), req.getPoints(), req.getUserId(), openId); + saveOrder(orderNo, req.getAmount(), req.getPoints(), req.getUserId(), req.getResourceId(), openId); return Response.success(response); } - private void saveOrder(String orderNo, Long amount, Long points, Long userId, String openId) { + private void saveOrder(String orderNo, Long amount, Long points, Long userId, Long resourceId, String openId) { AppPayOrder order = appPayOrderMapper.selectAppPayOrderByOrderNo(orderNo); - if(Objects.isNull(order)){ + if (Objects.isNull(order)) { order = new AppPayOrder(); } order.setOrderNo(orderNo); order.setAmount(amount); order.setPoints(points); order.setUserId(userId); + order.setResourceId(resourceId); order.setOpenId(openId); order.setStatus(0); order.setCreateTime(new Date()); @@ -221,7 +234,9 @@ public class WxMiniappPayServiceImpl implements WxMiniappPayService { order.setPayTime(new Date()); appPayOrderMapper.updateAppPayOrder(order); // 更新充值积分 - updateUserPoints(order.getUserId(), order.getPoints()); + if (order.getPoints() != 0) { + updateUserPoints(order.getUserId(), order.getPoints()); + } returnMap.put("code", "SUCCESS"); returnMap.put("message", "成功"); @@ -234,6 +249,7 @@ public class WxMiniappPayServiceImpl implements WxMiniappPayService { if (sysUser == null) { throw new RuntimeException("用户不存在"); } + AppIntegralRecord appIntegralRecord = new AppIntegralRecord(); appIntegralRecord.setUserId(userId); appIntegralRecord.setIntegralNumber(points); @@ -241,6 +257,7 @@ public class WxMiniappPayServiceImpl implements WxMiniappPayService { appIntegralRecord.setIsAdd(0L); appIntegralRecord.setIntegralTime(new Date()); appIntegralRecordMapper.insertAppIntegralRecord(appIntegralRecord); + // 更新用户积分 sysUser.setIntegral(sysUser.getIntegral() + points.intValue()); sysUserMapper.updateUser(sysUser); } @@ -279,7 +296,7 @@ public class WxMiniappPayServiceImpl implements WxMiniappPayService { // TODO 修改订单信息 return Response.success(result.getTradeStateDesc()); - } catch (ServiceException e) { + } catch (ServiceException e) { log.error("根据支付订单号查询订单:订单查询失败,发送HTTP请求成功,返回异常,返回码:{},返回信息:", e.getErrorCode(), e); return Response.error("订单查询失败"); } catch (MalformedMessageException e) { diff --git a/ruoyi-system/src/main/resources/mapper/app/AppBlogArticleMapper.xml b/ruoyi-system/src/main/resources/mapper/app/AppBlogArticleMapper.xml index d8104e7..0e19e7c 100644 --- a/ruoyi-system/src/main/resources/mapper/app/AppBlogArticleMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/app/AppBlogArticleMapper.xml @@ -25,25 +25,65 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + + + + + + + + + + + + + + + + select id, title, content_info, article_type, keyword, show_img, app_resource_id, look_number, weight, love_number, is_recommendation, is_show, is_ad, ad_number, del_flag, create_by, create_time, remark from app_blog_article - + select + a.id, a.title, a.content_info, a.article_type, a.keyword, a.show_img, a.app_resource_id, + a.look_number, a.weight, a.love_number, a.is_recommendation, a.is_show, a.is_ad, + a.ad_number, a.del_flag, a.create_by, a.create_time, a.remark, + r.id as resource_id, + r.resource_title, + r.show_img as resource_show_img, + r.explain as resource_explain, + r.resource_type, + r.keyword as resource_keyword, + r.is_show as resource_is_show, + r.is_ad as resource_is_ad, + r.ad_number as resource_ad_number, + r.down_num as resource_down_num, + r.weight as resource_weight, + r.del_flag as resource_del_flag, + r.create_by as resource_create_by, + r.create_time as resource_create_time, + r.remark as resource_remark + from app_blog_article a + left join app_resource r on a.app_resource_id = r.id - and title like concat('%', #{title}, '%') - and content_info like concat('%', #{contentInfo}, '%') - and article_type = #{articleType} - and app_resource_id = #{appResourceId} - and is_recommendation = #{isRecommendation} - and is_show = #{isShow} - and weight = #{weight} - and (keyword like concat('%', #{keyword}, '%') or title like concat('%', #{keyword}, '%')) + and a.title like concat('%', #{title}, '%') + and a.content_info like concat('%', #{contentInfo}, '%') + and a.article_type = #{articleType} + and a.app_resource_id = #{appResourceId} + and a.is_recommendation = #{isRecommendation} + and a.is_show = #{isShow} + and a.weight = #{weight} + and (a.keyword like concat('%', #{keyword}, '%') or a.title like concat('%', #{keyword}, '%')) - ORDER BY look_number desc, create_time desc - ORDER BY weight desc, create_time desc + ORDER BY a.look_number desc, a.create_time desc + ORDER BY a.weight desc, a.create_time desc diff --git a/ruoyi-system/src/main/resources/mapper/app/AppPayOrderMapper.xml b/ruoyi-system/src/main/resources/mapper/app/AppPayOrderMapper.xml index 9c96d46..37f9f64 100644 --- a/ruoyi-system/src/main/resources/mapper/app/AppPayOrderMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/app/AppPayOrderMapper.xml @@ -9,6 +9,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -18,7 +19,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select id, order_no, trade_no, user_id, open_id, amount, points, status, create_time, pay_time from app_pay_order + select id, order_no, trade_no, user_id, resource_id, open_id, amount, points, status, create_time, pay_time from app_pay_order