“mitao”
2025-12-25 07ad21ab9c793750d1e0b3a40d99e19d58f4ee44
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
package com.ruoyi.web.controller.api;
 
 
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.utils.WebUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.dto.TransferOrderDto;
import com.ruoyi.system.export.BigGiftPackageImport;
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.service.*;
import com.ruoyi.system.vo.TOrderTransferDetailVo;
import com.ruoyi.system.vo.TOrderTransferVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.core.domain.AjaxResult;
 
import java.io.IOException;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
 
/**
 * <p>
 * 大礼包订单 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2025-12-08
 */
@RestController
@RequestMapping("/t-big-gift-package-order")
@Api(tags = "(嘉视达)大礼包订单")
public class TBigGiftPackageOrderController {
 
    private final TBigGiftPackageOrderService tBigGiftPackageOrderService;
    private final TokenService tokenService;
    private final TAppUserService tAppUserService;
    private final TCompanyService tCompanyService;
    private final TOrderTransferService  tOrderTransferService;
    private final TBigGiftPackageService tBigGiftPackageService;
    private final ISysUserService sysUserService;
 
    public TBigGiftPackageOrderController(TBigGiftPackageOrderService tBigGiftPackageOrderService, TokenService tokenService, TAppUserService tAppUserService, TCompanyService tCompanyService, TOrderTransferService tOrderTransferService, TBigGiftPackageService tBigGiftPackageService, ISysUserService sysUserService) {
        this.tBigGiftPackageOrderService = tBigGiftPackageOrderService;
        this.tokenService = tokenService;
        this.tAppUserService = tAppUserService;
        this.tCompanyService = tCompanyService;
        this.tOrderTransferService = tOrderTransferService;
 
        this.tBigGiftPackageService = tBigGiftPackageService;
        this.sysUserService = sysUserService;
    }
 
 
    @ApiOperation(value = "大礼包订单列表")
    @PostMapping(value = "/pageList")
    public R<Page<TBigGiftPackageOrder>> pageList(@RequestBody BigGiftPackageOrderQuery query) {
        Page<TBigGiftPackageOrder> tBigGiftPackageOrderPage = new Page<>(query.getPageNum(), query.getPageSize());
        List<TBigGiftPackageOrder> list = tBigGiftPackageOrderService.pageList(tBigGiftPackageOrderPage,query);
        tBigGiftPackageOrderPage.setRecords(list);
        return R.ok(tBigGiftPackageOrderPage);
    }
 
    @ApiOperation(value = "导出大礼包订单")
    @Log(title = "大礼包订单-导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export( @RequestBody BigGiftPackageOrderQuery query) {
        List<TBigGiftPackageOrder> list = tBigGiftPackageOrderService.export(query);
        ArrayList<TBigGiftPackageOrderExport> exports = new ArrayList<>();
        for (TBigGiftPackageOrder order : list) {
            TBigGiftPackageOrderExport export = new TBigGiftPackageOrderExport();
            export.setCompanyName(order.getCompanyName());
            export.setOrderNo(order.getCode());
            export.setCreateTime(order.getCreateTime());
            export.setUsername(order.getUserName());
            export.setUserPhone(order.getPhone());
            export.setOrderAmount(order.getOrderPrice());
            export.setGoodsName(order.getBigGiftPackageName());
            export.setPayMethod("微信支付");
            export.setDeposit(order.getDeposit());
            export.setBalance(order.getFinalPayment());
            export.setOrderStatus(order.getStatus());
            exports.add(export);
        }
 
 
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TBigGiftPackageOrderExport.class, exports);
        HttpServletResponse response = WebUtils.response();
        assert response != null;
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        ServletOutputStream outputStream = null;
        try {
            String fileName = URLEncoder.encode("大礼包订单导出信息.xls", "utf-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setHeader("Pragma", "no-cache");
            response.setHeader("Cache-Control", "no-cache");
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
 
 
    @ApiOperation(value = "大礼包订单详情")
    @PostMapping(value = "/detail/{id}")
    public R<TBigGiftPackageOrder> detail(@PathVariable Integer id) {
        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 = "删除大礼包订单")
    @DeleteMapping(value = "/delete/{id}")
    @Log(title = "大礼包订单-删除", businessType = BusinessType.DELETE)
    public R<String> delete(@PathVariable Integer id) {
        TBigGiftPackageOrder tBigGiftPackageOrder = tBigGiftPackageOrderService.getById(id);
        tBigGiftPackageOrder.setDelFlag(1);
        boolean delete = tBigGiftPackageOrderService.updateById(tBigGiftPackageOrder);
        return delete ? R.ok() : R.fail();
    }
 
 
    @ApiOperation(value = "大礼包订单编辑")
    @PostMapping(value = "/edit")
    @Log(title = "大礼包订单-编辑", businessType = BusinessType.UPDATE)
    public R<String> edit(@RequestBody TBigGiftPackageOrder tBigGiftPackageOrder) {
        TBigGiftPackageOrder tBigGiftPackageOrder1 = tBigGiftPackageOrderService.getById(tBigGiftPackageOrder.getId());
        if(tBigGiftPackageOrder1.getStatus()!=1){
            return R.fail("订单状态不是待付款,不能修改");
        }
        tBigGiftPackageOrder1.setOrderPrice(tBigGiftPackageOrder.getOrderPrice());
        tBigGiftPackageOrder1.setRemark(tBigGiftPackageOrder.getRemark());
        boolean update = tBigGiftPackageOrderService.updateById(tBigGiftPackageOrder1);
        return update ? R.ok() : R.fail();
    }
 
    @ApiOperation(value = "订单转让")
    @PostMapping(value = "/transfer")
    @Log(title = "大礼包订单-转让", businessType = BusinessType.UPDATE)
    public R<String> transfer(@RequestBody TransferOrderDto dto) {
        TBigGiftPackageOrder tBigGiftPackageOrder = tBigGiftPackageOrderService.getById(dto.getOrderId());
        Integer oldUserId = tBigGiftPackageOrder.getAppUserId();
        tBigGiftPackageOrder.setAppUserId(dto.getAppUserId());
        boolean update = tBigGiftPackageOrderService.updateById(tBigGiftPackageOrder);
        TOrderTransfer tOrderTransfer = new TOrderTransfer();
        tOrderTransfer.setOldAppUserId(oldUserId);
        tOrderTransfer.setNewAppUserId(dto.getAppUserId());
        tOrderTransfer.setBigGiftPackageOrderId(dto.getOrderId());
        tOrderTransfer.setCreateTime(LocalDateTime.now());
 
        Long userId = tokenService.getLoginUser().getUserId();
        tOrderTransfer.setNewUserId(userId);
        tOrderTransferService.save(tOrderTransfer);
 
        return update ? R.ok() : R.fail();
    }
 
 
 
 
 
 
    @ApiOperation(value = "订单转让列表")
    @PostMapping(value = "/transferList")
    public R<Page<TOrderTransferVo>> transferList(@RequestBody OrderTransferQuery query) {
        Page<TOrderTransferVo> tOrderTransferPage = new Page<>(query.getPageNum(), query.getPageSize());
        List<TOrderTransferVo> list =  tOrderTransferService.pageList(tOrderTransferPage,query);
        tOrderTransferPage.setRecords(list);
        return R.ok(tOrderTransferPage);
    }
 
 
    @ApiOperation(value = "订单转让--导出")
    @Log(title = "订单转让-导出", businessType = BusinessType.EXPORT)
    @PostMapping("/transferExport")
    public void transferExport(@RequestBody OrderTransferQuery query) {
        List<TOrderTransferVo> list =  tOrderTransferService.pageListExport(query);
 
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TOrderTransferVo.class, list);
        HttpServletResponse response = WebUtils.response();
        assert response != null;
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        ServletOutputStream outputStream = null;
        try {
            String fileName = URLEncoder.encode("订单转让导出信息.xls", "utf-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setHeader("Pragma", "no-cache");
            response.setHeader("Cache-Control", "no-cache");
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
 
 
 
    @ApiOperation(value = "订单转让详情")
    @PostMapping(value = "/transferDetail/{id}")
    public R<TOrderTransferDetailVo> transferDetail(@PathVariable Integer id) {
        TOrderTransfer tOrderTransfer = tOrderTransferService.getById(id);
        TOrderTransferDetailVo tOrderTransferVo = new TOrderTransferDetailVo();
        tOrderTransferVo.setId(tOrderTransfer.getId());
        tOrderTransferVo.setBigGiftPackageOrderId(tOrderTransfer.getBigGiftPackageOrderId());
 
        // 订单
        TBigGiftPackageOrder tBigGiftPackageOrder = tBigGiftPackageOrderService.getById(tOrderTransfer.getBigGiftPackageOrderId());
        tOrderTransferVo.setCode(tBigGiftPackageOrder.getCode());
        tOrderTransferVo.setCreateTime(tBigGiftPackageOrder.getCreateTime());
 
        // 老用户
        TAppUser oldUser = tAppUserService.getById(tOrderTransfer.getOldAppUserId());
        tOrderTransferVo.setOldUser(oldUser.getName());
        tOrderTransferVo.setOldUserId(oldUser.getId());
        tOrderTransferVo.setOrderPrice(tBigGiftPackageOrder.getOrderPrice());
 
        // 商品
        Integer bigGiftPackageId = tBigGiftPackageOrder.getBigGiftPackageId();
        TBigGiftPackage giftPackage = tBigGiftPackageService.getById(bigGiftPackageId);
        tOrderTransferVo.setProductName(giftPackage.getName());
        tOrderTransferVo.setPayType(tBigGiftPackageOrder.getPaymentType());
        tOrderTransferVo.setDeposit(tBigGiftPackageOrder.getDeposit());
        tOrderTransferVo.setFinalPayment(tBigGiftPackageOrder.getFinalPayment());
        tOrderTransferVo.setStatus(tBigGiftPackageOrder.getStatus());
 
        // 新用户
        TAppUser newUser = tAppUserService.getById(tOrderTransfer.getNewAppUserId());
        tOrderTransferVo.setNewUserAvatar(newUser.getProfilePhoto());
        tOrderTransferVo.setNewUser(newUser.getName());
        tOrderTransferVo.setNewUserCode(newUser.getCode());
        tOrderTransferVo.setNewUserPhone(newUser.getPhone());
        tOrderTransferVo.setNewUserId(newUser.getId());
        tOrderTransferVo.setNewUserGender(newUser.getGender());
        tOrderTransferVo.setNewUserBirthday(newUser.getBirthday());
        tOrderTransferVo.setNewUserRegisterTime(newUser.getCreateTime());
        tOrderTransferVo.setNewUserStatus(newUser.getStatus());
 
 
        // 操作人
        tOrderTransferVo.setOperateTime(tOrderTransfer.getCreateTime());
        SysUser sysUser = sysUserService.selectUserById(tOrderTransfer.getNewUserId());
        tOrderTransferVo.setOperateUser(sysUser.getNickName());
        return R.ok(tOrderTransferVo);
    }
 
 
    @ApiOperation(value = "订单转让删除")
    @DeleteMapping(value = "/transferDelete/{id}")
    @Log(title = "订单转让-删除", businessType = BusinessType.DELETE)
    public R<String> transferDelete(@PathVariable Integer id) {
        TOrderTransfer orderTransfer = tOrderTransferService.getById(id);
        if (orderTransfer == null) {
            return R.fail("订单转让不存在");
        }
        orderTransfer.setDelFlag(1);
       tOrderTransferService.updateById(orderTransfer);
        return R.ok() ;
    }
 
 
    @ApiOperation(value = "用户管理分页列表")
    @PostMapping(value = "/transferPageUserList")
    public R<PageInfo<TAppUser>> transferPageUserList(@RequestBody AppUserListQuery query) {
        return R.ok(tAppUserService.transferPageUserList(query));
    }
 
 
}