小程序首页初版,订单回显商户二维码,

This commit is contained in:
liuyingfang
2024-04-08 14:05:38 +08:00
parent e77a77c883
commit 934a116cf2
25 changed files with 1525 additions and 64 deletions

View File

@@ -1,16 +1,12 @@
package com.chaozhanggui.system.cashierservice.service;
import com.chaozhanggui.system.cashierservice.dao.TbPlatformDictMapper;
import com.chaozhanggui.system.cashierservice.dao.TbProductSkuMapper;
import com.chaozhanggui.system.cashierservice.dao.TbShopInfoMapper;
import com.chaozhanggui.system.cashierservice.entity.TbPlatformDict;
import com.chaozhanggui.system.cashierservice.entity.TbProductSku;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.HomeDto;
import com.chaozhanggui.system.cashierservice.entity.vo.HomeUpVO;
import com.chaozhanggui.system.cashierservice.entity.vo.HomeVO;
import com.chaozhanggui.system.cashierservice.entity.vo.UserDutyVo;
import com.chaozhanggui.system.cashierservice.entity.vo.*;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.util.Threads;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@@ -19,6 +15,8 @@ import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
/**
* @author lyf
@@ -32,52 +30,79 @@ public class HomePageService {
private TbProductSkuMapper productSkuMapper;
@Resource
private TbPlatformDictMapper platformDictMapper;
@Resource
private TbMerchantCouponMapper merchantCouponMapper;
@Resource
private TbProductMapper productMapper;
@Resource
private SysDictDetailMapper sysDictDetailMapper;
public Result homePage(HomeDto homeDto){
public Result homePage(HomeDto homeDto,String environmen) throws ExecutionException, InterruptedException {
int beginNo;
if(homeDto.getPage() <=0){
beginNo = 0;
}else{
beginNo = (homeDto.getPage() - 1) * homeDto.getSize();
}
List<HomeVO> homeVO = shopInfoMapper.selectShopInfo(beginNo,homeDto.getSize());
List<Integer> objects = new ArrayList<>();
for (HomeVO o :homeVO) {
objects.add(o.getProductId());
//优惠卷
List<TbMerchantCoupon> tbMerchantCoupons = merchantCouponMapper.queryAllByPage(beginNo, homeDto.getSize());
//统计shopId以及productId
List<String> shopIds = new ArrayList<>();
List<String> productIds = new ArrayList<>();
for (TbMerchantCoupon coupon : tbMerchantCoupons) {
shopIds.add(coupon.getShopId());
productIds.add(coupon.getRelationIds());
}
//原价现价
List<TbProductSku> tbProductSkus = productSkuMapper.selectDownSku(objects);
//销量
List<UserDutyVo> userDutyVos = shopInfoMapper.searchUserDutyDetail(objects);
//组装数据
for (HomeVO o :homeVO) {
for (TbProductSku sku :tbProductSkus) {
if (o.getProductId().toString().equals(sku.getProductId())){
o.setOriginPrice(sku.getOriginPrice() == null?BigDecimal.ZERO:sku.getOriginPrice());
o.setSalePrice(sku.getSalePrice() == null?BigDecimal.ZERO:sku.getSalePrice());
CompletableFuture<List<TbShopInfo>> shopInfo = CompletableFuture.supplyAsync(() ->
shopInfoMapper.selectByIds(shopIds));
CompletableFuture<List<TbProduct>> product = CompletableFuture.supplyAsync(() ->
productMapper.selectByIds((productIds)));
CompletableFuture<List<TbProductSku>> productSku = CompletableFuture.supplyAsync(() ->
productSkuMapper.selectSkus((productIds)));
CompletableFuture<List<TbPlatformDict>> dictPro = CompletableFuture.supplyAsync(() ->
platformDictMapper.queryAllByType("proTag",environmen));
CompletableFuture<List<TbPlatformDict>> dictShop = CompletableFuture.supplyAsync(() ->
platformDictMapper.queryAllByType("shopTag",environmen));
Threads.call(shopInfo,product,productSku,dictPro,dictShop);
boolean isFirstAdded = true;
//组装
List<HomeVO> homeVOList = new ArrayList<>();
for (TbMerchantCoupon o :tbMerchantCoupons) {
HomeVO homeVO = new HomeVO();
homeVO.setDiscount(o.getRatio());
if (isFirstAdded){
homeVO.setShopTag(dictShop.get().get(0).getName());
homeVO.setProTag(dictPro.get().get(0).getName());
isFirstAdded = false;
}
for (TbShopInfo tbShopInfo : shopInfo.get()) {
if (o.getShopId().equals(tbShopInfo.getId().toString())) {
homeVO.setShopName(tbShopInfo.getShopName());
homeVO.setImage(tbShopInfo.getLogo());
}
}
if (userDutyVos == null){
o.setRealSalesNumber(BigDecimal.ZERO);
}else {
for (UserDutyVo duty : userDutyVos) {
if (o.getProductId().equals(duty.getProductId())) {
o.setRealSalesNumber(duty.getNumber());
}else {
o.setRealSalesNumber(BigDecimal.ZERO);
}
for (TbProduct tbProduct :product.get()) {
if (o.getRelationIds().equals(tbProduct.getId().toString())) {
homeVO.setProductName(tbProduct.getName());
homeVO.setImage(tbProduct.getCoverImg());
homeVO.setId(tbProduct.getId());
}
}
//共省金额
o.setSave(o.getOriginPrice().subtract(o.getSalePrice()));
if (o.getOriginPrice().compareTo(BigDecimal.ZERO) == 0){
o.setDiscount(null);
}else {
o.setDiscount(o.getSalePrice().divide(o.getOriginPrice(), 2, RoundingMode.DOWN).multiply(new BigDecimal("10")));
for (TbProductSku tbProductSku :productSku.get()) {
if (o.getRelationIds().equals(tbProductSku.getProductId())) {
homeVO.setOriginPrice(tbProductSku.getSalePrice());
homeVO.setRealSalesNumber(tbProductSku.getRealSalesNumber() == null?BigDecimal.ZERO: new BigDecimal(tbProductSku.getRealSalesNumber()));
Float discount = homeVO.getDiscount();
BigDecimal discountDecimal = new BigDecimal(discount);
homeVO.setSalePrice(tbProductSku.getSalePrice().multiply((discountDecimal.multiply(new BigDecimal("0.1")))));
homeVO.setSave(homeVO.getOriginPrice().subtract(homeVO.getSalePrice()));
}
}
homeVOList.add(homeVO);
}
return Result.success(CodeEnum.SUCCESS,homeVO);
return Result.success(CodeEnum.SUCCESS,homeVOList);
}
public Result homePageUp(String environment){
@@ -88,6 +113,44 @@ public class HomePageService {
//金刚区
List<TbPlatformDict> districtList = platformDictMapper.queryAllByType("homeDistrict",environment);
homeUpVO.setDistrict(districtList);
//菜单
List<SysDict> sysDicts = sysDictDetailMapper.selectByAll();
List<DicDetailVO> dicDetailVO = new ArrayList<>();
for (SysDict sysDictsList : sysDicts) {
DicDetailVO dicDetailVOList = new DicDetailVO();
dicDetailVOList.setName(sysDictsList.getName());
dicDetailVOList.setDescription(sysDictsList.getDescription());
dicDetailVOList.setDetail(sysDictDetailMapper.selectByDictId(sysDictsList.getDictId()));
dicDetailVOList.setIsChild(sysDictsList.getIsChild());
dicDetailVO.add(dicDetailVOList);
}
homeUpVO.setMenu(dicDetailVO);
/**
* 销量榜
*/
List<HomeVO> homeVOs = productSkuMapper.selectSale();
for (HomeVO o : homeVOs) {
BigDecimal originPrice = o.getOriginPrice();
if (originPrice.compareTo(BigDecimal.ZERO)!= 0){
BigDecimal multiply = o.getSalePrice().divide(o.getOriginPrice(),2,RoundingMode.DOWN).multiply(BigDecimal.TEN);
o.setDiscount(multiply.floatValue());
}else {
o.setDiscount(null);
}
}
HotRankingVO hotRankingVO = new HotRankingVO();
hotRankingVO.setHotList(homeVOs);
homeUpVO.setSalesList(hotRankingVO);
/**
*每日榜
*/
List<HomeVO> homeVODay = productSkuMapper.selectDay();
TodayRankingVO todayRankingVO = new TodayRankingVO();
todayRankingVO.setTodayList(homeVODay);
homeUpVO.setTodayList(todayRankingVO);
return Result.success(CodeEnum.SUCCESS,homeUpVO);
}
}

View File

@@ -165,7 +165,8 @@ public class OrderService {
OrderVo orderVo = new OrderVo();
orderVo.setName(tbShopInfo.getShopName());
orderVo.setStatus(orderInfo.getStatus());
//TODO 增加商家二维码
orderVo.setShopQrcode(tbShopInfo.getShopQrcode());
orderVo.setDetails(details);
orderVo.setOrderNo(orderInfo.getOrderNo());
orderVo.setTime(orderInfo.getCreatedAt());