diff --git a/src/main/java/com/gxwebsoft/booking/controller/PeriodController.java b/src/main/java/com/gxwebsoft/booking/controller/PeriodController.java index 570978a..b4aaa2c 100644 --- a/src/main/java/com/gxwebsoft/booking/controller/PeriodController.java +++ b/src/main/java/com/gxwebsoft/booking/controller/PeriodController.java @@ -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 orderInfoList = orderInfoService.list(new LambdaQueryWrapper().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().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()); diff --git a/src/main/java/com/gxwebsoft/cms/controller/WebsiteController.java b/src/main/java/com/gxwebsoft/cms/controller/WebsiteController.java index a995790..642f627 100644 --- a/src/main/java/com/gxwebsoft/cms/controller/WebsiteController.java +++ b/src/main/java/com/gxwebsoft/cms/controller/WebsiteController.java @@ -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().eq(Order::getPayStatus,0)) > 0) { + vo.setHasNoPayOrder(true); + } + } System.out.println("hour = " + hour); // DateUtil.between(DateUtil.date(), , DateUnit.DAY); diff --git a/src/main/java/com/gxwebsoft/cms/entity/ServerTimeVO.java b/src/main/java/com/gxwebsoft/cms/entity/ServerTimeVO.java index a3c43e8..d61d6ff 100644 --- a/src/main/java/com/gxwebsoft/cms/entity/ServerTimeVO.java +++ b/src/main/java/com/gxwebsoft/cms/entity/ServerTimeVO.java @@ -39,4 +39,7 @@ public class ServerTimeVO implements Serializable { @ApiModelProperty(value = "是否已过时间") private Integer isAfter; + @ApiModelProperty(value = "是否含有未支付订单") + private Boolean hasNoPayOrder; + } diff --git a/src/main/java/com/gxwebsoft/shop/controller/OrderController.java b/src/main/java/com/gxwebsoft/shop/controller/OrderController.java index f3360e3..7b6400a 100644 --- a/src/main/java/com/gxwebsoft/shop/controller/OrderController.java +++ b/src/main/java/com/gxwebsoft/shop/controller/OrderController.java @@ -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("删除订单") diff --git a/src/main/java/com/gxwebsoft/shop/controller/OrderTaskController.java b/src/main/java/com/gxwebsoft/shop/controller/OrderTaskController.java new file mode 100644 index 0000000..bc78e96 --- /dev/null +++ b/src/main/java/com/gxwebsoft/shop/controller/OrderTaskController.java @@ -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 list = orderMapper.selectExpirationOrder(p); + System.out.println("自动处理过期订单任务 = " + list); + list.forEach(d -> { + orderMapper.updateExpirationOrder(d.getOrderId()); + }); + } + +} diff --git a/src/main/java/com/gxwebsoft/shop/controller/WxPayNotifyController.java b/src/main/java/com/gxwebsoft/shop/controller/WxPayNotifyController.java index 850d0b7..a54a4fb 100644 --- a/src/main/java/com/gxwebsoft/shop/controller/WxPayNotifyController.java +++ b/src/main/java/com/gxwebsoft/shop/controller/WxPayNotifyController.java @@ -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"); diff --git a/src/main/java/com/gxwebsoft/shop/entity/Order.java b/src/main/java/com/gxwebsoft/shop/entity/Order.java index 811d1af..6f595ec 100644 --- a/src/main/java/com/gxwebsoft/shop/entity/Order.java +++ b/src/main/java/com/gxwebsoft/shop/entity/Order.java @@ -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; diff --git a/src/main/java/com/gxwebsoft/shop/mapper/OrderMapper.java b/src/main/java/com/gxwebsoft/shop/mapper/OrderMapper.java index 4593f45..cefaa6c 100644 --- a/src/main/java/com/gxwebsoft/shop/mapper/OrderMapper.java +++ b/src/main/java/com/gxwebsoft/shop/mapper/OrderMapper.java @@ -41,4 +41,10 @@ public interface OrderMapper extends BaseMapper { @InterceptorIgnore(tenantLine = "true") void updateByOutTradeNo(@Param("param") Order outTradeNo); + + @InterceptorIgnore(tenantLine = "true") + List selectExpirationOrder(@Param("param") OrderParam param); + + @InterceptorIgnore(tenantLine = "true") + void updateExpirationOrder(@Param("orderId") Integer orderId); } diff --git a/src/main/java/com/gxwebsoft/shop/mapper/xml/OrderMapper.xml b/src/main/java/com/gxwebsoft/shop/mapper/xml/OrderMapper.xml index 972f1dc..5e518df 100644 --- a/src/main/java/com/gxwebsoft/shop/mapper/xml/OrderMapper.xml +++ b/src/main/java/com/gxwebsoft/shop/mapper/xml/OrderMapper.xml @@ -110,6 +110,9 @@ AND a.refund_apply_time LIKE CONCAT('%', #{param.refundApplyTime}, '%') + + AND a.expiration_time <= #{param.expirationTime} + AND a.check_bill = #{param.checkBill} @@ -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} + + + + + + diff --git a/src/main/java/com/gxwebsoft/shop/param/OrderParam.java b/src/main/java/com/gxwebsoft/shop/param/OrderParam.java index d9a09c4..798318f 100644 --- a/src/main/java/com/gxwebsoft/shop/param/OrderParam.java +++ b/src/main/java/com/gxwebsoft/shop/param/OrderParam.java @@ -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; + } diff --git a/src/main/java/com/gxwebsoft/shop/service/impl/OrderServiceImpl.java b/src/main/java/com/gxwebsoft/shop/service/impl/OrderServiceImpl.java index 354736a..169d31c 100644 --- a/src/main/java/com/gxwebsoft/shop/service/impl/OrderServiceImpl.java +++ b/src/main/java/com/gxwebsoft/shop/service/impl/OrderServiceImpl.java @@ -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 implements final List orderInfoList = orderInfoService.list(new LambdaQueryWrapper().in(OrderInfo::getOrderId, orderIds)); final Map> 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 orderInfos = orderInfo.get(d.getOrderId()); if (!CollectionUtils.isEmpty(orderInfos)) { @@ -93,7 +99,13 @@ public class OrderServiceImpl extends ServiceImpl 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 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()); // 秘钥证书