自定取消过期订单
This commit is contained in:
@@ -20,6 +20,7 @@ import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.shop.entity.Order;
|
||||
import com.gxwebsoft.shop.entity.OrderInfo;
|
||||
import com.gxwebsoft.shop.service.OrderInfoService;
|
||||
import com.gxwebsoft.shop.service.OrderService;
|
||||
@@ -51,6 +52,8 @@ public class PeriodController extends BaseController {
|
||||
@Resource
|
||||
private OrderInfoService orderInfoService;
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@ApiOperation("分页查询场地时段")
|
||||
@@ -88,6 +91,15 @@ public class PeriodController extends BaseController {
|
||||
List<OrderInfo> orderInfoList = orderInfoService.list(new LambdaQueryWrapper<OrderInfo>().eq(OrderInfo::getDateTime, param.getDateTime()).eq(OrderInfo::getMerchantId,param.getMerchantId()).gt(OrderInfo::getExpirationTime, LocalDateTime.now()));
|
||||
collectKey = orderInfoList.stream().collect(Collectors.groupingBy(OrderInfo::getOrderCode));
|
||||
|
||||
// 查询是否含有未支付订单
|
||||
final User loginUser = getLoginUser();
|
||||
if(loginUser != null){
|
||||
if (orderService.count(new LambdaQueryWrapper<Order>().eq(Order::getPayStatus,0).eq(Order::getOrderStatus,0).eq(Order::getUserId,loginUser.getUserId())) > 0) {
|
||||
return fail("您还有未支付订单,请先支付",null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final FieldParam fieldParam = new FieldParam();
|
||||
fieldParam.setIsStatus(param.getIsStatus());
|
||||
fieldParam.setMerchantId(param.getMerchantId());
|
||||
|
||||
@@ -20,8 +20,10 @@ import com.gxwebsoft.oa.param.LinkParam;
|
||||
import com.gxwebsoft.oa.service.LinkService;
|
||||
import com.gxwebsoft.shop.entity.Merchant;
|
||||
import com.gxwebsoft.shop.entity.MerchantAccount;
|
||||
import com.gxwebsoft.shop.entity.Order;
|
||||
import com.gxwebsoft.shop.service.MerchantAccountService;
|
||||
import com.gxwebsoft.shop.service.MerchantService;
|
||||
import com.gxwebsoft.shop.service.OrderService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
@@ -76,6 +78,8 @@ public class WebsiteController extends BaseController {
|
||||
private MerchantAccountService merchantAccountService;
|
||||
@Resource
|
||||
private MpMenuService mpMenuService;
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
|
||||
@ApiOperation("获取网站信息")
|
||||
@GetMapping("/getSiteInfo")
|
||||
@@ -313,7 +317,13 @@ public class WebsiteController extends BaseController {
|
||||
vo.setHourMinute(String.format("%02d", hour).concat(String.format("%02d", minute)));
|
||||
final int compare = Integer.compare(Integer.valueOf(vo.getHourMinute()), 900);
|
||||
vo.setIsAfter(compare);
|
||||
// vo.setHourMinute(String.valueOf(hour).concat(String.valueOf(minute)));
|
||||
|
||||
final User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
if (orderService.count(new LambdaQueryWrapper<Order>().eq(Order::getPayStatus,0)) > 0) {
|
||||
vo.setHasNoPayOrder(true);
|
||||
}
|
||||
}
|
||||
System.out.println("hour = " + hour);
|
||||
// DateUtil.between(DateUtil.date(), , DateUnit.DAY);
|
||||
|
||||
|
||||
@@ -39,4 +39,7 @@ public class ServerTimeVO implements Serializable {
|
||||
@ApiModelProperty(value = "是否已过时间")
|
||||
private Integer isAfter;
|
||||
|
||||
@ApiModelProperty(value = "是否含有未支付订单")
|
||||
private Boolean hasNoPayOrder;
|
||||
|
||||
}
|
||||
|
||||
@@ -87,7 +87,18 @@ public class OrderController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
// 订单信息
|
||||
// 已下过订单
|
||||
if(order.getOrderId() != null){
|
||||
Order order1 = orderService.getByIdRel(order.getOrderId());
|
||||
order1.setOpenid(loginUser.getOpenid());
|
||||
System.out.println("已下过订单 = " + order1);
|
||||
// 微信统一下单接口
|
||||
if (order.getPayType().equals(1)) {
|
||||
return success("下单成功", orderService.createWxOrder(order1));
|
||||
}
|
||||
}
|
||||
|
||||
// 创建订单
|
||||
long timeMillis = System.currentTimeMillis();
|
||||
long orderNo = IdUtil.getSnowflakeNextId();
|
||||
order.setOrderNo(Long.toString(orderNo));
|
||||
@@ -101,7 +112,6 @@ public class OrderController extends BaseController {
|
||||
// OrderInfo orderInfo = order.getOrderInfoList().get(0);
|
||||
// order.setStartTime(DateUtil.formatTime(orderInfo.getStartTime()));
|
||||
// order.setVersion(10);
|
||||
System.out.println("order = " + order);
|
||||
if (orderService.save(order)) {
|
||||
order.getOrderInfoList().forEach(d -> {
|
||||
d.setOrderId(order.getOrderId());
|
||||
@@ -112,7 +122,7 @@ public class OrderController extends BaseController {
|
||||
d.setExpirationTime(order.getExpirationTime());
|
||||
});
|
||||
orderInfoService.saveBatch(order.getOrderInfoList());
|
||||
// 创建微信订单
|
||||
// 微信统一下单接口
|
||||
if (order.getPayType().equals(1)) {
|
||||
return success("下单成功", orderService.createWxOrder(order));
|
||||
}
|
||||
@@ -124,9 +134,9 @@ public class OrderController extends BaseController {
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Order order) {
|
||||
if (orderService.updateById(order)) {
|
||||
return success("修改成功");
|
||||
return success("操作成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
return fail("操作失败");
|
||||
}
|
||||
|
||||
@ApiOperation("删除订单")
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.gxwebsoft.shop.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.shop.entity.Order;
|
||||
import com.gxwebsoft.shop.mapper.OrderMapper;
|
||||
import com.gxwebsoft.shop.param.OrderParam;
|
||||
import com.gxwebsoft.shop.service.OrderInfoService;
|
||||
import com.gxwebsoft.shop.service.OrderService;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单结算任务
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-05-14 13:20:04
|
||||
*/
|
||||
@Api(tags = "订单结算任务")
|
||||
@RestController
|
||||
@RequestMapping("/api/shop/order")
|
||||
public class OrderTaskController extends BaseController {
|
||||
@Resource
|
||||
private OrderMapper orderMapper;
|
||||
@Resource
|
||||
private OrderInfoService orderInfoService;
|
||||
/**
|
||||
* 自动处理过期订单任务
|
||||
*/
|
||||
@Scheduled(fixedDelay = 2000, initialDelay = 2000)
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public void settledUserPlanLog() {
|
||||
final OrderParam p = new OrderParam();
|
||||
p.setOrderStatus(0);
|
||||
p.setExpirationTime(DateUtil.date());
|
||||
System.out.println("p = " + p);
|
||||
final List<Order> list = orderMapper.selectExpirationOrder(p);
|
||||
System.out.println("自动处理过期订单任务 = " + list);
|
||||
list.forEach(d -> {
|
||||
orderMapper.updateExpirationOrder(d.getOrderId());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -107,7 +107,7 @@ public class WxPayNotifyController extends BaseController {
|
||||
if (order.getPayStatus().equals(false)) {
|
||||
// 5. TODO 处理订单状态
|
||||
order.setPayTime(DateUtil.date());
|
||||
order.setPayStatus(true);
|
||||
order.setPayStatus(1);
|
||||
order.setTransactionId(transactionId);
|
||||
// 实际付款金额:Integer除以100后转BigDecimal
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
|
||||
@@ -102,7 +102,7 @@ public class Order implements Serializable {
|
||||
private Integer payType;
|
||||
|
||||
@ApiModelProperty(value = "0未付款,1已付款")
|
||||
private Boolean payStatus;
|
||||
private Integer payStatus;
|
||||
|
||||
@ApiModelProperty(value = "0未使用,1已完成,2已取消,3取消中,4退款申请中,5退款被拒绝,6退款成功,7客户端申请退款")
|
||||
private Integer orderStatus;
|
||||
@@ -140,6 +140,10 @@ public class Order implements Serializable {
|
||||
@ApiModelProperty(value = "订单过期时间")
|
||||
private Date expirationTime;
|
||||
|
||||
@ApiModelProperty(value = "剩余时间戳")
|
||||
@TableField(exist = false)
|
||||
private Long timestamp;
|
||||
|
||||
@ApiModelProperty(value = "对账情况:0=未对账;1=已对账;3=已对账,金额对不上;4=未查询到该订单")
|
||||
private Integer checkBill;
|
||||
|
||||
|
||||
@@ -41,4 +41,10 @@ public interface OrderMapper extends BaseMapper<Order> {
|
||||
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
void updateByOutTradeNo(@Param("param") Order outTradeNo);
|
||||
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
List<Order> selectExpirationOrder(@Param("param") OrderParam param);
|
||||
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
void updateExpirationOrder(@Param("orderId") Integer orderId);
|
||||
}
|
||||
|
||||
@@ -110,6 +110,9 @@
|
||||
<if test="param.refundApplyTime != null">
|
||||
AND a.refund_apply_time LIKE CONCAT('%', #{param.refundApplyTime}, '%')
|
||||
</if>
|
||||
<if test="param.expirationTime != null">
|
||||
AND a.expiration_time <= #{param.expirationTime}
|
||||
</if>
|
||||
<if test="param.checkBill != null">
|
||||
AND a.check_bill = #{param.checkBill}
|
||||
</if>
|
||||
@@ -172,4 +175,14 @@
|
||||
UPDATE shop_order SET pay_status = #{param.payStatus}, pay_time = #{param.payTime}, pay_price = #{param.payPrice}, transaction_id = #{param.transactionId} WHERE order_no = #{param.orderNo}
|
||||
</select>
|
||||
|
||||
<!-- 查询过期订单 -->
|
||||
<select id="selectExpirationOrder" resultType="com.gxwebsoft.shop.entity.Order">
|
||||
SELECT * from shop_order where pay_status = 0 AND order_status = 0 AND expiration_time <= #{param.expirationTime}
|
||||
</select>
|
||||
|
||||
<!-- 更明过期订单的状态 -->
|
||||
<select id="updateExpirationOrder" resultType="com.gxwebsoft.shop.entity.Order">
|
||||
UPDATE shop_order SET order_status = 2 WHERE order_id = #{orderId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.gxwebsoft.shop.param;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
import com.gxwebsoft.common.core.annotation.QueryField;
|
||||
import com.gxwebsoft.common.core.annotation.QueryType;
|
||||
import com.gxwebsoft.common.core.web.BaseParam;
|
||||
@@ -174,4 +176,11 @@ public class OrderParam extends BaseParam {
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer deleted;
|
||||
|
||||
@ApiModelProperty(value = "下单时间")
|
||||
private Date createTime;
|
||||
|
||||
@ApiModelProperty(value = "当前时间")
|
||||
@QueryField(type = QueryType.GT)
|
||||
private Date expirationTime;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.gxwebsoft.shop.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
@@ -10,6 +12,7 @@ import com.gxwebsoft.common.system.service.SettingService;
|
||||
import com.gxwebsoft.shop.entity.OrderInfo;
|
||||
import com.gxwebsoft.shop.entity.Payment;
|
||||
import com.gxwebsoft.shop.mapper.OrderMapper;
|
||||
import com.gxwebsoft.shop.param.OrderInfoParam;
|
||||
import com.gxwebsoft.shop.service.OrderInfoService;
|
||||
import com.gxwebsoft.shop.service.OrderService;
|
||||
import com.gxwebsoft.shop.entity.Order;
|
||||
@@ -69,6 +72,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
final List<OrderInfo> orderInfoList = orderInfoService.list(new LambdaQueryWrapper<OrderInfo>().in(OrderInfo::getOrderId, orderIds));
|
||||
final Map<Integer, List<OrderInfo>> orderInfo = orderInfoList.stream().collect(Collectors.groupingBy(OrderInfo::getOrderId));
|
||||
list.forEach(d -> {
|
||||
final DateTime date = DateUtil.date(d.getExpirationTime());
|
||||
final DateTime now = DateUtil.date();
|
||||
d.setTimestamp(date.getTime() - now.getTime());
|
||||
if (!orderInfo.isEmpty()) {
|
||||
final List<OrderInfo> orderInfos = orderInfo.get(d.getOrderId());
|
||||
if (!CollectionUtils.isEmpty(orderInfos)) {
|
||||
@@ -93,7 +99,13 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
public Order getByIdRel(Integer orderId) {
|
||||
OrderParam param = new OrderParam();
|
||||
param.setOrderId(orderId);
|
||||
return param.getOne(baseMapper.selectListRel(param));
|
||||
Order order = param.getOne(baseMapper.selectListRel(param));
|
||||
if(order != null){
|
||||
final OrderInfoParam orderInfoParam = new OrderInfoParam();
|
||||
orderInfoParam.setOrderId(orderId);
|
||||
order.setOrderInfoList(orderInfoService.listRel(orderInfoParam));
|
||||
}
|
||||
return order;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,7 +125,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
|
||||
// 计算金额
|
||||
BigDecimal decimal = order.getTotalPrice();
|
||||
final BigDecimal multiply = decimal.multiply(new BigDecimal(100));
|
||||
final BigDecimal multiply = decimal.multiply(new BigDecimal(10));
|
||||
// 将 BigDecimal 转换为 Integer
|
||||
Integer money = multiply.intValue();
|
||||
String privateKey = uploadPath.concat("/file").concat(payment.getApiclientKey()); // 秘钥证书
|
||||
|
||||
Reference in New Issue
Block a user