基于mall4j产品的二开项目后端
lee
2024-12-18 efdb99f8cecc4afb592afad79c761081d5d5cf22
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
/*
 * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
 *
 * https://www.mall4j.com/
 *
 * 未经允许,不可做商业用途!
 *
 * 版权所有,侵权必究!
 */
package com.yami.shop.api.controller;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.enums.InvoiceHeaderType;
import com.yami.shop.bean.enums.OrderInvoiceState;
import com.yami.shop.bean.model.OrderInvoice;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.api.util.SecurityUtils;
import com.yami.shop.service.OrderInvoiceService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.Valid;
import java.util.Date;
import java.util.Objects;
 
 
/**
 * @author Citrus
 * @date 2021-08-16 14:22:47
 */
@RestController("appOrderInvoiceController")
@RequestMapping("/p/orderInvoice")
@Tag(name = "app订单发票接口")
public class OrderInvoiceController {
 
    @Autowired
    private OrderInvoiceService orderInvoiceService;
 
    @GetMapping("/page")
    @Operation(summary = "分页查询订单发票列表信息")
    public ServerResponseEntity<IPage<OrderInvoice>> getOrderInvoicePage(PageParam<OrderInvoice> page) {
        IPage<OrderInvoice> userInvoicePage = orderInvoiceService.pageUserInvoice(page, SecurityUtils.getUser().getUserId());
        return ServerResponseEntity.success(userInvoicePage);
    }
 
    @GetMapping("/info/{orderInvoiceId}")
    @Operation(summary = "通过订单发票id查询订单发票信息")
    @Parameter(name = "orderInvoiceId", description = "订单发票id" , required = true)
    public ServerResponseEntity<OrderInvoice> getById(@PathVariable("orderInvoiceId") Long orderInvoiceId) {
        OrderInvoice orderInvoice = orderInvoiceService.getById(orderInvoiceId);
        if (Objects.nonNull(orderInvoice.getUserId()) && !Objects.equals(orderInvoice.getUserId(), SecurityUtils.getUser().getUserId())) {
            //非当前用户的发票信息
            throw new YamiShopBindException("yami.invoice.not.user");
        }
        return ServerResponseEntity.success(orderInvoice);
    }
 
    @PostMapping
    @Operation(summary = "申请开票")
    public ServerResponseEntity<Boolean> save(@RequestBody @Valid OrderInvoice orderInvoice) {
        if (Objects.isNull(orderInvoice.getShopId())) {
            //店铺id不能为空
            throw new YamiShopBindException("yami.invoice.shopId.notNull");
        }
        Long orderId = orderInvoiceService.getByorderNumber(orderInvoice.getOrderNumber());
        if (Objects.nonNull(orderId)) {
            //该订单已经申请发票,请勿重复申请!
            throw new YamiShopBindException("yami.invoice.invoiceId.duplicate");
        }
        if (Objects.equals(InvoiceHeaderType.PERSONAL.value(), orderInvoice.getHeaderType())) {
            orderInvoice.setInvoiceTaxNumber(null);
        }
        orderInvoice.setInvoiceState(OrderInvoiceState.APPLICATION.value());
        orderInvoice.setApplicationTime(new Date());
        return ServerResponseEntity.success(orderInvoiceService.save(orderInvoice));
    }
 
    @PutMapping
    @Operation(summary = "申请换开")
    public ServerResponseEntity<Boolean> updateById(@RequestBody @Valid OrderInvoice orderInvoice) {
        orderInvoice.setInvoiceState(OrderInvoiceState.APPLICATION.value());
        orderInvoice.setApplicationTime(new Date());
        if (Objects.equals(InvoiceHeaderType.PERSONAL.value(), orderInvoice.getHeaderType())) {
            orderInvoice.setInvoiceTaxNumber(null);
        }
        return ServerResponseEntity.success(orderInvoiceService.updateById(orderInvoice));
    }
}