FengChaoYu 1 hete
szülő
commit
12eeb659e0

+ 18 - 0
src/main/java/com/gree/mall/contest/bean/tax/OrderTaxExcelBean.java

@@ -0,0 +1,18 @@
+package com.gree.mall.contest.bean.tax;
+
+import com.gree.mall.contest.plus.entity.OrderTax;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.Date;
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class OrderTaxExcelBean extends OrderTax {
+
+    @Schema(description = "商品分类")
+    public String categoryNames;
+    @Schema(description = "支付时间")
+    private Date payTime;
+}

+ 15 - 0
src/main/java/com/gree/mall/contest/bean/tax/RspOrderTax.java

@@ -0,0 +1,15 @@
+package com.gree.mall.contest.bean.tax;
+
+import com.gree.mall.contest.plus.entity.OrderTax;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class RspOrderTax extends OrderTax {
+
+    @Schema(description = "商品分类")
+    public String categoryNames;
+
+}

+ 10 - 0
src/main/java/com/gree/mall/contest/commonmapper/CommonMapper.java

@@ -1,6 +1,7 @@
 package com.gree.mall.contest.commonmapper;
 
 import cn.hutool.core.date.DateTime;
+import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.gree.mall.contest.bean.common.AmityUrlVO;
@@ -12,7 +13,9 @@ import com.gree.mall.contest.bean.merchant.MerchantRegionVO;
 import com.gree.mall.contest.bean.merchant.MerchantVO;
 import com.gree.mall.contest.bean.merchant.WebsitApplyVO;
 import com.gree.mall.contest.bean.store.PlatformStoreVO;
+import com.gree.mall.contest.bean.tax.OrderTaxExcelBean;
 import com.gree.mall.contest.bean.zfire.ZfireParamBean;
+import com.gree.mall.contest.plus.entity.GoodsCategory;
 import com.gree.mall.contest.plus.entity.UserTopPop;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -104,4 +107,11 @@ public interface CommonMapper {
      * @return
      */
     IPage<PlatformStoreVO> platformStorePage(Page page, @Param("ex") ZfireParamBean zfireParamBean);
+
+
+    @InterceptorIgnore(tenantLine = "true")
+    List<GoodsCategory> queryGoodsCategoryByOrderId(@Param("orderId") String orderId);
+
+    List<OrderTaxExcelBean> queryOrderTaxExcelMsg(@Param("companyWechatIds") List<String> companyWechatIds, @Param("adminWebsitIds") List<String> adminWebsitIds
+            , @Param("status") Boolean status, @Param("orderId") String orderId);
 }

+ 2 - 2
src/main/java/com/gree/mall/contest/controller/mini/order/MiniOrderTaxController.java

@@ -69,7 +69,7 @@ public class MiniOrderTaxController {
     public ResponseHelper<OrderTax> updateTax(
             @RequestBody OrderTax orderTax
     ) throws Exception {
-        orderTaxLogic.updateTax(orderTax);
+        orderTaxLogic.miniUpdateTax(orderTax);
         return ResponseHelper.success();
     }
 
@@ -110,7 +110,7 @@ public class MiniOrderTaxController {
             @Parameter(description = "页大小", required = true) @RequestParam Integer pageSize
     ) throws Exception {
 
-        IPage<OrderTax> page = orderTaxLogic.page(userId, pageNum, pageSize);
+        IPage<OrderTax> page = orderTaxLogic.miniPage(userId, pageNum, pageSize);
         return ResponseHelper.success(page);
     }
 

+ 89 - 0
src/main/java/com/gree/mall/contest/controller/pc/order/OrderTaxController.java

@@ -0,0 +1,89 @@
+package com.gree.mall.contest.controller.pc.order;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.gree.mall.contest.bean.tax.RspOrderTax;
+import com.gree.mall.contest.exception.RemoteServiceException;
+import com.gree.mall.contest.helper.ResponseHelper;
+import com.gree.mall.contest.logic.order.OrderTaxLogic;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+@Slf4j
+@RestController
+@Tag(name = "发票管理", description = "发票管理")
+@RequestMapping(value = "/pc/tax", produces = "application/json; charset=utf-8")
+@RequiredArgsConstructor
+public class OrderTaxController {
+
+    private final OrderTaxLogic orderTaxLogic;
+
+    @PostMapping("/update")
+    @Operation(summary = "上传发票pdf地址")
+    public ResponseHelper updateTax(
+            @Parameter(description = "发票id", required = true) @RequestParam String orderTaxId,
+            @Parameter(description = "发票pdf的url,使用urlencode编码", required = true) @RequestParam String taxlink
+    ) throws RemoteServiceException {
+        orderTaxLogic.updateTax(orderTaxId, taxlink);
+        return ResponseHelper.success();
+    }
+
+    @PostMapping("/offline")
+    @Operation(summary = "已线下处理")
+    public ResponseHelper updateTax(
+            @Parameter(description = "发票id", required = true) @RequestParam(required = true) String orderTaxId
+    ) throws RemoteServiceException {
+        orderTaxLogic.offline(orderTaxId);
+        return ResponseHelper.success();
+    }
+
+    @GetMapping("/list")
+    @Operation(summary = "发票列表")
+    public ResponseHelper<Page<RspOrderTax>> pageTax(
+            @Parameter(description = "开票状态true:已开发票,false:未开,不传:所有的", required = false) @RequestParam(required = false) Boolean status,
+            @Parameter(description = "订单号", required = false) @RequestParam(required = false) String orderId,
+            @Parameter(description = "页号", required = true) @RequestParam Integer pageNum,
+            @Parameter(description = "页大小", required = true) @RequestParam Integer pageSize,
+            HttpServletRequest request
+    ) throws Exception {
+
+        IPage<RspOrderTax> page = orderTaxLogic.page(status, orderId, pageNum, pageSize, request);
+        return ResponseHelper.success(page);
+    }
+
+    @PostMapping("/updateWkp")
+    @Operation(summary = "修改未开票信息")
+    public ResponseHelper updateTaxInfo(
+            @Parameter(description = "orderTaxId", required = true) @RequestParam(required = true) String orderTaxId,
+            @Parameter(description = "公司名称或个人名", required = true) @RequestParam(required = true) String name,
+            @Parameter(description = "纳税人识别号", required = true) @RequestParam(required = true) String taxNo,
+            @Parameter(description = "收票人名称", required = true) @RequestParam(required = true) String receiverName,
+            @Parameter(description = "接收电话", required = true) @RequestParam(required = true) String receiverPhone,
+            @Parameter(description = "接收邮箱", required = true) @RequestParam(required = true) String receiverEmail,
+            @Parameter(description = "收票人地址", required = true) @RequestParam(required = true) String receiverAddress
+    ) throws RemoteServiceException {
+        orderTaxLogic.updateInfo(orderTaxId, name, taxNo, receiverName, receiverPhone, receiverEmail, receiverAddress);
+        return ResponseHelper.success();
+    }
+
+
+    @GetMapping("/export")
+    @Operation(summary = "导出发票信息")
+    public void exportOrderTax(
+            @Parameter(description = "开票状态true:已开发票,false:未开,不传:所有的", required = false) @RequestParam(required = false) Boolean status,
+            @Parameter(description = "订单号", required = false) @RequestParam(required = false) String orderId,
+            HttpServletResponse response,
+            HttpServletRequest request
+    ) throws Exception {
+        orderTaxLogic.exportOrderTax(status, orderId, request, response);
+    }
+
+
+}

+ 138 - 10
src/main/java/com/gree/mall/contest/logic/order/OrderTaxLogic.java

@@ -1,17 +1,22 @@
 package com.gree.mall.contest.logic.order;
 
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.lang.TypeReference;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.gree.mall.contest.bean.ExcelData;
+import com.gree.mall.contest.bean.admin.AdminUserCom;
 import com.gree.mall.contest.bean.order.OrderDetailBean;
+import com.gree.mall.contest.bean.tax.OrderTaxExcelBean;
+import com.gree.mall.contest.bean.tax.RspOrderTax;
+import com.gree.mall.contest.commonmapper.CommonMapper;
 import com.gree.mall.contest.constant.Constant;
 import com.gree.mall.contest.exception.RemoteServiceException;
 import com.gree.mall.contest.logic.common.CommonLogic;
+import com.gree.mall.contest.plus.entity.GoodsCategory;
 import com.gree.mall.contest.plus.entity.OrderTax;
-import com.gree.mall.contest.plus.service.GoodsCategoryService;
-import com.gree.mall.contest.plus.service.GoodsService;
-import com.gree.mall.contest.plus.service.GoodsSpecService;
 import com.gree.mall.contest.plus.service.OrderTaxService;
 import com.gree.mall.contest.utils.RedisUtil;
 import com.gree.mall.contest.utils.email.EmailUtilsNew;
@@ -23,26 +28,28 @@ import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.hssf.usermodel.HSSFFont;
 import org.apache.poi.ss.usermodel.IndexedColors;
 import org.apache.poi.xssf.usermodel.*;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import java.io.*;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.stream.Collectors;
 
 @Service
 @Slf4j
 @RequiredArgsConstructor
 public class OrderTaxLogic {
     private final OrderTaxService orderTaxService;
-    private final GoodsService goodsService;
-    private final GoodsSpecService goodsSpecService;
-    private final GoodsCategoryService goodsCategoryService;
     private final RedisUtil redisUtil;
     private final CommonLogic commonLogic;
-    OrderLogic orderLogic;
+    private final CommonMapper commonMapper;
+    private final OrderLogic orderLogic;
     @Value("${tax.token.appid}")
     private String clientId;
     @Value("${tax.token.appSecret}")
@@ -81,7 +88,7 @@ public class OrderTaxLogic {
         return orderTaxBean;
     }
 
-    public void updateTax(OrderTax orderTaxBean) {
+    public void miniUpdateTax(OrderTax orderTaxBean) {
         orderTaxService.lambdaUpdate().eq(OrderTax::getOrderTaxId, orderTaxBean.getOrderTaxId())
                 .set(StringUtils.isNotBlank(orderTaxBean.getAccount()), OrderTax::getAccount, orderTaxBean.getAccount())
                 .set(orderTaxBean.getType() != null, OrderTax::getType, orderTaxBean.getType())
@@ -118,10 +125,11 @@ public class OrderTaxLogic {
     }
 
 
-    public IPage<OrderTax> page(String userId, Integer pageNum, Integer pageSize) {
+    public IPage<OrderTax> miniPage(String userId, Integer pageNum, Integer pageSize) {
         return orderTaxService.lambdaQuery()
                 .eq(StringUtils.isNotBlank(userId), OrderTax::getUserId, userId)
-                .orderByDesc(OrderTax::getCreateTime).page(new Page(pageNum, pageSize));
+                .orderByDesc(OrderTax::getCreateTime)
+                .page(new Page(pageNum, pageSize));
 
     }
 
@@ -306,5 +314,125 @@ public class OrderTaxLogic {
         }
     }
 
+    public void updateTax(String orderTaxId, String taxlink) {
+        orderTaxService.lambdaUpdate().eq(StringUtils.isNotBlank(orderTaxId), OrderTax::getOrderTaxId, orderTaxId)
+                .set(StringUtils.isNotBlank(taxlink), OrderTax::getTaxLink, taxlink)
+                .set(OrderTax::getStatus, true)
+                .update();
+    }
+
+
+    /**
+     * 线下处理发票
+     */
+    public void offline(String orderTaxId) throws RemoteServiceException {
+        OrderTax orderTax = orderTaxService.getById(orderTaxId);
+        if (!orderTax.getTaxType()) {
+            throw new RemoteServiceException("非专票不可处理");
+        }
+        orderTax.setStatus(true);
+        orderTax.updateById();
+    }
+
+
+    public IPage<RspOrderTax> page(Boolean status, String orderId, Integer pageNum, Integer pageSize, HttpServletRequest request) {
+        AdminUserCom adminUser = commonLogic.getAdminUser(request);
+
+        IPage page = orderTaxService.lambdaQuery()
+                .like(StringUtils.isNotEmpty(orderId), OrderTax::getOrderId, orderId)
+                .in(CollectionUtil.isNotEmpty(adminUser.getCompanyWechatIds()), OrderTax::getCompanyWechatId, adminUser.getCompanyWechatIds())
+                ////.//in(CollectionUtils.isNotEmpty(adminUser.getAdminWebsitIds()),OrderTax::getWebsitId,adminUser.getAdminWebsitIds())
+                .eq(status != null, OrderTax::getStatus, status)
+                .orderByDesc(OrderTax::getCreateTime).page(new Page(pageNum, pageSize));
+
+        List<RspOrderTax> list = new ArrayList<>();
+        for (Object o : page.getRecords()) {
+            OrderTax tax = (OrderTax) o;
+            RspOrderTax rspOrderTax = new RspOrderTax();
+            BeanUtils.copyProperties(tax, rspOrderTax);
+            List<GoodsCategory> goodsCategories = commonMapper.queryGoodsCategoryByOrderId(tax.getOrderId());
+            if (goodsCategories.size() == 0) {
+                continue;
+            }
+            List<String> categoryNames = goodsCategories.stream().map(GoodsCategory::getName).distinct().collect(Collectors.toList());
+            rspOrderTax.setCategoryNames(StringUtils.join(categoryNames, ","));
+            list.add(rspOrderTax);
+        }
+        page.setRecords(list);
+        return page;
+    }
+
+    public void updateInfo(String orderTaxId, String name, String taxNo, String receiverName, String receiverPhone, String receiveEmail, String receiverAddress) throws RemoteServiceException {
 
+        //判断是否允许修改,已开票的不许修改
+        OrderTax orderTax = orderTaxService.getById(orderTaxId);
+        if (!orderTax.getStatus()) {
+            throw new RemoteServiceException("已开票的不许修改");
+        }
+        //修改
+        orderTaxService.lambdaUpdate()
+                .eq(OrderTax::getStatus, false)
+                .eq(OrderTax::getOrderTaxId, orderTaxId)
+                .set(StringUtils.isNotEmpty(name), OrderTax::getName, name)
+                .set(StringUtils.isNotEmpty(taxNo), OrderTax::getTaxNo, taxNo)
+                .set(StringUtils.isNotEmpty(receiverName), OrderTax::getReceiverName, receiverName)
+                .set(StringUtils.isNotEmpty(receiverPhone), OrderTax::getReceiverPhone, receiverPhone)
+                .set(StringUtils.isNotEmpty(receiveEmail), OrderTax::getReceiverEmail, receiveEmail)
+                .set(StringUtils.isNotEmpty(receiverAddress), OrderTax::getReceiverAddress, receiverAddress)
+                .update();
+    }
+
+    public void exportOrderTax(Boolean status, String orderId, HttpServletRequest request, HttpServletResponse response) throws Exception {
+
+        AdminUserCom adminUser = commonLogic.getAdminUser(request);
+        List<String> companyWechatIds = adminUser.getCompanyWechatIds();
+        List<String> adminWebsitIds = adminUser.getAdminWebsitIds();
+
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
+        List<List<Object>> rowList = new ArrayList<>();
+
+        ExcelData excelData = new ExcelData();
+        excelData.setRows(rowList);
+        excelData.setName("发票");
+        excelData.setTitles(
+                Arrays.asList(
+                        "发票编号", "订单编号", "用户编号", "公司/个人", "专票/普票", "公司名称或个人名", "纳税人识别号",
+                        "公司注册地址", "公司注册电话", "开户银行", "银行账号", "接收电话", "接收邮箱", "收票人名称",
+                        "收票人地址", "发票内容", "已开票/未开票", "电子发票下载链接", "创建时间", "商品分类", "订单支付时间"
+                )
+        );
+        adminWebsitIds = null;
+        List<OrderTaxExcelBean> orderTaxExcelBeanList = commonMapper.queryOrderTaxExcelMsg(companyWechatIds, adminWebsitIds, status, orderId);
+        for (OrderTaxExcelBean orderTaxExcelBean : orderTaxExcelBeanList
+        ) {
+            List<Object> row = new ArrayList<>();
+            rowList.add(row);
+
+            row.add(orderTaxExcelBean.getOrderTaxId());
+            row.add(orderTaxExcelBean.getOrderId());
+            row.add(orderTaxExcelBean.getUserId());
+            row.add(orderTaxExcelBean.getType() == null ? "" : (orderTaxExcelBean.getType() ? "公司" : "个人"));
+            row.add(orderTaxExcelBean.getTaxType() == null ? "" : (orderTaxExcelBean.getTaxType() ? "专票" : "普票"));
+            row.add(orderTaxExcelBean.getName());
+            row.add(orderTaxExcelBean.getTaxNo());
+            row.add(orderTaxExcelBean.getRegisterAddress());
+            row.add(orderTaxExcelBean.getRegisterPhone());
+            row.add(orderTaxExcelBean.getBank());
+            row.add(orderTaxExcelBean.getAccount());
+            row.add(orderTaxExcelBean.getReceiverPhone());
+            row.add(orderTaxExcelBean.getReceiverEmail());
+            row.add(orderTaxExcelBean.getReceiverName());
+            row.add(orderTaxExcelBean.getReceiverAddress());
+            row.add(orderTaxExcelBean.getContent());
+            row.add(orderTaxExcelBean.getStatus() == null ? "" : (orderTaxExcelBean.getStatus() ? "已开" : "待开"));
+            row.add(orderTaxExcelBean.getTaxLink());
+            row.add(orderTaxExcelBean.getCreateTime() == null ? "" : DateUtil.formatDate(orderTaxExcelBean.getCreateTime()));
+            row.add(orderTaxExcelBean.getCategoryNames());
+            row.add(orderTaxExcelBean.getPayTime() == null ? "" : DateUtil.formatDate(orderTaxExcelBean.getPayTime()));
+        }
+
+
+        ExcelUtils.exportExcel(request, response, String.format("发票导出%s.xlsx", simpleDateFormat.format(new Date())), excelData);
+
+    }
 }

+ 40 - 0
src/main/resources/mapper/CommonMapper.xml

@@ -118,5 +118,45 @@
         </if>
         ${ex.orderBy}
     </select>
+    <select id="queryGoodsCategoryByOrderId" resultType="com.gree.mall.contest.plus.entity.GoodsCategory">
+        select c.* from order_detail a
+                            join goods b on a.goods_id = b.goods_id
+                            join goods_category c on c.category_id = b.category_id
+        where a.order_id=#{orderId}
+    </select>
+    <select id="queryOrderTaxExcelMsg" resultType="com.gree.mall.contest.bean.tax.OrderTaxExcelBean">
+        SELECT
+        ot.* ,
+        GROUP_CONCAT(gc.name) as categoryNames,
+        a.pay_time
+        from order_tax ot
+        left join order_info a on a.order_id = ot.order_id
+        LEFT JOIN order_detail od on od.order_id=ot.order_id
+        LEFT JOIN goods g on g.goods_id=od.goods_id
+        LEFT JOIN goods_category gc on gc.category_id=g.category_id
+        <where>
+            gc.category_id is not null
+            <if test="status != null">
+                and ot.status = #{status}
+            </if>
+            <if test="orderId != null">
+                and ot.order_id like concat('%',#{orderId},'%')
+            </if>
+            <if test="companyWechatIds != null and companyWechatIds.size > 0">
+                and ot.company_wechat_id in
+                <foreach item="item" index="index" collection="companyWechatIds" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="adminWebsitIds != null and adminWebsitIds.size > 0">
+                and ot.websit_id in
+                <foreach item="item" index="index" collection="adminWebsitIds" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+            </if>
+        </where>
+        GROUP BY ot.order_tax_id
+        ORDER BY ot.create_time DESC
+    </select>
 
 </mapper>