zhangqian
2023-10-30 4d0b38be2e3977ec390f70de2f022fe96c4cbb61
数据权限支持职级
32个文件已修改
189 ■■■■ 已修改文件
api/v1/client.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/contact.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/contract.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/followRecord.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/invoice.go 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/masterOrder.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/plan.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/quotation.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/receipt.go 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/saleChance.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/subOrder.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
conf/aps-crm.json 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
main.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/client.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/contact.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/contract.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/followRecord.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/invoice.go 21 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/masterOrder.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/plan.go 19 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/quotation.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/receipt.go 21 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/invoice.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/receipt.go 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/saleChance.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/salesLeads.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/serviceFeeManage.go 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/serviceOrder.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/subOrder.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/user.go 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/invoice.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/receipt.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/client.go
@@ -220,7 +220,7 @@
        if params.SearchMap == nil {
            params.SearchMap = make(map[string]interface{}, 0)
        }
        params.SearchMap["member_id"] = userInfo.CrmUserId
        params.SearchMap["member_ids"] = userInfo.SubUserIds
    }
    clients, total, errCode := clientService.GetClientList(params.Page, params.PageSize, params.SearchMap)
api/v1/contact.go
@@ -181,7 +181,7 @@
        if params.SearchMap == nil {
            params.SearchMap = make(map[string]interface{}, 0)
        }
        params.SearchMap["member_id"] = userInfo.CrmUserId
        params.SearchMap["member_ids"] = userInfo.SubUserIds
    }
    contacts, total, errCode := contactService.GetContactList(params.Page, params.PageSize, params.SearchMap, params.ClientId)
api/v1/contract.go
@@ -166,7 +166,7 @@
        if params.SearchMap == nil {
            params.SearchMap = make(map[string]interface{}, 0)
        }
        params.SearchMap["member_id"] = userInfo.CrmUserId
        params.SearchMap["member_ids"] = userInfo.SubUserIds
    }
    contracts, total, errCode := contractService.GetContractList(params.Page, params.PageSize, params.SearchMap)
api/v1/followRecord.go
@@ -246,7 +246,7 @@
        if params.SearchMap == nil {
            params.SearchMap = make(map[string]interface{}, 0)
        }
        params.SearchMap["member_id"] = userInfo.CrmUserId
        params.SearchMap["member_ids"] = userInfo.SubUserIds
    }
    followRecords, total, errCode := followRecordService.GetFollowRecordList(params.Page, params.PageSize, params.SearchMap)
api/v1/invoice.go
@@ -1,6 +1,7 @@
package v1
import (
    "aps_crm/constvar"
    "aps_crm/model"
    "aps_crm/model/request"
    "aps_crm/model/response"
@@ -8,6 +9,7 @@
    "aps_crm/pkg/ecode"
    "aps_crm/pkg/structx"
    "aps_crm/service"
    "aps_crm/utils"
    "github.com/gin-gonic/gin"
    "strconv"
)
@@ -123,6 +125,11 @@
        return
    }
    userInfo := utils.GetUserInfo(c)
    if userInfo.UserType == constvar.UserTypeSub {
        params.PrincipalIds = userInfo.SubUserIds
    }
    invoice, total, errCode := service.NewInvoiceService().GetInvoiceList(params)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
api/v1/masterOrder.go
@@ -168,7 +168,7 @@
        if params.SearchMap == nil {
            params.SearchMap = make(map[string]interface{}, 0)
        }
        params.SearchMap["member_id"] = userInfo.CrmUserId
        params.SearchMap["member_ids"] = userInfo.SubUserIds
    }
    masterOrders, total, errCode := masterOrderService.GetMasterOrderList(params.Page, params.PageSize, params.SearchMap)
api/v1/plan.go
@@ -98,7 +98,6 @@
    ctx.Ok()
}
func checkPlanParams(plan request.Plan) (errCode int, p model.Plan) {
    //if plan.Number == "" {
    //    return ecode.InvalidParams, p
@@ -155,7 +154,7 @@
    }
    ctx.OkWithDetailed(response.PlanResponse{
        List: plans,
        List:  plans,
        Count: int(total),
    })
}
}
api/v1/quotation.go
@@ -186,7 +186,7 @@
        if params.SearchMap == nil {
            params.SearchMap = make(map[string]interface{}, 0)
        }
        params.SearchMap["member_id"] = userInfo.CrmUserId
        params.SearchMap["member_ids"] = userInfo.CrmUserId
    }
    quotations, total, errCode := quotationService.GetQuotationList(params.Page, params.PageSize, params.SearchMap)
api/v1/receipt.go
@@ -1,11 +1,13 @@
package v1
import (
    "aps_crm/constvar"
    "aps_crm/model/request"
    "aps_crm/model/response"
    "aps_crm/pkg/contextx"
    "aps_crm/pkg/ecode"
    "aps_crm/service"
    "aps_crm/utils"
    "github.com/gin-gonic/gin"
    "strconv"
)
@@ -99,6 +101,11 @@
        return
    }
    userInfo := utils.GetUserInfo(c)
    if userInfo.UserType == constvar.UserTypeSub {
        params.PrincipleIds = userInfo.SubUserIds
    }
    receipt, total, errCode := service.NewReceiptService().GetReceiptList(params)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
api/v1/saleChance.go
@@ -226,7 +226,7 @@
        if params.SearchMap == nil {
            params.SearchMap = make(map[string]interface{}, 0)
        }
        params.SearchMap["member_id"] = userInfo.CrmUserId
        params.SearchMap["member_ids"] = userInfo.SubUserIds
    }
    saleChances, total, errCode := saleChanceService.GetSaleChanceList(params.Page, params.PageSize, params.SearchMap)
api/v1/subOrder.go
@@ -157,7 +157,7 @@
        if params.SearchMap == nil {
            params.SearchMap = make(map[string]interface{}, 0)
        }
        params.SearchMap["member_id"] = userInfo.CrmUserId
        params.SearchMap["member_ids"] = userInfo.SubUserIds
    }
    subOrders, total, errCode := subOrderService.GetSubOrderList(params.Page, params.PageSize, params.SearchMap)
conf/aps-crm.json
@@ -48,8 +48,8 @@
    "Issuer": "qmPlus"
  },
  "GrpcServiceAddr": {
    "Aps": "192.168.20.119:9091",
    "Admin": "192.168.20.119:50051"
    "Aps": "192.168.20.120:9091",
    "Admin": "192.168.20.120:50051"
  }
}
main.go
@@ -50,7 +50,7 @@
    middleware.InitUserConn()
    v1.InitCodeServiceConn()
    middleware.InitRefreshUserManager(5, 5, 3600)
    middleware.InitRefreshUserManager(1, 5, 3600)
    middleware.RunRefreshUser() ///定时对活跃用户更新用户详情
    logx.Error(server.ListenAndServe().Error())
model/client.go
@@ -129,6 +129,10 @@
                        db = db.Where("clients.member_id = ?", constvar.UserTypeSuper)
                    }
                }
            case []int:
                if key == "member_ids" {
                    db = db.Where("clients.member_id in ?", v)
                }
            }
        }
model/contact.go
@@ -100,6 +100,10 @@
                if key == "client_id" {
                    db = db.Where("client_id = ? and is_first = true", v)
                }
            case []int:
                if key == "member_ids" {
                    db = db.Where("contacts.member_id in ?", v)
                }
            }
        }
    }
model/contract.go
@@ -80,6 +80,10 @@
                if key == "member_id" {
                    db = db.Where(key+"= ?", v)
                }
            case []int:
                if key == "member_ids" {
                    db = db.Where("contract.member_id in ?", v)
                }
            }
        }
    }
model/followRecord.go
@@ -106,6 +106,10 @@
                if key == "client_id" || key == "contact_id" || key == "sales_leads_id" || key == "sale_chance_id" || key == "member_id" {
                    db = db.Where(key+" = ?", v)
                }
            case []int:
                if key == "member_ids" {
                    db = db.Where("follow_records.member_id in ?", v)
                }
            }
        }
    }
model/invoice.go
@@ -36,12 +36,13 @@
    // InvoiceSearch 销售发票搜索条件
    InvoiceSearch struct {
        Invoice
        Orm         *gorm.DB
        QueryClass  constvar.InvoiceQueryClass
        KeywordType constvar.InvoiceKeywordType
        Keyword     string
        PageNum     int
        PageSize    int
        Orm          *gorm.DB
        QueryClass   constvar.InvoiceQueryClass
        KeywordType  constvar.InvoiceKeywordType
        Keyword      string
        PageNum      int
        PageSize     int
        PrincipalIds []int
    }
)
@@ -65,6 +66,11 @@
    return slf
}
func (slf *InvoiceSearch) SetPrincipalIds(principalIds []int) *InvoiceSearch {
    slf.PrincipalIds = principalIds
    return slf
}
func (slf *InvoiceSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&Invoice{})
    if slf.Id != 0 {
@@ -81,6 +87,9 @@
    if slf.Number != "" {
        db.Where("number = ?", slf.Number)
    }
    if len(slf.PrincipalIds) > 0 {
        db = db.Where("principal_id in ?", slf.PrincipalIds)
    }
    return db
}
model/masterOrder.go
@@ -72,6 +72,10 @@
                if key == "client_id" || key == "member_id" || key == "money" {
                    db = db.Where(key+" = ?", v)
                }
            case []int:
                if key == "member_ids" {
                    db = db.Where("master_order.member_id in ?", v)
                }
            }
        }
    }
model/plan.go
@@ -25,11 +25,12 @@
    PlanSearch struct {
        Plan
        Orm      *gorm.DB
        Keyword  string
        OrderBy  string
        PageNum  int
        PageSize int
        Orm       *gorm.DB
        Keyword   string
        OrderBy   string
        PageNum   int
        PageSize  int
        MemberIds []int
    }
)
@@ -50,6 +51,9 @@
    }
    if slf.Id != 0 {
        db = db.Where("id = ?", slf.Id)
    }
    if len(slf.MemberIds) != 0 {
        db = db.Where("member_id in ?", slf.MemberIds)
    }
    return db
@@ -97,6 +101,11 @@
    return slf
}
func (slf *PlanSearch) SetMemberIds(ids []int) *PlanSearch {
    slf.MemberIds = ids
    return slf
}
func (slf *PlanSearch) SetKeyword(keyword string) *PlanSearch {
    slf.Keyword = keyword
    return slf
model/quotation.go
@@ -88,6 +88,10 @@
                if key == "client_id" || key == "sale_chance_id" || key == "member_id" {
                    db = db.Where(key+" = ?", v)
                }
            case []int:
                if key == "member_ids" {
                    db = db.Where("quotation.member_id in ?", v)
                }
            }
        }
    }
model/receipt.go
@@ -34,12 +34,13 @@
    // ReceiptSearch 收款单搜索条件
    ReceiptSearch struct {
        Receipt
        Orm         *gorm.DB
        QueryClass  constvar.ReceiptQueryClass
        KeywordType constvar.ReceiptKeywordType
        Keyword     string
        PageNum     int
        PageSize    int
        Orm          *gorm.DB
        QueryClass   constvar.ReceiptQueryClass
        KeywordType  constvar.ReceiptKeywordType
        Keyword      string
        PageNum      int
        PageSize     int
        PrincipalIds []int
    }
)
@@ -72,6 +73,11 @@
    return slf
}
func (slf *ReceiptSearch) SetPrincipalIds(principalIds []int) *ReceiptSearch {
    slf.PrincipalIds = principalIds
    return slf
}
func (slf *ReceiptSearch) SetPage(page, size int) *ReceiptSearch {
    slf.PageNum, slf.PageSize = page, size
    return slf
@@ -91,6 +97,9 @@
    if slf.ClientId != 0 {
        db = db.Where("client_id = ?", slf.ClientId)
    }
    if len(slf.PrincipalIds) != 0 {
        db = db.Where("principal_id in ?", slf.PrincipalIds)
    }
    return db
}
model/request/invoice.go
@@ -44,6 +44,7 @@
type GetInvoiceList struct {
    PageInfo
    SourceId   int                        `json:"sourceId"`
    SourceType constvar.InvoiceSourceType `json:"sourceType"` // 源单类型(1销售明细单2服务合同)
    SourceId     int                        `json:"sourceId"`
    SourceType   constvar.InvoiceSourceType `json:"sourceType"` // 源单类型(1销售明细单2服务合同)
    PrincipalIds []int
}
model/request/receipt.go
@@ -16,7 +16,8 @@
type GetReceiptList struct {
    PageInfo
    SourceType constvar.ReceiptSourceType `json:"sourceType" form:"sourceType"` //来源类型(1销售明细单2服务合同3销售发票4收款计划5出库单)
    SourceId   int                        `json:"sourceId" form:"sourceId"`
    ClientId   int                        `json:"clientId"  form:"clientId"` //客户id
    SourceType   constvar.ReceiptSourceType `json:"sourceType" form:"sourceType"` //来源类型(1销售明细单2服务合同3销售发票4收款计划5出库单)
    SourceId     int                        `json:"sourceId" form:"sourceId"`
    ClientId     int                        `json:"clientId"  form:"clientId"` //客户id
    PrincipleIds []int
}
model/saleChance.go
@@ -121,6 +121,10 @@
                if key == "member_id" || key == "budget" || key == "projected_amount" || key == "client_id" {
                    db = db.Where(key+" = ?", v)
                }
            case []int:
                if key == "member_ids" {
                    db = db.Where("sale_chance.member_id in ?", v)
                }
            }
        }
    }
model/salesLeads.go
@@ -92,6 +92,7 @@
                }
            case int:
            case []int:
                if key == "member_ids" {
                    db = db.Where("sales_leads.member_id in ?", v)
                }
model/serviceFeeManage.go
@@ -28,6 +28,7 @@
        OrderBy     string
        PageNum     int
        PageSize    int
        MemberIds   []int
    }
)
@@ -53,6 +54,11 @@
    if slf.ClientId != 0 {
        db.Where("client_id = ?", slf.ClientId)
    }
    if len(slf.MemberIds) > 0 {
        db.Where("service_fee_manage.member_id in ?", slf.MemberIds)
    }
    switch slf.QueryClass {
    case constvar.ServiceFeeQueryClassExpireLessThen60Days:
        db = db.Where("latest_date > ? and latest_date < ?", time.Now(), time.Now().AddDate(0, 0, 60))
@@ -120,6 +126,11 @@
    return slf
}
func (slf *ServiceFeeManageSearch) SetMemberIds(ids []int) *ServiceFeeManageSearch {
    slf.MemberIds = ids
    return slf
}
func (slf *ServiceFeeManageSearch) SetKeywordType(keyword constvar.ServiceFeeKeywordType) *ServiceFeeManageSearch {
    slf.KeywordType = keyword
    return slf
model/serviceOrder.go
@@ -132,7 +132,7 @@
    }
    if len(slf.ServiceManIds) > 0 {
        db = db.Where("service_man_id in ?", slf.ServiceManIds)
        db = db.Where("service_order.service_man_id in ?", slf.ServiceManIds)
    }
    if slf.ServiceNumber != "" {
        db = db.Where("service_number = ?", slf.ServiceNumber)
model/subOrder.go
@@ -81,6 +81,10 @@
                if key == "member_id" {
                    db = db.Where("sub_order.member_id = ?", v)
                }
            case []int:
                if key == "member_ids" {
                    db = db.Where("sub_order.member_id in ?", v)
                }
            }
        }
    }
model/user.go
@@ -5,14 +5,13 @@
    "aps_crm/pkg/mysqlx"
    "fmt"
    "gorm.io/gorm"
    "gorm.io/gorm/clause"
)
type (
    // User token里边把用户ID、父用户ID、角色都带上
    User struct {
        ID           int               `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
        UUID         string            `json:"uuid" gorm:"unique;type:varchar(255);comment:用户ID"`
        UUID         string            `json:"uuid" gorm:"uniqueIndex;type:varchar(255);comment:用户ID"`
        Username     string            `json:"username" gorm:"index;type:varchar(255);comment:用户登录名"`
        UserType     constvar.UserType `json:"userType" gorm:"type:int(11);comment:用户类型 1超级管理员 2主账户 3子账户"`
        Password     string            `json:"-"  gorm:"type:varchar(255);comment:用户登录密码"`
@@ -294,13 +293,24 @@
}
func (slf *UserSearch) Upsert(record User) error {
    var db = slf.build()
    if err := db.Clauses(clause.OnConflict{
        Columns:   []clause.Column{{Name: "uuid"}},
        DoUpdates: clause.AssignmentColumns([]string{"username", "user_type", "nick_name", "sub_user_ids"}),
    }).Create(&record).Error; err != nil {
        return fmt.Errorf("first or create err: %v, record: %+v", err, record)
    var db = slf.SetId(record.UUID).build()
    old, err := slf.First()
    if err == gorm.ErrRecordNotFound {
        if err := db.Create(&record).Error; err != nil {
            return fmt.Errorf("create user err: %v, record: %+v", err, record)
        }
    } else if old.Username != record.Username ||
        old.UserType != record.UserType ||
        old.NickName != record.NickName ||
        old.SubUserIds != record.SubUserIds {
        old.Username = record.Username
        old.UserType = record.UserType
        old.NickName = record.NickName
        old.SubUserIds = record.SubUserIds
        if err := db.Updates(&record).Error; err != nil {
            return fmt.Errorf("update user err: %v, record: %+v", err, record)
        }
    }
    return nil
service/invoice.go
@@ -140,7 +140,7 @@
}
func (InvoiceService) GetInvoiceList(params request.GetInvoiceList) ([]*model.Invoice, int64, int) {
    list, total, err := model.NewInvoiceSearch().SetSourceId(params.SourceId).SetSourceType(params.SourceType).Find()
    list, total, err := model.NewInvoiceSearch().SetSourceId(params.SourceId).SetSourceType(params.SourceType).SetPrincipalIds(params.PrincipalIds).Find()
    if err != nil {
        return nil, 0, ecode.DBErr
    }
service/receipt.go
@@ -136,6 +136,7 @@
        SetSourceType(params.SourceType).
        SetSourceId(params.SourceId).
        SetClientId(params.ClientId).
        SetPrincipalIds(params.PrincipleIds).
        Find()
    if err != nil {
        return nil, 0, ecode.DBErr