api/v1/serviceContract.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
docs/docs.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
docs/swagger.json | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
docs/swagger.yaml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
model/serviceContract.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
service/serviceContract.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
api/v1/serviceContract.go
@@ -1,176 +1,176 @@ 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" ) 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 object body request.DeleteserviceContract true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/serviceContract/delete [delete] func (s *ServiceContractApi) Delete(c *gin.Context) { var params request.DeleteserviceContract ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } errCode := serviceContractService.DeleteServiceContract(params.Ids) 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() } // 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.ServiceContractTypeId = serviceContract.TypeId result.ServiceContractStatusId = serviceContract.StatusId result.ServiceTimes = serviceContract.ServiceTimes result.Terms = serviceContract.Terms result.Products = serviceContract.Products return ecode.OK, result } // List // // @Tags ServiceContract // @Summary 生成计划列表 // @Produce application/json // @Param object body request.GetServiceContractList true "参数" // @Success 200 {object} contextx.Response{data=response.ServiceContractsResponse} // @Router /api/serviceContract/list [post] func (con *ServiceContractApi) List(c *gin.Context) { var params request.GetServiceContractList ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } serviceContracts, total, errCode := serviceContractService.GetServiceContractList(params.Page, params.PageSize, params.QueryClass, params.KeywordType, params.Keyword) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.OkWithDetailed(response.ServiceContractsResponse{ List: serviceContracts, Count: int(total), }) } 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" ) 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 object body request.DeleteserviceContract true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/serviceContract/delete [delete] func (s *ServiceContractApi) Delete(c *gin.Context) { var params request.DeleteserviceContract ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } errCode := serviceContractService.DeleteServiceContract(params.Ids) 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() } // 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.ServiceContractTypeId = serviceContract.TypeId result.ServiceContractStatusId = serviceContract.StatusId result.ServiceTimes = serviceContract.ServiceTimes result.Terms = serviceContract.Terms result.Products = serviceContract.Products return ecode.OK, result } // List // // @Tags ServiceContract // @Summary 服务合同列表 // @Produce application/json // @Param object body request.GetServiceContractList true "参数" // @Success 200 {object} contextx.Response{data=response.ServiceContractsResponse} // @Router /api/serviceContract/list [post] func (con *ServiceContractApi) List(c *gin.Context) { var params request.GetServiceContractList ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } serviceContracts, total, errCode := serviceContractService.GetServiceContractList(params.Page, params.PageSize, params.QueryClass, params.KeywordType, params.Keyword) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.OkWithDetailed(response.ServiceContractsResponse{ List: serviceContracts, Count: int(total), }) } docs/docs.go
@@ -7642,7 +7642,7 @@ "tags": [ "ServiceContract" ], "summary": "生成计划列表", "summary": "服务合同列表", "parameters": [ { "description": "参数", @@ -11366,6 +11366,9 @@ "model.ServiceContract": { "type": "object", "properties": { "SaleChance": { "$ref": "#/definitions/model.SaleChance" }, "amountInvoiced": { "description": "已开票金额", "type": "number" @@ -11382,9 +11385,6 @@ "type": "integer" }, "contactId": { "type": "integer" }, "contractId": { "type": "integer" }, "endTime": { @@ -11405,6 +11405,9 @@ "$ref": "#/definitions/model.Product" } }, "quotation": { "$ref": "#/definitions/model.Quotation" }, "quotationId": { "type": "integer" }, @@ -11414,9 +11417,21 @@ "saleChanceId": { "type": "integer" }, "salesDetails": { "$ref": "#/definitions/model.SalesDetails" }, "salesDetailsId": { "type": "integer" }, "serviceContractStatus": { "$ref": "#/definitions/model.ServiceContractStatus" }, "serviceContractStatusId": { "type": "integer" }, "serviceContractType": { "$ref": "#/definitions/model.ServiceContractType" }, "serviceContractTypeId": { "type": "integer" }, docs/swagger.json
@@ -7630,7 +7630,7 @@ "tags": [ "ServiceContract" ], "summary": "生成计划列表", "summary": "服务合同列表", "parameters": [ { "description": "参数", @@ -11354,6 +11354,9 @@ "model.ServiceContract": { "type": "object", "properties": { "SaleChance": { "$ref": "#/definitions/model.SaleChance" }, "amountInvoiced": { "description": "已开票金额", "type": "number" @@ -11370,9 +11373,6 @@ "type": "integer" }, "contactId": { "type": "integer" }, "contractId": { "type": "integer" }, "endTime": { @@ -11393,6 +11393,9 @@ "$ref": "#/definitions/model.Product" } }, "quotation": { "$ref": "#/definitions/model.Quotation" }, "quotationId": { "type": "integer" }, @@ -11402,9 +11405,21 @@ "saleChanceId": { "type": "integer" }, "salesDetails": { "$ref": "#/definitions/model.SalesDetails" }, "salesDetailsId": { "type": "integer" }, "serviceContractStatus": { "$ref": "#/definitions/model.ServiceContractStatus" }, "serviceContractStatusId": { "type": "integer" }, "serviceContractType": { "$ref": "#/definitions/model.ServiceContractType" }, "serviceContractTypeId": { "type": "integer" }, docs/swagger.yaml
@@ -1271,6 +1271,8 @@ type: object model.ServiceContract: properties: SaleChance: $ref: '#/definitions/model.SaleChance' amountInvoiced: description: 已开票金额 type: number @@ -1284,8 +1286,6 @@ type: integer contactId: type: integer contractId: type: integer endTime: type: string id: @@ -1298,14 +1298,24 @@ items: $ref: '#/definitions/model.Product' type: array quotation: $ref: '#/definitions/model.Quotation' quotationId: type: integer remark: type: string saleChanceId: type: integer salesDetails: $ref: '#/definitions/model.SalesDetails' salesDetailsId: type: integer serviceContractStatus: $ref: '#/definitions/model.ServiceContractStatus' serviceContractStatusId: type: integer serviceContractType: $ref: '#/definitions/model.ServiceContractType' serviceContractTypeId: type: integer serviceTimes: @@ -10002,7 +10012,7 @@ data: $ref: '#/definitions/response.ServiceContractsResponse' type: object summary: 生成计划列表 summary: 服务合同列表 tags: - ServiceContract /api/serviceContract/update: model/serviceContract.go
@@ -11,26 +11,31 @@ 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"` ServiceContractTypeId int `json:"serviceContractTypeId" gorm:"column:service_contract_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:结束时间"` ServiceContractStatusId int `json:"serviceContractStatusId" gorm:"column:service_contract_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:备注"` AmountReceivable decimal.Decimal `gorm:"amount_receivable" json:"amountReceivable"` // 应收金额 AmountReceived decimal.Decimal `gorm:"amount_received" json:"amountReceived"` // 已收金额 AmountInvoiced decimal.Decimal `gorm:"amount_invoiced" json:"amountInvoiced"` // 已开票金额 Products []Product `json:"products" gorm:"many2many:serviceContract_product;"` 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"` SaleChance SaleChance `json:"SaleChance" gorm:"foreignKey:SaleChanceId"` SalesDetailsId int `json:"salesDetailsId" gorm:"column:sales_details_id;type:int;comment:合同订单id"` SalesDetails SalesDetails `json:"salesDetails" gorm:"foreignKey:SalesDetailsId"` QuotationId int `json:"quotationId" gorm:"column:quotation_id;type:int;comment:报价单id"` Quotation Quotation `json:"quotation" gorm:"foreignKey:QuotationId"` ServiceContractTypeId int `json:"serviceContractTypeId" gorm:"column:service_contract_type_id;type:int;comment:合同类型id"` ServiceContractType ServiceContractType `json:"serviceContractType" gorm:"foreignKey:ServiceContractTypeId"` 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:结束时间"` ServiceContractStatusId int `json:"serviceContractStatusId" gorm:"column:service_contract_status_id;type:int;comment:合同状态id"` ServiceContractStatus ServiceContractStatus `json:"serviceContractStatus" gorm:"foreignKey:ServiceContractStatusId"` 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:备注"` AmountReceivable decimal.Decimal `gorm:"amount_receivable" json:"amountReceivable"` // 应收金额 AmountReceived decimal.Decimal `gorm:"amount_received" json:"amountReceived"` // 已收金额 AmountInvoiced decimal.Decimal `gorm:"amount_invoiced" json:"amountInvoiced"` // 已开票金额 Products []Product `json:"products" gorm:"many2many:service_contract_product;"` gorm.Model `json:"-"` } @@ -44,6 +49,7 @@ OrderBy string PageNum int PageSize int Preload bool } ) @@ -97,6 +103,15 @@ //todo } if slf.Preload { db = db. Preload("SaleChance"). Preload("SalesDetails"). Preload("Quotation"). Preload("ServiceContractType"). Preload("ServiceContractStatus"). Preload("Products") } return db } @@ -116,14 +131,7 @@ 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, int64, error) { func (slf *ServiceContractSearch) Find() ([]*ServiceContract, int64, error) { var db = slf.build() var records = make([]*ServiceContract, 0) var total int64 @@ -134,11 +142,7 @@ db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize) } if slf.PageNum > 0 && slf.PageSize > 0 { db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize) } err := db.Preload("Products").Find(&records).Error err := db.Find(&records).Error return records, total, err } @@ -176,6 +180,11 @@ return slf } func (slf *ServiceContractSearch) SetPreload(preload bool) *ServiceContractSearch { slf.Preload = preload return slf } func (slf *ServiceContractSearch) UpdateByMap(upMap map[string]interface{}) error { var ( db = slf.build() service/serviceContract.go
@@ -19,7 +19,7 @@ func (SContractService) UpdateServiceContract(serviceContract *model.ServiceContract) int { // check serviceContract exist _, err := model.NewServiceContractSearch().SetId(serviceContract.Id).Find() _, err := model.NewServiceContractSearch().SetId(serviceContract.Id).First() if err != nil { return ecode.SContractNotExist } @@ -56,7 +56,9 @@ SetKeyword(keyword). SetKeywordType(keywordType). SetQueryClass(queryClass). SetPage(page, pageSize).FindAll() SetPage(page, pageSize). SetPreload(true). Find() if err != nil { return nil, 0, ecode.SContractListErr }