更新若干
This commit is contained in:
1 parent
54c90072fb
commit
5682069553
59 files changed
+3813
-1617
No files matched your search
@@ -0,0 +1,366 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"server/models"
|
||||
"server/pkg/jwtutil"
|
||||
"server/services"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
)
|
||||
|
||||
// AppCrmProjectController 提供 App 端(uniapp)CRM 项目管理接口。
|
||||
// 与 Web 后台的 /backend/crm/project/* 共用同一套模型、权限与核心逻辑,
|
||||
// 差异仅在于鉴权入口(App/Backend 双端令牌)与响应包装。
|
||||
type AppCrmProjectController struct {
|
||||
AppErpBaseController
|
||||
}
|
||||
|
||||
type crmProjectSavePayload struct {
|
||||
ID uint64 `json:"id"`
|
||||
projectPayload
|
||||
}
|
||||
|
||||
// List GET /api/crm/project/list
|
||||
func (c *AppCrmProjectController) List() {
|
||||
cl, err := c.erpClaims()
|
||||
if c.erpDenied(err) {
|
||||
return
|
||||
}
|
||||
page, pageSize := c.erpPage()
|
||||
tenantID := pipelineTenantID(cl)
|
||||
|
||||
cond := orm.NewCondition().
|
||||
And("tenant_id", tenantID).
|
||||
And("delete_time__isnull", true)
|
||||
cond = crmApplyOwnerScope(cond, cl)
|
||||
|
||||
if kw := c.erpQuery("keyword"); kw != "" {
|
||||
cond = cond.AndCond(orm.NewCondition().
|
||||
Or("project_name__contains", kw).
|
||||
Or("project_no__contains", kw).
|
||||
Or("customer_name__contains", kw).
|
||||
Or("supplier_name__contains", kw))
|
||||
}
|
||||
if st := c.erpQuery("status"); st != "" {
|
||||
cond = cond.And("status", st)
|
||||
}
|
||||
if pt := c.erpQuery("project_type"); pt != "" {
|
||||
if _, err := strconv.Atoi(pt); err == nil {
|
||||
cond = cond.And("project_type", pt)
|
||||
}
|
||||
}
|
||||
if y := c.erpQuery("year"); y != "" {
|
||||
if year, err := strconv.Atoi(y); err == nil && year > 0 {
|
||||
from := time.Date(year, time.January, 1, 0, 0, 0, 0, time.Local)
|
||||
cond = cond.AndCond(orm.NewCondition().
|
||||
And("start_date__gte", from).
|
||||
And("start_date__lt", from.AddDate(1, 0, 0)))
|
||||
}
|
||||
}
|
||||
|
||||
qs := models.Orm.QueryTable(new(models.TenantCrmProject)).SetCond(cond)
|
||||
total, _ := qs.Count()
|
||||
list := make([]models.TenantCrmProject, 0)
|
||||
if total > 0 {
|
||||
if _, err := qs.OrderBy("-start_date", "-id").
|
||||
Limit(pageSize, (page-1)*pageSize).All(&list); err != nil {
|
||||
c.erpFail(500, 500, "查询失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
attachBusinessName(tenantID, list)
|
||||
}
|
||||
c.erpListOK(list, total, page, pageSize, nil)
|
||||
}
|
||||
|
||||
// Detail GET /api/crm/project/detail/:id
|
||||
func (c *AppCrmProjectController) Detail() {
|
||||
cl, err := c.erpClaims()
|
||||
if c.erpDenied(err) {
|
||||
return
|
||||
}
|
||||
id := c.erpPathID()
|
||||
if id == 0 {
|
||||
c.erpFail(400, 400, "无效的ID")
|
||||
return
|
||||
}
|
||||
tenantID := pipelineTenantID(cl)
|
||||
var proj models.TenantCrmProject
|
||||
if err := models.Orm.QueryTable(new(models.TenantCrmProject)).
|
||||
Filter("id", id).Filter("tenant_id", tenantID).
|
||||
Filter("delete_time__isnull", true).One(&proj); err != nil {
|
||||
c.erpFail(404, 404, "项目未找到")
|
||||
return
|
||||
}
|
||||
if !canAccessCrmRecord(cl, proj.OwnerUserID, proj.CreateUserID) {
|
||||
c.erpFail(403, 403, "无权查看该项目数据")
|
||||
return
|
||||
}
|
||||
list := []models.TenantCrmProject{proj}
|
||||
attachBusinessName(tenantID, list)
|
||||
c.erpOk(list[0])
|
||||
}
|
||||
|
||||
// Save POST /api/crm/project/save
|
||||
// id 为 0 时新建,否则更新。
|
||||
func (c *AppCrmProjectController) Save() {
|
||||
cl, err := c.erpClaims()
|
||||
if c.erpDenied(err) {
|
||||
return
|
||||
}
|
||||
var p crmProjectSavePayload
|
||||
if !c.erpBody(&p, false) {
|
||||
return
|
||||
}
|
||||
if strings.TrimSpace(p.ProjectName) == "" {
|
||||
c.erpFail(400, 400, "项目名称不能为空")
|
||||
return
|
||||
}
|
||||
tenantID := pipelineTenantID(cl)
|
||||
if p.ID == 0 {
|
||||
c.createProject(cl, tenantID, &p)
|
||||
return
|
||||
}
|
||||
c.updateProject(cl, tenantID, &p)
|
||||
}
|
||||
|
||||
func (c *AppCrmProjectController) createProject(cl *jwtutil.Claims, tenantID string, p *crmProjectSavePayload) {
|
||||
custIDVal, custRefType, customerName := resolveProjectCustomer(tenantID, p.CustomerRefType, p.CustomerID, p.CustomerName)
|
||||
status := p.Status
|
||||
if status == 0 {
|
||||
status = 1
|
||||
}
|
||||
pt, upstream, downstream, upContact, upPhone, downContact, downPhone := normalizeProjectFields(&p.projectPayload)
|
||||
supplierID, supplierRefType, supplierName := resolveProjectSupplier(tenantID, p.SupplierRefType, p.SupplierID, p.SupplierName)
|
||||
if pt == 1 {
|
||||
supplierID, supplierRefType, supplierName = nil, 0, ""
|
||||
}
|
||||
now := time.Now()
|
||||
proj := models.TenantCrmProject{
|
||||
TenantID: tenantID,
|
||||
ProjectName: strings.TrimSpace(p.ProjectName),
|
||||
ProjectNo: strings.TrimSpace(p.ProjectNo),
|
||||
ProjectType: pt,
|
||||
CustomerID: custIDVal,
|
||||
CustomerRefType: custRefType,
|
||||
CustomerName: customerName,
|
||||
SupplierID: supplierID,
|
||||
SupplierRefType: supplierRefType,
|
||||
SupplierName: supplierName,
|
||||
SupplierIndustry: strings.TrimSpace(p.SupplierIndustry),
|
||||
OwnerUserID: firstNonEmpty(p.OwnerUserID, pipelineUID(cl)),
|
||||
OwnerUserName: firstNonEmpty(p.OwnerUserName, resolveUserName(cl)),
|
||||
Industry: strings.TrimSpace(p.Industry),
|
||||
UpstreamAmount: upstream,
|
||||
DownstreamAmount: downstream,
|
||||
Amount: upstream,
|
||||
Status: status,
|
||||
StartDate: parsePipelineDate(p.StartDate),
|
||||
EndDate: parsePipelineDate(p.EndDate),
|
||||
UpstreamContact: upContact,
|
||||
UpstreamPhone: upPhone,
|
||||
DownstreamContact: downContact,
|
||||
DownstreamPhone: downPhone,
|
||||
ContactPerson: upContact,
|
||||
ContactPhone: upPhone,
|
||||
Address: strings.TrimSpace(p.Address),
|
||||
Remark: p.Remark,
|
||||
CreateUserID: pipelineUID(cl),
|
||||
CreateTime: now,
|
||||
UpdateTime: now,
|
||||
}
|
||||
if crmProjectNameDuplicated(tenantID, proj.ProjectName, proj.CustomerID, proj.CustomerRefType) {
|
||||
c.erpFail(409, 409, "该客户下已存在同名项目(可能由其他同事创建)")
|
||||
return
|
||||
}
|
||||
id, err := models.Orm.Insert(&proj)
|
||||
if err != nil {
|
||||
c.erpFail(500, 500, "创建失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
if cid, err := services.EnsureCrmProjectDocCategory(cl.TenantId, uint64(id), proj.ProjectName, 0); err == nil {
|
||||
proj.DocCategoryID = cid
|
||||
}
|
||||
crmWriteLog(tenantID, 3, uint64(id), "create", "创建项目:"+proj.ProjectName, cl)
|
||||
c.erpOk(map[string]interface{}{"id": id, "doc_category_id": proj.DocCategoryID})
|
||||
}
|
||||
|
||||
func (c *AppCrmProjectController) updateProject(cl *jwtutil.Claims, tenantID string, p *crmProjectSavePayload) {
|
||||
var proj models.TenantCrmProject
|
||||
if err := models.Orm.QueryTable(new(models.TenantCrmProject)).
|
||||
Filter("id", p.ID).Filter("tenant_id", tenantID).
|
||||
Filter("delete_time__isnull", true).One(&proj); err != nil {
|
||||
c.erpFail(404, 404, "项目未找到")
|
||||
return
|
||||
}
|
||||
if !canAccessCrmRecord(cl, proj.OwnerUserID, proj.CreateUserID) {
|
||||
c.erpFail(403, 403, "无权操作该项目数据")
|
||||
return
|
||||
}
|
||||
|
||||
proj.ProjectName = strings.TrimSpace(p.ProjectName)
|
||||
proj.ProjectNo = strings.TrimSpace(p.ProjectNo)
|
||||
if p.CustomerID > 0 {
|
||||
cid, cref, cname := resolveProjectCustomer(tenantID, p.CustomerRefType, p.CustomerID, p.CustomerName)
|
||||
proj.CustomerID = cid
|
||||
proj.CustomerRefType = cref
|
||||
proj.CustomerName = cname
|
||||
} else if strings.TrimSpace(p.CustomerName) != "" {
|
||||
proj.CustomerName = strings.TrimSpace(p.CustomerName)
|
||||
}
|
||||
if strings.TrimSpace(p.OwnerUserID) != "" {
|
||||
proj.OwnerUserID = strings.TrimSpace(p.OwnerUserID)
|
||||
}
|
||||
if strings.TrimSpace(p.OwnerUserName) != "" {
|
||||
proj.OwnerUserName = strings.TrimSpace(p.OwnerUserName)
|
||||
}
|
||||
proj.Industry = strings.TrimSpace(p.Industry)
|
||||
pt, upstream, downstream, upContact, upPhone, downContact, downPhone := normalizeProjectFields(&p.projectPayload)
|
||||
supplierID, supplierRefType, supplierName := resolveProjectSupplier(tenantID, p.SupplierRefType, p.SupplierID, p.SupplierName)
|
||||
if pt == 1 {
|
||||
supplierID, supplierRefType, supplierName = nil, 0, ""
|
||||
}
|
||||
proj.ProjectType = pt
|
||||
proj.SupplierID = supplierID
|
||||
proj.SupplierRefType = supplierRefType
|
||||
proj.SupplierName = supplierName
|
||||
proj.SupplierIndustry = strings.TrimSpace(p.SupplierIndustry)
|
||||
proj.UpstreamAmount = upstream
|
||||
proj.DownstreamAmount = downstream
|
||||
proj.Amount = upstream
|
||||
proj.UpstreamContact = upContact
|
||||
proj.UpstreamPhone = upPhone
|
||||
proj.DownstreamContact = downContact
|
||||
proj.DownstreamPhone = downPhone
|
||||
proj.ContactPerson = upContact
|
||||
proj.ContactPhone = upPhone
|
||||
|
||||
prevStatus := proj.Status
|
||||
if p.Status != 0 {
|
||||
proj.Status = p.Status
|
||||
}
|
||||
proj.StartDate = parsePipelineDate(p.StartDate)
|
||||
proj.EndDate = parsePipelineDate(p.EndDate)
|
||||
proj.Address = strings.TrimSpace(p.Address)
|
||||
proj.Remark = p.Remark
|
||||
proj.UpdateTime = time.Now()
|
||||
|
||||
statusChanged := p.Status != 0 && p.Status != prevStatus
|
||||
reason := strings.TrimSpace(p.Reason)
|
||||
if p.Status == 5 && prevStatus != 5 && reason == "" {
|
||||
c.erpFail(400, 400, "请填写项目异常原因")
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := models.Orm.Update(&proj); err != nil {
|
||||
c.erpFail(500, 500, "更新失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
if proj.DocCategoryID > 0 {
|
||||
_ = services.RenameCrmProjectDocCategory(cl.TenantId, proj.DocCategoryID, proj.ProjectName)
|
||||
}
|
||||
if statusChanged {
|
||||
logText := "项目状态:" + projectStatusName(prevStatus) + " → " + projectStatusName(proj.Status)
|
||||
if proj.Status == 5 && reason != "" {
|
||||
logText += ";异常原因:" + reason
|
||||
}
|
||||
crmWriteLog(tenantID, 3, proj.ID, "status", logText, cl)
|
||||
}
|
||||
crmWriteLog(tenantID, 3, proj.ID, "update", "更新项目:"+proj.ProjectName, cl)
|
||||
c.erpOk(map[string]interface{}{"id": proj.ID})
|
||||
}
|
||||
|
||||
// ChangeStatus POST /api/crm/project/status/:id
|
||||
func (c *AppCrmProjectController) ChangeStatus() {
|
||||
cl, err := c.erpClaims()
|
||||
if c.erpDenied(err) {
|
||||
return
|
||||
}
|
||||
id := c.erpPathID()
|
||||
if id == 0 {
|
||||
c.erpFail(400, 400, "无效的ID")
|
||||
return
|
||||
}
|
||||
var body struct {
|
||||
Status int8 `json:"status"`
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
if !c.erpBody(&body, false) {
|
||||
return
|
||||
}
|
||||
if body.Status < 1 || body.Status > 5 {
|
||||
c.erpFail(400, 400, "项目状态不合法")
|
||||
return
|
||||
}
|
||||
reason := strings.TrimSpace(body.Reason)
|
||||
if body.Status == 5 && reason == "" {
|
||||
c.erpFail(400, 400, "请填写项目异常原因")
|
||||
return
|
||||
}
|
||||
tenantID := pipelineTenantID(cl)
|
||||
var proj models.TenantCrmProject
|
||||
if err := models.Orm.QueryTable(new(models.TenantCrmProject)).
|
||||
Filter("id", id).Filter("tenant_id", tenantID).
|
||||
Filter("delete_time__isnull", true).One(&proj); err != nil {
|
||||
c.erpFail(404, 404, "项目未找到")
|
||||
return
|
||||
}
|
||||
if !canAccessCrmRecord(cl, proj.OwnerUserID, proj.CreateUserID) {
|
||||
c.erpFail(403, 403, "无权操作该项目数据")
|
||||
return
|
||||
}
|
||||
prevStatus := proj.Status
|
||||
proj.Status = body.Status
|
||||
proj.UpdateTime = time.Now()
|
||||
if _, err := models.Orm.Update(&proj); err != nil {
|
||||
c.erpFail(500, 500, "状态更新失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
logText := "项目状态:" + projectStatusName(prevStatus) + " → " + projectStatusName(proj.Status)
|
||||
if proj.Status == 5 && reason != "" {
|
||||
logText += ";异常原因:" + reason
|
||||
}
|
||||
crmWriteLog(tenantID, 3, proj.ID, "status", logText, cl)
|
||||
c.erpOk(map[string]interface{}{"id": proj.ID, "status": proj.Status})
|
||||
}
|
||||
|
||||
// Delete DELETE /api/crm/project/delete/:id
|
||||
func (c *AppCrmProjectController) Delete() {
|
||||
cl, err := c.erpClaims()
|
||||
if c.erpDenied(err) {
|
||||
return
|
||||
}
|
||||
id := c.erpPathID()
|
||||
if id == 0 {
|
||||
c.erpFail(400, 400, "无效的ID")
|
||||
return
|
||||
}
|
||||
tenantID := pipelineTenantID(cl)
|
||||
var proj models.TenantCrmProject
|
||||
if err := models.Orm.QueryTable(new(models.TenantCrmProject)).
|
||||
Filter("id", id).Filter("tenant_id", tenantID).
|
||||
Filter("delete_time__isnull", true).One(&proj); err != nil {
|
||||
c.erpFail(404, 404, "项目未找到")
|
||||
return
|
||||
}
|
||||
if !canAccessCrmRecord(cl, proj.OwnerUserID, proj.CreateUserID) {
|
||||
c.erpFail(403, 403, "无权操作该项目数据")
|
||||
return
|
||||
}
|
||||
if !canDeleteCrmRecord(cl, proj.CreateUserID) {
|
||||
c.erpFail(403, 403, "只有创建人、租户管理员或平台管理员可以删除该项目")
|
||||
return
|
||||
}
|
||||
now := time.Now()
|
||||
if _, err := models.Orm.QueryTable(new(models.TenantCrmProject)).
|
||||
Filter("id", id).Filter("tenant_id", tenantID).
|
||||
Update(map[string]interface{}{"delete_time": now, "update_time": now}); err != nil {
|
||||
c.erpFail(500, 500, "删除失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
crmWriteLog(tenantID, 3, proj.ID, "delete", "删除项目:"+proj.ProjectName, cl)
|
||||
c.erpOk(map[string]interface{}{"id": proj.ID})
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"server/services"
|
||||
authsvc "server/services/auth"
|
||||
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// AuthCodeLoginController 手机号/邮箱验证码登录(统一认证体系)。
|
||||
type AuthCodeLoginController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
func (c *AuthCodeLoginController) serveJSON(data map[string]interface{}) {
|
||||
c.Data["json"] = data
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
func (c *AuthCodeLoginController) fail(bizCode int, msg string) {
|
||||
c.Ctx.Output.SetStatus(400)
|
||||
c.serveJSON(map[string]interface{}{"code": bizCode, "msg": msg})
|
||||
}
|
||||
|
||||
func (c *AuthCodeLoginController) readBody() map[string]interface{} {
|
||||
body := c.Ctx.Input.RequestBody
|
||||
if len(body) == 0 {
|
||||
body, _ = io.ReadAll(c.Ctx.Request.Body)
|
||||
}
|
||||
var req map[string]interface{}
|
||||
if err := json.Unmarshal(body, &req); err != nil {
|
||||
return map[string]interface{}{}
|
||||
}
|
||||
return req
|
||||
}
|
||||
|
||||
func codeLoginString(req map[string]interface{}, key string) string {
|
||||
if req == nil {
|
||||
return ""
|
||||
}
|
||||
if v, ok := req[key].(string); ok {
|
||||
return strings.TrimSpace(v)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// SendCode 发送登录验证码。account 为手机号或邮箱,channel 为 sms/email。
|
||||
func (c *AuthCodeLoginController) SendCode() {
|
||||
req := c.readBody()
|
||||
account := codeLoginString(req, "account")
|
||||
channel := codeLoginString(req, "channel")
|
||||
if account == "" {
|
||||
c.fail(400, "请输入手机号或邮箱")
|
||||
return
|
||||
}
|
||||
if channel == "" {
|
||||
if services.IsEmail(account) {
|
||||
channel = "email"
|
||||
} else if services.IsMobile(account) {
|
||||
channel = "sms"
|
||||
}
|
||||
}
|
||||
if channel == "sms" && !services.IsMobile(account) {
|
||||
c.fail(400, "请输入正确的手机号")
|
||||
return
|
||||
}
|
||||
if channel == "email" && !services.IsEmail(account) {
|
||||
c.fail(400, "请输入正确的邮箱")
|
||||
return
|
||||
}
|
||||
|
||||
var err error
|
||||
if channel == "email" {
|
||||
err = services.SendIdentityEmailCode("login", account)
|
||||
} else {
|
||||
err = services.SendIdentityCode("login", account)
|
||||
}
|
||||
if err != nil {
|
||||
c.fail(400, err.Error())
|
||||
return
|
||||
}
|
||||
c.serveJSON(map[string]interface{}{"code": 200, "msg": "验证码已发送"})
|
||||
}
|
||||
|
||||
// Login 验证码登录。校验验证码后签发统一认证登录态。
|
||||
func (c *AuthCodeLoginController) Login() {
|
||||
req := c.readBody()
|
||||
account := codeLoginString(req, "account")
|
||||
code := codeLoginString(req, "code")
|
||||
channel := codeLoginString(req, "channel")
|
||||
clientID := codeLoginString(req, "client_id")
|
||||
if clientID == "" {
|
||||
clientID = "yz-miniapp"
|
||||
}
|
||||
if account == "" || code == "" {
|
||||
c.fail(400, "请输入手机号/邮箱和验证码")
|
||||
return
|
||||
}
|
||||
if channel == "" {
|
||||
if services.IsEmail(account) {
|
||||
channel = "email"
|
||||
} else {
|
||||
channel = "sms"
|
||||
}
|
||||
}
|
||||
|
||||
var verifyErr error
|
||||
if channel == "email" {
|
||||
verifyErr = services.VerifyIdentityEmailCode("login", account, code)
|
||||
} else {
|
||||
verifyErr = services.VerifyIdentityCode("login", account, code)
|
||||
}
|
||||
if verifyErr != nil {
|
||||
c.fail(400, verifyErr.Error())
|
||||
return
|
||||
}
|
||||
|
||||
identity, err := authsvc.FindIdentityByAccount(account)
|
||||
if err != nil || identity == nil {
|
||||
c.fail(404, "账号不存在")
|
||||
return
|
||||
}
|
||||
|
||||
amr := authsvc.AmrSms
|
||||
loginType := "sms"
|
||||
if channel == "email" {
|
||||
amr = "email"
|
||||
loginType = "email"
|
||||
}
|
||||
|
||||
clientIP := c.Ctx.Input.IP()
|
||||
userAgent := c.Ctx.Request.UserAgent()
|
||||
result, err := authsvc.CodeLogin(identity, clientID, clientIP, userAgent, amr, loginType)
|
||||
if err != nil {
|
||||
if err == authsvc.ErrNoTenantBound {
|
||||
c.fail(403, err.Error())
|
||||
return
|
||||
}
|
||||
logs.Warn("[auth-code-login] 登录失败: %v", err)
|
||||
c.fail(400, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := map[string]interface{}{
|
||||
"code": 200,
|
||||
"msg": "登录成功",
|
||||
"tokens": result.Tokens,
|
||||
"tenants": result.Tenants,
|
||||
"identity": result.Identity,
|
||||
}
|
||||
if result.NeedChooseTenant {
|
||||
resp["need_choose_tenant"] = true
|
||||
resp["sid"] = result.Tokens.Sid
|
||||
}
|
||||
c.serveJSON(resp)
|
||||
}
|
||||
@@ -305,6 +305,7 @@ func (c *BackendProductPurchaseController) GetPackageList() {
|
||||
if _, err := models.Orm.QueryTable(new(models.SystemTenantPackage)).
|
||||
Filter("delete_time__isnull", true).
|
||||
Filter("status", 1).
|
||||
Filter("can_purchase", 1).
|
||||
OrderBy("sort", "id").
|
||||
All(&rows); err != nil {
|
||||
c.jsonErr(500, 500, "获取失败:"+err.Error())
|
||||
@@ -349,6 +350,7 @@ func (c *BackendProductPurchaseController) GetPackageList() {
|
||||
"extra_user_price": r.ExtraUserPrice,
|
||||
"is_default": r.IsDefault,
|
||||
"allow_repurchase": r.AllowRepurchase,
|
||||
"can_purchase": r.CanPurchase,
|
||||
"purchased": purchased[r.ID],
|
||||
"sort": r.Sort,
|
||||
"status": r.Status,
|
||||
@@ -378,6 +380,7 @@ func (c *BackendProductPurchaseController) GetPackageDetailByCode() {
|
||||
Filter("code", code).
|
||||
Filter("delete_time__isnull", true).
|
||||
Filter("status", 1).
|
||||
Filter("can_purchase", 1).
|
||||
One(&row); err != nil {
|
||||
c.jsonErr(404, 404, "套餐不存在或已下架")
|
||||
return
|
||||
@@ -448,6 +451,10 @@ func (c *BackendProductPurchaseController) CreatePackageOrder() {
|
||||
c.jsonErr(404, 404, "套餐不存在或已下架")
|
||||
return
|
||||
}
|
||||
if pkg.CanPurchase == 0 {
|
||||
c.jsonErr(403, 403, "该套餐暂不支持购买,请联系平台管理员")
|
||||
return
|
||||
}
|
||||
if pkg.Price <= 0 {
|
||||
c.jsonErr(400, 400, "该套餐未配置价格,请联系平台")
|
||||
return
|
||||
|
||||
@@ -38,6 +38,8 @@ type tenantDTO struct {
|
||||
UserQuota int `json:"user_quota"`
|
||||
UserUsed int `json:"user_used"`
|
||||
StorageQuotaMB int `json:"storage_quota_mb"`
|
||||
StorageUsedMB float64 `json:"storage_used_mb"`
|
||||
StoragePercent float64 `json:"storage_percent"`
|
||||
Remark string `json:"remark"`
|
||||
CreateTime *time.Time `json:"create_time,omitempty"`
|
||||
UpdateTime *time.Time `json:"update_time,omitempty"`
|
||||
@@ -164,6 +166,11 @@ func (c *PlatformTenantController) GetTenant() {
|
||||
dto := toTenantDTO(t)
|
||||
dto.PackageName = packageNames[t.PackageID]
|
||||
dto.UserUsed = userCounts[t.ID]
|
||||
if info, ierr := services.GetTenantStorageInfo(t.ID); ierr == nil && info != nil {
|
||||
dto.StorageQuotaMB = info.QuotaMB
|
||||
dto.StorageUsedMB = math.Round(float64(info.UsedBytes)/float64(1024*1024)*10) / 10
|
||||
dto.StoragePercent = info.UsedPercent
|
||||
}
|
||||
list = append(list, dto)
|
||||
}
|
||||
|
||||
|
||||
@@ -92,6 +92,7 @@ type tenantPackagePayload struct {
|
||||
ExtraUserPrice *float64 `json:"extra_user_price"`
|
||||
IsDefault *int8 `json:"is_default"`
|
||||
AllowRepurchase *int8 `json:"allow_repurchase"`
|
||||
CanPurchase *int8 `json:"can_purchase"`
|
||||
Sort *int `json:"sort"`
|
||||
Status *int8 `json:"status"`
|
||||
Remark string `json:"remark"`
|
||||
@@ -182,6 +183,7 @@ func (c *PlatformTenantPackageController) GetPackageList() {
|
||||
"extra_user_price": r.ExtraUserPrice,
|
||||
"is_default": r.IsDefault,
|
||||
"allow_repurchase": r.AllowRepurchase,
|
||||
"can_purchase": r.CanPurchase,
|
||||
"sort": r.Sort,
|
||||
"status": r.Status,
|
||||
"remark": r.Remark,
|
||||
@@ -241,6 +243,7 @@ func (c *PlatformTenantPackageController) GetPackageSelectList() {
|
||||
"extra_user_price": r.ExtraUserPrice,
|
||||
"is_default": r.IsDefault,
|
||||
"allow_repurchase": r.AllowRepurchase,
|
||||
"can_purchase": r.CanPurchase,
|
||||
"modules": modules,
|
||||
"module_codes": moduleCodes(modules),
|
||||
})
|
||||
@@ -401,6 +404,7 @@ func (c *PlatformTenantPackageController) CreatePackage() {
|
||||
ExtraUserPrice: valueFloat(p.ExtraUserPrice, services.DefaultTenantExtraUserPrice),
|
||||
IsDefault: valueInt8(p.IsDefault, 0),
|
||||
AllowRepurchase: valueInt8(p.AllowRepurchase, 1),
|
||||
CanPurchase: valueInt8(p.CanPurchase, 1),
|
||||
Sort: valueInt(p.Sort, 0),
|
||||
Status: valueInt8(p.Status, 1),
|
||||
Remark: strings.TrimSpace(p.Remark),
|
||||
@@ -491,6 +495,9 @@ func (c *PlatformTenantPackageController) EditPackage() {
|
||||
if p.AllowRepurchase != nil {
|
||||
update["allow_repurchase"] = *p.AllowRepurchase
|
||||
}
|
||||
if p.CanPurchase != nil {
|
||||
update["can_purchase"] = *p.CanPurchase
|
||||
}
|
||||
|
||||
allowRepurchase := int8(1)
|
||||
if p.AllowRepurchase != nil {
|
||||
|
||||
Reference in new issue
Block a user