fix
add batch assign function to followRecord, salesLeads, contact, client module
| | |
| | | // Assign |
| | | // |
| | | // @Tags Assign |
| | | // @Summary 审核 |
| | | // @Summary 分配 |
| | | // @Produce application/json |
| | | // @Param object body request.Assign true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | |
| | | return |
| | | } |
| | | |
| | | if params.Id == 0 { |
| | | if len(params.Ids) == 0 { |
| | | ctx.Fail(ecode.AssignWrongId) |
| | | return |
| | | } |
| | |
| | | return |
| | | } |
| | | |
| | | errCode := assignService.Assign(params.MemberId, params.Id, params.Type) |
| | | errCode := assignService.Assign(params.MemberId, params.Ids, params.Type) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | |
| | | "tags": [ |
| | | "Assign" |
| | | ], |
| | | "summary": "审核", |
| | | "summary": "分配", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | |
| | | "request.Assign": { |
| | | "type": "object", |
| | | "properties": { |
| | | "id": { |
| | | "ids": { |
| | | "type": "array", |
| | | "items": { |
| | | "type": "integer" |
| | | } |
| | | }, |
| | | "member_id": { |
| | | "type": "integer" |
| | |
| | | "tags": [ |
| | | "Assign" |
| | | ], |
| | | "summary": "审核", |
| | | "summary": "分配", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | |
| | | "request.Assign": { |
| | | "type": "object", |
| | | "properties": { |
| | | "id": { |
| | | "ids": { |
| | | "type": "array", |
| | | "items": { |
| | | "type": "integer" |
| | | } |
| | | }, |
| | | "member_id": { |
| | | "type": "integer" |
| | |
| | | type: object |
| | | request.Assign: |
| | | properties: |
| | | id: |
| | | ids: |
| | | items: |
| | | type: integer |
| | | type: array |
| | | member_id: |
| | | type: integer |
| | | type: |
| | |
| | | description: OK |
| | | schema: |
| | | $ref: '#/definitions/contextx.Response' |
| | | summary: 审核 |
| | | summary: 分配 |
| | | tags: |
| | | - Assign |
| | | /api/authority/add: |
| | |
| | | slf.Orm = slf.Orm.Where("id in (?)", ids) |
| | | return slf |
| | | } |
| | | |
| | | func (slf *FollowRecordSearch) UpdateMap(data map[string]interface{}) error { |
| | | var db = slf.build() |
| | | return db.Updates(data).Error |
| | | } |
| | |
| | | type Assign struct { |
| | | MemberId int `json:"member_id"` |
| | | Type string `json:"type"` |
| | | Id int `json:"id"` |
| | | Ids []int `json:"ids"` |
| | | } |
| | |
| | | ContactListErr = 600003 // 获取联系人列表失败
|
| | | ContactDeleteErr = 600004 // 删除联系人失败
|
| | | ContactUpdateErr = 600005 // 更新联系人失败
|
| | | ContactAssignErr = 600006 // 分配联系人失败 |
| | |
|
| | | ClientExist = 700001 // 客户已存在
|
| | | ClientNotExist = 700002 // 客户不存在
|
| | |
| | | FollowRecordSetErr = 1800004 // 设置跟进记录失败
|
| | | FollowRecordUpdateErr = 1800005 // 更新跟进记录失败
|
| | | FollowRecordDeleteErr = 1800006 // 删除跟进记录失败
|
| | | FollowRecordAssignErr = 1800007 // 分配跟进记录失败 |
| | |
|
| | | SaleChanceExist = 1900001 // 销售机会已存在
|
| | | SaleChanceNotExist = 1900002 // 销售机会不存在
|
| | |
| | | Assign(id int) error |
| | | } |
| | | |
| | | func (AssignService) Assign(memberId, id int, modelType string) int { |
| | | func (AssignService) Assign(memberId int, ids []int, modelType string) int { |
| | | // check member exist |
| | | _, err := model.NewUserSearch(nil).SetUserId(memberId).First() |
| | | if err != nil { |
| | |
| | | var errCode int |
| | | switch modelType { |
| | | case "client": |
| | | errCode = ClientService{}.Assign(id, memberId) |
| | | errCode = ClientService{}.Assign(ids, memberId) |
| | | case "salesLead": |
| | | errCode = SalesLeadsService{}.Assign(id, memberId) |
| | | errCode = SalesLeadsService{}.Assign(ids, memberId) |
| | | case "contact": |
| | | errCode = ContactService{}.Assign(ids, memberId) |
| | | case "followRecord": |
| | | errCode = FollowRecordService{}.Assign(ids, memberId) |
| | | |
| | | default: |
| | | errCode = ecode.AssignWrongModelType |
| | | } |
| | |
| | | return contacts, total, ecode.OK |
| | | } |
| | | |
| | | func (ClientService) Assign(id, memberId int) int { |
| | | func (ClientService) Assign(ids []int, memberId int) int { |
| | | // check client exist |
| | | errCode := CheckClientExist(id) |
| | | if errCode != ecode.OK { |
| | | return errCode |
| | | } |
| | | //errCode := CheckClientExist(id) |
| | | //if errCode != ecode.OK { |
| | | // return errCode |
| | | //} |
| | | |
| | | // assign client |
| | | err := model.NewClientSearch(nil).SetId(id).UpdateByMap(map[string]interface{}{ |
| | | err := model.NewClientSearch(nil).SetIds(ids).UpdateByMap(map[string]interface{}{ |
| | | "member_id": memberId, |
| | | }) |
| | | if err != nil { |
| | |
| | | return ecode.OK |
| | | } |
| | | |
| | | |
| | | func (ContactService) UpdateContact(contact *model.Contact) int { |
| | | // check contact exist |
| | | _, err := model.NewContactSearch(nil).SetId(contact.Id).First() |
| | |
| | | } |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (ContactService) Assign(ids []int, memberId int) int { |
| | | // check contact exist |
| | | //errCode := CheckContactExist(id) |
| | | //if errCode != ecode.OK { |
| | | // return errCode |
| | | //} |
| | | |
| | | // assign contact |
| | | err := model.NewContactSearch(nil).SetIds(ids).UpdateByMap(map[string]interface{}{ |
| | | "member_id": memberId, |
| | | }) |
| | | if err != nil { |
| | | return ecode.ContactAssignErr |
| | | } |
| | | |
| | | return ecode.OK |
| | | } |
| | |
| | | } |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (FollowRecordService) Assign(ids []int, memberId int) int { |
| | | // check followRecord exist |
| | | //errCode := checkFollowRecordExist(id) |
| | | //if errCode != ecode.OK { |
| | | // return errCode |
| | | //} |
| | | |
| | | // assign followRecord |
| | | err := model.NewFollowRecordSearch().SetIds(ids).UpdateMap(map[string]interface{}{ |
| | | "member_id": memberId, |
| | | }) |
| | | if err != nil { |
| | | return ecode.FollowRecordAssignErr |
| | | } |
| | | |
| | | return ecode.OK |
| | | } |
| | |
| | | return contacts, total, ecode.OK |
| | | } |
| | | |
| | | func (SalesLeadsService) Assign(id, memberId int) int { |
| | | func (SalesLeadsService) Assign(ids []int, memberId int) int { |
| | | // check salesLeads exist |
| | | errCode := CheckSalesLeadsExist(id) |
| | | if errCode != ecode.OK { |
| | | return errCode |
| | | } |
| | | //errCode := CheckSalesLeadsExist(id) |
| | | //if errCode != ecode.OK { |
| | | // return errCode |
| | | //} |
| | | |
| | | // update salesLeads |
| | | err := model.NewSalesLeadsSearch().SetId(id).UpdateMap(map[string]interface{}{ |
| | | err := model.NewSalesLeadsSearch().SetIds(ids).UpdateMap(map[string]interface{}{ |
| | | "member_id": memberId, |
| | | }) |
| | | if err != nil { |