基于mall4j产品的二开项目后端
lee
2024-12-18 921461a3f906d74403aeb6a27051deb77eca10fc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.yami.shop.api.controller;
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yami.shop.bean.app.dto.ProdCommDataDto;
import com.yami.shop.bean.model.Product;
import com.yami.shop.bean.model.ShopDetail;
import com.yami.shop.bean.model.ShopWallet;
import com.yami.shop.bean.model.UserAssets;
import com.yami.shop.bean.param.ShopManagementParam;
import com.yami.shop.bean.vo.HalfMonthShopRevenueVO;
import com.yami.shop.bean.vo.ShopDetailVO;
import com.yami.shop.bean.vo.statistics.PlatformStatisticsVO;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.security.api.util.SecurityUtils;
import com.yami.shop.service.*;
import com.yami.shop.sys.common.service.ShopEmployeeService;
import com.yami.shop.user.common.service.UserScoreDetailService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.List;
 
@RestController
@RequestMapping("/p/shopManagement")
@Tag(name = "店铺管理接口")
public class ShopManagementController {
    @Autowired
    private ShopDetailService shopDetailService;
    @Autowired
    private UserCollectionShopService userCollectionShopService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private ProductService productService;
    @Autowired
    private UserScoreDetailService userScoreDetailService;
    @Autowired
    private ShopEmployeeService shopEmployeeService;
    @Autowired
    private StatisticsService statisticsService;
    @Autowired
    private ShopWalletService shopWalletService;
    @Autowired
    private IUserAssetsService userAssetsService;
    @Autowired
    private MapperFacade mapperFacade;
    @Autowired
    private ProdCommService prodCommService;
 
    @GetMapping("/getShopInfo")
    @Operation(summary = "获取店铺管理页面展示信息" ,description = "获取店铺管理页面展示信息")
    public ServerResponseEntity<ShopManagementParam> getShopInfo() {
        ShopManagementParam shopManagementParam = new ShopManagementParam();
        String userId = SecurityUtils.getUser().getUserId();
        PlatformStatisticsVO platformStatisticsVO = statisticsService.platformRealTimeOverview(new Date());
        ShopDetail shopDetail = shopDetailService.getShopDetailByUserId(userId);
        ShopDetailVO shopDetailVO = mapperFacade.map(shopDetail, ShopDetailVO.class);
        if (shopDetail != null) {
            shopManagementParam.setShopDetail(shopDetailVO);
            shopManagementParam.setShopFans(userCollectionShopService.getFansCountByShopId(shopDetail.getShopId()));
            List<Long> prodId = productService.getProdIdByShopId(shopDetail.getShopId());
            shopManagementParam.setShopGrade(prodCommService.getProdScoreByProdIdList(prodId) != null ? prodCommService.getProdScoreByProdIdList(prodId) : shopManagementParam.getShopGrade());
            shopManagementParam.setShopProdCount(orderService.getShopProdCountByShopId(shopDetail.getShopId()));
            shopManagementParam.setTodayDealQuota(orderService.getCurrentPayAmount(shopDetail.getShopId()));
            // 今日访客
            shopManagementParam.setTodayCaller(platformStatisticsVO.getTodayVisitors() != null ? platformStatisticsVO.getTodayVisitors() : 0);
            shopManagementParam.setThisWeekOrderNumber(orderService.countByShopIdAndWeek(shopDetail.getShopId(),new Date()));
            List<HalfMonthShopRevenueVO> halfMonthShopRevenue = orderService.getHalfMonthShopRevenue(shopDetail.getShopId());
            shopManagementParam.setHalfMonthShopRevenue(halfMonthShopRevenue);
            ShopWallet shopWallet = shopWalletService.getShopWalletByShopId(shopDetail.getShopId());
            shopManagementParam.setCanWithdrawMoney(shopWallet.getSettledAmount() != null ? shopWallet.getSettledAmount() : 0);
            UserAssets userAssets = userAssetsService
                    .getOne(Wrappers.lambdaQuery(UserAssets.class)
                            .eq(UserAssets::getUserId, userId)
                            .isNotNull(UserAssets::getBalance));
            shopManagementParam.setAccountBalance(userAssets != null ? userAssets.getBalance() : 0);
            shopManagementParam.setFreezeBalance(userAssets != null ? userAssets.getFreeze() : 0.0);
            shopManagementParam.setUnconfirmedPayment(shopWallet.getFreezeAmount() != null ? shopWallet.getFreezeAmount() : 0);
            shopManagementParam.setScoreCount(userScoreDetailService.getUsableScoreByUserId(userId));
            shopManagementParam.setShopEmployeeCount(shopEmployeeService.getShopEmployeeCountByShopId(shopDetail.getShopId()));
            return ServerResponseEntity.success(shopManagementParam);
        }
        return ServerResponseEntity.success();
    }
}