| | |
| | | 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 |
| | |
| | | |
| | | ContractSearch struct { |
| | | Contract |
| | | |
| | | Keyword string |
| | | Orm *gorm.DB |
| | | SearchMap map[string]interface{} |
| | | OrderBy string |
| | |
| | | } |
| | | } |
| | | |
| | | func (slf *ContractSearch) SetKeyword(keyword string) *ContractSearch { |
| | | slf.Keyword = keyword |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ContractSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&Contract{}) |
| | | |
| | |
| | | } |
| | | 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 { |
| | |
| | | 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) |
| | |
| | | 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 { |
| | |
| | | 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 |
| | | } |