liujie
2025-12-26 9197cc8e3ef4d0f8f2b178a657c2fe823a809fb6
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package com.ruoyi.web.controller.api.agent;
 
 
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.WebUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.dto.RefundApplyDTO;
import com.ruoyi.system.dto.TransferOrderDto;
import com.ruoyi.system.export.TBigGiftPackageOrderExport;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.AppUserListQuery;
import com.ruoyi.system.query.BigGiftPackageOrderQuery;
import com.ruoyi.system.query.OrderTransferQuery;
import com.ruoyi.system.query.RefundApplicationQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.TOrderTransferDetailVo;
import com.ruoyi.system.vo.TOrderTransferVo;
import com.ruoyi.system.vo.TRefundApplicationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.context.annotation.Lazy;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
 
/**
 * <p>
 * 大礼包订单 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2025-12-08
 */
@RestController
@RequestMapping("/agent/t-big-gift-package-order")
@Api(tags = "(嘉视达经销商后台)大礼包订单")
@RequiredArgsConstructor(onConstructor_ = @Lazy)
public class AgentBigGiftPackageOrderController {
 
    private final TBigGiftPackageOrderService tBigGiftPackageOrderService;
    private final TAppUserService tAppUserService;
    private final TCompanyService tCompanyService;
    private final TBigGiftPackageService tBigGiftPackageService;
    private final TRefundApplicationService tRefundApplicationService;
 
 
    @ApiOperation(value = "大礼包订单列表")
    @PostMapping(value = "/pageList")
    public R<Page<TBigGiftPackageOrder>> pageList(@RequestBody BigGiftPackageOrderQuery query) {
        if (SecurityUtils.isAgentUser()) {
            throw new ServiceException("请使用经销商/股东帐号访问");
        }
        Page<TBigGiftPackageOrder> tBigGiftPackageOrderPage = new Page<>(query.getPageNum(), query.getPageSize());
        query.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
        List<TBigGiftPackageOrder> list = tBigGiftPackageOrderService.pageList(tBigGiftPackageOrderPage, query);
        tBigGiftPackageOrderPage.setRecords(list);
        return R.ok(tBigGiftPackageOrderPage);
    }
 
    @ApiOperation(value = "大礼包订单详情")
    @PostMapping(value = "/detail/{id}")
    public R<TBigGiftPackageOrder> detail(@PathVariable Integer id) {
        if (SecurityUtils.isAgentUser()) {
            throw new ServiceException("请使用经销商/股东帐号访问");
        }
        TBigGiftPackageOrder tBigGiftPackageOrder = tBigGiftPackageOrderService.getById(id);
        Integer appUserId = tBigGiftPackageOrder.getAppUserId();
        TAppUser appUser = tAppUserService.getById(appUserId);
        Integer referrerUserId = appUser.getReferrerUserId();
        if(referrerUserId!=null){
            // 上级用户
            TAppUser lastUser = tAppUserService.getById(referrerUserId);
            if (lastUser != null && lastUser.getUserType()==2){
                tBigGiftPackageOrder.setSaleName(lastUser.getName());
                if(lastUser.getReferrerUserId()!=null){
                    // 上上级
                    TAppUser lastLastUser = tAppUserService.getById(lastUser.getReferrerUserId());
                    if (lastLastUser != null && lastLastUser.getUserType()==1){
                        tBigGiftPackageOrder.setPartnerName(lastLastUser.getName());
                    }
                }
            }
            if (lastUser != null && lastUser.getUserType()==1){
                tBigGiftPackageOrder.setPartnerName(lastUser.getName());
            }
        }
        Integer bigGiftPackageId = tBigGiftPackageOrder.getBigGiftPackageId();
        TBigGiftPackage tBigGiftPackage = tBigGiftPackageService.getById(bigGiftPackageId);
        tBigGiftPackageOrder.setBigGiftPackageName(tBigGiftPackage.getName());
        tBigGiftPackageOrder.setBigGiftPackageCover(tBigGiftPackage.getCoverImage());
        tBigGiftPackageOrder.setBigGiftPackagePrice(tBigGiftPackage.getTotalPrice());
        tBigGiftPackageOrder.setBigGiftPackageIntro(tBigGiftPackage.getIntroduction());
        // 销量
        long count = tBigGiftPackageOrderService.count(new LambdaQueryWrapper<TBigGiftPackageOrder>().eq(TBigGiftPackageOrder::getBigGiftPackageId, bigGiftPackageId).ne(TBigGiftPackageOrder::getStatus, 5));
        tBigGiftPackageOrder.setBigGiftPackageSales((int)count);
 
 
        Integer companyId = appUser.getCompanyId();
        if(companyId!=null){
            TCompany tCompany = tCompanyService.getById(companyId);
            tBigGiftPackageOrder.setCompanyName(tCompany.getName());
        }
        return R.ok(tBigGiftPackageOrder);
    }
 
    @ApiOperation(value = "大礼包订单退款申请")
    @PostMapping(value = "/applyRefund")
    public R<Void> applyRefund(@Validated @RequestBody RefundApplyDTO dto) {
        if (SecurityUtils.isAgentUser()) {
            throw new ServiceException("请使用经销商/股东帐号访问");
        }
        Integer userId = SecurityUtils.getLoginUser().getUser().getUserId().intValue();
        tRefundApplicationService.applyRefund(dto, userId);
        return R.ok();
    }
 
    @ApiOperation(value = "退款申请记录列表")
    @PostMapping(value = "/refundList")
    public R<Page<TBigGiftPackageOrder>> refundList(@RequestBody RefundApplicationQuery query) {
        if (SecurityUtils.isAgentUser()) {
            throw new ServiceException("请使用经销商/股东帐号访问");
        }
        query.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
        Page<TBigGiftPackageOrder> page = tRefundApplicationService.pageRefundList(query);
        return R.ok(page);
    }
    @ApiOperation(value = "退款申请详情")
    @GetMapping(value = "/refundDetail/{id}")
    public R<TRefundApplicationVo> refundDetail(@PathVariable Integer id) {
        return R.ok(tRefundApplicationService.refundDetail(id));
    }
 
}