|
|
@@ -15,8 +15,8 @@ import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
import com.cyksj.mapper.GoodsDonSkuMapper;
|
|
|
import com.cyksj.mapper.OrderDonMapper;
|
|
|
-import com.cyksj.mapper.SysConfigMapper;
|
|
|
import com.cyksj.mapper.RegisterOrderDonMapper;
|
|
|
+import com.cyksj.mapper.SysConfigMapper;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.views.*;
|
|
|
import com.cyksj.redis.RedisService;
|
|
|
@@ -165,6 +165,10 @@ public class GoodsDonController {
|
|
|
if (value != null) {
|
|
|
try {
|
|
|
List<GoodsFrontListView> list = Jsons.parseObject(value, List.class);
|
|
|
+ list.forEach(data->{
|
|
|
+ //销量
|
|
|
+ data.setSold(data.getVirtualSold() + getSoldNumByGid(data.getId(), 1));;
|
|
|
+ });
|
|
|
if (CollUtil.isNotEmpty(list)) {
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(list);
|
|
|
}
|
|
|
@@ -180,9 +184,8 @@ public class GoodsDonController {
|
|
|
list.forEach(data -> {
|
|
|
data.setSpecs(beanSearcher.searchFirst(GoodsDonSpec.class, MapUtils.builder().field(GoodsDonSpec::getGoodsId, data.getId()).build()));
|
|
|
data.setSkuList(beanSearcher.searchAll(GoodsDonFrontSkuView.class, MapUtils.builder().field(GoodsDonFrontSkuView::getGoodsId, data.getId()).field(GoodsDonFrontSkuView::getStatus, true).orderBy(GoodsDonFrontSkuView::getPrice).asc().build()));
|
|
|
- Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
- .eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
|
|
|
- data.setSold(sold + data.getVirtualSold());
|
|
|
+ //销量
|
|
|
+ data.setSold(data.getVirtualSold() + getSoldNumByGid(data.getId(), 1));;
|
|
|
|
|
|
Optional.ofNullable(data.getSkuList()).ifPresent(skuList -> {
|
|
|
if (skuList.size() > 0) {
|
|
|
@@ -197,11 +200,6 @@ public class GoodsDonController {
|
|
|
.orderBy(OrderCommentFrontView::getId).desc()
|
|
|
.build());
|
|
|
data.setComments(comments);
|
|
|
- OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
- .eq(OrderDon::getGoodsId, data.getId())
|
|
|
- .notIn(OrderDon::getStatus, Constant.noOrderStatus).select(OrderDon::getCreatedTime, OrderDon::getPayTime, OrderDon::getId)
|
|
|
- .orderByDesc(OrderDon::getId)
|
|
|
- .last("limit 1"));
|
|
|
data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1));
|
|
|
});
|
|
|
redisService.setNx(pcCacheKey, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
|
|
|
@@ -222,6 +220,10 @@ public class GoodsDonController {
|
|
|
if (value != null) {
|
|
|
try {
|
|
|
List<GoodsHomePageView> list = Jsons.parseObject(value, List.class);
|
|
|
+ list.forEach(data -> {
|
|
|
+ //销量
|
|
|
+ data.setSold(data.getVirtualSold() + getSoldNumByGid(data.getId(), 1));;
|
|
|
+ });
|
|
|
if (CollUtil.isNotEmpty(list)) {
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(list);
|
|
|
}
|
|
|
@@ -234,9 +236,8 @@ public class GoodsDonController {
|
|
|
}
|
|
|
List<GoodsHomePageView> dataList = beanSearcher.searchAll(GoodsHomePageView.class, builder.build());
|
|
|
dataList.forEach(data -> {
|
|
|
- Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
- .eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
|
|
|
- data.setSold(sold + data.getVirtualSold());
|
|
|
+ //销量
|
|
|
+ data.setSold(data.getVirtualSold() + getSoldNumByGid(data.getId(), 1));;
|
|
|
GoodsDonFrontSkuView skuView = beanSearcher.searchFirst(GoodsDonFrontSkuView.class, MapUtils.builder().field(GoodsDonFrontSkuView::getGoodsId, data.getId()).field(GoodsDonFrontSkuView::getStatus, true).orderBy(GoodsDonFrontSkuView::getPrice).asc().build());
|
|
|
if (skuView != null) {
|
|
|
data.setPrice(skuView.getPrice());
|
|
|
@@ -256,7 +257,11 @@ public class GoodsDonController {
|
|
|
Object value = redisService.get(registerCacheKey);
|
|
|
if (value != null) {
|
|
|
try {
|
|
|
- List<RegisterGoodsDonView> list = Jsons.parseList(value, RegisterGoodsDonView.class);
|
|
|
+ List<RegisterGoodsDonView> list = Jsons.parseList(value, RegisterGoodsDonView.class);
|
|
|
+ list.forEach(data -> {
|
|
|
+ //销量
|
|
|
+ data.setSold(data.getVirtualSold() + getSoldNumByGid(data.getId(), 2));
|
|
|
+ });
|
|
|
if (CollUtil.isNotEmpty(list)) {
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(list);
|
|
|
}
|
|
|
@@ -267,9 +272,8 @@ public class GoodsDonController {
|
|
|
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.setSold(data.getVirtualSold() + getSoldNumByGid(data.getId(), 2));
|
|
|
data.setNotifyMsg(getPayMsgTime(data.getId(), now, 2));
|
|
|
});
|
|
|
redisService.setNx(registerCacheKey, dataList, RedisService.key.REGISTER_HOME_PAGE_CACHE.getTimeout());
|
|
|
@@ -390,4 +394,31 @@ public class GoodsDonController {
|
|
|
notifyMsg.append("前有人购买");
|
|
|
return notifyMsg.toString();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取订单销售数据
|
|
|
+ */
|
|
|
+ public Integer getSoldNumByGid(Long goodsId, Integer type) {
|
|
|
+ String goodsSoldKey = null;
|
|
|
+ if (type == 1) {
|
|
|
+ goodsSoldKey = RedisService.key.HOME_PAGE_GOODS_SOLD_NUM_KEY.getName() + goodsId;
|
|
|
+ } else if (type == 2) {
|
|
|
+ goodsSoldKey = RedisService.key.HOME_PAGE_REGISTER_GOODS_SOLD_NUM_KEY.getName() + goodsId;
|
|
|
+ }
|
|
|
+ Object soldNumObj = redisService.get(goodsSoldKey);
|
|
|
+ if (soldNumObj == null) {
|
|
|
+ Integer sold = 0;
|
|
|
+ if (type == 1) {
|
|
|
+ sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
+ .eq(OrderDon::getGoodsId, goodsId).notIn(OrderDon::getStatus, Constant.noOrderStatus));
|
|
|
+ } else if (type == 2) {
|
|
|
+ sold = registerOrderDonMapper.selectCount(Wrappers.lambdaQuery(RegisterOrderDon.class)
|
|
|
+ .eq(RegisterOrderDon::getGoodsId, goodsId).notIn(RegisterOrderDon::getStatus, Constant.noOrderStatus));
|
|
|
+ }
|
|
|
+ redisService.setNx(goodsSoldKey, sold, RedisService.key.HOME_PAGE_GOODS_SOLD_NUM_KEY.getTimeout());
|
|
|
+ return sold;
|
|
|
+ }
|
|
|
+ Integer soldNum = Integer.valueOf(soldNumObj.toString());
|
|
|
+ return soldNum;
|
|
|
+ }
|
|
|
}
|