更新密码找回uniapp
This commit is contained in:
1 parent
7f9a66da0f
commit
3fdda89833
1304 files changed
+3503
-26132
No files matched your search
@@ -13,19 +13,8 @@ import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
)
|
||||
|
||||
// ERP 单据核心逻辑(两端共用)。
|
||||
//
|
||||
// 按项目的接口隔离约定,/backend/erp/document* 与 /api/erp/document* 必须各有独立的
|
||||
// handler 与路由,但单据的校验、明细装配、落库事务与审批提交口径只能有一份实现:
|
||||
// 这里就是那一份。两端 handler 只负责「解析自己的令牌 → 组装 erpActor → 调核心 →
|
||||
// 按各自的响应信封输出」,业务规则不在两端各写一遍,避免移动端口径慢慢跑偏。
|
||||
//
|
||||
// 返回约定沿用 reimburse*Core:最后一个 string 为空即成功,非空时给出处置状态码与文案,
|
||||
// 由调用方原样透出,保证抽取前后接口行为完全一致。
|
||||
|
||||
// erpActor ERP 操作人:由各自端的 JWT 解析而来,核心层只认这个结构,不认 beego 上下文
|
||||
type erpActor struct {
|
||||
Tid string // 租户ID字符串口径(ERP 表的 tenant_id 是 VARCHAR)
|
||||
Tid string
|
||||
TidNum uint64
|
||||
UID uint64
|
||||
Name string
|
||||
@@ -40,10 +29,9 @@ func erpNewActor(claims *jwtutil.Claims) erpActor {
|
||||
}
|
||||
}
|
||||
|
||||
// erpDocFilter 单据列表筛选条件(与 Web 端查询参数一一对应)
|
||||
type erpDocFilter struct {
|
||||
DocType string
|
||||
DocTypes string // 逗号分隔的多类型
|
||||
DocTypes string
|
||||
Status string
|
||||
Keyword string
|
||||
PartnerID uint64
|
||||
@@ -53,7 +41,6 @@ type erpDocFilter struct {
|
||||
DateTo string
|
||||
}
|
||||
|
||||
// erpDocListCore 单据分页查询
|
||||
func erpDocListCore(a erpActor, f erpDocFilter, page, pageSize int) ([]models.ErpDocument, int64, int, string) {
|
||||
if f.DocType != "" && !erpDocTypes[f.DocType] {
|
||||
return nil, 0, 400, "未知的单据类型"
|
||||
@@ -117,7 +104,6 @@ func erpDocListCore(a erpActor, f erpDocFilter, page, pageSize int) ([]models.Er
|
||||
return list, total, 200, ""
|
||||
}
|
||||
|
||||
// erpDocDetailCore 单据详情(含明细、库存快照与审批实例摘要)
|
||||
func erpDocDetailCore(a erpActor, id uint64) (*models.ErpDocument, int, string) {
|
||||
if id == 0 {
|
||||
return nil, 400, "无效的ID"
|
||||
@@ -137,7 +123,6 @@ func erpDocDetailCore(a erpActor, id uint64) (*models.ErpDocument, int, string)
|
||||
return &single[0], 200, ""
|
||||
}
|
||||
|
||||
// erpValidateDocHead 校验表头:仓库归属、往来单位匹配、调拨/盘点的仓库约束
|
||||
func erpValidateDocHead(tid string, p *erpDocPayload) string {
|
||||
needWh := models.ErpDocAffectsStock(p.DocType)
|
||||
if needWh && p.WarehouseID == 0 && p.DocType != models.ErpDocStockTake {
|
||||
@@ -191,7 +176,6 @@ func erpValidateDocHead(tid string, p *erpDocPayload) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// refItemIDs 收集明细行引用的来源单据行ID
|
||||
func refItemIDs(raw []erpDocItemPayload) []uint64 {
|
||||
out := make([]uint64, 0, len(raw))
|
||||
for _, r := range raw {
|
||||
@@ -202,7 +186,6 @@ func refItemIDs(raw []erpDocItemPayload) []uint64 {
|
||||
return out
|
||||
}
|
||||
|
||||
// erpBuildItems 明细行规范化:补商品快照/单价(价格体系)、算金额、校验限价与批次
|
||||
func erpBuildItems(tid string, doc *models.ErpDocument, raw []erpDocItemPayload) ([]models.ErpDocumentItem, string) {
|
||||
ids := make([]uint64, 0, len(raw))
|
||||
for _, r := range raw {
|
||||
@@ -211,8 +194,6 @@ func erpBuildItems(tid string, doc *models.ErpDocument, raw []erpDocItemPayload)
|
||||
}
|
||||
}
|
||||
pmap := erpProductMap(tid, ids)
|
||||
// 来源订单明细行归属:草稿覆盖保存会重建明细(行 ID 变化),前端若仍拿着旧行 ID,
|
||||
// 不在开单时就拦下,脏引用要拖到审核生效才报错,移动端更难定位。
|
||||
refOwner := map[uint64]uint64{}
|
||||
if refIDs := refItemIDs(raw); len(refIDs) > 0 {
|
||||
var refs []models.ErpDocumentItem
|
||||
@@ -239,7 +220,6 @@ func erpBuildItems(tid string, doc *models.ErpDocument, raw []erpDocItemPayload)
|
||||
if unitPrice <= 0 {
|
||||
unitPrice = erpPickPrice(p, doc.DocType, settings.SalesPriceType)
|
||||
}
|
||||
// 限价控制:低于最低售价直接拦截(除管理员放行的场景,这里不做例外)
|
||||
if strings.HasPrefix(doc.DocType, "sales") && p.MinPrice > 0 && unitPrice < p.MinPrice-0.005 {
|
||||
return nil, fmt.Sprintf("商品「%s」售价 %.2f 低于最低售价 %.2f", p.ProductName, unitPrice, p.MinPrice)
|
||||
}
|
||||
@@ -287,7 +267,6 @@ func erpBuildItems(tid string, doc *models.ErpDocument, raw []erpDocItemPayload)
|
||||
it.ExpireDate = &t
|
||||
}
|
||||
}
|
||||
// 盘点行未带账面数时按当前结存补齐
|
||||
if doc.DocType == models.ErpDocStockTake && it.BookQty == 0 && it.WarehouseID == 0 {
|
||||
it.BookQty = erpStockQty(tid, p.ID, doc.WarehouseID, it.BatchNo)
|
||||
if it.UnitPrice == 0 {
|
||||
@@ -302,7 +281,6 @@ func erpBuildItems(tid string, doc *models.ErpDocument, raw []erpDocItemPayload)
|
||||
return out, ""
|
||||
}
|
||||
|
||||
// erpDocSaveCore 新建或覆盖保存草稿(payload 带 id 即为编辑)。已生效/审批中的单据不允许改动。
|
||||
func erpDocSaveCore(a erpActor, p erpDocPayload) (uint64, string, int, string) {
|
||||
tid := a.Tid
|
||||
if !erpDocTypes[p.DocType] {
|
||||
@@ -431,7 +409,6 @@ func erpDocSaveCore(a erpActor, p erpDocPayload) (uint64, string, int, string) {
|
||||
return doc.ID, doc.DocNo, 200, ""
|
||||
}
|
||||
|
||||
// erpDocDeleteCore 删除单据(软删主表、硬删明细),仅草稿/驳回可删
|
||||
func erpDocDeleteCore(a erpActor, id uint64) (int, string) {
|
||||
doc, errMsg := erpLoadEditable(id, a.Tid, []int8{models.ErpDocStatusDraft, models.ErpDocStatusRejected})
|
||||
if errMsg != "" {
|
||||
@@ -448,7 +425,6 @@ func erpDocDeleteCore(a erpActor, id uint64) (int, string) {
|
||||
Update(orm.Params{"delete_time": now, "update_time": now}); err != nil {
|
||||
return 500, "删除失败: " + err.Error()
|
||||
}
|
||||
// 明细随主表硬删:主表只软删,历史仍可追溯;明细无独立查询价值
|
||||
if _, err = tx.QueryTable(new(models.ErpDocumentItem)).Filter("doc_id", doc.ID).Delete(); err != nil {
|
||||
return 500, "删除失败: " + err.Error()
|
||||
}
|
||||
@@ -459,8 +435,6 @@ func erpDocDeleteCore(a erpActor, id uint64) (int, string) {
|
||||
return 200, ""
|
||||
}
|
||||
|
||||
// erpDocCancelCore 作废:草稿/驳回/审批中均可作废;已生效单据不做反向单据,直接拒绝,
|
||||
// 保证「已生效=流水已入账」这一不可篡改前提。
|
||||
func erpDocCancelCore(a erpActor, id uint64) (int, string) {
|
||||
doc, errMsg := erpLoadEditable(id, a.Tid, []int8{
|
||||
models.ErpDocStatusDraft, models.ErpDocStatusRejected, models.ErpDocStatusPending,
|
||||
@@ -479,7 +453,6 @@ func erpDocCancelCore(a erpActor, id uint64) (int, string) {
|
||||
return 200, ""
|
||||
}
|
||||
|
||||
// erpDocApproveCore 直接审核生效(未走审批流时使用)。库存/往来账效果在同一事务内落地。
|
||||
func erpDocApproveCore(a erpActor, id uint64) (int, string) {
|
||||
if id == 0 {
|
||||
return 400, "无效的ID"
|
||||
@@ -490,8 +463,6 @@ func erpDocApproveCore(a erpActor, id uint64) (int, string) {
|
||||
return 200, ""
|
||||
}
|
||||
|
||||
// erpDocSubmitCore 提交审批:flowID 为 0 时按单据类型自动选流。
|
||||
// 流程未配置人工节点时引擎会直接结束实例,此时同步单据终态。
|
||||
func erpDocSubmitCore(a erpActor, id, flowID uint64) (uint64, int, string) {
|
||||
if id == 0 {
|
||||
return 0, 400, "无效的ID"
|
||||
@@ -551,7 +522,6 @@ type erpFlowRow struct {
|
||||
BizType string `json:"biz_type"`
|
||||
}
|
||||
|
||||
// erpDocFlowsCore 该单据类型可用的审批流(先精确匹配 erp_xxx,再回落到模块级 erp)
|
||||
func erpDocFlowsCore(a erpActor, docType string) (string, []erpFlowRow, int, string) {
|
||||
if !erpDocTypes[docType] {
|
||||
return "", nil, 400, "未知的单据类型"
|
||||
@@ -572,14 +542,11 @@ func erpDocFlowsCore(a erpActor, docType string) (string, []erpFlowRow, int, str
|
||||
return bizType, out, 200, ""
|
||||
}
|
||||
|
||||
// erpDocExecutableCore 取来源订单中尚可执行的明细行(入库/出库/退货按行带出,避免超收超发)
|
||||
func erpDocExecutableCore(a erpActor, id uint64) (map[string]interface{}, int, string) {
|
||||
doc, e := erpLoadDoc(id, a.Tid)
|
||||
if e != nil {
|
||||
return nil, 404, "单据未找到"
|
||||
}
|
||||
// 只有已生效单据可作为下推来源;作废、草稿、审批中、驳回都直接拒绝,
|
||||
// 与保存时 erpValidateDocHead 的来源状态校验保持一致,避免绕过前端菜单
|
||||
if doc.Status != models.ErpDocStatusApproved {
|
||||
return nil, 400, "来源单据未生效,不能下推"
|
||||
}
|
||||
@@ -606,7 +573,6 @@ func erpDocExecutableCore(a erpActor, id uint64) (map[string]interface{}, int, s
|
||||
return map[string]interface{}{"doc": doc, "items": out}, 200, ""
|
||||
}
|
||||
|
||||
// erpTakeSheetCore 盘点表初始化:带出当前账面数量与加权成本,盘点员只改实盘数
|
||||
func erpTakeSheetCore(a erpActor, warehouseID uint64) ([]map[string]interface{}, int, string) {
|
||||
var stocks []models.ErpStock
|
||||
_, _ = models.Orm.QueryTable(new(models.ErpStock)).
|
||||
@@ -629,7 +595,6 @@ func erpTakeSheetCore(a erpActor, warehouseID uint64) ([]map[string]interface{},
|
||||
return out, 200, ""
|
||||
}
|
||||
|
||||
// erpDocMetaDict 开单页所需字典与默认值(两端共用同一份口径)
|
||||
func erpDocMetaDict(a erpActor) map[string]interface{} {
|
||||
s := erp.GetSettings(a.Tid)
|
||||
types := make([]map[string]interface{}, 0, len(models.ErpDocTypeLabel))
|
||||
|
||||
Reference in new issue
Block a user