| | |
| | | Count: int(total), |
| | | }) |
| | | } |
| | | |
| | | // CheckName |
| | | // |
| | | // @Tags Client |
| | | // @Summary 检查客户名称是否重复 |
| | | // @Produce application/json |
| | | // @Param object body request.CheckClientName true "参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/client/checkName [post] |
| | | func (cli *ClientApi) CheckName(c *gin.Context) { |
| | | var params request.CheckClientName |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | errCode := clientService.CheckName(params.Name) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api/client/checkName": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Client" |
| | | ], |
| | | "summary": "检查客户名称是否重复", |
| | | "parameters": [ |
| | | { |
| | | "description": "参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.CheckClientName" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/client/delete": { |
| | | "delete": { |
| | | "produces": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.CheckClientName": { |
| | | "type": "object", |
| | | "properties": { |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.Contact": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api/client/checkName": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Client" |
| | | ], |
| | | "summary": "检查客户名称是否重复", |
| | | "parameters": [ |
| | | { |
| | | "description": "参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.CheckClientName" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/client/delete": { |
| | | "delete": { |
| | | "produces": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.CheckClientName": { |
| | | "type": "object", |
| | | "properties": { |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.Contact": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | description: 用户岗位 |
| | | type: string |
| | | type: object |
| | | request.CheckClientName: |
| | | properties: |
| | | name: |
| | | type: string |
| | | type: object |
| | | request.Contact: |
| | | properties: |
| | | birthday: |
| | |
| | | summary: 添加客户 |
| | | tags: |
| | | - Client |
| | | /api/client/checkName: |
| | | post: |
| | | parameters: |
| | | - description: 参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.CheckClientName' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: OK |
| | | schema: |
| | | $ref: '#/definitions/contextx.Response' |
| | | summary: 检查客户名称是否重复 |
| | | tags: |
| | | - Client |
| | | /api/client/delete: |
| | | delete: |
| | | parameters: |
| | |
| | | type ( |
| | | Client struct { |
| | | Id int `json:"id" gorm:"column:id;primaryKey;autoIncrement;not null"` |
| | | Name string `json:"name" gorm:"column:name;unique;type:varchar(255);comment:客户名称"` |
| | | Name string `json:"name" gorm:"column:name;uniqueIndex:name_isDeleted_idx;type:varchar(255);comment:客户名称"` |
| | | IsDeleted bool `json:"-" gorm:"column:is_deleted;uniqueIndex:name_isDeleted_idx;type:tinyint(1);comment:是否删除"` |
| | | Number string `json:"number" gorm:"column:number;type:varchar(255);comment:客户编号"` |
| | | ClientStatusId int `json:"client_status_id" gorm:"column:client_status_id;type:int(11);comment:客户状态ID"` |
| | | ClientStatus ClientStatus `json:"client_status" gorm:"foreignKey:ClientStatusId"` |
| | |
| | | } |
| | | } |
| | | |
| | | func (c *Client) BeforeSave(tx *gorm.DB) (err error) { |
| | | if c.DeletedAt.Valid { |
| | | c.IsDeleted = true |
| | | } else { |
| | | c.IsDeleted = false |
| | | } |
| | | return |
| | | } |
| | | |
| | | func (slf *ClientSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&Client{}) |
| | | if slf.Id != 0 { |
| | |
| | | type DeleteClient struct { |
| | | Ids []int `json:"ids"` |
| | | } |
| | | |
| | | type CheckClientName struct { |
| | | Name string `json:"name"` |
| | | } |
| | |
| | | clientRouter.POST("add", clientApi.Add) // 添加客户 |
| | | clientRouter.DELETE("delete", clientApi.Delete) // 删除客户 |
| | | clientRouter.PUT("update", clientApi.Update) // 更新客户 |
| | | clientRouter.POST("list", clientApi.List) // 获取客户列表 |
| | | clientRouter.POST("list", clientApi.List) // 获取客户列表 |
| | | clientRouter.POST("checkName", clientApi.CheckName) // 检查客户名称是否重复 |
| | | } |
| | | } |
| | | } |
| | |
| | | "aps_crm/model" |
| | | "aps_crm/pkg/ecode" |
| | | "aps_crm/pkg/mysqlx" |
| | | "gorm.io/gorm" |
| | | ) |
| | | |
| | | type ClientService struct{} |
| | |
| | | } |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (ClientService) CheckName(name string) int { |
| | | // check client exist |
| | | _, err := model.NewClientSearch(nil).SetName(name).First() |
| | | if err != gorm.ErrRecordNotFound { |
| | | return ecode.ClientExist |
| | | } |
| | | |
| | | return ecode.OK |
| | | } |