| | |
| | | return |
| | | } |
| | | |
| | | contacts, total, errCode := contactService.GetContactList(params.Page, params.PageSize, params.SearchMap) |
| | | contacts, total, errCode := contactService.GetContactList(params.Page, params.PageSize, params.SearchMap, params.ClientId) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | if params.CodeRule.Method != 1 { |
| | | count, err := model.NewSaleChanceSearch().SetNumber(saleChance.Number).Count() |
| | | if err != nil { |
| | | ctx.FailWithMsg(ecode.UnknownErr, "编码验证失败") |
| | | return |
| | | } |
| | | if count > 0 { |
| | | ctx.FailWithMsg(ecode.UnknownErr, "销售机会编码已存在") |
| | | return |
| | | } |
| | | } |
| | | |
| | | errCode = saleChanceService.AddSaleChance(&saleChance) |
| | | if errCode != ecode.OK { |
| | |
| | | return |
| | | } |
| | | |
| | | salesDetailss, total, errCode := salesDetailsService.GetSalesDetailsList(params.Page, params.PageSize, params.KeywordType, params.Keyword, params.SaleChanceId) |
| | | salesDetailss, total, errCode := salesDetailsService.GetSalesDetailsList(params) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | |
| | | "codeStandID": { |
| | | "type": "string" |
| | | }, |
| | | "contractName": { |
| | | "type": "string" |
| | | }, |
| | | "created_at": { |
| | | "description": "The date when the item was created\nexample: 2023-08-10 15:48:25", |
| | | "type": "string" |
| | |
| | | "description": "编码id", |
| | | "type": "string" |
| | | }, |
| | | "contractName": { |
| | | "description": "合同名称", |
| | | "type": "string" |
| | | }, |
| | | "file": { |
| | | "type": "string" |
| | | }, |
| | |
| | | "request.GetContactList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "clientId": { |
| | | "description": "客户id", |
| | | "type": "integer" |
| | | }, |
| | | "page": { |
| | | "description": "页码", |
| | | "type": "integer" |
| | |
| | | "request.GetSalesDetailsList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "clientId": { |
| | | "description": "客户id", |
| | | "type": "integer" |
| | | }, |
| | | "keyword": { |
| | | "type": "string" |
| | | }, |
| | |
| | | "request.GetSalesReturnList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "clientId": { |
| | | "description": "客户id", |
| | | "type": "integer" |
| | | }, |
| | | "keyword": { |
| | | "type": "string" |
| | | }, |
| | |
| | | "description": "编码id", |
| | | "type": "string" |
| | | }, |
| | | "contractName": { |
| | | "description": "合同名称", |
| | | "type": "string" |
| | | }, |
| | | "file": { |
| | | "type": "string" |
| | | }, |
| | |
| | | "codeStandID": { |
| | | "type": "string" |
| | | }, |
| | | "contractName": { |
| | | "type": "string" |
| | | }, |
| | | "created_at": { |
| | | "description": "The date when the item was created\nexample: 2023-08-10 15:48:25", |
| | | "type": "string" |
| | |
| | | "description": "编码id", |
| | | "type": "string" |
| | | }, |
| | | "contractName": { |
| | | "description": "合同名称", |
| | | "type": "string" |
| | | }, |
| | | "file": { |
| | | "type": "string" |
| | | }, |
| | |
| | | "request.GetContactList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "clientId": { |
| | | "description": "客户id", |
| | | "type": "integer" |
| | | }, |
| | | "page": { |
| | | "description": "页码", |
| | | "type": "integer" |
| | |
| | | "request.GetSalesDetailsList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "clientId": { |
| | | "description": "客户id", |
| | | "type": "integer" |
| | | }, |
| | | "keyword": { |
| | | "type": "string" |
| | | }, |
| | |
| | | "request.GetSalesReturnList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "clientId": { |
| | | "description": "客户id", |
| | | "type": "integer" |
| | | }, |
| | | "keyword": { |
| | | "type": "string" |
| | | }, |
| | |
| | | "description": "编码id", |
| | | "type": "string" |
| | | }, |
| | | "contractName": { |
| | | "description": "合同名称", |
| | | "type": "string" |
| | | }, |
| | | "file": { |
| | | "type": "string" |
| | | }, |
| | |
| | | type: integer |
| | | codeStandID: |
| | | type: string |
| | | contractName: |
| | | type: string |
| | | created_at: |
| | | description: |- |
| | | The date when the item was created |
| | |
| | | codeStandID: |
| | | description: 编码id |
| | | type: string |
| | | contractName: |
| | | description: 合同名称 |
| | | type: string |
| | | file: |
| | | type: string |
| | | member_id: |
| | |
| | | type: object |
| | | request.GetContactList: |
| | | properties: |
| | | clientId: |
| | | description: 客户id |
| | | type: integer |
| | | page: |
| | | description: 页码 |
| | | type: integer |
| | |
| | | type: object |
| | | request.GetSalesDetailsList: |
| | | properties: |
| | | clientId: |
| | | description: 客户id |
| | | type: integer |
| | | keyword: |
| | | type: string |
| | | keywordType: |
| | |
| | | type: object |
| | | request.GetSalesReturnList: |
| | | properties: |
| | | clientId: |
| | | description: 客户id |
| | | type: integer |
| | | keyword: |
| | | type: string |
| | | keywordType: |
| | |
| | | codeStandID: |
| | | description: 编码id |
| | | type: string |
| | | contractName: |
| | | description: 合同名称 |
| | | type: string |
| | | file: |
| | | type: string |
| | | id: |
| | |
| | | type ( |
| | | Contract struct { |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | ContractName string `json:"contractName" gorm:"column:contract_name;type:varchar(255);comment:合同名称"` |
| | | ClientId int `json:"clientId" gorm:"column:client_id;type:int;comment:客户id"` |
| | | Client Client `json:"client" gorm:"foreignKey:ClientId"` |
| | | MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:负责人id"` |
| | |
| | | db = db.Where(key+" LIKE ?", "%"+v+"%") |
| | | } |
| | | |
| | | if key == "name" { |
| | | if key == "client_name" { |
| | | db = db.Joins("Client").Where("Client.name LIKE ?", "%"+v+"%") |
| | | } |
| | | |
| | |
| | | db = db.Joins("Member").Where("Member.username LIKE ?", "%"+v+"%") |
| | | } |
| | | |
| | | case int: |
| | | case float64: |
| | | if key == "client_id" || key == "sale_chance_id" { |
| | | db = db.Where(key+" = ?", v) |
| | | } |
| | |
| | | type GetContactList struct { |
| | | PageInfo |
| | | SearchMap map[string]interface{} `json:"search_map"` // 搜索条件: map[string]interface{}{"name": "xxx"}; {"name": "客户名称", "phone": "手机号码", "detail_address":"详细地址", "next_visit_time":"下回回访日期", "member_name": "销售负责人", "client_status": "客户状态", "client_level": "重要级别", "is_first": "是否是首要联系人", "client_id": "clientId 用于返回首要联系人"} |
| | | ClientId int `json:"clientId"` //客户id |
| | | } |
| | | |
| | | type DeleteContact struct { |
| | |
| | | } |
| | | |
| | | type Contract struct { |
| | | ClientId int `json:"client_id"` |
| | | MemberId int `json:"member_id"` |
| | | Number string `json:"number"` |
| | | QuotationId int `json:"quotation_id"` |
| | | StatusId int `json:"status_id"` |
| | | File string `json:"file"` |
| | | CodeStandID string `json:"codeStandID"` //编码id |
| | | CodeRule code.CodeStandard `json:"codeRule"` |
| | | ContractName string `json:"contractName"` //合同名称 |
| | | ClientId int `json:"client_id"` |
| | | MemberId int `json:"member_id"` |
| | | Number string `json:"number"` |
| | | QuotationId int `json:"quotation_id"` |
| | | StatusId int `json:"status_id"` |
| | | File string `json:"file"` |
| | | CodeStandID string `json:"codeStandID"` //编码id |
| | | CodeRule code.CodeStandard `json:"codeRule"` |
| | | } |
| | | |
| | | type UpdateContract struct { |
| | |
| | | KeywordType constvar.SalesDetailsKeywordType `json:"keywordType"` |
| | | Keyword string `json:"keyword"` |
| | | SaleChanceId int `json:"saleChanceId"` //销售机会id |
| | | ClientId int `json:"clientId"` //客户id |
| | | } |
| | |
| | | KeywordType constvar.SalesReturnKeywordType |
| | | SourceType constvar.SalesReturnSourceType `json:"sourceType"` // 源单类型(1销售明细) |
| | | SourceId int `json:"sourceId"` // 源单id |
| | | ClientId int `json:"clientId"` //客户id |
| | | } |
| | |
| | | if slf.Name != "" { |
| | | db = db.Where("name = ?", slf.Name) |
| | | } |
| | | if slf.Number != "" { |
| | | db = db.Where("number = ?", slf.Number) |
| | | } |
| | | |
| | | if len(slf.SearchMap) > 0 { |
| | | for key, value := range slf.SearchMap { |
| | |
| | | |
| | | case int: |
| | | case float64: |
| | | if key == "member_id" || key == "budget" || key == "projected_amount" { |
| | | if key == "member_id" || key == "budget" || key == "projected_amount" || key == "client_id" { |
| | | db = db.Where(key+" = ?", v) |
| | | } |
| | | } |
| | |
| | | db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize) |
| | | } |
| | | |
| | | err := db.Preload("SaleType").Preload("RegularCustomers").Preload("SalesSources").Preload("Member").Preload("SaleStage").Preload("Possibility").Preload("CollectionProjections").Preload("Client").Preload("Contact.Province").Preload("Contact.City").Order("id desc").Find(&records).Error |
| | | err := db.Preload("SaleType").Preload("RegularCustomers").Preload("SalesSources").Preload("Member").Preload("SaleStage").Preload("Possibility").Preload("CollectionProjections").Preload("Client").Preload("Province").Preload("City").Order("id desc").Find(&records).Error |
| | | return records, total, err |
| | | } |
| | | |
| | | func (slf *SaleChanceSearch) Count() (int64, error) { |
| | | var db = slf.build() |
| | | var total int64 |
| | | err := db.Count(&total).Error |
| | | return total, err |
| | | } |
| | | |
| | | func (slf *SaleChanceSearch) SetId(id int) *SaleChanceSearch { |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *SaleChanceSearch) SetNumber(number string) *SaleChanceSearch { |
| | | slf.Number = number |
| | | return slf |
| | | } |
| | | |
| | | func (slf *SaleChanceSearch) SetSearchMap(searchMap map[string]interface{}) *SaleChanceSearch { |
| | | slf.SearchMap = searchMap |
| | | return slf |
| | |
| | | db = db.Where("sale_chance_id = ?", slf.SaleChanceId) |
| | | } |
| | | |
| | | if slf.ClientId != 0 { |
| | | db = db.Where("client_id = ?", slf.ClientId) |
| | | } |
| | | |
| | | switch slf.KeywordType { |
| | | case constvar.SalesDetailsKeywordTypeCustomerName: |
| | | db = db.Joins("Client", clause.LeftJoin).Where("Client.name like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *SalesDetailsSearch) SetClientId(clientId int) *SalesDetailsSearch { |
| | | slf.ClientId = clientId |
| | | return slf |
| | | } |
| | | |
| | | func (slf *SalesDetailsSearch) SetSaleChanceId(saleChanceId int) *SalesDetailsSearch { |
| | | slf.SaleChanceId = saleChanceId |
| | | return slf |
| | |
| | | if slf.SourceId != 0 { |
| | | db = db.Where("source_id = ?", slf.SourceId) |
| | | } |
| | | if slf.ClientId != 0 { |
| | | db = db.Where("client_id = ?", slf.ClientId) |
| | | } |
| | | if slf.Preload { |
| | | db = db.Preload("Client"). |
| | | Preload("Member"). |
| | |
| | | slf.SourceType = sourceType |
| | | return slf |
| | | } |
| | | |
| | | func (slf *SalesReturnSearch) SetSourceId(sourceId int) *SalesReturnSearch { |
| | | slf.SourceId = sourceId |
| | | return slf |
| | | } |
| | | |
| | | func (slf *SalesReturnSearch) SetClientId(clientId int) *SalesReturnSearch { |
| | | slf.ClientId = clientId |
| | | return slf |
| | | } |
| | | |
| | | func (slf *SalesReturnSearch) UpdateByMap(data map[string]interface{}) error { |
| | | var db = slf.build() |
| | | return db.Updates(data).Error |
| | |
| | | db = db.Joins("Member").Where("User.username LIKE ?", "%"+v+"%") |
| | | } |
| | | case int: |
| | | if key == "master_order_id" { |
| | | db = db.Where("master_order_id = ?", v) |
| | | case float64: |
| | | if key == "client_id" || key == "master_order_id" { |
| | | db = db.Where(key+" = ?", v) |
| | | } |
| | | } |
| | | } |
| | |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (ContactService) GetContactList(page, pageSize int, data map[string]interface{}) ([]*model.ContactDetail, int64, int) { |
| | | func (ContactService) GetContactList(page, pageSize int, data map[string]interface{}, clientId int) ([]*model.ContactDetail, int64, int) { |
| | | // get contact list |
| | | contacts, total, err := model.NewContactSearch(nil).SetPage(page, pageSize).SetSearchMap(data).FindAll() |
| | | contacts, total, err := model.NewContactSearch(nil).SetPage(page, pageSize).SetSearchMap(data).SetClientId(clientId).FindAll() |
| | | if err != nil { |
| | | return nil, 0, ecode.ContactListErr |
| | | } |
| | |
| | | package service |
| | | |
| | | import ( |
| | | "aps_crm/constvar" |
| | | "aps_crm/model" |
| | | "aps_crm/model/request" |
| | | "aps_crm/pkg/ecode" |
| | | "github.com/shopspring/decimal" |
| | | "gorm.io/gorm" |
| | |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (SalesDetailsService) GetSalesDetailsList(page, pageSize int, keywordType constvar.SalesDetailsKeywordType, keyword string, saleChanceId int) ([]*model.SalesDetails, int64, int) { |
| | | func (SalesDetailsService) GetSalesDetailsList(params request.GetSalesDetailsList) ([]*model.SalesDetails, int64, int) { |
| | | // get contact list |
| | | contacts, total, err := model.NewSalesDetailsSearch(). |
| | | SetPreload(true). |
| | | SetKeywordType(keywordType). |
| | | SetSaleChanceId(saleChanceId). |
| | | SetKeyword(keyword).SetPage(page, pageSize).FindAll() |
| | | SetKeywordType(params.KeywordType). |
| | | SetSaleChanceId(params.SaleChanceId). |
| | | SetClientId(params.ClientId). |
| | | SetKeyword(params.Keyword).SetPage(params.Page, params.PageSize).FindAll() |
| | | if err != nil { |
| | | return nil, 0, ecode.SalesDetailsListErr |
| | | } |
| | |
| | | SetPage(params.Page, params.PageSize). |
| | | SetSourceId(params.SourceId). |
| | | SetSourceType(params.SourceType). |
| | | SetClientId(params.ClientId). |
| | | SetPreload(true). |
| | | FindAll() |
| | | if err != nil { |