提交 3bf25a5f 作者: han

增加积分购买聊天时长、微信购买积分相关接口

上级 be2ee615
流水线 #8392 已通过 于阶段
in 2 分 32 秒
package com.mmc.iuav.user.model.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BuyPointsVO implements Serializable {
private static final long serialVersionUID = -1481188328848093579L;
@ApiModelProperty(value = "购买积分类型展示", example = "1")
@NotNull(message = "类型不能为空")
private Integer id;
@ApiModelProperty(value = "微信支付金额", example = "10")
private BigDecimal money;
@ApiModelProperty(value = "购买的积分数额", example = "200")
private Integer points;
private Date createTime;
private Date updateTime;
}
package com.mmc.iuav.user.model.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class MessageTimeVO implements Serializable {
private static final long serialVersionUID = -1481188328848093579L;
@ApiModelProperty(value = "购买聊天时长的类型", example = "1")
@NotNull(message = "类型不能为空")
private Integer id;
@ApiModelProperty(value = "微信支付金额", example = "5")
private BigDecimal money;
@ApiModelProperty(value = "购买的积分数额", example = "200")
private Integer points;
@ApiModelProperty(value = "聊天时长", example = "7")
private Integer chatDuration;
}
package com.mmc.iuav.user.model.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class OrderRequestParamsVO implements Serializable {
@ApiModelProperty(value = "订单编号")
private String orderNo;
@ApiModelProperty(value = "商品描述")
private String description;
@ApiModelProperty(value = "订单金额(分为单位)")
private Integer amount;
@ApiModelProperty(value = "订单来源 0:产品商城 1:租赁订单 2:培训订单 3:充值云享金 ...其他后续加")
private Integer orderPort;
@ApiModelProperty(value = "附加参数 :附加数据,在查询API和支付通知中原样返回,可作为自定义参数使用,实际情况下只有支付完成状态才会返回该字段。")
private String attach;
}
...@@ -39,7 +39,30 @@ ...@@ -39,7 +39,30 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId> <artifactId>spring-boot-starter-aop</artifactId>
</dependency> </dependency>
<!-- 引入 Feign, 可以以声明的方式调用微服务 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.2.9.RELEASE</version>
</dependency>
<!-- 使用okhttp-feign-连接池技术 -->
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-okhttp</artifactId>
<version>10.12</version>
</dependency>
<!-- 引入服务容错 Hystrix 的依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
<version>2.2.9.RELEASE</version>
</dependency>
<!-- mybatis驱动&Druid数据源-start --> <!-- mybatis驱动&Druid数据源-start -->
<dependency> <dependency>
......
...@@ -2,16 +2,17 @@ package com.mmc.iuav.user; ...@@ -2,16 +2,17 @@ package com.mmc.iuav.user;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
/** /**
* @author:zhenjie * @author:zhenjie
* @Date:2023/5/15 15:35 * @Date:2023/5/15 15:35
*/ */
@EnableScheduling @EnableScheduling
@SpringBootApplication @SpringBootApplication
@EnableFeignClients(basePackages = "com.mmc.iuav.user.feign") // 所有FeignClient放在client-feign-springboot-starter里面进行管理
public class UserApplication { public class UserApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(UserApplication.class, args); SpringApplication.run(UserApplication.class, args);
......
package com.mmc.iuav.user.controller; package com.mmc.iuav.user.controller;
import com.mmc.iuav.response.ResultBody; import com.mmc.iuav.response.ResultBody;
import com.mmc.iuav.user.model.dto.LoginSuccessDTO;
import com.mmc.iuav.user.model.qo.MessageQO; import com.mmc.iuav.user.model.qo.MessageQO;
import com.mmc.iuav.user.model.qo.MessageUserQO; import com.mmc.iuav.user.model.qo.MessageUserQO;
import com.mmc.iuav.user.model.vo.MessageTimeVO;
import com.mmc.iuav.user.model.vo.SystemMessageVO; import com.mmc.iuav.user.model.vo.SystemMessageVO;
import com.mmc.iuav.user.model.vo.UserMessageVO; import com.mmc.iuav.user.model.vo.UserMessageVO;
import com.mmc.iuav.user.service.MessageService; import com.mmc.iuav.user.service.MessageService;
...@@ -102,4 +104,32 @@ public class MessageController extends BaseController{ ...@@ -102,4 +104,32 @@ public class MessageController extends BaseController{
return messageService.removeUserMessage(id); return messageService.removeUserMessage(id);
} }
@ApiOperation(value = "购买聊天时长(积分或微信支付)")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
@PostMapping("/purchaseTime")
public ResultBody purchaseTime(HttpServletRequest request,@RequestBody MessageTimeVO messageTimeVO){
LoginSuccessDTO userLoginInfoFromRedis = this.getUserLoginInfoFromRedis(request);
Integer userAccountId = userLoginInfoFromRedis.getUserAccountId();
String token = userLoginInfoFromRedis.getToken();
return messageService.purchaseTime(userAccountId,messageTimeVO,token);
}
@ApiOperation(value = "返回聊天时长选购类型")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
@PostMapping("/listTimeType")
public ResultBody listTimeType(){
return messageService.listTimeType();
}
@ApiOperation(value = "后台管理——修改聊天时长选购类型")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
@PostMapping("/updateTimeType")
public ResultBody updateTimeType(@RequestBody MessageTimeVO messageTimeVO){
return messageService.updateTimeType(messageTimeVO);
}
@ApiOperation(value = "后台管理——新增聊天时长选购类型")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
@PostMapping("/insertTimeType")
public ResultBody insertTimeType(@RequestBody MessageTimeVO messageTimeVO){
return messageService.insertTimeType(messageTimeVO);
}
} }
...@@ -10,6 +10,8 @@ import com.mmc.iuav.user.model.dto.userpoints.UserPointsDetailsDTO; ...@@ -10,6 +10,8 @@ import com.mmc.iuav.user.model.dto.userpoints.UserPointsDetailsDTO;
import com.mmc.iuav.user.model.qo.userpoints.AppPointsDetailsQO; import com.mmc.iuav.user.model.qo.userpoints.AppPointsDetailsQO;
import com.mmc.iuav.user.model.qo.userpoints.UserPointQO; import com.mmc.iuav.user.model.qo.userpoints.UserPointQO;
import com.mmc.iuav.user.model.qo.userpoints.UserPointsDetailsQO; import com.mmc.iuav.user.model.qo.userpoints.UserPointsDetailsQO;
import com.mmc.iuav.user.model.vo.BuyPointsVO;
import com.mmc.iuav.user.model.vo.MessageTimeVO;
import com.mmc.iuav.user.model.vo.userpoints.ChangeUserPointVO; import com.mmc.iuav.user.model.vo.userpoints.ChangeUserPointVO;
import com.mmc.iuav.user.service.userpoints.UserPointsService; import com.mmc.iuav.user.service.userpoints.UserPointsService;
import io.swagger.annotations.*; import io.swagger.annotations.*;
...@@ -86,4 +88,32 @@ public class UserPointsController extends BaseController { ...@@ -86,4 +88,32 @@ public class UserPointsController extends BaseController {
public ResultBody feignChangeUserPoints(HttpServletRequest request,@RequestParam("id") int changePoint,String reason) { public ResultBody feignChangeUserPoints(HttpServletRequest request,@RequestParam("id") int changePoint,String reason) {
return userPointsService.changeUserPoints(this.getUserLoginInfoFromRedis(request).getUserAccountId(), null,changePoint,reason); return userPointsService.changeUserPoints(this.getUserLoginInfoFromRedis(request).getUserAccountId(), null,changePoint,reason);
} }
@ApiOperation(value = "用户购买积分")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
@PostMapping("/weixinBuyPoints")
public ResultBody weixinBuyPoints(@RequestBody BuyPointsVO buyPointsVO,HttpServletRequest request) {
return userPointsService.weixinBuyPoints(buyPointsVO,this.getUserLoginInfoFromRedis(request).getUserAccountId(),this.getUserLoginInfoFromRedis(request).getToken());
}
@ApiOperation(value = "返回购买积分选购类型")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
@PostMapping("/selectAllBuyPointsType")
public ResultBody selectAllBuyPointsType(){
return userPointsService.selectAllBuyPointsType();
}
@ApiOperation(value = "后台管理——修改购买积分选购类型")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
@PostMapping("/updateBuyPointsType")
public ResultBody updateBuyPointsType(@RequestBody BuyPointsVO buyPointsVO){
return userPointsService.updateBuyPointsType(buyPointsVO);
}
@ApiOperation(value = "后台管理——新增购买积分选购类型")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
@PostMapping("/insertBuyPointsType")
public ResultBody insertBuyPointsType(@RequestBody BuyPointsVO buyPointsVO){
return userPointsService.insertBuyPointsType(buyPointsVO);
}
} }
...@@ -15,8 +15,9 @@ public enum UserPointsEnum { ...@@ -15,8 +15,9 @@ public enum UserPointsEnum {
OTHER_CHANGE(5, "其他变动"), OTHER_CHANGE(5, "其他变动"),
USER_USE(6, "使用"), USER_USE(6, "使用"),
INVITE_USER(7, "邀请用户"), INVITE_USER(7, "邀请用户"),
BUY_TIME(8,"购买聊天时长"),
BUY_POINT(9,"购买积分")
; ;
private int code; private int code;
private String message; private String message;
......
...@@ -5,6 +5,7 @@ import com.mmc.iuav.user.entity.UserMessageDO; ...@@ -5,6 +5,7 @@ import com.mmc.iuav.user.entity.UserMessageDO;
import com.mmc.iuav.user.entity.UserMessageLogDO; import com.mmc.iuav.user.entity.UserMessageLogDO;
import com.mmc.iuav.user.model.qo.MessageQO; import com.mmc.iuav.user.model.qo.MessageQO;
import com.mmc.iuav.user.model.qo.MessageUserQO; import com.mmc.iuav.user.model.qo.MessageUserQO;
import com.mmc.iuav.user.model.vo.MessageTimeVO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -113,4 +114,8 @@ public interface MessageDao { ...@@ -113,4 +114,8 @@ public interface MessageDao {
void removeUserMessageLog(@Param("id") Integer logId); void removeUserMessageLog(@Param("id") Integer logId);
UserMessageDO selectUserMessageById(@Param("id") Integer id); UserMessageDO selectUserMessageById(@Param("id") Integer id);
MessageTimeVO selectUserMessageTimeType(@Param("id")Integer id);
List<MessageTimeVO> listTimeType();
void updateTimeType(MessageTimeVO messageTimeVO);
void insertTimeType(MessageTimeVO messageTimeVO);
} }
...@@ -2,7 +2,9 @@ package com.mmc.iuav.user.dao.userpoints; ...@@ -2,7 +2,9 @@ package com.mmc.iuav.user.dao.userpoints;
import com.mmc.iuav.user.entity.userpoints.UserPointsDO; import com.mmc.iuav.user.entity.userpoints.UserPointsDO;
import com.mmc.iuav.user.model.qo.userpoints.UserPointQO; import com.mmc.iuav.user.model.qo.userpoints.UserPointQO;
import com.mmc.iuav.user.model.vo.BuyPointsVO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
...@@ -22,5 +24,11 @@ public interface UserPointsDao { ...@@ -22,5 +24,11 @@ public interface UserPointsDao {
List<UserPointsDO> userPointList(UserPointQO param); List<UserPointsDO> userPointList(UserPointQO param);
int count(UserPointQO param); int count(UserPointQO param);
BuyPointsVO selectBuyPointsType(@Param("id") Integer id);
List<BuyPointsVO> selectAllBuyPointsType();
void insertBuyPointsType(BuyPointsVO buyPointsVO);
void updateBuyPointsType(BuyPointsVO buyPointsVO);
} }
package com.mmc.iuav.user.feign;
import com.mmc.iuav.response.ResultBody;
import com.mmc.iuav.user.feign.hystrix.PaymentAppApiHystrix;
import com.mmc.iuav.user.model.vo.OrderRequestParamsVO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
@FeignClient(url = "${iuav.pay.uri}", name = "payment-svc", fallback = PaymentAppApiHystrix.class)
public interface PaymentAppApi {
@PostMapping("/payment/wechat/pay")
Map orderPay(@RequestBody OrderRequestParamsVO orderRequestParamsVO, @RequestHeader("token") String token);
}
package com.mmc.iuav.user.feign.config;
import com.mmc.iuav.user.feign.hystrix.PaymentAppApiHystrix;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
/**
* @author: zj
* @Date: 2023/5/18 18:21
*/
@ComponentScan(basePackages = "com.mmc.iuav.user.feign")
@Configuration
public class FeignConfiguration {
@Bean(name = "paymentAppApiHystrix")
public PaymentAppApiHystrix userAppApi(){
return new PaymentAppApiHystrix();
}
}
package com.mmc.iuav.user.feign.hystrix;
import com.mmc.iuav.response.ResultBody;
import com.mmc.iuav.user.feign.PaymentAppApi;
import com.mmc.iuav.user.model.vo.OrderRequestParamsVO;
import lombok.extern.slf4j.Slf4j;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
/**
* @author: zj
* @Date: 2023/6/10 20:24
*/
@Slf4j
public class PaymentAppApiHystrix implements PaymentAppApi {
@Override
public Map orderPay(OrderRequestParamsVO orderRequestParamsVO, String token) {
log.info("熔断--feignOrderPay:");
return null;
}
}
...@@ -4,6 +4,7 @@ import com.mmc.iuav.page.PageResult; ...@@ -4,6 +4,7 @@ import com.mmc.iuav.page.PageResult;
import com.mmc.iuav.response.ResultBody; import com.mmc.iuav.response.ResultBody;
import com.mmc.iuav.user.model.qo.MessageQO; import com.mmc.iuav.user.model.qo.MessageQO;
import com.mmc.iuav.user.model.qo.MessageUserQO; import com.mmc.iuav.user.model.qo.MessageUserQO;
import com.mmc.iuav.user.model.vo.MessageTimeVO;
import com.mmc.iuav.user.model.vo.SystemMessageVO; import com.mmc.iuav.user.model.vo.SystemMessageVO;
import com.mmc.iuav.user.model.vo.UserMessageVO; import com.mmc.iuav.user.model.vo.UserMessageVO;
...@@ -70,4 +71,12 @@ public interface MessageService { ...@@ -70,4 +71,12 @@ public interface MessageService {
ResultBody removeUserMessage(Integer id); ResultBody removeUserMessage(Integer id);
ResultBody removeUser(Integer senderUserId, Integer receiverUserId); ResultBody removeUser(Integer senderUserId, Integer receiverUserId);
ResultBody purchaseTime(Integer userAccountId, MessageTimeVO messageTimeVO, String token);
ResultBody listTimeType();
ResultBody updateTimeType(MessageTimeVO messageTimeVO);
ResultBody insertTimeType(MessageTimeVO messageTimeVO);
} }
package com.mmc.iuav.user.service.impl; package com.mmc.iuav.user.service.impl;
import com.google.gson.Gson;
import com.mmc.iuav.page.PageResult; import com.mmc.iuav.page.PageResult;
import com.mmc.iuav.response.ResultBody; import com.mmc.iuav.response.ResultBody;
import com.mmc.iuav.user.dao.MessageDao; import com.mmc.iuav.user.dao.MessageDao;
import com.mmc.iuav.user.dao.UserServiceDao; import com.mmc.iuav.user.dao.UserServiceDao;
import com.mmc.iuav.user.entity.*; import com.mmc.iuav.user.entity.*;
import com.mmc.iuav.user.feign.PaymentAppApi;
import com.mmc.iuav.user.model.qo.MessageQO; import com.mmc.iuav.user.model.qo.MessageQO;
import com.mmc.iuav.user.model.qo.MessageUserQO; import com.mmc.iuav.user.model.qo.MessageUserQO;
import com.mmc.iuav.user.model.vo.MessageTimeVO;
import com.mmc.iuav.user.model.vo.OrderRequestParamsVO;
import com.mmc.iuav.user.model.vo.SystemMessageVO; import com.mmc.iuav.user.model.vo.SystemMessageVO;
import com.mmc.iuav.user.model.vo.UserMessageVO; import com.mmc.iuav.user.model.vo.UserMessageVO;
import com.mmc.iuav.user.model.vo.userpoints.ChangeUserPointVO;
import com.mmc.iuav.user.service.MessageService; import com.mmc.iuav.user.service.MessageService;
import com.mmc.iuav.user.service.userpoints.UserPointsService;
import com.mmc.iuav.user.util.ScheduledTaskUtil; import com.mmc.iuav.user.util.ScheduledTaskUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
@Service @Service
public class MessageServiceImpl implements MessageService { public class MessageServiceImpl implements MessageService {
...@@ -31,6 +43,17 @@ public class MessageServiceImpl implements MessageService { ...@@ -31,6 +43,17 @@ public class MessageServiceImpl implements MessageService {
@Autowired @Autowired
private ScheduledTaskUtil scheduledTaskUtil; private ScheduledTaskUtil scheduledTaskUtil;
@Autowired
private StringRedisTemplate redisTemplate;
@Autowired
private UserPointsService userPointsService;
@Qualifier("com.mmc.iuav.user.feign.PaymentAppApi")
@Autowired
private PaymentAppApi paymentAppApi;
@Override @Override
public ResultBody insertSystemMessage(SystemMessageVO messageVO) { public ResultBody insertSystemMessage(SystemMessageVO messageVO) {
SystemMessageDO systemMessageDO = new SystemMessageDO(messageVO); SystemMessageDO systemMessageDO = new SystemMessageDO(messageVO);
...@@ -126,6 +149,11 @@ public class MessageServiceImpl implements MessageService { ...@@ -126,6 +149,11 @@ public class MessageServiceImpl implements MessageService {
if(senderUserId == null){ if(senderUserId == null){
return ResultBody.success("消息发送失败,请先登录"); return ResultBody.success("消息发送失败,请先登录");
} }
redisTemplate.setValueSerializer(RedisSerializer.json());
String s = redisTemplate.opsForValue().get("Message" + senderUserId);
if(s == null || s == ""){
return ResultBody.error("请先花费积分购买聊天时长");
}
userMessageDO.setSenderUserId(senderUserId); userMessageDO.setSenderUserId(senderUserId);
if(messageDao.insertUserMessage(userMessageDO) != 0){ if(messageDao.insertUserMessage(userMessageDO) != 0){
UserAccountDO userAccount = userServiceDao.getUserAccountById(userMessageDO.getReceiverUserId()); UserAccountDO userAccount = userServiceDao.getUserAccountById(userMessageDO.getReceiverUserId());
...@@ -225,6 +253,71 @@ public class MessageServiceImpl implements MessageService { ...@@ -225,6 +253,71 @@ public class MessageServiceImpl implements MessageService {
return ResultBody.error("删除失败"); return ResultBody.error("删除失败");
} }
@Override
public ResultBody purchaseTime(Integer userAccountId, MessageTimeVO messageTimeVO,String token) {
if(messageTimeVO.getId() == null){
return ResultBody.error("聊天类型不能传递为空");
}
MessageTimeVO messageTimeVO1 = messageDao.selectUserMessageTimeType(messageTimeVO.getId());
if(messageTimeVO.getMoney() != null && messageTimeVO.getMoney().compareTo(BigDecimal.ZERO) > 0){
// 微信支付购买聊天时长
OrderRequestParamsVO orderRequestParamsVO = new OrderRequestParamsVO();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
String content = "WT" + sdf.format(new Date());
orderRequestParamsVO.setOrderNo(content);
orderRequestParamsVO.setDescription("购买聊天时长");
BigDecimal money = messageTimeVO1.getMoney();
BigDecimal amountInFen = money.multiply(new BigDecimal("100")).setScale(0, RoundingMode.DOWN);
orderRequestParamsVO.setAmount(amountInFen.intValue());
orderRequestParamsVO.setOrderPort(5);
// 扣除金额
Map map = paymentAppApi.orderPay(orderRequestParamsVO, token);
}else if(messageTimeVO.getPoints() > 0){
ChangeUserPointVO changeUserPointVO = new ChangeUserPointVO();
changeUserPointVO.setUserAccountId(userAccountId);
changeUserPointVO.setChangePoint(messageTimeVO1.getPoints());
changeUserPointVO.setChangeType(8);
ResultBody resultBody = userPointsService.change(changeUserPointVO);
if (!"200".equals(resultBody.getCode())) {
return resultBody;
}
}else{
return ResultBody.error("请选择积分购买或者微信支付,不能同时为空");
}
// 增加聊天时长
String timeValue = redisTemplate.opsForValue().get("Message" + userAccountId);
if (timeValue == null || timeValue.equals("")) {
redisTemplate.setValueSerializer(RedisSerializer.json());
redisTemplate.opsForValue().set("Message" + userAccountId, userAccountId.toString(), messageTimeVO1.getChatDuration() * 24 * 60 * 60, TimeUnit.SECONDS);
return ResultBody.success("成功购买"+messageTimeVO1.getChatDuration()+"天聊天功能");
}
Long remainingTime = redisTemplate.getExpire("Message" + userAccountId, TimeUnit.SECONDS);
if (remainingTime != null && remainingTime >= 0) {
long newTime = remainingTime + (messageTimeVO1.getChatDuration() * 24 * 60 * 60); // 转换为毫秒后加上七天的毫秒数
redisTemplate.opsForValue().set("Message" + userAccountId, userAccountId.toString(), newTime, TimeUnit.SECONDS);
}
return ResultBody.success("成功购买"+messageTimeVO1.getChatDuration()+"天聊天功能");
}
@Override
public ResultBody listTimeType() {
List<MessageTimeVO> messageTimeVOS = messageDao.listTimeType();
return ResultBody.success(messageTimeVOS);
}
@Override
public ResultBody updateTimeType(MessageTimeVO messageTimeVO) {
messageDao.updateTimeType(messageTimeVO);
return ResultBody.success();
}
@Override
public ResultBody insertTimeType(MessageTimeVO messageTimeVO) {
messageDao.insertTimeType(messageTimeVO);
return ResultBody.success();
}
public static boolean isOverThreeMinutes(String createTime) { public static boolean isOverThreeMinutes(String createTime) {
// 定义日期时间格式化对象 // 定义日期时间格式化对象
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
......
...@@ -5,6 +5,7 @@ import com.mmc.iuav.response.ResultBody; ...@@ -5,6 +5,7 @@ import com.mmc.iuav.response.ResultBody;
import com.mmc.iuav.user.model.qo.userpoints.AppPointsDetailsQO; import com.mmc.iuav.user.model.qo.userpoints.AppPointsDetailsQO;
import com.mmc.iuav.user.model.qo.userpoints.UserPointQO; import com.mmc.iuav.user.model.qo.userpoints.UserPointQO;
import com.mmc.iuav.user.model.qo.userpoints.UserPointsDetailsQO; import com.mmc.iuav.user.model.qo.userpoints.UserPointsDetailsQO;
import com.mmc.iuav.user.model.vo.BuyPointsVO;
import com.mmc.iuav.user.model.vo.userpoints.ChangeUserPointVO; import com.mmc.iuav.user.model.vo.userpoints.ChangeUserPointVO;
/** /**
...@@ -34,4 +35,11 @@ public interface UserPointsService { ...@@ -34,4 +35,11 @@ public interface UserPointsService {
*/ */
ResultBody changeUserPoints(Integer userId,Integer pointChangeTypeId,int changePoint,String reason); ResultBody changeUserPoints(Integer userId,Integer pointChangeTypeId,int changePoint,String reason);
ResultBody weixinBuyPoints(BuyPointsVO buyPointsVO, Integer userAccountId,String token);
ResultBody insertBuyPointsType(BuyPointsVO buyPointsVO);
ResultBody updateBuyPointsType(BuyPointsVO buyPointsVO);
ResultBody selectAllBuyPointsType();
} }
...@@ -8,21 +8,30 @@ import com.mmc.iuav.user.dao.userpoints.UserPointsDetailsDao; ...@@ -8,21 +8,30 @@ import com.mmc.iuav.user.dao.userpoints.UserPointsDetailsDao;
import com.mmc.iuav.user.entity.userpoints.UserPointChangeTypeDO; import com.mmc.iuav.user.entity.userpoints.UserPointChangeTypeDO;
import com.mmc.iuav.user.entity.userpoints.UserPointsDO; import com.mmc.iuav.user.entity.userpoints.UserPointsDO;
import com.mmc.iuav.user.entity.userpoints.UserPointsDetails; import com.mmc.iuav.user.entity.userpoints.UserPointsDetails;
import com.mmc.iuav.user.feign.PaymentAppApi;
import com.mmc.iuav.user.model.dto.userpoints.UserPointsDTO; import com.mmc.iuav.user.model.dto.userpoints.UserPointsDTO;
import com.mmc.iuav.user.model.dto.userpoints.UserPointsDetailsDTO; import com.mmc.iuav.user.model.dto.userpoints.UserPointsDetailsDTO;
import com.mmc.iuav.user.model.qo.userpoints.AppPointsDetailsQO; import com.mmc.iuav.user.model.qo.userpoints.AppPointsDetailsQO;
import com.mmc.iuav.user.model.qo.userpoints.UserPointQO; import com.mmc.iuav.user.model.qo.userpoints.UserPointQO;
import com.mmc.iuav.user.model.qo.userpoints.UserPointsDetailsQO; import com.mmc.iuav.user.model.qo.userpoints.UserPointsDetailsQO;
import com.mmc.iuav.user.model.vo.BuyPointsVO;
import com.mmc.iuav.user.model.vo.OrderRequestParamsVO;
import com.mmc.iuav.user.model.vo.userpoints.ChangeUserPointVO; import com.mmc.iuav.user.model.vo.userpoints.ChangeUserPointVO;
import com.mmc.iuav.user.model.vo.userpoints.PointTypeVO; import com.mmc.iuav.user.model.vo.userpoints.PointTypeVO;
import com.mmc.iuav.user.service.userpoints.UserPointsService; import com.mmc.iuav.user.service.userpoints.UserPointsService;
import io.swagger.models.auth.In; import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -39,6 +48,10 @@ public class UserPointsServiceImpl implements UserPointsService { ...@@ -39,6 +48,10 @@ public class UserPointsServiceImpl implements UserPointsService {
@Autowired @Autowired
private UserPointsDetailsDao userPointsDetailsDao; private UserPointsDetailsDao userPointsDetailsDao;
@Qualifier("com.mmc.iuav.user.feign.PaymentAppApi")
@Autowired
private PaymentAppApi paymentAppApi;
@Override @Override
public PageResult userPointList(UserPointQO param) { public PageResult userPointList(UserPointQO param) {
int count = userPointsDao.count(param); int count = userPointsDao.count(param);
...@@ -85,10 +98,18 @@ public class UserPointsServiceImpl implements UserPointsService { ...@@ -85,10 +98,18 @@ public class UserPointsServiceImpl implements UserPointsService {
public ResultBody change(ChangeUserPointVO changePoint) { public ResultBody change(ChangeUserPointVO changePoint) {
UserPointsDO userPointsDO = userPointsDao.selectUserPoints(changePoint.getUserAccountId()); UserPointsDO userPointsDO = userPointsDao.selectUserPoints(changePoint.getUserAccountId());
//如果邀请人没有绑定手机号 是没有积分的 //如果邀请人没有绑定手机号 是没有积分的
if(userPointsDO == null) { if (userPointsDO == null) {
return ResultBody.success(); userPointsDO = new UserPointsDO();
userPointsDO.setUserAccountId(changePoint.getUserAccountId());
userPointsDO.setTotalPoints(0);
userPointsDao.insertPoints(userPointsDO);
} }
userPointsDO.setTotalPoints(userPointsDO.getTotalPoints() + changePoint.getChangePoint()); //改变后的用户总积分
Integer userNowPoints = userPointsDO.getTotalPoints() + changePoint.getChangePoint();
if(userNowPoints < 0) {
return ResultBody.error("积分不足,请先去赚取积分");
}
userPointsDO.setTotalPoints(userNowPoints);
// 修改用户积分 // 修改用户积分
userPointsDao.updatePoints(userPointsDO); userPointsDao.updatePoints(userPointsDO);
// 添加记录 // 添加记录
...@@ -147,4 +168,48 @@ public class UserPointsServiceImpl implements UserPointsService { ...@@ -147,4 +168,48 @@ public class UserPointsServiceImpl implements UserPointsService {
userPointsDetailsDao.insertPointsDetails(userPointsDetails); userPointsDetailsDao.insertPointsDetails(userPointsDetails);
return ResultBody.success(); return ResultBody.success();
} }
@Override
public ResultBody weixinBuyPoints(BuyPointsVO buyPointsVO, Integer userAccountId,String token) {
if(buyPointsVO.getId() == null){
return ResultBody.error("购买积分类型不能传递为空");
}
BuyPointsVO buyPointsVO1 = userPointsDao.selectBuyPointsType(buyPointsVO.getId());
OrderRequestParamsVO orderRequestParamsVO = new OrderRequestParamsVO();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
String content = "WP" + sdf.format(new Date());
orderRequestParamsVO.setOrderNo(content);
orderRequestParamsVO.setDescription("购买积分");
BigDecimal money = buyPointsVO1.getMoney();
BigDecimal amountInFen = money.multiply(new BigDecimal("100")).setScale(0, RoundingMode.DOWN);
orderRequestParamsVO.setAmount(amountInFen.intValue());
orderRequestParamsVO.setOrderPort(4);
// 扣除金额
Map map = paymentAppApi.orderPay(orderRequestParamsVO, token);
// 增加积分
ChangeUserPointVO changeUserPointVO = new ChangeUserPointVO();
changeUserPointVO.setUserAccountId(userAccountId);
changeUserPointVO.setChangePoint(buyPointsVO1.getPoints());
changeUserPointVO.setChangeType(9);
ResultBody change = change(changeUserPointVO);
return change;
}
@Override
public ResultBody insertBuyPointsType(BuyPointsVO buyPointsVO) {
userPointsDao.insertBuyPointsType(buyPointsVO);
return ResultBody.success();
}
@Override
public ResultBody updateBuyPointsType(BuyPointsVO buyPointsVO) {
userPointsDao.updateBuyPointsType(buyPointsVO);
return ResultBody.success();
}
@Override
public ResultBody selectAllBuyPointsType() {
List<BuyPointsVO> buyPointsVOS = userPointsDao.selectAllBuyPointsType();
return ResultBody.success(buyPointsVOS);
}
} }
...@@ -692,7 +692,7 @@ public class PayWalletServiceImpl implements PayWalletService { ...@@ -692,7 +692,7 @@ public class PayWalletServiceImpl implements PayWalletService {
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
ResultBody handleGiveBackPledge(PayUavWalletVO payUavWalletVO, PayWalletDO userWalletInfo, PayLogDO payLogDO, PayWalletDO payWalletDO) { public ResultBody handleGiveBackPledge(PayUavWalletVO payUavWalletVO, PayWalletDO userWalletInfo, PayLogDO payLogDO, PayWalletDO payWalletDO) {
payLogDO.setPayMethod(payUavWalletVO.getOrderStatus()); payLogDO.setPayMethod(payUavWalletVO.getOrderStatus());
payLogDO.setCashAmtPaid(payUavWalletVO.getCashAmount()); payLogDO.setCashAmtPaid(payUavWalletVO.getCashAmount());
payLogDO.setSalaryAmtPaid(payUavWalletVO.getSalaryAmount()); payLogDO.setSalaryAmtPaid(payUavWalletVO.getSalaryAmount());
......
...@@ -92,6 +92,15 @@ ...@@ -92,6 +92,15 @@
order by create_time desc order by create_time desc
LIMIT 1 LIMIT 1
</select> </select>
<select id="selectUserMessageTimeType" resultType="com.mmc.iuav.user.model.vo.MessageTimeVO">
select *
from user_message_time_type
where id = #{id}
</select>
<select id="listTimeType" resultType="com.mmc.iuav.user.model.vo.MessageTimeVO">
select *
from user_message_time_type
</select>
<insert id="insertSystemMessage"> <insert id="insertSystemMessage">
insert into message insert into message
...@@ -143,6 +152,19 @@ ...@@ -143,6 +152,19 @@
<if test="messageCount != null">#{messageCount,jdbcType=VARCHAR},</if> <if test="messageCount != null">#{messageCount,jdbcType=VARCHAR},</if>
</trim> </trim>
</insert> </insert>
<insert id="insertTimeType">
insert into user_message_time_type
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="money != null">money,</if>
<if test="points != null">points,</if>
<if test="chatDuration != null">chat_duration,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="money != null">#{money},</if>
<if test="points != null">#{points},</if>
<if test="chatDuration != null">#{chatDuration},</if>
</trim>
</insert>
<update id="removeMessage"> <update id="removeMessage">
update message update message
set is_deleted = 1, deleted_time = NOW() set is_deleted = 1, deleted_time = NOW()
...@@ -161,12 +183,14 @@ ...@@ -161,12 +183,14 @@
<update id="updateSystemMessage"> <update id="updateSystemMessage">
UPDATE message UPDATE message
<set> <set>
<if test="subject != null">subject,</if> <if test="subject != null">
<if test="content != null">content</if> subject = #{subject},
</if>
<if test="content != null">
content = #{content}
</if>
</set> </set>
<where> WHERE id = #{id}
id = #{id}
</where>
</update> </update>
<update id="removeUserMessage"> <update id="removeUserMessage">
update user_message update user_message
...@@ -192,5 +216,20 @@ ...@@ -192,5 +216,20 @@
message_count = message_count - 1 message_count = message_count - 1
where id = #{id} where id = #{id}
</update> </update>
<update id="updateTimeType">
update user_message_time_type
<set>
<if test="money != null">
money = #{money},
</if>
<if test="points != null">
points = #{points},
</if>
<if test="chatDuration != null">
chat_duration = #{chatDuration}
</if>
</set>
where id = #{id}
</update>
</mapper> </mapper>
...@@ -27,11 +27,35 @@ ...@@ -27,11 +27,35 @@
</set> </set>
where user_account_id = #{userAccountId} where user_account_id = #{userAccountId}
</update> </update>
<update id="updateBuyPointsType">
update user_message_time_type
<set>
<if test="money != null">
money = #{money},
</if>
<if test="points != null">
points = #{points},
</if>
create_time = NOW()
</set>
where id = #{id}
</update>
<insert id="insertPoints" parameterType="com.mmc.iuav.user.entity.userpoints.UserPointsDO"> <insert id="insertPoints" parameterType="com.mmc.iuav.user.entity.userpoints.UserPointsDO">
insert into user_points(total_points, user_account_id, create_time, insert into user_points(total_points, user_account_id, create_time,
update_time) update_time)
values (#{totalPoints}, #{userAccountId}, NOW(), NOW()) values (#{totalPoints}, #{userAccountId}, NOW(), NOW())
</insert> </insert>
<insert id="insertBuyPointsType">
insert into user_points_buy
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="money != null">money,</if>
<if test="points != null">points</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="money != null">#{money},</if>
<if test="points != null">#{points}</if>
</trim>
</insert>
<select id="userPointList" resultMap="pointList" parameterType="com.mmc.iuav.user.model.qo.userpoints.UserPointQO"> <select id="userPointList" resultMap="pointList" parameterType="com.mmc.iuav.user.model.qo.userpoints.UserPointQO">
SELECT up.id, SELECT up.id,
...@@ -66,6 +90,15 @@ ...@@ -66,6 +90,15 @@
and ua.nick_name like CONCAT("%",#{nickName},"%") and ua.nick_name like CONCAT("%",#{nickName},"%")
</if> </if>
</select> </select>
<select id="selectBuyPointsType" resultType="com.mmc.iuav.user.model.vo.BuyPointsVO">
select *
from user_points_buy
where id = #{id}
</select>
<select id="selectAllBuyPointsType" resultType="com.mmc.iuav.user.model.vo.BuyPointsVO">
select *
from user_points_buy
</select>
</mapper> </mapper>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论