add
Quotation 报价单
add, Delete, update, list
| | |
| | | RegularCustomersApi |
| | | PossibilityApi |
| | | StatusApi |
| | | QuotationApi |
| | | } |
| | | |
| | | var ApiGroup = new(Group) |
| | |
| | | regularCustomersService = service.ServiceGroup.RegularCustomersService |
| | | possibilityService = service.ServiceGroup.PossibilityService |
| | | statusService = service.ServiceGroup.StatusService |
| | | quotationService = service.ServiceGroup.QuotationService |
| | | ) |
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 QuotationApi struct{} |
| | | |
| | | // Add |
| | | // |
| | | // @Tags Quotation |
| | | // @Summary 添加报价单 |
| | | // @Produce application/json |
| | | // @Param object body request.AddQuotation true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/quotation/add [post] |
| | | func (s *QuotationApi) Add(c *gin.Context) { |
| | | var params request.AddQuotation |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | errCode, quotation := checkQuotationParams(params.Quotation) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | errCode = quotationService.AddQuotation("ation) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // Delete |
| | | // |
| | | // @Tags Quotation |
| | | // @Summary 删除报价单 |
| | | // @Produce application/json |
| | | // @Param id path int true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/quotation/delete/{id} [delete] |
| | | func (s *QuotationApi) Delete(c *gin.Context) { |
| | | ctx, ok := contextx.NewContext(c, nil) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | id, _ := strconv.Atoi(c.Param("id")) |
| | | errCode := quotationService.DeleteQuotation(id) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // Update |
| | | // |
| | | // @Tags Quotation |
| | | // @Summary 更新报价单 |
| | | // @Produce application/json |
| | | // @Param object body request.UpdateQuotation true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/quotation/update [put] |
| | | func (s *QuotationApi) Update(c *gin.Context) { |
| | | var params request.UpdateQuotation |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | errCode, quotation := checkQuotationParams(params.Quotation) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | quotation.Id = params.Id |
| | | |
| | | errCode = quotationService.UpdateQuotation("ation) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // List |
| | | // |
| | | // @Tags Quotation |
| | | // @Summary 报价单列表 |
| | | // @Produce application/json |
| | | // @Success 200 {object} contextx.Response{data=response.QuotationResponse} |
| | | // @Router /api/quotation/list [get] |
| | | func (s *QuotationApi) List(c *gin.Context) { |
| | | ctx, ok := contextx.NewContext(c, nil) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | list, errCode := quotationService.GetQuotationList() |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.OkWithDetailed(response.QuotationResponse{ |
| | | List: list, |
| | | }) |
| | | } |
| | | |
| | | // checkQuotationParams |
| | | func checkQuotationParams(quotation request.Quotation) (int, model.Quotation) { |
| | | var errCode int |
| | | var quotationModel model.Quotation |
| | | |
| | | if quotation.ClientId == 0 { |
| | | errCode = ecode.InvalidParams |
| | | return errCode, quotationModel |
| | | } |
| | | |
| | | if quotation.QuotationStatusId == 0 { |
| | | errCode = ecode.InvalidParams |
| | | return errCode, quotationModel |
| | | } |
| | | |
| | | if quotation.Number == "" { |
| | | errCode = ecode.InvalidParams |
| | | return errCode, quotationModel |
| | | } |
| | | |
| | | if quotation.MemberId == 0 { |
| | | errCode = ecode.InvalidParams |
| | | return errCode, quotationModel |
| | | } |
| | | |
| | | t, err := checkTimeFormat(quotation.ValidityDate) |
| | | if err != nil { |
| | | errCode = ecode.InvalidParams |
| | | return errCode, quotationModel |
| | | } |
| | | |
| | | quotationModel.ValidityDate = t |
| | | quotationModel.ClientId = quotation.ClientId |
| | | quotationModel.QuotationStatusId = quotation.QuotationStatusId |
| | | quotationModel.Number = quotation.Number |
| | | quotationModel.MemberId = quotation.MemberId |
| | | quotationModel.SaleChanceId = quotation.SaleChanceId |
| | | quotationModel.ContactId = quotation.ContactId |
| | | quotationModel.Conditions = quotation.Conditions |
| | | quotationModel.File = quotation.File |
| | | |
| | | return ecode.OK, quotationModel |
| | | |
| | | } |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api/quotation/add": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Quotation" |
| | | ], |
| | | "summary": "添加报价单", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.AddQuotation" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/quotation/delete/{id}": { |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Quotation" |
| | | ], |
| | | "summary": "删除报价单", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "description": "查询参数", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/quotation/list": { |
| | | "get": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Quotation" |
| | | ], |
| | | "summary": "报价单列表", |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "$ref": "#/definitions/response.QuotationResponse" |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/quotation/update": { |
| | | "put": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Quotation" |
| | | ], |
| | | "summary": "更新报价单", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.UpdateQuotation" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/region/add": { |
| | | "post": { |
| | | "produces": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "model.Quotation": { |
| | | "type": "object", |
| | | "properties": { |
| | | "client_id": { |
| | | "type": "integer" |
| | | }, |
| | | "conditions": { |
| | | "type": "string" |
| | | }, |
| | | "contact_id": { |
| | | "type": "integer" |
| | | }, |
| | | "file": { |
| | | "type": "string" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "member_id": { |
| | | "type": "integer" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "quotation_status_id": { |
| | | "type": "integer" |
| | | }, |
| | | "sale_chance_id": { |
| | | "type": "integer" |
| | | }, |
| | | "validity_date": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "model.Region": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | "properties": { |
| | | "name": { |
| | | "description": "省份名称", |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.AddQuotation": { |
| | | "type": "object", |
| | | "properties": { |
| | | "client_id": { |
| | | "type": "integer" |
| | | }, |
| | | "conditions": { |
| | | "type": "string" |
| | | }, |
| | | "contact_id": { |
| | | "type": "integer" |
| | | }, |
| | | "file": { |
| | | "type": "string" |
| | | }, |
| | | "member_id": { |
| | | "type": "integer" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "quotation_status_id": { |
| | | "type": "integer" |
| | | }, |
| | | "sale_chance_id": { |
| | | "type": "integer" |
| | | }, |
| | | "validity_date": { |
| | | "type": "string" |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateQuotation": { |
| | | "type": "object", |
| | | "properties": { |
| | | "client_id": { |
| | | "type": "integer" |
| | | }, |
| | | "conditions": { |
| | | "type": "string" |
| | | }, |
| | | "contact_id": { |
| | | "type": "integer" |
| | | }, |
| | | "file": { |
| | | "type": "string" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "member_id": { |
| | | "type": "integer" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "quotation_status_id": { |
| | | "type": "integer" |
| | | }, |
| | | "sale_chance_id": { |
| | | "type": "integer" |
| | | }, |
| | | "validity_date": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateRegion": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "response.QuotationResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | | "list": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/model.Quotation" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "response.RegisteredCapitalResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api/quotation/add": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Quotation" |
| | | ], |
| | | "summary": "添加报价单", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.AddQuotation" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/quotation/delete/{id}": { |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Quotation" |
| | | ], |
| | | "summary": "删除报价单", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "description": "查询参数", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/quotation/list": { |
| | | "get": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Quotation" |
| | | ], |
| | | "summary": "报价单列表", |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "$ref": "#/definitions/response.QuotationResponse" |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/quotation/update": { |
| | | "put": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "Quotation" |
| | | ], |
| | | "summary": "更新报价单", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.UpdateQuotation" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/region/add": { |
| | | "post": { |
| | | "produces": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "model.Quotation": { |
| | | "type": "object", |
| | | "properties": { |
| | | "client_id": { |
| | | "type": "integer" |
| | | }, |
| | | "conditions": { |
| | | "type": "string" |
| | | }, |
| | | "contact_id": { |
| | | "type": "integer" |
| | | }, |
| | | "file": { |
| | | "type": "string" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "member_id": { |
| | | "type": "integer" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "quotation_status_id": { |
| | | "type": "integer" |
| | | }, |
| | | "sale_chance_id": { |
| | | "type": "integer" |
| | | }, |
| | | "validity_date": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "model.Region": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | "properties": { |
| | | "name": { |
| | | "description": "省份名称", |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.AddQuotation": { |
| | | "type": "object", |
| | | "properties": { |
| | | "client_id": { |
| | | "type": "integer" |
| | | }, |
| | | "conditions": { |
| | | "type": "string" |
| | | }, |
| | | "contact_id": { |
| | | "type": "integer" |
| | | }, |
| | | "file": { |
| | | "type": "string" |
| | | }, |
| | | "member_id": { |
| | | "type": "integer" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "quotation_status_id": { |
| | | "type": "integer" |
| | | }, |
| | | "sale_chance_id": { |
| | | "type": "integer" |
| | | }, |
| | | "validity_date": { |
| | | "type": "string" |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateQuotation": { |
| | | "type": "object", |
| | | "properties": { |
| | | "client_id": { |
| | | "type": "integer" |
| | | }, |
| | | "conditions": { |
| | | "type": "string" |
| | | }, |
| | | "contact_id": { |
| | | "type": "integer" |
| | | }, |
| | | "file": { |
| | | "type": "string" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "member_id": { |
| | | "type": "integer" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "quotation_status_id": { |
| | | "type": "integer" |
| | | }, |
| | | "sale_chance_id": { |
| | | "type": "integer" |
| | | }, |
| | | "validity_date": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateRegion": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "response.QuotationResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | | "list": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/model.Quotation" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "response.RegisteredCapitalResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | name: |
| | | type: string |
| | | type: object |
| | | model.Quotation: |
| | | properties: |
| | | client_id: |
| | | type: integer |
| | | conditions: |
| | | type: string |
| | | contact_id: |
| | | type: integer |
| | | file: |
| | | type: string |
| | | id: |
| | | type: integer |
| | | member_id: |
| | | type: integer |
| | | number: |
| | | type: string |
| | | quotation_status_id: |
| | | type: integer |
| | | sale_chance_id: |
| | | type: integer |
| | | validity_date: |
| | | type: string |
| | | type: object |
| | | model.Region: |
| | | properties: |
| | | id: |
| | |
| | | properties: |
| | | name: |
| | | description: 省份名称 |
| | | type: string |
| | | type: object |
| | | request.AddQuotation: |
| | | properties: |
| | | client_id: |
| | | type: integer |
| | | conditions: |
| | | type: string |
| | | contact_id: |
| | | type: integer |
| | | file: |
| | | type: string |
| | | member_id: |
| | | type: integer |
| | | number: |
| | | type: string |
| | | quotation_status_id: |
| | | type: integer |
| | | sale_chance_id: |
| | | type: integer |
| | | validity_date: |
| | | type: string |
| | | type: object |
| | | request.AddRegion: |
| | |
| | | $ref: '#/definitions/request.UpdateProvince' |
| | | type: array |
| | | type: object |
| | | request.UpdateQuotation: |
| | | properties: |
| | | client_id: |
| | | type: integer |
| | | conditions: |
| | | type: string |
| | | contact_id: |
| | | type: integer |
| | | file: |
| | | type: string |
| | | id: |
| | | type: integer |
| | | member_id: |
| | | type: integer |
| | | number: |
| | | type: string |
| | | quotation_status_id: |
| | | type: integer |
| | | sale_chance_id: |
| | | type: integer |
| | | validity_date: |
| | | type: string |
| | | type: object |
| | | request.UpdateRegion: |
| | | properties: |
| | | id: |
| | |
| | | list: |
| | | items: |
| | | $ref: '#/definitions/model.Province' |
| | | type: array |
| | | type: object |
| | | response.QuotationResponse: |
| | | properties: |
| | | list: |
| | | items: |
| | | $ref: '#/definitions/model.Quotation' |
| | | type: array |
| | | type: object |
| | | response.RegisteredCapitalResponse: |
| | |
| | | summary: 更新省份 |
| | | tags: |
| | | - Province |
| | | /api/quotation/add: |
| | | post: |
| | | parameters: |
| | | - description: 查询参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.AddQuotation' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: OK |
| | | schema: |
| | | $ref: '#/definitions/contextx.Response' |
| | | summary: 添加报价单 |
| | | tags: |
| | | - Quotation |
| | | /api/quotation/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: |
| | | - Quotation |
| | | /api/quotation/list: |
| | | get: |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: OK |
| | | schema: |
| | | allOf: |
| | | - $ref: '#/definitions/contextx.Response' |
| | | - properties: |
| | | data: |
| | | $ref: '#/definitions/response.QuotationResponse' |
| | | type: object |
| | | summary: 报价单列表 |
| | | tags: |
| | | - Quotation |
| | | /api/quotation/update: |
| | | put: |
| | | parameters: |
| | | - description: 查询参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.UpdateQuotation' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: OK |
| | | schema: |
| | | $ref: '#/definitions/contextx.Response' |
| | | summary: 更新报价单 |
| | | tags: |
| | | - Quotation |
| | | /api/region/add: |
| | | post: |
| | | parameters: |
| | |
| | | RegularCustomers{}, |
| | | Possibility{}, |
| | | Status{}, |
| | | Quotation{}, |
| | | ) |
| | | return err |
| | | } |
New file |
| | |
| | | package model |
| | | |
| | | import ( |
| | | "aps_crm/pkg/mysqlx" |
| | | "gorm.io/gorm" |
| | | "time" |
| | | ) |
| | | |
| | | type ( |
| | | // Quotation 报价单 |
| | | Quotation struct { |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | ClientId int `json:"client_id" gorm:"column:client_id;type:int;comment:客户id"` |
| | | Number string `json:"number" gorm:"column:number;type:varchar(255);comment:报价单号"` |
| | | QuotationStatusId int `json:"quotation_status_id" gorm:"column:quotation_status_id;type:int;comment:报价单状态id"` |
| | | ValidityDate time.Time `json:"validity_date" gorm:"column:validity_date;type:datetime;comment:有效期"` |
| | | ContactId int `json:"contact_id" gorm:"column:contact_id;type:int;comment:联系人id"` |
| | | MemberId int `json:"member_id" gorm:"column:member_id;type:int;comment:负责人id"` |
| | | SaleChanceId int `json:"sale_chance_id" gorm:"column:sale_chance_id;type:int;comment:商机id"` |
| | | Conditions string `json:"conditions" gorm:"column:conditions;type:text;comment:报价条件"` |
| | | File string `json:"file" gorm:"column:file;type:varchar(255);comment:附件"` |
| | | Client Client `json:"client" gorm:"foreignKey:ClientId"` |
| | | Contact Contact `json:"contact" gorm:"foreignKey:ContactId"` |
| | | SaleChance SaleChance `json:"sale_chance" gorm:"foreignKey:SaleChanceId"` |
| | | } |
| | | |
| | | // QuotationSearch 报价单搜索条件 |
| | | QuotationSearch struct { |
| | | Quotation |
| | | Orm *gorm.DB |
| | | } |
| | | ) |
| | | |
| | | func (Quotation) TableName() string { |
| | | return "quotation" |
| | | } |
| | | |
| | | func NewQuotationSearch() *QuotationSearch { |
| | | return &QuotationSearch{ |
| | | Orm: mysqlx.GetDB(), |
| | | } |
| | | } |
| | | |
| | | func (slf *QuotationSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&Quotation{}) |
| | | if slf.Id != 0 { |
| | | db = db.Where("id = ?", slf.Id) |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |
| | | func (slf *QuotationSearch) Create(record *Quotation) error { |
| | | var db = slf.build() |
| | | return db.Create(record).Error |
| | | } |
| | | |
| | | func (slf *QuotationSearch) Delete() error { |
| | | var db = slf.build() |
| | | return db.Delete(&Quotation{}).Error |
| | | } |
| | | |
| | | func (slf *QuotationSearch) Update(record *Quotation) error { |
| | | var db = slf.build() |
| | | return db.Updates(record).Error |
| | | } |
| | | |
| | | func (slf *QuotationSearch) Find() (*Quotation, error) { |
| | | var db = slf.build() |
| | | var record Quotation |
| | | err := db.Preload("Client").Preload("Contact").Preload("SaleChance").First(&record).Error |
| | | return &record, err |
| | | } |
| | | |
| | | func (slf *QuotationSearch) FindAll() ([]*Quotation, error) { |
| | | var db = slf.build() |
| | | var records []*Quotation |
| | | err := db.Find(&records).Error |
| | | return records, err |
| | | } |
| | | |
| | | func (slf *QuotationSearch) SetId(id int) *QuotationSearch { |
| | | slf.Id = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *QuotationSearch) Updates(data map[string]interface{}) error { |
| | | var db = slf.build() |
| | | return db.Updates(data).Error |
| | | } |
New file |
| | |
| | | package request |
| | | |
| | | type AddQuotation struct { |
| | | Quotation |
| | | } |
| | | |
| | | type Quotation struct { |
| | | ClientId int `json:"client_id"` |
| | | Number string `json:"number"` |
| | | QuotationStatusId int `json:"quotation_status_id"` |
| | | ValidityDate string `json:"validity_date"` |
| | | ContactId int `json:"contact_id"` |
| | | MemberId int `json:"member_id"` |
| | | SaleChanceId int `json:"sale_chance_id"` |
| | | Conditions string `json:"conditions"` |
| | | File string `json:"file"` |
| | | } |
| | | |
| | | type UpdateQuotation struct { |
| | | Id int `json:"id"` |
| | | Quotation |
| | | } |
| | |
| | | StatusResponse struct { |
| | | List []*model.Status `json:"list"` |
| | | } |
| | | |
| | | QuotationResponse struct { |
| | | List []*model.Quotation `json:"list"` |
| | | } |
| | | ) |
| | |
| | | StatusUpdateErr = 2400005 // 更新销售机会状态失败 |
| | | StatusDeleteErr = 2400006 // 删除销售机会状态失败 |
| | | |
| | | QuotationExist = 2500001 // 报价单已存在 |
| | | QuotationNotExist = 2500002 // 报价单不存在 |
| | | QuotationListErr = 2500003 // 获取报价单列表失败 |
| | | QuotationSetErr = 2500004 // 设置报价单失败 |
| | | QuotationUpdateErr = 2500005 // 更新报价单失败 |
| | | QuotationDeleteErr = 2500006 // 删除报价单失败 |
| | | ) |
| | |
| | | RegularCustomersRouter |
| | | PossibilityRouter |
| | | StatusRouter |
| | | QuotationRouter |
| | | } |
| | | |
| | | func InitRouter() *gin.Engine { |
| | |
| | | routerGroup.InitRegularCustomersRouter(PrivateGroup) // 注册regularCustomers路由 |
| | | routerGroup.InitPossibilityRouter(PrivateGroup) // 注册possibility路由 |
| | | routerGroup.InitStatusRouter(PrivateGroup) // 注册status路由 |
| | | routerGroup.InitQuotationRouter(PrivateGroup) // 注册quotation路由 |
| | | } |
| | | return Router |
| | | } |
New file |
| | |
| | | package router |
| | | |
| | | import ( |
| | | v1 "aps_crm/api/v1" |
| | | "github.com/gin-gonic/gin" |
| | | ) |
| | | |
| | | type QuotationRouter struct{} |
| | | |
| | | func (s *QuotationRouter) InitQuotationRouter(router *gin.RouterGroup) { |
| | | quotationRouter := router.Group("quotation") |
| | | quotationApi := v1.ApiGroup.QuotationApi |
| | | { |
| | | quotationRouter.POST("add", quotationApi.Add) // 添加报价单 |
| | | quotationRouter.DELETE("delete/:id", quotationApi.Delete) // 删除报价单 |
| | | quotationRouter.PUT("update", quotationApi.Update) // 更新报价单 |
| | | quotationRouter.GET("list", quotationApi.List) // 获取报价单列表 |
| | | } |
| | | } |
| | |
| | | RegularCustomersService |
| | | PossibilityService |
| | | StatusService |
| | | QuotationService |
| | | } |
| | | |
| | | var ServiceGroup = new(Group) |
New file |
| | |
| | | package service |
| | | |
| | | import ( |
| | | "aps_crm/model" |
| | | "aps_crm/pkg/ecode" |
| | | ) |
| | | |
| | | type QuotationService struct{} |
| | | |
| | | func (QuotationService) AddQuotation(quotation *model.Quotation) int { |
| | | err := model.NewQuotationSearch().Create(quotation) |
| | | if err != nil { |
| | | return ecode.QuotationExist |
| | | } |
| | | |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (QuotationService) DeleteQuotation(id int) int { |
| | | _, err := model.NewQuotationSearch().SetId(id).Find() |
| | | if err != nil { |
| | | return ecode.QuotationNotExist |
| | | } |
| | | |
| | | err = model.NewQuotationSearch().SetId(id).Delete() |
| | | if err != nil { |
| | | return ecode.QuotationNotExist |
| | | } |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (QuotationService) GetQuotationList() ([]*model.Quotation, int) { |
| | | list, err := model.NewQuotationSearch().FindAll() |
| | | if err != nil { |
| | | return nil, ecode.QuotationListErr |
| | | } |
| | | |
| | | return list, ecode.OK |
| | | } |
| | | |
| | | func (QuotationService) UpdateQuotation(quotation *model.Quotation) int { |
| | | // check quotation exist |
| | | _, err := model.NewQuotationSearch().SetId(quotation.Id).Find() |
| | | if err != nil { |
| | | return ecode.QuotationNotExist |
| | | } |
| | | |
| | | err = model.NewQuotationSearch().SetId(quotation.Id).Update(quotation) |
| | | if err != nil { |
| | | return ecode.QuotationSetErr |
| | | } |
| | | |
| | | return ecode.OK |
| | | } |