修复个人中心问题
This commit is contained in:
@@ -298,6 +298,93 @@ func (c *BackendCrmBusinessController) Update() {
|
||||
pipelineOk(&c.Controller, map[string]interface{}{"id": biz.ID})
|
||||
}
|
||||
|
||||
// ChangeStage POST /backend/crm/business/:id/stage
|
||||
// 商机阶段流转:1初步接洽 2需求确认 3方案报价 4商务谈判 5赢单 6输单。
|
||||
// 仅更新阶段字段,不触碰其他业务字段;已转化并锁定的商机不允许再流转。
|
||||
func (c *BackendCrmBusinessController) ChangeStage() {
|
||||
claims, err := pipelineClaims(&c.Controller)
|
||||
if err != nil {
|
||||
pipelineErr(&c.Controller, 401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
id, _ := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
|
||||
if id == 0 {
|
||||
pipelineErr(&c.Controller, 400, 400, "无效的ID")
|
||||
return
|
||||
}
|
||||
raw, _ := io.ReadAll(c.Ctx.Request.Body)
|
||||
var p struct {
|
||||
Stage string `json:"stage"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &p); err != nil {
|
||||
pipelineErr(&c.Controller, 400, 400, "参数错误")
|
||||
return
|
||||
}
|
||||
stage := strings.TrimSpace(p.Stage)
|
||||
if !validBusinessStage(stage) {
|
||||
pipelineErr(&c.Controller, 400, 400, "无效的商机阶段")
|
||||
return
|
||||
}
|
||||
tenantID := pipelineTenantID(claims)
|
||||
var biz models.TenantCrmBusiness
|
||||
if err := models.Orm.QueryTable(new(models.TenantCrmBusiness)).
|
||||
Filter("id", id).Filter("tenant_id", tenantID).
|
||||
Filter("delete_time__isnull", true).One(&biz); err != nil {
|
||||
pipelineErr(&c.Controller, 404, 404, "商机未找到")
|
||||
return
|
||||
}
|
||||
// 数据范围校验:非管理员仅能操作本人(负责人或创建人)的数据
|
||||
if !canAccessCrmRecord(claims, biz.OwnerUserID, biz.CreateUserID) {
|
||||
pipelineErr(&c.Controller, 403, 403, "无权操作该商机数据")
|
||||
return
|
||||
}
|
||||
if biz.Locked == 1 || biz.Status == 2 {
|
||||
pipelineErr(&c.Controller, 400, 400, "商机已转化并锁定,不能流转阶段")
|
||||
return
|
||||
}
|
||||
// 阶段未变化:直接幂等返回,不写日志
|
||||
if strings.TrimSpace(biz.Stage) == stage {
|
||||
pipelineOk(&c.Controller, map[string]interface{}{"id": biz.ID, "stage": biz.Stage})
|
||||
return
|
||||
}
|
||||
if _, err := models.Orm.QueryTable(new(models.TenantCrmBusiness)).
|
||||
Filter("id", id).Filter("tenant_id", tenantID).
|
||||
Update(map[string]interface{}{"stage": stage, "update_time": time.Now()}); err != nil {
|
||||
pipelineErr(&c.Controller, 500, 500, "阶段更新失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
crmWriteLog(tenantID, 2, biz.ID, "status",
|
||||
"商机阶段:"+businessStageName(biz.Stage)+" → "+businessStageName(stage), claims)
|
||||
pipelineOk(&c.Controller, map[string]interface{}{"id": biz.ID, "stage": stage})
|
||||
}
|
||||
|
||||
// businessStageName 商机阶段文案(用于操作日志):1初步接洽 … 5赢单 / 6输单
|
||||
func businessStageName(s string) string {
|
||||
switch strings.TrimSpace(s) {
|
||||
case "2":
|
||||
return "需求确认"
|
||||
case "3":
|
||||
return "方案报价"
|
||||
case "4":
|
||||
return "商务谈判"
|
||||
case "5":
|
||||
return "赢单"
|
||||
case "6":
|
||||
return "输单"
|
||||
default:
|
||||
return "初步接洽"
|
||||
}
|
||||
}
|
||||
|
||||
// validBusinessStage 商机阶段取值校验(1~6)
|
||||
func validBusinessStage(s string) bool {
|
||||
switch s {
|
||||
case "1", "2", "3", "4", "5", "6":
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Delete DELETE /backend/crm/business/:id
|
||||
func (c *BackendCrmBusinessController) Delete() {
|
||||
claims, err := pipelineClaims(&c.Controller)
|
||||
|
||||
Reference in New Issue
Block a user