add
serviceContract 服务合同
add, Delete, update, list
| | |
| | | SalesRefundApi |
| | | ContractApi |
| | | PlanApi |
| | | ServiceContractApi |
| | | } |
| | | |
| | | var ApiGroup = new(Group) |
| | |
| | | salesRefundService = service.ServiceGroup.SalesRefundService |
| | | contractService = service.ServiceGroup.ContractService |
| | | planService = service.ServiceGroup.PlanService |
| | | serviceContractService = service.ServiceGroup.SContractService |
| | | ) |
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 ServiceContractApi struct{} |
| | | |
| | | // Add |
| | | // |
| | | // @Tags ServiceContract |
| | | // @Summary 添加服务合同 |
| | | // @Produce application/json |
| | | // @Param object body request.AddServiceContract true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/serviceContract/add [post] |
| | | func (s *ServiceContractApi) Add(c *gin.Context) { |
| | | var params request.AddServiceContract |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | errCode, serviceContract := checkServiceContractParams(params.ServiceContract) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | errCode = serviceContractService.AddServiceContract(&serviceContract) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // Delete |
| | | // |
| | | // @Tags ServiceContract |
| | | // @Summary 删除服务合同 |
| | | // @Produce application/json |
| | | // @Param id path int true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/serviceContract/delete/{id} [delete] |
| | | func (s *ServiceContractApi) Delete(c *gin.Context) { |
| | | ctx, ok := contextx.NewContext(c, nil) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | id, _ := strconv.Atoi(c.Param("id")) |
| | | errCode := serviceContractService.DeleteServiceContract(id) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // Update |
| | | // |
| | | // @Tags ServiceContract |
| | | // @Summary 更新服务合同 |
| | | // @Produce application/json |
| | | // @Param object body request.UpdateServiceContract true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/serviceContract/update [put] |
| | | func (s *ServiceContractApi) Update(c *gin.Context) { |
| | | var params request.UpdateServiceContract |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | errCode, serviceContract := checkServiceContractParams(params.ServiceContract) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | serviceContract.Id = params.Id |
| | | |
| | | errCode = serviceContractService.UpdateServiceContract(&serviceContract) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // List |
| | | // |
| | | // @Tags ServiceContract |
| | | // @Summary 服务合同列表 |
| | | // @Produce application/json |
| | | // @Success 200 {object} contextx.Response{data=response.ServiceContractsResponse} |
| | | // @Router /api/serviceContract/list [get] |
| | | func (s *ServiceContractApi) List(c *gin.Context) { |
| | | ctx, ok := contextx.NewContext(c, nil) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | serviceContracts, errCode := serviceContractService.GetServiceContractList() |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.OkWithDetailed(response.ServiceContractsResponse{ |
| | | List: serviceContracts, |
| | | }) |
| | | } |
| | | |
| | | // check params |
| | | func checkServiceContractParams(serviceContract request.ServiceContract) (errCode int, result model.ServiceContract) { |
| | | if serviceContract.SignTime == "" { |
| | | return ecode.InvalidParams, result |
| | | } |
| | | |
| | | if serviceContract.Number == "" { |
| | | return ecode.InvalidParams, result |
| | | } |
| | | |
| | | if serviceContract.MemberId <= 0 { |
| | | return ecode.InvalidParams, result |
| | | } |
| | | |
| | | t, err := checkTimeFormat(serviceContract.SignTime) |
| | | if err != nil { |
| | | return ecode.InvalidParams, result |
| | | } |
| | | |
| | | result.SignTime = t |
| | | |
| | | t, err = checkTimeFormat(serviceContract.StartTime) |
| | | if err != nil { |
| | | return ecode.InvalidParams, result |
| | | } |
| | | |
| | | result.StartTime = t |
| | | |
| | | t, err = checkTimeFormat(serviceContract.EndTime) |
| | | if err != nil { |
| | | return ecode.InvalidParams, result |
| | | } |
| | | |
| | | result.EndTime = t |
| | | |
| | | result.Number = serviceContract.Number |
| | | result.MemberId = serviceContract.MemberId |
| | | result.Remark = serviceContract.Remark |
| | | result.ClientId = serviceContract.ClientId |
| | | result.ContactId = serviceContract.ContactId |
| | | result.SaleChanceId = serviceContract.SaleChanceId |
| | | result.QuotationId = serviceContract.QuotationId |
| | | result.TypeId = serviceContract.TypeId |
| | | result.StatusId = serviceContract.StatusId |
| | | result.ServiceTimes = serviceContract.ServiceTimes |
| | | result.Terms = serviceContract.Terms |
| | | result.Products = serviceContract.Products |
| | | |
| | | return ecode.OK, result |
| | | } |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api/serviceContract/add": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "ServiceContract" |
| | | ], |
| | | "summary": "添加服务合同", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.AddServiceContract" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/serviceContract/delete/{id}": { |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "ServiceContract" |
| | | ], |
| | | "summary": "删除服务合同", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "description": "查询参数", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/serviceContract/list": { |
| | | "get": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "ServiceContract" |
| | | ], |
| | | "summary": "服务合同列表", |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "$ref": "#/definitions/response.ServiceContractsResponse" |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/serviceContract/update": { |
| | | "put": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "ServiceContract" |
| | | ], |
| | | "summary": "更新服务合同", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.UpdateServiceContract" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/status/add": { |
| | | "post": { |
| | | "produces": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "model.ServiceContract": { |
| | | "type": "object", |
| | | "properties": { |
| | | "clientId": { |
| | | "type": "integer" |
| | | }, |
| | | "contactId": { |
| | | "type": "integer" |
| | | }, |
| | | "contractId": { |
| | | "type": "integer" |
| | | }, |
| | | "endTime": { |
| | | "type": "string" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "memberId": { |
| | | "type": "integer" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "products": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/model.Product" |
| | | } |
| | | }, |
| | | "quotationId": { |
| | | "type": "integer" |
| | | }, |
| | | "remark": { |
| | | "type": "string" |
| | | }, |
| | | "saleChanceId": { |
| | | "type": "integer" |
| | | }, |
| | | "serviceTimes": { |
| | | "type": "integer" |
| | | }, |
| | | "signTime": { |
| | | "type": "string" |
| | | }, |
| | | "startTime": { |
| | | "type": "string" |
| | | }, |
| | | "statusId": { |
| | | "type": "integer" |
| | | }, |
| | | "terms": { |
| | | "type": "string" |
| | | }, |
| | | "typeId": { |
| | | "type": "integer" |
| | | } |
| | | } |
| | | }, |
| | | "model.SubOrder": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | "properties": { |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.AddServiceContract": { |
| | | "type": "object", |
| | | "properties": { |
| | | "clientId": { |
| | | "type": "integer" |
| | | }, |
| | | "contactId": { |
| | | "type": "integer" |
| | | }, |
| | | "contractId": { |
| | | "type": "integer" |
| | | }, |
| | | "endTime": { |
| | | "type": "string" |
| | | }, |
| | | "memberId": { |
| | | "type": "integer" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "products": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/model.Product" |
| | | } |
| | | }, |
| | | "quotationId": { |
| | | "type": "integer" |
| | | }, |
| | | "remark": { |
| | | "type": "string" |
| | | }, |
| | | "saleChanceId": { |
| | | "type": "integer" |
| | | }, |
| | | "serviceTimes": { |
| | | "type": "integer" |
| | | }, |
| | | "signTime": { |
| | | "type": "string" |
| | | }, |
| | | "startTime": { |
| | | "type": "string" |
| | | }, |
| | | "statusId": { |
| | | "type": "integer" |
| | | }, |
| | | "terms": { |
| | | "type": "string" |
| | | }, |
| | | "typeId": { |
| | | "type": "integer" |
| | | } |
| | | } |
| | | }, |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateServiceContract": { |
| | | "type": "object", |
| | | "properties": { |
| | | "clientId": { |
| | | "type": "integer" |
| | | }, |
| | | "contactId": { |
| | | "type": "integer" |
| | | }, |
| | | "contractId": { |
| | | "type": "integer" |
| | | }, |
| | | "endTime": { |
| | | "type": "string" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "memberId": { |
| | | "type": "integer" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "products": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/model.Product" |
| | | } |
| | | }, |
| | | "quotationId": { |
| | | "type": "integer" |
| | | }, |
| | | "remark": { |
| | | "type": "string" |
| | | }, |
| | | "saleChanceId": { |
| | | "type": "integer" |
| | | }, |
| | | "serviceTimes": { |
| | | "type": "integer" |
| | | }, |
| | | "signTime": { |
| | | "type": "string" |
| | | }, |
| | | "startTime": { |
| | | "type": "string" |
| | | }, |
| | | "statusId": { |
| | | "type": "integer" |
| | | }, |
| | | "terms": { |
| | | "type": "string" |
| | | }, |
| | | "typeId": { |
| | | "type": "integer" |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateStatus": { |
| | | "type": "object", |
| | | "required": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "response.ServiceContractsResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | | "list": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/model.ServiceContract" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "response.SubOrderResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api/serviceContract/add": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "ServiceContract" |
| | | ], |
| | | "summary": "添加服务合同", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.AddServiceContract" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/serviceContract/delete/{id}": { |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "ServiceContract" |
| | | ], |
| | | "summary": "删除服务合同", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "description": "查询参数", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/serviceContract/list": { |
| | | "get": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "ServiceContract" |
| | | ], |
| | | "summary": "服务合同列表", |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "$ref": "#/definitions/response.ServiceContractsResponse" |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/serviceContract/update": { |
| | | "put": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "ServiceContract" |
| | | ], |
| | | "summary": "更新服务合同", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.UpdateServiceContract" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/status/add": { |
| | | "post": { |
| | | "produces": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "model.ServiceContract": { |
| | | "type": "object", |
| | | "properties": { |
| | | "clientId": { |
| | | "type": "integer" |
| | | }, |
| | | "contactId": { |
| | | "type": "integer" |
| | | }, |
| | | "contractId": { |
| | | "type": "integer" |
| | | }, |
| | | "endTime": { |
| | | "type": "string" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "memberId": { |
| | | "type": "integer" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "products": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/model.Product" |
| | | } |
| | | }, |
| | | "quotationId": { |
| | | "type": "integer" |
| | | }, |
| | | "remark": { |
| | | "type": "string" |
| | | }, |
| | | "saleChanceId": { |
| | | "type": "integer" |
| | | }, |
| | | "serviceTimes": { |
| | | "type": "integer" |
| | | }, |
| | | "signTime": { |
| | | "type": "string" |
| | | }, |
| | | "startTime": { |
| | | "type": "string" |
| | | }, |
| | | "statusId": { |
| | | "type": "integer" |
| | | }, |
| | | "terms": { |
| | | "type": "string" |
| | | }, |
| | | "typeId": { |
| | | "type": "integer" |
| | | } |
| | | } |
| | | }, |
| | | "model.SubOrder": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | "properties": { |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.AddServiceContract": { |
| | | "type": "object", |
| | | "properties": { |
| | | "clientId": { |
| | | "type": "integer" |
| | | }, |
| | | "contactId": { |
| | | "type": "integer" |
| | | }, |
| | | "contractId": { |
| | | "type": "integer" |
| | | }, |
| | | "endTime": { |
| | | "type": "string" |
| | | }, |
| | | "memberId": { |
| | | "type": "integer" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "products": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/model.Product" |
| | | } |
| | | }, |
| | | "quotationId": { |
| | | "type": "integer" |
| | | }, |
| | | "remark": { |
| | | "type": "string" |
| | | }, |
| | | "saleChanceId": { |
| | | "type": "integer" |
| | | }, |
| | | "serviceTimes": { |
| | | "type": "integer" |
| | | }, |
| | | "signTime": { |
| | | "type": "string" |
| | | }, |
| | | "startTime": { |
| | | "type": "string" |
| | | }, |
| | | "statusId": { |
| | | "type": "integer" |
| | | }, |
| | | "terms": { |
| | | "type": "string" |
| | | }, |
| | | "typeId": { |
| | | "type": "integer" |
| | | } |
| | | } |
| | | }, |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateServiceContract": { |
| | | "type": "object", |
| | | "properties": { |
| | | "clientId": { |
| | | "type": "integer" |
| | | }, |
| | | "contactId": { |
| | | "type": "integer" |
| | | }, |
| | | "contractId": { |
| | | "type": "integer" |
| | | }, |
| | | "endTime": { |
| | | "type": "string" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "memberId": { |
| | | "type": "integer" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "products": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/model.Product" |
| | | } |
| | | }, |
| | | "quotationId": { |
| | | "type": "integer" |
| | | }, |
| | | "remark": { |
| | | "type": "string" |
| | | }, |
| | | "saleChanceId": { |
| | | "type": "integer" |
| | | }, |
| | | "serviceTimes": { |
| | | "type": "integer" |
| | | }, |
| | | "signTime": { |
| | | "type": "string" |
| | | }, |
| | | "startTime": { |
| | | "type": "string" |
| | | }, |
| | | "statusId": { |
| | | "type": "integer" |
| | | }, |
| | | "terms": { |
| | | "type": "string" |
| | | }, |
| | | "typeId": { |
| | | "type": "integer" |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateStatus": { |
| | | "type": "object", |
| | | "required": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "response.ServiceContractsResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | | "list": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/model.ServiceContract" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "response.SubOrderResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | name: |
| | | type: string |
| | | type: object |
| | | model.ServiceContract: |
| | | properties: |
| | | clientId: |
| | | type: integer |
| | | contactId: |
| | | type: integer |
| | | contractId: |
| | | type: integer |
| | | endTime: |
| | | type: string |
| | | id: |
| | | type: integer |
| | | memberId: |
| | | type: integer |
| | | number: |
| | | type: string |
| | | products: |
| | | items: |
| | | $ref: '#/definitions/model.Product' |
| | | type: array |
| | | quotationId: |
| | | type: integer |
| | | remark: |
| | | type: string |
| | | saleChanceId: |
| | | type: integer |
| | | serviceTimes: |
| | | type: integer |
| | | signTime: |
| | | type: string |
| | | startTime: |
| | | type: string |
| | | statusId: |
| | | type: integer |
| | | terms: |
| | | type: string |
| | | typeId: |
| | | type: integer |
| | | type: object |
| | | model.SubOrder: |
| | | properties: |
| | | clientId: |
| | |
| | | type: string |
| | | required: |
| | | - name |
| | | type: object |
| | | request.AddServiceContract: |
| | | properties: |
| | | clientId: |
| | | type: integer |
| | | contactId: |
| | | type: integer |
| | | contractId: |
| | | type: integer |
| | | endTime: |
| | | type: string |
| | | memberId: |
| | | type: integer |
| | | number: |
| | | type: string |
| | | products: |
| | | items: |
| | | $ref: '#/definitions/model.Product' |
| | | type: array |
| | | quotationId: |
| | | type: integer |
| | | remark: |
| | | type: string |
| | | saleChanceId: |
| | | type: integer |
| | | serviceTimes: |
| | | type: integer |
| | | signTime: |
| | | type: string |
| | | startTime: |
| | | type: string |
| | | statusId: |
| | | type: integer |
| | | terms: |
| | | type: string |
| | | typeId: |
| | | type: integer |
| | | type: object |
| | | request.AddStatus: |
| | | properties: |
| | |
| | | $ref: '#/definitions/request.UpdateSalesSources' |
| | | type: array |
| | | type: object |
| | | request.UpdateServiceContract: |
| | | properties: |
| | | clientId: |
| | | type: integer |
| | | contactId: |
| | | type: integer |
| | | contractId: |
| | | type: integer |
| | | endTime: |
| | | type: string |
| | | id: |
| | | type: integer |
| | | memberId: |
| | | type: integer |
| | | number: |
| | | type: string |
| | | products: |
| | | items: |
| | | $ref: '#/definitions/model.Product' |
| | | type: array |
| | | quotationId: |
| | | type: integer |
| | | remark: |
| | | type: string |
| | | saleChanceId: |
| | | type: integer |
| | | serviceTimes: |
| | | type: integer |
| | | signTime: |
| | | type: string |
| | | startTime: |
| | | type: string |
| | | statusId: |
| | | type: integer |
| | | terms: |
| | | type: string |
| | | typeId: |
| | | type: integer |
| | | type: object |
| | | request.UpdateStatus: |
| | | properties: |
| | | id: |
| | |
| | | list: |
| | | items: |
| | | $ref: '#/definitions/model.SalesSources' |
| | | type: array |
| | | type: object |
| | | response.ServiceContractsResponse: |
| | | properties: |
| | | list: |
| | | items: |
| | | $ref: '#/definitions/model.ServiceContract' |
| | | type: array |
| | | type: object |
| | | response.SubOrderResponse: |
| | |
| | | summary: 更新商机来源 |
| | | tags: |
| | | - SalesSources |
| | | /api/serviceContract/add: |
| | | post: |
| | | parameters: |
| | | - description: 查询参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.AddServiceContract' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: OK |
| | | schema: |
| | | $ref: '#/definitions/contextx.Response' |
| | | summary: 添加服务合同 |
| | | tags: |
| | | - ServiceContract |
| | | /api/serviceContract/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: |
| | | - ServiceContract |
| | | /api/serviceContract/list: |
| | | get: |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: OK |
| | | schema: |
| | | allOf: |
| | | - $ref: '#/definitions/contextx.Response' |
| | | - properties: |
| | | data: |
| | | $ref: '#/definitions/response.ServiceContractsResponse' |
| | | type: object |
| | | summary: 服务合同列表 |
| | | tags: |
| | | - ServiceContract |
| | | /api/serviceContract/update: |
| | | put: |
| | | parameters: |
| | | - description: 查询参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.UpdateServiceContract' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: OK |
| | | schema: |
| | | $ref: '#/definitions/contextx.Response' |
| | | summary: 更新服务合同 |
| | | tags: |
| | | - ServiceContract |
| | | /api/status/add: |
| | | post: |
| | | parameters: |
| | |
| | | [2023-07-11 11:33:55] [error] [gorm.io/gorm/migrator.Migrator.CreateTable:198] failed to parse value model.SubOrder{Id:0, ClientId:0, MemberId:0, MasterOrderId:0, Number:"", ProductOrder:model.ProductOrder{Id:0, Products:[]model.Product(nil)}, Model:gorm.Model{ID:0x0, CreatedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), UpdatedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), DeletedAt:gorm.DeletedAt{Time:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), Valid:false}}}, got error invalid field found for struct aps_crm/model.SubOrder's field ProductOrder: define a valid foreign key for relations or implement the Valuer/Scanner interface |
| | | [2023-07-11 11:33:55] [error] [main.main:29] model Init err:invalid field found for struct aps_crm/model.SubOrder's field ProductOrder: define a valid foreign key for relations or implement the Valuer/Scanner interface |
| | | [2023-07-12 15:23:10] [error] [aps_crm/model.(*ContractSearch).Create:46] trace {"error": "Error 1146 (42S02): Table 'aps_crm.contract' doesn't exist", "elapsed": 0.003547, "rows": 0, "sql": "INSERT INTO `contract` (`client_id`,`member_id`,`number`,`quotation_id`,`status_id`,`file`) VALUES (11,11,'ZDYB02-2',0,0,'string')"} |
| | | [2023-07-13 10:55:49] [error] [aps_crm/model.(*ServiceContractSearch).FindAll:80] trace {"error": ": unsupported relations for schema ServiceContract", "elapsed": 0.001442, "rows": 2, "sql": "SELECT * FROM `service_contract`"} |
| | | [2023-07-13 10:57:45] [error] [aps_crm/model.(*ServiceContractSearch).FindAll:80] trace {"error": ": unsupported relations for schema ServiceContract", "elapsed": 0.0011591, "rows": 2, "sql": "SELECT * FROM `service_contract`"} |
| | |
| | | SalesRefund{}, |
| | | Contract{}, |
| | | Plan{}, |
| | | ServiceContract{}, |
| | | ) |
| | | return err |
| | | } |
New file |
| | |
| | | package request |
| | | |
| | | import ( |
| | | "aps_crm/model" |
| | | ) |
| | | |
| | | type AddServiceContract struct { |
| | | ServiceContract |
| | | } |
| | | |
| | | type ServiceContract struct { |
| | | ClientId int `json:"clientId"` |
| | | Number string `json:"number"` |
| | | MemberId int `json:"memberId"` |
| | | ContactId int `json:"contactId"` |
| | | SaleChanceId int `json:"saleChanceId"` |
| | | ContractId int `json:"contractId"` |
| | | QuotationId int `json:"quotationId"` |
| | | TypeId int `json:"typeId"` |
| | | SignTime string `json:"signTime"` |
| | | StartTime string `json:"startTime"` |
| | | EndTime string `json:"endTime"` |
| | | StatusId int `json:"statusId"` |
| | | ServiceTimes int `json:"serviceTimes"` |
| | | Terms string `json:"terms"` |
| | | Remark string `json:"remark"` |
| | | Products []model.Product `json:"products"` |
| | | } |
| | | |
| | | type UpdateServiceContract struct { |
| | | Id int `json:"id"` |
| | | ServiceContract |
| | | } |
| | |
| | | PlanResponse struct { |
| | | List []*model.Plan `json:"list"` |
| | | } |
| | | |
| | | ServiceContractsResponse struct { |
| | | List []*model.ServiceContract `json:"list"` |
| | | } |
| | | ) |
New file |
| | |
| | | package model |
| | | |
| | | import ( |
| | | "aps_crm/pkg/mysqlx" |
| | | "gorm.io/gorm" |
| | | "time" |
| | | ) |
| | | |
| | | type ( |
| | | ServiceContract struct { |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | ClientId int `json:"clientId" gorm:"column:client_id;type:int;comment:客户id"` |
| | | Number string `json:"number" gorm:"column:number;type:varchar(255);comment:合同编号"` |
| | | MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:负责人id"` |
| | | ContactId int `json:"contactId" gorm:"column:contact_id;type:int;comment:联系人id"` |
| | | SaleChanceId int `json:"saleChanceId" gorm:"column:sale_chance_id;type:int;comment:销售机会id"` |
| | | ContractId int `json:"contractId" gorm:"column:contract_id;type:int;comment:合同id"` |
| | | QuotationId int `json:"quotationId" gorm:"column:quotation_id;type:int;comment:报价单id"` |
| | | TypeId int `json:"typeId" gorm:"column:type_id;type:int;comment:合同类型id"` |
| | | SignTime time.Time `json:"signTime" gorm:"column:sign_time;type:datetime;comment:签约时间"` |
| | | StartTime time.Time `json:"startTime" gorm:"column:start_time;type:datetime;comment:开始时间"` |
| | | EndTime time.Time `json:"endTime" gorm:"column:end_time;type:datetime;comment:结束时间"` |
| | | StatusId int `json:"statusId" gorm:"column:status_id;type:int;comment:合同状态id"` |
| | | ServiceTimes int `json:"serviceTimes" gorm:"column:service_times;type:int;comment:服务次数"` |
| | | Terms string `json:"terms" gorm:"column:terms;type:text;comment:条款"` |
| | | Remark string `json:"remark" gorm:"column:remark;type:text;comment:备注"` |
| | | Products []Product `json:"products" gorm:"many2many:serviceContract_product;"` |
| | | } |
| | | |
| | | ServiceContractSearch struct { |
| | | ServiceContract |
| | | Orm *gorm.DB |
| | | } |
| | | ) |
| | | |
| | | func (ServiceContract) TableName() string { |
| | | return "service_contract" |
| | | } |
| | | |
| | | func NewServiceContractSearch() *ServiceContractSearch { |
| | | return &ServiceContractSearch{ |
| | | Orm: mysqlx.GetDB(), |
| | | } |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&ServiceContract{}) |
| | | if slf.Id != 0 { |
| | | db = db.Where("id = ?", slf.Id) |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) Create(record *ServiceContract) error { |
| | | var db = slf.build() |
| | | return db.Create(record).Error |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) Update(record *ServiceContract) error { |
| | | var db = slf.build() |
| | | return db.Updates(record).Error |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) Delete() error { |
| | | var db = slf.build() |
| | | return db.Delete(&ServiceContract{}).Error |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) Find() (*ServiceContract, error) { |
| | | var db = slf.build() |
| | | var record = &ServiceContract{} |
| | | err := db.First(record).Error |
| | | return record, err |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) FindAll() ([]*ServiceContract, error) { |
| | | var db = slf.build() |
| | | var records = make([]*ServiceContract, 0) |
| | | err := db.Preload("Products").Find(&records).Error |
| | | return records, err |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetId(id int) *ServiceContractSearch { |
| | | slf.Id = id |
| | | return slf |
| | | } |
| | |
| | | PlanSetErr = 3200004 // 设置计划失败 |
| | | PlanUpdateErr = 3200005 // 更新计划失败 |
| | | PlanDeleteErr = 3200006 // 删除计划失败 |
| | | |
| | | SContractExist = 3300001 // 服务合同已存在 |
| | | SContractNotExist = 3300002 // 服务合同不存在 |
| | | SContractListErr = 3300003 // 获取服务合同列表失败 |
| | | SContractSetErr = 3300004 // 设置服务合同失败 |
| | | SContractUpdateErr = 3300005 // 更新服务合同失败 |
| | | SContractDeleteErr = 3300006 // 删除服务合同失败 |
| | | ) |
| | |
| | | SalesRefundRouter |
| | | ContractRouter |
| | | PlanRouter |
| | | ServiceContractRouter |
| | | } |
| | | |
| | | func InitRouter() *gin.Engine { |
| | |
| | | routerGroup.InitSalesRefundRouter(PrivateGroup) // 注册salesRefund路由 |
| | | routerGroup.InitContractRouter(PrivateGroup) // 注册contract路由 |
| | | routerGroup.InitPlanRouter(PrivateGroup) // 注册plan路由 |
| | | routerGroup.InitServiceContractRouter(PrivateGroup) // 注册serviceContract路由 |
| | | } |
| | | return Router |
| | | } |
New file |
| | |
| | | package router |
| | | |
| | | import ( |
| | | v1 "aps_crm/api/v1" |
| | | "github.com/gin-gonic/gin" |
| | | ) |
| | | |
| | | type ServiceContractRouter struct{} |
| | | |
| | | func (s *ServiceContractRouter) InitServiceContractRouter(router *gin.RouterGroup) { |
| | | serviceContractRouter := router.Group("serviceContract") |
| | | serviceContractApi := v1.ApiGroup.ServiceContractApi |
| | | { |
| | | serviceContractRouter.POST("add", serviceContractApi.Add) // 添加服务合同 |
| | | serviceContractRouter.DELETE("delete/:id", serviceContractApi.Delete) // 删除服务合同 |
| | | serviceContractRouter.PUT("update", serviceContractApi.Update) // 更新服务合同 |
| | | serviceContractRouter.GET("list", serviceContractApi.List) // 获取服务合同列表 |
| | | } |
| | | } |
| | |
| | | SalesRefundService |
| | | ContractService |
| | | PlanService |
| | | SContractService |
| | | } |
| | | |
| | | var ServiceGroup = new(Group) |
New file |
| | |
| | | package service |
| | | |
| | | import ( |
| | | "aps_crm/model" |
| | | "aps_crm/pkg/ecode" |
| | | ) |
| | | |
| | | type SContractService struct{} |
| | | |
| | | func (SContractService) AddServiceContract(serviceContract *model.ServiceContract) int { |
| | | err := model.NewServiceContractSearch().Create(serviceContract) |
| | | if err != nil { |
| | | return ecode.SContractExist |
| | | } |
| | | |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (SContractService) DeleteServiceContract(id int) int { |
| | | _, err := model.NewServiceContractSearch().SetId(id).Find() |
| | | if err != nil { |
| | | return ecode.SContractNotExist |
| | | } |
| | | |
| | | err = model.NewServiceContractSearch().SetId(id).Delete() |
| | | if err != nil { |
| | | return ecode.SContractNotExist |
| | | } |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (SContractService) GetServiceContractList() ([]*model.ServiceContract, int) { |
| | | list, err := model.NewServiceContractSearch().FindAll() |
| | | if err != nil { |
| | | return nil, ecode.SContractListErr |
| | | } |
| | | |
| | | return list, ecode.OK |
| | | } |
| | | |
| | | func (SContractService) UpdateServiceContract(serviceContract *model.ServiceContract) int { |
| | | // check serviceContract exist |
| | | _, err := model.NewServiceContractSearch().SetId(serviceContract.Id).Find() |
| | | if err != nil { |
| | | return ecode.SContractNotExist |
| | | } |
| | | |
| | | err = model.NewServiceContractSearch().SetId(serviceContract.Id).Update(serviceContract) |
| | | if err != nil { |
| | | return ecode.SContractSetErr |
| | | } |
| | | |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (SContractService) GetServiceContractByContractId(contractId int) ([]*model.ServiceContract, int) { |
| | | list, err := model.NewServiceContractSearch().SetId(contractId).FindAll() |
| | | if err != nil { |
| | | return nil, ecode.SContractListErr |
| | | } |
| | | |
| | | return list, ecode.OK |
| | | } |