feat: 开票管理与品牌/收款码同源出图
All checks were successful
Build and Deploy / deploy (push) Successful in 1m20s

新增发票申请/抬头/审批接入,并将品牌 Logo、收款码改为 API 同源文件地址,避免浏览器直连 COS 证书域名失败。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zzh 2026-11-21 11:55:34 +08:00
parent 7940b50edf
commit b8b18c4f59
21 changed files with 2654 additions and 26 deletions

79
db.sql
View File

@ -75,6 +75,9 @@ DROP TABLE IF EXISTS `t_employee`;
DROP TABLE IF EXISTS `t_dict_type`; DROP TABLE IF EXISTS `t_dict_type`;
DROP TABLE IF EXISTS `t_dict`; DROP TABLE IF EXISTS `t_dict`;
DROP TABLE IF EXISTS `t_country`; DROP TABLE IF EXISTS `t_country`;
DROP TABLE IF EXISTS `t_invoice_apply_line`;
DROP TABLE IF EXISTS `t_invoice_apply`;
DROP TABLE IF EXISTS `t_customer_invoice_profile`;
DROP TABLE IF EXISTS `t_recharge_record`; DROP TABLE IF EXISTS `t_recharge_record`;
DROP TABLE IF EXISTS `t_customer`; DROP TABLE IF EXISTS `t_customer`;
DROP TABLE IF EXISTS `t_label_print_record`; DROP TABLE IF EXISTS `t_label_print_record`;
@ -1141,6 +1144,82 @@ CREATE TABLE `t_recharge_record` (
KEY `idx_rr_audit_time` (`AuditTime`) KEY `idx_rr_audit_time` (`AuditTime`)
) COMMENT='充值记录表'; ) COMMENT='充值记录表';
CREATE TABLE `t_customer_invoice_profile` (
`Id` INT NOT NULL AUTO_INCREMENT COMMENT '主键',
`CustomerId` INT NOT NULL COMMENT '客户 ID',
`TitleName` VARCHAR(128) NOT NULL COMMENT '发票抬头',
`TaxNo` VARCHAR(64) NOT NULL COMMENT '税号',
`AddressPhone` VARCHAR(256) NULL COMMENT '地址电话',
`BankNameAccount` VARCHAR(256) NULL COMMENT '开户行及账号',
`IsDefault` TINYINT NOT NULL DEFAULT 0 COMMENT '是否默认:0-否,1-是',
`Remark` VARCHAR(512) NULL COMMENT '备注',
`IsDeleted` TINYINT NOT NULL DEFAULT 0 COMMENT '软删除:0-否,1-是',
`ConcurrencyStamp` CHAR(36) NOT NULL DEFAULT (UUID()) COMMENT '并发戳',
`CreateUserId` INT NOT NULL DEFAULT 0 COMMENT '创建人',
`CreateTime` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`UpdateUserId` INT NULL COMMENT '更新人',
`UpdateTime` DATETIME NULL COMMENT '更新时间',
PRIMARY KEY (`Id`),
KEY `ix_inv_profile_customer` (`CustomerId`)
) COMMENT='客户发票抬头';
CREATE TABLE `t_invoice_apply` (
`Id` INT NOT NULL AUTO_INCREMENT COMMENT '主键',
`ApplyNo` VARCHAR(32) NOT NULL COMMENT '申请单号 INV+yyyyMMdd+序号',
`CustomerId` INT NOT NULL COMMENT '客户 ID',
`InvoiceType` VARCHAR(16) NOT NULL DEFAULT 'normal' COMMENT '发票类型:normal 普票 / special 专票',
`Medium` VARCHAR(16) NOT NULL DEFAULT 'electronic' COMMENT '介质:electronic 电子 / paper 纸质',
`TitleName` VARCHAR(128) NOT NULL COMMENT '发票抬头快照',
`TaxNo` VARCHAR(64) NOT NULL COMMENT '税号快照',
`AddressPhone` VARCHAR(256) NULL COMMENT '地址电话快照',
`BankNameAccount` VARCHAR(256) NULL COMMENT '开户行及账号快照',
`AmountTotal` DECIMAL(18,2) NOT NULL DEFAULT 0.00 COMMENT '价税合计(含税)',
`TaxRate` DECIMAL(8,4) NOT NULL DEFAULT 0.0600 COMMENT '税率备注(含税金额不拆分)',
`Currency` VARCHAR(8) NOT NULL DEFAULT 'CNY' COMMENT '币种',
`Status` VARCHAR(32) NOT NULL DEFAULT 'draft' COMMENT 'draft/pendingApproval/approved/issued/rejected/voided/redFlushed',
`ApplicantSource` VARCHAR(16) NOT NULL DEFAULT 'admin' COMMENT '申请人来源:admin/customer',
`InvoiceCode` VARCHAR(64) NULL COMMENT '发票代码',
`InvoiceNumber` VARCHAR(64) NULL COMMENT '发票号码',
`InvoiceDate` DATETIME NULL COMMENT '开票日期',
`InvoicePdfUrl` VARCHAR(1024) NULL COMMENT '发票 PDF 地址',
`Remark` VARCHAR(512) NULL COMMENT '备注',
`ApprovalInstanceId` INT NULL COMMENT '审批实例 Id',
`ApprovalInstanceNo` VARCHAR(32) NULL COMMENT '审批单号',
`RejectReason` VARCHAR(512) NULL COMMENT '驳回原因',
`IssueTime` DATETIME NULL COMMENT '开票时间',
`IssueBy` VARCHAR(64) NULL COMMENT '开票人',
`IsDeleted` TINYINT NOT NULL DEFAULT 0 COMMENT '软删除:0-否,1-是',
`ConcurrencyStamp` CHAR(36) NOT NULL DEFAULT (UUID()) COMMENT '并发戳',
`CreateUserId` INT NOT NULL DEFAULT 0 COMMENT '创建人',
`CreateTime` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`UpdateUserId` INT NULL COMMENT '更新人',
`UpdateTime` DATETIME NULL COMMENT '更新时间',
PRIMARY KEY (`Id`),
KEY `ix_inv_apply_customer` (`CustomerId`),
KEY `ix_inv_apply_no` (`ApplyNo`),
KEY `ix_inv_apply_status` (`Status`)
) COMMENT='发票申请';
CREATE TABLE `t_invoice_apply_line` (
`Id` INT NOT NULL AUTO_INCREMENT COMMENT '主键',
`InvoiceApplyId` INT NOT NULL COMMENT '发票申请 Id',
`SourceType` VARCHAR(32) NOT NULL COMMENT '来源:parcelOrder/pickupOrder/storageRent',
`SourceId` INT NOT NULL COMMENT '来源单据 Id',
`SourceNo` VARCHAR(64) NOT NULL COMMENT '来源单号',
`Amount` DECIMAL(18,2) NOT NULL DEFAULT 0.00 COMMENT '本行开票金额(含税)',
`Currency` VARCHAR(8) NOT NULL DEFAULT 'CNY' COMMENT '币种',
`Remark` VARCHAR(512) NULL COMMENT '备注',
`IsDeleted` TINYINT NOT NULL DEFAULT 0 COMMENT '软删除:0-否,1-是',
`ConcurrencyStamp` CHAR(36) NOT NULL DEFAULT (UUID()) COMMENT '并发戳',
`CreateUserId` INT NOT NULL DEFAULT 0 COMMENT '创建人',
`CreateTime` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`UpdateUserId` INT NULL COMMENT '更新人',
`UpdateTime` DATETIME NULL COMMENT '更新时间',
PRIMARY KEY (`Id`),
KEY `ix_inv_line_apply` (`InvoiceApplyId`),
KEY `ix_inv_line_source` (`SourceType`, `SourceId`)
) COMMENT='发票申请明细';
CREATE TABLE `t_country` ( CREATE TABLE `t_country` (
`Id` INT NOT NULL AUTO_INCREMENT COMMENT '主键,自增,步长 1', `Id` INT NOT NULL AUTO_INCREMENT COMMENT '主键,自增,步长 1',
`ChineseName` VARCHAR(128) NOT NULL COMMENT '国家中文名', `ChineseName` VARCHAR(128) NOT NULL COMMENT '国家中文名',

View File

@ -0,0 +1,112 @@
# migrate_invoice_manage_20261121.sql
# 发票管理:客户抬头 + 开票申请头/行(可重复执行)
# no UNIQUE KEY;单号/占用唯一性在 Application 校验
SET NAMES utf8mb4;
SET @db := DATABASE();
# t_customer_invoice_profile
SET @tbl := (
SELECT COUNT(1) FROM information_schema.TABLES
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 't_customer_invoice_profile'
);
SET @sql := IF(
@tbl = 0,
'CREATE TABLE `t_customer_invoice_profile` (
`Id` INT NOT NULL AUTO_INCREMENT COMMENT ''主键'',
`CustomerId` INT NOT NULL COMMENT ''客户 ID'',
`TitleName` VARCHAR(128) NOT NULL COMMENT ''发票抬头'',
`TaxNo` VARCHAR(64) NOT NULL COMMENT ''税号'',
`AddressPhone` VARCHAR(256) NULL COMMENT ''地址电话'',
`BankNameAccount` VARCHAR(256) NULL COMMENT ''开户行及账号'',
`IsDefault` TINYINT NOT NULL DEFAULT 0 COMMENT ''是否默认:0-否,1-是'',
`Remark` VARCHAR(512) NULL COMMENT ''备注'',
`IsDeleted` TINYINT NOT NULL DEFAULT 0 COMMENT ''软删除:0-否,1-是'',
`ConcurrencyStamp` CHAR(36) NOT NULL DEFAULT (UUID()) COMMENT ''并发戳'',
`CreateUserId` INT NOT NULL DEFAULT 0 COMMENT ''创建人'',
`CreateTime` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ''创建时间'',
`UpdateUserId` INT NULL COMMENT ''更新人'',
`UpdateTime` DATETIME NULL COMMENT ''更新时间'',
PRIMARY KEY (`Id`),
KEY `ix_inv_profile_customer` (`CustomerId`)
) COMMENT=''客户发票抬头''',
'SELECT 1'
);
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
# t_invoice_apply
SET @tbl := (
SELECT COUNT(1) FROM information_schema.TABLES
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 't_invoice_apply'
);
SET @sql := IF(
@tbl = 0,
'CREATE TABLE `t_invoice_apply` (
`Id` INT NOT NULL AUTO_INCREMENT COMMENT ''主键'',
`ApplyNo` VARCHAR(32) NOT NULL COMMENT ''申请单号 INV+yyyyMMdd+序号'',
`CustomerId` INT NOT NULL COMMENT ''客户 ID'',
`InvoiceType` VARCHAR(16) NOT NULL DEFAULT ''normal'' COMMENT ''发票类型:normal 普票 / special 专票'',
`Medium` VARCHAR(16) NOT NULL DEFAULT ''electronic'' COMMENT ''介质:electronic 电子 / paper 纸质'',
`TitleName` VARCHAR(128) NOT NULL COMMENT ''发票抬头快照'',
`TaxNo` VARCHAR(64) NOT NULL COMMENT ''税号快照'',
`AddressPhone` VARCHAR(256) NULL COMMENT ''地址电话快照'',
`BankNameAccount` VARCHAR(256) NULL COMMENT ''开户行及账号快照'',
`AmountTotal` DECIMAL(18,2) NOT NULL DEFAULT 0.00 COMMENT ''价税合计(含税)'',
`TaxRate` DECIMAL(8,4) NOT NULL DEFAULT 0.0600 COMMENT ''税率备注(含税金额不拆分)'',
`Currency` VARCHAR(8) NOT NULL DEFAULT ''CNY'' COMMENT ''币种'',
`Status` VARCHAR(32) NOT NULL DEFAULT ''draft'' COMMENT ''draft/pendingApproval/approved/issued/rejected/voided/redFlushed'',
`ApplicantSource` VARCHAR(16) NOT NULL DEFAULT ''admin'' COMMENT ''申请人来源:admin/customer'',
`InvoiceCode` VARCHAR(64) NULL COMMENT ''发票代码'',
`InvoiceNumber` VARCHAR(64) NULL COMMENT ''发票号码'',
`InvoiceDate` DATETIME NULL COMMENT ''开票日期'',
`InvoicePdfUrl` VARCHAR(1024) NULL COMMENT ''发票 PDF 地址'',
`Remark` VARCHAR(512) NULL COMMENT ''备注'',
`ApprovalInstanceId` INT NULL COMMENT ''审批实例 Id'',
`ApprovalInstanceNo` VARCHAR(32) NULL COMMENT ''审批单号'',
`RejectReason` VARCHAR(512) NULL COMMENT ''驳回原因'',
`IssueTime` DATETIME NULL COMMENT ''开票时间'',
`IssueBy` VARCHAR(64) NULL COMMENT ''开票人'',
`IsDeleted` TINYINT NOT NULL DEFAULT 0 COMMENT ''软删除:0-否,1-是'',
`ConcurrencyStamp` CHAR(36) NOT NULL DEFAULT (UUID()) COMMENT ''并发戳'',
`CreateUserId` INT NOT NULL DEFAULT 0 COMMENT ''创建人'',
`CreateTime` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ''创建时间'',
`UpdateUserId` INT NULL COMMENT ''更新人'',
`UpdateTime` DATETIME NULL COMMENT ''更新时间'',
PRIMARY KEY (`Id`),
KEY `ix_inv_apply_customer` (`CustomerId`),
KEY `ix_inv_apply_no` (`ApplyNo`),
KEY `ix_inv_apply_status` (`Status`)
) COMMENT=''发票申请''',
'SELECT 1'
);
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
# t_invoice_apply_line
SET @tbl := (
SELECT COUNT(1) FROM information_schema.TABLES
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 't_invoice_apply_line'
);
SET @sql := IF(
@tbl = 0,
'CREATE TABLE `t_invoice_apply_line` (
`Id` INT NOT NULL AUTO_INCREMENT COMMENT ''主键'',
`InvoiceApplyId` INT NOT NULL COMMENT ''发票申请 Id'',
`SourceType` VARCHAR(32) NOT NULL COMMENT ''来源:parcelOrder/pickupOrder/storageRent'',
`SourceId` INT NOT NULL COMMENT ''来源单据 Id'',
`SourceNo` VARCHAR(64) NOT NULL COMMENT ''来源单号'',
`Amount` DECIMAL(18,2) NOT NULL DEFAULT 0.00 COMMENT ''本行开票金额(含税)'',
`Currency` VARCHAR(8) NOT NULL DEFAULT ''CNY'' COMMENT ''币种'',
`Remark` VARCHAR(512) NULL COMMENT ''备注'',
`IsDeleted` TINYINT NOT NULL DEFAULT 0 COMMENT ''软删除:0-否,1-是'',
`ConcurrencyStamp` CHAR(36) NOT NULL DEFAULT (UUID()) COMMENT ''并发戳'',
`CreateUserId` INT NOT NULL DEFAULT 0 COMMENT ''创建人'',
`CreateTime` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ''创建时间'',
`UpdateUserId` INT NULL COMMENT ''更新人'',
`UpdateTime` DATETIME NULL COMMENT ''更新时间'',
PRIMARY KEY (`Id`),
KEY `ix_inv_line_apply` (`InvoiceApplyId`),
KEY `ix_inv_line_source` (`SourceType`, `SourceId`)
) COMMENT=''发票申请明细''',
'SELECT 1'
);
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;

View File

@ -0,0 +1,445 @@
namespace Oms.Application.Dtos.Finance;
/// <summary>
/// 发票抬头列表查询。
/// </summary>
public class InvoiceProfileListInput
{
/// <summary>客户主键;客户登录忽略入参,强制本客户。</summary>
public int? CustomerId { get; set; }
}
/// <summary>
/// 保存发票抬头。
/// </summary>
public class InvoiceProfileSaveInput
{
/// <summary>主键;空则新增。</summary>
public int? Id { get; set; }
/// <summary>客户主键(管理端必填)。</summary>
public int? CustomerId { get; set; }
/// <summary>发票抬头。</summary>
public string TitleName { get; set; } = string.Empty;
/// <summary>税号。</summary>
public string TaxNo { get; set; } = string.Empty;
/// <summary>地址电话。</summary>
public string? AddressPhone { get; set; }
/// <summary>开户行及账号。</summary>
public string? BankNameAccount { get; set; }
/// <summary>是否默认抬头。</summary>
public bool IsDefault { get; set; }
/// <summary>备注。</summary>
public string? Remark { get; set; }
}
/// <summary>
/// 发票抬头输出。
/// </summary>
public class InvoiceProfileOutput
{
/// <summary>主键。</summary>
public int Id { get; set; }
/// <summary>客户主键。</summary>
public int CustomerId { get; set; }
/// <summary>发票抬头。</summary>
public string TitleName { get; set; } = string.Empty;
/// <summary>税号。</summary>
public string TaxNo { get; set; } = string.Empty;
/// <summary>地址电话。</summary>
public string? AddressPhone { get; set; }
/// <summary>开户行及账号。</summary>
public string? BankNameAccount { get; set; }
/// <summary>是否默认抬头。</summary>
public bool IsDefault { get; set; }
/// <summary>备注。</summary>
public string? Remark { get; set; }
/// <summary>创建时间。</summary>
public DateTime CreateTime { get; set; }
/// <summary>更新时间。</summary>
public DateTime? UpdateTime { get; set; }
}
/// <summary>
/// 可开票来源查询。
/// </summary>
public class InvoiceSelectableInput
{
/// <summary>客户主键(管理端必填)。</summary>
public int? CustomerId { get; set; }
/// <summary>来源类型:parcelOrder / pickupOrder / storageRent;空则合并三类。</summary>
public string? SourceType { get; set; }
/// <summary>来源单号关键词。</summary>
public string? Keyword { get; set; }
/// <summary>页码,从 1 开始。</summary>
public int Page { get; set; } = 1;
/// <summary>每页条数。</summary>
public int PageSize { get; set; } = 50;
}
/// <summary>
/// 可开票来源行。
/// </summary>
public class InvoiceSelectableItemOutput
{
/// <summary>来源类型。</summary>
public string SourceType { get; set; } = string.Empty;
/// <summary>来源类型名称。</summary>
public string SourceTypeName { get; set; } = string.Empty;
/// <summary>来源单据 Id。</summary>
public int SourceId { get; set; }
/// <summary>来源单号。</summary>
public string SourceNo { get; set; } = string.Empty;
/// <summary>来源含税金额。</summary>
public decimal BaseAmount { get; set; }
/// <summary>已被占用金额(草稿/待审/已审/已开票)。</summary>
public decimal OccupiedAmount { get; set; }
/// <summary>剩余可开票金额。</summary>
public decimal RemainingAmount { get; set; }
/// <summary>币种,固定 CNY。</summary>
public string Currency { get; set; } = "CNY";
/// <summary>支付时间。</summary>
public DateTime? PaidTime { get; set; }
}
/// <summary>
/// 开票申请明细入参。
/// </summary>
public class InvoiceApplyLineInput
{
/// <summary>来源类型:parcelOrder / pickupOrder / storageRent。</summary>
public string SourceType { get; set; } = string.Empty;
/// <summary>来源单据 Id。</summary>
public int SourceId { get; set; }
/// <summary>本行开票金额(含税,允许小于剩余)。</summary>
public decimal Amount { get; set; }
/// <summary>行备注。</summary>
public string? Remark { get; set; }
}
/// <summary>
/// 新建开票申请。
/// </summary>
public class InvoiceApplyCreateInput
{
/// <summary>客户主键(管理端必填)。</summary>
public int? CustomerId { get; set; }
/// <summary>发票类型:normal / special。</summary>
public string InvoiceType { get; set; } = "normal";
/// <summary>介质:electronic / paper。</summary>
public string Medium { get; set; } = "electronic";
/// <summary>抬头 Id;有值则快照该抬头。</summary>
public int? ProfileId { get; set; }
/// <summary>发票抬头(未传 ProfileId 时必填)。</summary>
public string? TitleName { get; set; }
/// <summary>税号(未传 ProfileId 时必填)。</summary>
public string? TaxNo { get; set; }
/// <summary>地址电话(专票必填)。</summary>
public string? AddressPhone { get; set; }
/// <summary>开户行及账号(专票必填)。</summary>
public string? BankNameAccount { get; set; }
/// <summary>税率备注,默认 0.06。</summary>
public decimal? TaxRate { get; set; }
/// <summary>备注。</summary>
public string? Remark { get; set; }
/// <summary>为 true 时创建后立即提交审批。</summary>
public bool Submit { get; set; }
/// <summary>开票明细。</summary>
public List<InvoiceApplyLineInput> Lines { get; set; } = [];
}
/// <summary>
/// 更新开票申请(仅草稿)。
/// </summary>
public class InvoiceApplyUpdateInput : InvoiceApplyCreateInput
{
/// <summary>申请主键。</summary>
public int Id { get; set; }
}
/// <summary>
/// 提交 / 作废等按 Id 操作。
/// </summary>
public class InvoiceApplyIdInput
{
/// <summary>申请主键。</summary>
public int Id { get; set; }
}
/// <summary>
/// 开票入参(仅已审批)。
/// </summary>
public class InvoiceApplyIssueInput
{
/// <summary>申请主键。</summary>
public int Id { get; set; }
/// <summary>发票代码。</summary>
public string? InvoiceCode { get; set; }
/// <summary>发票号码。</summary>
public string InvoiceNumber { get; set; } = string.Empty;
/// <summary>开票日期;空则取当前时间。</summary>
public DateTime? InvoiceDate { get; set; }
/// <summary>发票 PDF 地址。</summary>
public string? InvoicePdfUrl { get; set; }
/// <summary>备注。</summary>
public string? Remark { get; set; }
}
/// <summary>
/// 作废入参。
/// </summary>
public class InvoiceApplyVoidInput
{
/// <summary>申请主键。</summary>
public int Id { get; set; }
/// <summary>作废原因。</summary>
public string? Remark { get; set; }
}
/// <summary>
/// 开票申请分页查询。
/// </summary>
public class InvoiceApplyListInput
{
/// <summary>页码,从 1 开始。</summary>
public int Page { get; set; } = 1;
/// <summary>每页条数。</summary>
public int PageSize { get; set; } = 50;
/// <summary>客户主键。</summary>
public int? CustomerId { get; set; }
/// <summary>状态。</summary>
public string? Status { get; set; }
/// <summary>发票类型。</summary>
public string? InvoiceType { get; set; }
/// <summary>申请单号 / 发票号 / 抬头关键词。</summary>
public string? Keyword { get; set; }
/// <summary>创建时间起。</summary>
public DateTime? StartTime { get; set; }
/// <summary>创建时间止。</summary>
public DateTime? EndTime { get; set; }
}
/// <summary>
/// 导出入参。
/// </summary>
public class InvoiceExportInput
{
/// <summary>客户主键。</summary>
public int? CustomerId { get; set; }
/// <summary>状态。</summary>
public string? Status { get; set; }
/// <summary>发票类型。</summary>
public string? InvoiceType { get; set; }
/// <summary>申请单号 / 发票号 / 抬头关键词。</summary>
public string? Keyword { get; set; }
/// <summary>创建时间起。</summary>
public DateTime? StartTime { get; set; }
/// <summary>创建时间止。</summary>
public DateTime? EndTime { get; set; }
}
/// <summary>
/// 开票申请明细输出。
/// </summary>
public class InvoiceApplyLineOutput
{
/// <summary>明细主键。</summary>
public int Id { get; set; }
/// <summary>来源类型。</summary>
public string SourceType { get; set; } = string.Empty;
/// <summary>来源类型名称。</summary>
public string SourceTypeName { get; set; } = string.Empty;
/// <summary>来源单据 Id。</summary>
public int SourceId { get; set; }
/// <summary>来源单号。</summary>
public string SourceNo { get; set; } = string.Empty;
/// <summary>本行含税金额。</summary>
public decimal Amount { get; set; }
/// <summary>币种。</summary>
public string Currency { get; set; } = "CNY";
/// <summary>行备注。</summary>
public string? Remark { get; set; }
}
/// <summary>
/// 开票申请列表行。
/// </summary>
public class InvoiceApplyListOutput
{
/// <summary>主键。</summary>
public int Id { get; set; }
/// <summary>申请单号。</summary>
public string ApplyNo { get; set; } = string.Empty;
/// <summary>客户主键。</summary>
public int CustomerId { get; set; }
/// <summary>客户编码。</summary>
public string? CustomerCode { get; set; }
/// <summary>客户名称。</summary>
public string? CustomerName { get; set; }
/// <summary>发票类型。</summary>
public string InvoiceType { get; set; } = string.Empty;
/// <summary>发票类型名称。</summary>
public string InvoiceTypeName { get; set; } = string.Empty;
/// <summary>介质。</summary>
public string Medium { get; set; } = string.Empty;
/// <summary>介质名称。</summary>
public string MediumName { get; set; } = string.Empty;
/// <summary>发票抬头。</summary>
public string TitleName { get; set; } = string.Empty;
/// <summary>税号。</summary>
public string TaxNo { get; set; } = string.Empty;
/// <summary>价税合计(含税)。</summary>
public decimal AmountTotal { get; set; }
/// <summary>税率备注。</summary>
public decimal TaxRate { get; set; }
/// <summary>币种。</summary>
public string Currency { get; set; } = "CNY";
/// <summary>状态。</summary>
public string Status { get; set; } = string.Empty;
/// <summary>状态名称。</summary>
public string StatusName { get; set; } = string.Empty;
/// <summary>申请人来源。</summary>
public string ApplicantSource { get; set; } = string.Empty;
/// <summary>发票代码。</summary>
public string? InvoiceCode { get; set; }
/// <summary>发票号码。</summary>
public string? InvoiceNumber { get; set; }
/// <summary>开票日期。</summary>
public DateTime? InvoiceDate { get; set; }
/// <summary>发票 PDF。</summary>
public string? InvoicePdfUrl { get; set; }
/// <summary>备注。</summary>
public string? Remark { get; set; }
/// <summary>审批实例 Id。</summary>
public int? ApprovalInstanceId { get; set; }
/// <summary>审批单号。</summary>
public string? ApprovalInstanceNo { get; set; }
/// <summary>是否存在在途审批。</summary>
public bool ApprovalPending { get; set; }
/// <summary>驳回原因。</summary>
public string? RejectReason { get; set; }
/// <summary>开票时间。</summary>
public DateTime? IssueTime { get; set; }
/// <summary>开票人。</summary>
public string? IssueBy { get; set; }
/// <summary>创建时间。</summary>
public DateTime CreateTime { get; set; }
/// <summary>更新时间。</summary>
public DateTime? UpdateTime { get; set; }
}
/// <summary>
/// 开票申请详情。
/// </summary>
public class InvoiceApplyDetailOutput : InvoiceApplyListOutput
{
/// <summary>地址电话。</summary>
public string? AddressPhone { get; set; }
/// <summary>开户行及账号。</summary>
public string? BankNameAccount { get; set; }
/// <summary>审批门面判定:Bypass / PendingApproval。</summary>
public string? Decision { get; set; }
/// <summary>提交结果说明。</summary>
public string? Message { get; set; }
/// <summary>开票明细。</summary>
public List<InvoiceApplyLineOutput> Lines { get; set; } = [];
}

View File

@ -6,22 +6,22 @@ namespace Oms.Application.Dtos.System;
public class BrandLogoOutput public class BrandLogoOutput
{ {
/// <summary> /// <summary>
/// 系统顶栏 Logo 可访问 URL;未配置时为空。 /// 系统顶栏 Logo 同源 API 地址(/system/other-config/brand-logo/file?...);未配置时为空。
/// </summary> /// </summary>
public string PortalUrl { get; set; } = string.Empty; public string PortalUrl { get; set; } = string.Empty;
/// <summary> /// <summary>
/// 官网 Logo 可访问 URL;未配置时为空。 /// 官网 Logo 同源 API 地址;未配置时为空。
/// </summary> /// </summary>
public string SiteUrl { get; set; } = string.Empty; public string SiteUrl { get; set; } = string.Empty;
/// <summary> /// <summary>
/// 网站标签(favicon)可访问 URL;未配置时为空。 /// 网站标签(favicon)同源 API 地址;未配置时为空。
/// </summary> /// </summary>
public string FaviconUrl { get; set; } = string.Empty; public string FaviconUrl { get; set; } = string.Empty;
/// <summary> /// <summary>
/// 启动页 / 空态吉祥物可访问 URL;未配置时为空。 /// 启动页 / 空态吉祥物同源 API 地址;未配置时为空。
/// </summary> /// </summary>
public string MascotUrl { get; set; } = string.Empty; public string MascotUrl { get; set; } = string.Empty;
} }

View File

@ -6,12 +6,12 @@ namespace Oms.Application.Dtos.System;
public class PaymentReceiveQrOutput public class PaymentReceiveQrOutput
{ {
/// <summary> /// <summary>
/// 支付宝收款码可访问 URL;未配置时为空。 /// 支付宝收款码同源 API 地址(/system/other-config/payment-qr/file?...);未配置时为空。
/// </summary> /// </summary>
public string AlipayUrl { get; set; } = string.Empty; public string AlipayUrl { get; set; } = string.Empty;
/// <summary> /// <summary>
/// 微信收款码可访问 URL;未配置时为空。 /// 微信收款码同源 API 地址;未配置时为空。
/// </summary> /// </summary>
public string WechatUrl { get; set; } = string.Empty; public string WechatUrl { get; set; } = string.Empty;
} }

View File

@ -15,6 +15,7 @@ using Oms.Application.Labeling.Hiprint;
using Oms.Application.Services.Approval; using Oms.Application.Services.Approval;
using Oms.Application.Services.Approval.Contracts; using Oms.Application.Services.Approval.Contracts;
using Oms.Application.Services.Channels; using Oms.Application.Services.Channels;
using Oms.Application.Services.Finance;
using Oms.Application.Services.Recharge; using Oms.Application.Services.Recharge;
using Oms.Application.Services.Storage; using Oms.Application.Services.Storage;
using Oms.Application.Shared; using Oms.Application.Shared;
@ -63,6 +64,7 @@ public class OmsApplicationModule : FakeModule
// 否则 Approve 会空跑成 Executed、不落发布/入账。 // 否则 Approve 会空跑成 Executed、不落发布/入账。
context.Services.AddTransient<IApprovalOperationHandler, SalesProductPricePublishApprovalHandler>(); context.Services.AddTransient<IApprovalOperationHandler, SalesProductPricePublishApprovalHandler>();
context.Services.AddTransient<IApprovalOperationHandler, RechargeCreditApprovalHandler>(); context.Services.AddTransient<IApprovalOperationHandler, RechargeCreditApprovalHandler>();
context.Services.AddTransient<IApprovalOperationHandler, InvoiceIssueApprovalHandler>();
context.Services.AddTransient<IApprovalOperationHandler, NoopApprovalHandler>(); context.Services.AddTransient<IApprovalOperationHandler, NoopApprovalHandler>();
context.Services.AddHttpClient(FileStorageService.UrlFetchClientName, client => context.Services.AddHttpClient(FileStorageService.UrlFetchClientName, client =>

View File

@ -31,6 +31,12 @@ public static class ApprovalOperationCatalog
"Finance", "Finance",
SupportsCondition: false, SupportsCondition: false,
ConditionHint: "已接入提交接口;未配置或未启用不拦截(直接入账),启用后提交审批"), ConditionHint: "已接入提交接口;未配置或未启用不拦截(直接入账),启用后提交审批"),
new(
ApprovalCodes.FinanceInvoiceIssue,
"发票开具",
"Finance",
SupportsCondition: false,
ConditionHint: "已接入提交接口;未配置或未启用不拦截(直接通过),启用后提交审批"),
new( new(
"Marketing.Commission.Withdraw", "Marketing.Commission.Withdraw",
"佣金提现", "佣金提现",

View File

@ -0,0 +1,150 @@
using System.Text.Json;
using Fake.Application;
using Fake.DependencyInjection;
using Oms.Application.Services.Approval.Contracts;
using Oms.Domain.ApprovalAggregate.Consts;
using Oms.Domain.FinanceAggregate.Consts;
using Oms.Domain.FinanceAggregate.Entities;
using Oms.Domain.FinanceAggregate.Repositories;
namespace Oms.Application.Services.Finance;
/// <summary>
/// 发票开具审批:通过后置为已审批待开票;驳回置 rejected;撤回置 draft。
/// </summary>
[ExposeServices(typeof(IApprovalOperationHandler))]
public class InvoiceIssueApprovalHandler(
IInvoiceApplyRepository invoiceApplyRepository) : IApprovalOperationHandler, ITransientDependency
{
private static readonly JsonSerializerOptions JsonOptions = new()
{
PropertyNameCaseInsensitive = true
};
/// <inheritdoc />
public string OperationCode => ApprovalCodes.FinanceInvoiceIssue;
/// <inheritdoc />
public async Task ExecuteAsync(ApprovalExecutionContext context, CancellationToken cancellationToken = default)
{
var apply = await GetApplyOrThrowAsync(context, cancellationToken);
if (apply.Status == InvoiceStatusCodes.Approved || apply.Status == InvoiceStatusCodes.Issued)
{
return;
}
if (apply.Status != InvoiceStatusCodes.PendingApproval)
{
throw new BusinessException("只有待审批的发票申请才能审批通过");
}
apply.Status = InvoiceStatusCodes.Approved;
apply.ApprovalInstanceId = context.InstanceId;
apply.ApprovalInstanceNo = context.InstanceNo;
apply.RejectReason = null;
await invoiceApplyRepository.UpdateAsync(apply, cancellationToken);
}
/// <inheritdoc />
public async Task OnRejectedAsync(
ApprovalExecutionContext context,
string? comment,
CancellationToken cancellationToken = default)
{
var apply = await TryGetPendingApplyAsync(context, cancellationToken);
if (apply == null)
{
return;
}
apply.Status = InvoiceStatusCodes.Rejected;
apply.RejectReason = string.IsNullOrWhiteSpace(comment)
? $"审批驳回 {context.InstanceNo}".Trim()
: comment.Trim();
apply.ApprovalInstanceId = context.InstanceId;
apply.ApprovalInstanceNo = context.InstanceNo;
await invoiceApplyRepository.UpdateAsync(apply, cancellationToken);
}
/// <inheritdoc />
public async Task OnWithdrawnAsync(
ApprovalExecutionContext context,
string? comment,
CancellationToken cancellationToken = default)
{
var apply = await TryGetPendingApplyAsync(context, cancellationToken);
if (apply == null)
{
return;
}
apply.Status = InvoiceStatusCodes.Draft;
apply.RejectReason = null;
apply.ApprovalInstanceId = context.InstanceId;
apply.ApprovalInstanceNo = context.InstanceNo;
if (!string.IsNullOrWhiteSpace(comment))
{
apply.Remark = comment.Trim();
}
await invoiceApplyRepository.UpdateAsync(apply, cancellationToken);
}
private async Task<InvoiceApply> GetApplyOrThrowAsync(
ApprovalExecutionContext context,
CancellationToken cancellationToken)
{
var applyId = ResolveApplyId(context);
return await invoiceApplyRepository.FirstOrDefaultAsync(x => x.Id == applyId, cancellationToken)
?? throw new BusinessException("发票申请不存在");
}
private async Task<InvoiceApply?> TryGetPendingApplyAsync(
ApprovalExecutionContext context,
CancellationToken cancellationToken)
{
var applyId = ResolveApplyId(context);
var apply = await invoiceApplyRepository.FirstOrDefaultAsync(x => x.Id == applyId, cancellationToken);
if (apply == null || apply.Status != InvoiceStatusCodes.PendingApproval)
{
return null;
}
return apply;
}
private static int ResolveApplyId(ApprovalExecutionContext context)
{
if (!string.IsNullOrWhiteSpace(context.PayloadJson))
{
try
{
var payload = JsonSerializer.Deserialize<InvoiceIssuePayload>(context.PayloadJson, JsonOptions);
if (payload is { InvoiceApplyId: > 0 })
{
return payload.InvoiceApplyId;
}
}
catch
{
// fall through BizKey
}
}
var bizKey = context.BizKey ?? string.Empty;
var prefix = $"{ApprovalCodes.FinanceInvoiceIssue}:";
if (bizKey.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)
&& int.TryParse(bizKey[prefix.Length..], out var id)
&& id > 0)
{
return id;
}
throw new BusinessException("发票审批载荷缺少申请 Id");
}
private sealed class InvoiceIssuePayload
{
public int InvoiceApplyId { get; set; }
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,5 @@
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Text.RegularExpressions;
using Fake.Application; using Fake.Application;
using Fake.ObjectStorage; using Fake.ObjectStorage;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
@ -152,17 +153,40 @@ public class SystemOtherConfigService : ApplicationService
} }
/// <summary> /// <summary>
/// 获取客户充值用支付宝/微信收款码图片地址。未配置时对应 URL 为空(前端可回退本地默认图)。 /// 获取客户充值用支付宝/微信收款码图片地址。
/// 返回同源 API 文件地址(非 COS 直链),未配置时对应 URL 为空(前端可回退本地默认图)。
/// </summary> /// </summary>
[HttpGet("/system/other-config/payment-qr")] [HttpGet("/system/other-config/payment-qr")]
public async Task<PaymentReceiveQrOutput> GetPaymentReceiveQrAsync() public async Task<PaymentReceiveQrOutput> GetPaymentReceiveQrAsync()
{ {
var entity = await SystemOtherConfigRepository.GetByConfigCodeAsync(SystemOtherConfigCodes.PaymentReceiveQr); var entity = await SystemOtherConfigRepository.GetByConfigCodeAsync(SystemOtherConfigCodes.PaymentReceiveQr);
return new PaymentReceiveQrOutput return MapPaymentReceiveQrOutput(entity);
}
/// <summary>
/// 按渠道输出收款码图片字节(同源,避免浏览器直连 COS 证书域名)。
/// 收款码本身用于对客展示,允许匿名读取以便 &lt;img src&gt; 无需带 Authorization。
/// </summary>
/// <param name="channel">alipay / wechat。</param>
/// <param name="v">缓存戳(来自 object key),可选。</param>
/// <param name="cancellationToken">取消令牌。</param>
[AllowAnonymous]
[HttpGet("/system/other-config/payment-qr/file")]
public async Task<FileContentResult> GetPaymentReceiveQrFileAsync(
[FromQuery] string channel,
[FromQuery] string? v = null,
CancellationToken cancellationToken = default)
{
_ = v;
var normalized = (channel ?? string.Empty).Trim().ToLowerInvariant();
if (normalized is not (PaymentQrChannelAlipay or PaymentQrChannelWechat))
{ {
AlipayUrl = FileStorage.GetPublicUrl(entity?.AppKey), throw new BusinessException("渠道仅支持 alipay 或 wechat");
WechatUrl = FileStorage.GetPublicUrl(entity?.Remark) }
};
var entity = await SystemOtherConfigRepository.GetByConfigCodeAsync(SystemOtherConfigCodes.PaymentReceiveQr);
var objectKey = normalized == PaymentQrChannelAlipay ? entity?.AppKey : entity?.Remark;
return await StreamManagedImageAsync(objectKey, cancellationToken);
} }
/// <summary> /// <summary>
@ -191,11 +215,7 @@ public class SystemOtherConfigService : ApplicationService
} }
await SystemOtherConfigRepository.UpdateAsync(entity); await SystemOtherConfigRepository.UpdateAsync(entity);
return new PaymentReceiveQrOutput return MapPaymentReceiveQrOutput(entity);
{
AlipayUrl = FileStorage.GetPublicUrl(entity.AppKey),
WechatUrl = FileStorage.GetPublicUrl(entity.Remark)
};
} }
/// <summary> /// <summary>
@ -222,15 +242,12 @@ public class SystemOtherConfigService : ApplicationService
} }
await SystemOtherConfigRepository.UpdateAsync(entity); await SystemOtherConfigRepository.UpdateAsync(entity);
return new PaymentReceiveQrOutput return MapPaymentReceiveQrOutput(entity);
{
AlipayUrl = FileStorage.GetPublicUrl(entity.AppKey),
WechatUrl = FileStorage.GetPublicUrl(entity.Remark)
};
} }
/// <summary> /// <summary>
/// 获取品牌 Logo(系统顶栏 / 官网 / 网站标签 / 启动页吉祥物)。未配置时对应 URL 为空(前端回退本地默认图)。匿名可读。 /// 获取品牌 Logo(系统顶栏 / 官网 / 网站标签 / 启动页吉祥物)。
/// 返回同源 API 文件地址(非 COS 直链);未配置时对应 URL 为空。匿名可读。
/// </summary> /// </summary>
[AllowAnonymous] [AllowAnonymous]
[HttpGet("/system/other-config/brand-logo")] [HttpGet("/system/other-config/brand-logo")]
@ -240,6 +257,41 @@ public class SystemOtherConfigService : ApplicationService
return MapBrandLogoOutput(entity); return MapBrandLogoOutput(entity);
} }
/// <summary>
/// 按渠道输出品牌 Logo 图片字节(同源,避免浏览器直连 COS)。启动页/登录页匿名可读。
/// </summary>
/// <param name="channel">portal / site / favicon / mascot。</param>
/// <param name="v">缓存戳(来自 object key),可选。</param>
/// <param name="cancellationToken">取消令牌。</param>
[AllowAnonymous]
[HttpGet("/system/other-config/brand-logo/file")]
public async Task<FileContentResult> GetBrandLogoFileAsync(
[FromQuery] string channel,
[FromQuery] string? v = null,
CancellationToken cancellationToken = default)
{
_ = v;
var normalized = (channel ?? string.Empty).Trim().ToLowerInvariant();
if (normalized is not (
BrandLogoChannelPortal
or BrandLogoChannelSite
or BrandLogoChannelFavicon
or BrandLogoChannelMascot))
{
throw new BusinessException("渠道仅支持 portal、site、favicon 或 mascot");
}
var entity = await SystemOtherConfigRepository.GetByConfigCodeAsync(SystemOtherConfigCodes.BrandLogo);
var objectKey = normalized switch
{
BrandLogoChannelPortal => entity?.AppKey,
BrandLogoChannelSite => entity?.Remark,
BrandLogoChannelFavicon => entity?.BaseUrl,
_ => entity?.AppSecret
};
return await StreamManagedImageAsync(objectKey, cancellationToken);
}
/// <summary> /// <summary>
/// 上传并替换品牌 Logo。Channel=portal|site|favicon|mascot;返回最新可访问 URL。 /// 上传并替换品牌 Logo。Channel=portal|site|favicon|mascot;返回最新可访问 URL。
/// </summary> /// </summary>
@ -325,12 +377,143 @@ public class SystemOtherConfigService : ApplicationService
private BrandLogoOutput MapBrandLogoOutput(SystemOtherConfig? entity) => private BrandLogoOutput MapBrandLogoOutput(SystemOtherConfig? entity) =>
new() new()
{ {
PortalUrl = FileStorage.GetPublicUrl(entity?.AppKey), PortalUrl = BuildSameOriginImageUrl("/system/other-config/brand-logo/file", BrandLogoChannelPortal, entity?.AppKey),
SiteUrl = FileStorage.GetPublicUrl(entity?.Remark), SiteUrl = BuildSameOriginImageUrl("/system/other-config/brand-logo/file", BrandLogoChannelSite, entity?.Remark),
FaviconUrl = FileStorage.GetPublicUrl(entity?.BaseUrl), FaviconUrl = BuildSameOriginImageUrl("/system/other-config/brand-logo/file", BrandLogoChannelFavicon, entity?.BaseUrl),
MascotUrl = FileStorage.GetPublicUrl(entity?.AppSecret) MascotUrl = BuildSameOriginImageUrl("/system/other-config/brand-logo/file", BrandLogoChannelMascot, entity?.AppSecret)
}; };
private PaymentReceiveQrOutput MapPaymentReceiveQrOutput(SystemOtherConfig? entity) =>
new()
{
AlipayUrl = BuildSameOriginImageUrl("/system/other-config/payment-qr/file", PaymentQrChannelAlipay, entity?.AppKey),
WechatUrl = BuildSameOriginImageUrl("/system/other-config/payment-qr/file", PaymentQrChannelWechat, entity?.Remark)
};
/// <summary>
/// 生成浏览器可直开的同源相对路径;object key 仍存库,物理文件可在 COS/Local,但不把 cos.* 签发给前端。
/// </summary>
private static string BuildSameOriginImageUrl(string path, string channel, string? objectKey)
{
if (string.IsNullOrWhiteSpace(objectKey) || objectKey == "0")
{
return string.Empty;
}
string logicalKey;
try
{
logicalKey = FileStoragePath.NormalizeKey(objectKey);
}
catch
{
return string.Empty;
}
if (string.IsNullOrWhiteSpace(logicalKey))
{
return string.Empty;
}
var stamp = Path.GetFileNameWithoutExtension(logicalKey.Replace('\\', '/'));
if (string.IsNullOrWhiteSpace(stamp))
{
stamp = Math.Abs(logicalKey.GetHashCode(StringComparison.Ordinal)).ToString("x");
}
return $"{path}?channel={Uri.EscapeDataString(channel)}&v={Uri.EscapeDataString(stamp)}";
}
private async Task<FileContentResult> StreamManagedImageAsync(
string? objectKey,
CancellationToken cancellationToken)
{
if (string.IsNullOrWhiteSpace(objectKey) || objectKey == "0")
{
throw new BusinessException("图片未配置");
}
string logicalKey;
try
{
logicalKey = FileStoragePath.NormalizeKey(objectKey);
}
catch
{
throw new BusinessException("图片路径无效");
}
foreach (var candidate in FileStoragePath.ExpandReadKeys(logicalKey))
{
try
{
if (!await FileStorage.ExistsAsync(candidate, cancellationToken))
{
continue;
}
await using var stream = await FileStorage.GetAsync(candidate, cancellationToken);
using var ms = new MemoryStream();
await stream.CopyToAsync(ms, cancellationToken);
var bytes = ms.ToArray();
if (bytes.Length <= 0)
{
continue;
}
return new FileContentResult(bytes, GuessImageMime(candidate))
{
FileDownloadName = Path.GetFileName(candidate.Replace('\\', '/'))
};
}
catch (UnauthorizedAccessException)
{
// try next key shape
}
catch (DirectoryNotFoundException)
{
}
catch (FileNotFoundException)
{
}
catch (IOException)
{
}
}
throw new BusinessException("图片不存在或无法读取");
}
private static string GuessImageMime(string pathOrKey)
{
if (Regex.IsMatch(pathOrKey, @"\.png(\?|#|$)", RegexOptions.IgnoreCase))
{
return "image/png";
}
if (Regex.IsMatch(pathOrKey, @"\.jpe?g(\?|#|$)", RegexOptions.IgnoreCase))
{
return "image/jpeg";
}
if (Regex.IsMatch(pathOrKey, @"\.webp(\?|#|$)", RegexOptions.IgnoreCase))
{
return "image/webp";
}
if (Regex.IsMatch(pathOrKey, @"\.gif(\?|#|$)", RegexOptions.IgnoreCase))
{
return "image/gif";
}
if (Regex.IsMatch(pathOrKey, @"\.bmp(\?|#|$)", RegexOptions.IgnoreCase))
{
return "image/bmp";
}
return "application/octet-stream";
}
private async Task<SystemOtherConfig> EnsurePaymentReceiveQrConfigAsync() private async Task<SystemOtherConfig> EnsurePaymentReceiveQrConfigAsync()
{ {
var entity = await SystemOtherConfigRepository.GetByConfigCodeAsync(SystemOtherConfigCodes.PaymentReceiveQr); var entity = await SystemOtherConfigRepository.GetByConfigCodeAsync(SystemOtherConfigCodes.PaymentReceiveQr);

View File

@ -40,6 +40,9 @@ public static class ApprovalCodes
/// <summary>客户充值入账。</summary> /// <summary>客户充值入账。</summary>
public const string FinanceRechargeCredit = "Finance.Recharge.Credit"; public const string FinanceRechargeCredit = "Finance.Recharge.Credit";
/// <summary>发票开具。</summary>
public const string FinanceInvoiceIssue = "Finance.Invoice.Issue";
} }
/// <summary> /// <summary>

View File

@ -0,0 +1,111 @@
namespace Oms.Domain.FinanceAggregate.Consts;
/// <summary>
/// 发票申请状态。
/// </summary>
public static class InvoiceStatusCodes
{
/// <summary>草稿。</summary>
public const string Draft = "draft";
/// <summary>待审批。</summary>
public const string PendingApproval = "pendingApproval";
/// <summary>已审批待开票。</summary>
public const string Approved = "approved";
/// <summary>已开票。</summary>
public const string Issued = "issued";
/// <summary>已驳回。</summary>
public const string Rejected = "rejected";
/// <summary>已作废(释放占用)。</summary>
public const string Voided = "voided";
/// <summary>已红冲。</summary>
public const string RedFlushed = "redFlushed";
/// <summary>占用可开票额度的状态(作废/驳回/红冲不占用)。</summary>
public static readonly string[] OccupyingStatuses =
[
Draft,
PendingApproval,
Approved,
Issued
];
/// <summary>默认税率备注(含税不拆分)。</summary>
public const decimal DefaultTaxRate = 0.06m;
public static bool OccupiesSource(string? status) =>
status is Draft or PendingApproval or Approved or Issued;
}
/// <summary>
/// 开票来源类型。
/// </summary>
public static class InvoiceSourceTypeCodes
{
/// <summary>已支付运单(应付金额)。</summary>
public const string ParcelOrder = "parcelOrder";
/// <summary>已支付揽收单(应收金额)。</summary>
public const string PickupOrder = "pickupOrder";
/// <summary>已支付仓租账单。</summary>
public const string StorageRent = "storageRent";
public static bool IsKnown(string? sourceType) =>
sourceType is ParcelOrder or PickupOrder or StorageRent;
}
/// <summary>
/// 发票类型。
/// </summary>
public static class InvoiceTypeCodes
{
/// <summary>增值税普通发票。</summary>
public const string Normal = "normal";
/// <summary>增值税专用发票。</summary>
public const string Special = "special";
public static bool IsKnown(string? invoiceType) =>
invoiceType is Normal or Special;
}
/// <summary>
/// 发票介质。
/// </summary>
public static class InvoiceMediumCodes
{
/// <summary>电子发票。</summary>
public const string Electronic = "electronic";
/// <summary>纸质发票。</summary>
public const string Paper = "paper";
public static bool IsKnown(string? medium) =>
medium is Electronic or Paper;
}
/// <summary>
/// 申请人来源。
/// </summary>
public static class InvoiceApplicantSourceCodes
{
/// <summary>管理端。</summary>
public const string Admin = "admin";
/// <summary>客户门户。</summary>
public const string Customer = "customer";
}
/// <summary>
/// 发票币种。
/// </summary>
public static class InvoiceCurrencyCodes
{
public const string Cny = "CNY";
}

View File

@ -0,0 +1,31 @@
using Oms.Domain.Shared;
using SqlSugar;
namespace Oms.Domain.FinanceAggregate.Entities;
/// <summary>
/// 客户发票抬头。
/// </summary>
[SugarTable("t_customer_invoice_profile")]
public class CustomerInvoiceProfile : OmsAuditedAggregateRoot
{
public int CustomerId { get; set; }
[SugarColumn(Length = 128)]
public string TitleName { get; set; } = string.Empty;
[SugarColumn(Length = 64)]
public string TaxNo { get; set; } = string.Empty;
[SugarColumn(Length = 256, IsNullable = true)]
public string? AddressPhone { get; set; }
[SugarColumn(Length = 256, IsNullable = true)]
public string? BankNameAccount { get; set; }
/// <summary>是否默认:0-否,1-是。</summary>
public byte IsDefault { get; set; }
[SugarColumn(Length = 512, IsNullable = true)]
public string? Remark { get; set; }
}

View File

@ -0,0 +1,82 @@
using Oms.Domain.FinanceAggregate.Consts;
using Oms.Domain.Shared;
using SqlSugar;
namespace Oms.Domain.FinanceAggregate.Entities;
/// <summary>
/// 发票申请头。金额为含税价税合计。
/// </summary>
[SugarTable("t_invoice_apply")]
public class InvoiceApply : OmsAuditedAggregateRoot
{
[SugarColumn(Length = 32)]
public string ApplyNo { get; set; } = string.Empty;
public int CustomerId { get; set; }
[SugarColumn(Length = 16)]
public string InvoiceType { get; set; } = InvoiceTypeCodes.Normal;
[SugarColumn(Length = 16)]
public string Medium { get; set; } = InvoiceMediumCodes.Electronic;
[SugarColumn(Length = 128)]
public string TitleName { get; set; } = string.Empty;
[SugarColumn(Length = 64)]
public string TaxNo { get; set; } = string.Empty;
[SugarColumn(Length = 256, IsNullable = true)]
public string? AddressPhone { get; set; }
[SugarColumn(Length = 256, IsNullable = true)]
public string? BankNameAccount { get; set; }
/// <summary>价税合计(含税)。</summary>
[SugarColumn(DecimalDigits = 2)]
public decimal AmountTotal { get; set; }
/// <summary>税率备注,默认 0.06;不拆分税额。</summary>
[SugarColumn(DecimalDigits = 4)]
public decimal TaxRate { get; set; } = InvoiceStatusCodes.DefaultTaxRate;
[SugarColumn(Length = 8)]
public string Currency { get; set; } = InvoiceCurrencyCodes.Cny;
[SugarColumn(Length = 32)]
public string Status { get; set; } = InvoiceStatusCodes.Draft;
[SugarColumn(Length = 16)]
public string ApplicantSource { get; set; } = InvoiceApplicantSourceCodes.Admin;
[SugarColumn(Length = 64, IsNullable = true)]
public string? InvoiceCode { get; set; }
[SugarColumn(Length = 64, IsNullable = true)]
public string? InvoiceNumber { get; set; }
[SugarColumn(IsNullable = true)]
public DateTime? InvoiceDate { get; set; }
[SugarColumn(Length = 1024, IsNullable = true)]
public string? InvoicePdfUrl { get; set; }
[SugarColumn(Length = 512, IsNullable = true)]
public string? Remark { get; set; }
[SugarColumn(IsNullable = true)]
public int? ApprovalInstanceId { get; set; }
[SugarColumn(Length = 32, IsNullable = true)]
public string? ApprovalInstanceNo { get; set; }
[SugarColumn(Length = 512, IsNullable = true)]
public string? RejectReason { get; set; }
[SugarColumn(IsNullable = true)]
public DateTime? IssueTime { get; set; }
[SugarColumn(Length = 64, IsNullable = true)]
public string? IssueBy { get; set; }
}

View File

@ -0,0 +1,31 @@
using Oms.Domain.FinanceAggregate.Consts;
using Oms.Domain.Shared;
using SqlSugar;
namespace Oms.Domain.FinanceAggregate.Entities;
/// <summary>
/// 发票申请明细(来源占用行,金额含税)。
/// </summary>
[SugarTable("t_invoice_apply_line")]
public class InvoiceApplyLine : OmsAuditedAggregateRoot
{
public int InvoiceApplyId { get; set; }
[SugarColumn(Length = 32)]
public string SourceType { get; set; } = string.Empty;
public int SourceId { get; set; }
[SugarColumn(Length = 64)]
public string SourceNo { get; set; } = string.Empty;
[SugarColumn(DecimalDigits = 2)]
public decimal Amount { get; set; }
[SugarColumn(Length = 8)]
public string Currency { get; set; } = InvoiceCurrencyCodes.Cny;
[SugarColumn(Length = 512, IsNullable = true)]
public string? Remark { get; set; }
}

View File

@ -0,0 +1,8 @@
using Fake.Domain.Repositories;
using Oms.Domain.FinanceAggregate.Entities;
namespace Oms.Domain.FinanceAggregate.Repositories;
public interface ICustomerInvoiceProfileRepository : IRepository<CustomerInvoiceProfile>
{
}

View File

@ -0,0 +1,11 @@
using Fake.Domain.Repositories;
using Oms.Domain.FinanceAggregate.Entities;
namespace Oms.Domain.FinanceAggregate.Repositories;
public interface IInvoiceApplyLineRepository : IRepository<InvoiceApplyLine>
{
Task<List<InvoiceApplyLine>> GetListByApplyIdAsync(
int invoiceApplyId,
CancellationToken cancellationToken = default);
}

View File

@ -0,0 +1,11 @@
using Fake.Domain.Repositories;
using Oms.Domain.FinanceAggregate.Entities;
namespace Oms.Domain.FinanceAggregate.Repositories;
public interface IInvoiceApplyRepository : IRepository<InvoiceApply>
{
Task<bool> ExistsApplyNoAsync(string applyNo, CancellationToken cancellationToken = default);
Task<InvoiceApply?> GetByApplyNoAsync(string applyNo, CancellationToken cancellationToken = default);
}

View File

@ -0,0 +1,11 @@
using Fake.DependencyInjection;
using Oms.Domain.FinanceAggregate.Entities;
using Oms.Domain.FinanceAggregate.Repositories;
using Oms.SqlSugarCore.Repositories;
namespace Oms.SqlSugarCore.Finance;
public class CustomerInvoiceProfileRepository
: OmsSqlSugarRepository<CustomerInvoiceProfile>, ICustomerInvoiceProfileRepository, IScopedDependency
{
}

View File

@ -0,0 +1,17 @@
using Fake.DependencyInjection;
using Oms.Domain.FinanceAggregate.Entities;
using Oms.Domain.FinanceAggregate.Repositories;
using Oms.SqlSugarCore.Repositories;
namespace Oms.SqlSugarCore.Finance;
public class InvoiceApplyLineRepository
: OmsSqlSugarRepository<InvoiceApplyLine>, IInvoiceApplyLineRepository, IScopedDependency
{
public Task<List<InvoiceApplyLine>> GetListByApplyIdAsync(
int invoiceApplyId,
CancellationToken cancellationToken = default)
{
return GetListAsync(x => x.InvoiceApplyId == invoiceApplyId, cancellationToken: cancellationToken);
}
}

View File

@ -0,0 +1,20 @@
using Fake.DependencyInjection;
using Oms.Domain.FinanceAggregate.Entities;
using Oms.Domain.FinanceAggregate.Repositories;
using Oms.SqlSugarCore.Repositories;
namespace Oms.SqlSugarCore.Finance;
public class InvoiceApplyRepository
: OmsSqlSugarRepository<InvoiceApply>, IInvoiceApplyRepository, IScopedDependency
{
public Task<bool> ExistsApplyNoAsync(string applyNo, CancellationToken cancellationToken = default)
{
return AnyAsync(x => x.ApplyNo == applyNo, cancellationToken);
}
public Task<InvoiceApply?> GetByApplyNoAsync(string applyNo, CancellationToken cancellationToken = default)
{
return FirstOrDefaultAsync(x => x.ApplyNo == applyNo, cancellationToken);
}
}