add
Possibility 销售预测可能性
add, Delete, update, list
| | |
| | | SaleStageApi |
| | | SaleTypeApi |
| | | RegularCustomersApi |
| | | PossibilityApi |
| | | } |
| | | |
| | | var ApiGroup = new(Group) |
| | |
| | | saleStageService = service.ServiceGroup.SaleStageService |
| | | saleTypeService = service.ServiceGroup.SaleTypeService |
| | | regularCustomersService = service.ServiceGroup.RegularCustomersService |
| | | possibilityService = service.ServiceGroup.PossibilityService |
| | | ) |
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 PossibilityApi struct{} |
| | | |
| | | // Add |
| | | // |
| | | // @Tags Possibility |
| | | // @Summary 添加商机可能性 |
| | | // @Produce application/json |
| | | // @Param object body request.AddPossibility true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/possibility/add [post] |
| | | func (s *PossibilityApi) Add(c *gin.Context) { |
| | | var params request.AddPossibility |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | possibility := new(model.Possibility) |
| | | possibility.Name = params.Name |
| | | |
| | | errCode := possibilityService.AddPossibility(possibility) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // Delete |
| | | // |
| | | // @Tags Possibility |
| | | // @Summary 删除商机可能性 |
| | | // @Produce application/json |
| | | // @Param id path int true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/possibility/delete/{id} [delete] |
| | | func (s *PossibilityApi) Delete(c *gin.Context) { |
| | | ctx, ok := contextx.NewContext(c, nil) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | id, _ := strconv.Atoi(c.Param("id")) |
| | | errCode := possibilityService.DeletePossibility(id) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // Update |
| | | // |
| | | // @Tags Possibility |
| | | // @Summary 更新商机可能性 |
| | | // @Produce application/json |
| | | // @Param object body request.UpdatePossibilities true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/possibility/update [put] |
| | | func (s *PossibilityApi) Update(c *gin.Context) { |
| | | var params request.UpdatePossibilities |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | errCode := possibilityService.UpdatePossibility(params.Possibilities) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // List |
| | | // |
| | | // @Tags Possibility |
| | | // @Summary 商机可能性列表 |
| | | // @Produce application/json |
| | | // @Success 200 {object} contextx.Response{data=response.PossibilityResponse} |
| | | // @Router /api/possibility/list [get] |
| | | func (s *PossibilityApi) List(c *gin.Context) { |
| | | ctx, ok := contextx.NewContext(c, nil) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | possibilityList, errCode := possibilityService.GetPossibilityList() |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.OkWithDetailed(response.PossibilityResponse{List: possibilityList}) |
| | | } |
| | |
| | | sc.MemberId = saleChance.MemberId |
| | | sc.RegularCustomersId = saleChance.RegularCustomersId |
| | | sc.Competitors = saleChance.Competitors |
| | | sc.Possibilities = saleChance.Possibilities |
| | | sc.PossibilitiesId = saleChance.Possibilities |
| | | sc.Budget = saleChance.Budget |
| | | sc.ProjectedAmount = saleChance.ProjectedAmount |
| | | sc.Currency = constvar.CurrencyType(saleChance.Currency) |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api/possibility/add": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Possibility" |
| | | ], |
| | | "summary": "添加商机可能性", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.AddPossibility" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/possibility/delete/{id}": { |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Possibility" |
| | | ], |
| | | "summary": "删除商机可能性", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "description": "查询参数", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/possibility/list": { |
| | | "get": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Possibility" |
| | | ], |
| | | "summary": "商机可能性列表", |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "$ref": "#/definitions/response.PossibilityResponse" |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/possibility/update": { |
| | | "put": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Possibility" |
| | | ], |
| | | "summary": "更新商机可能性", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.UpdatePossibilities" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/province/add": { |
| | | "post": { |
| | | "produces": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "model.Possibility": { |
| | | "type": "object", |
| | | "properties": { |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "model.Province": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | "pain_points": { |
| | | "type": "string" |
| | | }, |
| | | "possibilities": { |
| | | "possibilities_id": { |
| | | "type": "integer" |
| | | }, |
| | | "process": { |
| | |
| | | } |
| | | }, |
| | | "request.AddIndustry": { |
| | | "type": "object", |
| | | "required": [ |
| | | "name" |
| | | ], |
| | | "properties": { |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.AddPossibility": { |
| | | "type": "object", |
| | | "required": [ |
| | | "name" |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdatePossibilities": { |
| | | "type": "object", |
| | | "required": [ |
| | | "possibilities" |
| | | ], |
| | | "properties": { |
| | | "possibilities": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/request.UpdatePossibility" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdatePossibility": { |
| | | "type": "object", |
| | | "required": [ |
| | | "id", |
| | | "name" |
| | | ], |
| | | "properties": { |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateProvince": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "response.PossibilityResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | | "list": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/model.Possibility" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "response.ProvinceResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api/possibility/add": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Possibility" |
| | | ], |
| | | "summary": "添加商机可能性", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.AddPossibility" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/possibility/delete/{id}": { |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Possibility" |
| | | ], |
| | | "summary": "删除商机可能性", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "description": "查询参数", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/possibility/list": { |
| | | "get": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Possibility" |
| | | ], |
| | | "summary": "商机可能性列表", |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "$ref": "#/definitions/response.PossibilityResponse" |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/possibility/update": { |
| | | "put": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Possibility" |
| | | ], |
| | | "summary": "更新商机可能性", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.UpdatePossibilities" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/province/add": { |
| | | "post": { |
| | | "produces": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "model.Possibility": { |
| | | "type": "object", |
| | | "properties": { |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "model.Province": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | "pain_points": { |
| | | "type": "string" |
| | | }, |
| | | "possibilities": { |
| | | "possibilities_id": { |
| | | "type": "integer" |
| | | }, |
| | | "process": { |
| | |
| | | } |
| | | }, |
| | | "request.AddIndustry": { |
| | | "type": "object", |
| | | "required": [ |
| | | "name" |
| | | ], |
| | | "properties": { |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.AddPossibility": { |
| | | "type": "object", |
| | | "required": [ |
| | | "name" |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdatePossibilities": { |
| | | "type": "object", |
| | | "required": [ |
| | | "possibilities" |
| | | ], |
| | | "properties": { |
| | | "possibilities": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/request.UpdatePossibility" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdatePossibility": { |
| | | "type": "object", |
| | | "required": [ |
| | | "id", |
| | | "name" |
| | | ], |
| | | "properties": { |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateProvince": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "response.PossibilityResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | | "list": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/model.Possibility" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "response.ProvinceResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | name: |
| | | type: string |
| | | type: object |
| | | model.Possibility: |
| | | properties: |
| | | id: |
| | | type: integer |
| | | name: |
| | | type: string |
| | | type: object |
| | | model.Province: |
| | | properties: |
| | | cities: |
| | |
| | | type: string |
| | | pain_points: |
| | | type: string |
| | | possibilities: |
| | | possibilities_id: |
| | | type: integer |
| | | process: |
| | | type: string |
| | |
| | | - follow_record |
| | | type: object |
| | | request.AddIndustry: |
| | | properties: |
| | | name: |
| | | type: string |
| | | required: |
| | | - name |
| | | type: object |
| | | request.AddPossibility: |
| | | properties: |
| | | name: |
| | | type: string |
| | |
| | | - id |
| | | - name |
| | | type: object |
| | | request.UpdatePossibilities: |
| | | properties: |
| | | possibilities: |
| | | items: |
| | | $ref: '#/definitions/request.UpdatePossibility' |
| | | type: array |
| | | required: |
| | | - possibilities |
| | | type: object |
| | | request.UpdatePossibility: |
| | | properties: |
| | | id: |
| | | type: integer |
| | | name: |
| | | type: string |
| | | required: |
| | | - id |
| | | - name |
| | | type: object |
| | | request.UpdateProvince: |
| | | properties: |
| | | id: |
| | |
| | | type: integer |
| | | total: |
| | | type: integer |
| | | type: object |
| | | response.PossibilityResponse: |
| | | properties: |
| | | list: |
| | | items: |
| | | $ref: '#/definitions/model.Possibility' |
| | | type: array |
| | | type: object |
| | | response.ProvinceResponse: |
| | | properties: |
| | |
| | | summary: 更新行业 |
| | | tags: |
| | | - Industry |
| | | /api/possibility/add: |
| | | post: |
| | | parameters: |
| | | - description: 查询参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.AddPossibility' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: OK |
| | | schema: |
| | | $ref: '#/definitions/contextx.Response' |
| | | summary: 添加商机可能性 |
| | | tags: |
| | | - Possibility |
| | | /api/possibility/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: |
| | | - Possibility |
| | | /api/possibility/list: |
| | | get: |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: OK |
| | | schema: |
| | | allOf: |
| | | - $ref: '#/definitions/contextx.Response' |
| | | - properties: |
| | | data: |
| | | $ref: '#/definitions/response.PossibilityResponse' |
| | | type: object |
| | | summary: 商机可能性列表 |
| | | tags: |
| | | - Possibility |
| | | /api/possibility/update: |
| | | put: |
| | | parameters: |
| | | - description: 查询参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.UpdatePossibilities' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: OK |
| | | schema: |
| | | $ref: '#/definitions/contextx.Response' |
| | | summary: 更新商机可能性 |
| | | tags: |
| | | - Possibility |
| | | /api/province/add: |
| | | post: |
| | | parameters: |
| | |
| | | [2023-07-06 13:52:52] [error] [main.main:29] model Init err:Error 1170 (42000): BLOB/TEXT column 'name' used in key specification without a key length |
| | | [2023-07-06 13:55:26] [error] [gorm.io/driver/mysql.Migrator.AlterColumn.func1:59] trace {"error": "Error 1170 (42000): BLOB/TEXT column 'name' used in key specification without a key length", "elapsed": 0.0007354, "rows": 0, "sql": "ALTER TABLE `client_level` MODIFY COLUMN `name` longtext"} |
| | | [2023-07-06 13:55:26] [error] [main.main:29] model Init err:Error 1170 (42000): BLOB/TEXT column 'name' used in key specification without a key length |
| | | [2023-07-10 11:06:33] [error] [aps_crm/model.(*PossibilitySearch).Create:46] trace {"error": "Error 1146 (42S02): Table 'aps_crm.possibility' doesn't exist", "elapsed": 0.0032687, "rows": 0, "sql": "INSERT INTO `possibility` (`name`) VALUES ('10')"} |
| | |
| | | SaleStage{}, |
| | | SaleType{}, |
| | | RegularCustomers{}, |
| | | Possibility{}, |
| | | ) |
| | | return err |
| | | } |
New file |
| | |
| | | package model |
| | | |
| | | import ( |
| | | "aps_crm/pkg/mysqlx" |
| | | "gorm.io/gorm" |
| | | ) |
| | | |
| | | type ( |
| | | // Possibility 商机可能性 |
| | | Possibility struct { |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | Name string `json:"name" gorm:"column:name;type:varchar(255);comment:商机可能性名称"` |
| | | } |
| | | |
| | | // PossibilitySearch 商机可能性搜索条件 |
| | | PossibilitySearch struct { |
| | | Possibility |
| | | Orm *gorm.DB |
| | | } |
| | | ) |
| | | |
| | | func (Possibility) TableName() string { |
| | | return "possibility" |
| | | } |
| | | |
| | | func NewPossibilitySearch() *PossibilitySearch { |
| | | return &PossibilitySearch{ |
| | | Orm: mysqlx.GetDB(), |
| | | } |
| | | } |
| | | |
| | | func (slf *PossibilitySearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&Possibility{}) |
| | | if slf.Id != 0 { |
| | | db = db.Where("id = ?", slf.Id) |
| | | } |
| | | if slf.Name != "" { |
| | | db = db.Where("name = ?", slf.Name) |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |
| | | func (slf *PossibilitySearch) Create(record *Possibility) error { |
| | | var db = slf.build() |
| | | return db.Create(record).Error |
| | | } |
| | | |
| | | func (slf *PossibilitySearch) Delete() error { |
| | | var db = slf.build() |
| | | return db.Delete(&Possibility{}).Error |
| | | } |
| | | |
| | | func (slf *PossibilitySearch) Update(record *Possibility) error { |
| | | var db = slf.build() |
| | | return db.Updates(record).Error |
| | | } |
| | | |
| | | func (slf *PossibilitySearch) Find() (*Possibility, error) { |
| | | var db = slf.build() |
| | | var record = new(Possibility) |
| | | err := db.First(record).Error |
| | | return record, err |
| | | } |
| | | |
| | | func (slf *PossibilitySearch) FindAll() ([]*Possibility, error) { |
| | | var db = slf.build() |
| | | var records = make([]*Possibility, 0) |
| | | err := db.Find(&records).Error |
| | | return records, err |
| | | } |
| | | |
| | | func (slf *PossibilitySearch) SetId(id int) *PossibilitySearch { |
| | | slf.Id = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *PossibilitySearch) SetName(name string) *PossibilitySearch { |
| | | slf.Name = name |
| | | return slf |
| | | } |
| | | |
| | | func (slf *PossibilitySearch) Updates(data map[string]interface{}) error { |
| | | var db = slf.build() |
| | | return db.Updates(data).Error |
| | | } |
New file |
| | |
| | | package request |
| | | |
| | | type AddPossibility struct { |
| | | Name string `json:"name" binding:"required"` |
| | | } |
| | | |
| | | type UpdatePossibility struct { |
| | | Id int `json:"id" binding:"required"` |
| | | Name string `json:"name" binding:"required"` |
| | | } |
| | | |
| | | type UpdatePossibilities struct { |
| | | Possibilities []*UpdatePossibility `json:"possibilities" binding:"required"` |
| | | } |
| | |
| | | RegularCustomersResponse struct { |
| | | List []*model.RegularCustomers `json:"list"` |
| | | } |
| | | |
| | | PossibilityResponse struct { |
| | | List []*model.Possibility `json:"list"` |
| | | } |
| | | ) |
| | |
| | | MemberId int `json:"member_id" gorm:"column:member_id;type:int(11);comment:销售负责人ID"` |
| | | RegularCustomersId int `json:"regular_customers_id" gorm:"column:regular_customers_id;type:int(11);comment:常客ID"` |
| | | Competitors string `json:"competitors" gorm:"column:competitors;type:varchar(255);comment:竞争对手"` |
| | | Possibilities int `json:"possibilities" gorm:"column:possibilities;type:int(11);comment:可能性"` |
| | | PossibilitiesId int `json:"possibilities_id" gorm:"column:possibilities_id;type:int(11);comment:可能性ID"` |
| | | Budget float64 `json:"budget" gorm:"column:budget;type:decimal(10,2);comment:预算"` |
| | | ProjectedAmount float64 `json:"projected_amount" gorm:"column:projected_amount;type:decimal(10,2);comment:预计金额"` |
| | | Currency constvar.CurrencyType `json:"currency" gorm:"column:currency;type:int(11);comment:货币类型"` |
| | |
| | | RegularCustomersUpdateErr = 2200005 // 更新固定客户失败 |
| | | RegularCustomersDeleteErr = 2200006 // 删除固定客户失败 |
| | | |
| | | PossibilityExist = 2300001 // 销售机会可能性已存在 |
| | | PossibilityNotExist = 2300002 // 销售机会可能性不存在 |
| | | PossibilityListErr = 2300003 // 获取销售机会可能性列表失败 |
| | | PossibilitySetErr = 2300004 // 设置销售机会可能性失败 |
| | | PossibilityUpdateErr = 2300005 // 更新销售机会可能性失败 |
| | | PossibilityDeleteErr = 2300006 // 删除销售机会可能性失败 |
| | | |
| | | ) |
| | |
| | | SaleStageRouter |
| | | SaleTypeRouter |
| | | RegularCustomersRouter |
| | | PossibilityRouter |
| | | } |
| | | |
| | | func InitRouter() *gin.Engine { |
| | |
| | | routerGroup.InitSaleStageRouter(PrivateGroup) // 注册saleStage路由 |
| | | routerGroup.InitSaleTypeRouter(PrivateGroup) // 注册saleType路由 |
| | | routerGroup.InitRegularCustomersRouter(PrivateGroup) // 注册regularCustomers路由 |
| | | routerGroup.InitPossibilityRouter(PrivateGroup) // 注册possibility路由 |
| | | } |
| | | return Router |
| | | } |
New file |
| | |
| | | package router |
| | | |
| | | import ( |
| | | v1 "aps_crm/api/v1" |
| | | "github.com/gin-gonic/gin" |
| | | ) |
| | | |
| | | type PossibilityRouter struct{} |
| | | |
| | | func (p *PossibilityRouter) InitPossibilityRouter(router *gin.RouterGroup) { |
| | | possibilityRouter := router.Group("possibility") |
| | | possibilityApi := v1.ApiGroup.PossibilityApi |
| | | { |
| | | possibilityRouter.POST("add", possibilityApi.Add) // 添加销售线索 |
| | | possibilityRouter.DELETE("delete/:id", possibilityApi.Delete) // 删除销售线索 |
| | | possibilityRouter.PUT("update", possibilityApi.Update) // 更新销售线索 |
| | | possibilityRouter.GET("list", possibilityApi.List) // 获取销售线索列表 |
| | | } |
| | | } |
| | |
| | | SaleStageService |
| | | SaleTypeService |
| | | RegularCustomersService |
| | | PossibilityService |
| | | } |
| | | |
| | | var ServiceGroup = new(Group) |
New file |
| | |
| | | package service |
| | | |
| | | import ( |
| | | "aps_crm/model" |
| | | "aps_crm/model/request" |
| | | "aps_crm/pkg/ecode" |
| | | ) |
| | | |
| | | type PossibilityService struct{} |
| | | |
| | | func (PossibilityService) AddPossibility(possibility *model.Possibility) int { |
| | | err := model.NewPossibilitySearch().Create(possibility) |
| | | if err != nil { |
| | | return ecode.PossibilityExist |
| | | } |
| | | |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (PossibilityService) DeletePossibility(id int) int { |
| | | _, err := model.NewPossibilitySearch().SetId(id).Find() |
| | | if err != nil { |
| | | return ecode.PossibilityNotExist |
| | | } |
| | | |
| | | err = model.NewPossibilitySearch().SetId(id).Delete() |
| | | if err != nil { |
| | | return ecode.PossibilityNotExist |
| | | } |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (PossibilityService) GetPossibilityList() ([]*model.Possibility, int) { |
| | | list, err := model.NewPossibilitySearch().FindAll() |
| | | if err != nil { |
| | | return nil, ecode.PossibilityListErr |
| | | } |
| | | |
| | | return list, ecode.OK |
| | | } |
| | | |
| | | func (PossibilityService) UpdatePossibility(possibilities []*request.UpdatePossibility) int { |
| | | for _, v := range possibilities { |
| | | // check possibility exist |
| | | _, err := model.NewPossibilitySearch().SetId(v.Id).Find() |
| | | if err != nil { |
| | | return ecode.PossibilityNotExist |
| | | } |
| | | |
| | | err = model.NewPossibilitySearch().SetId(v.Id).Updates(map[string]interface{}{ |
| | | "name": v.Name, |
| | | }) |
| | | if err != nil { |
| | | return ecode.PossibilitySetErr |
| | | } |
| | | } |
| | | |
| | | return ecode.OK |
| | | } |