更新密码找回uniapp
This commit is contained in:
1 parent
7f9a66da0f
commit
3fdda89833
1304 files changed
+3503
-26132
No files matched your search
@@ -20,7 +20,6 @@ import (
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// BackendReimburseController 报销及审批接口。
|
||||
type BackendReimburseController struct {
|
||||
beego.Controller
|
||||
}
|
||||
@@ -89,8 +88,6 @@ func (c *BackendReimburseController) getID() (uint64, bool) {
|
||||
return id, err == nil && id > 0
|
||||
}
|
||||
|
||||
// findOwnedReimbursement 按 id + 租户 + 申请人 查询本人报销单(未删除)。
|
||||
// 报销单为个人单据:与列表口径一致,按 JWT 中 tid + user_id 双重隔离。
|
||||
func findOwnedReimbursement(claims *jwtutil.Claims, id uint64) (*models.BackendReimbursement, error) {
|
||||
row := &models.BackendReimbursement{}
|
||||
err := models.Orm.QueryTable(new(models.BackendReimbursement)).
|
||||
@@ -191,8 +188,6 @@ func remapReceiptAmounts(oldIDs []uint64, oldAmounts []string, newIDs []uint64)
|
||||
return joinReceiptAmounts(parts)
|
||||
}
|
||||
|
||||
// normalizeReceiptURLs 规范化逗号分隔的票据地址(历史七牛 HTTP 域名改写为存储配置入口),
|
||||
// 保证 HTTPS 页面不会因 Mixed Content 拦截发票预览。
|
||||
func normalizeReceiptURLs(scheme, host, raw string) string {
|
||||
if strings.TrimSpace(raw) == "" {
|
||||
return ""
|
||||
@@ -352,7 +347,6 @@ func reimbursementDTO(row models.BackendReimbursement, items []models.BackendRei
|
||||
return result
|
||||
}
|
||||
|
||||
// List GET /backend/reimbursements
|
||||
func (c *BackendReimburseController) List() {
|
||||
claims, ok := c.claims()
|
||||
if !ok {
|
||||
@@ -363,7 +357,6 @@ func (c *BackendReimburseController) List() {
|
||||
pageSize, _ := c.GetInt("pageSize", 10)
|
||||
keyword := strings.TrimSpace(c.GetString("keyword"))
|
||||
status, statusErr := c.GetInt("status")
|
||||
// 列表 tab:all(不传)/ unpaid(未报销)/ paid(已报销)
|
||||
reimbursed := strings.TrimSpace(c.GetString("reimbursed"))
|
||||
|
||||
data, code, msg := reimburseListData(claims, page, pageSize, keyword, statusErr == nil, status, reimbursed)
|
||||
@@ -374,9 +367,6 @@ func (c *BackendReimburseController) List() {
|
||||
c.reply(200, "success", data)
|
||||
}
|
||||
|
||||
// reimburseListData 报销单列表共享逻辑:Web 后台与移动端(/api/oa/expense/list)共用。
|
||||
// reimbursed 供 Web 列表的「全部/未报销/已报销」tab 使用,移动端传空串保持原行为。
|
||||
// 返回 (数据, HTTP 状态码, 错误信息),错误信息为空串表示成功。
|
||||
func reimburseListData(claims *jwtutil.Claims, page, pageSize int, keyword string, hasStatus bool, status int, reimbursed string) (map[string]interface{}, int, string) {
|
||||
if page < 1 {
|
||||
page = 1
|
||||
@@ -388,8 +378,6 @@ func reimburseListData(claims *jwtutil.Claims, page, pageSize int, keyword strin
|
||||
qs := models.Orm.QueryTable(new(models.BackendReimbursement)).
|
||||
Filter("tid", claims.TenantId).Filter("user_id", claims.UserID).Filter("is_deleted", 0)
|
||||
|
||||
// 待我审批(status=-1 约定值):审批人视角,切换为「我名下运行中实例的待办单据」
|
||||
// 查询(yz_approval_task.approver_id=当前用户),不再按创建人 user_id 过滤
|
||||
mineOnly := hasStatus && status == -1
|
||||
if mineOnly {
|
||||
hasStatus = false
|
||||
@@ -420,9 +408,6 @@ func reimburseListData(claims *jwtutil.Claims, page, pageSize int, keyword strin
|
||||
if keyword != "" {
|
||||
qs = qs.Filter("description__icontains", keyword)
|
||||
}
|
||||
// 「全部 / 未报销 / 已报销」:已通过(2) + 已打款(5) 算已报销,
|
||||
// 草稿/审批中/已驳回/已撤回算未报销,口径与 dashboard 的 paid/unpaid 一致。
|
||||
// 用 status__in 明确枚举,避免 Exclude 对 NULL 或新增状态的歧义;可与 status 精确筛选叠加。
|
||||
reimbursedStatuses := []int8{reimbursementStatusApproved, reimbursementStatusPaid}
|
||||
unreimbursedStatuses := []int8{
|
||||
reimbursementStatusDraft, reimbursementStatusApproving,
|
||||
@@ -451,7 +436,6 @@ func reimburseListData(claims *jwtutil.Claims, page, pageSize int, keyword strin
|
||||
}
|
||||
list := make([]map[string]interface{}, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
// 审批已结束但业务状态未及时回写时,读取即自愈
|
||||
row.Status = syncReimburseStatusFromInstance(&row)
|
||||
list = append(list, map[string]interface{}{
|
||||
"id": row.ID,
|
||||
@@ -472,7 +456,6 @@ func reimburseListData(claims *jwtutil.Claims, page, pageSize int, keyword strin
|
||||
return map[string]interface{}{"list": list, "total": total}, 200, ""
|
||||
}
|
||||
|
||||
// Detail GET /backend/reimbursements/:id
|
||||
func (c *BackendReimburseController) Detail() {
|
||||
claims, ok := c.claims()
|
||||
if !ok {
|
||||
@@ -493,29 +476,22 @@ func (c *BackendReimburseController) Detail() {
|
||||
c.reply(200, "success", data)
|
||||
}
|
||||
|
||||
// reimburseDetailData 报销单详情共享逻辑(主单 + 明细 + 发票文件)。
|
||||
func reimburseDetailData(claims *jwtutil.Claims, id uint64, scheme, host string) (map[string]interface{}, int, string) {
|
||||
row, err := findOwnedReimbursement(claims, id)
|
||||
if err != nil {
|
||||
return nil, 404, "报销单不存在"
|
||||
}
|
||||
var items []models.BackendReimbursementItem
|
||||
// 只按 reimbursement_id 查明细:主单已按 tid + 申请人校验过。
|
||||
// 历史单据存在明细 tid 与主单不一致的情况,再按 tid 过滤会导致明细「消失」。
|
||||
_, err = models.Orm.QueryTable(new(models.BackendReimbursementItem)).
|
||||
Filter("reimbursement_id", id).Filter("is_deleted", 0).
|
||||
OrderBy("id").All(&items)
|
||||
if err != nil && err != orm.ErrNoRows {
|
||||
return nil, 500, "查询明细失败: " + err.Error()
|
||||
}
|
||||
// 审批已结束但业务状态未及时回写时,读取即自愈
|
||||
row.Status = syncReimburseStatusFromInstance(row)
|
||||
return reimbursementDTO(*row, items, scheme, host), 200, ""
|
||||
}
|
||||
|
||||
// syncReimburseStatusFromInstance 报销单状态自愈:单据处于「审批中」时,
|
||||
// 按审批引擎中对应实例(biz_type=reimburse)的最终态回写业务状态。
|
||||
// 用于兜底引擎回写异常/历史数据,列表与详情读取时调用,无变化时原样返回。
|
||||
func syncReimburseStatusFromInstance(row *models.BackendReimbursement) int8 {
|
||||
if row == nil {
|
||||
return 0
|
||||
@@ -539,9 +515,6 @@ func syncReimburseStatusFromInstance(row *models.BackendReimbursement) int8 {
|
||||
return row.Status
|
||||
}
|
||||
|
||||
// findReimburseInstance 查报销单对应的审批实例。
|
||||
// 兼容两种 biz_type 写法(reimburse / 早期的 oa),并按 tid、biz_tid 依次匹配,
|
||||
// 这样租户侧与平台侧产生的实例都能找到。
|
||||
func findReimburseInstance(tid, bizID uint64) (*models.ApprovalInstance, bool) {
|
||||
if tid == 0 || bizID == 0 {
|
||||
return nil, false
|
||||
@@ -560,7 +533,6 @@ func findReimburseInstance(tid, bizID uint64) (*models.ApprovalInstance, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// Create POST /backend/reimbursements
|
||||
func (c *BackendReimburseController) Create() {
|
||||
claims, ok := c.claims()
|
||||
if !ok {
|
||||
@@ -580,11 +552,6 @@ func (c *BackendReimburseController) Create() {
|
||||
c.reply(200, "success", map[string]interface{}{"id": id})
|
||||
}
|
||||
|
||||
// reimburseCreateCore 创建报销单(草稿)共享逻辑。
|
||||
//
|
||||
// 创建只落草稿:不接受客户端传入的状态,也不启动审批流程。
|
||||
// 提交审批必须由用户显式调用 Submit(Web 端为列表操作栏的「提交审核」),
|
||||
// 在此之前草稿可反复编辑,满足周期性报销多次修改的需求。
|
||||
func reimburseCreateCore(claims *jwtutil.Claims, payload reimbursementPayload) (uint64, int, string) {
|
||||
applyDate, err := parseReimburseDate(payload.ApplyDate)
|
||||
if err != nil {
|
||||
@@ -603,7 +570,6 @@ func reimburseCreateCore(claims *jwtutil.Claims, payload reimbursementPayload) (
|
||||
return row.ID, 200, ""
|
||||
}
|
||||
|
||||
// Update POST /backend/reimbursements/:id
|
||||
func (c *BackendReimburseController) Update() {
|
||||
claims, ok := c.claims()
|
||||
if !ok {
|
||||
@@ -628,7 +594,6 @@ func (c *BackendReimburseController) Update() {
|
||||
c.reply(200, "success", map[string]interface{}{"id": id})
|
||||
}
|
||||
|
||||
// reimburseUpdateCore 编辑报销单(草稿/已驳回/已撤回)共享逻辑。
|
||||
func reimburseUpdateCore(claims *jwtutil.Claims, id uint64, payload reimbursementPayload) (int, string) {
|
||||
row, err := findOwnedReimbursement(claims, id)
|
||||
if err != nil {
|
||||
@@ -648,7 +613,6 @@ func reimburseUpdateCore(claims *jwtutil.Claims, id uint64, payload reimbursemen
|
||||
return 200, ""
|
||||
}
|
||||
|
||||
// Delete DELETE /backend/reimbursements/:id
|
||||
func (c *BackendReimburseController) Delete() {
|
||||
claims, ok := c.claims()
|
||||
if !ok {
|
||||
@@ -668,7 +632,6 @@ func (c *BackendReimburseController) Delete() {
|
||||
c.reply(200, "success", nil)
|
||||
}
|
||||
|
||||
// reimburseDeleteCore 删除报销单(仅草稿,连明细一起软删)共享逻辑。
|
||||
func reimburseDeleteCore(claims *jwtutil.Claims, id uint64) (int, string) {
|
||||
row, err := findOwnedReimbursement(claims, id)
|
||||
if err != nil {
|
||||
@@ -703,9 +666,6 @@ func (c *BackendReimburseController) getItemID() (uint64, bool) {
|
||||
return id, err == nil && id > 0
|
||||
}
|
||||
|
||||
// findOwnedReimbursementItem 查询本人报销单下的费用明细(包级共享,移动端复用)。
|
||||
// 主单归属已由 ensureEditableReimbursement 按 tid + 申请人校验,这里只按
|
||||
// id + reimbursement_id 定位,避免历史明细 tid/uid 不一致时无法编辑。
|
||||
func findOwnedReimbursementItem(_ *jwtutil.Claims, id, reimbursementID uint64) (*models.BackendReimbursementItem, error) {
|
||||
item := &models.BackendReimbursementItem{}
|
||||
err := models.Orm.QueryTable(new(models.BackendReimbursementItem)).
|
||||
@@ -730,37 +690,21 @@ func validateReimbursementItem(item reimbursementItemPayload) (time.Time, error)
|
||||
return date, nil
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 发票挂靠
|
||||
|
||||
// invoicePoolEntry 发票池中的一张票(按附件文件 ID 聚合)。
|
||||
type invoicePoolEntry struct {
|
||||
FileID uint64
|
||||
Name string
|
||||
URL string
|
||||
ExpenseDate string
|
||||
Amount float64 // 票面金额(receipt_amounts)
|
||||
UsedAmount float64 // 已被各明细占用的金额
|
||||
Amount float64
|
||||
UsedAmount float64
|
||||
SourceItemID uint64
|
||||
SourceReimbursementID uint64
|
||||
}
|
||||
|
||||
// collectInvoicePool 聚合「当前报销单」内的发票及余额。
|
||||
//
|
||||
// 边界:只能挂靠本报销单里上传过的发票,不跨单据、不跨用户。
|
||||
// 口径:
|
||||
// - 票面金额取「上传该票的明细行」receipt_amounts 对应值(OCR 或人工填写);
|
||||
// - 上传发票的明细按「明细金额 / 该行发票张数」自动占用额度,保证一条明细
|
||||
// 上传多张票时不会被重复占用;
|
||||
// - 本单其它明细通过 invoice_file_id + invoice_use_amount 显式挂靠,累加占用;
|
||||
// - 余额 = 票面 - 占用。明细删除(软删)后占用自动释放,无需额外回滚。
|
||||
//
|
||||
// excludeItemID 用于编辑某条明细时排除它自身的占用,得到「本单其它明细用完后
|
||||
// 还剩多少可挂靠」。
|
||||
func collectInvoicePool(claims *jwtutil.Claims, reimbursementID, excludeItemID uint64) ([]invoicePoolEntry, error) {
|
||||
if reimbursementID == 0 {
|
||||
return []invoicePoolEntry{}, nil
|
||||
}
|
||||
// 归属校验:只允许访问本人的报销单(tid + user_id + 未删除)
|
||||
if _, err := findOwnedReimbursement(claims, reimbursementID); err != nil {
|
||||
return nil, fmt.Errorf("报销单不存在")
|
||||
}
|
||||
@@ -811,7 +755,6 @@ func collectInvoicePool(claims *jwtutil.Claims, reimbursementID, excludeItemID u
|
||||
if row.ID == excludeItemID || row.InvoiceFileID == 0 || row.InvoiceUseAmount <= 0 {
|
||||
continue
|
||||
}
|
||||
// 自己上传的票已按明细金额算过宿主占用,不重复累计
|
||||
selfUploaded := false
|
||||
for _, id := range parseReceiptFileIDs(row.ReceiptFileIDs) {
|
||||
if id == row.InvoiceFileID {
|
||||
@@ -827,7 +770,6 @@ func collectInvoicePool(claims *jwtutil.Claims, reimbursementID, excludeItemID u
|
||||
}
|
||||
}
|
||||
|
||||
// 一次性补齐文件名,避免逐票查询
|
||||
ids := make([]uint64, 0, len(pool))
|
||||
for id := range pool {
|
||||
ids = append(ids, id)
|
||||
@@ -861,10 +803,7 @@ func collectInvoicePool(claims *jwtutil.Claims, reimbursementID, excludeItemID u
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// validateInvoiceLink 校验挂靠是否合法:只能挂靠当前报销单里上传的发票,
|
||||
// 且票面金额已维护、余额充足、本次使用额不超过明细金额。
|
||||
func validateInvoiceLink(claims *jwtutil.Claims, payload reimbursementItemPayload, reimbursementID, excludeItemID uint64) (int, string) {
|
||||
// 未带挂靠字段(上传发票 / 保存票面金额等)表示不改挂靠关系,直接放行
|
||||
if payload.InvoiceFileID == nil {
|
||||
return 200, ""
|
||||
}
|
||||
@@ -882,13 +821,11 @@ func validateInvoiceLink(claims *jwtutil.Claims, payload reimbursementItemPayloa
|
||||
if useAmount > payload.Amount+0.005 {
|
||||
return 400, "挂靠金额不能超过本条费用明细金额"
|
||||
}
|
||||
// 本行已经上传这张票时无需再挂靠:宿主明细本身已按明细金额占用额度
|
||||
for _, id := range parseReceiptFileIDs(payload.ReceiptFileIDs) {
|
||||
if id == fileID {
|
||||
return 400, "本条明细已上传该发票,无需重复挂靠"
|
||||
}
|
||||
}
|
||||
// 发票池只取本报销单的明细,因此天然挡住跨单据 / 跨用户挂靠
|
||||
pool, err := collectInvoicePool(claims, reimbursementID, excludeItemID)
|
||||
if err != nil {
|
||||
return 400, "报销单不存在或无法读取发票信息"
|
||||
@@ -909,8 +846,6 @@ func validateInvoiceLink(claims *jwtutil.Claims, payload reimbursementItemPayloa
|
||||
return 400, "该发票不属于当前报销单,或已无余额;请取消挂靠后选择本单上传的发票"
|
||||
}
|
||||
|
||||
// AvailableInvoices GET /backend/reimbursements/invoices/available?reimbursement_id=
|
||||
// 返回「当前报销单」内仍有余额、可供挂靠的发票;其它报销单的发票一律不可见。
|
||||
func (c *BackendReimburseController) AvailableInvoices() {
|
||||
claims, ok := c.claims()
|
||||
if !ok {
|
||||
@@ -954,10 +889,6 @@ func (c *BackendReimburseController) AvailableInvoices() {
|
||||
c.reply(200, "success", map[string]interface{}{"list": list})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 发票挂靠结束
|
||||
|
||||
// canEditReimbursement 可编辑状态:草稿、已驳回、已撤回。
|
||||
// 审批中需先撤回;已通过/已打款不可编辑,保证审批结果与打款金额不被改动。
|
||||
func canEditReimbursement(status int8) bool {
|
||||
switch status {
|
||||
case reimbursementStatusDraft, reimbursementStatusRejected, reimbursementStatusWithdrawn:
|
||||
@@ -966,8 +897,6 @@ func canEditReimbursement(status int8) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// resolveReimburseUserName 按 identity_id 解析姓名:
|
||||
// 认证中心企业绑定表 → 身份表 → 老租户用户表。历史令牌/导入数据可能缺映射,逐级兜底。
|
||||
func resolveReimburseUserName(tid, userID uint64) string {
|
||||
if userID == 0 {
|
||||
return ""
|
||||
@@ -1008,8 +937,6 @@ func resolveReimburseUserName(tid, userID uint64) string {
|
||||
return strings.TrimSpace(account)
|
||||
}
|
||||
|
||||
// reimburseActorName 审批时间线的操作人名称:
|
||||
// 优先令牌中的 username,缺失时回落到认证中心/租户用户表。
|
||||
func reimburseActorName(tid uint64, claims *jwtutil.Claims) string {
|
||||
if claims == nil {
|
||||
return "系统"
|
||||
@@ -1023,8 +950,6 @@ func reimburseActorName(tid uint64, claims *jwtutil.Claims) string {
|
||||
return "系统"
|
||||
}
|
||||
|
||||
// ensureEditableReimbursement 校验报销单存在且处于可编辑状态(包级共享,移动端复用)。
|
||||
// 返回 (报销单, HTTP 状态码, 错误信息),错误信息为空串表示通过。
|
||||
func ensureEditableReimbursement(claims *jwtutil.Claims, id uint64) (*models.BackendReimbursement, int, string) {
|
||||
row, err := findOwnedReimbursement(claims, id)
|
||||
if err != nil {
|
||||
@@ -1055,7 +980,6 @@ func recalculateReimbursementTotal(id uint64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// AddItem POST /backend/reimbursements/:id/items
|
||||
func (c *BackendReimburseController) AddItem() {
|
||||
claims, ok := c.claims()
|
||||
if !ok {
|
||||
@@ -1081,7 +1005,6 @@ func (c *BackendReimburseController) AddItem() {
|
||||
c.reply(200, "success", item)
|
||||
}
|
||||
|
||||
// reimburseAddItemCore 新增费用明细共享逻辑(仅草稿;自动重算报销总额)。
|
||||
func reimburseAddItemCore(claims *jwtutil.Claims, reimbursementID uint64, payload reimbursementItemPayload, scheme, host string) (map[string]interface{}, int, string) {
|
||||
if _, _, msg := ensureEditableReimbursement(claims, reimbursementID); msg != "" {
|
||||
code := 400
|
||||
@@ -1130,7 +1053,6 @@ func reimburseAddItemCore(claims *jwtutil.Claims, reimbursementID uint64, payloa
|
||||
return reimbursementItemDTO(*item, scheme, host), 200, ""
|
||||
}
|
||||
|
||||
// UpdateItem POST /backend/reimbursements/:id/items/:item_id
|
||||
func (c *BackendReimburseController) UpdateItem() {
|
||||
claims, ok := c.claims()
|
||||
if !ok {
|
||||
@@ -1161,7 +1083,6 @@ func (c *BackendReimburseController) UpdateItem() {
|
||||
c.reply(200, "success", item)
|
||||
}
|
||||
|
||||
// reimburseUpdateItemCore 更新费用明细共享逻辑(仅草稿;自动重算报销总额)。
|
||||
func reimburseUpdateItemCore(claims *jwtutil.Claims, reimbursementID, itemID uint64, payload reimbursementItemPayload, scheme, host string) (map[string]interface{}, int, string) {
|
||||
if _, _, msg := ensureEditableReimbursement(claims, reimbursementID); msg != "" {
|
||||
code := 400
|
||||
@@ -1215,7 +1136,6 @@ func reimburseUpdateItemCore(claims *jwtutil.Claims, reimbursementID, itemID uin
|
||||
return reimbursementItemDTO(*item, scheme, host), 200, ""
|
||||
}
|
||||
|
||||
// DeleteItem DELETE /backend/reimbursements/:id/items/:item_id
|
||||
func (c *BackendReimburseController) DeleteItem() {
|
||||
claims, ok := c.claims()
|
||||
if !ok {
|
||||
@@ -1240,7 +1160,6 @@ func (c *BackendReimburseController) DeleteItem() {
|
||||
c.reply(200, "success", nil)
|
||||
}
|
||||
|
||||
// reimburseDeleteItemCore 删除费用明细共享逻辑(仅草稿;自动重算报销总额)。
|
||||
func reimburseDeleteItemCore(claims *jwtutil.Claims, reimbursementID, itemID uint64) (int, string) {
|
||||
if _, _, msg := ensureEditableReimbursement(claims, reimbursementID); msg != "" {
|
||||
if msg == "报销单不存在" {
|
||||
@@ -1264,7 +1183,6 @@ func reimburseDeleteItemCore(claims *jwtutil.Claims, reimbursementID, itemID uin
|
||||
return 200, ""
|
||||
}
|
||||
|
||||
// Submit POST /backend/reimbursements/:id/submit
|
||||
func (c *BackendReimburseController) Submit() {
|
||||
claims, ok := c.claims()
|
||||
if !ok {
|
||||
@@ -1284,10 +1202,6 @@ func (c *BackendReimburseController) Submit() {
|
||||
c.reply(200, "success", nil)
|
||||
}
|
||||
|
||||
// Withdraw POST /backend/reimbursements/:id/withdraw
|
||||
//
|
||||
// 报销人撤回审批中的单据:撤掉运行中的审批实例,并把单据退回草稿,
|
||||
// 撤回后可在详情继续编辑费用条目,确认无误后再次提交审核。
|
||||
func (c *BackendReimburseController) Withdraw() {
|
||||
claims, ok := c.claims()
|
||||
if !ok {
|
||||
@@ -1307,10 +1221,6 @@ func (c *BackendReimburseController) Withdraw() {
|
||||
c.reply(200, "success", nil)
|
||||
}
|
||||
|
||||
// reimburseWithdrawCore 撤回审批中的报销单并退回草稿。
|
||||
//
|
||||
// 与「审批中心」的发起人撤回一致:运行中的实例置为已撤回、待办任务置为已跳过;
|
||||
// 区别是报销单本身退回草稿(0)而不是已撤回(4),这样用户能继续编辑条目并重新提交。
|
||||
func reimburseWithdrawCore(claims *jwtutil.Claims, id uint64, comment string) (int, string) {
|
||||
row, err := findOwnedReimbursement(claims, id)
|
||||
if err != nil {
|
||||
@@ -1320,7 +1230,6 @@ func reimburseWithdrawCore(claims *jwtutil.Claims, id uint64, comment string) (i
|
||||
return 400, "只有审批中的报销单可以撤回"
|
||||
}
|
||||
|
||||
// 历史单据可能没有审批实例:没有实例时直接退回草稿,保证仍可编辑
|
||||
inst, ok := findReimburseInstance(row.Tid, row.ID)
|
||||
if ok {
|
||||
if inst.Status != models.ApprovalInstanceRunning {
|
||||
@@ -1351,7 +1260,6 @@ func reimburseWithdrawCore(claims *jwtutil.Claims, id uint64, comment string) (i
|
||||
}); err != nil {
|
||||
return 500, "撤回失败"
|
||||
}
|
||||
// 时间线补一条撤回记录(不调用引擎 SyncBizResult,避免把单据同步成「已撤回」)
|
||||
_, _ = models.Orm.Insert(&models.BackendApprovalRecord{
|
||||
Tid: uint64(claims.TenantId), UID: uint64Ptr(uint64(claims.UserID)),
|
||||
ReimbursementID: id, ApproverID: uint64(claims.UserID),
|
||||
@@ -1362,12 +1270,10 @@ func reimburseWithdrawCore(claims *jwtutil.Claims, id uint64, comment string) (i
|
||||
return 200, ""
|
||||
}
|
||||
|
||||
// reimburseActPayload 审批操作请求体。
|
||||
type reimburseActPayload struct {
|
||||
Comment string `json:"comment"`
|
||||
}
|
||||
|
||||
// readReimburseComment 读取审批/撤回意见(可空),Web 与移动端共用。
|
||||
func readReimburseComment(ctrl *beego.Controller) string {
|
||||
var payload reimburseActPayload
|
||||
raw, err := io.ReadAll(ctrl.Ctx.Request.Body)
|
||||
@@ -1377,12 +1283,10 @@ func readReimburseComment(ctrl *beego.Controller) string {
|
||||
return strings.TrimSpace(payload.Comment)
|
||||
}
|
||||
|
||||
// readReimburseActPayload 读取审批意见(可空)。
|
||||
func (c *BackendReimburseController) readReimburseActPayload() string {
|
||||
return readReimburseComment(&c.Controller)
|
||||
}
|
||||
|
||||
// Approve POST /backend/reimbursements/approve/:id 通过当前审批节点(body: {comment})。
|
||||
func (c *BackendReimburseController) Approve() {
|
||||
claims, ok := c.claims()
|
||||
if !ok {
|
||||
@@ -1402,7 +1306,6 @@ func (c *BackendReimburseController) Approve() {
|
||||
c.reply(200, hint, nil)
|
||||
}
|
||||
|
||||
// Reject POST /backend/reimbursements/reject/:id 驳回报销单(body: {comment})。
|
||||
func (c *BackendReimburseController) Reject() {
|
||||
claims, ok := c.claims()
|
||||
if !ok {
|
||||
@@ -1422,8 +1325,6 @@ func (c *BackendReimburseController) Reject() {
|
||||
c.reply(200, hint, nil)
|
||||
}
|
||||
|
||||
// MyApproveTask GET /backend/reimbursements/my-approve-task/:id
|
||||
// 查当前用户在该单据上的待审批任务:返回 {task_id, node_name},无待办返回 data=null。
|
||||
func (c *BackendReimburseController) MyApproveTask() {
|
||||
claims, ok := c.claims()
|
||||
if !ok {
|
||||
@@ -1450,17 +1351,8 @@ func (c *BackendReimburseController) MyApproveTask() {
|
||||
})
|
||||
}
|
||||
|
||||
// reimburseFallbackBizTypes 报销匹配审批流的单据类型回退顺序:
|
||||
// 先按报销专有流(biz_type=reimburse),未配置时回退到 OA 分类默认流
|
||||
// (FlowSave 未显式指定单据类型时 biz_type=module_code,即 oa)。
|
||||
var reimburseFallbackBizTypes = []string{models.ApprovalBizReimburse, "oa"}
|
||||
|
||||
// reimburseSubmitCore 提交审批共享逻辑:仅草稿可提交,需租户已配置启用审批流。
|
||||
//
|
||||
// 提交进入统一审批引擎(biz_type=reimburse、biz_id=报销单ID),引擎负责节点流转;
|
||||
// 审批最终结果由 services/approval.SyncBizResult 回写到报销单状态,保证
|
||||
// 「审批中心」与「报销管理」看到的状态一致。
|
||||
// 提交后报销单置为审批中(1),并写入 action=1 的审批记录供业务详情时间线展示。
|
||||
func reimburseSubmitCore(claims *jwtutil.Claims, id uint64, comment string) (int, string) {
|
||||
row, err := findOwnedReimbursement(claims, id)
|
||||
if err != nil {
|
||||
@@ -1498,7 +1390,6 @@ func reimburseSubmitCore(claims *jwtutil.Claims, id uint64, comment string) (int
|
||||
return 400, err.Error()
|
||||
}
|
||||
|
||||
// 流程未配置审批节点时引擎会直接通过,此时报销单同步为已通过(2)
|
||||
status := reimbursementStatusApproving
|
||||
var inst models.ApprovalInstance
|
||||
if e := models.Orm.QueryTable(new(models.ApprovalInstance)).Filter("id", instID).One(&inst); e == nil {
|
||||
@@ -1529,8 +1420,6 @@ func reimburseSubmitCore(claims *jwtutil.Claims, id uint64, comment string) (int
|
||||
return 200, ""
|
||||
}
|
||||
|
||||
// findReimburseFlowID 查找报销单可用的启用审批流:
|
||||
// 优先精确匹配 biz_type=reimburse;若租户未区分单据类型(只按模块 oa 配置),回退到模块流程。
|
||||
func findReimburseFlowID(tid uint64) uint64 {
|
||||
var flow models.TenantApprovalFlow
|
||||
if err := models.Orm.QueryTable(new(models.TenantApprovalFlow)).
|
||||
@@ -1549,7 +1438,6 @@ func findReimburseFlowID(tid uint64) uint64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
// reimburseSubmitDeptID 取发起人所属组织ID,供审批引擎按「部门主管」规则解析审批人。
|
||||
func reimburseSubmitDeptID(tid, uid uint64) uint64 {
|
||||
var tu models.SystemTenantUser
|
||||
if err := models.Orm.QueryTable(new(models.SystemTenantUser)).
|
||||
@@ -1560,7 +1448,6 @@ func reimburseSubmitDeptID(tid, uid uint64) uint64 {
|
||||
return tu.OrgID
|
||||
}
|
||||
|
||||
// reimburseBizTitle 审批标题:优先报销说明,其次带单据号。
|
||||
func reimburseBizTitle(row *models.BackendReimbursement) string {
|
||||
if desc := reimburseDescription(row); desc != "" {
|
||||
return desc
|
||||
@@ -1579,27 +1466,19 @@ type reimbursementStatusPayload struct {
|
||||
Status int8 `json:"status"`
|
||||
}
|
||||
|
||||
// 报销单状态(0草稿 1审批中 2已通过 3已驳回 4已撤回 5已打款)
|
||||
const (
|
||||
// reimbursementStatusDraft 草稿:新建后的唯一初始状态。
|
||||
// 草稿可反复编辑/增删明细,只有用户在列表点「提交审核」才会进入审批流。
|
||||
reimbursementStatusDraft int8 = 0
|
||||
reimbursementStatusApproving int8 = 1 // 审批中
|
||||
reimbursementStatusApproved int8 = 2 // 已通过
|
||||
reimbursementStatusRejected int8 = 3 // 已驳回
|
||||
reimbursementStatusWithdrawn int8 = 4 // 已撤回
|
||||
reimbursementStatusPaid int8 = 5 // 已打款
|
||||
reimbursementStatusApproving int8 = 1
|
||||
reimbursementStatusApproved int8 = 2
|
||||
reimbursementStatusRejected int8 = 3
|
||||
reimbursementStatusWithdrawn int8 = 4
|
||||
reimbursementStatusPaid int8 = 5
|
||||
)
|
||||
|
||||
// isReimbursedStatus 判断报销单是否属于「已报销」。
|
||||
// 业务口径:审批已通过(2) 与已打款(5) 均算已报销;
|
||||
// 草稿(0) / 审批中(1) / 已驳回(3) / 已撤回(4) 均为未报销。
|
||||
func isReimbursedStatus(status int8) bool {
|
||||
return status == reimbursementStatusApproved || status == reimbursementStatusPaid
|
||||
}
|
||||
|
||||
// UpdateStatus POST /backend/reimbursements/:id/status — 报销人确认款项到账(置为「已打款」)。
|
||||
// 其它状态均由审批引擎/流程动作推进,不再支持手工变更。
|
||||
func (c *BackendReimburseController) UpdateStatus() {
|
||||
claims, ok := c.claims()
|
||||
if !ok {
|
||||
@@ -1629,11 +1508,6 @@ func (c *BackendReimburseController) UpdateStatus() {
|
||||
c.reply(200, "success", map[string]interface{}{"status": newStatus})
|
||||
}
|
||||
|
||||
// reimburseUpdateStatusCore 报销人确认款项到账共享逻辑。
|
||||
//
|
||||
// 规则:审批通过后,报销金额是否到账由报销人本人确认;确认后单据置为「已打款」。
|
||||
// 草稿/审批中/已通过/已驳回/已撤回等状态一律由流程动作与审批引擎推进,不再支持手工修改。
|
||||
// 返回 (生效状态, HTTP 状态码, 错误信息)。
|
||||
func reimburseUpdateStatusCore(claims *jwtutil.Claims, id uint64, status int8) (int8, int, string) {
|
||||
if status != reimbursementStatusPaid {
|
||||
return 0, 400, "仅支持确认收款,其它状态由审批流程自动推进"
|
||||
@@ -1658,7 +1532,6 @@ func reimburseUpdateStatusCore(claims *jwtutil.Claims, id uint64, status int8) (
|
||||
return reimbursementStatusPaid, 200, ""
|
||||
}
|
||||
|
||||
// Records GET /backend/reimbursements/:id/records
|
||||
func (c *BackendReimburseController) Records() {
|
||||
claims, ok := c.claims()
|
||||
if !ok {
|
||||
@@ -1678,7 +1551,6 @@ func (c *BackendReimburseController) Records() {
|
||||
c.reply(200, "success", rows)
|
||||
}
|
||||
|
||||
// reimburseRecordsData 审批记录共享逻辑(按 step、id 升序)。
|
||||
func reimburseRecordsData(claims *jwtutil.Claims, id uint64) ([]models.BackendApprovalRecord, int, string) {
|
||||
if _, err := findOwnedReimbursement(claims, id); err != nil {
|
||||
return nil, 404, "报销单不存在"
|
||||
@@ -1693,7 +1565,6 @@ func reimburseRecordsData(claims *jwtutil.Claims, id uint64) ([]models.BackendAp
|
||||
if rows == nil {
|
||||
rows = []models.BackendApprovalRecord{}
|
||||
}
|
||||
// 历史记录的 approver_name 可能为空(旧令牌没有 username 字段),读取时补齐
|
||||
tid := uint64(claims.TenantId)
|
||||
for i := range rows {
|
||||
if strings.TrimSpace(rows[i].ApproverName) != "" {
|
||||
@@ -1733,7 +1604,6 @@ func (c *BackendReimburseController) queryExpenseTypes(tenantID int, activeOnly
|
||||
return queryReimburseExpenseTypes(tenantID, activeOnly)
|
||||
}
|
||||
|
||||
// queryReimburseExpenseTypes 费用类型查询共享逻辑:全局通用(tid=0)+ 当前租户专有。
|
||||
func queryReimburseExpenseTypes(tenantID int, activeOnly bool) ([]models.BackendReimbursementExpenseType, error) {
|
||||
qs := models.Orm.QueryTable(new(models.BackendReimbursementExpenseType)).
|
||||
SetCond(expenseTypeScopeCond(tenantID)).
|
||||
@@ -1777,7 +1647,6 @@ func (c *BackendReimburseController) parseExpenseTypePayload() (expenseTypePaylo
|
||||
return payload, err
|
||||
}
|
||||
|
||||
// Types GET /backend/reimbursements/types — 下拉选项:全局通用 + 当前租户专有(仅启用)
|
||||
func (c *BackendReimburseController) Types() {
|
||||
claims, ok := c.claims()
|
||||
if !ok {
|
||||
@@ -1796,7 +1665,6 @@ func (c *BackendReimburseController) Types() {
|
||||
c.reply(200, "success", list)
|
||||
}
|
||||
|
||||
// TypesManage GET /backend/reimbursements/types/manage — 管理列表:含禁用项,标注是否可编辑
|
||||
func (c *BackendReimburseController) TypesManage() {
|
||||
claims, ok := c.claims()
|
||||
if !ok {
|
||||
@@ -1815,7 +1683,6 @@ func (c *BackendReimburseController) TypesManage() {
|
||||
c.reply(200, "success", list)
|
||||
}
|
||||
|
||||
// CreateType POST /backend/reimbursements/types — 租户新增专有费项
|
||||
func (c *BackendReimburseController) CreateType() {
|
||||
claims, ok := c.claims()
|
||||
if !ok {
|
||||
@@ -1852,7 +1719,6 @@ func (c *BackendReimburseController) CreateType() {
|
||||
c.reply(200, "success", expenseTypeDTO(*row, claims.TenantId))
|
||||
}
|
||||
|
||||
// UpdateType POST /backend/reimbursements/types/:type_id — 仅可修改本租户专有费项
|
||||
func (c *BackendReimburseController) UpdateType() {
|
||||
claims, ok := c.claims()
|
||||
if !ok {
|
||||
@@ -1896,7 +1762,6 @@ func (c *BackendReimburseController) UpdateType() {
|
||||
c.reply(200, "success", expenseTypeDTO(*row, claims.TenantId))
|
||||
}
|
||||
|
||||
// DeleteType DELETE /backend/reimbursements/types/:type_id — 仅可删除本租户专有费项
|
||||
func (c *BackendReimburseController) DeleteType() {
|
||||
claims, ok := c.claims()
|
||||
if !ok {
|
||||
@@ -1924,7 +1789,6 @@ func (c *BackendReimburseController) DeleteType() {
|
||||
c.reply(200, "success", nil)
|
||||
}
|
||||
|
||||
// Flows GET /backend/reimbursements/flows
|
||||
func (c *BackendReimburseController) Flows() {
|
||||
claims, ok := c.claims()
|
||||
if !ok {
|
||||
@@ -1990,7 +1854,6 @@ func uint64Ptr(value uint64) *uint64 {
|
||||
return &value
|
||||
}
|
||||
|
||||
// Dashboard GET /backend/reimbursements/dashboard — 报销统计(周/月/年 + 近6个月趋势 + 状态分布)
|
||||
func (c *BackendReimburseController) Dashboard() {
|
||||
claims, ok := c.claims()
|
||||
if !ok {
|
||||
@@ -2020,14 +1883,13 @@ func (c *BackendReimburseController) Dashboard() {
|
||||
return
|
||||
}
|
||||
|
||||
// ponytail: 个人报销单量小,一次全量查询内存聚合;量大时改 SQL GROUP BY
|
||||
newStat := func() map[string]interface{} {
|
||||
return map[string]interface{}{"total": 0.0, "paid": 0.0, "unpaid": 0.0, "count": 0}
|
||||
}
|
||||
addTo := func(stat map[string]interface{}, row *models.BackendReimbursement) {
|
||||
stat["total"] = stat["total"].(float64) + row.TotalAmount
|
||||
stat["count"] = stat["count"].(int) + 1
|
||||
if isReimbursedStatus(row.Status) { // 已通过 / 已打款均视为已报销
|
||||
if isReimbursedStatus(row.Status) {
|
||||
stat["paid"] = stat["paid"].(float64) + row.TotalAmount
|
||||
} else {
|
||||
stat["unpaid"] = stat["unpaid"].(float64) + row.TotalAmount
|
||||
@@ -2050,8 +1912,6 @@ func (c *BackendReimburseController) Dashboard() {
|
||||
|
||||
for i := range rows {
|
||||
row := &rows[i]
|
||||
// 按报销单「创建日期」归期(周/月/年 + 趋势)。
|
||||
// 申请日期 apply_date 允许回填为历史日期,用它会导致本月/本周漏统计。
|
||||
created := row.CreateTime
|
||||
if inRange(created, weekStart, tomorrow) {
|
||||
addTo(weekStat, row)
|
||||
@@ -2084,7 +1944,6 @@ func (c *BackendReimburseController) Dashboard() {
|
||||
})
|
||||
}
|
||||
|
||||
// 报销类型分析:仅统计已打款(status=5)的报销单费用明细
|
||||
paidIDs := map[uint64]bool{}
|
||||
for i := range rows {
|
||||
if rows[i].Status == 5 {
|
||||
@@ -2100,7 +1959,6 @@ func (c *BackendReimburseController) Dashboard() {
|
||||
amount float64
|
||||
}{}
|
||||
if len(paidIDList) > 0 {
|
||||
// 按已打款主单 ID 查明细,不依赖明细行的 tid/uid(历史数据可能不一致)
|
||||
var items []models.BackendReimbursementItem
|
||||
_, err = models.Orm.QueryTable(new(models.BackendReimbursementItem)).
|
||||
Filter("reimbursement_id__in", paidIDList).
|
||||
|
||||
Reference in new issue
Block a user