add
regularCustomers 老客户营销
add, Delete, update, list
| | |
| | | SaleChanceApi |
| | | SaleStageApi |
| | | SaleTypeApi |
| | | RegularCustomersApi |
| | | } |
| | | |
| | | var ApiGroup = new(Group) |
| | |
| | | saleChanceService = service.ServiceGroup.SaleChanceService |
| | | saleStageService = service.ServiceGroup.SaleStageService |
| | | saleTypeService = service.ServiceGroup.SaleTypeService |
| | | regularCustomersService = service.ServiceGroup.RegularCustomersService |
| | | ) |
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 RegularCustomersApi struct{} |
| | | |
| | | // Add |
| | | // |
| | | // @Tags RegularCustomers |
| | | // @Summary 添加常客 |
| | | // @Produce application/json |
| | | // @Param object body request.AddRegularCustomers true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/regularCustomers/add [post] |
| | | func (s *RegularCustomersApi) Add(c *gin.Context) { |
| | | var params request.AddRegularCustomers |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | regularCustomers := new(model.RegularCustomers) |
| | | regularCustomers.Name = params.Name |
| | | |
| | | errCode := regularCustomersService.AddRegularCustomers(regularCustomers) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // Delete |
| | | // |
| | | // @Tags RegularCustomers |
| | | // @Summary 删除常客 |
| | | // @Produce application/json |
| | | // @Param id path int true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/regularCustomers/delete/{id} [delete] |
| | | func (s *RegularCustomersApi) Delete(c *gin.Context) { |
| | | ctx, ok := contextx.NewContext(c, nil) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | id, _ := strconv.Atoi(c.Param("id")) |
| | | errCode := regularCustomersService.DeleteRegularCustomers(id) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // Update |
| | | // |
| | | // @Tags RegularCustomers |
| | | // @Summary 更新常客 |
| | | // @Produce application/json |
| | | // @Param object body request.UpdateRegularCustomersList true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/regularCustomers/update [put] |
| | | func (s *RegularCustomersApi) Update(c *gin.Context) { |
| | | var params request.UpdateRegularCustomersList |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | errCode := regularCustomersService.UpdateRegularCustomers(params.RegularCustomers) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // List |
| | | // |
| | | // @Tags RegularCustomers |
| | | // @Summary 常客列表 |
| | | // @Produce application/json |
| | | // @Success 200 {object} contextx.Response{data=response.RegularCustomersResponse} |
| | | // @Router /api/regularCustomers/list [get] |
| | | func (s *RegularCustomersApi) List(c *gin.Context) { |
| | | ctx, ok := contextx.NewContext(c, nil) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | regularCustomers, errCode := regularCustomersService.GetRegularCustomersList() |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.OkWithDetailed(response.RegularCustomersResponse{ |
| | | List: regularCustomers, |
| | | }) |
| | | } |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api/regularCustomers/add": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "RegularCustomers" |
| | | ], |
| | | "summary": "添加常客", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.AddRegularCustomers" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/regularCustomers/delete/{id}": { |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "RegularCustomers" |
| | | ], |
| | | "summary": "删除常客", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "description": "查询参数", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/regularCustomers/list": { |
| | | "get": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "RegularCustomers" |
| | | ], |
| | | "summary": "常客列表", |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "$ref": "#/definitions/response.RegularCustomersResponse" |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/regularCustomers/update": { |
| | | "put": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "RegularCustomers" |
| | | ], |
| | | "summary": "更新常客", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.UpdateRegularCustomersList" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/saleChance/add": { |
| | | "post": { |
| | | "produces": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "model.RegularCustomers": { |
| | | "type": "object", |
| | | "properties": { |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "model.SaleChance": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | }, |
| | | "request.AddRegisteredCapital": { |
| | | "type": "object", |
| | | "required": [ |
| | | "name" |
| | | ], |
| | | "properties": { |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.AddRegularCustomers": { |
| | | "type": "object", |
| | | "required": [ |
| | | "name" |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateRegularCustomers": { |
| | | "type": "object", |
| | | "required": [ |
| | | "id", |
| | | "name" |
| | | ], |
| | | "properties": { |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateRegularCustomersList": { |
| | | "type": "object", |
| | | "required": [ |
| | | "regularCustomers" |
| | | ], |
| | | "properties": { |
| | | "regularCustomers": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/request.UpdateRegularCustomers" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateSaleChance": { |
| | | "type": "object", |
| | | "required": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "response.RegularCustomersResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | | "list": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/model.RegularCustomers" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "response.SaleChanceResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api/regularCustomers/add": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "RegularCustomers" |
| | | ], |
| | | "summary": "添加常客", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.AddRegularCustomers" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/regularCustomers/delete/{id}": { |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "RegularCustomers" |
| | | ], |
| | | "summary": "删除常客", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "description": "查询参数", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/regularCustomers/list": { |
| | | "get": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "RegularCustomers" |
| | | ], |
| | | "summary": "常客列表", |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "$ref": "#/definitions/response.RegularCustomersResponse" |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/regularCustomers/update": { |
| | | "put": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "RegularCustomers" |
| | | ], |
| | | "summary": "更新常客", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.UpdateRegularCustomersList" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/saleChance/add": { |
| | | "post": { |
| | | "produces": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "model.RegularCustomers": { |
| | | "type": "object", |
| | | "properties": { |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "model.SaleChance": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | }, |
| | | "request.AddRegisteredCapital": { |
| | | "type": "object", |
| | | "required": [ |
| | | "name" |
| | | ], |
| | | "properties": { |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.AddRegularCustomers": { |
| | | "type": "object", |
| | | "required": [ |
| | | "name" |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateRegularCustomers": { |
| | | "type": "object", |
| | | "required": [ |
| | | "id", |
| | | "name" |
| | | ], |
| | | "properties": { |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateRegularCustomersList": { |
| | | "type": "object", |
| | | "required": [ |
| | | "regularCustomers" |
| | | ], |
| | | "properties": { |
| | | "regularCustomers": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/request.UpdateRegularCustomers" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateSaleChance": { |
| | | "type": "object", |
| | | "required": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "response.RegularCustomersResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | | "list": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/model.RegularCustomers" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "response.SaleChanceResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | name: |
| | | type: string |
| | | type: object |
| | | model.RegularCustomers: |
| | | properties: |
| | | id: |
| | | type: integer |
| | | name: |
| | | type: string |
| | | type: object |
| | | model.SaleChance: |
| | | properties: |
| | | advantages: |
| | |
| | | type: string |
| | | type: object |
| | | request.AddRegisteredCapital: |
| | | properties: |
| | | name: |
| | | type: string |
| | | required: |
| | | - name |
| | | type: object |
| | | request.AddRegularCustomers: |
| | | properties: |
| | | name: |
| | | type: string |
| | |
| | | $ref: '#/definitions/request.UpdateRegisteredCapital' |
| | | type: array |
| | | type: object |
| | | request.UpdateRegularCustomers: |
| | | properties: |
| | | id: |
| | | type: integer |
| | | name: |
| | | type: string |
| | | required: |
| | | - id |
| | | - name |
| | | type: object |
| | | request.UpdateRegularCustomersList: |
| | | properties: |
| | | regularCustomers: |
| | | items: |
| | | $ref: '#/definitions/request.UpdateRegularCustomers' |
| | | type: array |
| | | required: |
| | | - regularCustomers |
| | | type: object |
| | | request.UpdateSaleChance: |
| | | properties: |
| | | advantages: |
| | |
| | | list: |
| | | items: |
| | | $ref: '#/definitions/model.RegisteredCapital' |
| | | type: array |
| | | type: object |
| | | response.RegularCustomersResponse: |
| | | properties: |
| | | list: |
| | | items: |
| | | $ref: '#/definitions/model.RegularCustomers' |
| | | type: array |
| | | type: object |
| | | response.SaleChanceResponse: |
| | |
| | | summary: 更新注册资本 |
| | | tags: |
| | | - RegisteredCapital |
| | | /api/regularCustomers/add: |
| | | post: |
| | | parameters: |
| | | - description: 查询参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.AddRegularCustomers' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: OK |
| | | schema: |
| | | $ref: '#/definitions/contextx.Response' |
| | | summary: 添加常客 |
| | | tags: |
| | | - RegularCustomers |
| | | /api/regularCustomers/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: |
| | | - RegularCustomers |
| | | /api/regularCustomers/list: |
| | | get: |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: OK |
| | | schema: |
| | | allOf: |
| | | - $ref: '#/definitions/contextx.Response' |
| | | - properties: |
| | | data: |
| | | $ref: '#/definitions/response.RegularCustomersResponse' |
| | | type: object |
| | | summary: 常客列表 |
| | | tags: |
| | | - RegularCustomers |
| | | /api/regularCustomers/update: |
| | | put: |
| | | parameters: |
| | | - description: 查询参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.UpdateRegularCustomersList' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: OK |
| | | schema: |
| | | $ref: '#/definitions/contextx.Response' |
| | | summary: 更新常客 |
| | | tags: |
| | | - RegularCustomers |
| | | /api/saleChance/add: |
| | | post: |
| | | parameters: |
New file |
| | |
| | | package model |
| | | |
| | | import ( |
| | | "aps_crm/pkg/mysqlx" |
| | | "gorm.io/gorm" |
| | | ) |
| | | |
| | | type ( |
| | | // RegularCustomers 老客户 |
| | | RegularCustomers struct { |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | Name string `json:"name" gorm:"column:name;type:varchar(255);comment:客户名称"` |
| | | } |
| | | |
| | | // RegularCustomersSearch 老客户搜索条件 |
| | | RegularCustomersSearch struct { |
| | | RegularCustomers |
| | | Orm *gorm.DB |
| | | } |
| | | ) |
| | | |
| | | func (RegularCustomers) TableName() string { |
| | | return "regular_customers" |
| | | } |
| | | |
| | | func NewRegularCustomersSearch() *RegularCustomersSearch { |
| | | return &RegularCustomersSearch{ |
| | | Orm: mysqlx.GetDB(), |
| | | } |
| | | } |
| | | |
| | | func (slf *RegularCustomersSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&RegularCustomers{}) |
| | | if slf.Id != 0 { |
| | | db = db.Where("id = ?", slf.Id) |
| | | } |
| | | if slf.Name != "" { |
| | | db = db.Where("name = ?", slf.Name) |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |
| | | func (slf *RegularCustomersSearch) Create(record *RegularCustomers) error { |
| | | var db = slf.build() |
| | | return db.Create(record).Error |
| | | } |
| | | |
| | | func (slf *RegularCustomersSearch) Delete() error { |
| | | var db = slf.build() |
| | | return db.Delete(&RegularCustomers{}).Error |
| | | } |
| | | |
| | | func (slf *RegularCustomersSearch) Update(record *RegularCustomers) error { |
| | | var db = slf.build() |
| | | return db.Updates(record).Error |
| | | } |
| | | |
| | | func (slf *RegularCustomersSearch) Find() (*RegularCustomers, error) { |
| | | var db = slf.build() |
| | | var record = &RegularCustomers{} |
| | | err := db.First(record).Error |
| | | return record, err |
| | | } |
| | | |
| | | func (slf *RegularCustomersSearch) FindAll() ([]*RegularCustomers, error) { |
| | | var db = slf.build() |
| | | var records = make([]*RegularCustomers, 0) |
| | | err := db.Find(&records).Error |
| | | return records, err |
| | | } |
| | | |
| | | func (slf *RegularCustomersSearch) SetId(id int) *RegularCustomersSearch { |
| | | slf.Id = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *RegularCustomersSearch) SetName(name string) *RegularCustomersSearch { |
| | | slf.Name = name |
| | | return slf |
| | | } |
| | | |
| | | func (slf *RegularCustomersSearch) Updates(data map[string]interface{}) error { |
| | | var db = slf.build() |
| | | return db.Updates(data).Error |
| | | } |
| | |
| | | SalesSources{}, |
| | | SaleStage{}, |
| | | SaleType{}, |
| | | RegularCustomers{}, |
| | | ) |
| | | return err |
| | | } |
New file |
| | |
| | | package request |
| | | |
| | | type AddRegularCustomers struct { |
| | | Name string `json:"name" binding:"required"` |
| | | } |
| | | |
| | | type UpdateRegularCustomers struct { |
| | | Id int `json:"id" binding:"required"` |
| | | Name string `json:"name" binding:"required"` |
| | | } |
| | | |
| | | type UpdateRegularCustomersList struct { |
| | | RegularCustomers []*UpdateRegularCustomers `json:"regularCustomers" binding:"required"` |
| | | } |
| | |
| | | SaleTypeResponse struct { |
| | | List []*model.SaleType `json:"list"` |
| | | } |
| | | |
| | | RegularCustomersResponse struct { |
| | | List []*model.RegularCustomers `json:"list"` |
| | | } |
| | | ) |
| | |
| | | SaleTypeUpdateErr = 2100005 // 更新销售类型失败 |
| | | SaleTypeDeleteErr = 2100006 // 删除销售类型失败 |
| | | |
| | | RegularCustomersExist = 2200001 // 固定客户已存在 |
| | | RegularCustomersNotExist = 2200002 // 固定客户不存在 |
| | | RegularCustomersListErr = 2200003 // 获取固定客户列表失败 |
| | | RegularCustomersSetErr = 2200004 // 设置固定客户失败 |
| | | RegularCustomersUpdateErr = 2200005 // 更新固定客户失败 |
| | | RegularCustomersDeleteErr = 2200006 // 删除固定客户失败 |
| | | |
| | | ) |
| | |
| | | SaleChanceRouter |
| | | SaleStageRouter |
| | | SaleTypeRouter |
| | | RegularCustomersRouter |
| | | } |
| | | |
| | | func InitRouter() *gin.Engine { |
| | |
| | | routerGroup.InitSaleChanceRouter(PrivateGroup) // 注册saleChance路由 |
| | | routerGroup.InitSaleStageRouter(PrivateGroup) // 注册saleStage路由 |
| | | routerGroup.InitSaleTypeRouter(PrivateGroup) // 注册saleType路由 |
| | | routerGroup.InitRegularCustomersRouter(PrivateGroup) // 注册regularCustomers路由 |
| | | } |
| | | return Router |
| | | } |
New file |
| | |
| | | package router |
| | | |
| | | import ( |
| | | v1 "aps_crm/api/v1" |
| | | "github.com/gin-gonic/gin" |
| | | ) |
| | | |
| | | type RegularCustomersRouter struct{} |
| | | |
| | | func (r *RegularCustomersRouter) InitRegularCustomersRouter(router *gin.RouterGroup) { |
| | | regularCustomersRouter := router.Group("regularCustomers") |
| | | regularCustomersApi := v1.ApiGroup.RegularCustomersApi |
| | | { |
| | | regularCustomersRouter.POST("add", regularCustomersApi.Add) // 添加常客 |
| | | regularCustomersRouter.DELETE("delete/:id", regularCustomersApi.Delete) // 删除常客 |
| | | regularCustomersRouter.PUT("update", regularCustomersApi.Update) // 更新常客 |
| | | regularCustomersRouter.GET("list", regularCustomersApi.List) // 获取常客列表 |
| | | } |
| | | } |
| | |
| | | SaleChanceService |
| | | SaleStageService |
| | | SaleTypeService |
| | | RegularCustomersService |
| | | } |
| | | |
| | | var ServiceGroup = new(Group) |
New file |
| | |
| | | package service |
| | | |
| | | import ( |
| | | "aps_crm/model" |
| | | "aps_crm/model/request" |
| | | "aps_crm/pkg/ecode" |
| | | ) |
| | | |
| | | type RegularCustomersService struct{} |
| | | |
| | | func (RegularCustomersService) AddRegularCustomers(regularCustomers *model.RegularCustomers) int { |
| | | err := model.NewRegularCustomersSearch().Create(regularCustomers) |
| | | if err != nil { |
| | | return ecode.RegularCustomersExist |
| | | } |
| | | |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (RegularCustomersService) DeleteRegularCustomers(id int) int { |
| | | _, err := model.NewRegularCustomersSearch().SetId(id).Find() |
| | | if err != nil { |
| | | return ecode.RegularCustomersNotExist |
| | | } |
| | | |
| | | err = model.NewRegularCustomersSearch().SetId(id).Delete() |
| | | if err != nil { |
| | | return ecode.RegularCustomersNotExist |
| | | } |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (RegularCustomersService) GetRegularCustomersList() ([]*model.RegularCustomers, int) { |
| | | list, err := model.NewRegularCustomersSearch().FindAll() |
| | | if err != nil { |
| | | return nil, ecode.RegularCustomersListErr |
| | | } |
| | | |
| | | return list, ecode.OK |
| | | } |
| | | |
| | | func (RegularCustomersService) UpdateRegularCustomers(regularCustomers []*request.UpdateRegularCustomers) int { |
| | | for _, v := range regularCustomers { |
| | | // check regularCustomers exist |
| | | _, err := model.NewRegularCustomersSearch().SetId(v.Id).Find() |
| | | if err != nil { |
| | | return ecode.RegularCustomersNotExist |
| | | } |
| | | |
| | | err = model.NewRegularCustomersSearch().SetId(v.Id).Updates(map[string]interface{}{ |
| | | "name": v.Name, |
| | | }) |
| | | if err != nil { |
| | | return ecode.RegularCustomersSetErr |
| | | } |
| | | } |
| | | |
| | | return ecode.OK |
| | | } |