app后台----下订单--未完成.
This commit is contained in:
parent
c17dbf7025
commit
183be624de
@ -6,6 +6,7 @@ import com.ruoyi.common.core.redis.RedisCache;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.MessageUtils;
|
||||
import com.ruoyi.common.utils.uuid.IdUtils;
|
||||
import com.ruoyi.common.utils.uuid.UUID;
|
||||
import com.ruoyi.framework.manager.AsyncManager;
|
||||
import com.ruoyi.framework.manager.factory.AsyncFactory;
|
||||
import com.ruoyi.system.domain.*;
|
||||
@ -22,6 +23,8 @@ import com.ruoyi.framework.web.service.SysLoginService;
|
||||
import com.ruoyi.framework.web.service.SysRegisterService;
|
||||
//import com.ruoyi.system.domain.UserWork;
|
||||
import com.ruoyi.system.domain.dto.*;
|
||||
import com.ruoyi.system.domain.vo.OrderCacheVo;
|
||||
import com.ruoyi.system.domain.vo.SourcePriceVo;
|
||||
import com.ruoyi.system.domain.vo.UserMessageVo;
|
||||
import com.ruoyi.system.service.*;
|
||||
import com.ruoyi.framework.web.service.TokenService;
|
||||
@ -39,9 +42,10 @@ import static com.ruoyi.common.core.domain.AjaxResult.success;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/app/system")
|
||||
@ -783,7 +787,9 @@ public class AppSystemController {
|
||||
|
||||
System.out.println(orderIdList);
|
||||
|
||||
boolean back = payService.genOrder(orderIdList, totalPrice, userId);
|
||||
// 旧版本接口
|
||||
// boolean back = payService.genOrder(orderIdList, totalPrice, userId);
|
||||
boolean back = true;
|
||||
|
||||
if(back){
|
||||
return success("支付成功");
|
||||
@ -877,6 +883,174 @@ public class AppSystemController {
|
||||
|
||||
}
|
||||
|
||||
// 发布用户作品-------新版
|
||||
@Transactional
|
||||
@PostMapping("/publishUserWorkNew")
|
||||
public AjaxResult publishUserWorkNew(@RequestBody List<PublishUserWorkDto> publishUserWorkDtoList)
|
||||
{
|
||||
// 获取用户id
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
|
||||
// 订单总价
|
||||
Double tPrice = 0.0;
|
||||
|
||||
// 订单信息缓存
|
||||
List<OrderCacheVo> orderCacheVoList = new ArrayList<>();
|
||||
|
||||
|
||||
|
||||
// 获取订单数据
|
||||
for(PublishUserWorkDto publishUserWorkDto:publishUserWorkDtoList){
|
||||
|
||||
Long sourceId = publishUserWorkDto.getSourceId();
|
||||
Long workId = publishUserWorkDto.getWorkId();
|
||||
|
||||
Long day = publishUserWorkDto.getDay();
|
||||
|
||||
// //-----------------------------测试注释内容-------------------------------------
|
||||
// // 查看 work 是否属于这个人
|
||||
// UserWork userWork = userWorkService.selectUserWorkByWorkId(workId);
|
||||
// if(userWork == null || userWork.getUserId() != userId){
|
||||
// return error("用户与作品不符, 已记录ip");
|
||||
// }
|
||||
// //----------------------------测试注释内容---------------------------------------
|
||||
|
||||
|
||||
LocalDate startTime = publishUserWorkDto.getStartTime();
|
||||
LocalDate endTime = startTime;
|
||||
|
||||
// 根据资源位查看价格和时间
|
||||
|
||||
SysSource sysSource = sysSourceService.selectSysSourceBySourceId(sourceId);
|
||||
|
||||
// 解析价格数据------这里不知道为什么默认是Double类型的??
|
||||
List<Map<String, Double>> list = GsonUtils.fromJson(sysSource.getPrice(), List.class);
|
||||
|
||||
// 价格匹配标志量
|
||||
boolean flag = true;
|
||||
|
||||
for(Map<String, Double> map : list){
|
||||
|
||||
Double days = map.get("days");
|
||||
if(days==day.doubleValue()){
|
||||
System.out.println("就是这个天: "+ day);
|
||||
flag = false;
|
||||
// 加上价格
|
||||
tPrice += map.get("price");
|
||||
// 结束时间
|
||||
endTime = startTime.plusDays(days.intValue()-1);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(flag){
|
||||
return error("输入天数数据错误");
|
||||
}
|
||||
|
||||
// 检查时间是否合法, 从订单中查询当前资源位的订单时间, 每个资源位一年最多有 366条数据
|
||||
// 要不直接查资源位的起止时间??-------并不能这样做-----一个资源位可以购买多个时间段---一个数据根本存不下.
|
||||
// 所以只能通过订单的时间来查询时间是否合法.--这里默认一个订单只有一个时间(即使一个订单对应多个资源位)
|
||||
int back = sysOrderService.isTimeLegal(startTime, endTime, sourceId);
|
||||
|
||||
// 这里也要检查redis缓存中的时间是否合法 --sourceId + startTime + endTime 这三元组就行.
|
||||
|
||||
if(back > 0){
|
||||
return error("购买时间不合法:" + startTime + "至" + endTime);
|
||||
}
|
||||
|
||||
//-----------------------------------------方案1通过redis缓存确保订单不会冲突-------------------------------------
|
||||
// 缓存中查看订单是否合法
|
||||
// 1. 查看缓存中是否存在键值----------键为order_{source_id}, 值为 [startTime, endTime]
|
||||
if(redisCache.hasKey("order_"+sourceId)){// 有缓存key
|
||||
|
||||
List<List<String>> value = redisCache.getCacheObject("order_"+sourceId);
|
||||
|
||||
System.out.println("缓存中存在键值: order_"+value);
|
||||
|
||||
for(List<String> tList : value){
|
||||
|
||||
// 字符串型的 日期
|
||||
String sStartTime = tList.get(0);
|
||||
String sEndTime = tList.get(1);
|
||||
|
||||
// 日期格式化
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
// 获取起止时间
|
||||
LocalDate tStartTime = LocalDate.parse(sStartTime, formatter);
|
||||
LocalDate tEndTime = LocalDate.parse(sEndTime, formatter);
|
||||
|
||||
// 判断时间是否合法
|
||||
if(endTime.isAfter(tStartTime) && startTime.isBefore(tEndTime)){
|
||||
return error("购买时间不合法:" + startTime + "至" + endTime);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
List<String> tList = new ArrayList<>();
|
||||
tList.add(startTime.toString());
|
||||
tList.add(endTime.toString());
|
||||
value.add(tList);
|
||||
|
||||
// 写入缓存--更新缓存时间
|
||||
redisCache.setCacheObject("order_"+sourceId, value, 5, TimeUnit.MINUTES);
|
||||
|
||||
}
|
||||
else{ // 无缓存key, 通过了订单的时间校验就能直接生成订单了, 先写入缓存, 5分钟有效期----订单支付有效期也为5分钟
|
||||
|
||||
|
||||
// 缓存中默认都是字符串, 使用时需要转换
|
||||
List<List<String>> value = new ArrayList<>();
|
||||
List<String> tList = new ArrayList<>();
|
||||
tList.add(startTime.toString());
|
||||
tList.add(endTime.toString());
|
||||
value.add(tList);
|
||||
|
||||
// 写入缓存
|
||||
redisCache.setCacheObject("order_"+sourceId, value, 5, TimeUnit.MINUTES);
|
||||
|
||||
}
|
||||
|
||||
OrderCacheVo orderCacheVo = new OrderCacheVo();
|
||||
orderCacheVo.setEndTime(endTime);
|
||||
orderCacheVo.setMoney(tPrice.longValue());
|
||||
orderCacheVo.setSourceId(sourceId);
|
||||
orderCacheVo.setStartTime(startTime);
|
||||
orderCacheVo.setUserId(userId);
|
||||
orderCacheVo.setWay("微信支付");
|
||||
|
||||
orderCacheVoList.add(orderCacheVo);
|
||||
|
||||
|
||||
//-------------------------------------------------方案1 end----------------------------------------------------------
|
||||
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------订单相关---------------------------------------------------------
|
||||
|
||||
// 直接在这生成订单就行了
|
||||
|
||||
// 订单号, 自己生成,用来标识这一次支付.
|
||||
String mchOrderNo = "M" + UUID.randomUUID().toString().replaceAll("-", "");
|
||||
|
||||
// 缓存订单和用户关系, 为了回调函数中写入订单数据库
|
||||
System.out.println("mchOrderNo: " + mchOrderNo);
|
||||
|
||||
|
||||
|
||||
//------------------------------------------------------订单相关----------------------------------------------------------
|
||||
|
||||
// 将订单信息写入缓存--超时时间稍微比订单时间长1分钟吧
|
||||
redisCache.setCacheObject(mchOrderNo, orderCacheVoList, 6, TimeUnit.MINUTES);
|
||||
|
||||
System.out.println("总价格:"+ tPrice);
|
||||
|
||||
return AjaxResult.success(mchOrderNo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 新增关注
|
||||
@GetMapping("/addFollower/{followedUserId}")
|
||||
@Transactional
|
||||
|
||||
@ -3,6 +3,8 @@ package com.ruoyi.web.controller.app.pay;
|
||||
|
||||
import com.jeequan.jeepay.util.JeepayKit;
|
||||
import com.ruoyi.common.core.redis.RedisCache;
|
||||
import com.ruoyi.system.domain.vo.OrderCacheVo;
|
||||
import com.ruoyi.web.controller.app.baidu.GsonUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@ -12,37 +14,50 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/wxPay/result")
|
||||
@RequestMapping("/wxPay")
|
||||
public class PayBackController {
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
@Transactional
|
||||
@PostMapping("/wxRechargeCallback/{result}")
|
||||
public String wxRechargeCallback(HttpServletRequest req, @PathVariable String type){
|
||||
@PostMapping("/wxRechargeCallback/{mchOrderNo}")
|
||||
public String wxRechargeCallback(HttpServletRequest req, @PathVariable String mchOrderNo){
|
||||
|
||||
String result = "failure";
|
||||
try {
|
||||
Map<String, Object> map = getParamsMap(req);
|
||||
//获取私钥
|
||||
String apikey = "";
|
||||
//验签
|
||||
if (chackSgin(map, apikey)) {
|
||||
return result;
|
||||
}
|
||||
//订单号
|
||||
String orderNumber = map.get("mchOrderNo").toString();
|
||||
String cacheObject = redisCache.getCacheObject(orderNumber);
|
||||
}
|
||||
catch (Exception e){
|
||||
return result;
|
||||
}
|
||||
// //--------------------------------------------旧版--------------------------------------------
|
||||
// String result = "failure";
|
||||
// try {
|
||||
// Map<String, Object> map = getParamsMap(req);
|
||||
// //获取私钥
|
||||
// String apikey = "";
|
||||
// //验签
|
||||
// if (chackSgin(map, apikey)) {
|
||||
// return result;
|
||||
// }
|
||||
// //订单号
|
||||
// String orderNumber = map.get("mchOrderNo").toString();
|
||||
// String cacheObject = redisCache.getCacheObject(orderNumber);
|
||||
// }
|
||||
// catch (Exception e){
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// return result;
|
||||
// //-------------------------------------------旧版end----------------------------------------------
|
||||
|
||||
return result;
|
||||
// 获取缓存中的订单信息
|
||||
List<OrderCacheVo> list = redisCache.getCacheObject(mchOrderNo);
|
||||
for(OrderCacheVo orderCacheVo:list){
|
||||
// System.out.println(orderCacheVo);
|
||||
|
||||
}
|
||||
System.out.println(list);
|
||||
|
||||
return "";
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -46,7 +46,8 @@ public class PayService {
|
||||
|
||||
|
||||
|
||||
public boolean genOrder(List<Long> orderIdList, Long Price, Long userId) {
|
||||
// 生成订单--------将订单数据保存在redis缓存中----缓存时间为10分钟吧
|
||||
public boolean genOrder(double price) {
|
||||
|
||||
|
||||
|
||||
@ -55,22 +56,13 @@ public class PayService {
|
||||
// 订单号, 自己生成,用来标识这一次支付.
|
||||
String mchOrderNo = "M" + UUID.randomUUID().toString().replaceAll("-", "");
|
||||
|
||||
// 将订单号以字符串拼接
|
||||
String result = orderIdList.stream()
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.joining("_"));
|
||||
|
||||
System.out.println("订单id: "+result);
|
||||
|
||||
// 缓存订单和用户关系,
|
||||
// 这里值应该是 orderIdList + Price + userId
|
||||
System.out.println("userId"+userId);
|
||||
// 缓存订单和用户关系, 为了回调函数中写入订单数据库
|
||||
System.out.println("mchOrderNo: " + mchOrderNo);
|
||||
System.out.println(redisCache);
|
||||
System.out.println("result: "+result);
|
||||
// System.out.println(redisCache);
|
||||
|
||||
redisCache.setCacheObject(mchOrderNo, userId.toString() + "_" + result, 1, TimeUnit.DAYS);
|
||||
System.out.println(redisCache.getCacheObject(mchOrderNo).toString());
|
||||
|
||||
// redisCache.setCacheObject(mchOrderNo, userId.toString() + "_" + result, 1, TimeUnit.DAYS);
|
||||
// System.out.println(redisCache.getCacheObject(mchOrderNo).toString());
|
||||
// log.info("缓存订单和用户关系: mchOrderNo=" + mchOrderNo + ", userId=" + userId);
|
||||
|
||||
|
||||
|
||||
@ -10,6 +10,8 @@ public class PublishUserWorkDto {
|
||||
private String type;
|
||||
private LocalDate startTime;
|
||||
|
||||
private Long day;
|
||||
|
||||
public Long getWorkId() {
|
||||
return workId;
|
||||
}
|
||||
@ -35,4 +37,14 @@ public class PublishUserWorkDto {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
public Long getDay() {
|
||||
return day;
|
||||
}
|
||||
|
||||
public void setDay(Long day) {
|
||||
this.day = day;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,62 @@
|
||||
package com.ruoyi.system.domain.vo;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class OrderCacheVo {
|
||||
|
||||
private Long source_id;
|
||||
private Long user_id;
|
||||
private LocalDate startTime;
|
||||
private LocalDate endTime;
|
||||
private String way;
|
||||
private Long money;
|
||||
|
||||
public Long getSourceId() {
|
||||
return source_id;
|
||||
}
|
||||
|
||||
public void setSourceId(Long source_id) {
|
||||
this.source_id = source_id;
|
||||
}
|
||||
|
||||
public Long getUserId() {
|
||||
return user_id;
|
||||
}
|
||||
|
||||
public void setUserId(Long user_id) {
|
||||
this.user_id = user_id;
|
||||
}
|
||||
|
||||
public LocalDate getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(LocalDate startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
public LocalDate getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public void setEndTime(LocalDate endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
public String getWay() {
|
||||
return way;
|
||||
}
|
||||
|
||||
public void setWay(String way) {
|
||||
this.way = way;
|
||||
}
|
||||
|
||||
public Long getMoney() {
|
||||
return money;
|
||||
}
|
||||
|
||||
public void setMoney(Long money) {
|
||||
this.money = money;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user