|
|
@@ -12,6 +12,7 @@ import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
import com.cyksj.mapper.GoodsDonSkuMapper;
|
|
|
import com.cyksj.mapper.OrderDonMapper;
|
|
|
+import com.cyksj.mapper.RegisterOrderDonMapper;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.views.*;
|
|
|
import com.cyksj.redis.RedisService;
|
|
|
@@ -40,11 +41,13 @@ import java.util.Optional;
|
|
|
public class GoodsDonController {
|
|
|
|
|
|
private final HttpServletRequest request;
|
|
|
-
|
|
|
+
|
|
|
private final BeanSearcher beanSearcher;
|
|
|
|
|
|
private final OrderDonMapper orderDonMapper;
|
|
|
|
|
|
+ private final RegisterOrderDonMapper registerOrderDonMapper;
|
|
|
+
|
|
|
private final GoodsDonSkuMapper goodsDonSkuMapper;
|
|
|
|
|
|
private final RedisService redisService;
|
|
|
@@ -185,35 +188,7 @@ public class GoodsDonController {
|
|
|
.notIn(OrderDon::getStatus, Constant.noOrderStatus).select(OrderDon::getCreatedTime, OrderDon::getPayTime, OrderDon::getId)
|
|
|
.orderByDesc(OrderDon::getId)
|
|
|
.last("limit 1"));
|
|
|
- StringBuilder notifyMsg = new StringBuilder();
|
|
|
- if (orderDon == null) {
|
|
|
- notifyMsg.append("点击购买立即上车");
|
|
|
- data.setNotifyMsg(notifyMsg.toString());
|
|
|
- return;
|
|
|
- } else {
|
|
|
- Date payTime = orderDon.getPayTime();
|
|
|
- Date startTime = payTime != null ? payTime : orderDon.getCreatedTime();
|
|
|
- long hour = DateUtil.between(startTime, now, DateUnit.HOUR);
|
|
|
- if (hour == 0) {
|
|
|
- long minute = DateUtil.between(startTime, now, DateUnit.MINUTE);
|
|
|
- if (minute == 0) {
|
|
|
- notifyMsg.append("1分钟");
|
|
|
- } else {
|
|
|
- notifyMsg.append(minute);
|
|
|
- notifyMsg.append("分钟");
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (hour > 3) {
|
|
|
- int hours = RandomUtil.randomInt(3) + 1;
|
|
|
- notifyMsg.append(hours);
|
|
|
- } else {
|
|
|
- notifyMsg.append(hour);
|
|
|
- }
|
|
|
- notifyMsg.append("小时");
|
|
|
- }
|
|
|
- }
|
|
|
- notifyMsg.append("前有人购买");
|
|
|
- data.setNotifyMsg(notifyMsg.toString());
|
|
|
+ data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1));
|
|
|
});
|
|
|
redisService.setNx(RedisService.key.PC_WEB_CACHE.getName(), list, RedisService.key.PC_WEB_CACHE.getTimeout());
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(list);
|
|
|
@@ -268,6 +243,13 @@ public class GoodsDonController {
|
|
|
}
|
|
|
MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
|
|
|
List<RegisterGoodsDonView> dataList = beanSearcher.searchAll(RegisterGoodsDonView.class, builder.build());
|
|
|
+ DateTime now = DateTime.now();
|
|
|
+ dataList.forEach(data->{
|
|
|
+ Integer sold = registerOrderDonMapper.selectCount(Wrappers.lambdaQuery(RegisterOrderDon.class)
|
|
|
+ .eq(RegisterOrderDon::getGoodsId, data.getId()).notIn(RegisterOrderDon::getStatus, Constant.noOrderStatus));
|
|
|
+ data.setSold(sold + data.getVirtualSold());
|
|
|
+ data.setNotifyMsg(getPayMsgTime(data.getId(), now, 2));
|
|
|
+ });
|
|
|
redisService.setNx(registerCacheKey, dataList, RedisService.key.REGISTER_HOME_PAGE_CACHE.getTimeout());
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(dataList);
|
|
|
}
|
|
|
@@ -316,4 +298,57 @@ public class GoodsDonController {
|
|
|
.build());
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param goodsId
|
|
|
+ * @param type 1、普通,2、注册平台
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getPayMsgTime(Long goodsId, DateTime now, Integer type) {
|
|
|
+ Date startTime = null;
|
|
|
+ StringBuilder notifyMsg = new StringBuilder();
|
|
|
+ if (type == 1) {
|
|
|
+ OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
+ .eq(OrderDon::getGoodsId, goodsId)
|
|
|
+ .notIn(OrderDon::getStatus, Constant.noOrderStatus).select(OrderDon::getCreatedTime, OrderDon::getPayTime, OrderDon::getId)
|
|
|
+ .orderByDesc(OrderDon::getId)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (orderDon == null) {
|
|
|
+ notifyMsg.append("点击购买立即上车");
|
|
|
+ return notifyMsg.toString();
|
|
|
+ }
|
|
|
+ startTime = orderDon.getPayTime() != null ? orderDon.getPayTime() : orderDon.getCreatedTime();
|
|
|
+ } else if (type == 2) {
|
|
|
+ RegisterOrderDon orderDon = registerOrderDonMapper.selectOne(Wrappers.lambdaQuery(RegisterOrderDon.class)
|
|
|
+ .eq(RegisterOrderDon::getGoodsId, goodsId)
|
|
|
+ .notIn(RegisterOrderDon::getStatus, Constant.noOrderStatus).select(RegisterOrderDon::getCreatedTime, RegisterOrderDon::getPayTime, RegisterOrderDon::getId)
|
|
|
+ .orderByDesc(RegisterOrderDon::getId)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (orderDon == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ startTime = orderDon.getPayTime() != null ? orderDon.getPayTime() : orderDon.getCreatedTime();
|
|
|
+ }
|
|
|
+ long hour = DateUtil.between(startTime, now, DateUnit.HOUR);
|
|
|
+ if (hour == 0) {
|
|
|
+ long minute = DateUtil.between(startTime, now, DateUnit.MINUTE);
|
|
|
+ if (minute == 0) {
|
|
|
+ notifyMsg.append("1分钟");
|
|
|
+ } else {
|
|
|
+ notifyMsg.append(minute);
|
|
|
+ notifyMsg.append("分钟");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (hour > 3) {
|
|
|
+ int hours = RandomUtil.randomInt(3) + 1;
|
|
|
+ notifyMsg.append(hours);
|
|
|
+ } else {
|
|
|
+ notifyMsg.append(hour);
|
|
|
+ }
|
|
|
+ notifyMsg.append("小时");
|
|
|
+ }
|
|
|
+ notifyMsg.append("前有人购买");
|
|
|
+ return notifyMsg.toString();
|
|
|
+ }
|
|
|
}
|