zhangqian
2023-10-13 b90a31431164b4b0756e4ef76f08b08953b8b04d
服务合同简单数据权限
3个文件已修改
30 ■■■■ 已修改文件
api/v1/serviceContract.go 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/serviceContract.go 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/serviceContract.go 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/serviceContract.go
@@ -1,12 +1,14 @@
package v1
import (
    "aps_crm/constvar"
    "aps_crm/model"
    "aps_crm/model/request"
    "aps_crm/model/response"
    "aps_crm/pkg/contextx"
    "aps_crm/pkg/ecode"
    "aps_crm/pkg/structx"
    "aps_crm/utils"
    "github.com/gin-gonic/gin"
)
@@ -136,7 +138,13 @@
        return
    }
    serviceContracts, total, errCode := serviceContractService.GetServiceContractList(params.Page, params.PageSize, params.QueryClass, params.KeywordType, params.Keyword)
    var memberIds []int
    userInfo := utils.GetUserInfo(c)
    if userInfo.UserType == constvar.UserTypeSub {
        memberIds = []int{userInfo.CrmUserId}
    }
    serviceContracts, total, errCode := serviceContractService.GetServiceContractList(params.Page, params.PageSize, params.QueryClass, params.KeywordType, params.Keyword, memberIds)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
model/serviceContract.go
@@ -36,11 +36,11 @@
        ServiceTimes            int                   `json:"serviceTimes" gorm:"column:service_times;type:int;comment:服务次数"`
        Terms                   string                `json:"terms" gorm:"column:terms;type:text;comment:条款"`
        Remark                  string                `json:"remark" gorm:"column:remark;type:text;comment:备注"`
        AmountReceivable        decimal.Decimal       `gorm:"column:amount_receivable;type:decimal(12,2);comment:应收金额" json:"amountReceivable"`    // 应收金额
        AmountReceived          decimal.Decimal       `gorm:"column:amount_received;type:decimal(12,2);comment:已收金额" json:"amountReceived"`        // 已收金额
        AmountReceivable        decimal.Decimal       `gorm:"column:amount_receivable;type:decimal(12,2);comment:应收金额" json:"amountReceivable"`     // 应收金额
        AmountReceived          decimal.Decimal       `gorm:"column:amount_received;type:decimal(12,2);comment:已收金额" json:"amountReceived"`         // 已收金额
        AmountInvoiced          decimal.Decimal       `gorm:"column:amount_invoiced;type:decimal(12,2);comment:已开票金额" json:"amountInvoiced"`       // 已开票金额
        AmountUnInvoiced        decimal.Decimal       `gorm:"column:amount_not_invoiced;type:decimal(12,2);comment:未开票金额" json:"amountUnInvoiced"` // 未开票金额
        AmountTotal             decimal.Decimal       `gorm:"column:amount_total;type:decimal(12,2);comment:价税合计" json:"amountTotal"`              // 价税合计
        AmountTotal             decimal.Decimal       `gorm:"column:amount_total;type:decimal(12,2);comment:价税合计" json:"amountTotal"`               // 价税合计
        Products                []*Product            `json:"products" gorm:"many2many:service_contract_product;"`
        CrmModel
    }
@@ -55,6 +55,7 @@
        PageNum     int
        PageSize    int
        Preload     bool
        MemberIds   []int
    }
)
@@ -108,6 +109,11 @@
        db = db.Where("amount_receivable = ?", slf.Keyword)
    }
    if len(slf.MemberIds) > 0 {
        db = db.Where("member_id in ?", slf.MemberIds)
    }
    if slf.Preload {
        db = db.
            Preload("Client").
@@ -198,6 +204,11 @@
    return slf
}
func (slf *ServiceContractSearch) SetMemberIds(memberIds []int) *ServiceContractSearch {
    slf.MemberIds = memberIds
    return slf
}
func (slf *ServiceContractSearch) SetPreload(preload bool) *ServiceContractSearch {
    slf.Preload = preload
    return slf
service/serviceContract.go
@@ -117,12 +117,13 @@
    return ecode.OK
}
func (SContractService) GetServiceContractList(page, pageSize int, queryClass constvar.ServiceContractQueryClass, keywordType constvar.ServiceContractKeywordType, keyword string) ([]*model.ServiceContract, int64, int) {
func (SContractService) GetServiceContractList(page, pageSize int, queryClass constvar.ServiceContractQueryClass, keywordType constvar.ServiceContractKeywordType, keyword string, memberIds []int) ([]*model.ServiceContract, int64, int) {
    // get contact list
    contacts, total, err := model.NewServiceContractSearch().
        SetKeyword(keyword).
        SetKeywordType(keywordType).
        SetQueryClass(queryClass).
        SetMemberIds(memberIds).
        SetPage(page, pageSize).
        SetPreload(true).
        Find()