jiangshuai
2023-11-21 91afffaa4f3eb9104d39044197e4140c2044a78c
合同管理列表修改筛选条件
4个文件已修改
22 ■■■■ 已修改文件
api/v1/contract.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/contract.go 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/contract.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/contract.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/contract.go
@@ -169,7 +169,7 @@
        params.SearchMap["member_ids"] = userInfo.SubUserIds
    }
    contracts, total, errCode := contractService.GetContractList(params.Page, params.PageSize, params.SearchMap)
    contracts, total, errCode := contractService.GetContractList(params.Page, params.PageSize, params.SearchMap, params.Keyword)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
model/contract.go
@@ -28,7 +28,7 @@
    ContractSearch struct {
        Contract
        Keyword   string
        Orm       *gorm.DB
        SearchMap map[string]interface{}
        OrderBy   string
@@ -47,6 +47,11 @@
    }
}
func (slf *ContractSearch) SetKeyword(keyword string) *ContractSearch {
    slf.Keyword = keyword
    return slf
}
func (slf *ContractSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&Contract{})
@@ -55,6 +60,10 @@
    }
    if slf.Number != "" {
        db = db.Where("number = ?", slf.Number)
    }
    if slf.Keyword != "" {
        db = db.Joins("Client").Where("contract_name like ? or number like ? or Client.name like ?", fmt.Sprintf("%%%v%%", slf.Keyword), fmt.Sprintf("%%%v%%", slf.Keyword), fmt.Sprintf("%%%v%%", slf.Keyword))
    }
    if len(slf.SearchMap) > 0 {
@@ -76,6 +85,10 @@
                if key == "created_at" {
                    db = db.Where(key+"= ?", v)
                }
                if key == "contract_name" {
                    db = db.Where("contract_name=?", "%"+v+"%")
                }
            case int:
                if key == "member_id" {
                    db = db.Where(key+"= ?", v)
model/request/contract.go
@@ -24,6 +24,7 @@
type GetContractList struct {
    PageInfo
    SearchMap map[string]interface{} `json:"search_map"` // 搜索条件: map[string]interface{} {"member_name": "销售负责人", "number": "合同编号", "created_at": "创建时间"}
    Keyword   string                 `json:"keyword"`
}
type DeleteContract struct {
service/contract.go
@@ -31,9 +31,9 @@
    return ecode.OK
}
func (ContractService) GetContractList(page, pageSize int, data map[string]interface{}) ([]*model.Contract, int64, int) {
func (ContractService) GetContractList(page, pageSize int, data map[string]interface{}, keyword string) ([]*model.Contract, int64, int) {
    // get contact list
    contacts, total, err := model.NewContractSearch().SetPage(page, pageSize).SetSearchMap(data).FindAll()
    contacts, total, err := model.NewContractSearch().SetPage(page, pageSize).SetSearchMap(data).SetKeyword(keyword).FindAll()
    if err != nil {
        return nil, 0, ecode.ContractListErr
    }