20261121 #30
115
db.sql
115
db.sql
@ -62,6 +62,8 @@ DROP TABLE IF EXISTS `t_customer_account_flow`;
|
||||
DROP TABLE IF EXISTS `t_system_batch_email_record`;
|
||||
DROP TABLE IF EXISTS `t_system_batch_email_account`;
|
||||
DROP TABLE IF EXISTS `t_system_batch_email_template`;
|
||||
DROP TABLE IF EXISTS `t_order_notify_log`;
|
||||
DROP TABLE IF EXISTS `t_order_notify_email_log`;
|
||||
DROP TABLE IF EXISTS `t_wechat_notify_log`;
|
||||
DROP TABLE IF EXISTS `t_customer_wechat_notify_pref`;
|
||||
DROP TABLE IF EXISTS `t_wechat_notify_template`;
|
||||
@ -73,6 +75,9 @@ DROP TABLE IF EXISTS `t_employee`;
|
||||
DROP TABLE IF EXISTS `t_dict_type`;
|
||||
DROP TABLE IF EXISTS `t_dict`;
|
||||
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_customer`;
|
||||
DROP TABLE IF EXISTS `t_label_print_record`;
|
||||
@ -1139,6 +1144,82 @@ CREATE TABLE `t_recharge_record` (
|
||||
KEY `idx_rr_audit_time` (`AuditTime`)
|
||||
) 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` (
|
||||
`Id` INT NOT NULL AUTO_INCREMENT COMMENT '主键,自增,步长 1',
|
||||
`ChineseName` VARCHAR(128) NOT NULL COMMENT '国家中文名',
|
||||
@ -1215,7 +1296,11 @@ CREATE TABLE `t_wechat_notify_template` (
|
||||
`TemplateId` VARCHAR(128) NULL COMMENT '微信公众号模板 ID',
|
||||
`UrlTemplate` VARCHAR(512) NULL COMMENT '跳转 URL 模板,支持 {baseUrl}/{orderId}/{serviceNo}',
|
||||
`FieldMappingJson` TEXT NULL COMMENT '字段映射 JSON:[{key,placeholder,color?}]',
|
||||
`IsEnabled` TINYINT NOT NULL DEFAULT 0 COMMENT '是否启用:0-否,1-是',
|
||||
`IsEnabled` TINYINT NOT NULL DEFAULT 0 COMMENT '是否启用微信推送:0-否,1-是',
|
||||
`EmailEnabled` TINYINT NOT NULL DEFAULT 0 COMMENT '是否启用邮件通知:0-否,1-是',
|
||||
`EmailTemplateName` VARCHAR(128) NULL COMMENT 'batch-email 模板名称',
|
||||
`EmailTemplateOwnerUserId` INT NULL COMMENT 'batch-email 模板所属用户',
|
||||
`EmailSmtpOwnerUserId` INT NULL COMMENT '发信 SMTP 所属用户;0 表示系统发信账号',
|
||||
`Remark` VARCHAR(512) NULL COMMENT '备注',
|
||||
`IsDeleted` TINYINT NOT NULL DEFAULT 0 COMMENT '软删除:0-否,1-是',
|
||||
`ConcurrencyStamp` CHAR(36) NOT NULL DEFAULT (UUID()) COMMENT '并发戳',
|
||||
@ -1226,13 +1311,14 @@ CREATE TABLE `t_wechat_notify_template` (
|
||||
PRIMARY KEY (`Id`),
|
||||
KEY `ix_wechat_notify_tpl_event` (`EventCode`),
|
||||
KEY `ix_wechat_notify_tpl_enabled` (`IsEnabled`, `Id`)
|
||||
) COMMENT='微信订单通知模板配置';
|
||||
) COMMENT='订单通知模板配置(微信 + 邮件)';
|
||||
|
||||
CREATE TABLE `t_customer_wechat_notify_pref` (
|
||||
`Id` INT NOT NULL AUTO_INCREMENT COMMENT '主键,自增,步长 1',
|
||||
`CustomerId` INT NOT NULL COMMENT '客户 Id',
|
||||
`EventCode` VARCHAR(32) NOT NULL COMMENT '事件码',
|
||||
`IsSubscribed` TINYINT NOT NULL DEFAULT 0 COMMENT '是否订阅:0-否,1-是',
|
||||
`IsSubscribed` TINYINT NOT NULL DEFAULT 0 COMMENT '是否订阅微信:0-否,1-是',
|
||||
`IsEmailSubscribed` TINYINT NOT NULL DEFAULT 0 COMMENT '是否订阅邮件:0-否,1-是',
|
||||
`IsDeleted` TINYINT NOT NULL DEFAULT 0 COMMENT '软删除:0-否,1-是',
|
||||
`ConcurrencyStamp` CHAR(36) NOT NULL DEFAULT (UUID()) COMMENT '并发戳',
|
||||
`CreateUserId` INT NOT NULL DEFAULT 0 COMMENT '创建人',
|
||||
@ -1242,19 +1328,22 @@ CREATE TABLE `t_customer_wechat_notify_pref` (
|
||||
PRIMARY KEY (`Id`),
|
||||
KEY `ix_cus_wechat_notify_pref_cus` (`CustomerId`, `EventCode`),
|
||||
KEY `ix_cus_wechat_notify_pref_event` (`EventCode`, `IsSubscribed`)
|
||||
) COMMENT='客户微信订单通知订阅偏好';
|
||||
) COMMENT='客户订单通知订阅偏好(微信 / 邮件)';
|
||||
|
||||
CREATE TABLE `t_wechat_notify_log` (
|
||||
CREATE TABLE `t_order_notify_log` (
|
||||
`Id` INT NOT NULL AUTO_INCREMENT COMMENT '主键,自增,步长 1',
|
||||
`CustomerId` INT NOT NULL DEFAULT 0 COMMENT '客户 Id',
|
||||
`OrderId` INT NOT NULL DEFAULT 0 COMMENT '订单 Id',
|
||||
`Channel` VARCHAR(16) NOT NULL COMMENT 'wechat/email',
|
||||
`EventCode` VARCHAR(32) NOT NULL COMMENT '事件码',
|
||||
`OpenId` VARCHAR(64) NULL COMMENT '接收 openid',
|
||||
`TemplateId` VARCHAR(128) NULL COMMENT '模板 Id',
|
||||
`Recipient` VARCHAR(256) NULL COMMENT 'OpenId 或收件邮箱',
|
||||
`TemplateRef` VARCHAR(128) NULL COMMENT '微信 TemplateId 或邮件模板名',
|
||||
`Subject` VARCHAR(512) NULL COMMENT '邮件主题',
|
||||
`Status` VARCHAR(16) NOT NULL DEFAULT 'skipped' COMMENT 'sent/failed/skipped',
|
||||
`WxMsgId` VARCHAR(64) NULL COMMENT '微信 msgid',
|
||||
`ErrCode` INT NULL COMMENT '微信/业务错误码',
|
||||
`ProviderMsgId` VARCHAR(64) NULL COMMENT '通道回执 msgid',
|
||||
`ErrCode` INT NULL COMMENT '错误码',
|
||||
`ErrMsg` VARCHAR(512) NULL COMMENT '错误或跳过原因',
|
||||
`SmtpUsername` VARCHAR(256) NULL COMMENT '发件 SMTP',
|
||||
`PayloadJson` TEXT NULL COMMENT '发送快照',
|
||||
`IsDeleted` TINYINT NOT NULL DEFAULT 0 COMMENT '软删除:0-否,1-是',
|
||||
`ConcurrencyStamp` CHAR(36) NOT NULL DEFAULT (UUID()) COMMENT '并发戳',
|
||||
@ -1263,10 +1352,10 @@ CREATE TABLE `t_wechat_notify_log` (
|
||||
`UpdateUserId` INT NULL COMMENT '更新人',
|
||||
`UpdateTime` DATETIME NULL COMMENT '更新时间',
|
||||
PRIMARY KEY (`Id`),
|
||||
KEY `ix_wechat_notify_log_order_event` (`OrderId`, `EventCode`, `CreateTime`),
|
||||
KEY `ix_wechat_notify_log_cus_time` (`CustomerId`, `CreateTime`),
|
||||
KEY `ix_wechat_notify_log_status` (`Status`, `Id`)
|
||||
) COMMENT='微信订单通知发送日志';
|
||||
KEY `ix_order_notify_log_order_ch_event` (`OrderId`, `Channel`, `EventCode`, `CreateTime`),
|
||||
KEY `ix_order_notify_log_cus_time` (`CustomerId`, `CreateTime`),
|
||||
KEY `ix_order_notify_log_status` (`Status`, `Id`)
|
||||
) COMMENT='订单通知发送日志(微信/邮件)';
|
||||
|
||||
CREATE TABLE `t_system_batch_email_template` (
|
||||
`Id` INT NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
|
||||
195
sql/migrate_finance_contract_payment_20261121.sql
Normal file
195
sql/migrate_finance_contract_payment_20261121.sql
Normal file
@ -0,0 +1,195 @@
|
||||
# migrate_finance_contract_payment_20261121.sql
|
||||
# 财务:供应商、公司收付款账户、合同、付款申请(可重复执行)
|
||||
# no UNIQUE KEY;编码/单号唯一性在 Application 校验
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
SET @db := DATABASE();
|
||||
|
||||
# t_finance_supplier
|
||||
SET @tbl := (
|
||||
SELECT COUNT(1) FROM information_schema.TABLES
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 't_finance_supplier'
|
||||
);
|
||||
SET @sql := IF(
|
||||
@tbl = 0,
|
||||
'CREATE TABLE `t_finance_supplier` (
|
||||
`Id` INT NOT NULL AUTO_INCREMENT COMMENT ''主键'',
|
||||
`SupplierCode` VARCHAR(32) NOT NULL COMMENT ''供应商编码'',
|
||||
`SupplierName` VARCHAR(128) NOT NULL COMMENT ''供应商名称'',
|
||||
`ContactName` VARCHAR(64) NULL COMMENT ''联系人'',
|
||||
`Phone` VARCHAR(32) NULL COMMENT ''电话'',
|
||||
`Email` VARCHAR(128) NULL COMMENT ''邮箱'',
|
||||
`BankAccountName` VARCHAR(128) NULL COMMENT ''收款户名'',
|
||||
`BankName` VARCHAR(128) NULL COMMENT ''开户行'',
|
||||
`BankAccountNo` VARCHAR(64) NULL COMMENT ''银行账号'',
|
||||
`Currency` VARCHAR(8) NOT NULL DEFAULT ''CNY'' COMMENT ''默认币种'',
|
||||
`Status` TINYINT NOT NULL DEFAULT 2 COMMENT ''1-停用 2-启用'',
|
||||
`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_fin_supplier_code` (`SupplierCode`),
|
||||
KEY `ix_fin_supplier_name` (`SupplierName`)
|
||||
) COMMENT=''财务供应商''',
|
||||
'SELECT 1'
|
||||
);
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
# t_finance_company_account
|
||||
SET @tbl := (
|
||||
SELECT COUNT(1) FROM information_schema.TABLES
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 't_finance_company_account'
|
||||
);
|
||||
SET @sql := IF(
|
||||
@tbl = 0,
|
||||
'CREATE TABLE `t_finance_company_account` (
|
||||
`Id` INT NOT NULL AUTO_INCREMENT COMMENT ''主键'',
|
||||
`AccountName` VARCHAR(128) NOT NULL COMMENT ''账户名称/户名'',
|
||||
`BankName` VARCHAR(128) NOT NULL COMMENT ''开户行'',
|
||||
`AccountNo` VARCHAR(64) NOT NULL COMMENT ''银行账号'',
|
||||
`Currency` VARCHAR(8) NOT NULL DEFAULT ''CNY'' COMMENT ''币种'',
|
||||
`IsDefault` TINYINT NOT NULL DEFAULT 0 COMMENT ''是否默认:0-否,1-是'',
|
||||
`Status` TINYINT NOT NULL DEFAULT 2 COMMENT ''1-停用 2-启用'',
|
||||
`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_fin_co_account_no` (`AccountNo`)
|
||||
) COMMENT=''公司收付款账户''',
|
||||
'SELECT 1'
|
||||
);
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
# t_finance_contract
|
||||
SET @tbl := (
|
||||
SELECT COUNT(1) FROM information_schema.TABLES
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 't_finance_contract'
|
||||
);
|
||||
SET @sql := IF(
|
||||
@tbl = 0,
|
||||
'CREATE TABLE `t_finance_contract` (
|
||||
`Id` INT NOT NULL AUTO_INCREMENT COMMENT ''主键'',
|
||||
`ContractNo` VARCHAR(32) NOT NULL COMMENT ''合同编号 CTR+yyyyMMdd+序号'',
|
||||
`ContractName` VARCHAR(128) NOT NULL COMMENT ''合同名称'',
|
||||
`PartyType` VARCHAR(16) NOT NULL COMMENT ''对方类型:customer/supplier/agent'',
|
||||
`PartyId` INT NOT NULL COMMENT ''对方 Id'',
|
||||
`OurEntityName` VARCHAR(128) NULL COMMENT ''我方签约主体'',
|
||||
`SignDate` DATETIME NULL COMMENT ''签订日期'',
|
||||
`EffectiveDate` DATETIME NOT NULL COMMENT ''生效日期'',
|
||||
`ExpireDate` DATETIME NULL COMMENT ''到期日期'',
|
||||
`AutoRenew` TINYINT NOT NULL DEFAULT 0 COMMENT ''是否自动续签:0-否,1-是'',
|
||||
`SettlementMethod` VARCHAR(16) NOT NULL DEFAULT ''monthly'' COMMENT ''结算方式:prepaid/ticket/monthly/biweekly'',
|
||||
`PaymentTermDays` INT NOT NULL DEFAULT 30 COMMENT ''账期天数'',
|
||||
`BillingDay` INT NULL COMMENT ''账单日(1-28)'',
|
||||
`PaymentDay` INT NULL COMMENT ''约定付款日(1-28)'',
|
||||
`Currency` VARCHAR(8) NOT NULL DEFAULT ''CNY'' COMMENT ''币种'',
|
||||
`CreditLimit` DECIMAL(18,2) NULL COMMENT ''客户信用额度(客户合同)'',
|
||||
`CommissionBaseType` VARCHAR(32) NULL COMMENT ''代理佣金基数:freight/receivable'',
|
||||
`CommissionRate` DECIMAL(10,4) NULL COMMENT ''代理佣金比例'',
|
||||
`RequireVendorInvoice` TINYINT NOT NULL DEFAULT 0 COMMENT ''供应商须先有进项发票才付款'',
|
||||
`OwnerUserId` INT NULL COMMENT ''负责人用户 Id'',
|
||||
`OwnerName` VARCHAR(64) NULL COMMENT ''负责人姓名快照'',
|
||||
`Status` VARCHAR(16) NOT NULL DEFAULT ''draft'' COMMENT ''draft/active/expired/terminated'',
|
||||
`AttachmentUrls` VARCHAR(2048) NULL COMMENT ''附件 URL,逗号分隔'',
|
||||
`Remark` VARCHAR(512) NULL COMMENT ''备注'',
|
||||
`RenewedFromId` INT NULL COMMENT ''续签来源合同 Id'',
|
||||
`TerminatedTime` DATETIME NULL COMMENT ''终止时间'',
|
||||
`TerminateReason` 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_fin_contract_no` (`ContractNo`),
|
||||
KEY `ix_fin_contract_party` (`PartyType`, `PartyId`),
|
||||
KEY `ix_fin_contract_status` (`Status`),
|
||||
KEY `ix_fin_contract_expire` (`ExpireDate`)
|
||||
) COMMENT=''财务合同''',
|
||||
'SELECT 1'
|
||||
);
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
# t_finance_payment_apply
|
||||
SET @tbl := (
|
||||
SELECT COUNT(1) FROM information_schema.TABLES
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 't_finance_payment_apply'
|
||||
);
|
||||
SET @sql := IF(
|
||||
@tbl = 0,
|
||||
'CREATE TABLE `t_finance_payment_apply` (
|
||||
`Id` INT NOT NULL AUTO_INCREMENT COMMENT ''主键'',
|
||||
`ApplyNo` VARCHAR(32) NOT NULL COMMENT ''申请单号 PAY+yyyyMMdd+序号'',
|
||||
`PaymentType` VARCHAR(32) NOT NULL COMMENT ''supplier/agentCommission/customerRefund/other'',
|
||||
`PayeeType` VARCHAR(16) NOT NULL COMMENT ''收款方类型:customer/supplier/agent'',
|
||||
`PayeeId` INT NOT NULL COMMENT ''收款方 Id'',
|
||||
`ContractId` INT NULL COMMENT ''关联合同 Id'',
|
||||
`Currency` VARCHAR(8) NOT NULL DEFAULT ''CNY'' COMMENT ''币种'',
|
||||
`AmountTotal` DECIMAL(18,2) NOT NULL DEFAULT 0.00 COMMENT ''申请金额'',
|
||||
`ExpectPayDate` DATETIME NULL COMMENT ''期望付款日'',
|
||||
`PayeeAccountName` VARCHAR(128) NULL COMMENT ''收款户名'',
|
||||
`PayeeBankName` VARCHAR(128) NULL COMMENT ''收款开户行'',
|
||||
`PayeeAccountNo` VARCHAR(64) NULL COMMENT ''收款账号'',
|
||||
`CompanyAccountId` INT NULL COMMENT ''付款公司账户 Id'',
|
||||
`Status` VARCHAR(32) NOT NULL DEFAULT ''draft'' COMMENT ''draft/pendingApproval/pendingPay/paid/rejected'',
|
||||
`ApplicantName` VARCHAR(64) NULL COMMENT ''申请人姓名快照'',
|
||||
`AttachmentUrls` VARCHAR(2048) NULL COMMENT ''附件 URL,逗号分隔'',
|
||||
`Remark` VARCHAR(512) NULL COMMENT ''备注'',
|
||||
`ApprovalInstanceId` INT NULL COMMENT ''审批实例 Id'',
|
||||
`ApprovalInstanceNo` VARCHAR(32) NULL COMMENT ''审批单号'',
|
||||
`RejectReason` VARCHAR(512) NULL COMMENT ''驳回原因'',
|
||||
`PaidTime` DATETIME NULL COMMENT ''实际付款时间'',
|
||||
`BankTxnNo` VARCHAR(64) NULL COMMENT ''银行流水号'',
|
||||
`PaidBy` VARCHAR(64) NULL COMMENT ''登记付款人'',
|
||||
`PaidVoucherUrl` VARCHAR(1024) NULL COMMENT ''付款凭证 URL'',
|
||||
`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_fin_pay_apply_no` (`ApplyNo`),
|
||||
KEY `ix_fin_pay_payee` (`PayeeType`, `PayeeId`),
|
||||
KEY `ix_fin_pay_status` (`Status`),
|
||||
KEY `ix_fin_pay_contract` (`ContractId`)
|
||||
) COMMENT=''付款申请''',
|
||||
'SELECT 1'
|
||||
);
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
# t_finance_payment_apply_line
|
||||
SET @tbl := (
|
||||
SELECT COUNT(1) FROM information_schema.TABLES
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 't_finance_payment_apply_line'
|
||||
);
|
||||
SET @sql := IF(
|
||||
@tbl = 0,
|
||||
'CREATE TABLE `t_finance_payment_apply_line` (
|
||||
`Id` INT NOT NULL AUTO_INCREMENT COMMENT ''主键'',
|
||||
`PaymentApplyId` INT NOT NULL COMMENT ''付款申请 Id'',
|
||||
`Description` VARCHAR(256) NOT NULL COMMENT ''费用说明'',
|
||||
`Amount` DECIMAL(18,2) NOT NULL DEFAULT 0.00 COMMENT ''金额'',
|
||||
`RefNo` VARCHAR(64) NULL 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_fin_pay_line_apply` (`PaymentApplyId`)
|
||||
) COMMENT=''付款申请明细''',
|
||||
'SELECT 1'
|
||||
);
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
112
sql/migrate_invoice_manage_20261121.sql
Normal file
112
sql/migrate_invoice_manage_20261121.sql
Normal 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;
|
||||
175
sql/migrate_order_notify_all_20261121.sql
Normal file
175
sql/migrate_order_notify_all_20261121.sql
Normal file
@ -0,0 +1,175 @@
|
||||
-- =============================================================================
|
||||
-- 订单通知(微信 + 邮件)一次升级脚本
|
||||
-- 前提:已有 t_wechat_notify_template / t_customer_wechat_notify_pref / t_wechat_notify_log
|
||||
-- 可重复执行
|
||||
-- =============================================================================
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
SET @db := DATABASE();
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- 1) 模板表:邮件通道字段
|
||||
-- ---------------------------------------------------------------------------
|
||||
SET @sql := (
|
||||
SELECT IF(
|
||||
EXISTS(
|
||||
SELECT 1 FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @db
|
||||
AND TABLE_NAME = 't_wechat_notify_template'
|
||||
AND COLUMN_NAME = 'EmailEnabled'
|
||||
),
|
||||
'SELECT ''EmailEnabled already exists'' AS info',
|
||||
'ALTER TABLE `t_wechat_notify_template`
|
||||
ADD COLUMN `EmailEnabled` TINYINT NOT NULL DEFAULT 0 COMMENT ''是否启用邮件通知:0-否,1-是'' AFTER `IsEnabled`,
|
||||
ADD COLUMN `EmailTemplateName` VARCHAR(128) NULL COMMENT ''batch-email 模板名称'' AFTER `EmailEnabled`,
|
||||
ADD COLUMN `EmailSmtpOwnerUserId` INT NULL COMMENT ''发信 SMTP 所属用户;0 表示系统发信账号'' AFTER `EmailTemplateName`'
|
||||
)
|
||||
);
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- 2) 模板表:模板归属用户(与 SMTP 解耦)
|
||||
-- ---------------------------------------------------------------------------
|
||||
SET @sql := (
|
||||
SELECT IF(
|
||||
EXISTS(
|
||||
SELECT 1 FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @db
|
||||
AND TABLE_NAME = 't_wechat_notify_template'
|
||||
AND COLUMN_NAME = 'EmailTemplateOwnerUserId'
|
||||
),
|
||||
'SELECT ''EmailTemplateOwnerUserId already exists'' AS info',
|
||||
'ALTER TABLE `t_wechat_notify_template`
|
||||
ADD COLUMN `EmailTemplateOwnerUserId` INT NULL COMMENT ''batch-email 模板所属用户'' AFTER `EmailTemplateName`'
|
||||
)
|
||||
);
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
UPDATE `t_wechat_notify_template`
|
||||
SET `EmailTemplateOwnerUserId` = `EmailSmtpOwnerUserId`
|
||||
WHERE `EmailTemplateOwnerUserId` IS NULL
|
||||
AND `EmailSmtpOwnerUserId` IS NOT NULL
|
||||
AND `EmailSmtpOwnerUserId` > 0;
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- 3) 客户偏好:邮件订阅
|
||||
-- ---------------------------------------------------------------------------
|
||||
SET @sql := (
|
||||
SELECT IF(
|
||||
EXISTS(
|
||||
SELECT 1 FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @db
|
||||
AND TABLE_NAME = 't_customer_wechat_notify_pref'
|
||||
AND COLUMN_NAME = 'IsEmailSubscribed'
|
||||
),
|
||||
'SELECT ''IsEmailSubscribed already exists'' AS info',
|
||||
'ALTER TABLE `t_customer_wechat_notify_pref`
|
||||
ADD COLUMN `IsEmailSubscribed` TINYINT NOT NULL DEFAULT 0 COMMENT ''是否订阅邮件:0-否,1-是'' AFTER `IsSubscribed`'
|
||||
)
|
||||
);
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- 4) 统一通知日志表 t_order_notify_log(微信 / 邮件)
|
||||
-- ---------------------------------------------------------------------------
|
||||
SET @sql := (
|
||||
SELECT IF(
|
||||
EXISTS(
|
||||
SELECT 1 FROM information_schema.TABLES
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 't_order_notify_log'
|
||||
),
|
||||
'SELECT ''t_order_notify_log already exists'' AS info',
|
||||
'CREATE TABLE `t_order_notify_log` (
|
||||
`Id` INT NOT NULL AUTO_INCREMENT COMMENT ''主键,自增,步长 1'',
|
||||
`CustomerId` INT NOT NULL DEFAULT 0 COMMENT ''客户 Id'',
|
||||
`OrderId` INT NOT NULL DEFAULT 0 COMMENT ''订单 Id'',
|
||||
`Channel` VARCHAR(16) NOT NULL COMMENT ''wechat/email'',
|
||||
`EventCode` VARCHAR(32) NOT NULL COMMENT ''事件码'',
|
||||
`Recipient` VARCHAR(256) NULL COMMENT ''OpenId 或收件邮箱'',
|
||||
`TemplateRef` VARCHAR(128) NULL COMMENT ''微信 TemplateId 或邮件模板名'',
|
||||
`Subject` VARCHAR(512) NULL COMMENT ''邮件主题'',
|
||||
`Status` VARCHAR(16) NOT NULL DEFAULT ''skipped'' COMMENT ''sent/failed/skipped'',
|
||||
`ProviderMsgId` VARCHAR(64) NULL COMMENT ''通道回执 msgid'',
|
||||
`ErrCode` INT NULL COMMENT ''错误码'',
|
||||
`ErrMsg` VARCHAR(512) NULL COMMENT ''错误或跳过原因'',
|
||||
`SmtpUsername` VARCHAR(256) NULL COMMENT ''发件 SMTP'',
|
||||
`PayloadJson` TEXT 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_order_notify_log_order_ch_event` (`OrderId`, `Channel`, `EventCode`, `CreateTime`),
|
||||
KEY `ix_order_notify_log_cus_time` (`CustomerId`, `CreateTime`),
|
||||
KEY `ix_order_notify_log_status` (`Status`, `Id`)
|
||||
) COMMENT=''订单通知发送日志(微信/邮件)'''
|
||||
)
|
||||
);
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- 5) 若线上已有旧微信日志,灌入统一表(无则跳过;可重复)
|
||||
-- ---------------------------------------------------------------------------
|
||||
SET @has_wx := (
|
||||
SELECT COUNT(*) FROM information_schema.TABLES
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 't_wechat_notify_log'
|
||||
);
|
||||
SET @sql := IF(
|
||||
@has_wx > 0,
|
||||
'INSERT INTO `t_order_notify_log` (
|
||||
`CustomerId`, `OrderId`, `Channel`, `EventCode`, `Recipient`, `TemplateRef`, `Subject`,
|
||||
`Status`, `ProviderMsgId`, `ErrCode`, `ErrMsg`, `SmtpUsername`, `PayloadJson`,
|
||||
`IsDeleted`, `ConcurrencyStamp`, `CreateUserId`, `CreateTime`, `UpdateUserId`, `UpdateTime`
|
||||
)
|
||||
SELECT
|
||||
w.`CustomerId`, w.`OrderId`, ''wechat'', w.`EventCode`, w.`OpenId`, w.`TemplateId`, NULL,
|
||||
w.`Status`, w.`WxMsgId`, w.`ErrCode`, w.`ErrMsg`, NULL, w.`PayloadJson`,
|
||||
w.`IsDeleted`, UUID(), w.`CreateUserId`, w.`CreateTime`, w.`UpdateUserId`, w.`UpdateTime`
|
||||
FROM `t_wechat_notify_log` w
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM `t_order_notify_log` n
|
||||
WHERE n.`Channel` = ''wechat''
|
||||
AND n.`OrderId` = w.`OrderId`
|
||||
AND n.`EventCode` = w.`EventCode`
|
||||
AND n.`CreateTime` = w.`CreateTime`
|
||||
AND IFNULL(n.`Status`, '''') = IFNULL(w.`Status`, '''')
|
||||
AND IFNULL(n.`Recipient`, '''') = IFNULL(w.`OpenId`, '''')
|
||||
)',
|
||||
'SELECT ''skip wechat migrate'' AS info'
|
||||
);
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 若曾建过邮件专用日志表,一并灌入(多数环境无此表)
|
||||
SET @has_mail := (
|
||||
SELECT COUNT(*) FROM information_schema.TABLES
|
||||
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 't_order_notify_email_log'
|
||||
);
|
||||
SET @sql := IF(
|
||||
@has_mail > 0,
|
||||
'INSERT INTO `t_order_notify_log` (
|
||||
`CustomerId`, `OrderId`, `Channel`, `EventCode`, `Recipient`, `TemplateRef`, `Subject`,
|
||||
`Status`, `ProviderMsgId`, `ErrCode`, `ErrMsg`, `SmtpUsername`, `PayloadJson`,
|
||||
`IsDeleted`, `ConcurrencyStamp`, `CreateUserId`, `CreateTime`, `UpdateUserId`, `UpdateTime`
|
||||
)
|
||||
SELECT
|
||||
e.`CustomerId`, e.`OrderId`, ''email'', e.`EventCode`, e.`ToEmail`, e.`TemplateName`, e.`Subject`,
|
||||
e.`Status`, NULL, NULL, e.`ErrMsg`, e.`SmtpUsername`, e.`PayloadJson`,
|
||||
e.`IsDeleted`, UUID(), e.`CreateUserId`, e.`CreateTime`, e.`UpdateUserId`, e.`UpdateTime`
|
||||
FROM `t_order_notify_email_log` e
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM `t_order_notify_log` n
|
||||
WHERE n.`Channel` = ''email''
|
||||
AND n.`OrderId` = e.`OrderId`
|
||||
AND n.`EventCode` = e.`EventCode`
|
||||
AND n.`CreateTime` = e.`CreateTime`
|
||||
AND IFNULL(n.`Status`, '''') = IFNULL(e.`Status`, '''')
|
||||
AND IFNULL(n.`Recipient`, '''') = IFNULL(e.`ToEmail`, '''')
|
||||
)',
|
||||
'SELECT ''skip email migrate'' AS info'
|
||||
);
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 旧表 t_wechat_notify_log / t_order_notify_email_log 可保留只读;确认无流量后再手工 DROP
|
||||
SELECT 'migrate_order_notify_all_20261121 done' AS info;
|
||||
@ -1,11 +1,14 @@
|
||||
namespace Oms.Application.Dtos.Customers;
|
||||
|
||||
/// <summary>客户微信通知前置状态 + 订阅项。</summary>
|
||||
/// <summary>客户订单通知前置状态 + 订阅项(微信 / 邮件)。</summary>
|
||||
public class CustomerWechatNotifyStatusOutput
|
||||
{
|
||||
/// <summary>是否已绑定微信 OpenId。</summary>
|
||||
public bool HasOpenId { get; set; }
|
||||
|
||||
/// <summary>是否已配置客户邮箱。</summary>
|
||||
public bool HasEmail { get; set; }
|
||||
|
||||
/// <summary>是否已配置公众号关注跳转(仅提示用)。</summary>
|
||||
public bool HasFollowUrl { get; set; }
|
||||
|
||||
@ -20,11 +23,17 @@ public class CustomerWechatNotifyPrefItemOutput
|
||||
|
||||
public string EventName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>运营是否已启用该事件模板。</summary>
|
||||
/// <summary>运营是否已启用微信模板。</summary>
|
||||
public bool OpsEnabled { get; set; }
|
||||
|
||||
/// <summary>客户是否订阅。</summary>
|
||||
/// <summary>运营是否已启用邮件。</summary>
|
||||
public bool OpsEmailEnabled { get; set; }
|
||||
|
||||
/// <summary>客户是否订阅微信。</summary>
|
||||
public bool IsSubscribed { get; set; }
|
||||
|
||||
/// <summary>客户是否订阅邮件。</summary>
|
||||
public bool IsEmailSubscribed { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>保存客户订阅。</summary>
|
||||
@ -38,4 +47,6 @@ public class SaveCustomerWechatNotifyPrefItemInput
|
||||
public string EventCode { get; set; } = string.Empty;
|
||||
|
||||
public bool IsSubscribed { get; set; }
|
||||
|
||||
public bool IsEmailSubscribed { get; set; }
|
||||
}
|
||||
|
||||
164
src/Oms.Application/Dtos/Finance/FinanceContractDtos.cs
Normal file
164
src/Oms.Application/Dtos/Finance/FinanceContractDtos.cs
Normal file
@ -0,0 +1,164 @@
|
||||
namespace Oms.Application.Dtos.Finance;
|
||||
|
||||
/// <summary>合同列表查询。</summary>
|
||||
public class FinanceContractListInput
|
||||
{
|
||||
public int Page { get; set; } = 1;
|
||||
|
||||
public int PageSize { get; set; } = 50;
|
||||
|
||||
/// <summary>对方类型。</summary>
|
||||
public string? PartyType { get; set; }
|
||||
|
||||
public int? PartyId { get; set; }
|
||||
|
||||
/// <summary>状态;或 tab 值 expiringSoon。</summary>
|
||||
public string? Status { get; set; }
|
||||
|
||||
public string? Keyword { get; set; }
|
||||
|
||||
public DateTime? SignStartTime { get; set; }
|
||||
|
||||
public DateTime? SignEndTime { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>合同保存。</summary>
|
||||
public class FinanceContractSaveInput
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public string ContractName { get; set; } = string.Empty;
|
||||
|
||||
public string PartyType { get; set; } = string.Empty;
|
||||
|
||||
public int PartyId { get; set; }
|
||||
|
||||
public string? OurEntityName { get; set; }
|
||||
|
||||
public DateTime? SignDate { get; set; }
|
||||
|
||||
public DateTime EffectiveDate { get; set; }
|
||||
|
||||
public DateTime? ExpireDate { get; set; }
|
||||
|
||||
public bool AutoRenew { get; set; }
|
||||
|
||||
public string SettlementMethod { get; set; } = "monthly";
|
||||
|
||||
public int PaymentTermDays { get; set; } = 30;
|
||||
|
||||
public int? BillingDay { get; set; }
|
||||
|
||||
public int? PaymentDay { get; set; }
|
||||
|
||||
public string? Currency { get; set; }
|
||||
|
||||
public decimal? CreditLimit { get; set; }
|
||||
|
||||
public string? CommissionBaseType { get; set; }
|
||||
|
||||
public decimal? CommissionRate { get; set; }
|
||||
|
||||
public bool RequireVendorInvoice { get; set; }
|
||||
|
||||
public int? OwnerUserId { get; set; }
|
||||
|
||||
public string? OwnerName { get; set; }
|
||||
|
||||
public string? AttachmentUrls { get; set; }
|
||||
|
||||
public string? Remark { get; set; }
|
||||
|
||||
/// <summary>保存后直接生效。</summary>
|
||||
public bool Activate { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>合同 Id 入参。</summary>
|
||||
public class FinanceContractIdInput
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>终止合同。</summary>
|
||||
public class FinanceContractTerminateInput
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string? Reason { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>合同输出。</summary>
|
||||
public class FinanceContractOutput
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string ContractNo { get; set; } = string.Empty;
|
||||
|
||||
public string ContractName { get; set; } = string.Empty;
|
||||
|
||||
public string PartyType { get; set; } = string.Empty;
|
||||
|
||||
public string PartyTypeName { get; set; } = string.Empty;
|
||||
|
||||
public int PartyId { get; set; }
|
||||
|
||||
public string? PartyCode { get; set; }
|
||||
|
||||
public string? PartyName { get; set; }
|
||||
|
||||
public string? OurEntityName { get; set; }
|
||||
|
||||
public DateTime? SignDate { get; set; }
|
||||
|
||||
public DateTime EffectiveDate { get; set; }
|
||||
|
||||
public DateTime? ExpireDate { get; set; }
|
||||
|
||||
public bool AutoRenew { get; set; }
|
||||
|
||||
public string SettlementMethod { get; set; } = string.Empty;
|
||||
|
||||
public string SettlementMethodName { get; set; } = string.Empty;
|
||||
|
||||
public int PaymentTermDays { get; set; }
|
||||
|
||||
public int? BillingDay { get; set; }
|
||||
|
||||
public int? PaymentDay { get; set; }
|
||||
|
||||
public string Currency { get; set; } = "CNY";
|
||||
|
||||
public decimal? CreditLimit { get; set; }
|
||||
|
||||
public string? CommissionBaseType { get; set; }
|
||||
|
||||
public decimal? CommissionRate { get; set; }
|
||||
|
||||
public bool RequireVendorInvoice { get; set; }
|
||||
|
||||
public int? OwnerUserId { get; set; }
|
||||
|
||||
public string? OwnerName { get; set; }
|
||||
|
||||
public string Status { get; set; } = string.Empty;
|
||||
|
||||
public string StatusName { get; set; } = string.Empty;
|
||||
|
||||
public string? AttachmentUrls { get; set; }
|
||||
|
||||
public int AttachmentCount { get; set; }
|
||||
|
||||
public string? Remark { get; set; }
|
||||
|
||||
public int? RenewedFromId { get; set; }
|
||||
|
||||
public DateTime? TerminatedTime { get; set; }
|
||||
|
||||
public string? TerminateReason { get; set; }
|
||||
|
||||
public bool ExpiringSoon { get; set; }
|
||||
|
||||
public DateTime CreateTime { get; set; }
|
||||
|
||||
public DateTime? UpdateTime { get; set; }
|
||||
}
|
||||
145
src/Oms.Application/Dtos/Finance/FinanceMasterDtos.cs
Normal file
145
src/Oms.Application/Dtos/Finance/FinanceMasterDtos.cs
Normal file
@ -0,0 +1,145 @@
|
||||
namespace Oms.Application.Dtos.Finance;
|
||||
|
||||
/// <summary>供应商列表查询。</summary>
|
||||
public class FinanceSupplierListInput
|
||||
{
|
||||
/// <summary>关键词:编码/名称。</summary>
|
||||
public string? Keyword { get; set; }
|
||||
|
||||
/// <summary>状态:1 停用 / 2 启用;空=全部。</summary>
|
||||
public byte? Status { get; set; }
|
||||
|
||||
public int Page { get; set; } = 1;
|
||||
|
||||
public int PageSize { get; set; } = 50;
|
||||
}
|
||||
|
||||
/// <summary>供应商保存。</summary>
|
||||
public class FinanceSupplierSaveInput
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
/// <summary>编码;新建必填。</summary>
|
||||
public string SupplierCode { get; set; } = string.Empty;
|
||||
|
||||
public string SupplierName { get; set; } = string.Empty;
|
||||
|
||||
public string? ContactName { get; set; }
|
||||
|
||||
public string? Phone { get; set; }
|
||||
|
||||
public string? Email { get; set; }
|
||||
|
||||
public string? BankAccountName { get; set; }
|
||||
|
||||
public string? BankName { get; set; }
|
||||
|
||||
public string? BankAccountNo { get; set; }
|
||||
|
||||
public string? Currency { get; set; }
|
||||
|
||||
/// <summary>1 停用 / 2 启用。</summary>
|
||||
public byte? Status { get; set; }
|
||||
|
||||
public string? Remark { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>供应商输出。</summary>
|
||||
public class FinanceSupplierOutput
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string SupplierCode { get; set; } = string.Empty;
|
||||
|
||||
public string SupplierName { get; set; } = string.Empty;
|
||||
|
||||
public string? ContactName { get; set; }
|
||||
|
||||
public string? Phone { get; set; }
|
||||
|
||||
public string? Email { get; set; }
|
||||
|
||||
public string? BankAccountName { get; set; }
|
||||
|
||||
public string? BankName { get; set; }
|
||||
|
||||
public string? BankAccountNo { get; set; }
|
||||
|
||||
public string Currency { get; set; } = "CNY";
|
||||
|
||||
public byte Status { get; set; }
|
||||
|
||||
public string? Remark { get; set; }
|
||||
|
||||
public DateTime CreateTime { get; set; }
|
||||
|
||||
public DateTime? UpdateTime { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>供应商删除。</summary>
|
||||
public class FinanceSupplierDeleteInput
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>公司账户列表查询。</summary>
|
||||
public class FinanceCompanyAccountListInput
|
||||
{
|
||||
public string? Keyword { get; set; }
|
||||
|
||||
public byte? Status { get; set; }
|
||||
|
||||
public int Page { get; set; } = 1;
|
||||
|
||||
public int PageSize { get; set; } = 50;
|
||||
}
|
||||
|
||||
/// <summary>公司账户保存。</summary>
|
||||
public class FinanceCompanyAccountSaveInput
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public string AccountName { get; set; } = string.Empty;
|
||||
|
||||
public string BankName { get; set; } = string.Empty;
|
||||
|
||||
public string AccountNo { get; set; } = string.Empty;
|
||||
|
||||
public string? Currency { get; set; }
|
||||
|
||||
public bool IsDefault { get; set; }
|
||||
|
||||
public byte? Status { get; set; }
|
||||
|
||||
public string? Remark { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>公司账户输出。</summary>
|
||||
public class FinanceCompanyAccountOutput
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string AccountName { get; set; } = string.Empty;
|
||||
|
||||
public string BankName { get; set; } = string.Empty;
|
||||
|
||||
public string AccountNo { get; set; } = string.Empty;
|
||||
|
||||
public string Currency { get; set; } = "CNY";
|
||||
|
||||
public bool IsDefault { get; set; }
|
||||
|
||||
public byte Status { get; set; }
|
||||
|
||||
public string? Remark { get; set; }
|
||||
|
||||
public DateTime CreateTime { get; set; }
|
||||
|
||||
public DateTime? UpdateTime { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>公司账户删除。</summary>
|
||||
public class FinanceCompanyAccountDeleteInput
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
200
src/Oms.Application/Dtos/Finance/FinancePaymentDtos.cs
Normal file
200
src/Oms.Application/Dtos/Finance/FinancePaymentDtos.cs
Normal file
@ -0,0 +1,200 @@
|
||||
namespace Oms.Application.Dtos.Finance;
|
||||
|
||||
/// <summary>付款申请列表查询。</summary>
|
||||
public class FinancePaymentApplyListInput
|
||||
{
|
||||
public int Page { get; set; } = 1;
|
||||
|
||||
public int PageSize { get; set; } = 50;
|
||||
|
||||
public string? Status { get; set; }
|
||||
|
||||
public string? PaymentType { get; set; }
|
||||
|
||||
public string? PayeeType { get; set; }
|
||||
|
||||
public int? PayeeId { get; set; }
|
||||
|
||||
public string? Currency { get; set; }
|
||||
|
||||
public string? Keyword { get; set; }
|
||||
|
||||
public DateTime? StartTime { get; set; }
|
||||
|
||||
public DateTime? EndTime { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>付款申请明细行入参。</summary>
|
||||
public class FinancePaymentApplyLineInput
|
||||
{
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
public decimal Amount { get; set; }
|
||||
|
||||
public string? RefNo { get; set; }
|
||||
|
||||
public string? Remark { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>付款申请保存。</summary>
|
||||
public class FinancePaymentApplySaveInput
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public string PaymentType { get; set; } = string.Empty;
|
||||
|
||||
public int PayeeId { get; set; }
|
||||
|
||||
public int? ContractId { get; set; }
|
||||
|
||||
public string? Currency { get; set; }
|
||||
|
||||
public DateTime? ExpectPayDate { get; set; }
|
||||
|
||||
public string? PayeeAccountName { get; set; }
|
||||
|
||||
public string? PayeeBankName { get; set; }
|
||||
|
||||
public string? PayeeAccountNo { get; set; }
|
||||
|
||||
public int? CompanyAccountId { get; set; }
|
||||
|
||||
public string? AttachmentUrls { get; set; }
|
||||
|
||||
public string? Remark { get; set; }
|
||||
|
||||
/// <summary>保存后提交审批。</summary>
|
||||
public bool Submit { get; set; }
|
||||
|
||||
public List<FinancePaymentApplyLineInput> Lines { get; set; } = [];
|
||||
}
|
||||
|
||||
/// <summary>付款申请 Id。</summary>
|
||||
public class FinancePaymentApplyIdInput
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>登记付款。</summary>
|
||||
public class FinancePaymentMarkPaidInput
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public DateTime? PaidTime { get; set; }
|
||||
|
||||
public string? BankTxnNo { get; set; }
|
||||
|
||||
public string? PaidVoucherUrl { get; set; }
|
||||
|
||||
public string? Remark { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>付款申请明细输出。</summary>
|
||||
public class FinancePaymentApplyLineOutput
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
public decimal Amount { get; set; }
|
||||
|
||||
public string? RefNo { get; set; }
|
||||
|
||||
public string? Remark { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>付款申请输出。</summary>
|
||||
public class FinancePaymentApplyOutput
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string ApplyNo { get; set; } = string.Empty;
|
||||
|
||||
public string PaymentType { get; set; } = string.Empty;
|
||||
|
||||
public string PaymentTypeName { get; set; } = string.Empty;
|
||||
|
||||
public string PayeeType { get; set; } = string.Empty;
|
||||
|
||||
public string PayeeTypeName { get; set; } = string.Empty;
|
||||
|
||||
public int PayeeId { get; set; }
|
||||
|
||||
public string? PayeeCode { get; set; }
|
||||
|
||||
public string? PayeeName { get; set; }
|
||||
|
||||
public int? ContractId { get; set; }
|
||||
|
||||
public string? ContractNo { get; set; }
|
||||
|
||||
public string Currency { get; set; } = "CNY";
|
||||
|
||||
public decimal AmountTotal { get; set; }
|
||||
|
||||
public DateTime? ExpectPayDate { get; set; }
|
||||
|
||||
public string? PayeeAccountName { get; set; }
|
||||
|
||||
public string? PayeeBankName { get; set; }
|
||||
|
||||
public string? PayeeAccountNo { get; set; }
|
||||
|
||||
public int? CompanyAccountId { get; set; }
|
||||
|
||||
public string? CompanyAccountName { get; set; }
|
||||
|
||||
public string Status { get; set; } = string.Empty;
|
||||
|
||||
public string StatusName { get; set; } = string.Empty;
|
||||
|
||||
public string? ApplicantName { get; set; }
|
||||
|
||||
public string? AttachmentUrls { get; set; }
|
||||
|
||||
public string? Remark { get; set; }
|
||||
|
||||
public int? ApprovalInstanceId { get; set; }
|
||||
|
||||
public string? ApprovalInstanceNo { get; set; }
|
||||
|
||||
public bool ApprovalPending { get; set; }
|
||||
|
||||
public string? RejectReason { get; set; }
|
||||
|
||||
public DateTime? PaidTime { get; set; }
|
||||
|
||||
public string? BankTxnNo { get; set; }
|
||||
|
||||
public string? PaidBy { get; set; }
|
||||
|
||||
public string? PaidVoucherUrl { get; set; }
|
||||
|
||||
public DateTime CreateTime { get; set; }
|
||||
|
||||
public DateTime? UpdateTime { get; set; }
|
||||
|
||||
public string? Decision { get; set; }
|
||||
|
||||
public string? Message { get; set; }
|
||||
|
||||
public List<FinancePaymentApplyLineOutput> Lines { get; set; } = [];
|
||||
}
|
||||
|
||||
/// <summary>付款申请汇总。</summary>
|
||||
public class FinancePaymentApplySummaryOutput
|
||||
{
|
||||
public List<FinancePaymentApplySummaryItemOutput> Items { get; set; } = [];
|
||||
}
|
||||
|
||||
/// <summary>付款申请汇总项(按币种)。</summary>
|
||||
public class FinancePaymentApplySummaryItemOutput
|
||||
{
|
||||
public string Currency { get; set; } = "CNY";
|
||||
|
||||
public decimal PendingApprovalAmount { get; set; }
|
||||
|
||||
public decimal PendingPayAmount { get; set; }
|
||||
|
||||
public decimal PaidThisMonthAmount { get; set; }
|
||||
}
|
||||
451
src/Oms.Application/Dtos/Finance/InvoiceDtos.cs
Normal file
451
src/Oms.Application/Dtos/Finance/InvoiceDtos.cs
Normal file
@ -0,0 +1,451 @@
|
||||
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? CustomerCode { get; set; }
|
||||
|
||||
/// <summary>客户名称(列表展示用)。</summary>
|
||||
public string? CustomerName { 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; } = [];
|
||||
}
|
||||
49
src/Oms.Application/Dtos/Orders/OrderNotifyLogDtos.cs
Normal file
49
src/Oms.Application/Dtos/Orders/OrderNotifyLogDtos.cs
Normal file
@ -0,0 +1,49 @@
|
||||
namespace Oms.Application.Dtos.Orders;
|
||||
|
||||
/// <summary>订单通知日志条目(微信 / 邮件)。</summary>
|
||||
public class OrderNotifyLogOutput
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public int OrderId { get; set; }
|
||||
|
||||
/// <summary>wechat / email。</summary>
|
||||
public string Channel { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>微信 / 邮件。</summary>
|
||||
public string ChannelName { get; set; } = string.Empty;
|
||||
|
||||
public string EventCode { get; set; } = string.Empty;
|
||||
|
||||
public string EventName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>OpenId 或邮箱。</summary>
|
||||
public string? Recipient { get; set; }
|
||||
|
||||
public string? TemplateRef { get; set; }
|
||||
|
||||
public string? Subject { get; set; }
|
||||
|
||||
/// <summary>sent / failed / skipped。</summary>
|
||||
public string Status { get; set; } = string.Empty;
|
||||
|
||||
public string? ProviderMsgId { get; set; }
|
||||
|
||||
public int? ErrCode { get; set; }
|
||||
|
||||
public string? ErrMsg { get; set; }
|
||||
|
||||
public string? SmtpUsername { get; set; }
|
||||
|
||||
/// <summary>列表「内容」摘要。</summary>
|
||||
public string Summary { get; set; } = string.Empty;
|
||||
|
||||
public string? PayloadJson { get; set; }
|
||||
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
|
||||
public class OrderNotifyLogListOutput
|
||||
{
|
||||
public List<OrderNotifyLogOutput> Items { get; set; } = [];
|
||||
}
|
||||
55
src/Oms.Application/Dtos/System/BrandCopyDtos.cs
Normal file
55
src/Oms.Application/Dtos/System/BrandCopyDtos.cs
Normal file
@ -0,0 +1,55 @@
|
||||
namespace Oms.Application.Dtos.System;
|
||||
|
||||
/// <summary>
|
||||
/// 品牌文案(存对象存储 JSON,非数据库;前端可本地缓存秒开)。
|
||||
/// </summary>
|
||||
public class BrandCopyOutput
|
||||
{
|
||||
/// <summary>顶栏 / 官网短名,如 BCD。</summary>
|
||||
public string NavName { get; set; } = "BCD";
|
||||
|
||||
/// <summary>顶栏 / 官网全称,如 Business & Customer & Delivery。</summary>
|
||||
public string NavFullName { get; set; } = "Business & Customer & Delivery";
|
||||
|
||||
/// <summary>官网 AI 顾问欢迎主标题(中文)。</summary>
|
||||
public string AiWelcomeTitleZh { get; set; } = "BCD · 一站式跨境物流顾问";
|
||||
|
||||
/// <summary>官网 AI 顾问欢迎短标题(中文,窄屏备用)。</summary>
|
||||
public string AiWelcomeTitleShortZh { get; set; } = "BCD · 跨境物流顾问";
|
||||
|
||||
/// <summary>官网 AI 顾问欢迎主标题(英文)。</summary>
|
||||
public string AiWelcomeTitleEn { get; set; } = "BCD · One-stop cross-border logistics advisor";
|
||||
|
||||
/// <summary>官网 AI 顾问欢迎短标题(英文)。</summary>
|
||||
public string AiWelcomeTitleShortEn { get; set; } = "BCD · Logistics advisor";
|
||||
|
||||
/// <summary>工信部 ICP 备案号(官网页脚 / 顾问栏展示)。</summary>
|
||||
public string Icp { get; set; } = "粤ICP备2025463970号-2";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存品牌文案。
|
||||
/// </summary>
|
||||
public class BrandCopySaveInput
|
||||
{
|
||||
/// <summary>顶栏 / 官网短名。</summary>
|
||||
public string NavName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>顶栏 / 官网全称。</summary>
|
||||
public string NavFullName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>AI 欢迎主标题(中文)。</summary>
|
||||
public string AiWelcomeTitleZh { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>AI 欢迎短标题(中文)。</summary>
|
||||
public string AiWelcomeTitleShortZh { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>AI 欢迎主标题(英文)。</summary>
|
||||
public string AiWelcomeTitleEn { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>AI 欢迎短标题(英文)。</summary>
|
||||
public string AiWelcomeTitleShortEn { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>工信部 ICP 备案号。</summary>
|
||||
public string Icp { get; set; } = string.Empty;
|
||||
}
|
||||
@ -6,22 +6,22 @@ namespace Oms.Application.Dtos.System;
|
||||
public class BrandLogoOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 系统顶栏 Logo 可访问 URL;未配置时为空。
|
||||
/// 系统顶栏 Logo 同源 API 地址(/system/other-config/brand-logo/file?...);未配置时为空。
|
||||
/// </summary>
|
||||
public string PortalUrl { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 官网 Logo 可访问 URL;未配置时为空。
|
||||
/// 官网 Logo 同源 API 地址;未配置时为空。
|
||||
/// </summary>
|
||||
public string SiteUrl { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 网站标签(favicon)可访问 URL;未配置时为空。
|
||||
/// 网站标签(favicon)同源 API 地址;未配置时为空。
|
||||
/// </summary>
|
||||
public string FaviconUrl { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 启动页 / 空态吉祥物可访问 URL;未配置时为空。
|
||||
/// 启动页 / 空态吉祥物同源 API 地址;未配置时为空。
|
||||
/// </summary>
|
||||
public string MascotUrl { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
@ -6,12 +6,12 @@ namespace Oms.Application.Dtos.System;
|
||||
public class PaymentReceiveQrOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 支付宝收款码可访问 URL;未配置时为空。
|
||||
/// 支付宝收款码同源 API 地址(/system/other-config/payment-qr/file?...);未配置时为空。
|
||||
/// </summary>
|
||||
public string AlipayUrl { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 微信收款码可访问 URL;未配置时为空。
|
||||
/// 微信收款码同源 API 地址;未配置时为空。
|
||||
/// </summary>
|
||||
public string WechatUrl { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
namespace Oms.Application.Dtos.System;
|
||||
|
||||
/// <summary>微信订单通知模板配置输出。</summary>
|
||||
/// <summary>订单通知模板配置输出(微信 + 邮件)。</summary>
|
||||
public class WechatOrderNotifyTemplateOutput
|
||||
{
|
||||
public int Id { get; set; }
|
||||
@ -20,14 +20,29 @@ public class WechatOrderNotifyTemplateOutput
|
||||
/// <summary>字段映射 JSON。</summary>
|
||||
public string? FieldMappingJson { get; set; }
|
||||
|
||||
/// <summary>是否启用。</summary>
|
||||
/// <summary>是否启用微信推送。</summary>
|
||||
public bool IsEnabled { get; set; }
|
||||
|
||||
/// <summary>是否启用邮件通知。</summary>
|
||||
public bool EmailEnabled { get; set; }
|
||||
|
||||
/// <summary>batch-email 模板名称。</summary>
|
||||
public string? EmailTemplateName { get; set; }
|
||||
|
||||
/// <summary>batch-email 模板所属用户。</summary>
|
||||
public int? EmailTemplateOwnerUserId { get; set; }
|
||||
|
||||
/// <summary>发信 SMTP 所属用户;0 表示系统发信账号。</summary>
|
||||
public int? EmailSmtpOwnerUserId { get; set; }
|
||||
|
||||
/// <summary>是否使用系统发信 SMTP。</summary>
|
||||
public bool EmailUseSystemSmtp { get; set; }
|
||||
|
||||
/// <summary>备注。</summary>
|
||||
public string? Remark { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>保存微信订单通知模板。</summary>
|
||||
/// <summary>保存订单通知模板。</summary>
|
||||
public class SaveWechatOrderNotifyTemplateInput
|
||||
{
|
||||
/// <summary>事件码。</summary>
|
||||
@ -42,13 +57,35 @@ public class SaveWechatOrderNotifyTemplateInput
|
||||
/// <summary>字段映射 JSON。</summary>
|
||||
public string? FieldMappingJson { get; set; }
|
||||
|
||||
/// <summary>是否启用。</summary>
|
||||
/// <summary>是否启用微信推送。</summary>
|
||||
public bool IsEnabled { get; set; }
|
||||
|
||||
/// <summary>是否启用邮件通知。</summary>
|
||||
public bool EmailEnabled { get; set; }
|
||||
|
||||
/// <summary>batch-email 模板名称(启用邮件时必填)。</summary>
|
||||
public string? EmailTemplateName { get; set; }
|
||||
|
||||
/// <summary>是否使用系统发信 SMTP(OwnerUserId=0)。</summary>
|
||||
public bool EmailUseSystemSmtp { get; set; }
|
||||
|
||||
/// <summary>备注。</summary>
|
||||
public string? Remark { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>系统发信 SMTP 状态。</summary>
|
||||
public class OrderNotifySystemSmtpStatusOutput
|
||||
{
|
||||
/// <summary>是否已配置系统 SMTP(OwnerUserId=0)。</summary>
|
||||
public bool Configured { get; set; }
|
||||
|
||||
/// <summary>发件账号(脱敏场景仍返回用户名)。</summary>
|
||||
public string? SmtpUsername { get; set; }
|
||||
|
||||
/// <summary>发件人显示名。</summary>
|
||||
public string? FromName { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>试发入参。</summary>
|
||||
public class TrialWechatOrderNotifyInput
|
||||
{
|
||||
@ -61,3 +98,89 @@ public class TrialWechatOrderNotifyInput
|
||||
/// <summary>运单号(OrderId 为空时使用)。</summary>
|
||||
public string? ServiceNo { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>试发结果(含微信/邮件请求响应明细)。</summary>
|
||||
public class TrialWechatOrderNotifyResultOutput
|
||||
{
|
||||
/// <summary>是否最终发送成功(微信成功即 true;邮件结果见 Email)。</summary>
|
||||
public bool Success { get; set; }
|
||||
|
||||
/// <summary>是否跳过发送(未启用/未绑 OpenId 等)。</summary>
|
||||
public bool Skipped { get; set; }
|
||||
|
||||
/// <summary>状态:sent / failed / skipped。</summary>
|
||||
public string Status { get; set; } = "skipped";
|
||||
|
||||
/// <summary>说明或错误信息。</summary>
|
||||
public string? Message { get; set; }
|
||||
|
||||
/// <summary>订单 Id。</summary>
|
||||
public int OrderId { get; set; }
|
||||
|
||||
/// <summary>运单号。</summary>
|
||||
public string? ServiceNo { get; set; }
|
||||
|
||||
/// <summary>事件码。</summary>
|
||||
public string EventCode { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>事件名。</summary>
|
||||
public string? EventName { get; set; }
|
||||
|
||||
/// <summary>接收 OpenId。</summary>
|
||||
public string? OpenId { get; set; }
|
||||
|
||||
/// <summary>微信模板 ID。</summary>
|
||||
public string? TemplateId { get; set; }
|
||||
|
||||
/// <summary>跳转 URL。</summary>
|
||||
public string? Url { get; set; }
|
||||
|
||||
/// <summary>微信接口地址(不含 access_token)。</summary>
|
||||
public string? RequestUrl { get; set; }
|
||||
|
||||
/// <summary>发给微信的请求体 JSON。</summary>
|
||||
public string? RequestBody { get; set; }
|
||||
|
||||
/// <summary>微信返回 JSON(或合成摘要)。</summary>
|
||||
public string? ResponseBody { get; set; }
|
||||
|
||||
/// <summary>微信 msgid。</summary>
|
||||
public string? WxMsgId { get; set; }
|
||||
|
||||
/// <summary>微信 errcode。</summary>
|
||||
public int? ErrCode { get; set; }
|
||||
|
||||
/// <summary>邮件通道试发结果。</summary>
|
||||
public TrialOrderNotifyEmailResultOutput? Email { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>订单通知邮件试发明细。</summary>
|
||||
public class TrialOrderNotifyEmailResultOutput
|
||||
{
|
||||
/// <summary>是否发送成功。</summary>
|
||||
public bool Success { get; set; }
|
||||
|
||||
/// <summary>是否跳过。</summary>
|
||||
public bool Skipped { get; set; }
|
||||
|
||||
/// <summary>状态:sent / failed / skipped。</summary>
|
||||
public string Status { get; set; } = "skipped";
|
||||
|
||||
/// <summary>说明。</summary>
|
||||
public string? Message { get; set; }
|
||||
|
||||
/// <summary>收件邮箱。</summary>
|
||||
public string? ToEmail { get; set; }
|
||||
|
||||
/// <summary>模板名称。</summary>
|
||||
public string? TemplateName { get; set; }
|
||||
|
||||
/// <summary>替换后主题。</summary>
|
||||
public string? Subject { get; set; }
|
||||
|
||||
/// <summary>替换后正文。</summary>
|
||||
public string? Body { get; set; }
|
||||
|
||||
/// <summary>发件 SMTP 账号。</summary>
|
||||
public string? SmtpUsername { get; set; }
|
||||
}
|
||||
|
||||
@ -0,0 +1,77 @@
|
||||
using Fake.DependencyInjection;
|
||||
using Fake.EventBus;
|
||||
using Fake.UnitOfWork;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Oms.Application.Services.WeChatNotify;
|
||||
using Oms.Domain.OrdersAggregate.Repositories;
|
||||
|
||||
namespace Oms.Application.Messaging.OrderSideEffects;
|
||||
|
||||
/// <summary>消费订单通知异步任务(微信 + 邮件)。</summary>
|
||||
public sealed class OrderNotifyEventHandler(
|
||||
IOrderRepository orderRepository,
|
||||
WechatOrderNotifyDispatcher notifyDispatcher,
|
||||
IUnitOfWorkManager unitOfWorkManager,
|
||||
ILogger<OrderNotifyEventHandler> logger)
|
||||
: IEventHandler<OrderNotifyIntegrationEvent>, ITransientDependency
|
||||
{
|
||||
public async Task HandleAsync(
|
||||
OrderNotifyIntegrationEvent @event,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (@event.OrderId <= 0 || string.IsNullOrWhiteSpace(@event.EventCode))
|
||||
{
|
||||
logger.LogWarning(
|
||||
"OrderNotify skipped invalid payload OrderId={OrderId} Event={EventCode}",
|
||||
@event.OrderId,
|
||||
@event.EventCode);
|
||||
return;
|
||||
}
|
||||
|
||||
using var unitOfWork = unitOfWorkManager.Begin(OmsOutboxUnitOfWork.Transactional());
|
||||
try
|
||||
{
|
||||
var order = await orderRepository.FirstOrDefaultAsync(
|
||||
x => x.Id == @event.OrderId,
|
||||
cancellationToken);
|
||||
if (order == null)
|
||||
{
|
||||
logger.LogWarning(
|
||||
"OrderNotify order not found OrderId={OrderId} Event={EventCode}",
|
||||
@event.OrderId,
|
||||
@event.EventCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
await notifyDispatcher.NotifyDetailedAsync(
|
||||
order,
|
||||
@event.EventCode,
|
||||
@event.Remark,
|
||||
@event.Force,
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
await unitOfWork.CompleteAsync(cancellationToken);
|
||||
}
|
||||
catch (OrderNotifyRetryableException ex)
|
||||
{
|
||||
// 不 Complete:外层 Outbox/MQ 可重试
|
||||
logger.LogWarning(
|
||||
ex,
|
||||
"OrderNotify retryable OrderId={OrderId} Event={EventCode}",
|
||||
@event.OrderId,
|
||||
@event.EventCode);
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 业务跳过 / 不可重试:Ack,避免打满队列
|
||||
logger.LogWarning(
|
||||
ex,
|
||||
"OrderNotify failed(non-retry) OrderId={OrderId} Event={EventCode}",
|
||||
@event.OrderId,
|
||||
@event.EventCode);
|
||||
await unitOfWork.CompleteAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
using Fake.EventBus.Distributed;
|
||||
|
||||
namespace Oms.Application.Messaging.OrderSideEffects;
|
||||
|
||||
/// <summary>
|
||||
/// 订单状态通知(微信模板 + 邮件),走 Fake.EventBus Outbox。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class OrderNotifyIntegrationEvent : IntegrationEvent
|
||||
{
|
||||
public int OrderId { get; set; }
|
||||
|
||||
/// <summary>事件码,见 <see cref="Domain.SystemAggregate.Consts.WechatOrderNotifyEventCodes"/>。</summary>
|
||||
public string EventCode { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>可选备注(问题件说明等)。</summary>
|
||||
public string? Remark { get; set; }
|
||||
|
||||
/// <summary>试发/强制:跳过客户订阅与去重(微信)。</summary>
|
||||
public bool Force { get; set; }
|
||||
}
|
||||
@ -173,23 +173,24 @@ public sealed class TrackChangeOrderStatusApplier(
|
||||
operatorType: "system",
|
||||
source: "trackCenter");
|
||||
|
||||
await unitOfWork.CompleteAsync(cancellationToken);
|
||||
|
||||
// 与返佣等同事务写入 Outbox,Commit 后异步发微信/邮件
|
||||
if (string.Equals(targetStatus, OrderStatusCodes.DeliverySuccess, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
await wechatOrderNotifyDispatcher.TryNotifyAsync(
|
||||
await wechatOrderNotifyDispatcher.EnqueueNotifyAsync(
|
||||
order,
|
||||
WechatOrderNotifyEventCodes.DeliverySuccess,
|
||||
cancellationToken: cancellationToken);
|
||||
}
|
||||
else if (string.Equals(targetStatus, OrderStatusCodes.DeliveryFailed, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
await wechatOrderNotifyDispatcher.TryNotifyAsync(
|
||||
await wechatOrderNotifyDispatcher.EnqueueNotifyAsync(
|
||||
order,
|
||||
WechatOrderNotifyEventCodes.DeliveryFailed,
|
||||
cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
await unitOfWork.CompleteAsync(cancellationToken);
|
||||
|
||||
logger.LogInformation(
|
||||
"TrackChange applied OrderId={OrderId} ServiceNo={ServiceNo} {From} → {To} TrackStatusCode={TrackStatusCode}",
|
||||
order.Id,
|
||||
|
||||
@ -15,6 +15,7 @@ using Oms.Application.Labeling.Hiprint;
|
||||
using Oms.Application.Services.Approval;
|
||||
using Oms.Application.Services.Approval.Contracts;
|
||||
using Oms.Application.Services.Channels;
|
||||
using Oms.Application.Services.Finance;
|
||||
using Oms.Application.Services.Recharge;
|
||||
using Oms.Application.Services.Storage;
|
||||
using Oms.Application.Shared;
|
||||
@ -63,6 +64,7 @@ public class OmsApplicationModule : FakeModule
|
||||
// 否则 Approve 会空跑成 Executed、不落发布/入账。
|
||||
context.Services.AddTransient<IApprovalOperationHandler, SalesProductPricePublishApprovalHandler>();
|
||||
context.Services.AddTransient<IApprovalOperationHandler, RechargeCreditApprovalHandler>();
|
||||
context.Services.AddTransient<IApprovalOperationHandler, InvoiceIssueApprovalHandler>();
|
||||
context.Services.AddTransient<IApprovalOperationHandler, NoopApprovalHandler>();
|
||||
|
||||
context.Services.AddHttpClient(FileStorageService.UrlFetchClientName, client =>
|
||||
|
||||
@ -31,6 +31,18 @@ public static class ApprovalOperationCatalog
|
||||
"Finance",
|
||||
SupportsCondition: false,
|
||||
ConditionHint: "已接入提交接口;未配置或未启用不拦截(直接入账),启用后提交审批"),
|
||||
new(
|
||||
ApprovalCodes.FinanceInvoiceIssue,
|
||||
"发票开具",
|
||||
"Finance",
|
||||
SupportsCondition: false,
|
||||
ConditionHint: "已接入提交接口;未配置或未启用不拦截(直接通过),启用后提交审批"),
|
||||
new(
|
||||
ApprovalCodes.FinancePaymentApply,
|
||||
"付款申请",
|
||||
"Finance",
|
||||
SupportsCondition: false,
|
||||
ConditionHint: "已接入提交接口;未配置或未启用不拦截(直接待付款),启用后提交审批"),
|
||||
new(
|
||||
"Marketing.Commission.Withdraw",
|
||||
"佣金提现",
|
||||
|
||||
@ -12,5 +12,6 @@
|
||||
已接入:
|
||||
- `Channel.SalesProduct.PublishPrice`(`/channel/sales-product/publish`,operatorType=price)。未配置/未启用 Bypass 直接发布;启用后由 `SalesProductPricePublishApprovalHandler` 落发布记录。
|
||||
- `Finance.Recharge.Credit`(`/recharge/recharge/submit`)。未配置/未启用 Bypass 直接入账;启用后建单,终审由 `RechargeCreditApprovalHandler` 入账,驳回/撤回同步充值记录为驳回。
|
||||
- `Finance.Payment.Apply`(`/finance/payment-apply/submit`)。未配置/未启用 Bypass 直接待付款;启用后建单,终审由 `PaymentApplyApprovalHandler` 置为待付款,驳回/撤回同步申请状态。
|
||||
|
||||
联调也可用「模拟提交」+ 操作码 `System.Approval.Simulate`。
|
||||
|
||||
@ -10,7 +10,7 @@ using Oms.Domain.SystemAggregate.Repositories;
|
||||
namespace Oms.Application.Services.Customers;
|
||||
|
||||
/// <summary>
|
||||
/// 客户微信订单通知订阅(H5/门户)。
|
||||
/// 客户订单通知订阅(微信 / 邮件;H5/门户)。
|
||||
/// </summary>
|
||||
[ApiExplorerSettings(GroupName = "OMS-Customer")]
|
||||
public class CustomerWechatNotifyService : ApplicationService
|
||||
@ -44,9 +44,12 @@ public class CustomerWechatNotifyService : ApplicationService
|
||||
SystemOtherConfigCodes.WeChatMpFollow,
|
||||
cancellationToken);
|
||||
|
||||
var hasEmail = !string.IsNullOrWhiteSpace(customer.Email) && customer.Email.Contains('@');
|
||||
|
||||
return new CustomerWechatNotifyStatusOutput
|
||||
{
|
||||
HasOpenId = !string.IsNullOrWhiteSpace(customer.WechatOpenid),
|
||||
HasEmail = hasEmail,
|
||||
HasFollowUrl = !string.IsNullOrWhiteSpace(follow?.BaseUrl),
|
||||
Items = WechatOrderNotifyEventCodes.All.Select(e =>
|
||||
{
|
||||
@ -57,7 +60,10 @@ public class CustomerWechatNotifyService : ApplicationService
|
||||
EventCode = e.Code,
|
||||
EventName = e.Name,
|
||||
OpsEnabled = tpl is { IsEnabled: true } && !string.IsNullOrWhiteSpace(tpl.TemplateId),
|
||||
IsSubscribed = pref?.IsSubscribed == true
|
||||
OpsEmailEnabled = tpl is { EmailEnabled: true }
|
||||
&& !string.IsNullOrWhiteSpace(tpl.EmailTemplateName),
|
||||
IsSubscribed = pref?.IsSubscribed == true,
|
||||
IsEmailSubscribed = pref?.IsEmailSubscribed == true
|
||||
};
|
||||
}).ToList()
|
||||
};
|
||||
@ -93,13 +99,15 @@ public class CustomerWechatNotifyService : ApplicationService
|
||||
{
|
||||
CustomerId = customer.Id,
|
||||
EventCode = code,
|
||||
IsSubscribed = item.IsSubscribed
|
||||
IsSubscribed = item.IsSubscribed,
|
||||
IsEmailSubscribed = item.IsEmailSubscribed
|
||||
},
|
||||
cancellationToken: cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.IsSubscribed = item.IsSubscribed;
|
||||
entity.IsEmailSubscribed = item.IsEmailSubscribed;
|
||||
entity.UpdateTime = DateTime.Now;
|
||||
await PrefRepository.UpdateAsync(entity, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
558
src/Oms.Application/Services/Finance/FinanceContractService.cs
Normal file
558
src/Oms.Application/Services/Finance/FinanceContractService.cs
Normal file
@ -0,0 +1,558 @@
|
||||
using System.Linq.Expressions;
|
||||
using Fake.Application;
|
||||
using Fake.Domain.Exceptions;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Oms.Application.Dtos.Finance;
|
||||
using Oms.Application.Dtos.Shared;
|
||||
using Oms.Application.Shared;
|
||||
using Oms.Domain.AgentsAggregate.Repositories;
|
||||
using Oms.Domain.CustomersAggregate.Repositories;
|
||||
using Oms.Domain.FinanceAggregate.Consts;
|
||||
using Oms.Domain.FinanceAggregate.Entities;
|
||||
using Oms.Domain.FinanceAggregate.Repositories;
|
||||
|
||||
namespace Oms.Application.Services.Finance;
|
||||
|
||||
/// <summary>
|
||||
/// 财务合同管理(客户 / 供应商 / 代理)。
|
||||
/// </summary>
|
||||
[ApiExplorerSettings(GroupName = "OMS-Finance")]
|
||||
public class FinanceContractService : ApplicationService
|
||||
{
|
||||
private IFinanceContractRepository ContractRepository =>
|
||||
LazyServiceProvider.GetRequiredService<IFinanceContractRepository>();
|
||||
|
||||
private IFinanceSupplierRepository SupplierRepository =>
|
||||
LazyServiceProvider.GetRequiredService<IFinanceSupplierRepository>();
|
||||
|
||||
private ICustomerRepository CustomerRepository =>
|
||||
LazyServiceProvider.GetRequiredService<ICustomerRepository>();
|
||||
|
||||
private IAgentRepository AgentRepository =>
|
||||
LazyServiceProvider.GetRequiredService<IAgentRepository>();
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询合同。
|
||||
/// </summary>
|
||||
[HttpGet("/finance/contract/list")]
|
||||
public async Task<OmsPageResult<FinanceContractOutput>> GetListAsync([FromQuery] FinanceContractListInput input)
|
||||
{
|
||||
await RefreshExpiredContractsAsync();
|
||||
var predicate = BuildListPredicate(input);
|
||||
var page = OmsDocHelper.NormalizePage(input.Page);
|
||||
var pageSize = OmsDocHelper.NormalizePageSize(input.PageSize);
|
||||
var entities = await ContractRepository.GetPagedListAsync(
|
||||
predicate,
|
||||
page,
|
||||
pageSize,
|
||||
new Dictionary<string, bool>
|
||||
{
|
||||
[nameof(FinanceContract.CreateTime)] = false,
|
||||
[nameof(FinanceContract.Id)] = false
|
||||
});
|
||||
var total = await ContractRepository.CountAsync(predicate);
|
||||
var items = await MapListAsync(entities);
|
||||
return new OmsPageResult<FinanceContractOutput>
|
||||
{
|
||||
Items = items,
|
||||
Total = total
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 合同详情。
|
||||
/// </summary>
|
||||
[HttpGet("/finance/contract/detail")]
|
||||
public async Task<FinanceContractOutput> GetDetailAsync([FromQuery] int id)
|
||||
{
|
||||
await RefreshExpiredContractsAsync();
|
||||
var entity = await ContractRepository.FirstOrDefaultAsync(x => x.Id == id)
|
||||
?? throw new BusinessException("合同不存在");
|
||||
var list = await MapListAsync([entity]);
|
||||
return list[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 按对方查询当前生效合同(付款申请带出)。
|
||||
/// </summary>
|
||||
[HttpGet("/finance/contract/active-by-party")]
|
||||
public async Task<FinanceContractOutput?> GetActiveByPartyAsync(
|
||||
[FromQuery] string partyType,
|
||||
[FromQuery] int partyId)
|
||||
{
|
||||
await RefreshExpiredContractsAsync();
|
||||
if (!FinancePartyTypeCodes.IsKnown(partyType) || partyId <= 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var entity = await ContractRepository.GetActiveByPartyAsync(partyType.Trim(), partyId);
|
||||
if (entity == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var list = await MapListAsync([entity]);
|
||||
return list[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存合同(草稿;可勾选 Activate 直接生效)。
|
||||
/// </summary>
|
||||
[HttpPost("/finance/contract/save")]
|
||||
public async Task<FinanceContractOutput> SaveAsync(FinanceContractSaveInput input)
|
||||
{
|
||||
ValidateSaveInput(input);
|
||||
await EnsurePartyExistsAsync(input.PartyType, input.PartyId);
|
||||
|
||||
FinanceContract entity;
|
||||
if (input.Id is > 0)
|
||||
{
|
||||
entity = await ContractRepository.FirstOrDefaultAsync(x => x.Id == input.Id.Value)
|
||||
?? throw new BusinessException("合同不存在");
|
||||
if (entity.Status is not (FinanceContractStatusCodes.Draft or FinanceContractStatusCodes.Active))
|
||||
{
|
||||
throw new BusinessException("仅草稿或生效合同可编辑");
|
||||
}
|
||||
|
||||
if (entity.Status == FinanceContractStatusCodes.Active
|
||||
&& (entity.PartyType != input.PartyType.Trim() || entity.PartyId != input.PartyId))
|
||||
{
|
||||
throw new BusinessException("生效合同不可更换对方");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
entity = new FinanceContract
|
||||
{
|
||||
ContractNo = await GenerateContractNoAsync(),
|
||||
Status = FinanceContractStatusCodes.Draft
|
||||
};
|
||||
}
|
||||
|
||||
ApplySaveFields(entity, input);
|
||||
|
||||
if (input.Id is > 0)
|
||||
{
|
||||
await ContractRepository.UpdateAsync(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity = await ContractRepository.InsertAsync(entity);
|
||||
}
|
||||
|
||||
if (input.Activate)
|
||||
{
|
||||
await ActivateCoreAsync(entity);
|
||||
}
|
||||
|
||||
return (await MapListAsync([entity]))[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生效合同。同一对方同时仅允许一份生效合同。
|
||||
/// </summary>
|
||||
[HttpPost("/finance/contract/activate")]
|
||||
public async Task<FinanceContractOutput> ActivateAsync(FinanceContractIdInput input)
|
||||
{
|
||||
var entity = await ContractRepository.FirstOrDefaultAsync(x => x.Id == input.Id)
|
||||
?? throw new BusinessException("合同不存在");
|
||||
if (entity.Status != FinanceContractStatusCodes.Draft)
|
||||
{
|
||||
throw new BusinessException("仅草稿合同可生效");
|
||||
}
|
||||
|
||||
await ActivateCoreAsync(entity);
|
||||
return (await MapListAsync([entity]))[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 续签:复制条款生成新草稿。
|
||||
/// </summary>
|
||||
[HttpPost("/finance/contract/renew")]
|
||||
public async Task<FinanceContractOutput> RenewAsync(FinanceContractIdInput input)
|
||||
{
|
||||
var source = await ContractRepository.FirstOrDefaultAsync(x => x.Id == input.Id)
|
||||
?? throw new BusinessException("合同不存在");
|
||||
if (source.Status is FinanceContractStatusCodes.Terminated)
|
||||
{
|
||||
throw new BusinessException("已终止合同不可续签");
|
||||
}
|
||||
|
||||
var entity = new FinanceContract
|
||||
{
|
||||
ContractNo = await GenerateContractNoAsync(),
|
||||
ContractName = source.ContractName,
|
||||
PartyType = source.PartyType,
|
||||
PartyId = source.PartyId,
|
||||
OurEntityName = source.OurEntityName,
|
||||
SignDate = DateTime.Now.Date,
|
||||
EffectiveDate = source.ExpireDate?.Date.AddDays(1) ?? DateTime.Now.Date,
|
||||
ExpireDate = source.ExpireDate.HasValue
|
||||
? source.ExpireDate.Value.AddYears(1)
|
||||
: DateTime.Now.Date.AddYears(1),
|
||||
AutoRenew = source.AutoRenew,
|
||||
SettlementMethod = source.SettlementMethod,
|
||||
PaymentTermDays = source.PaymentTermDays,
|
||||
BillingDay = source.BillingDay,
|
||||
PaymentDay = source.PaymentDay,
|
||||
Currency = source.Currency,
|
||||
CreditLimit = source.CreditLimit,
|
||||
CommissionBaseType = source.CommissionBaseType,
|
||||
CommissionRate = source.CommissionRate,
|
||||
RequireVendorInvoice = source.RequireVendorInvoice,
|
||||
OwnerUserId = source.OwnerUserId,
|
||||
OwnerName = source.OwnerName,
|
||||
Status = FinanceContractStatusCodes.Draft,
|
||||
Remark = source.Remark,
|
||||
RenewedFromId = source.Id
|
||||
};
|
||||
entity = await ContractRepository.InsertAsync(entity);
|
||||
return (await MapListAsync([entity]))[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 终止合同。
|
||||
/// </summary>
|
||||
[HttpPost("/finance/contract/terminate")]
|
||||
public async Task<FinanceContractOutput> TerminateAsync(FinanceContractTerminateInput input)
|
||||
{
|
||||
var entity = await ContractRepository.FirstOrDefaultAsync(x => x.Id == input.Id)
|
||||
?? throw new BusinessException("合同不存在");
|
||||
if (entity.Status is FinanceContractStatusCodes.Terminated or FinanceContractStatusCodes.Expired)
|
||||
{
|
||||
throw new BusinessException("合同已结束,无需终止");
|
||||
}
|
||||
|
||||
entity.Status = FinanceContractStatusCodes.Terminated;
|
||||
entity.TerminatedTime = DateTime.Now;
|
||||
entity.TerminateReason = string.IsNullOrWhiteSpace(input.Reason) ? null : input.Reason.Trim();
|
||||
await ContractRepository.UpdateAsync(entity);
|
||||
return (await MapListAsync([entity]))[0];
|
||||
}
|
||||
|
||||
private async Task ActivateCoreAsync(FinanceContract entity)
|
||||
{
|
||||
var existing = await ContractRepository.GetActiveByPartyAsync(
|
||||
entity.PartyType,
|
||||
entity.PartyId,
|
||||
entity.Id);
|
||||
if (existing != null)
|
||||
{
|
||||
throw new BusinessException($"该对方已有生效合同 {existing.ContractNo},请先终止或到期后再生效");
|
||||
}
|
||||
|
||||
if (entity.ExpireDate.HasValue && entity.ExpireDate.Value.Date < DateTime.Now.Date)
|
||||
{
|
||||
throw new BusinessException("到期日早于今天,无法生效");
|
||||
}
|
||||
|
||||
entity.Status = FinanceContractStatusCodes.Active;
|
||||
entity.TerminatedTime = null;
|
||||
entity.TerminateReason = null;
|
||||
await ContractRepository.UpdateAsync(entity);
|
||||
|
||||
if (entity.PartyType == FinancePartyTypeCodes.Customer && entity.CreditLimit is >= 0)
|
||||
{
|
||||
var customer = await CustomerRepository.FirstOrDefaultAsync(x => x.Id == entity.PartyId);
|
||||
if (customer != null)
|
||||
{
|
||||
customer.TotalQuota = entity.CreditLimit.Value;
|
||||
await CustomerRepository.UpdateAsync(customer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RefreshExpiredContractsAsync()
|
||||
{
|
||||
var today = DateTime.Now.Date;
|
||||
var actives = await ContractRepository.GetListAsync(x =>
|
||||
x.Status == FinanceContractStatusCodes.Active
|
||||
&& x.ExpireDate != null
|
||||
&& x.ExpireDate < today);
|
||||
foreach (var item in actives)
|
||||
{
|
||||
item.Status = FinanceContractStatusCodes.Expired;
|
||||
await ContractRepository.UpdateAsync(item);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ValidateSaveInput(FinanceContractSaveInput input)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(input.ContractName))
|
||||
{
|
||||
throw new BusinessException("合同名称不能为空");
|
||||
}
|
||||
|
||||
if (!FinancePartyTypeCodes.IsKnown(input.PartyType))
|
||||
{
|
||||
throw new BusinessException("对方类型无效");
|
||||
}
|
||||
|
||||
if (input.PartyId <= 0)
|
||||
{
|
||||
throw new BusinessException("请选择对方");
|
||||
}
|
||||
|
||||
if (!FinanceSettlementMethodCodes.IsKnown(input.SettlementMethod))
|
||||
{
|
||||
throw new BusinessException("结算方式无效");
|
||||
}
|
||||
|
||||
if (input.PaymentTermDays < 0)
|
||||
{
|
||||
throw new BusinessException("账期天数不能为负");
|
||||
}
|
||||
|
||||
if (input.ExpireDate.HasValue && input.ExpireDate.Value.Date < input.EffectiveDate.Date)
|
||||
{
|
||||
throw new BusinessException("到期日不能早于生效日");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task EnsurePartyExistsAsync(string partyType, int partyId)
|
||||
{
|
||||
var type = partyType.Trim();
|
||||
switch (type)
|
||||
{
|
||||
case FinancePartyTypeCodes.Customer:
|
||||
_ = await CustomerRepository.FirstOrDefaultAsync(x => x.Id == partyId)
|
||||
?? throw new BusinessException("客户不存在");
|
||||
break;
|
||||
case FinancePartyTypeCodes.Supplier:
|
||||
_ = await SupplierRepository.FirstOrDefaultAsync(x => x.Id == partyId)
|
||||
?? throw new BusinessException("供应商不存在");
|
||||
break;
|
||||
case FinancePartyTypeCodes.Agent:
|
||||
_ = await AgentRepository.FirstOrDefaultAsync(x => x.Id == partyId)
|
||||
?? throw new BusinessException("代理不存在");
|
||||
break;
|
||||
default:
|
||||
throw new BusinessException("对方类型无效");
|
||||
}
|
||||
}
|
||||
|
||||
private static void ApplySaveFields(FinanceContract entity, FinanceContractSaveInput input)
|
||||
{
|
||||
entity.ContractName = input.ContractName.Trim();
|
||||
entity.PartyType = input.PartyType.Trim();
|
||||
entity.PartyId = input.PartyId;
|
||||
entity.OurEntityName = NormalizeOptional(input.OurEntityName);
|
||||
entity.SignDate = input.SignDate?.Date;
|
||||
entity.EffectiveDate = input.EffectiveDate.Date;
|
||||
entity.ExpireDate = input.ExpireDate?.Date;
|
||||
entity.AutoRenew = input.AutoRenew;
|
||||
entity.SettlementMethod = input.SettlementMethod.Trim();
|
||||
entity.PaymentTermDays = input.PaymentTermDays;
|
||||
entity.BillingDay = NormalizeDay(input.BillingDay);
|
||||
entity.PaymentDay = NormalizeDay(input.PaymentDay);
|
||||
entity.Currency = string.IsNullOrWhiteSpace(input.Currency)
|
||||
? FinanceCurrencyCodes.Cny
|
||||
: input.Currency.Trim().ToUpperInvariant();
|
||||
entity.CreditLimit = input.PartyType == FinancePartyTypeCodes.Customer ? input.CreditLimit : null;
|
||||
entity.CommissionBaseType = input.PartyType == FinancePartyTypeCodes.Agent
|
||||
? NormalizeOptional(input.CommissionBaseType)
|
||||
: null;
|
||||
entity.CommissionRate = input.PartyType == FinancePartyTypeCodes.Agent ? input.CommissionRate : null;
|
||||
entity.RequireVendorInvoice = input.PartyType == FinancePartyTypeCodes.Supplier && input.RequireVendorInvoice;
|
||||
entity.OwnerUserId = input.OwnerUserId is > 0 ? input.OwnerUserId : null;
|
||||
entity.OwnerName = NormalizeOptional(input.OwnerName);
|
||||
entity.AttachmentUrls = NormalizeOptional(input.AttachmentUrls);
|
||||
entity.Remark = NormalizeOptional(input.Remark);
|
||||
}
|
||||
|
||||
private static int? NormalizeDay(int? day) =>
|
||||
day is >= 1 and <= 28 ? day : null;
|
||||
|
||||
private static string? NormalizeOptional(string? value) =>
|
||||
string.IsNullOrWhiteSpace(value) ? null : value.Trim();
|
||||
|
||||
private static Expression<Func<FinanceContract, bool>> BuildListPredicate(FinanceContractListInput input)
|
||||
{
|
||||
var hasPartyType = !string.IsNullOrWhiteSpace(input.PartyType)
|
||||
&& input.PartyType != "all"
|
||||
&& input.PartyType != "expiringSoon";
|
||||
var partyType = input.PartyType?.Trim();
|
||||
var hasPartyId = input.PartyId is > 0;
|
||||
var partyId = input.PartyId.GetValueOrDefault();
|
||||
var hasKeyword = !string.IsNullOrWhiteSpace(input.Keyword);
|
||||
var keyword = input.Keyword?.Trim();
|
||||
var hasSignStart = input.SignStartTime.HasValue;
|
||||
var signStart = input.SignStartTime;
|
||||
var hasSignEnd = input.SignEndTime.HasValue;
|
||||
var signEnd = input.SignEndTime;
|
||||
var expiringSoon = string.Equals(input.Status, "expiringSoon", StringComparison.OrdinalIgnoreCase)
|
||||
|| string.Equals(input.PartyType, "expiringSoon", StringComparison.OrdinalIgnoreCase);
|
||||
var endedTab = string.Equals(input.Status, "ended", StringComparison.OrdinalIgnoreCase);
|
||||
var hasStatus = !string.IsNullOrWhiteSpace(input.Status)
|
||||
&& !expiringSoon
|
||||
&& !endedTab
|
||||
&& input.Status != "all";
|
||||
var status = input.Status?.Trim();
|
||||
var soonEnd = DateTime.Now.Date.AddDays(30);
|
||||
|
||||
return x =>
|
||||
(!hasPartyType || x.PartyType == partyType)
|
||||
&& (!hasPartyId || x.PartyId == partyId)
|
||||
&& (!hasKeyword
|
||||
|| x.ContractNo.Contains(keyword!)
|
||||
|| x.ContractName.Contains(keyword!))
|
||||
&& (!hasSignStart || (x.SignDate != null && x.SignDate >= signStart))
|
||||
&& (!hasSignEnd || (x.SignDate != null && x.SignDate <= signEnd))
|
||||
&& (!expiringSoon
|
||||
|| (x.Status == FinanceContractStatusCodes.Active
|
||||
&& x.ExpireDate != null
|
||||
&& x.ExpireDate <= soonEnd
|
||||
&& x.ExpireDate >= DateTime.Now.Date))
|
||||
&& (!endedTab
|
||||
|| x.Status == FinanceContractStatusCodes.Expired
|
||||
|| x.Status == FinanceContractStatusCodes.Terminated)
|
||||
&& (!hasStatus || x.Status == status);
|
||||
}
|
||||
|
||||
private async Task<List<FinanceContractOutput>> MapListAsync(List<FinanceContract> entities)
|
||||
{
|
||||
if (entities.Count == 0)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
var customerIds = entities
|
||||
.Where(x => x.PartyType == FinancePartyTypeCodes.Customer)
|
||||
.Select(x => x.PartyId)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
var supplierIds = entities
|
||||
.Where(x => x.PartyType == FinancePartyTypeCodes.Supplier)
|
||||
.Select(x => x.PartyId)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
var agentIds = entities
|
||||
.Where(x => x.PartyType == FinancePartyTypeCodes.Agent)
|
||||
.Select(x => x.PartyId)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
var customers = customerIds.Count == 0
|
||||
? []
|
||||
: await CustomerRepository.GetListAsync(x => customerIds.Contains(x.Id));
|
||||
var suppliers = supplierIds.Count == 0
|
||||
? []
|
||||
: await SupplierRepository.GetListAsync(x => supplierIds.Contains(x.Id));
|
||||
var agents = agentIds.Count == 0
|
||||
? []
|
||||
: await AgentRepository.GetListAsync(x => agentIds.Contains(x.Id));
|
||||
|
||||
var customerMap = customers.ToDictionary(x => x.Id);
|
||||
var supplierMap = suppliers.ToDictionary(x => x.Id);
|
||||
var agentMap = agents.ToDictionary(x => x.Id);
|
||||
var soonEnd = DateTime.Now.Date.AddDays(30);
|
||||
|
||||
return entities.Select(entity =>
|
||||
{
|
||||
string? partyCode = null;
|
||||
string? partyName = null;
|
||||
if (entity.PartyType == FinancePartyTypeCodes.Customer
|
||||
&& customerMap.TryGetValue(entity.PartyId, out var customer))
|
||||
{
|
||||
partyCode = customer.CustomerCode;
|
||||
partyName = customer.CustomerName;
|
||||
}
|
||||
else if (entity.PartyType == FinancePartyTypeCodes.Supplier
|
||||
&& supplierMap.TryGetValue(entity.PartyId, out var supplier))
|
||||
{
|
||||
partyCode = supplier.SupplierCode;
|
||||
partyName = supplier.SupplierName;
|
||||
}
|
||||
else if (entity.PartyType == FinancePartyTypeCodes.Agent
|
||||
&& agentMap.TryGetValue(entity.PartyId, out var agent))
|
||||
{
|
||||
partyCode = agent.AgentCode;
|
||||
partyName = agent.AgentName;
|
||||
}
|
||||
|
||||
var attachmentCount = CountAttachments(entity.AttachmentUrls);
|
||||
return new FinanceContractOutput
|
||||
{
|
||||
Id = entity.Id,
|
||||
ContractNo = entity.ContractNo,
|
||||
ContractName = entity.ContractName,
|
||||
PartyType = entity.PartyType,
|
||||
PartyTypeName = FinancePartyTypeCodes.GetName(entity.PartyType),
|
||||
PartyId = entity.PartyId,
|
||||
PartyCode = partyCode,
|
||||
PartyName = partyName,
|
||||
OurEntityName = entity.OurEntityName,
|
||||
SignDate = entity.SignDate,
|
||||
EffectiveDate = entity.EffectiveDate,
|
||||
ExpireDate = entity.ExpireDate,
|
||||
AutoRenew = entity.AutoRenew,
|
||||
SettlementMethod = entity.SettlementMethod,
|
||||
SettlementMethodName = FinanceSettlementMethodCodes.GetName(entity.SettlementMethod),
|
||||
PaymentTermDays = entity.PaymentTermDays,
|
||||
BillingDay = entity.BillingDay,
|
||||
PaymentDay = entity.PaymentDay,
|
||||
Currency = entity.Currency,
|
||||
CreditLimit = entity.CreditLimit,
|
||||
CommissionBaseType = entity.CommissionBaseType,
|
||||
CommissionRate = entity.CommissionRate,
|
||||
RequireVendorInvoice = entity.RequireVendorInvoice,
|
||||
OwnerUserId = entity.OwnerUserId,
|
||||
OwnerName = entity.OwnerName,
|
||||
Status = entity.Status,
|
||||
StatusName = FinanceContractStatusCodes.GetName(entity.Status),
|
||||
AttachmentUrls = entity.AttachmentUrls,
|
||||
AttachmentCount = attachmentCount,
|
||||
Remark = entity.Remark,
|
||||
RenewedFromId = entity.RenewedFromId,
|
||||
TerminatedTime = entity.TerminatedTime,
|
||||
TerminateReason = entity.TerminateReason,
|
||||
ExpiringSoon = entity.Status == FinanceContractStatusCodes.Active
|
||||
&& entity.ExpireDate.HasValue
|
||||
&& entity.ExpireDate.Value.Date <= soonEnd
|
||||
&& entity.ExpireDate.Value.Date >= DateTime.Now.Date,
|
||||
CreateTime = entity.CreateTime,
|
||||
UpdateTime = entity.UpdateTime == default ? null : entity.UpdateTime
|
||||
};
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
private static int CountAttachments(string? urls)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(urls))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return urls.Split([',', ';', '\n'], StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
|
||||
.Length;
|
||||
}
|
||||
|
||||
private async Task<string> GenerateContractNoAsync()
|
||||
{
|
||||
var prefix = $"CTR{DateTime.Now:yyyyMMdd}";
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
var existing = await ContractRepository.GetListAsync(x => x.ContractNo.StartsWith(prefix));
|
||||
var maxSeq = 0;
|
||||
foreach (var item in existing)
|
||||
{
|
||||
var suffix = item.ContractNo.Length > prefix.Length
|
||||
? item.ContractNo[prefix.Length..]
|
||||
: string.Empty;
|
||||
if (int.TryParse(suffix, out var seq) && seq > maxSeq)
|
||||
{
|
||||
maxSeq = seq;
|
||||
}
|
||||
}
|
||||
|
||||
var contractNo = $"{prefix}{(maxSeq + 1):D4}";
|
||||
if (!await ContractRepository.ExistsContractNoAsync(contractNo))
|
||||
{
|
||||
return contractNo;
|
||||
}
|
||||
}
|
||||
|
||||
throw new BusinessException("合同编号生成失败");
|
||||
}
|
||||
}
|
||||
329
src/Oms.Application/Services/Finance/FinanceMasterService.cs
Normal file
329
src/Oms.Application/Services/Finance/FinanceMasterService.cs
Normal file
@ -0,0 +1,329 @@
|
||||
using System.Linq.Expressions;
|
||||
using Fake.Application;
|
||||
using Fake.Domain.Exceptions;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Oms.Application.Dtos.Finance;
|
||||
using Oms.Application.Dtos.Shared;
|
||||
using Oms.Application.Shared;
|
||||
using Oms.Domain.FinanceAggregate.Entities;
|
||||
using Oms.Domain.FinanceAggregate.Repositories;
|
||||
using Oms.Domain.Shared.Enums;
|
||||
|
||||
namespace Oms.Application.Services.Finance;
|
||||
|
||||
/// <summary>
|
||||
/// 财务主数据:供应商、公司收付款账户。
|
||||
/// </summary>
|
||||
[ApiExplorerSettings(GroupName = "OMS-Finance")]
|
||||
public class FinanceMasterService : ApplicationService
|
||||
{
|
||||
private IFinanceSupplierRepository SupplierRepository =>
|
||||
LazyServiceProvider.GetRequiredService<IFinanceSupplierRepository>();
|
||||
|
||||
private IFinanceCompanyAccountRepository CompanyAccountRepository =>
|
||||
LazyServiceProvider.GetRequiredService<IFinanceCompanyAccountRepository>();
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询供应商。
|
||||
/// </summary>
|
||||
[HttpGet("/finance/supplier/list")]
|
||||
public async Task<OmsPageResult<FinanceSupplierOutput>> GetSupplierListAsync(
|
||||
[FromQuery] FinanceSupplierListInput input)
|
||||
{
|
||||
var predicate = BuildSupplierPredicate(input.Keyword, input.Status);
|
||||
var page = OmsDocHelper.NormalizePage(input.Page);
|
||||
var pageSize = OmsDocHelper.NormalizePageSize(input.PageSize);
|
||||
var entities = await SupplierRepository.GetPagedListAsync(
|
||||
predicate,
|
||||
page,
|
||||
pageSize,
|
||||
new Dictionary<string, bool>
|
||||
{
|
||||
[nameof(FinanceSupplier.CreateTime)] = false,
|
||||
[nameof(FinanceSupplier.Id)] = false
|
||||
});
|
||||
var total = await SupplierRepository.CountAsync(predicate);
|
||||
return new OmsPageResult<FinanceSupplierOutput>
|
||||
{
|
||||
Items = entities.Select(MapSupplier).ToList(),
|
||||
Total = total
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 供应商下拉(启用)。
|
||||
/// </summary>
|
||||
[HttpGet("/finance/supplier/options")]
|
||||
public async Task<List<FinanceSupplierOutput>> GetSupplierOptionsAsync([FromQuery] string? keyword)
|
||||
{
|
||||
var hasKeyword = !string.IsNullOrWhiteSpace(keyword);
|
||||
var kw = keyword?.Trim();
|
||||
var list = await SupplierRepository.GetListAsync(x =>
|
||||
x.Status == EnableStatus.Enabled
|
||||
&& (!hasKeyword
|
||||
|| x.SupplierCode.Contains(kw!)
|
||||
|| x.SupplierName.Contains(kw!)));
|
||||
return list
|
||||
.OrderBy(x => x.SupplierCode)
|
||||
.Take(100)
|
||||
.Select(MapSupplier)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存供应商(新增/修改)。编码业务侧唯一校验。
|
||||
/// </summary>
|
||||
[HttpPost("/finance/supplier/save")]
|
||||
public async Task<FinanceSupplierOutput> SaveSupplierAsync(FinanceSupplierSaveInput input)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(input.SupplierName))
|
||||
{
|
||||
throw new BusinessException("供应商名称不能为空");
|
||||
}
|
||||
|
||||
var code = (input.SupplierCode ?? string.Empty).Trim();
|
||||
if (string.IsNullOrWhiteSpace(code))
|
||||
{
|
||||
throw new BusinessException("供应商编码不能为空");
|
||||
}
|
||||
|
||||
FinanceSupplier entity;
|
||||
if (input.Id is > 0)
|
||||
{
|
||||
entity = await SupplierRepository.FirstOrDefaultAsync(x => x.Id == input.Id.Value)
|
||||
?? throw new BusinessException("供应商不存在");
|
||||
if (await SupplierRepository.ExistsCodeAsync(code, entity.Id))
|
||||
{
|
||||
throw new BusinessException("供应商编码已存在");
|
||||
}
|
||||
|
||||
entity.SupplierCode = code;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (await SupplierRepository.ExistsCodeAsync(code))
|
||||
{
|
||||
throw new BusinessException("供应商编码已存在");
|
||||
}
|
||||
|
||||
entity = new FinanceSupplier { SupplierCode = code };
|
||||
}
|
||||
|
||||
entity.SupplierName = input.SupplierName.Trim();
|
||||
entity.ContactName = NormalizeOptional(input.ContactName);
|
||||
entity.Phone = NormalizeOptional(input.Phone);
|
||||
entity.Email = NormalizeOptional(input.Email);
|
||||
entity.BankAccountName = NormalizeOptional(input.BankAccountName);
|
||||
entity.BankName = NormalizeOptional(input.BankName);
|
||||
entity.BankAccountNo = NormalizeOptional(input.BankAccountNo);
|
||||
entity.Currency = string.IsNullOrWhiteSpace(input.Currency) ? "CNY" : input.Currency.Trim().ToUpperInvariant();
|
||||
entity.Status = ResolveStatus(input.Status);
|
||||
entity.Remark = NormalizeOptional(input.Remark);
|
||||
|
||||
if (input.Id is > 0)
|
||||
{
|
||||
await SupplierRepository.UpdateAsync(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity = await SupplierRepository.InsertAsync(entity);
|
||||
}
|
||||
|
||||
return MapSupplier(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除供应商(软删)。
|
||||
/// </summary>
|
||||
[HttpPost("/finance/supplier/delete")]
|
||||
public async Task DeleteSupplierAsync(FinanceSupplierDeleteInput input)
|
||||
{
|
||||
var entity = await SupplierRepository.FirstOrDefaultAsync(x => x.Id == input.Id)
|
||||
?? throw new BusinessException("供应商不存在");
|
||||
await SupplierRepository.DeleteAsync(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询公司收付款账户。
|
||||
/// </summary>
|
||||
[HttpGet("/finance/company-account/list")]
|
||||
public async Task<OmsPageResult<FinanceCompanyAccountOutput>> GetCompanyAccountListAsync(
|
||||
[FromQuery] FinanceCompanyAccountListInput input)
|
||||
{
|
||||
var predicate = BuildCompanyAccountPredicate(input.Keyword, input.Status);
|
||||
var page = OmsDocHelper.NormalizePage(input.Page);
|
||||
var pageSize = OmsDocHelper.NormalizePageSize(input.PageSize);
|
||||
var entities = await CompanyAccountRepository.GetPagedListAsync(
|
||||
predicate,
|
||||
page,
|
||||
pageSize,
|
||||
new Dictionary<string, bool>
|
||||
{
|
||||
[nameof(FinanceCompanyAccount.IsDefault)] = false,
|
||||
[nameof(FinanceCompanyAccount.Id)] = false
|
||||
});
|
||||
var total = await CompanyAccountRepository.CountAsync(predicate);
|
||||
return new OmsPageResult<FinanceCompanyAccountOutput>
|
||||
{
|
||||
Items = entities.Select(MapCompanyAccount).ToList(),
|
||||
Total = total
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 公司账户下拉(启用)。
|
||||
/// </summary>
|
||||
[HttpGet("/finance/company-account/options")]
|
||||
public async Task<List<FinanceCompanyAccountOutput>> GetCompanyAccountOptionsAsync()
|
||||
{
|
||||
var list = await CompanyAccountRepository.GetListAsync(x => x.Status == EnableStatus.Enabled);
|
||||
return list
|
||||
.OrderByDescending(x => x.IsDefault)
|
||||
.ThenBy(x => x.Id)
|
||||
.Select(MapCompanyAccount)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存公司收付款账户。
|
||||
/// </summary>
|
||||
[HttpPost("/finance/company-account/save")]
|
||||
public async Task<FinanceCompanyAccountOutput> SaveCompanyAccountAsync(FinanceCompanyAccountSaveInput input)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(input.AccountName))
|
||||
{
|
||||
throw new BusinessException("账户名称不能为空");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input.BankName))
|
||||
{
|
||||
throw new BusinessException("开户行不能为空");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input.AccountNo))
|
||||
{
|
||||
throw new BusinessException("银行账号不能为空");
|
||||
}
|
||||
|
||||
FinanceCompanyAccount entity;
|
||||
if (input.Id is > 0)
|
||||
{
|
||||
entity = await CompanyAccountRepository.FirstOrDefaultAsync(x => x.Id == input.Id.Value)
|
||||
?? throw new BusinessException("公司账户不存在");
|
||||
}
|
||||
else
|
||||
{
|
||||
entity = new FinanceCompanyAccount();
|
||||
}
|
||||
|
||||
entity.AccountName = input.AccountName.Trim();
|
||||
entity.BankName = input.BankName.Trim();
|
||||
entity.AccountNo = input.AccountNo.Trim();
|
||||
entity.Currency = string.IsNullOrWhiteSpace(input.Currency) ? "CNY" : input.Currency.Trim().ToUpperInvariant();
|
||||
entity.IsDefault = input.IsDefault;
|
||||
entity.Status = ResolveStatus(input.Status);
|
||||
entity.Remark = NormalizeOptional(input.Remark);
|
||||
|
||||
if (input.Id is > 0)
|
||||
{
|
||||
await CompanyAccountRepository.UpdateAsync(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity = await CompanyAccountRepository.InsertAsync(entity);
|
||||
}
|
||||
|
||||
if (entity.IsDefault)
|
||||
{
|
||||
await ClearOtherDefaultsAsync(entity.Id);
|
||||
}
|
||||
|
||||
return MapCompanyAccount(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除公司账户(软删)。
|
||||
/// </summary>
|
||||
[HttpPost("/finance/company-account/delete")]
|
||||
public async Task DeleteCompanyAccountAsync(FinanceCompanyAccountDeleteInput input)
|
||||
{
|
||||
var entity = await CompanyAccountRepository.FirstOrDefaultAsync(x => x.Id == input.Id)
|
||||
?? throw new BusinessException("公司账户不存在");
|
||||
await CompanyAccountRepository.DeleteAsync(entity);
|
||||
}
|
||||
|
||||
private async Task ClearOtherDefaultsAsync(int keepId)
|
||||
{
|
||||
var others = await CompanyAccountRepository.GetListAsync(x => x.IsDefault && x.Id != keepId);
|
||||
foreach (var item in others)
|
||||
{
|
||||
item.IsDefault = false;
|
||||
await CompanyAccountRepository.UpdateAsync(item);
|
||||
}
|
||||
}
|
||||
|
||||
private static Expression<Func<FinanceSupplier, bool>> BuildSupplierPredicate(string? keyword, byte? status)
|
||||
{
|
||||
var hasKeyword = !string.IsNullOrWhiteSpace(keyword);
|
||||
var kw = keyword?.Trim();
|
||||
var hasStatus = status is > 0;
|
||||
var statusValue = (EnableStatus)(status ?? 0);
|
||||
return x =>
|
||||
(!hasKeyword || x.SupplierCode.Contains(kw!) || x.SupplierName.Contains(kw!))
|
||||
&& (!hasStatus || x.Status == statusValue);
|
||||
}
|
||||
|
||||
private static Expression<Func<FinanceCompanyAccount, bool>> BuildCompanyAccountPredicate(
|
||||
string? keyword,
|
||||
byte? status)
|
||||
{
|
||||
var hasKeyword = !string.IsNullOrWhiteSpace(keyword);
|
||||
var kw = keyword?.Trim();
|
||||
var hasStatus = status is > 0;
|
||||
var statusValue = (EnableStatus)(status ?? 0);
|
||||
return x =>
|
||||
(!hasKeyword
|
||||
|| x.AccountName.Contains(kw!)
|
||||
|| x.BankName.Contains(kw!)
|
||||
|| x.AccountNo.Contains(kw!))
|
||||
&& (!hasStatus || x.Status == statusValue);
|
||||
}
|
||||
|
||||
private static EnableStatus ResolveStatus(byte? status) =>
|
||||
status is (byte)EnableStatus.Disabled ? EnableStatus.Disabled : EnableStatus.Enabled;
|
||||
|
||||
private static string? NormalizeOptional(string? value) =>
|
||||
string.IsNullOrWhiteSpace(value) ? null : value.Trim();
|
||||
|
||||
private static FinanceSupplierOutput MapSupplier(FinanceSupplier entity) => new()
|
||||
{
|
||||
Id = entity.Id,
|
||||
SupplierCode = entity.SupplierCode,
|
||||
SupplierName = entity.SupplierName,
|
||||
ContactName = entity.ContactName,
|
||||
Phone = entity.Phone,
|
||||
Email = entity.Email,
|
||||
BankAccountName = entity.BankAccountName,
|
||||
BankName = entity.BankName,
|
||||
BankAccountNo = entity.BankAccountNo,
|
||||
Currency = entity.Currency,
|
||||
Status = (byte)entity.Status,
|
||||
Remark = entity.Remark,
|
||||
CreateTime = entity.CreateTime,
|
||||
UpdateTime = entity.UpdateTime == default ? null : entity.UpdateTime
|
||||
};
|
||||
|
||||
private static FinanceCompanyAccountOutput MapCompanyAccount(FinanceCompanyAccount entity) => new()
|
||||
{
|
||||
Id = entity.Id,
|
||||
AccountName = entity.AccountName,
|
||||
BankName = entity.BankName,
|
||||
AccountNo = entity.AccountNo,
|
||||
Currency = entity.Currency,
|
||||
IsDefault = entity.IsDefault,
|
||||
Status = (byte)entity.Status,
|
||||
Remark = entity.Remark,
|
||||
CreateTime = entity.CreateTime,
|
||||
UpdateTime = entity.UpdateTime == default ? null : entity.UpdateTime
|
||||
};
|
||||
}
|
||||
@ -0,0 +1,725 @@
|
||||
using System.Linq.Expressions;
|
||||
using Fake.Application;
|
||||
using Fake.Domain.Exceptions;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Oms.Application.Dtos.Finance;
|
||||
using Oms.Application.Dtos.Shared;
|
||||
using Oms.Application.Services.Approval;
|
||||
using Oms.Application.Services.Approval.Contracts;
|
||||
using Oms.Application.Shared;
|
||||
using Oms.Domain.AgentsAggregate.Repositories;
|
||||
using Oms.Domain.ApprovalAggregate.Consts;
|
||||
using Oms.Domain.ApprovalAggregate.Enums;
|
||||
using Oms.Domain.CustomersAggregate.Repositories;
|
||||
using Oms.Domain.FinanceAggregate.Consts;
|
||||
using Oms.Domain.FinanceAggregate.Entities;
|
||||
using Oms.Domain.FinanceAggregate.Repositories;
|
||||
|
||||
namespace Oms.Application.Services.Finance;
|
||||
|
||||
/// <summary>
|
||||
/// 付款申请 API。
|
||||
/// </summary>
|
||||
[ApiExplorerSettings(GroupName = "OMS-Finance")]
|
||||
public class FinancePaymentApplyService : ApplicationService
|
||||
{
|
||||
private IFinancePaymentApplyRepository PaymentApplyRepository =>
|
||||
LazyServiceProvider.GetRequiredService<IFinancePaymentApplyRepository>();
|
||||
|
||||
private IFinancePaymentApplyLineRepository PaymentApplyLineRepository =>
|
||||
LazyServiceProvider.GetRequiredService<IFinancePaymentApplyLineRepository>();
|
||||
|
||||
private IFinanceContractRepository ContractRepository =>
|
||||
LazyServiceProvider.GetRequiredService<IFinanceContractRepository>();
|
||||
|
||||
private IFinanceSupplierRepository SupplierRepository =>
|
||||
LazyServiceProvider.GetRequiredService<IFinanceSupplierRepository>();
|
||||
|
||||
private IFinanceCompanyAccountRepository CompanyAccountRepository =>
|
||||
LazyServiceProvider.GetRequiredService<IFinanceCompanyAccountRepository>();
|
||||
|
||||
private ICustomerRepository CustomerRepository =>
|
||||
LazyServiceProvider.GetRequiredService<ICustomerRepository>();
|
||||
|
||||
private IAgentRepository AgentRepository =>
|
||||
LazyServiceProvider.GetRequiredService<IAgentRepository>();
|
||||
|
||||
private IApprovalGate ApprovalGate =>
|
||||
LazyServiceProvider.GetRequiredService<IApprovalGate>();
|
||||
|
||||
private ApprovalEngineCore ApprovalEngineCore =>
|
||||
LazyServiceProvider.GetRequiredService<ApprovalEngineCore>();
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询付款申请。
|
||||
/// </summary>
|
||||
[HttpGet("/finance/payment-apply/list")]
|
||||
public async Task<OmsPageResult<FinancePaymentApplyOutput>> GetListAsync(
|
||||
[FromQuery] FinancePaymentApplyListInput input)
|
||||
{
|
||||
var predicate = BuildListPredicate(input);
|
||||
var page = OmsDocHelper.NormalizePage(input.Page);
|
||||
var pageSize = OmsDocHelper.NormalizePageSize(input.PageSize);
|
||||
var entities = await PaymentApplyRepository.GetPagedListAsync(
|
||||
predicate,
|
||||
page,
|
||||
pageSize,
|
||||
new Dictionary<string, bool>
|
||||
{
|
||||
[nameof(FinancePaymentApply.CreateTime)] = false,
|
||||
[nameof(FinancePaymentApply.Id)] = false
|
||||
});
|
||||
var total = await PaymentApplyRepository.CountAsync(predicate);
|
||||
var items = await MapListAsync(entities, includeLines: false);
|
||||
return new OmsPageResult<FinancePaymentApplyOutput>
|
||||
{
|
||||
Items = items,
|
||||
Total = total
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 付款申请汇总(待审批 / 待付款 / 本月已付,按币种)。
|
||||
/// </summary>
|
||||
[HttpGet("/finance/payment-apply/summary")]
|
||||
public async Task<FinancePaymentApplySummaryOutput> GetSummaryAsync()
|
||||
{
|
||||
var monthStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
|
||||
var entities = await PaymentApplyRepository.GetListAsync(x =>
|
||||
x.Status == FinancePaymentStatusCodes.PendingApproval
|
||||
|| x.Status == FinancePaymentStatusCodes.PendingPay
|
||||
|| (x.Status == FinancePaymentStatusCodes.Paid && x.PaidTime != null && x.PaidTime >= monthStart));
|
||||
|
||||
var map = new Dictionary<string, FinancePaymentApplySummaryItemOutput>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
var currency = string.IsNullOrWhiteSpace(entity.Currency) ? FinanceCurrencyCodes.Cny : entity.Currency;
|
||||
if (!map.TryGetValue(currency, out var item))
|
||||
{
|
||||
item = new FinancePaymentApplySummaryItemOutput { Currency = currency };
|
||||
map[currency] = item;
|
||||
}
|
||||
|
||||
if (entity.Status == FinancePaymentStatusCodes.PendingApproval)
|
||||
{
|
||||
item.PendingApprovalAmount += entity.AmountTotal;
|
||||
}
|
||||
else if (entity.Status == FinancePaymentStatusCodes.PendingPay)
|
||||
{
|
||||
item.PendingPayAmount += entity.AmountTotal;
|
||||
}
|
||||
else if (entity.Status == FinancePaymentStatusCodes.Paid)
|
||||
{
|
||||
item.PaidThisMonthAmount += entity.AmountTotal;
|
||||
}
|
||||
}
|
||||
|
||||
return new FinancePaymentApplySummaryOutput
|
||||
{
|
||||
Items = map.Values.OrderBy(x => x.Currency).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 付款申请详情。
|
||||
/// </summary>
|
||||
[HttpGet("/finance/payment-apply/detail")]
|
||||
public async Task<FinancePaymentApplyOutput> GetDetailAsync([FromQuery] int id)
|
||||
{
|
||||
var entity = await PaymentApplyRepository.FirstOrDefaultAsync(x => x.Id == id)
|
||||
?? throw new BusinessException("付款申请不存在");
|
||||
var list = await MapListAsync([entity], includeLines: true);
|
||||
return list[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存付款申请(草稿;可勾选 Submit 提交审批)。
|
||||
/// </summary>
|
||||
[HttpPost("/finance/payment-apply/save")]
|
||||
public async Task<FinancePaymentApplyOutput> SaveAsync(FinancePaymentApplySaveInput input)
|
||||
{
|
||||
ValidateSaveInput(input);
|
||||
var payeeType = FinancePaymentTypeCodes.ResolvePayeeType(input.PaymentType);
|
||||
await EnsurePayeeExistsAsync(payeeType, input.PayeeId);
|
||||
var lines = BuildLines(input.Lines);
|
||||
var amountTotal = RoundMoney(lines.Sum(x => x.Amount));
|
||||
|
||||
FinancePaymentApply entity;
|
||||
if (input.Id is > 0)
|
||||
{
|
||||
entity = await PaymentApplyRepository.FirstOrDefaultAsync(x => x.Id == input.Id.Value)
|
||||
?? throw new BusinessException("付款申请不存在");
|
||||
if (entity.Status is not (FinancePaymentStatusCodes.Draft or FinancePaymentStatusCodes.Rejected))
|
||||
{
|
||||
throw new BusinessException("仅草稿或已驳回单据可编辑");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
entity = new FinancePaymentApply
|
||||
{
|
||||
ApplyNo = await GenerateApplyNoAsync(),
|
||||
Status = FinancePaymentStatusCodes.Draft,
|
||||
ApplicantName = CurrentUser.UserName
|
||||
};
|
||||
}
|
||||
|
||||
await ApplyHeaderAsync(entity, input, payeeType, amountTotal);
|
||||
|
||||
if (input.Id is > 0)
|
||||
{
|
||||
await PaymentApplyRepository.UpdateAsync(entity);
|
||||
await ReplaceLinesAsync(entity.Id, lines, deleteExisting: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity = await PaymentApplyRepository.InsertAsync(entity);
|
||||
await ReplaceLinesAsync(entity.Id, lines, deleteExisting: false);
|
||||
}
|
||||
|
||||
if (input.Submit)
|
||||
{
|
||||
return await SubmitCoreAsync(entity);
|
||||
}
|
||||
|
||||
var output = (await MapListAsync([entity], includeLines: true))[0];
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 提交审批。未配置审批定义时 Bypass 直接进入待付款。
|
||||
/// </summary>
|
||||
[HttpPost("/finance/payment-apply/submit")]
|
||||
public async Task<FinancePaymentApplyOutput> SubmitAsync(FinancePaymentApplyIdInput input)
|
||||
{
|
||||
var entity = await PaymentApplyRepository.FirstOrDefaultAsync(x => x.Id == input.Id)
|
||||
?? throw new BusinessException("付款申请不存在");
|
||||
if (entity.Status is not (FinancePaymentStatusCodes.Draft or FinancePaymentStatusCodes.Rejected))
|
||||
{
|
||||
throw new BusinessException("仅草稿或已驳回单据可提交");
|
||||
}
|
||||
|
||||
return await SubmitCoreAsync(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 撤回审批中的申请(回到草稿)。
|
||||
/// </summary>
|
||||
[HttpPost("/finance/payment-apply/withdraw")]
|
||||
public async Task<FinancePaymentApplyOutput> WithdrawAsync(FinancePaymentApplyIdInput input)
|
||||
{
|
||||
var entity = await PaymentApplyRepository.FirstOrDefaultAsync(x => x.Id == input.Id)
|
||||
?? throw new BusinessException("付款申请不存在");
|
||||
if (entity.Status != FinancePaymentStatusCodes.PendingApproval)
|
||||
{
|
||||
throw new BusinessException("仅审批中单据可撤回");
|
||||
}
|
||||
|
||||
if (entity.ApprovalInstanceId is > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
await ApprovalEngineCore.WithdrawAsync(entity.ApprovalInstanceId.Value, "业务撤回", null);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 引擎撤回失败时仍回写业务态,避免卡死
|
||||
entity.Status = FinancePaymentStatusCodes.Draft;
|
||||
entity.RejectReason = null;
|
||||
await PaymentApplyRepository.UpdateAsync(entity);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.Status = FinancePaymentStatusCodes.Draft;
|
||||
entity.RejectReason = null;
|
||||
await PaymentApplyRepository.UpdateAsync(entity);
|
||||
}
|
||||
|
||||
entity = await PaymentApplyRepository.FirstOrDefaultAsync(x => x.Id == input.Id) ?? entity;
|
||||
return (await MapListAsync([entity], includeLines: true))[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 出纳登记付款。
|
||||
/// </summary>
|
||||
[HttpPost("/finance/payment-apply/mark-paid")]
|
||||
public async Task<FinancePaymentApplyOutput> MarkPaidAsync(FinancePaymentMarkPaidInput input)
|
||||
{
|
||||
var entity = await PaymentApplyRepository.FirstOrDefaultAsync(x => x.Id == input.Id)
|
||||
?? throw new BusinessException("付款申请不存在");
|
||||
if (entity.Status != FinancePaymentStatusCodes.PendingPay)
|
||||
{
|
||||
throw new BusinessException("仅待付款单据可登记付款");
|
||||
}
|
||||
|
||||
entity.Status = FinancePaymentStatusCodes.Paid;
|
||||
entity.PaidTime = input.PaidTime ?? DateTime.Now;
|
||||
entity.BankTxnNo = NormalizeOptional(input.BankTxnNo);
|
||||
entity.PaidVoucherUrl = NormalizeOptional(input.PaidVoucherUrl);
|
||||
entity.PaidBy = CurrentUser.UserName;
|
||||
if (!string.IsNullOrWhiteSpace(input.Remark))
|
||||
{
|
||||
entity.Remark = input.Remark.Trim();
|
||||
}
|
||||
|
||||
await PaymentApplyRepository.UpdateAsync(entity);
|
||||
return (await MapListAsync([entity], includeLines: true))[0];
|
||||
}
|
||||
|
||||
private async Task<FinancePaymentApplyOutput> SubmitCoreAsync(FinancePaymentApply entity)
|
||||
{
|
||||
var lines = await PaymentApplyLineRepository.GetListByApplyIdAsync(entity.Id);
|
||||
if (lines.Count == 0)
|
||||
{
|
||||
throw new BusinessException("请填写付款明细");
|
||||
}
|
||||
|
||||
if (entity.AmountTotal <= 0)
|
||||
{
|
||||
throw new BusinessException("付款金额必须大于 0");
|
||||
}
|
||||
|
||||
var (payeeCode, payeeName) = await ResolvePayeeAsync(entity.PayeeType, entity.PayeeId);
|
||||
var gateResult = await ApprovalGate.CheckAndSubmitOrBypassAsync(new ApprovalSubmitRequest
|
||||
{
|
||||
OperationCode = ApprovalCodes.FinancePaymentApply,
|
||||
BizKey = BuildBizKey(entity.Id),
|
||||
Title = $"付款申请 - {payeeCode} {payeeName} {entity.ApplyNo}".Trim(),
|
||||
PayloadJson = OmsDocHelper.SerializeJson(new
|
||||
{
|
||||
paymentApplyId = entity.Id,
|
||||
applyNo = entity.ApplyNo,
|
||||
paymentType = entity.PaymentType,
|
||||
payeeType = entity.PayeeType,
|
||||
payeeId = entity.PayeeId,
|
||||
payeeCode,
|
||||
payeeName,
|
||||
amountTotal = entity.AmountTotal,
|
||||
currency = entity.Currency
|
||||
}),
|
||||
Summary = new
|
||||
{
|
||||
entity.ApplyNo,
|
||||
entity.PaymentType,
|
||||
payeeCode,
|
||||
payeeName,
|
||||
entity.AmountTotal,
|
||||
entity.Currency
|
||||
}
|
||||
});
|
||||
|
||||
if (gateResult.Decision == ApprovalGateDecision.Bypass)
|
||||
{
|
||||
entity.Status = FinancePaymentStatusCodes.PendingPay;
|
||||
entity.RejectReason = null;
|
||||
entity.ApprovalInstanceId = gateResult.InstanceId;
|
||||
entity.ApprovalInstanceNo = gateResult.InstanceNo;
|
||||
await PaymentApplyRepository.UpdateAsync(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.Status = FinancePaymentStatusCodes.PendingApproval;
|
||||
entity.RejectReason = null;
|
||||
entity.ApprovalInstanceId = gateResult.InstanceId;
|
||||
entity.ApprovalInstanceNo = gateResult.InstanceNo;
|
||||
await PaymentApplyRepository.UpdateAsync(entity);
|
||||
}
|
||||
|
||||
var output = (await MapListAsync([entity], includeLines: true))[0];
|
||||
output.Decision = gateResult.Decision.ToString();
|
||||
output.ApprovalInstanceId = gateResult.InstanceId;
|
||||
output.ApprovalInstanceNo = gateResult.InstanceNo;
|
||||
output.Message = gateResult.Decision == ApprovalGateDecision.PendingApproval
|
||||
? $"已提交审批({gateResult.InstanceNo}),通过后待付款"
|
||||
: (gateResult.Message ?? "未启用审批,已进入待付款");
|
||||
return output;
|
||||
}
|
||||
|
||||
private async Task ApplyHeaderAsync(
|
||||
FinancePaymentApply entity,
|
||||
FinancePaymentApplySaveInput input,
|
||||
string payeeType,
|
||||
decimal amountTotal)
|
||||
{
|
||||
entity.PaymentType = input.PaymentType.Trim();
|
||||
entity.PayeeType = payeeType;
|
||||
entity.PayeeId = input.PayeeId;
|
||||
entity.Currency = string.IsNullOrWhiteSpace(input.Currency)
|
||||
? FinanceCurrencyCodes.Cny
|
||||
: input.Currency.Trim().ToUpperInvariant();
|
||||
entity.AmountTotal = amountTotal;
|
||||
entity.ExpectPayDate = input.ExpectPayDate?.Date;
|
||||
entity.PayeeAccountName = NormalizeOptional(input.PayeeAccountName);
|
||||
entity.PayeeBankName = NormalizeOptional(input.PayeeBankName);
|
||||
entity.PayeeAccountNo = NormalizeOptional(input.PayeeAccountNo);
|
||||
entity.AttachmentUrls = NormalizeOptional(input.AttachmentUrls);
|
||||
entity.Remark = NormalizeOptional(input.Remark);
|
||||
entity.Status = FinancePaymentStatusCodes.Draft;
|
||||
entity.RejectReason = null;
|
||||
entity.ApplicantName ??= CurrentUser.UserName;
|
||||
|
||||
if (input.ContractId is > 0)
|
||||
{
|
||||
var contract = await ContractRepository.FirstOrDefaultAsync(x => x.Id == input.ContractId.Value)
|
||||
?? throw new BusinessException("关联合同不存在");
|
||||
if (contract.PartyType != payeeType || contract.PartyId != input.PayeeId)
|
||||
{
|
||||
throw new BusinessException("关联合同与收款方不匹配");
|
||||
}
|
||||
|
||||
entity.ContractId = contract.Id;
|
||||
if (string.IsNullOrWhiteSpace(input.Currency))
|
||||
{
|
||||
entity.Currency = contract.Currency;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.ContractId = null;
|
||||
}
|
||||
|
||||
if (input.CompanyAccountId is > 0)
|
||||
{
|
||||
var account = await CompanyAccountRepository.FirstOrDefaultAsync(x => x.Id == input.CompanyAccountId.Value)
|
||||
?? throw new BusinessException("付款账户不存在");
|
||||
entity.CompanyAccountId = account.Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.CompanyAccountId = null;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(entity.PayeeAccountName)
|
||||
|| string.IsNullOrWhiteSpace(entity.PayeeAccountNo))
|
||||
{
|
||||
await FillPayeeBankFromMasterAsync(entity);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task FillPayeeBankFromMasterAsync(FinancePaymentApply entity)
|
||||
{
|
||||
if (entity.PayeeType == FinancePartyTypeCodes.Supplier)
|
||||
{
|
||||
var supplier = await SupplierRepository.FirstOrDefaultAsync(x => x.Id == entity.PayeeId);
|
||||
if (supplier == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
entity.PayeeAccountName ??= supplier.BankAccountName;
|
||||
entity.PayeeBankName ??= supplier.BankName;
|
||||
entity.PayeeAccountNo ??= supplier.BankAccountNo;
|
||||
if (string.IsNullOrWhiteSpace(entity.Currency))
|
||||
{
|
||||
entity.Currency = supplier.Currency;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ValidateSaveInput(FinancePaymentApplySaveInput input)
|
||||
{
|
||||
if (!FinancePaymentTypeCodes.IsKnown(input.PaymentType))
|
||||
{
|
||||
throw new BusinessException("付款类型无效");
|
||||
}
|
||||
|
||||
if (input.PayeeId <= 0)
|
||||
{
|
||||
throw new BusinessException("请选择收款方");
|
||||
}
|
||||
|
||||
if (input.Lines == null || input.Lines.Count == 0)
|
||||
{
|
||||
throw new BusinessException("请填写付款明细");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task EnsurePayeeExistsAsync(string payeeType, int payeeId)
|
||||
{
|
||||
switch (payeeType)
|
||||
{
|
||||
case FinancePartyTypeCodes.Customer:
|
||||
_ = await CustomerRepository.FirstOrDefaultAsync(x => x.Id == payeeId)
|
||||
?? throw new BusinessException("客户不存在");
|
||||
break;
|
||||
case FinancePartyTypeCodes.Supplier:
|
||||
_ = await SupplierRepository.FirstOrDefaultAsync(x => x.Id == payeeId)
|
||||
?? throw new BusinessException("供应商不存在");
|
||||
break;
|
||||
case FinancePartyTypeCodes.Agent:
|
||||
_ = await AgentRepository.FirstOrDefaultAsync(x => x.Id == payeeId)
|
||||
?? throw new BusinessException("代理不存在");
|
||||
break;
|
||||
default:
|
||||
throw new BusinessException("收款方类型无效");
|
||||
}
|
||||
}
|
||||
|
||||
private static List<FinancePaymentApplyLine> BuildLines(List<FinancePaymentApplyLineInput> inputs)
|
||||
{
|
||||
var result = new List<FinancePaymentApplyLine>(inputs.Count);
|
||||
foreach (var input in inputs)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(input.Description))
|
||||
{
|
||||
throw new BusinessException("明细说明不能为空");
|
||||
}
|
||||
|
||||
var amount = RoundMoney(input.Amount);
|
||||
if (amount <= 0)
|
||||
{
|
||||
throw new BusinessException("明细金额必须大于 0");
|
||||
}
|
||||
|
||||
result.Add(new FinancePaymentApplyLine
|
||||
{
|
||||
Description = input.Description.Trim(),
|
||||
Amount = amount,
|
||||
RefNo = NormalizeOptional(input.RefNo),
|
||||
Remark = NormalizeOptional(input.Remark)
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task ReplaceLinesAsync(int applyId, List<FinancePaymentApplyLine> lines, bool deleteExisting)
|
||||
{
|
||||
if (deleteExisting)
|
||||
{
|
||||
await PaymentApplyLineRepository.DeleteByApplyIdAsync(applyId);
|
||||
}
|
||||
|
||||
foreach (var line in lines)
|
||||
{
|
||||
line.PaymentApplyId = applyId;
|
||||
await PaymentApplyLineRepository.InsertAsync(line);
|
||||
}
|
||||
}
|
||||
|
||||
private static Expression<Func<FinancePaymentApply, bool>> BuildListPredicate(
|
||||
FinancePaymentApplyListInput input)
|
||||
{
|
||||
var hasStatus = !string.IsNullOrWhiteSpace(input.Status) && input.Status != "all";
|
||||
var status = input.Status?.Trim();
|
||||
var hasPaymentType = !string.IsNullOrWhiteSpace(input.PaymentType);
|
||||
var paymentType = input.PaymentType?.Trim();
|
||||
var hasPayeeType = !string.IsNullOrWhiteSpace(input.PayeeType);
|
||||
var payeeType = input.PayeeType?.Trim();
|
||||
var hasPayeeId = input.PayeeId is > 0;
|
||||
var payeeId = input.PayeeId.GetValueOrDefault();
|
||||
var hasCurrency = !string.IsNullOrWhiteSpace(input.Currency);
|
||||
var currency = input.Currency?.Trim();
|
||||
var hasKeyword = !string.IsNullOrWhiteSpace(input.Keyword);
|
||||
var keyword = input.Keyword?.Trim();
|
||||
var hasStart = input.StartTime.HasValue;
|
||||
var start = input.StartTime;
|
||||
var hasEnd = input.EndTime.HasValue;
|
||||
var end = input.EndTime;
|
||||
|
||||
return x =>
|
||||
(!hasStatus || x.Status == status)
|
||||
&& (!hasPaymentType || x.PaymentType == paymentType)
|
||||
&& (!hasPayeeType || x.PayeeType == payeeType)
|
||||
&& (!hasPayeeId || x.PayeeId == payeeId)
|
||||
&& (!hasCurrency || x.Currency == currency)
|
||||
&& (!hasKeyword || x.ApplyNo.Contains(keyword!))
|
||||
&& (!hasStart || x.CreateTime >= start)
|
||||
&& (!hasEnd || x.CreateTime <= end);
|
||||
}
|
||||
|
||||
private async Task<List<FinancePaymentApplyOutput>> MapListAsync(
|
||||
List<FinancePaymentApply> entities,
|
||||
bool includeLines)
|
||||
{
|
||||
if (entities.Count == 0)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
var customerIds = entities.Where(x => x.PayeeType == FinancePartyTypeCodes.Customer)
|
||||
.Select(x => x.PayeeId).Distinct().ToList();
|
||||
var supplierIds = entities.Where(x => x.PayeeType == FinancePartyTypeCodes.Supplier)
|
||||
.Select(x => x.PayeeId).Distinct().ToList();
|
||||
var agentIds = entities.Where(x => x.PayeeType == FinancePartyTypeCodes.Agent)
|
||||
.Select(x => x.PayeeId).Distinct().ToList();
|
||||
var contractIds = entities.Where(x => x.ContractId is > 0)
|
||||
.Select(x => x.ContractId!.Value).Distinct().ToList();
|
||||
var accountIds = entities.Where(x => x.CompanyAccountId is > 0)
|
||||
.Select(x => x.CompanyAccountId!.Value).Distinct().ToList();
|
||||
var applyIds = entities.Select(x => x.Id).ToList();
|
||||
|
||||
var customers = customerIds.Count == 0
|
||||
? []
|
||||
: await CustomerRepository.GetListAsync(x => customerIds.Contains(x.Id));
|
||||
var suppliers = supplierIds.Count == 0
|
||||
? []
|
||||
: await SupplierRepository.GetListAsync(x => supplierIds.Contains(x.Id));
|
||||
var agents = agentIds.Count == 0
|
||||
? []
|
||||
: await AgentRepository.GetListAsync(x => agentIds.Contains(x.Id));
|
||||
var contracts = contractIds.Count == 0
|
||||
? []
|
||||
: await ContractRepository.GetListAsync(x => contractIds.Contains(x.Id));
|
||||
var accounts = accountIds.Count == 0
|
||||
? []
|
||||
: await CompanyAccountRepository.GetListAsync(x => accountIds.Contains(x.Id));
|
||||
var lines = !includeLines || applyIds.Count == 0
|
||||
? []
|
||||
: await PaymentApplyLineRepository.GetListAsync(x => applyIds.Contains(x.PaymentApplyId));
|
||||
|
||||
var customerMap = customers.ToDictionary(x => x.Id);
|
||||
var supplierMap = suppliers.ToDictionary(x => x.Id);
|
||||
var agentMap = agents.ToDictionary(x => x.Id);
|
||||
var contractMap = contracts.ToDictionary(x => x.Id);
|
||||
var accountMap = accounts.ToDictionary(x => x.Id);
|
||||
var lineGroups = lines.GroupBy(x => x.PaymentApplyId).ToDictionary(g => g.Key, g => g.ToList());
|
||||
|
||||
return entities.Select(entity =>
|
||||
{
|
||||
string? payeeCode = null;
|
||||
string? payeeName = null;
|
||||
if (entity.PayeeType == FinancePartyTypeCodes.Customer
|
||||
&& customerMap.TryGetValue(entity.PayeeId, out var customer))
|
||||
{
|
||||
payeeCode = customer.CustomerCode;
|
||||
payeeName = customer.CustomerName;
|
||||
}
|
||||
else if (entity.PayeeType == FinancePartyTypeCodes.Supplier
|
||||
&& supplierMap.TryGetValue(entity.PayeeId, out var supplier))
|
||||
{
|
||||
payeeCode = supplier.SupplierCode;
|
||||
payeeName = supplier.SupplierName;
|
||||
}
|
||||
else if (entity.PayeeType == FinancePartyTypeCodes.Agent
|
||||
&& agentMap.TryGetValue(entity.PayeeId, out var agent))
|
||||
{
|
||||
payeeCode = agent.AgentCode;
|
||||
payeeName = agent.AgentName;
|
||||
}
|
||||
|
||||
string? contractNo = null;
|
||||
if (entity.ContractId is > 0 && contractMap.TryGetValue(entity.ContractId.Value, out var contract))
|
||||
{
|
||||
contractNo = contract.ContractNo;
|
||||
}
|
||||
|
||||
string? companyAccountName = null;
|
||||
if (entity.CompanyAccountId is > 0
|
||||
&& accountMap.TryGetValue(entity.CompanyAccountId.Value, out var account))
|
||||
{
|
||||
companyAccountName = $"{account.AccountName} / {account.AccountNo}";
|
||||
}
|
||||
|
||||
var output = new FinancePaymentApplyOutput
|
||||
{
|
||||
Id = entity.Id,
|
||||
ApplyNo = entity.ApplyNo,
|
||||
PaymentType = entity.PaymentType,
|
||||
PaymentTypeName = FinancePaymentTypeCodes.GetName(entity.PaymentType),
|
||||
PayeeType = entity.PayeeType,
|
||||
PayeeTypeName = FinancePartyTypeCodes.GetName(entity.PayeeType),
|
||||
PayeeId = entity.PayeeId,
|
||||
PayeeCode = payeeCode,
|
||||
PayeeName = payeeName,
|
||||
ContractId = entity.ContractId,
|
||||
ContractNo = contractNo,
|
||||
Currency = entity.Currency,
|
||||
AmountTotal = entity.AmountTotal,
|
||||
ExpectPayDate = entity.ExpectPayDate,
|
||||
PayeeAccountName = entity.PayeeAccountName,
|
||||
PayeeBankName = entity.PayeeBankName,
|
||||
PayeeAccountNo = entity.PayeeAccountNo,
|
||||
CompanyAccountId = entity.CompanyAccountId,
|
||||
CompanyAccountName = companyAccountName,
|
||||
Status = entity.Status,
|
||||
StatusName = FinancePaymentStatusCodes.GetName(entity.Status),
|
||||
ApplicantName = entity.ApplicantName,
|
||||
AttachmentUrls = entity.AttachmentUrls,
|
||||
Remark = entity.Remark,
|
||||
ApprovalInstanceId = entity.ApprovalInstanceId,
|
||||
ApprovalInstanceNo = entity.ApprovalInstanceNo,
|
||||
ApprovalPending = entity.Status == FinancePaymentStatusCodes.PendingApproval,
|
||||
RejectReason = entity.RejectReason,
|
||||
PaidTime = entity.PaidTime,
|
||||
BankTxnNo = entity.BankTxnNo,
|
||||
PaidBy = entity.PaidBy,
|
||||
PaidVoucherUrl = entity.PaidVoucherUrl,
|
||||
CreateTime = entity.CreateTime,
|
||||
UpdateTime = entity.UpdateTime == default ? null : entity.UpdateTime
|
||||
};
|
||||
|
||||
if (includeLines && lineGroups.TryGetValue(entity.Id, out var applyLines))
|
||||
{
|
||||
output.Lines = applyLines.Select(x => new FinancePaymentApplyLineOutput
|
||||
{
|
||||
Id = x.Id,
|
||||
Description = x.Description,
|
||||
Amount = x.Amount,
|
||||
RefNo = x.RefNo,
|
||||
Remark = x.Remark
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
return output;
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
private async Task<(string? Code, string? Name)> ResolvePayeeAsync(string payeeType, int payeeId)
|
||||
{
|
||||
if (payeeType == FinancePartyTypeCodes.Customer)
|
||||
{
|
||||
var customer = await CustomerRepository.FirstOrDefaultAsync(x => x.Id == payeeId);
|
||||
return customer == null ? (null, null) : (customer.CustomerCode, customer.CustomerName);
|
||||
}
|
||||
|
||||
if (payeeType == FinancePartyTypeCodes.Supplier)
|
||||
{
|
||||
var supplier = await SupplierRepository.FirstOrDefaultAsync(x => x.Id == payeeId);
|
||||
return supplier == null ? (null, null) : (supplier.SupplierCode, supplier.SupplierName);
|
||||
}
|
||||
|
||||
if (payeeType == FinancePartyTypeCodes.Agent)
|
||||
{
|
||||
var agent = await AgentRepository.FirstOrDefaultAsync(x => x.Id == payeeId);
|
||||
return agent == null ? (null, null) : (agent.AgentCode, agent.AgentName);
|
||||
}
|
||||
|
||||
return (null, null);
|
||||
}
|
||||
|
||||
private async Task<string> GenerateApplyNoAsync()
|
||||
{
|
||||
var prefix = $"PAY{DateTime.Now:yyyyMMdd}";
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
var existing = await PaymentApplyRepository.GetListAsync(x => x.ApplyNo.StartsWith(prefix));
|
||||
var maxSeq = 0;
|
||||
foreach (var item in existing)
|
||||
{
|
||||
var suffix = item.ApplyNo.Length > prefix.Length ? item.ApplyNo[prefix.Length..] : string.Empty;
|
||||
if (int.TryParse(suffix, out var seq) && seq > maxSeq)
|
||||
{
|
||||
maxSeq = seq;
|
||||
}
|
||||
}
|
||||
|
||||
var applyNo = $"{prefix}{(maxSeq + 1):D4}";
|
||||
if (!await PaymentApplyRepository.ExistsApplyNoAsync(applyNo))
|
||||
{
|
||||
return applyNo;
|
||||
}
|
||||
}
|
||||
|
||||
throw new BusinessException("付款申请单号生成失败");
|
||||
}
|
||||
|
||||
private static string BuildBizKey(int paymentApplyId) =>
|
||||
$"{ApprovalCodes.FinancePaymentApply}:{paymentApplyId}";
|
||||
|
||||
private static decimal RoundMoney(decimal value) => Math.Round(value, 2, MidpointRounding.AwayFromZero);
|
||||
|
||||
private static string? NormalizeOptional(string? value) =>
|
||||
string.IsNullOrWhiteSpace(value) ? null : value.Trim();
|
||||
}
|
||||
@ -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; }
|
||||
}
|
||||
}
|
||||
1333
src/Oms.Application/Services/Finance/InvoiceService.cs
Normal file
1333
src/Oms.Application/Services/Finance/InvoiceService.cs
Normal file
File diff suppressed because it is too large
Load Diff
@ -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 PaymentApplyApprovalHandler(
|
||||
IFinancePaymentApplyRepository paymentApplyRepository) : IApprovalOperationHandler, ITransientDependency
|
||||
{
|
||||
private static readonly JsonSerializerOptions JsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
/// <inheritdoc />
|
||||
public string OperationCode => ApprovalCodes.FinancePaymentApply;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task ExecuteAsync(ApprovalExecutionContext context, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var apply = await GetApplyOrThrowAsync(context, cancellationToken);
|
||||
if (apply.Status == FinancePaymentStatusCodes.PendingPay || apply.Status == FinancePaymentStatusCodes.Paid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (apply.Status != FinancePaymentStatusCodes.PendingApproval)
|
||||
{
|
||||
throw new BusinessException("只有审批中的付款申请才能审批通过");
|
||||
}
|
||||
|
||||
apply.Status = FinancePaymentStatusCodes.PendingPay;
|
||||
apply.ApprovalInstanceId = context.InstanceId;
|
||||
apply.ApprovalInstanceNo = context.InstanceNo;
|
||||
apply.RejectReason = null;
|
||||
await paymentApplyRepository.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 = FinancePaymentStatusCodes.Rejected;
|
||||
apply.RejectReason = string.IsNullOrWhiteSpace(comment)
|
||||
? $"审批驳回 {context.InstanceNo}".Trim()
|
||||
: comment.Trim();
|
||||
apply.ApprovalInstanceId = context.InstanceId;
|
||||
apply.ApprovalInstanceNo = context.InstanceNo;
|
||||
await paymentApplyRepository.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 = FinancePaymentStatusCodes.Draft;
|
||||
apply.RejectReason = null;
|
||||
apply.ApprovalInstanceId = context.InstanceId;
|
||||
apply.ApprovalInstanceNo = context.InstanceNo;
|
||||
if (!string.IsNullOrWhiteSpace(comment))
|
||||
{
|
||||
apply.Remark = comment.Trim();
|
||||
}
|
||||
|
||||
await paymentApplyRepository.UpdateAsync(apply, cancellationToken);
|
||||
}
|
||||
|
||||
private async Task<FinancePaymentApply> GetApplyOrThrowAsync(
|
||||
ApprovalExecutionContext context,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var applyId = ResolveApplyId(context);
|
||||
return await paymentApplyRepository.FirstOrDefaultAsync(x => x.Id == applyId, cancellationToken)
|
||||
?? throw new BusinessException("付款申请不存在");
|
||||
}
|
||||
|
||||
private async Task<FinancePaymentApply?> TryGetPendingApplyAsync(
|
||||
ApprovalExecutionContext context,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var applyId = ResolveApplyId(context);
|
||||
var apply = await paymentApplyRepository.FirstOrDefaultAsync(x => x.Id == applyId, cancellationToken);
|
||||
if (apply == null || apply.Status != FinancePaymentStatusCodes.PendingApproval)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return apply;
|
||||
}
|
||||
|
||||
private static int ResolveApplyId(ApprovalExecutionContext context)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(context.PayloadJson))
|
||||
{
|
||||
try
|
||||
{
|
||||
var payload = JsonSerializer.Deserialize<PaymentApplyPayload>(context.PayloadJson, JsonOptions);
|
||||
if (payload is { PaymentApplyId: > 0 })
|
||||
{
|
||||
return payload.PaymentApplyId;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// fall through BizKey
|
||||
}
|
||||
}
|
||||
|
||||
var bizKey = context.BizKey ?? string.Empty;
|
||||
var prefix = $"{ApprovalCodes.FinancePaymentApply}:";
|
||||
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 PaymentApplyPayload
|
||||
{
|
||||
public int PaymentApplyId { get; set; }
|
||||
}
|
||||
}
|
||||
@ -137,7 +137,7 @@ public class InboundRecordService : ApplicationService
|
||||
await AutoTriggerRuntimeService.EnqueueFireAsync(order.Id, AutoTriggerTiming.Inbound, operatorId);
|
||||
|
||||
var refreshed = await OrderRepository.GetByWaybillNoAsync(waybillNo);
|
||||
await WechatOrderNotifyDispatcher.TryNotifyAsync(
|
||||
await WechatOrderNotifyDispatcher.EnqueueNotifyAsync(
|
||||
refreshed ?? order,
|
||||
WechatOrderNotifyEventCodes.Inbound);
|
||||
var output = ObjectMapper.Map<InboundRecord, InboundRecordOutput>(savedEntity);
|
||||
|
||||
@ -147,9 +147,8 @@ public class OutboundRecordService : ApplicationService
|
||||
await AutoTriggerRuntimeService.EnqueueFireAsync(order.Id, AutoTriggerTiming.Outbound, operatorId);
|
||||
|
||||
var refreshed = await OrderRepository.GetByWaybillNoAsync(waybillNo);
|
||||
await WechatOrderNotifyDispatcher.TryNotifyAsync(
|
||||
refreshed ?? order,
|
||||
WechatOrderNotifyEventCodes.Outbound);
|
||||
// 与装袋出库共用入口;30 分钟 sent 去重防双通道重复
|
||||
await WechatOrderNotifyDispatcher.EnqueueOutboundNotifyAsync(refreshed ?? order);
|
||||
|
||||
return ObjectMapper.Map<OutboundRecord, OutboundRecordOutput>(savedEntity);
|
||||
}
|
||||
|
||||
@ -369,7 +369,7 @@ public class ShipBagService : ApplicationService
|
||||
});
|
||||
await AutoTriggerRuntimeService.EnqueueFireAsync(order.Id, AutoTriggerTiming.Outbound, operatorId);
|
||||
var refreshed = await OrderRepository.GetByServiceNoAsync(order.ServiceNo) ?? order;
|
||||
await WechatOrderNotifyDispatcher.TryNotifyAsync(refreshed, WechatOrderNotifyEventCodes.Outbound);
|
||||
await WechatOrderNotifyDispatcher.EnqueueOutboundNotifyAsync(refreshed);
|
||||
}
|
||||
|
||||
bag.Status = ShipBagStatusCodes.Shipped;
|
||||
|
||||
@ -80,7 +80,7 @@ public class OrderIssueNotificationService(
|
||||
// 仅问题件状态时投递客户订阅的微信通知(自动触发警告等不发)
|
||||
if (string.Equals(order.OrderStatus, OrderStatusCodes.Problematic, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
await wechatOrderNotifyDispatcher.TryNotifyAsync(
|
||||
await wechatOrderNotifyDispatcher.EnqueueNotifyAsync(
|
||||
order,
|
||||
WechatOrderNotifyEventCodes.Problematic,
|
||||
remark: string.IsNullOrWhiteSpace(content) ? title : content);
|
||||
|
||||
@ -0,0 +1,85 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Oms.Application.Dtos.Orders;
|
||||
using Oms.Domain.SystemAggregate.Consts;
|
||||
using Oms.Domain.SystemAggregate.Repositories;
|
||||
|
||||
namespace Oms.Application.Services.Orders;
|
||||
|
||||
public partial class OrderService
|
||||
{
|
||||
private IOrderNotifyLogRepository OrderNotifyLogRepository =>
|
||||
LazyServiceProvider.GetRequiredService<IOrderNotifyLogRepository>();
|
||||
|
||||
/// <summary>
|
||||
/// 运单通知日志列表(微信 / 邮件;按时间倒序)。
|
||||
/// </summary>
|
||||
/// <param name="orderId">订单 Id。</param>
|
||||
/// <param name="cancellationToken">取消令牌。</param>
|
||||
[HttpGet("/order/notify-log/list")]
|
||||
public async Task<OrderNotifyLogListOutput> GetNotifyLogListAsync(
|
||||
[FromQuery] int orderId,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
await GetOrderOrThrowAsync(orderId);
|
||||
var rows = await OrderNotifyLogRepository.ListByOrderIdAsync(orderId, cancellationToken);
|
||||
return new OrderNotifyLogListOutput
|
||||
{
|
||||
Items = rows.Select(x =>
|
||||
{
|
||||
var eventName = WechatOrderNotifyEventCodes.GetName(x.EventCode) ?? x.EventCode;
|
||||
var channelName = OrderNotifyChannels.GetName(x.Channel);
|
||||
var statusText = x.Status switch
|
||||
{
|
||||
"sent" => "成功",
|
||||
"failed" => "失败",
|
||||
"skipped" => "跳过",
|
||||
_ => x.Status
|
||||
};
|
||||
var parts = new List<string> { $"{eventName}:{statusText}" };
|
||||
if (!string.IsNullOrWhiteSpace(x.ErrMsg)
|
||||
&& !string.Equals(x.ErrMsg, "发送成功", StringComparison.Ordinal))
|
||||
{
|
||||
parts.Add(x.ErrMsg.Trim());
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(x.Recipient))
|
||||
{
|
||||
parts.Add(x.Channel == OrderNotifyChannels.Email
|
||||
? $"收件={x.Recipient}"
|
||||
: $"OpenId={x.Recipient}");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(x.ProviderMsgId))
|
||||
{
|
||||
parts.Add($"msgid={x.ProviderMsgId}");
|
||||
}
|
||||
|
||||
if (x.ErrCode is int code and not 0)
|
||||
{
|
||||
parts.Add($"errcode={code}");
|
||||
}
|
||||
|
||||
return new OrderNotifyLogOutput
|
||||
{
|
||||
Id = x.Id,
|
||||
OrderId = x.OrderId,
|
||||
Channel = x.Channel,
|
||||
ChannelName = channelName,
|
||||
EventCode = x.EventCode,
|
||||
EventName = eventName,
|
||||
Recipient = x.Recipient,
|
||||
TemplateRef = x.TemplateRef,
|
||||
Subject = x.Subject,
|
||||
Status = x.Status,
|
||||
ProviderMsgId = x.ProviderMsgId,
|
||||
ErrCode = x.ErrCode,
|
||||
ErrMsg = x.ErrMsg,
|
||||
SmtpUsername = x.SmtpUsername,
|
||||
Summary = string.Join(";", parts),
|
||||
PayloadJson = x.PayloadJson,
|
||||
CreateTime = x.CreateTime
|
||||
};
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -1356,7 +1356,7 @@ public partial class OrderService
|
||||
|
||||
if (becamePendingPayment)
|
||||
{
|
||||
await WechatOrderNotifyDispatcher.TryNotifyAsync(order, WechatOrderNotifyEventCodes.PendingPayment);
|
||||
await WechatOrderNotifyDispatcher.EnqueueNotifyAsync(order, WechatOrderNotifyEventCodes.PendingPayment);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2748,7 +2748,7 @@ public partial class OrderService
|
||||
|
||||
if (string.Equals(order.OrderStatus, OrderStatusCodes.PendingPayment, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
await WechatOrderNotifyDispatcher.TryNotifyAsync(order, WechatOrderNotifyEventCodes.PendingPayment);
|
||||
await WechatOrderNotifyDispatcher.EnqueueNotifyAsync(order, WechatOrderNotifyEventCodes.PendingPayment);
|
||||
}
|
||||
|
||||
if (allocated)
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using Fake.Application;
|
||||
using Fake.ObjectStorage;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@ -27,6 +30,16 @@ public class SystemOtherConfigService : ApplicationService
|
||||
private const string BrandLogoChannelFavicon = "favicon";
|
||||
private const string BrandLogoChannelMascot = "mascot";
|
||||
|
||||
/// <summary>品牌文案固定对象键(JSON,不落业务库表)。</summary>
|
||||
private const string BrandCopyObjectKey = "uploads/brand-logo/brand-copy.json";
|
||||
|
||||
private static readonly JsonSerializerOptions BrandCopyJsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
WriteIndented = true
|
||||
};
|
||||
|
||||
private ISystemOtherConfigRepository SystemOtherConfigRepository =>
|
||||
LazyServiceProvider.GetRequiredService<ISystemOtherConfigRepository>();
|
||||
|
||||
@ -152,17 +165,40 @@ public class SystemOtherConfigService : ApplicationService
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取客户充值用支付宝/微信收款码图片地址。未配置时对应 URL 为空(前端可回退本地默认图)。
|
||||
/// 获取客户充值用支付宝/微信收款码图片地址。
|
||||
/// 返回同源 API 文件地址(非 COS 直链),未配置时对应 URL 为空。
|
||||
/// </summary>
|
||||
[HttpGet("/system/other-config/payment-qr")]
|
||||
public async Task<PaymentReceiveQrOutput> GetPaymentReceiveQrAsync()
|
||||
{
|
||||
var entity = await SystemOtherConfigRepository.GetByConfigCodeAsync(SystemOtherConfigCodes.PaymentReceiveQr);
|
||||
return new PaymentReceiveQrOutput
|
||||
return MapPaymentReceiveQrOutput(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 按渠道输出收款码图片字节(同源,避免浏览器直连 COS 证书域名)。
|
||||
/// 收款码本身用于对客展示,允许匿名读取以便 <img src> 无需带 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),
|
||||
WechatUrl = FileStorage.GetPublicUrl(entity?.Remark)
|
||||
};
|
||||
throw new BusinessException("渠道仅支持 alipay 或 wechat");
|
||||
}
|
||||
|
||||
var entity = await SystemOtherConfigRepository.GetByConfigCodeAsync(SystemOtherConfigCodes.PaymentReceiveQr);
|
||||
var objectKey = normalized == PaymentQrChannelAlipay ? entity?.AppKey : entity?.Remark;
|
||||
return await StreamManagedImageAsync(objectKey, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -191,11 +227,7 @@ public class SystemOtherConfigService : ApplicationService
|
||||
}
|
||||
|
||||
await SystemOtherConfigRepository.UpdateAsync(entity);
|
||||
return new PaymentReceiveQrOutput
|
||||
{
|
||||
AlipayUrl = FileStorage.GetPublicUrl(entity.AppKey),
|
||||
WechatUrl = FileStorage.GetPublicUrl(entity.Remark)
|
||||
};
|
||||
return MapPaymentReceiveQrOutput(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -222,15 +254,12 @@ public class SystemOtherConfigService : ApplicationService
|
||||
}
|
||||
|
||||
await SystemOtherConfigRepository.UpdateAsync(entity);
|
||||
return new PaymentReceiveQrOutput
|
||||
{
|
||||
AlipayUrl = FileStorage.GetPublicUrl(entity.AppKey),
|
||||
WechatUrl = FileStorage.GetPublicUrl(entity.Remark)
|
||||
};
|
||||
return MapPaymentReceiveQrOutput(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取品牌 Logo(系统顶栏 / 官网 / 网站标签 / 启动页吉祥物)。未配置时对应 URL 为空(前端回退本地默认图)。匿名可读。
|
||||
/// 获取品牌 Logo(系统顶栏 / 官网 / 网站标签 / 启动页吉祥物)。
|
||||
/// 返回同源 API 文件地址(非 COS 直链);未配置时对应 URL 为空。匿名可读。
|
||||
/// </summary>
|
||||
[AllowAnonymous]
|
||||
[HttpGet("/system/other-config/brand-logo")]
|
||||
@ -240,6 +269,68 @@ public class SystemOtherConfigService : ApplicationService
|
||||
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>
|
||||
/// 获取品牌文案(顶栏/官网一套 + AI 欢迎语一套)。匿名可读;文件存对象存储,非数据库。
|
||||
/// </summary>
|
||||
[AllowAnonymous]
|
||||
[HttpGet("/system/other-config/brand-copy")]
|
||||
public async Task<BrandCopyOutput> GetBrandCopyAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await ReadBrandCopyAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存品牌文案到对象存储 JSON(uploads/brand-logo/brand-copy.json)。
|
||||
/// </summary>
|
||||
/// <param name="input">入参:顶栏文案与 AI 欢迎语文案。</param>
|
||||
/// <param name="cancellationToken">取消令牌。</param>
|
||||
[HttpPost("/system/other-config/brand-copy/save")]
|
||||
public async Task<BrandCopyOutput> SaveBrandCopyAsync(
|
||||
BrandCopySaveInput input,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var output = NormalizeBrandCopy(input);
|
||||
var json = JsonSerializer.Serialize(output, BrandCopyJsonOptions);
|
||||
await using var stream = new MemoryStream(Encoding.UTF8.GetBytes(json));
|
||||
await FileStorage.SaveObjectAsync(stream, BrandCopyObjectKey, "application/json", cancellationToken);
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上传并替换品牌 Logo。Channel=portal|site|favicon|mascot;返回最新可访问 URL。
|
||||
/// </summary>
|
||||
@ -325,12 +416,231 @@ public class SystemOtherConfigService : ApplicationService
|
||||
private BrandLogoOutput MapBrandLogoOutput(SystemOtherConfig? entity) =>
|
||||
new()
|
||||
{
|
||||
PortalUrl = FileStorage.GetPublicUrl(entity?.AppKey),
|
||||
SiteUrl = FileStorage.GetPublicUrl(entity?.Remark),
|
||||
FaviconUrl = FileStorage.GetPublicUrl(entity?.BaseUrl),
|
||||
MascotUrl = FileStorage.GetPublicUrl(entity?.AppSecret)
|
||||
PortalUrl = BuildSameOriginImageUrl("/system/other-config/brand-logo/file", BrandLogoChannelPortal, entity?.AppKey),
|
||||
SiteUrl = BuildSameOriginImageUrl("/system/other-config/brand-logo/file", BrandLogoChannelSite, entity?.Remark),
|
||||
FaviconUrl = BuildSameOriginImageUrl("/system/other-config/brand-logo/file", BrandLogoChannelFavicon, entity?.BaseUrl),
|
||||
MascotUrl = BuildSameOriginImageUrl("/system/other-config/brand-logo/file", BrandLogoChannelMascot, entity?.AppSecret)
|
||||
};
|
||||
|
||||
private static BrandCopyOutput DefaultBrandCopy() => new();
|
||||
|
||||
private static BrandCopyOutput NormalizeBrandCopy(BrandCopySaveInput? input)
|
||||
{
|
||||
if (input == null)
|
||||
{
|
||||
return DefaultBrandCopy();
|
||||
}
|
||||
|
||||
return new BrandCopyOutput
|
||||
{
|
||||
NavName = RequireBrandText(input.NavName, "顶栏短名"),
|
||||
NavFullName = RequireBrandText(input.NavFullName, "顶栏全称"),
|
||||
AiWelcomeTitleZh = RequireBrandText(input.AiWelcomeTitleZh, "AI 欢迎标题(中文)"),
|
||||
AiWelcomeTitleShortZh = RequireBrandText(input.AiWelcomeTitleShortZh, "AI 欢迎短标题(中文)"),
|
||||
AiWelcomeTitleEn = RequireBrandText(input.AiWelcomeTitleEn, "AI 欢迎标题(英文)"),
|
||||
AiWelcomeTitleShortEn = RequireBrandText(input.AiWelcomeTitleShortEn, "AI 欢迎短标题(英文)"),
|
||||
Icp = RequireBrandText(input.Icp, "ICP 备案号")
|
||||
};
|
||||
}
|
||||
|
||||
private static string RequireBrandText(string? value, string label)
|
||||
{
|
||||
var text = (value ?? string.Empty).Trim();
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
throw new BusinessException($"{label}不能为空");
|
||||
}
|
||||
|
||||
if (text.Length > 200)
|
||||
{
|
||||
throw new BusinessException($"{label}不能超过 200 字");
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
private async Task<BrandCopyOutput> ReadBrandCopyAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var defaults = DefaultBrandCopy();
|
||||
try
|
||||
{
|
||||
if (!await FileStorage.ExistsAsync(BrandCopyObjectKey, cancellationToken))
|
||||
{
|
||||
return defaults;
|
||||
}
|
||||
|
||||
await using var stream = await FileStorage.GetAsync(BrandCopyObjectKey, cancellationToken);
|
||||
using var ms = new MemoryStream();
|
||||
await stream.CopyToAsync(ms, cancellationToken);
|
||||
if (ms.Length <= 0)
|
||||
{
|
||||
return defaults;
|
||||
}
|
||||
|
||||
var parsed = JsonSerializer.Deserialize<BrandCopyOutput>(ms.ToArray(), BrandCopyJsonOptions);
|
||||
if (parsed == null)
|
||||
{
|
||||
return defaults;
|
||||
}
|
||||
|
||||
return new BrandCopyOutput
|
||||
{
|
||||
NavName = string.IsNullOrWhiteSpace(parsed.NavName) ? defaults.NavName : parsed.NavName.Trim(),
|
||||
NavFullName = string.IsNullOrWhiteSpace(parsed.NavFullName)
|
||||
? defaults.NavFullName
|
||||
: parsed.NavFullName.Trim(),
|
||||
AiWelcomeTitleZh = string.IsNullOrWhiteSpace(parsed.AiWelcomeTitleZh)
|
||||
? defaults.AiWelcomeTitleZh
|
||||
: parsed.AiWelcomeTitleZh.Trim(),
|
||||
AiWelcomeTitleShortZh = string.IsNullOrWhiteSpace(parsed.AiWelcomeTitleShortZh)
|
||||
? defaults.AiWelcomeTitleShortZh
|
||||
: parsed.AiWelcomeTitleShortZh.Trim(),
|
||||
AiWelcomeTitleEn = string.IsNullOrWhiteSpace(parsed.AiWelcomeTitleEn)
|
||||
? defaults.AiWelcomeTitleEn
|
||||
: parsed.AiWelcomeTitleEn.Trim(),
|
||||
AiWelcomeTitleShortEn = string.IsNullOrWhiteSpace(parsed.AiWelcomeTitleShortEn)
|
||||
? defaults.AiWelcomeTitleShortEn
|
||||
: parsed.AiWelcomeTitleShortEn.Trim(),
|
||||
Icp = string.IsNullOrWhiteSpace(parsed.Icp) ? defaults.Icp : parsed.Icp.Trim()
|
||||
};
|
||||
}
|
||||
catch
|
||||
{
|
||||
return defaults;
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
var entity = await SystemOtherConfigRepository.GetByConfigCodeAsync(SystemOtherConfigCodes.PaymentReceiveQr);
|
||||
|
||||
@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Oms.Application.Dtos.Shared;
|
||||
using Oms.Application.Dtos.System;
|
||||
using Oms.Application.Services.WeChatNotify;
|
||||
using Oms.Application.Shared;
|
||||
using Oms.Domain.OrdersAggregate.Repositories;
|
||||
using Oms.Domain.SystemAggregate.Consts;
|
||||
using Oms.Domain.SystemAggregate.Entities;
|
||||
@ -11,14 +12,23 @@ using Oms.Domain.SystemAggregate.Repositories;
|
||||
namespace Oms.Application.Services.System;
|
||||
|
||||
/// <summary>
|
||||
/// 微信订单通知模板配置(系统其他配置入口使用)。
|
||||
/// 订单通知模板配置(微信 + 邮件;系统其他配置入口使用)。
|
||||
/// </summary>
|
||||
[ApiExplorerSettings(GroupName = "OMS-System")]
|
||||
public class WechatOrderNotifyConfigService : ApplicationService
|
||||
{
|
||||
/// <summary>系统发信 SMTP 的 OwnerUserId。</summary>
|
||||
public const int SystemSmtpOwnerUserId = 0;
|
||||
|
||||
private IWechatNotifyTemplateRepository TemplateRepository =>
|
||||
LazyServiceProvider.GetRequiredService<IWechatNotifyTemplateRepository>();
|
||||
|
||||
private ISystemBatchEmailTemplateRepository BatchEmailTemplateRepository =>
|
||||
LazyServiceProvider.GetRequiredService<ISystemBatchEmailTemplateRepository>();
|
||||
|
||||
private ISystemBatchEmailAccountRepository BatchEmailAccountRepository =>
|
||||
LazyServiceProvider.GetRequiredService<ISystemBatchEmailAccountRepository>();
|
||||
|
||||
private IOrderRepository OrderRepository =>
|
||||
LazyServiceProvider.GetRequiredService<IOrderRepository>();
|
||||
|
||||
@ -62,6 +72,41 @@ public class WechatOrderNotifyConfigService : ApplicationService
|
||||
var name = WechatOrderNotifyEventCodes.GetName(code) ?? code;
|
||||
await EnsureSeedAsync(cancellationToken);
|
||||
|
||||
var ownerUserId = CurrentUser.GetId<int>();
|
||||
if (input.EmailEnabled)
|
||||
{
|
||||
if (ownerUserId <= 0)
|
||||
{
|
||||
throw new BusinessException("未登录,无法绑定邮件模板");
|
||||
}
|
||||
|
||||
var tplName = input.EmailTemplateName?.Trim() ?? string.Empty;
|
||||
if (string.IsNullOrWhiteSpace(tplName))
|
||||
{
|
||||
throw new BusinessException("启用邮件时请选择 batch-email 模板");
|
||||
}
|
||||
|
||||
var batchTpl = await BatchEmailTemplateRepository.GetByOwnerAndNameAsync(
|
||||
ownerUserId,
|
||||
tplName,
|
||||
cancellationToken);
|
||||
if (batchTpl == null)
|
||||
{
|
||||
throw new BusinessException($"邮件模板不存在:{tplName}(请先在「批量邮件」中创建)");
|
||||
}
|
||||
|
||||
if (input.EmailUseSystemSmtp)
|
||||
{
|
||||
var systemAccount = await BatchEmailAccountRepository.GetByOwnerAsync(
|
||||
SystemSmtpOwnerUserId,
|
||||
cancellationToken);
|
||||
if (systemAccount == null || string.IsNullOrWhiteSpace(systemAccount.SmtpPassword))
|
||||
{
|
||||
throw new BusinessException("尚未配置系统发信 SMTP,请先在本页保存系统发信账号");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var entity = await TemplateRepository.GetByEventCodeAsync(code, cancellationToken);
|
||||
if (entity == null)
|
||||
{
|
||||
@ -70,12 +115,12 @@ public class WechatOrderNotifyConfigService : ApplicationService
|
||||
EventCode = code,
|
||||
EventName = name
|
||||
};
|
||||
ApplyInput(entity, input, name);
|
||||
ApplyInput(entity, input, name, ownerUserId);
|
||||
await TemplateRepository.InsertAsync(entity, cancellationToken: cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
ApplyInput(entity, input, name);
|
||||
ApplyInput(entity, input, name, ownerUserId);
|
||||
entity.UpdateTime = DateTime.Now;
|
||||
await TemplateRepository.UpdateAsync(entity, cancellationToken: cancellationToken);
|
||||
}
|
||||
@ -84,10 +129,83 @@ public class WechatOrderNotifyConfigService : ApplicationService
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 按订单试发一条模板消息(跳过客户订阅与去重,仍要求客户有 OpenId)。
|
||||
/// 查询系统发信 SMTP 是否已配置。
|
||||
/// </summary>
|
||||
[HttpGet("/system/wechat-order-notify/system-smtp")]
|
||||
public async Task<OrderNotifySystemSmtpStatusOutput> GetSystemSmtpAsync(
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await BatchEmailAccountRepository.GetByOwnerAsync(
|
||||
SystemSmtpOwnerUserId,
|
||||
cancellationToken);
|
||||
return new OrderNotifySystemSmtpStatusOutput
|
||||
{
|
||||
Configured = entity != null && !string.IsNullOrWhiteSpace(entity.SmtpPassword),
|
||||
SmtpUsername = entity?.SmtpUsername,
|
||||
FromName = entity?.FromName
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存系统发信 SMTP(OwnerUserId=0,与配置操作人解耦)。
|
||||
/// </summary>
|
||||
[HttpPost("/system/wechat-order-notify/system-smtp/save")]
|
||||
public async Task<OrderNotifySystemSmtpStatusOutput> SaveSystemSmtpAsync(
|
||||
[FromBody] BatchEmailAccountSaveInput input,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var username = input.SmtpUsername?.Trim() ?? string.Empty;
|
||||
if (string.IsNullOrWhiteSpace(username))
|
||||
{
|
||||
throw new BusinessException("SMTP 账号不能为空");
|
||||
}
|
||||
|
||||
var password = input.SmtpPassword ?? string.Empty;
|
||||
var entity = await BatchEmailAccountRepository.GetByOwnerAsync(
|
||||
SystemSmtpOwnerUserId,
|
||||
cancellationToken);
|
||||
if (string.IsNullOrWhiteSpace(password)
|
||||
|| (BatchEmailSmtpHelper.IsSecretMask(password) && entity == null))
|
||||
{
|
||||
throw new BusinessException("SMTP 密码不能为空");
|
||||
}
|
||||
|
||||
var serverType = NormalizeServerType(input.ServerType);
|
||||
if (entity == null)
|
||||
{
|
||||
await BatchEmailAccountRepository.InsertAsync(
|
||||
new SystemBatchEmailAccount
|
||||
{
|
||||
OwnerUserId = SystemSmtpOwnerUserId,
|
||||
SmtpUsername = username,
|
||||
SmtpPassword = password,
|
||||
ServerType = serverType,
|
||||
FromName = NormalizeOptional(input.FromName)
|
||||
},
|
||||
cancellationToken: cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.SmtpUsername = username;
|
||||
if (!BatchEmailSmtpHelper.IsSecretMask(password))
|
||||
{
|
||||
entity.SmtpPassword = password;
|
||||
}
|
||||
|
||||
entity.ServerType = serverType;
|
||||
entity.FromName = NormalizeOptional(input.FromName);
|
||||
entity.UpdateTime = DateTime.Now;
|
||||
await BatchEmailAccountRepository.UpdateAsync(entity, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
return await GetSystemSmtpAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 按订单试发(微信 + 邮件);跳过客户订阅与去重,返回请求/响应明细。
|
||||
/// </summary>
|
||||
[HttpPost("/system/wechat-order-notify/trial-send")]
|
||||
public async Task TrialSendAsync(
|
||||
public async Task<TrialWechatOrderNotifyResultOutput> TrialSendAsync(
|
||||
[FromBody] TrialWechatOrderNotifyInput input,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
@ -100,7 +218,7 @@ public class WechatOrderNotifyConfigService : ApplicationService
|
||||
var order = await ResolveOrderAsync(input, cancellationToken)
|
||||
?? throw new BusinessException("未找到订单");
|
||||
|
||||
await Dispatcher.TryNotifyAsync(
|
||||
return await Dispatcher.NotifyDetailedAsync(
|
||||
order,
|
||||
code,
|
||||
remark: "运营试发",
|
||||
@ -153,7 +271,11 @@ public class WechatOrderNotifyConfigService : ApplicationService
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void ApplyInput(WechatNotifyTemplate entity, SaveWechatOrderNotifyTemplateInput input, string name)
|
||||
private static void ApplyInput(
|
||||
WechatNotifyTemplate entity,
|
||||
SaveWechatOrderNotifyTemplateInput input,
|
||||
string name,
|
||||
int ownerUserId)
|
||||
{
|
||||
entity.EventName = name;
|
||||
entity.TemplateId = string.IsNullOrWhiteSpace(input.TemplateId) ? null : input.TemplateId.Trim();
|
||||
@ -162,6 +284,23 @@ public class WechatOrderNotifyConfigService : ApplicationService
|
||||
? null
|
||||
: input.FieldMappingJson.Trim();
|
||||
entity.IsEnabled = input.IsEnabled;
|
||||
entity.EmailEnabled = input.EmailEnabled;
|
||||
if (input.EmailEnabled)
|
||||
{
|
||||
entity.EmailTemplateName = input.EmailTemplateName!.Trim();
|
||||
entity.EmailTemplateOwnerUserId = ownerUserId;
|
||||
entity.EmailSmtpOwnerUserId = input.EmailUseSystemSmtp
|
||||
? SystemSmtpOwnerUserId
|
||||
: ownerUserId;
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.EmailTemplateName = string.IsNullOrWhiteSpace(input.EmailTemplateName)
|
||||
? null
|
||||
: input.EmailTemplateName.Trim();
|
||||
// 关闭邮件时保留上次绑定,便于再开
|
||||
}
|
||||
|
||||
entity.Remark = string.IsNullOrWhiteSpace(input.Remark) ? null : input.Remark.Trim();
|
||||
}
|
||||
|
||||
@ -178,6 +317,20 @@ public class WechatOrderNotifyConfigService : ApplicationService
|
||||
UrlTemplate = entity?.UrlTemplate,
|
||||
FieldMappingJson = entity?.FieldMappingJson,
|
||||
IsEnabled = entity?.IsEnabled ?? false,
|
||||
EmailEnabled = entity?.EmailEnabled ?? false,
|
||||
EmailTemplateName = entity?.EmailTemplateName,
|
||||
EmailTemplateOwnerUserId = entity?.EmailTemplateOwnerUserId,
|
||||
EmailSmtpOwnerUserId = entity?.EmailSmtpOwnerUserId,
|
||||
EmailUseSystemSmtp = entity?.EmailSmtpOwnerUserId == SystemSmtpOwnerUserId,
|
||||
Remark = entity?.Remark
|
||||
};
|
||||
|
||||
private static string NormalizeServerType(string? serverType)
|
||||
{
|
||||
var value = (serverType ?? string.Empty).Trim().ToLowerInvariant();
|
||||
return value is "qiye" or "163" or "qq" or "gmail" or "outlook" ? value : "qiye";
|
||||
}
|
||||
|
||||
private static string? NormalizeOptional(string? value) =>
|
||||
string.IsNullOrWhiteSpace(value) ? null : value.Trim();
|
||||
}
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
namespace Oms.Application.Services.WeChatNotify;
|
||||
|
||||
/// <summary>
|
||||
/// 订单通知可重试失败(token/SMTP 临时故障等);Outbox 消费者应 Nack/重投。
|
||||
/// </summary>
|
||||
public sealed class OrderNotifyRetryableException : Exception
|
||||
{
|
||||
public OrderNotifyRetryableException(string message, Exception? inner = null)
|
||||
: base(message, inner)
|
||||
{
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -40,6 +40,12 @@ public static class ApprovalCodes
|
||||
|
||||
/// <summary>客户充值入账。</summary>
|
||||
public const string FinanceRechargeCredit = "Finance.Recharge.Credit";
|
||||
|
||||
/// <summary>发票开具。</summary>
|
||||
public const string FinanceInvoiceIssue = "Finance.Invoice.Issue";
|
||||
|
||||
/// <summary>付款申请。</summary>
|
||||
public const string FinancePaymentApply = "Finance.Payment.Apply";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
168
src/Oms.Domain/FinanceAggregate/Consts/FinanceContractCodes.cs
Normal file
168
src/Oms.Domain/FinanceAggregate/Consts/FinanceContractCodes.cs
Normal file
@ -0,0 +1,168 @@
|
||||
namespace Oms.Domain.FinanceAggregate.Consts;
|
||||
|
||||
/// <summary>
|
||||
/// 合同对方类型。
|
||||
/// </summary>
|
||||
public static class FinancePartyTypeCodes
|
||||
{
|
||||
/// <summary>客户。</summary>
|
||||
public const string Customer = "customer";
|
||||
|
||||
/// <summary>供应商。</summary>
|
||||
public const string Supplier = "supplier";
|
||||
|
||||
/// <summary>代理。</summary>
|
||||
public const string Agent = "agent";
|
||||
|
||||
public static bool IsKnown(string? partyType) =>
|
||||
partyType is Customer or Supplier or Agent;
|
||||
|
||||
public static string GetName(string? partyType) => partyType switch
|
||||
{
|
||||
Customer => "客户",
|
||||
Supplier => "供应商",
|
||||
Agent => "代理",
|
||||
_ => partyType ?? string.Empty
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 合同结算方式。
|
||||
/// </summary>
|
||||
public static class FinanceSettlementMethodCodes
|
||||
{
|
||||
/// <summary>预付。</summary>
|
||||
public const string Prepaid = "prepaid";
|
||||
|
||||
/// <summary>票结。</summary>
|
||||
public const string Ticket = "ticket";
|
||||
|
||||
/// <summary>月结。</summary>
|
||||
public const string Monthly = "monthly";
|
||||
|
||||
/// <summary>半月结。</summary>
|
||||
public const string Biweekly = "biweekly";
|
||||
|
||||
public static bool IsKnown(string? method) =>
|
||||
method is Prepaid or Ticket or Monthly or Biweekly;
|
||||
|
||||
public static string GetName(string? method) => method switch
|
||||
{
|
||||
Prepaid => "预付",
|
||||
Ticket => "票结",
|
||||
Monthly => "月结",
|
||||
Biweekly => "半月结",
|
||||
_ => method ?? string.Empty
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 合同状态。
|
||||
/// </summary>
|
||||
public static class FinanceContractStatusCodes
|
||||
{
|
||||
/// <summary>草稿。</summary>
|
||||
public const string Draft = "draft";
|
||||
|
||||
/// <summary>生效。</summary>
|
||||
public const string Active = "active";
|
||||
|
||||
/// <summary>已到期。</summary>
|
||||
public const string Expired = "expired";
|
||||
|
||||
/// <summary>已终止。</summary>
|
||||
public const string Terminated = "terminated";
|
||||
|
||||
public static bool IsKnown(string? status) =>
|
||||
status is Draft or Active or Expired or Terminated;
|
||||
|
||||
public static string GetName(string? status) => status switch
|
||||
{
|
||||
Draft => "草稿",
|
||||
Active => "生效",
|
||||
Expired => "已到期",
|
||||
Terminated => "已终止",
|
||||
_ => status ?? string.Empty
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 付款申请类型。
|
||||
/// </summary>
|
||||
public static class FinancePaymentTypeCodes
|
||||
{
|
||||
/// <summary>供应商款项。</summary>
|
||||
public const string Supplier = "supplier";
|
||||
|
||||
/// <summary>代理佣金。</summary>
|
||||
public const string AgentCommission = "agentCommission";
|
||||
|
||||
/// <summary>客户退款。</summary>
|
||||
public const string CustomerRefund = "customerRefund";
|
||||
|
||||
/// <summary>其他。</summary>
|
||||
public const string Other = "other";
|
||||
|
||||
public static bool IsKnown(string? paymentType) =>
|
||||
paymentType is Supplier or AgentCommission or CustomerRefund or Other;
|
||||
|
||||
public static string GetName(string? paymentType) => paymentType switch
|
||||
{
|
||||
Supplier => "供应商款项",
|
||||
AgentCommission => "代理佣金",
|
||||
CustomerRefund => "客户退款",
|
||||
Other => "其他",
|
||||
_ => paymentType ?? string.Empty
|
||||
};
|
||||
|
||||
/// <summary>付款类型对应的收款方类型。</summary>
|
||||
public static string ResolvePayeeType(string paymentType) => paymentType switch
|
||||
{
|
||||
Supplier => FinancePartyTypeCodes.Supplier,
|
||||
AgentCommission => FinancePartyTypeCodes.Agent,
|
||||
CustomerRefund => FinancePartyTypeCodes.Customer,
|
||||
_ => FinancePartyTypeCodes.Supplier
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 付款申请状态。
|
||||
/// </summary>
|
||||
public static class FinancePaymentStatusCodes
|
||||
{
|
||||
/// <summary>草稿。</summary>
|
||||
public const string Draft = "draft";
|
||||
|
||||
/// <summary>审批中。</summary>
|
||||
public const string PendingApproval = "pendingApproval";
|
||||
|
||||
/// <summary>待付款。</summary>
|
||||
public const string PendingPay = "pendingPay";
|
||||
|
||||
/// <summary>已付款。</summary>
|
||||
public const string Paid = "paid";
|
||||
|
||||
/// <summary>已驳回。</summary>
|
||||
public const string Rejected = "rejected";
|
||||
|
||||
public static bool IsKnown(string? status) =>
|
||||
status is Draft or PendingApproval or PendingPay or Paid or Rejected;
|
||||
|
||||
public static string GetName(string? status) => status switch
|
||||
{
|
||||
Draft => "草稿",
|
||||
PendingApproval => "审批中",
|
||||
PendingPay => "待付款",
|
||||
Paid => "已付款",
|
||||
Rejected => "已驳回",
|
||||
_ => status ?? string.Empty
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 财务币种。
|
||||
/// </summary>
|
||||
public static class FinanceCurrencyCodes
|
||||
{
|
||||
public const string Cny = "CNY";
|
||||
}
|
||||
111
src/Oms.Domain/FinanceAggregate/Consts/InvoiceCodes.cs
Normal file
111
src/Oms.Domain/FinanceAggregate/Consts/InvoiceCodes.cs
Normal 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";
|
||||
}
|
||||
@ -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; }
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
using Oms.Domain.Shared;
|
||||
using Oms.Domain.Shared.Enums;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Oms.Domain.FinanceAggregate.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// 公司收付款账户。
|
||||
/// </summary>
|
||||
[SugarTable("t_finance_company_account")]
|
||||
public class FinanceCompanyAccount : OmsAuditedAggregateRoot
|
||||
{
|
||||
[SugarColumn(Length = 128)]
|
||||
public string AccountName { get; set; } = string.Empty;
|
||||
|
||||
[SugarColumn(Length = 128)]
|
||||
public string BankName { get; set; } = string.Empty;
|
||||
|
||||
[SugarColumn(Length = 64)]
|
||||
public string AccountNo { get; set; } = string.Empty;
|
||||
|
||||
[SugarColumn(Length = 8)]
|
||||
public string Currency { get; set; } = "CNY";
|
||||
|
||||
public bool IsDefault { get; set; }
|
||||
|
||||
public EnableStatus Status { get; set; } = EnableStatus.Enabled;
|
||||
|
||||
[SugarColumn(Length = 512, IsNullable = true)]
|
||||
public string? Remark { get; set; }
|
||||
}
|
||||
85
src/Oms.Domain/FinanceAggregate/Entities/FinanceContract.cs
Normal file
85
src/Oms.Domain/FinanceAggregate/Entities/FinanceContract.cs
Normal file
@ -0,0 +1,85 @@
|
||||
using Oms.Domain.FinanceAggregate.Consts;
|
||||
using Oms.Domain.Shared;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Oms.Domain.FinanceAggregate.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// 财务合同(客户 / 供应商 / 代理)。
|
||||
/// </summary>
|
||||
[SugarTable("t_finance_contract")]
|
||||
public class FinanceContract : OmsAuditedAggregateRoot
|
||||
{
|
||||
[SugarColumn(Length = 32)]
|
||||
public string ContractNo { get; set; } = string.Empty;
|
||||
|
||||
[SugarColumn(Length = 128)]
|
||||
public string ContractName { get; set; } = string.Empty;
|
||||
|
||||
[SugarColumn(Length = 16)]
|
||||
public string PartyType { get; set; } = FinancePartyTypeCodes.Customer;
|
||||
|
||||
public int PartyId { get; set; }
|
||||
|
||||
[SugarColumn(Length = 128, IsNullable = true)]
|
||||
public string? OurEntityName { get; set; }
|
||||
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? SignDate { get; set; }
|
||||
|
||||
public DateTime EffectiveDate { get; set; }
|
||||
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? ExpireDate { get; set; }
|
||||
|
||||
public bool AutoRenew { get; set; }
|
||||
|
||||
[SugarColumn(Length = 16)]
|
||||
public string SettlementMethod { get; set; } = FinanceSettlementMethodCodes.Monthly;
|
||||
|
||||
public int PaymentTermDays { get; set; } = 30;
|
||||
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? BillingDay { get; set; }
|
||||
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? PaymentDay { get; set; }
|
||||
|
||||
[SugarColumn(Length = 8)]
|
||||
public string Currency { get; set; } = FinanceCurrencyCodes.Cny;
|
||||
|
||||
[SugarColumn(DecimalDigits = 2, IsNullable = true)]
|
||||
public decimal? CreditLimit { get; set; }
|
||||
|
||||
[SugarColumn(Length = 32, IsNullable = true)]
|
||||
public string? CommissionBaseType { get; set; }
|
||||
|
||||
[SugarColumn(DecimalDigits = 4, IsNullable = true)]
|
||||
public decimal? CommissionRate { get; set; }
|
||||
|
||||
public bool RequireVendorInvoice { get; set; }
|
||||
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? OwnerUserId { get; set; }
|
||||
|
||||
[SugarColumn(Length = 64, IsNullable = true)]
|
||||
public string? OwnerName { get; set; }
|
||||
|
||||
[SugarColumn(Length = 16)]
|
||||
public string Status { get; set; } = FinanceContractStatusCodes.Draft;
|
||||
|
||||
[SugarColumn(Length = 2048, IsNullable = true)]
|
||||
public string? AttachmentUrls { get; set; }
|
||||
|
||||
[SugarColumn(Length = 512, IsNullable = true)]
|
||||
public string? Remark { get; set; }
|
||||
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? RenewedFromId { get; set; }
|
||||
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? TerminatedTime { get; set; }
|
||||
|
||||
[SugarColumn(Length = 512, IsNullable = true)]
|
||||
public string? TerminateReason { get; set; }
|
||||
}
|
||||
@ -0,0 +1,80 @@
|
||||
using Oms.Domain.FinanceAggregate.Consts;
|
||||
using Oms.Domain.Shared;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Oms.Domain.FinanceAggregate.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// 付款申请头。
|
||||
/// </summary>
|
||||
[SugarTable("t_finance_payment_apply")]
|
||||
public class FinancePaymentApply : OmsAuditedAggregateRoot
|
||||
{
|
||||
[SugarColumn(Length = 32)]
|
||||
public string ApplyNo { get; set; } = string.Empty;
|
||||
|
||||
[SugarColumn(Length = 32)]
|
||||
public string PaymentType { get; set; } = FinancePaymentTypeCodes.Supplier;
|
||||
|
||||
[SugarColumn(Length = 16)]
|
||||
public string PayeeType { get; set; } = FinancePartyTypeCodes.Supplier;
|
||||
|
||||
public int PayeeId { get; set; }
|
||||
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? ContractId { get; set; }
|
||||
|
||||
[SugarColumn(Length = 8)]
|
||||
public string Currency { get; set; } = FinanceCurrencyCodes.Cny;
|
||||
|
||||
[SugarColumn(DecimalDigits = 2)]
|
||||
public decimal AmountTotal { get; set; }
|
||||
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? ExpectPayDate { get; set; }
|
||||
|
||||
[SugarColumn(Length = 128, IsNullable = true)]
|
||||
public string? PayeeAccountName { get; set; }
|
||||
|
||||
[SugarColumn(Length = 128, IsNullable = true)]
|
||||
public string? PayeeBankName { get; set; }
|
||||
|
||||
[SugarColumn(Length = 64, IsNullable = true)]
|
||||
public string? PayeeAccountNo { get; set; }
|
||||
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? CompanyAccountId { get; set; }
|
||||
|
||||
[SugarColumn(Length = 32)]
|
||||
public string Status { get; set; } = FinancePaymentStatusCodes.Draft;
|
||||
|
||||
[SugarColumn(Length = 64, IsNullable = true)]
|
||||
public string? ApplicantName { get; set; }
|
||||
|
||||
[SugarColumn(Length = 2048, IsNullable = true)]
|
||||
public string? AttachmentUrls { 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? PaidTime { get; set; }
|
||||
|
||||
[SugarColumn(Length = 64, IsNullable = true)]
|
||||
public string? BankTxnNo { get; set; }
|
||||
|
||||
[SugarColumn(Length = 64, IsNullable = true)]
|
||||
public string? PaidBy { get; set; }
|
||||
|
||||
[SugarColumn(Length = 1024, IsNullable = true)]
|
||||
public string? PaidVoucherUrl { get; set; }
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
using Oms.Domain.Shared;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Oms.Domain.FinanceAggregate.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// 付款申请明细。
|
||||
/// </summary>
|
||||
[SugarTable("t_finance_payment_apply_line")]
|
||||
public class FinancePaymentApplyLine : OmsAuditedAggregateRoot
|
||||
{
|
||||
public int PaymentApplyId { get; set; }
|
||||
|
||||
[SugarColumn(Length = 256)]
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
[SugarColumn(DecimalDigits = 2)]
|
||||
public decimal Amount { get; set; }
|
||||
|
||||
[SugarColumn(Length = 64, IsNullable = true)]
|
||||
public string? RefNo { get; set; }
|
||||
|
||||
[SugarColumn(Length = 512, IsNullable = true)]
|
||||
public string? Remark { get; set; }
|
||||
}
|
||||
44
src/Oms.Domain/FinanceAggregate/Entities/FinanceSupplier.cs
Normal file
44
src/Oms.Domain/FinanceAggregate/Entities/FinanceSupplier.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using Oms.Domain.Shared;
|
||||
using Oms.Domain.Shared.Enums;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Oms.Domain.FinanceAggregate.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// 财务供应商主数据。
|
||||
/// </summary>
|
||||
[SugarTable("t_finance_supplier")]
|
||||
public class FinanceSupplier : OmsAuditedAggregateRoot
|
||||
{
|
||||
[SugarColumn(Length = 32)]
|
||||
public string SupplierCode { get; set; } = string.Empty;
|
||||
|
||||
[SugarColumn(Length = 128)]
|
||||
public string SupplierName { get; set; } = string.Empty;
|
||||
|
||||
[SugarColumn(Length = 64, IsNullable = true)]
|
||||
public string? ContactName { get; set; }
|
||||
|
||||
[SugarColumn(Length = 32, IsNullable = true)]
|
||||
public string? Phone { get; set; }
|
||||
|
||||
[SugarColumn(Length = 128, IsNullable = true)]
|
||||
public string? Email { get; set; }
|
||||
|
||||
[SugarColumn(Length = 128, IsNullable = true)]
|
||||
public string? BankAccountName { get; set; }
|
||||
|
||||
[SugarColumn(Length = 128, IsNullable = true)]
|
||||
public string? BankName { get; set; }
|
||||
|
||||
[SugarColumn(Length = 64, IsNullable = true)]
|
||||
public string? BankAccountNo { get; set; }
|
||||
|
||||
[SugarColumn(Length = 8)]
|
||||
public string Currency { get; set; } = "CNY";
|
||||
|
||||
public EnableStatus Status { get; set; } = EnableStatus.Enabled;
|
||||
|
||||
[SugarColumn(Length = 512, IsNullable = true)]
|
||||
public string? Remark { get; set; }
|
||||
}
|
||||
82
src/Oms.Domain/FinanceAggregate/Entities/InvoiceApply.cs
Normal file
82
src/Oms.Domain/FinanceAggregate/Entities/InvoiceApply.cs
Normal 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; }
|
||||
}
|
||||
31
src/Oms.Domain/FinanceAggregate/Entities/InvoiceApplyLine.cs
Normal file
31
src/Oms.Domain/FinanceAggregate/Entities/InvoiceApplyLine.cs
Normal 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; }
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
using Fake.Domain.Repositories;
|
||||
using Oms.Domain.FinanceAggregate.Entities;
|
||||
|
||||
namespace Oms.Domain.FinanceAggregate.Repositories;
|
||||
|
||||
public interface ICustomerInvoiceProfileRepository : IRepository<CustomerInvoiceProfile>
|
||||
{
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
using Fake.Domain.Repositories;
|
||||
using Oms.Domain.FinanceAggregate.Entities;
|
||||
|
||||
namespace Oms.Domain.FinanceAggregate.Repositories;
|
||||
|
||||
public interface IFinanceSupplierRepository : IRepository<FinanceSupplier>
|
||||
{
|
||||
Task<bool> ExistsCodeAsync(string supplierCode, int? excludeId = null, CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
public interface IFinanceCompanyAccountRepository : IRepository<FinanceCompanyAccount>
|
||||
{
|
||||
}
|
||||
|
||||
public interface IFinanceContractRepository : IRepository<FinanceContract>
|
||||
{
|
||||
Task<bool> ExistsContractNoAsync(string contractNo, CancellationToken cancellationToken = default);
|
||||
|
||||
Task<FinanceContract?> GetActiveByPartyAsync(
|
||||
string partyType,
|
||||
int partyId,
|
||||
int? excludeId = null,
|
||||
CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
public interface IFinancePaymentApplyRepository : IRepository<FinancePaymentApply>
|
||||
{
|
||||
Task<bool> ExistsApplyNoAsync(string applyNo, CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
public interface IFinancePaymentApplyLineRepository : IRepository<FinancePaymentApplyLine>
|
||||
{
|
||||
Task<List<FinancePaymentApplyLine>> GetListByApplyIdAsync(
|
||||
int paymentApplyId,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
Task DeleteByApplyIdAsync(int paymentApplyId, CancellationToken cancellationToken = default);
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
@ -22,6 +22,12 @@ public static class OrderOperationActionCodes
|
||||
/// <summary>轨迹中心状态同步(TrackChange D03/D09/D11)。</summary>
|
||||
public const string TrackStatusSync = "trackStatusSync";
|
||||
|
||||
/// <summary>微信订单状态通知(模板消息)。</summary>
|
||||
public const string NotifyWechat = "notifyWechat";
|
||||
|
||||
/// <summary>邮件订单状态通知。</summary>
|
||||
public const string NotifyEmail = "notifyEmail";
|
||||
|
||||
public static string GetActionName(string action) => action switch
|
||||
{
|
||||
EditBasic => "编辑订单详情",
|
||||
@ -41,6 +47,8 @@ public static class OrderOperationActionCodes
|
||||
Outbound => "出库",
|
||||
ChangePostShipStatus => "修改出库后状态",
|
||||
TrackStatusSync => "轨迹状态同步",
|
||||
NotifyWechat => "微信通知",
|
||||
NotifyEmail => "邮件通知",
|
||||
_ => action
|
||||
};
|
||||
}
|
||||
|
||||
19
src/Oms.Domain/SystemAggregate/Consts/OrderNotifyChannels.cs
Normal file
19
src/Oms.Domain/SystemAggregate/Consts/OrderNotifyChannels.cs
Normal file
@ -0,0 +1,19 @@
|
||||
namespace Oms.Domain.SystemAggregate.Consts;
|
||||
|
||||
/// <summary>订单通知通道。</summary>
|
||||
public static class OrderNotifyChannels
|
||||
{
|
||||
public const string Wechat = "wechat";
|
||||
|
||||
public const string Email = "email";
|
||||
|
||||
public static bool IsKnown(string? channel) =>
|
||||
string.Equals(channel, Wechat, StringComparison.OrdinalIgnoreCase)
|
||||
|| string.Equals(channel, Email, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
public static string Normalize(string channel) =>
|
||||
string.Equals(channel, Email, StringComparison.OrdinalIgnoreCase) ? Email : Wechat;
|
||||
|
||||
public static string GetName(string channel) =>
|
||||
string.Equals(Normalize(channel), Email, StringComparison.OrdinalIgnoreCase) ? "邮件" : "微信";
|
||||
}
|
||||
@ -15,6 +15,9 @@ public class CustomerWechatNotifyPref : OmsAuditedAggregateRoot
|
||||
/// <summary>事件码。</summary>
|
||||
public string EventCode { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>是否订阅。</summary>
|
||||
/// <summary>是否订阅微信。</summary>
|
||||
public bool IsSubscribed { get; set; }
|
||||
|
||||
/// <summary>是否订阅邮件。</summary>
|
||||
public bool IsEmailSubscribed { get; set; }
|
||||
}
|
||||
|
||||
54
src/Oms.Domain/SystemAggregate/Entities/OrderNotifyLog.cs
Normal file
54
src/Oms.Domain/SystemAggregate/Entities/OrderNotifyLog.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using Oms.Domain.Shared;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Oms.Domain.SystemAggregate.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// 订单通知发送日志(微信 / 邮件统一表)。
|
||||
/// </summary>
|
||||
[SugarTable("t_order_notify_log")]
|
||||
public class OrderNotifyLog : OmsAuditedAggregateRoot
|
||||
{
|
||||
public int CustomerId { get; set; }
|
||||
|
||||
public int OrderId { get; set; }
|
||||
|
||||
/// <summary>wechat / email。</summary>
|
||||
[SugarColumn(Length = 16)]
|
||||
public string Channel { get; set; } = "wechat";
|
||||
|
||||
public string EventCode { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>OpenId 或收件邮箱。</summary>
|
||||
[SugarColumn(IsNullable = true, Length = 256)]
|
||||
public string? Recipient { get; set; }
|
||||
|
||||
/// <summary>微信 TemplateId 或邮件模板名。</summary>
|
||||
[SugarColumn(IsNullable = true, Length = 128)]
|
||||
public string? TemplateRef { get; set; }
|
||||
|
||||
/// <summary>邮件主题(微信可空)。</summary>
|
||||
[SugarColumn(IsNullable = true, Length = 512)]
|
||||
public string? Subject { get; set; }
|
||||
|
||||
/// <summary>sent / failed / skipped。</summary>
|
||||
[SugarColumn(Length = 16)]
|
||||
public string Status { get; set; } = "skipped";
|
||||
|
||||
/// <summary>微信 msgid 等通道回执。</summary>
|
||||
[SugarColumn(IsNullable = true, Length = 64)]
|
||||
public string? ProviderMsgId { get; set; }
|
||||
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? ErrCode { get; set; }
|
||||
|
||||
[SugarColumn(IsNullable = true, Length = 512)]
|
||||
public string? ErrMsg { get; set; }
|
||||
|
||||
/// <summary>发件 SMTP 账号(邮件)。</summary>
|
||||
[SugarColumn(IsNullable = true, Length = 256)]
|
||||
public string? SmtpUsername { get; set; }
|
||||
|
||||
[SugarColumn(ColumnDataType = "text", IsNullable = true)]
|
||||
public string? PayloadJson { get; set; }
|
||||
}
|
||||
@ -1,38 +0,0 @@
|
||||
using Oms.Domain.Shared;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Oms.Domain.SystemAggregate.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// 微信订单通知发送日志。
|
||||
/// </summary>
|
||||
[SugarTable("t_wechat_notify_log")]
|
||||
public class WechatNotifyLog : OmsAuditedAggregateRoot
|
||||
{
|
||||
public int CustomerId { get; set; }
|
||||
|
||||
public int OrderId { get; set; }
|
||||
|
||||
public string EventCode { get; set; } = string.Empty;
|
||||
|
||||
[SugarColumn(IsNullable = true, Length = 64)]
|
||||
public string? OpenId { get; set; }
|
||||
|
||||
[SugarColumn(IsNullable = true, Length = 128)]
|
||||
public string? TemplateId { get; set; }
|
||||
|
||||
/// <summary>sent / failed / skipped。</summary>
|
||||
public string Status { get; set; } = "skipped";
|
||||
|
||||
[SugarColumn(IsNullable = true, Length = 64)]
|
||||
public string? WxMsgId { get; set; }
|
||||
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? ErrCode { get; set; }
|
||||
|
||||
[SugarColumn(IsNullable = true, Length = 512)]
|
||||
public string? ErrMsg { get; set; }
|
||||
|
||||
[SugarColumn(ColumnDataType = "text", IsNullable = true)]
|
||||
public string? PayloadJson { get; set; }
|
||||
}
|
||||
@ -27,9 +27,24 @@ public class WechatNotifyTemplate : OmsAuditedAggregateRoot
|
||||
[SugarColumn(ColumnDataType = "text", IsNullable = true)]
|
||||
public string? FieldMappingJson { get; set; }
|
||||
|
||||
/// <summary>是否启用。</summary>
|
||||
/// <summary>是否启用微信推送。</summary>
|
||||
public bool IsEnabled { get; set; }
|
||||
|
||||
/// <summary>是否启用邮件通知。</summary>
|
||||
public bool EmailEnabled { get; set; }
|
||||
|
||||
/// <summary>关联的 batch-email 模板名称。</summary>
|
||||
[SugarColumn(IsNullable = true, Length = 128)]
|
||||
public string? EmailTemplateName { get; set; }
|
||||
|
||||
/// <summary>batch-email 模板所属用户。</summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? EmailTemplateOwnerUserId { get; set; }
|
||||
|
||||
/// <summary>发信 SMTP 所属用户;0 表示系统发信账号。</summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? EmailSmtpOwnerUserId { get; set; }
|
||||
|
||||
/// <summary>备注。</summary>
|
||||
[SugarColumn(IsNullable = true, Length = 512)]
|
||||
public string? Remark { get; set; }
|
||||
|
||||
@ -0,0 +1,24 @@
|
||||
using Fake.Domain.Repositories;
|
||||
using Oms.Domain.SystemAggregate.Entities;
|
||||
|
||||
namespace Oms.Domain.SystemAggregate.Repositories;
|
||||
|
||||
public interface IOrderNotifyLogRepository : IRepository<OrderNotifyLog>
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否存在近期同订单同事件同通道的成功发送(用于去重;不含 failed)。
|
||||
/// </summary>
|
||||
Task<bool> ExistsRecentSentAsync(
|
||||
int orderId,
|
||||
string eventCode,
|
||||
string channel,
|
||||
DateTime since,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// 按订单查询通知日志(时间倒序)。
|
||||
/// </summary>
|
||||
Task<List<OrderNotifyLog>> ListByOrderIdAsync(
|
||||
int orderId,
|
||||
CancellationToken cancellationToken = default);
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
using Fake.Domain.Repositories;
|
||||
using Oms.Domain.SystemAggregate.Entities;
|
||||
|
||||
namespace Oms.Domain.SystemAggregate.Repositories;
|
||||
|
||||
public interface IWechatNotifyLogRepository : IRepository<WechatNotifyLog>
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否存在近期同订单同事件的成功/进行中记录(用于去重)。
|
||||
/// </summary>
|
||||
Task<bool> ExistsRecentAsync(
|
||||
int orderId,
|
||||
string eventCode,
|
||||
DateTime since,
|
||||
CancellationToken cancellationToken = default);
|
||||
}
|
||||
@ -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
|
||||
{
|
||||
}
|
||||
91
src/Oms.SqlSugarCore/Finance/FinanceContractRepositories.cs
Normal file
91
src/Oms.SqlSugarCore/Finance/FinanceContractRepositories.cs
Normal file
@ -0,0 +1,91 @@
|
||||
using Fake.DependencyInjection;
|
||||
using Oms.Domain.FinanceAggregate.Consts;
|
||||
using Oms.Domain.FinanceAggregate.Entities;
|
||||
using Oms.Domain.FinanceAggregate.Repositories;
|
||||
using Oms.SqlSugarCore.Repositories;
|
||||
|
||||
namespace Oms.SqlSugarCore.Finance;
|
||||
|
||||
public class FinanceSupplierRepository
|
||||
: OmsSqlSugarRepository<FinanceSupplier>, IFinanceSupplierRepository, IScopedDependency
|
||||
{
|
||||
public async Task<bool> ExistsCodeAsync(
|
||||
string supplierCode,
|
||||
int? excludeId = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var code = supplierCode.Trim();
|
||||
if (excludeId is > 0)
|
||||
{
|
||||
return await AnyAsync(x => x.SupplierCode == code && x.Id != excludeId.Value, cancellationToken);
|
||||
}
|
||||
|
||||
return await AnyAsync(x => x.SupplierCode == code, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
public class FinanceCompanyAccountRepository
|
||||
: OmsSqlSugarRepository<FinanceCompanyAccount>, IFinanceCompanyAccountRepository, IScopedDependency
|
||||
{
|
||||
}
|
||||
|
||||
public class FinanceContractRepository
|
||||
: OmsSqlSugarRepository<FinanceContract>, IFinanceContractRepository, IScopedDependency
|
||||
{
|
||||
public Task<bool> ExistsContractNoAsync(string contractNo, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return AnyAsync(x => x.ContractNo == contractNo, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<FinanceContract?> GetActiveByPartyAsync(
|
||||
string partyType,
|
||||
int partyId,
|
||||
int? excludeId = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (excludeId is > 0)
|
||||
{
|
||||
return await FirstOrDefaultAsync(
|
||||
x => x.PartyType == partyType
|
||||
&& x.PartyId == partyId
|
||||
&& x.Status == FinanceContractStatusCodes.Active
|
||||
&& x.Id != excludeId.Value,
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
return await FirstOrDefaultAsync(
|
||||
x => x.PartyType == partyType
|
||||
&& x.PartyId == partyId
|
||||
&& x.Status == FinanceContractStatusCodes.Active,
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
public class FinancePaymentApplyRepository
|
||||
: OmsSqlSugarRepository<FinancePaymentApply>, IFinancePaymentApplyRepository, IScopedDependency
|
||||
{
|
||||
public Task<bool> ExistsApplyNoAsync(string applyNo, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return AnyAsync(x => x.ApplyNo == applyNo, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
public class FinancePaymentApplyLineRepository
|
||||
: OmsSqlSugarRepository<FinancePaymentApplyLine>, IFinancePaymentApplyLineRepository, IScopedDependency
|
||||
{
|
||||
public Task<List<FinancePaymentApplyLine>> GetListByApplyIdAsync(
|
||||
int paymentApplyId,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
return GetListAsync(x => x.PaymentApplyId == paymentApplyId, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
public async Task DeleteByApplyIdAsync(int paymentApplyId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var lines = await GetListByApplyIdAsync(paymentApplyId, cancellationToken);
|
||||
foreach (var line in lines)
|
||||
{
|
||||
await DeleteAsync(line, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/Oms.SqlSugarCore/Finance/InvoiceApplyLineRepository.cs
Normal file
17
src/Oms.SqlSugarCore/Finance/InvoiceApplyLineRepository.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
20
src/Oms.SqlSugarCore/Finance/InvoiceApplyRepository.cs
Normal file
20
src/Oms.SqlSugarCore/Finance/InvoiceApplyRepository.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
41
src/Oms.SqlSugarCore/System/OrderNotifyLogRepository.cs
Normal file
41
src/Oms.SqlSugarCore/System/OrderNotifyLogRepository.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using Fake.DependencyInjection;
|
||||
using Oms.Domain.SystemAggregate.Entities;
|
||||
using Oms.Domain.SystemAggregate.Repositories;
|
||||
using Oms.SqlSugarCore.Repositories;
|
||||
|
||||
namespace Oms.SqlSugarCore.System;
|
||||
|
||||
public class OrderNotifyLogRepository
|
||||
: OmsSqlSugarRepository<OrderNotifyLog>,
|
||||
IOrderNotifyLogRepository,
|
||||
IScopedDependency
|
||||
{
|
||||
public async Task<bool> ExistsRecentSentAsync(
|
||||
int orderId,
|
||||
string eventCode,
|
||||
string channel,
|
||||
DateTime since,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var code = eventCode.Trim();
|
||||
var ch = channel.Trim();
|
||||
return await AnyAsync(
|
||||
x => x.OrderId == orderId
|
||||
&& x.EventCode == code
|
||||
&& x.Channel == ch
|
||||
&& x.CreateTime >= since
|
||||
&& x.Status == "sent",
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<List<OrderNotifyLog>> ListByOrderIdAsync(
|
||||
int orderId,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var list = await GetListAsync(x => x.OrderId == orderId, cancellationToken: cancellationToken);
|
||||
return list
|
||||
.OrderByDescending(x => x.CreateTime)
|
||||
.ThenByDescending(x => x.Id)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
using Fake.DependencyInjection;
|
||||
using Oms.Domain.SystemAggregate.Entities;
|
||||
using Oms.Domain.SystemAggregate.Repositories;
|
||||
using Oms.SqlSugarCore.Repositories;
|
||||
|
||||
namespace Oms.SqlSugarCore.System;
|
||||
|
||||
public class WechatNotifyLogRepository
|
||||
: OmsSqlSugarRepository<WechatNotifyLog>,
|
||||
IWechatNotifyLogRepository,
|
||||
IScopedDependency
|
||||
{
|
||||
public async Task<bool> ExistsRecentAsync(
|
||||
int orderId,
|
||||
string eventCode,
|
||||
DateTime since,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var code = eventCode.Trim();
|
||||
return await AnyAsync(
|
||||
x => x.OrderId == orderId
|
||||
&& x.EventCode == code
|
||||
&& x.CreateTime >= since
|
||||
&& (x.Status == "sent" || x.Status == "failed"),
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user