add
status 销售阶段
add, Delete, update, list
| | |
| | | SaleTypeApi |
| | | RegularCustomersApi |
| | | PossibilityApi |
| | | StatusApi |
| | | } |
| | | |
| | | var ApiGroup = new(Group) |
| | |
| | | saleTypeService = service.ServiceGroup.SaleTypeService |
| | | regularCustomersService = service.ServiceGroup.RegularCustomersService |
| | | possibilityService = service.ServiceGroup.PossibilityService |
| | | statusService = service.ServiceGroup.StatusService |
| | | ) |
New file |
| | |
| | | package v1 |
| | | |
| | | import ( |
| | | "aps_crm/model" |
| | | "aps_crm/model/request" |
| | | "aps_crm/model/response" |
| | | "aps_crm/pkg/contextx" |
| | | "aps_crm/pkg/ecode" |
| | | "github.com/gin-gonic/gin" |
| | | "strconv" |
| | | ) |
| | | |
| | | type StatusApi struct{} |
| | | |
| | | // Add |
| | | // |
| | | // @Tags Status |
| | | // @Summary 添加状态 |
| | | // @Produce application/json |
| | | // @Param object body request.AddStatus true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/status/add [post] |
| | | func (s *StatusApi) Add(c *gin.Context) { |
| | | var params request.AddStatus |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | status := new(model.Status) |
| | | status.Name = params.Name |
| | | |
| | | errCode := statusService.AddStatus(status) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // Delete |
| | | // |
| | | // @Tags Status |
| | | // @Summary 删除状态 |
| | | // @Produce application/json |
| | | // @Param id path int true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/status/delete/{id} [delete] |
| | | func (s *StatusApi) Delete(c *gin.Context) { |
| | | ctx, ok := contextx.NewContext(c, nil) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | id, _ := strconv.Atoi(c.Param("id")) |
| | | errCode := statusService.DeleteStatus(id) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // Update |
| | | // |
| | | // @Tags Status |
| | | // @Summary 更新状态 |
| | | // @Produce application/json |
| | | // @Param object body request.UpdateStatusList true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/status/update [put] |
| | | func (s *StatusApi) Update(c *gin.Context) { |
| | | var params request.UpdateStatusList |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | errCode := statusService.UpdateStatus(params.List) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // List |
| | | // |
| | | // @Tags Status |
| | | // @Summary 状态列表 |
| | | // @Produce application/json |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/status/list [get] |
| | | func (s *StatusApi) List(c *gin.Context) { |
| | | ctx, ok := contextx.NewContext(c, nil) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | list, errCode := statusService.GetStatusList() |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.OkWithDetailed(response.StatusResponse{ |
| | | List: list, |
| | | }) |
| | | } |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api/status/add": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Status" |
| | | ], |
| | | "summary": "添加状态", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.AddStatus" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/status/delete/{id}": { |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Status" |
| | | ], |
| | | "summary": "删除状态", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "description": "查询参数", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/status/list": { |
| | | "get": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Status" |
| | | ], |
| | | "summary": "状态列表", |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/status/update": { |
| | | "put": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Status" |
| | | ], |
| | | "summary": "更新状态", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.UpdateStatusList" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/user/changePassword": { |
| | | "post": { |
| | | "produces": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.AddStatus": { |
| | | "type": "object", |
| | | "required": [ |
| | | "name" |
| | | ], |
| | | "properties": { |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.ChangePasswordReq": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateStatus": { |
| | | "type": "object", |
| | | "required": [ |
| | | "id", |
| | | "name" |
| | | ], |
| | | "properties": { |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateStatusList": { |
| | | "type": "object", |
| | | "required": [ |
| | | "list" |
| | | ], |
| | | "properties": { |
| | | "list": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/request.UpdateStatus" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "response.CityResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api/status/add": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Status" |
| | | ], |
| | | "summary": "添加状态", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.AddStatus" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/status/delete/{id}": { |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Status" |
| | | ], |
| | | "summary": "删除状态", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "description": "查询参数", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/status/list": { |
| | | "get": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Status" |
| | | ], |
| | | "summary": "状态列表", |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/status/update": { |
| | | "put": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Status" |
| | | ], |
| | | "summary": "更新状态", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.UpdateStatusList" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/user/changePassword": { |
| | | "post": { |
| | | "produces": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.AddStatus": { |
| | | "type": "object", |
| | | "required": [ |
| | | "name" |
| | | ], |
| | | "properties": { |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.ChangePasswordReq": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateStatus": { |
| | | "type": "object", |
| | | "required": [ |
| | | "id", |
| | | "name" |
| | | ], |
| | | "properties": { |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateStatusList": { |
| | | "type": "object", |
| | | "required": [ |
| | | "list" |
| | | ], |
| | | "properties": { |
| | | "list": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/request.UpdateStatus" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "response.CityResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | required: |
| | | - name |
| | | type: object |
| | | request.AddStatus: |
| | | properties: |
| | | name: |
| | | type: string |
| | | required: |
| | | - name |
| | | type: object |
| | | request.ChangePasswordReq: |
| | | properties: |
| | | newPassword: |
| | |
| | | items: |
| | | $ref: '#/definitions/request.UpdateSalesSources' |
| | | type: array |
| | | type: object |
| | | request.UpdateStatus: |
| | | properties: |
| | | id: |
| | | type: integer |
| | | name: |
| | | type: string |
| | | required: |
| | | - id |
| | | - name |
| | | type: object |
| | | request.UpdateStatusList: |
| | | properties: |
| | | list: |
| | | items: |
| | | $ref: '#/definitions/request.UpdateStatus' |
| | | type: array |
| | | required: |
| | | - list |
| | | type: object |
| | | response.CityResponse: |
| | | properties: |
| | |
| | | summary: 更新商机来源 |
| | | tags: |
| | | - SalesSources |
| | | /api/status/add: |
| | | post: |
| | | parameters: |
| | | - description: 查询参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.AddStatus' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: OK |
| | | schema: |
| | | $ref: '#/definitions/contextx.Response' |
| | | summary: 添加状态 |
| | | tags: |
| | | - Status |
| | | /api/status/delete/{id}: |
| | | delete: |
| | | parameters: |
| | | - description: 查询参数 |
| | | in: path |
| | | name: id |
| | | required: true |
| | | type: integer |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: OK |
| | | schema: |
| | | $ref: '#/definitions/contextx.Response' |
| | | summary: 删除状态 |
| | | tags: |
| | | - Status |
| | | /api/status/list: |
| | | get: |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: OK |
| | | schema: |
| | | $ref: '#/definitions/contextx.Response' |
| | | summary: 状态列表 |
| | | tags: |
| | | - Status |
| | | /api/status/update: |
| | | put: |
| | | parameters: |
| | | - description: 查询参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.UpdateStatusList' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: OK |
| | | schema: |
| | | $ref: '#/definitions/contextx.Response' |
| | | summary: 更新状态 |
| | | tags: |
| | | - Status |
| | | /api/user/changePassword: |
| | | post: |
| | | parameters: |
| | |
| | | SaleType{}, |
| | | RegularCustomers{}, |
| | | Possibility{}, |
| | | Status{}, |
| | | ) |
| | | return err |
| | | } |
New file |
| | |
| | | package request |
| | | |
| | | type AddStatus struct { |
| | | Name string `json:"name" binding:"required"` |
| | | } |
| | | |
| | | type UpdateStatus struct { |
| | | Id int `json:"id" binding:"required"` |
| | | Name string `json:"name" binding:"required"` |
| | | } |
| | | |
| | | type UpdateStatusList struct { |
| | | List []*UpdateStatus `json:"list" binding:"required"` |
| | | } |
| | |
| | | PossibilityResponse struct { |
| | | List []*model.Possibility `json:"list"` |
| | | } |
| | | |
| | | StatusResponse struct { |
| | | List []*model.Status `json:"list"` |
| | | } |
| | | ) |
New file |
| | |
| | | package model |
| | | |
| | | import ( |
| | | "aps_crm/pkg/mysqlx" |
| | | "gorm.io/gorm" |
| | | ) |
| | | |
| | | type ( |
| | | // Status 状态 |
| | | Status struct { |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | Name string `json:"name" gorm:"column:name;type:varchar(255);comment:状态名称"` |
| | | } |
| | | |
| | | // StatusSearch 状态搜索条件 |
| | | StatusSearch struct { |
| | | Status |
| | | Orm *gorm.DB |
| | | } |
| | | ) |
| | | |
| | | func (Status) TableName() string { |
| | | return "status" |
| | | } |
| | | |
| | | func NewStatusSearch() *StatusSearch { |
| | | return &StatusSearch{ |
| | | Orm: mysqlx.GetDB(), |
| | | } |
| | | } |
| | | |
| | | func (slf *StatusSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&Status{}) |
| | | if slf.Id != 0 { |
| | | db = db.Where("id = ?", slf.Id) |
| | | } |
| | | if slf.Name != "" { |
| | | db = db.Where("name = ?", slf.Name) |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |
| | | func (slf *StatusSearch) Create(record *Status) error { |
| | | var db = slf.build() |
| | | return db.Create(record).Error |
| | | } |
| | | |
| | | func (slf *StatusSearch) Delete() error { |
| | | var db = slf.build() |
| | | return db.Delete(&Status{}).Error |
| | | } |
| | | |
| | | func (slf *StatusSearch) Update(record *Status) error { |
| | | var db = slf.build() |
| | | return db.Updates(record).Error |
| | | } |
| | | |
| | | func (slf *StatusSearch) Find() (*Status, error) { |
| | | var db = slf.build() |
| | | var record = &Status{} |
| | | err := db.First(record).Error |
| | | return record, err |
| | | } |
| | | |
| | | func (slf *StatusSearch) FindAll() ([]*Status, error) { |
| | | var db = slf.build() |
| | | var records = make([]*Status, 0) |
| | | err := db.Find(&records).Error |
| | | return records, err |
| | | } |
| | | |
| | | func (slf *StatusSearch) SetId(id int) *StatusSearch { |
| | | slf.Id = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *StatusSearch) SetName(name string) *StatusSearch { |
| | | slf.Name = name |
| | | return slf |
| | | } |
| | | |
| | | func (slf *StatusSearch) Updates(data map[string]interface{}) error { |
| | | var db = slf.build() |
| | | return db.Updates(data).Error |
| | | } |
| | |
| | | PossibilityUpdateErr = 2300005 // 更新销售机会可能性失败 |
| | | PossibilityDeleteErr = 2300006 // 删除销售机会可能性失败 |
| | | |
| | | StatusExist = 2400001 // 销售机会状态已存在 |
| | | StatusNotExist = 2400002 // 销售机会状态不存在 |
| | | StatusListErr = 2400003 // 获取销售机会状态列表失败 |
| | | StatusSetErr = 2400004 // 设置销售机会状态失败 |
| | | StatusUpdateErr = 2400005 // 更新销售机会状态失败 |
| | | StatusDeleteErr = 2400006 // 删除销售机会状态失败 |
| | | |
| | | ) |
| | |
| | | SaleTypeRouter |
| | | RegularCustomersRouter |
| | | PossibilityRouter |
| | | StatusRouter |
| | | } |
| | | |
| | | func InitRouter() *gin.Engine { |
| | |
| | | routerGroup.InitSaleTypeRouter(PrivateGroup) // 注册saleType路由 |
| | | routerGroup.InitRegularCustomersRouter(PrivateGroup) // 注册regularCustomers路由 |
| | | routerGroup.InitPossibilityRouter(PrivateGroup) // 注册possibility路由 |
| | | routerGroup.InitStatusRouter(PrivateGroup) // 注册status路由 |
| | | } |
| | | return Router |
| | | } |
New file |
| | |
| | | package router |
| | | |
| | | import ( |
| | | v1 "aps_crm/api/v1" |
| | | "github.com/gin-gonic/gin" |
| | | ) |
| | | |
| | | type StatusRouter struct{} |
| | | |
| | | func (s *StatusRouter) InitStatusRouter(router *gin.RouterGroup) { |
| | | statusRouter := router.Group("status") |
| | | statusApi := v1.ApiGroup.StatusApi |
| | | { |
| | | statusRouter.POST("add", statusApi.Add) // 添加状态 |
| | | statusRouter.DELETE("delete/:id", statusApi.Delete) // 删除状态 |
| | | statusRouter.PUT("update", statusApi.Update) // 更新状态 |
| | | statusRouter.GET("list", statusApi.List) // 获取状态列表 |
| | | } |
| | | } |
| | |
| | | SaleTypeService |
| | | RegularCustomersService |
| | | PossibilityService |
| | | StatusService |
| | | } |
| | | |
| | | var ServiceGroup = new(Group) |
New file |
| | |
| | | package service |
| | | |
| | | import ( |
| | | "aps_crm/model" |
| | | "aps_crm/model/request" |
| | | "aps_crm/pkg/ecode" |
| | | ) |
| | | |
| | | type StatusService struct{} |
| | | |
| | | func (StatusService) AddStatus(status *model.Status) int { |
| | | err := model.NewStatusSearch().Create(status) |
| | | if err != nil { |
| | | return ecode.StatusExist |
| | | } |
| | | |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (StatusService) DeleteStatus(id int) int { |
| | | _, err := model.NewStatusSearch().SetId(id).Find() |
| | | if err != nil { |
| | | return ecode.StatusNotExist |
| | | } |
| | | |
| | | err = model.NewStatusSearch().SetId(id).Delete() |
| | | if err != nil { |
| | | return ecode.StatusNotExist |
| | | } |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (StatusService) GetStatusList() ([]*model.Status, int) { |
| | | list, err := model.NewStatusSearch().FindAll() |
| | | if err != nil { |
| | | return nil, ecode.StatusListErr |
| | | } |
| | | |
| | | return list, ecode.OK |
| | | } |
| | | |
| | | func (StatusService) UpdateStatus(statuses []*request.UpdateStatus) int { |
| | | for _, v := range statuses { |
| | | // check status exist |
| | | _, err := model.NewStatusSearch().SetId(v.Id).Find() |
| | | if err != nil { |
| | | return ecode.StatusNotExist |
| | | } |
| | | |
| | | err = model.NewStatusSearch().SetId(v.Id).Updates(map[string]interface{}{ |
| | | "name": v.Name, |
| | | }) |
| | | if err != nil { |
| | | return ecode.StatusSetErr |
| | | } |
| | | } |
| | | |
| | | return ecode.OK |
| | | } |