数据
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package com.ruoyi.web.controller.cai.admin.init;
|
||||
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.ruoyi.cai.service.CitysService;
|
||||
import com.ruoyi.cai.trdpay.TrdPayManager;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -18,10 +20,24 @@ public class CityController {
|
||||
|
||||
@Autowired
|
||||
private CitysService citysService;
|
||||
@Autowired
|
||||
private TrdPayManager trdPayManager;
|
||||
|
||||
@GetMapping("/resetRedis")
|
||||
public R<Void> resetRedis(){
|
||||
citysService.resetRedis();
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@GetMapping("/resetOrder")
|
||||
public R<JSONObject> resetOrder(String orderNo){
|
||||
JSONObject jsonObject = trdPayManager.resetOrder(orderNo);
|
||||
return R.ok(jsonObject);
|
||||
}
|
||||
|
||||
@GetMapping("/queryOrder")
|
||||
public R<JSONObject> queryOrder(String orderNo){
|
||||
JSONObject jsonObject = trdPayManager.queryOrder(orderNo);
|
||||
return R.ok(jsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.ijpay.core.kit.WxPayKit;
|
||||
import com.ijpay.wxpay.WxPayApi;
|
||||
import com.ijpay.wxpay.model.UnifiedOrderModel;
|
||||
import com.ruoyi.cai.domain.PayConfig;
|
||||
import com.ruoyi.cai.dto.app.vo.pay.OrderPayStatusResp;
|
||||
import com.ruoyi.cai.enums.SystemConfigEnum;
|
||||
import com.ruoyi.cai.manager.SystemConfigManager;
|
||||
import com.ruoyi.cai.pay.*;
|
||||
@@ -30,10 +31,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
@@ -56,21 +54,28 @@ public class PayController {
|
||||
private TrdPayManager trdPayManager;
|
||||
@Autowired
|
||||
private SystemConfigManager systemConfigManager;
|
||||
|
||||
private static final String NOTIFY_WX_URL = "/api/pay/wx/notify";
|
||||
private static final String NOTIFY_ALI_URL = "/api/pay/ali/notify";
|
||||
|
||||
|
||||
@PostMapping(value = "/trdAli")
|
||||
@Operation(summary = "第三方支付宝支付")
|
||||
@Log(title = "第三方支付宝支付", businessType = BusinessType.OTHER, isSaveDb = true)
|
||||
public R<Map<String,Object>> checkPayType(){
|
||||
Integer payInit = systemConfigManager.getSystemConfigOfInt(SystemConfigEnum.COS_DOMAIN);
|
||||
@GetMapping(value = "/checkPay")
|
||||
@Operation(summary = "检查使用的支付方式")
|
||||
@Log(title = "检查使用的支付方式", businessType = BusinessType.OTHER, isSaveDb = true)
|
||||
public R<UsePayResp> checkPayType(){
|
||||
Long userId = LoginHelper.getUserId();
|
||||
|
||||
|
||||
boolean userTrdPay = trdPayManager.useTrdPay(userId);
|
||||
UsePayResp usePayResp = new UsePayResp();
|
||||
usePayResp.setPayType(userTrdPay?2:1);
|
||||
return R.ok(usePayResp);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/findOrderPay")
|
||||
@Operation(summary = "查询订单支付状态")
|
||||
@Log(title = "查询订单支付状态", businessType = BusinessType.OTHER, isSaveDb = true)
|
||||
public R<OrderPayStatusResp> findOrderPay(String orderNo){
|
||||
OrderPayStatusResp orderPayStatusResp = payManager.getOrderPayStatus(orderNo);
|
||||
return R.ok(orderPayStatusResp);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/trdAli")
|
||||
@Operation(summary = "第三方支付宝支付")
|
||||
|
||||
@@ -15,9 +15,11 @@ import com.ruoyi.cai.enums.SystemConfigEnum;
|
||||
import com.ruoyi.cai.enums.account.AccountCateEnum;
|
||||
import com.ruoyi.cai.manager.SystemConfigManager;
|
||||
import com.ruoyi.cai.service.*;
|
||||
import com.ruoyi.cai.trdpay.TrdPayManager;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.helper.LoginHelper;
|
||||
import com.ruoyi.common.utils.BeanConvertUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -46,6 +48,8 @@ public class SettingAppController {
|
||||
private AgreementSettingService agreementSettingService;
|
||||
@Autowired
|
||||
private SystemConfigManager systemConfigManager;
|
||||
@Autowired
|
||||
private TrdPayManager trdPayManager;
|
||||
|
||||
@GetMapping("/goods")
|
||||
@Operation(summary = "充值配置")
|
||||
@@ -55,6 +59,8 @@ public class SettingAppController {
|
||||
vo.setHasAlipayPay(systemConfigManager.getSystemConfigOfInt(SystemConfigEnum.OPEN_ALI_PAY));
|
||||
vo.setHasWechatPay(systemConfigManager.getSystemConfigOfInt(SystemConfigEnum.OPEN_WX_PAY));
|
||||
vo.setAlipayFirst(systemConfigManager.getSystemConfigOfInt(SystemConfigEnum.ALI_PAY_FIRST));
|
||||
boolean useTrdPay = trdPayManager.useTrdPay(LoginHelper.getUserId());
|
||||
vo.setUseTrdPay(useTrdPay?1:0);
|
||||
List<Goods> list = goodsService.list(Wrappers.lambdaQuery(Goods.class)
|
||||
.eq(Goods::getStatus,0)
|
||||
.orderByAsc(Goods::getPrice));
|
||||
|
||||
@@ -44,6 +44,10 @@ public class Account implements Serializable {
|
||||
* 充值彩贝总额
|
||||
*/
|
||||
private Long totalBuyCoin;
|
||||
/**
|
||||
* 第四方充值总额
|
||||
*/
|
||||
private BigDecimal totalTrdMoney;
|
||||
/**
|
||||
* 聊天收入
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.ruoyi.cai.dto.app.vo.pay;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class OrderPayStatusResp {
|
||||
|
||||
private String orderNo;
|
||||
private BigDecimal amount;
|
||||
private Integer payStatus;
|
||||
}
|
||||
@@ -14,6 +14,8 @@ public class SettingGoodsVo {
|
||||
private Integer hasWechatPay = 1;
|
||||
@Schema(description = "支付宝是否放在第一个 1-是 0-否")
|
||||
private Integer alipayFirst = 1;
|
||||
@Schema(description = "是否使用第四方支付 1-是 0-否")
|
||||
private Integer useTrdPay = 1;
|
||||
@Schema(description = "支付设置")
|
||||
private List<Goods> goods;
|
||||
}
|
||||
|
||||
@@ -101,6 +101,7 @@ public enum SystemConfigEnum {
|
||||
OPEN_USER_CHAT_COUNT("0", "开启用户主动消息统计",SystemConfigGroupEnum.SYSTEM,new BooleanSystemConfigCheck()),
|
||||
IM_FILTER_PLUS("0", "IM拦截配置(勿动,开发配置)",SystemConfigGroupEnum.SYSTEM),
|
||||
COS_DOMAIN("http://ap-shanghai.myqcloud.com/", "文件系统域名前缀",SystemConfigGroupEnum.SYSTEM),
|
||||
PAY_LIMIT("200", "原生支付的阈值(元)",SystemConfigGroupEnum.SYSTEM, new NumberSystemConfigCheck()),
|
||||
SYSTEM_CUSTOMER_SERVICE("2,4", "系统客服",SystemConfigGroupEnum.SYSTEM),
|
||||
PRIVACY_AGREEMENT("/#/agreement/privacy", "隐私协议地址",SystemConfigGroupEnum.SYSTEM),
|
||||
USER_AGREEMENT("/#/agreement/user", "用户协议地址",SystemConfigGroupEnum.SYSTEM),
|
||||
|
||||
@@ -38,4 +38,9 @@ public class AccountTotalManager {
|
||||
log.info("开始收入统计 充值: userId={},price={},rechargeCoin={}, businessLogId={}", userId, price, rechargeCoin,consumeLogId);
|
||||
accountMapper.incsPayTotal(userId, rechargeCoin, price);
|
||||
}
|
||||
|
||||
public void incsTrdPayIncomeCoin(Long userId, BigDecimal price) {
|
||||
log.info("开始第四方支付统计 充值: userId={},price={}", userId, price);
|
||||
accountMapper.incsTrdPayTotal(userId, price);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,8 +177,11 @@ public class ConsumerManager {
|
||||
log.error("RabbitMq 发送失败, 充值分销流程流转失败!",e);
|
||||
}
|
||||
try {
|
||||
// 记录用户的消费统计
|
||||
// 记录用户的消费金额统计
|
||||
accountTotalManager.incsPayIncomeCoin(resp.getUserId(), resp.getRechargeCoin(),resp.getPrice(), resp.getConsumeLogId());
|
||||
if(PayTypeEnum.TRD == payTypeEnum){
|
||||
accountTotalManager.incsTrdPayIncomeCoin(resp.getUserId(), resp.getPrice());
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("主播消费记录失败-充值",e);
|
||||
}
|
||||
|
||||
@@ -37,5 +37,5 @@ public interface AccountMapper extends BaseMapper<Account> {
|
||||
|
||||
void incsPayTotal(@Param("userId") Long userId, @Param("rechargeCoin") Long rechargeCoin, @Param("price") BigDecimal price);
|
||||
|
||||
void incsTrdPayTotal(@Param("userId") Long userId, @Param("rechargeCoin") Long rechargeCoin, @Param("price") BigDecimal price);
|
||||
void incsTrdPayTotal(@Param("userId") Long userId, @Param("price") BigDecimal price);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.ruoyi.cai.domain.PayConfig;
|
||||
import com.ruoyi.cai.domain.RechargeOrder;
|
||||
import com.ruoyi.cai.domain.VipOrder;
|
||||
import com.ruoyi.cai.dto.ConsumeResp;
|
||||
import com.ruoyi.cai.dto.app.vo.pay.OrderPayStatusResp;
|
||||
import com.ruoyi.cai.dto.commom.consumer.RechargeConsumerResp;
|
||||
import com.ruoyi.cai.manager.AwardManager;
|
||||
import com.ruoyi.cai.manager.ConsumerManager;
|
||||
@@ -235,4 +236,36 @@ public class PayManager {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public OrderPayStatusResp getOrderPayStatus(String orderNo) {
|
||||
OrderTypeEnum orderTypeEnum = OrderNoUtil.getType(orderNo);
|
||||
if(orderTypeEnum == null){
|
||||
log.error("订单类型有误!orderNo={}",orderNo);
|
||||
return null;
|
||||
}
|
||||
OrderPayStatusResp resp = null;
|
||||
switch (orderTypeEnum) {
|
||||
case VIP_ORDER_SUB:
|
||||
VipOrder vipOrder = vipOrderService.getByOrderNo(orderNo);
|
||||
if(vipOrder != null){
|
||||
resp = new OrderPayStatusResp();
|
||||
resp.setOrderNo(vipOrder.getOrderNo());
|
||||
resp.setAmount(vipOrder.getPrice());
|
||||
resp.setPayStatus(vipOrder.getPayStatus());
|
||||
}
|
||||
break;
|
||||
case RECHARGE_ORDER_SUB:
|
||||
RechargeOrder rechargeOrder = rechargeOrderService.getByOrderNo(orderNo);
|
||||
if(rechargeOrder != null){
|
||||
resp = new OrderPayStatusResp();
|
||||
resp.setOrderNo(rechargeOrder.getOrderNo());
|
||||
resp.setAmount(rechargeOrder.getPrice());
|
||||
resp.setPayStatus(rechargeOrder.getPayStatus());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
|
||||
10
ruoyi-cai/src/main/java/com/ruoyi/cai/pay/UsePayResp.java
Normal file
10
ruoyi-cai/src/main/java/com/ruoyi/cai/pay/UsePayResp.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.ruoyi.cai.pay;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UsePayResp {
|
||||
@Schema(description = "1-原生接口 2-第四方接口")
|
||||
private Integer payType;
|
||||
}
|
||||
@@ -4,7 +4,13 @@ package com.ruoyi.cai.trdpay;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.ruoyi.cai.domain.Account;
|
||||
import com.ruoyi.cai.enums.SystemConfigEnum;
|
||||
import com.ruoyi.cai.manager.SystemConfigManager;
|
||||
import com.ruoyi.cai.pay.PayManager;
|
||||
import com.ruoyi.cai.pay.PayOrderInfoDTO;
|
||||
import com.ruoyi.cai.pay.PayTypeEnum;
|
||||
import com.ruoyi.cai.service.AccountService;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -29,6 +35,7 @@ import java.util.stream.Collectors;
|
||||
public class TrdPayManager {
|
||||
|
||||
private final String CREATE_ORDER_URL = "http://pay.jpay.one/api/pay/create_order";
|
||||
private final String QUERY_ORDER_URL = "http://pay.jpay.one/api/pay/query_order";
|
||||
|
||||
private static final String NOTIFY_ALI_URL = "/api/pay/trd/notify";
|
||||
|
||||
@@ -60,6 +67,63 @@ public class TrdPayManager {
|
||||
return createOrder(payOrderInfoDTO,trdPayProperties.getAliProductId());
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private AccountService accountService;
|
||||
@Autowired
|
||||
private SystemConfigManager systemConfigManager;
|
||||
|
||||
public boolean useTrdPay(Long userId){
|
||||
Account account = accountService.getByUserId(userId);
|
||||
if(account == null){
|
||||
return true;
|
||||
}
|
||||
BigDecimal payLimit = systemConfigManager.getSystemConfigOfBigDecimal(SystemConfigEnum.PAY_LIMIT);
|
||||
if(payLimit == null || payLimit.compareTo(BigDecimal.ZERO) == 0){
|
||||
return false;
|
||||
}
|
||||
if(account.getTotalTrdMoney().compareTo(payLimit) >= 0){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private PayManager payManager;
|
||||
|
||||
public JSONObject resetOrder(String orderNo){
|
||||
JSONObject jsonObject = queryOrder(orderNo);
|
||||
Integer status = jsonObject.getInteger("status");
|
||||
if(status != null && status.equals(2)){
|
||||
String mchOrderNo = jsonObject.getString("mchOrderNo");
|
||||
String payOrderId = jsonObject.getString("payOrderId");
|
||||
String productId = jsonObject.getString("productId");
|
||||
Map<String,String> objectJson = new HashMap<>();
|
||||
for (String key : jsonObject.keySet()) {
|
||||
objectJson.put(key, jsonObject.getString(key));
|
||||
}
|
||||
payManager.callBack(mchOrderNo,payOrderId,objectJson,productId, PayTypeEnum.TRD);
|
||||
}
|
||||
return jsonObject;
|
||||
}
|
||||
public JSONObject queryOrder(String orderNo){
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("mchId", trdPayProperties.getMchId());
|
||||
params.put("mchOrderNo", orderNo);
|
||||
String para = createParams(params);
|
||||
String url = QUERY_ORDER_URL + "?" + para;
|
||||
String body = restTemplate.getForEntity(url, String.class).getBody();
|
||||
JSONObject jsonObject = JSON.parseObject(body);
|
||||
if(jsonObject == null){
|
||||
log.error("第三方支付查询失败 返回数据为空");
|
||||
throw new ServiceException("调用支付失败");
|
||||
}
|
||||
if(!"SUCCESS".equals(jsonObject.getString("retCode"))){
|
||||
log.info("第三方支付查询失败 第三方支付查询失败 url={}, body={}",url, body);
|
||||
throw new ServiceException("调用支付失败");
|
||||
}
|
||||
log.info("第三方支付成功 URL={}, body={}",url, body);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
|
||||
public JSONObject createOrder(PayOrderInfoDTO payOrderInfoDTO,String productId){
|
||||
|
||||
@@ -67,6 +67,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
total_buy_coin = total_buy_coin + #{rechargeCoin}
|
||||
where user_id = #{userId}
|
||||
</update>
|
||||
<update id="incsTrdPayTotal">
|
||||
update cai_account
|
||||
set total_trd_money = total_trd_money + #{price}
|
||||
where user_id = #{userId}
|
||||
</update>
|
||||
<select id="pageAdmin" resultType="com.ruoyi.cai.dto.admin.vo.AccountAdminVo">
|
||||
select t1.*,t2.usercode,t2.nickname,t2.mobile,t2.avatar,t2.gender,t2.is_anchor,t2.age
|
||||
from cai_account t1
|
||||
|
||||
Reference in New Issue
Block a user