fix
add batch delete function to client module
| | |
| | | "aps_crm/pkg/contextx" |
| | | "aps_crm/pkg/ecode" |
| | | "github.com/gin-gonic/gin" |
| | | "strconv" |
| | | ) |
| | | |
| | | type ClientApi struct{} |
| | |
| | | // @Tags Client |
| | | // @Summary 删除客户 |
| | | // @Produce application/json |
| | | // @Param id path int true "客户ID" |
| | | // @Param object body request.DeleteClient true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/client/delete/{id} [delete] |
| | | // @Router /api/client/delete [delete] |
| | | func (cli *ClientApi) Delete(c *gin.Context) { |
| | | ctx, ok := contextx.NewContext(c, nil) |
| | | var params request.DeleteClient |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | id, _ := strconv.Atoi(c.Param("id")) |
| | | errCode := clientService.DeleteClient(id) |
| | | errCode := clientService.DeleteClient(params.Ids) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api/client/delete/{id}": { |
| | | "/api/client/delete": { |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | |
| | | "summary": "删除客户", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "description": "客户ID", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.DeleteClient" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.DeleteClient": { |
| | | "type": "object", |
| | | "properties": { |
| | | "ids": { |
| | | "type": "array", |
| | | "items": { |
| | | "type": "integer" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "request.DeleteCountry": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api/client/delete/{id}": { |
| | | "/api/client/delete": { |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | |
| | | "summary": "删除客户", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "description": "客户ID", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.DeleteClient" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.DeleteClient": { |
| | | "type": "object", |
| | | "properties": { |
| | | "ids": { |
| | | "type": "array", |
| | | "items": { |
| | | "type": "integer" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "request.DeleteCountry": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | description: 微信号 |
| | | type: string |
| | | type: object |
| | | request.DeleteClient: |
| | | properties: |
| | | ids: |
| | | items: |
| | | type: integer |
| | | type: array |
| | | type: object |
| | | request.DeleteCountry: |
| | | properties: |
| | | id: |
| | |
| | | summary: 添加客户 |
| | | tags: |
| | | - Client |
| | | /api/client/delete/{id}: |
| | | /api/client/delete: |
| | | delete: |
| | | parameters: |
| | | - description: 客户ID |
| | | in: path |
| | | name: id |
| | | - description: 查询参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | type: integer |
| | | schema: |
| | | $ref: '#/definitions/request.DeleteClient' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | |
| | | slf.OrderBy = order |
| | | return slf |
| | | } |
| | | func (slf *ClientSearch) SetIds(ids []int) *ClientSearch { |
| | | slf.Orm = slf.Orm.Where("id in (?)", ids) |
| | | return slf |
| | | } |
| | |
| | | PageInfo |
| | | Keyword string `json:"keyword"` |
| | | } |
| | | |
| | | type DeleteClient struct { |
| | | Ids []int `json:"ids"` |
| | | } |
| | |
| | | clientApi := v1.ApiGroup.ClientApi |
| | | { |
| | | clientRouter.POST("add", clientApi.Add) // 添加客户 |
| | | clientRouter.DELETE("delete/:id", clientApi.Delete) // 删除客户 |
| | | clientRouter.DELETE("delete", clientApi.Delete) // 删除客户 |
| | | clientRouter.PUT("update", clientApi.Update) // 更新客户 |
| | | clientRouter.POST("list", clientApi.List) // 获取客户列表 |
| | | } |
| | |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (ClientService) DeleteClient(id int) int { |
| | | // check client exist |
| | | _, err := model.NewClientSearch(nil).SetId(id).First() |
| | | if err != nil { |
| | | return ecode.ClientNotExist |
| | | } |
| | | |
| | | // delete client |
| | | err = model.NewClientSearch(nil).SetId(id).Delete() |
| | | if err != nil { |
| | | return ecode.ClientDeleteErr |
| | | } |
| | | return ecode.OK |
| | | } |
| | | |
| | | // CheckClientExist check client exist |
| | | func CheckClientExist(id int) int { |
| | |
| | | |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (ClientService) DeleteClient (ids []int) int { |
| | | // delete client |
| | | err := model.NewClientSearch(nil).SetIds(ids).Delete() |
| | | if err != nil { |
| | | return ecode.ClientDeleteErr |
| | | } |
| | | return ecode.OK |
| | | } |