更新密码找回uniapp

This commit is contained in:
hero920103 committed 2026-11-16 17:22:50 +08:00
1 parent 7f9a66da0f
commit 3fdda89833
1304 files changed
+3503 -26132

No files matched your search

+2 -39
View File
@@ -9,11 +9,6 @@ import (
"server/models"
)
// ERP 报表/看板核心(两端共用):统计口径只认「已生效」单据与库存流水,
// 草稿/审批中/作废一律不参与,这样 Web 端与手机端看到的金额、毛利、库存预警数完全一致。
// erpReportDimension 归一购销汇总维度:只认 product|supplier|customer|month,
// 其它一律回落到商品,出参的 dimension 字段即后端真实使用的分组。
func erpReportDimension(raw string) string {
switch g := strings.TrimSpace(raw); g {
case "supplier", "customer", "month":
@@ -23,7 +18,6 @@ func erpReportDimension(raw string) string {
}
}
// erpWarningCounts 库存预警各类计数(看板角标用,不含明细)
func erpWarningCounts(tid string) map[string]int {
var products []models.ErpProduct
_, _ = models.Orm.QueryTable(new(models.ErpProduct)).
@@ -52,7 +46,6 @@ func erpWarningCounts(tid string) map[string]int {
return map[string]int{"low": low, "over": over, "out": out, "expiring": len(erpExpiringBatches(tid, 30))}
}
// erpDocAmount 区间内已生效单据的金额合计与单数
func erpDocAmount(tid string, docTypes []string, from, to time.Time) (float64, int64) {
ids := erpApprovedDocIDs(tid, docTypes, from, to, 0)
if len(ids) == 0 {
@@ -68,7 +61,6 @@ func erpDocAmount(tid string, docTypes []string, from, to time.Time) (float64, i
return round2f(sum), int64(len(docs))
}
// erpDashboardTrend 看板趋势点。Month 保留旧字段(兼容旧页面),Label 为图表 x 轴文案
type erpDashboardTrend struct {
Month string `json:"month"`
Label string `json:"label"`
@@ -76,7 +68,6 @@ type erpDashboardTrend struct {
Sale float64 `json:"sale"`
}
// erpDashboardPeriod 解析看板统计周期:week|month|quarter|year,缺省或非法值回落 month
func erpDashboardPeriod(raw string) string {
switch p := strings.ToLower(strings.TrimSpace(raw)); p {
case "week", "quarter", "year":
@@ -86,18 +77,14 @@ func erpDashboardPeriod(raw string) string {
}
}
// erpPeriodSpan 趋势分桶:Key 用于把单据日期映射到桶,Label 是图表 x 轴文案
type erpPeriodSpan struct {
Key string
Label string
}
// erpPeriodRange 返回周期区间 [from, to)、中文标签与趋势分桶。
// 周/月按天分桶,季度按 3 个月分桶,年度按 12 个月分桶。
func erpPeriodRange(period string, now time.Time) (time.Time, time.Time, string, []erpPeriodSpan) {
switch period {
case "week":
// 周一为一周起点;Go 的 Sunday=0,需要换算成「距本周一的天数」
offset := (int(now.Weekday()) + 6) % 7
from := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, -offset)
names := []string{"周一", "周二", "周三", "周四", "周五", "周六", "周日"}
@@ -123,7 +110,7 @@ func erpPeriodRange(period string, now time.Time) (time.Time, time.Time, string,
spans = append(spans, erpPeriodSpan{Key: fmt.Sprintf("%04d-%02d", now.Year(), i), Label: fmt.Sprintf("%d月", i)})
}
return from, from.AddDate(1, 0, 0), "本年", spans
default: // month
default:
from := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.Local)
to := from.AddDate(0, 1, 0)
spans := make([]erpPeriodSpan, 0, 31)
@@ -134,13 +121,11 @@ func erpPeriodRange(period string, now time.Time) (time.Time, time.Time, string,
}
}
// erpDashboardStats 区间内购销/毛利统计(只认已生效单据与库存流水)
func erpDashboardStats(tid string, from, to time.Time) map[string]interface{} {
buyAmt, buyCnt := erpDocAmount(tid, []string{models.ErpDocPurchaseIn}, from, to)
saleAmt, saleCnt := erpDocAmount(tid, []string{models.ErpDocSalesOut}, from, to)
backAmt, _ := erpDocAmount(tid, []string{models.ErpDocSalesReturn}, from, to)
// 毛利按出库流水成本口径
var ledgers []models.ErpStockLedger
_, _ = models.Orm.QueryTable(new(models.ErpStockLedger)).
Filter("tenant_id", tid).
@@ -168,8 +153,6 @@ func erpDashboardStats(tid string, from, to time.Time) map[string]interface{} {
}
}
// erpDashboardPeriodTrend 当前周期内的购销分布:一次查出单据后按分桶汇总,
// 避免「每个点都打一次库」(年度 12 点、月度 31 点)。
func erpDashboardPeriodTrend(tid string, from, to time.Time, period string, spans []erpPeriodSpan) []erpDashboardTrend {
var docs []models.ErpDocument
_, _ = models.Orm.QueryTable(new(models.ErpDocument)).
@@ -211,9 +194,6 @@ func erpDashboardPeriodTrend(tid string, from, to time.Time, period string, span
return list
}
// erpDashboardCore 经营看板:所选周期的购销/毛利、今日销售、库存价值、往来余额、
// 待办、近 6 个月趋势、当前周期趋势与预警。period 取 week|month|quarter|year,缺省 month。
// month 字段保持「本月」口径不变,供旧页面与小程序继续使用;current 为所选周期。
func erpDashboardCore(a erpActor, periodRaw string) map[string]interface{} {
tid := a.Tid
period := erpDashboardPeriod(periodRaw)
@@ -228,8 +208,6 @@ func erpDashboardCore(a erpActor, periodRaw string) map[string]interface{} {
current = erpDashboardStats(tid, periodFrom, periodTo)
}
// 不能用 time.Now().Truncate(24*time.Hour):它按「自零时起算的绝对时长」取整,
// 在东八区得到的是 UTC 零点(本地 08:00),会把当天 00:00–08:00 的单据漏掉。
todayFrom := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
todaySale, todayCnt := erpDocAmount(tid, []string{models.ErpDocSalesOut}, todayFrom, todayFrom.AddDate(0, 0, 1))
@@ -255,7 +233,6 @@ func erpDashboardCore(a erpActor, periodRaw string) map[string]interface{} {
}
}
// 待办:待我审批的进销存单据 + 草稿单据数
pendingTasks := erpErpPendingTaskCount(a.TidNum, a.UID)
var draftCnt int64
if n, e := models.Orm.QueryTable(new(models.ErpDocument)).
@@ -281,7 +258,6 @@ func erpDashboardCore(a erpActor, periodRaw string) map[string]interface{} {
"label": periodLabel,
},
"current": current,
// 兼容旧调用方:month 始终是本月口径
"month": monthStats,
"today": map[string]interface{}{"sales_amount": todaySale, "sales_count": todayCnt},
"stock": map[string]interface{}{"value": round2f(stockValue), "qty": round4f(stockQty)},
@@ -295,7 +271,6 @@ func erpDashboardCore(a erpActor, periodRaw string) map[string]interface{} {
}
}
// erpReportRow 汇总报表行(按商品/往来单位/月份聚合后的结果)
type erpReportRow struct {
Key string `json:"key"`
Label string `json:"label"`
@@ -304,7 +279,6 @@ type erpReportRow struct {
Lines int64 `json:"lines"`
}
// erpSummaryReportData 购销汇总:按商品/往来单位/月份三种维度聚合,退货行做负向冲减
func erpSummaryReportData(group string, items []models.ErpDocumentItem,
docPartner map[uint64]models.ErpDocument, returnItems []models.ErpDocumentItem) map[string]interface{} {
@@ -334,7 +308,6 @@ func erpSummaryReportData(group string, items []models.ErpDocumentItem,
k, lb := bucket(it)
add(k, lb, it.Quantity, it.Amount)
}
// 退货按同维度负向冲减,净额与往来账口径一致
for _, it := range returnItems {
k, lb := bucket(it)
if group == "supplier" || group == "customer" {
@@ -361,7 +334,7 @@ func erpSummaryReportData(group string, items []models.ErpDocumentItem,
if list[i].Amount != list[j].Amount {
return list[i].Amount > list[j].Amount
}
return list[i].Key < list[j].Key // 金额相同(如对冲后同为 0)时按维度键定序,避免两次请求行序抖动
return list[i].Key < list[j].Key
})
return map[string]interface{}{
"list": list, "dimension": group,
@@ -369,7 +342,6 @@ func erpSummaryReportData(group string, items []models.ErpDocumentItem,
}
}
// erpSalesRankRow 热销/滞销排行行
type erpSalesRankRow struct {
ProductID uint64 `json:"product_id"`
ProductName string `json:"product_name"`
@@ -380,7 +352,6 @@ type erpSalesRankRow struct {
Amount float64 `json:"amount"`
}
// erpSalesRankCore 热销(desc)/滞销(asc)排行;滞销榜需要把「一件没卖」的在售商品也排进来
func erpSalesRankCore(a erpActor, from, to time.Time, top int, asc bool) (map[string]interface{}, int, string) {
if top < 1 || top > 50 {
top = 10
@@ -444,7 +415,6 @@ func erpSalesRankCore(a erpActor, from, to time.Time, top int, asc bool) (map[st
}, 200, ""
}
// erpSummaryPurchaseCore / erpSummarySalesCore 购销汇总取数:两端按维度调用同一份聚合
func erpSummaryDocs(tid, docType, returnType string, from, to time.Time, partnerID uint64) (
[]models.ErpDocumentItem, map[uint64]models.ErpDocument, []models.ErpDocumentItem) {
ids := erpApprovedDocIDs(tid, []string{docType}, from, to, partnerID)
@@ -454,8 +424,6 @@ func erpSummaryDocs(tid, docType, returnType string, from, to time.Time, partner
return items, erpDocPartnerMap(append(append([]uint64{}, ids...), rids...)), returnItems
}
// erpStockMoveRow 收发存汇总行:期末取自库存结存,本期收发取自库存流水,
// 期初=期末-(入-出),保证与账实一致。
type erpStockMoveRow struct {
ProductID uint64 `json:"product_id"`
ProductCode string `json:"product_code"`
@@ -476,7 +444,6 @@ type erpStockMoveRow struct {
EndAmount float64 `json:"end_amount"`
}
// erpStockMoveCore 收发存汇总表(分页 + 全量合计)
func erpStockMoveCore(a erpActor, from, to time.Time, warehouseID uint64, keyword string,
page, pageSize int) ([]erpStockMoveRow, int64, map[string]float64, int, string) {
@@ -526,7 +493,6 @@ func erpStockMoveCore(a erpActor, from, to time.Time, warehouseID uint64, keywor
outQty[k] += l.Quantity
outAmt[k] += l.TotalCost
}
// 区间内有流水但当前无结存的组合也要出现在表里(已全部出库)
found := false
for _, e := range keys {
if e == k {
@@ -602,8 +568,6 @@ func erpStockMoveCore(a erpActor, from, to time.Time, warehouseID uint64, keywor
return list[start:end], int64(len(list)), summary, 200, ""
}
// erpProfitRow 毛利分析行:收入=销售出库金额-销售退货金额,
// 成本取库存流水的实际出库成本(移动加权),不受手工录入影响。
type erpProfitRow struct {
ProductID uint64 `json:"product_id"`
ProductCode string `json:"product_code"`
@@ -617,7 +581,6 @@ type erpProfitRow struct {
ProfitRate float64 `json:"profit_rate"`
}
// erpProfitCore 毛利分析(按商品)
func erpProfitCore(a erpActor, from, to time.Time) (map[string]interface{}, int, string) {
tid := a.Tid
outIDs := erpApprovedDocIDs(tid, []string{models.ErpDocSalesOut}, from, to, 0)