| | |
| | | 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) { |
| | | result.Number = serviceContract.Number |
| | | result.MemberId = serviceContract.MemberId |
| | | result.Remark = serviceContract.Remark |
| | | result.ClientId = serviceContract.ClientId |
| | | result.SalesDetailsId = serviceContract.SalesDetailsId |
| | | 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 |
| | | result.SignTime = serviceContract.SignTime |
| | | result.StartTime = serviceContract.StartTime |
| | | result.EndTime = serviceContract.EndTime |
| | | |
| | | 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), |
| | | }) |
| | | } |
| | |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.DeleteserviceContract" |
| | | "$ref": "#/definitions/request.DeleteServiceContract" |
| | | } |
| | | } |
| | | ], |
| | |
| | | "tags": [ |
| | | "ServiceContract" |
| | | ], |
| | | "summary": "生成计划列表", |
| | | "summary": "服务合同列表", |
| | | "parameters": [ |
| | | { |
| | | "description": "参数", |
| | |
| | | "model.ServiceContract": { |
| | | "type": "object", |
| | | "properties": { |
| | | "SaleChance": { |
| | | "$ref": "#/definitions/model.SaleChance" |
| | | }, |
| | | "amountInvoiced": { |
| | | "description": "已开票金额", |
| | | "type": "number" |
| | |
| | | "type": "integer" |
| | | }, |
| | | "contactId": { |
| | | "type": "integer" |
| | | }, |
| | | "contractId": { |
| | | "type": "integer" |
| | | }, |
| | | "endTime": { |
| | |
| | | "$ref": "#/definitions/model.Product" |
| | | } |
| | | }, |
| | | "quotation": { |
| | | "$ref": "#/definitions/model.Quotation" |
| | | }, |
| | | "quotationId": { |
| | | "type": "integer" |
| | | }, |
| | |
| | | "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" |
| | |
| | | "contactId": { |
| | | "type": "integer" |
| | | }, |
| | | "contractId": { |
| | | "type": "integer" |
| | | }, |
| | | "endTime": { |
| | | "type": "string" |
| | | }, |
| | |
| | | "type": "string" |
| | | }, |
| | | "saleChanceId": { |
| | | "type": "integer" |
| | | }, |
| | | "salesDetailsId": { |
| | | "type": "integer" |
| | | }, |
| | | "serviceTimes": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.DeleteServiceContract": { |
| | | "type": "object", |
| | | "properties": { |
| | | "ids": { |
| | | "type": "array", |
| | | "items": { |
| | | "type": "integer" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "request.DeleteServiceFeeManage": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | "userId": { |
| | | "description": "用户ID", |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.DeleteserviceContract": { |
| | | "type": "object", |
| | | "properties": { |
| | | "ids": { |
| | | "type": "array", |
| | | "items": { |
| | | "type": "integer" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | |
| | | "contactId": { |
| | | "type": "integer" |
| | | }, |
| | | "contractId": { |
| | | "type": "integer" |
| | | }, |
| | | "endTime": { |
| | | "type": "string" |
| | | }, |
| | |
| | | "saleChanceId": { |
| | | "type": "integer" |
| | | }, |
| | | "salesDetailsId": { |
| | | "type": "integer" |
| | | }, |
| | | "serviceTimes": { |
| | | "type": "integer" |
| | | }, |
| | |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.DeleteserviceContract" |
| | | "$ref": "#/definitions/request.DeleteServiceContract" |
| | | } |
| | | } |
| | | ], |
| | |
| | | "tags": [ |
| | | "ServiceContract" |
| | | ], |
| | | "summary": "生成计划列表", |
| | | "summary": "服务合同列表", |
| | | "parameters": [ |
| | | { |
| | | "description": "参数", |
| | |
| | | "model.ServiceContract": { |
| | | "type": "object", |
| | | "properties": { |
| | | "SaleChance": { |
| | | "$ref": "#/definitions/model.SaleChance" |
| | | }, |
| | | "amountInvoiced": { |
| | | "description": "已开票金额", |
| | | "type": "number" |
| | |
| | | "type": "integer" |
| | | }, |
| | | "contactId": { |
| | | "type": "integer" |
| | | }, |
| | | "contractId": { |
| | | "type": "integer" |
| | | }, |
| | | "endTime": { |
| | |
| | | "$ref": "#/definitions/model.Product" |
| | | } |
| | | }, |
| | | "quotation": { |
| | | "$ref": "#/definitions/model.Quotation" |
| | | }, |
| | | "quotationId": { |
| | | "type": "integer" |
| | | }, |
| | |
| | | "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" |
| | |
| | | "contactId": { |
| | | "type": "integer" |
| | | }, |
| | | "contractId": { |
| | | "type": "integer" |
| | | }, |
| | | "endTime": { |
| | | "type": "string" |
| | | }, |
| | |
| | | "type": "string" |
| | | }, |
| | | "saleChanceId": { |
| | | "type": "integer" |
| | | }, |
| | | "salesDetailsId": { |
| | | "type": "integer" |
| | | }, |
| | | "serviceTimes": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.DeleteServiceContract": { |
| | | "type": "object", |
| | | "properties": { |
| | | "ids": { |
| | | "type": "array", |
| | | "items": { |
| | | "type": "integer" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "request.DeleteServiceFeeManage": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | "userId": { |
| | | "description": "用户ID", |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.DeleteserviceContract": { |
| | | "type": "object", |
| | | "properties": { |
| | | "ids": { |
| | | "type": "array", |
| | | "items": { |
| | | "type": "integer" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | |
| | | "contactId": { |
| | | "type": "integer" |
| | | }, |
| | | "contractId": { |
| | | "type": "integer" |
| | | }, |
| | | "endTime": { |
| | | "type": "string" |
| | | }, |
| | |
| | | "saleChanceId": { |
| | | "type": "integer" |
| | | }, |
| | | "salesDetailsId": { |
| | | "type": "integer" |
| | | }, |
| | | "serviceTimes": { |
| | | "type": "integer" |
| | | }, |
| | |
| | | type: object |
| | | model.ServiceContract: |
| | | properties: |
| | | SaleChance: |
| | | $ref: '#/definitions/model.SaleChance' |
| | | amountInvoiced: |
| | | description: 已开票金额 |
| | | type: number |
| | |
| | | type: integer |
| | | contactId: |
| | | type: integer |
| | | contractId: |
| | | type: integer |
| | | endTime: |
| | | type: string |
| | | id: |
| | |
| | | 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: |
| | |
| | | type: integer |
| | | contactId: |
| | | type: integer |
| | | contractId: |
| | | type: integer |
| | | endTime: |
| | | type: string |
| | | memberId: |
| | |
| | | remark: |
| | | type: string |
| | | saleChanceId: |
| | | type: integer |
| | | salesDetailsId: |
| | | type: integer |
| | | serviceTimes: |
| | | type: integer |
| | |
| | | type: integer |
| | | type: array |
| | | type: object |
| | | request.DeleteServiceContract: |
| | | properties: |
| | | ids: |
| | | items: |
| | | type: integer |
| | | type: array |
| | | type: object |
| | | request.DeleteServiceFeeManage: |
| | | properties: |
| | | ids: |
| | |
| | | userId: |
| | | description: 用户ID |
| | | type: string |
| | | type: object |
| | | request.DeleteserviceContract: |
| | | properties: |
| | | ids: |
| | | items: |
| | | type: integer |
| | | type: array |
| | | type: object |
| | | request.DownloadFile: |
| | | properties: |
| | |
| | | type: integer |
| | | contactId: |
| | | type: integer |
| | | contractId: |
| | | type: integer |
| | | endTime: |
| | | type: string |
| | | id: |
| | |
| | | remark: |
| | | type: string |
| | | saleChanceId: |
| | | type: integer |
| | | salesDetailsId: |
| | | type: integer |
| | | serviceTimes: |
| | | type: integer |
| | |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.DeleteserviceContract' |
| | | $ref: '#/definitions/request.DeleteServiceContract' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | |
| | | data: |
| | | $ref: '#/definitions/response.ServiceContractsResponse' |
| | | type: object |
| | | summary: 生成计划列表 |
| | | summary: 服务合同列表 |
| | | tags: |
| | | - ServiceContract |
| | | /api/serviceContract/update: |
| | |
| | | CourierNumber string `gorm:"courier_number" json:"courierNumber"` // 物流单号 |
| | | CourierCompanyId int `gorm:"courier_company_id" json:"courierCompanyId"` // 物流公司 |
| | | CourierCompany CourierCompany `gorm:"foreignKey:CourierCompanyId"` |
| | | Products []*Product `json:"products" gorm:"many2many:invoice_product;"` |
| | | } |
| | | |
| | | // InvoiceSearch 销售发票搜索条件 |
New file |
| | |
| | | package model |
| | | |
| | | import ( |
| | | "aps_crm/pkg/mysqlx" |
| | | "gorm.io/gorm" |
| | | ) |
| | | |
| | | type ( |
| | | // InvoiceProduct 合同产品 |
| | | InvoiceProduct struct { |
| | | InvoiceId int `gorm:"invoice_id" json:"invoiceId"` |
| | | ProductId int `gorm:"product_id" json:"productId"` |
| | | } |
| | | |
| | | // InvoiceProductSearch 合同产品搜索条件 |
| | | InvoiceProductSearch struct { |
| | | InvoiceProduct |
| | | Orm *gorm.DB |
| | | Keyword string |
| | | PageNum int |
| | | PageSize int |
| | | ProductIds []uint |
| | | } |
| | | ) |
| | | |
| | | func (InvoiceProduct) TableName() string { |
| | | return "invoice_product" |
| | | } |
| | | |
| | | func NewInvoiceProductSearch() *InvoiceProductSearch { |
| | | return &InvoiceProductSearch{ |
| | | Orm: mysqlx.GetDB(), |
| | | } |
| | | } |
| | | |
| | | func (slf *InvoiceProductSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&InvoiceProduct{}) |
| | | if len(slf.ProductIds) != 0 { |
| | | db = db.Where("product_id in ?", slf.ProductIds) |
| | | } |
| | | if slf.InvoiceId != 0 { |
| | | db = db.Where("invoice_id = ?", slf.InvoiceId) |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |
| | | func (slf *InvoiceProductSearch) Create(record *InvoiceProduct) error { |
| | | var db = slf.build() |
| | | return db.Create(record).Error |
| | | } |
| | | |
| | | func (slf *InvoiceProductSearch) CreateBatch(records []*InvoiceProduct) error { |
| | | var db = slf.build() |
| | | return db.Create(records).Error |
| | | } |
| | | |
| | | func (slf *InvoiceProductSearch) Delete() error { |
| | | var db = slf.build() |
| | | return db.Delete(&InvoiceProduct{}).Error |
| | | } |
| | | |
| | | func (slf *InvoiceProductSearch) Update(record *InvoiceProduct) error { |
| | | var db = slf.build() |
| | | return db.Updates(record).Error |
| | | } |
| | | |
| | | func (slf *InvoiceProductSearch) FindAll() ([]*InvoiceProduct, error) { |
| | | var db = slf.build() |
| | | var record = make([]*InvoiceProduct, 0) |
| | | err := db.Find(&record).Error |
| | | return record, err |
| | | } |
| | | |
| | | func (slf *InvoiceProductSearch) SetProductIds(ids []uint) *InvoiceProductSearch { |
| | | slf.ProductIds = ids |
| | | return slf |
| | | } |
| | | |
| | | func (slf *InvoiceProductSearch) SetInvoiceId(id int) *InvoiceProductSearch { |
| | | slf.InvoiceId = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *InvoiceProductSearch) SetOrm(tx *gorm.DB) *InvoiceProductSearch { |
| | | slf.Orm = tx |
| | | return slf |
| | | } |
| | | |
| | | func (slf *InvoiceProductSearch) First() (*InvoiceProduct, error) { |
| | | var db = slf.build() |
| | | var record = new(InvoiceProduct) |
| | | err := db.First(record).Error |
| | | return record, err |
| | | } |
| | | |
| | | func (slf *InvoiceProductSearch) Updates(values interface{}) error { |
| | | var db = slf.build() |
| | | return db.Updates(values).Error |
| | | } |
| | | |
| | | func (slf *InvoiceProductSearch) Find() ([]*InvoiceProduct, int64, error) { |
| | | var db = slf.build() |
| | | var records = make([]*InvoiceProduct, 0) |
| | | var total int64 |
| | | if err := db.Count(&total).Error; err != nil { |
| | | return records, total, err |
| | | } |
| | | if slf.PageNum > 0 && slf.PageSize > 0 { |
| | | db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize) |
| | | } |
| | | |
| | | err := db.Find(&records).Error |
| | | return records, total, err |
| | | } |
| | | |
| | | // InitDefaultData 初始化数据 |
| | | func (slf *InvoiceProductSearch) InitDefaultData() error { |
| | | var ( |
| | | db = slf.Orm.Table(slf.TableName()) |
| | | total int64 = 0 |
| | | ) |
| | | if err := db.Count(&total).Error; err != nil { |
| | | return err |
| | | } |
| | | if total != 0 { |
| | | return nil |
| | | } |
| | | records := []*InvoiceProduct{} |
| | | return slf.CreateBatch(records) |
| | | } |
| | |
| | | package model |
| | | |
| | | import "gorm.io/gorm" |
| | | import ( |
| | | "github.com/shopspring/decimal" |
| | | "gorm.io/gorm" |
| | | ) |
| | | |
| | | type Product struct { |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | Name string `json:"name" gorm:"column:name;type:varchar(255);comment:产品名称"` |
| | | Price float64 `json:"price" gorm:"column:price;type:decimal(10,2);comment:产品价格"` |
| | | Number string `json:"number" gorm:"column:number;type:varchar(255);comment:产品编号"` |
| | | Amount int `json:"amount" gorm:"column:amount;type:int;comment:产品数量"` |
| | | Total float64 `json:"total" gorm:"column:total;type:decimal(10,2);comment:产品总价"` |
| | | Desc string `json:"desc" gorm:"column:desc;type:varchar(255);comment:产品描述"` |
| | | Id uint `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | Name string `json:"name" gorm:"column:name;type:varchar(255);comment:产品名称"` |
| | | Price decimal.Decimal `json:"price" gorm:"column:price;type:decimal(10,2);comment:产品价格"` |
| | | Number string `json:"number" gorm:"column:number;type:varchar(255);comment:产品编号"` |
| | | Amount decimal.Decimal `json:"amount" gorm:"column:amount;type:int;comment:产品数量"` |
| | | Total decimal.Decimal `json:"total" gorm:"column:total;type:decimal(10,2);comment:产品总价"` |
| | | Desc string `json:"desc" gorm:"column:desc;type:varchar(255);comment:产品描述"` |
| | | gorm.Model `json:"-"` |
| | | } |
| | | |
| | |
| | | |
| | | import ( |
| | | "aps_crm/constvar" |
| | | "aps_crm/model" |
| | | ) |
| | | |
| | | type AddInvoice struct { |
| | |
| | | InvoiceDate string `gorm:"invoice_date" json:"invoiceDate"` // 开票日期 |
| | | CourierNumber string `gorm:"courier_number" json:"courierNumber"` // 物流单号 |
| | | CourierCompanyId int `gorm:"courier_company_id" json:"courierCompanyId"` // 物流公司 |
| | | Products []model.Product `json:"products"` //发票对应产品,从相应源单里获取 |
| | | } |
| | | |
| | | type UpdateInvoice struct { |
| | | Id int `json:"id"` |
| | | ClientId int `gorm:"client_id" json:"clientId"` // 客户id |
| | | InvoiceTypeId int `gorm:"invoice_type_id" json:"invoiceTypeId"` // 发票类型id |
| | | PrincipalId int `gorm:"principal_id" json:"principalId"` // 销售负责人id |
| | | Subject string `gorm:"subject" json:"subject"` // 主题 |
| | | InvoiceStatusId int `gorm:"invoice_status_id" json:"invoiceStatusId"` // 发票状态id |
| | | SourceType int `gorm:"source_type" json:"sourceType"` // 源单类型(1销售明细单2服务合同) |
| | | SourceId int `gorm:"source_id" json:"sourceId"` // 源单id |
| | | TaxpayerIdNumber string `gorm:"taxpayer_id_number" json:"taxpayerIdNumber"` // 纳税识别号 |
| | | InvoiceNumber string `gorm:"invoice_number" json:"invoiceNumber"` // 发票号码 |
| | | InvoiceDate int `gorm:"invoice_date" json:"invoiceDate"` // 开票日期 |
| | | CourierNumber string `gorm:"courier_number" json:"courierNumber"` // 物流单号 |
| | | CourierCompanyId int `gorm:"courier_company_id" json:"courierCompanyId"` // 物流公司 |
| | | Id int `json:"id" binding:"required"` |
| | | ClientId int `gorm:"client_id" json:"clientId"` // 客户id |
| | | InvoiceTypeId int `gorm:"invoice_type_id" json:"invoiceTypeId"` // 发票类型id |
| | | PrincipalId int `gorm:"principal_id" json:"principalId"` // 销售负责人id |
| | | Subject string `gorm:"subject" json:"subject"` // 主题 |
| | | InvoiceStatusId int `gorm:"invoice_status_id" json:"invoiceStatusId"` // 发票状态id |
| | | SourceType int `gorm:"source_type" json:"sourceType"` // 源单类型(1销售明细单2服务合同) |
| | | SourceId int `gorm:"source_id" json:"sourceId"` // 源单id |
| | | TaxpayerIdNumber string `gorm:"taxpayer_id_number" json:"taxpayerIdNumber"` // 纳税识别号 |
| | | InvoiceNumber string `gorm:"invoice_number" json:"invoiceNumber"` // 发票号码 |
| | | InvoiceDate int `gorm:"invoice_date" json:"invoiceDate"` // 开票日期 |
| | | CourierNumber string `gorm:"courier_number" json:"courierNumber"` // 物流单号 |
| | | CourierCompanyId int `gorm:"courier_company_id" json:"courierCompanyId"` // 物流公司 |
| | | Products []model.Product `json:"products"` //发票对应产品,从相应源单里获取 |
| | | } |
| | | |
| | | type GetInvoiceList struct { |
| | |
| | | package request
|
| | |
|
| | | import (
|
| | | "aps_crm/constvar"
|
| | | "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
|
| | | }
|
| | |
|
| | | type GetServiceContractList struct {
|
| | | PageInfo
|
| | | QueryClass constvar.ServiceContractQueryClass `json:"queryClass"`
|
| | | KeywordType constvar.ServiceContractKeywordType `json:"keywordType"`
|
| | | Keyword string `json:"keyword"`
|
| | | }
|
| | |
|
| | | type DeleteserviceContract struct {
|
| | | Ids []int `json:"ids"`
|
| | | }
|
| | | package request |
| | | |
| | | import ( |
| | | "aps_crm/constvar" |
| | | "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"` |
| | | SalesDetailsId int `json:"salesDetailsId"` |
| | | QuotationId int `json:"quotationId"` |
| | | TypeId int `json:"typeId"` |
| | | SignTime string `json:"signTime" binding:"datetime=2006-01-02"` |
| | | StartTime string `json:"startTime" binding:"datetime=2006-01-02"` |
| | | EndTime string `json:"endTime" binding:"datetime=2006-01-02"` |
| | | 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 |
| | | } |
| | | |
| | | type GetServiceContractList struct { |
| | | PageInfo |
| | | QueryClass constvar.ServiceContractQueryClass `json:"queryClass"` |
| | | KeywordType constvar.ServiceContractKeywordType `json:"keywordType"` |
| | | Keyword string `json:"keyword"` |
| | | } |
| | | |
| | | type DeleteServiceContract struct { |
| | | Ids []int `json:"ids"` |
| | | } |
| | |
| | | |
| | | 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 string `json:"signTime" gorm:"column:sign_time;type:datetime;comment:签约时间"` |
| | | StartTime string `json:"startTime" gorm:"column:start_time;type:datetime;comment:开始时间"` |
| | | EndTime string `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"` // 已开票金额 |
| | | AmountUnInvoiced decimal.Decimal `gorm:"-" json:"amountUnInvoiced"` // 未开票金额 |
| | | Products []*Product `json:"products" gorm:"many2many:service_contract_product;"` |
| | | gorm.Model `json:"-"` |
| | | } |
| | | |
| | |
| | | OrderBy string |
| | | PageNum int |
| | | PageSize int |
| | | Preload bool |
| | | } |
| | | ) |
| | | |
| | |
| | | } |
| | | switch slf.QueryClass { |
| | | case constvar.ServiceContractQueryClassExpireAfter30Day: |
| | | db = db.Where("end_time > ?", time.Now(), time.Now().AddDate(0, 0, 30)) |
| | | db = db.Where("end_time > ?", time.Now().AddDate(0, 0, 30).Format("2006-01-02")) |
| | | case constvar.ServiceContractQueryClassExpireAfter60Day: |
| | | db = db.Where("end_time > ?", time.Now(), time.Now().AddDate(0, 0, 60)) |
| | | db = db.Where("end_time > ?", time.Now().AddDate(0, 0, 60).Format("2006-01-02")) |
| | | case constvar.ServiceContractQueryClassExpiredBefore15Day: |
| | | db = db.Where("end_time < ?", time.Now().AddDate(0, 0, -15)) |
| | | db = db.Where("end_time < ?", time.Now().AddDate(0, 0, -15).Format("2006-01-02")) |
| | | case constvar.ServiceContractQueryClassExpiredBefore60Day: |
| | | db = db.Where("end_time < ?", time.Now().AddDate(0, 0, -60)) |
| | | db = db.Where("end_time < ?", time.Now().AddDate(0, 0, -60).Format("2006-01-02")) |
| | | |
| | | } |
| | | switch slf.KeywordType { |
| | |
| | | //todo |
| | | |
| | | } |
| | | if slf.Preload { |
| | | db = db. |
| | | Preload("SaleChance"). |
| | | Preload("SalesDetails"). |
| | | Preload("Quotation"). |
| | | Preload("ServiceContractType"). |
| | | Preload("ServiceContractStatus"). |
| | | Preload("Products") |
| | | } |
| | | |
| | | return db |
| | | } |
| | |
| | | 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 |
| | |
| | | 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 |
| | | } |
| | | |
| | |
| | | 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() |
| | |
| | | package contextx
|
| | |
|
| | | import (
|
| | | "aps_crm/pkg/ecode"
|
| | | "aps_crm/pkg/logx"
|
| | | "github.com/gin-gonic/gin"
|
| | | "net/http"
|
| | | )
|
| | |
|
| | | type (
|
| | | Context struct {
|
| | | ctx *gin.Context
|
| | | paramsMap map[string]interface{}
|
| | | }
|
| | |
|
| | | Response struct {
|
| | | Code int `json:"code"`
|
| | | Data interface{} `json:"data"`
|
| | | Msg string `json:"msg"`
|
| | | }
|
| | | )
|
| | |
|
| | | func NewContext(ctx *gin.Context, params interface{}) (r *Context, isAllow bool) {
|
| | | r = &Context{
|
| | | ctx: ctx,
|
| | | }
|
| | | if r.ctx.Request.Method == "OPTIONS" {
|
| | | r.ctx.String(http.StatusOK, "")
|
| | | return
|
| | | }
|
| | |
|
| | | defer func() {
|
| | | query := r.ctx.Request.URL.RawQuery
|
| | | if query != "" {
|
| | | query = "?" + query
|
| | | }
|
| | | urlPath := r.ctx.Request.URL.Path
|
| | | logx.Infof("%s | %s %s | uid: %s | %+v", ctx.ClientIP(), r.ctx.Request.Method, urlPath+query, r.GetUserId(), params)
|
| | | }()
|
| | |
|
| | | // validate params
|
| | | if params != nil {
|
| | | if err := r.ctx.ShouldBind(params); err != nil {
|
| | | r.Fail(ecode.ParamsErr)
|
| | | return
|
| | | }
|
| | | }
|
| | | isAllow = true
|
| | | return
|
| | | }
|
| | |
|
| | | func (slf *Context) GetRequestPath() (r string) {
|
| | | r = slf.ctx.Request.URL.Path
|
| | | return
|
| | | }
|
| | |
|
| | | func (slf *Context) GetUserId() (r string) {
|
| | | v := slf.paramsMap["userId"]
|
| | | switch v.(type) {
|
| | | case string:
|
| | | r = v.(string)
|
| | | }
|
| | | return
|
| | | }
|
| | |
|
| | | func (slf *Context) Result(code int, data interface{}, msg string) {
|
| | | slf.ctx.JSON(http.StatusOK, Response{
|
| | | Code: code,
|
| | | Data: data,
|
| | | Msg: msg,
|
| | | })
|
| | | }
|
| | |
|
| | | func (slf *Context) Ok() {
|
| | | slf.Result(ecode.OK, map[string]interface{}{}, "")
|
| | | }
|
| | |
|
| | | func (slf *Context) OkWithDetailed(data interface{}) {
|
| | | slf.Result(ecode.OK, data, "")
|
| | | }
|
| | |
|
| | | func (slf *Context) Fail(errCode int) {
|
| | | slf.Result(errCode, map[string]interface{}{}, ecode.GetMsg(errCode))
|
| | | }
|
| | |
|
| | | func (slf *Context) FailWithMsg(errCode int, msg string) {
|
| | | slf.Result(errCode, map[string]interface{}{}, msg)
|
| | | }
|
| | |
|
| | | func (slf *Context) FailWithDetailed(errCode int, data interface{}) {
|
| | | slf.Result(errCode, data, ecode.GetMsg(errCode))
|
| | | }
|
| | |
|
| | | func (slf *Context) GetCtx() *gin.Context {
|
| | | return slf.ctx
|
| | | }
|
| | |
|
| | | func (slf *Context) SetCtx(c *gin.Context) *Context {
|
| | | slf.ctx = c
|
| | | return slf
|
| | | }
|
| | | package contextx |
| | | |
| | | import ( |
| | | "aps_crm/pkg/ecode" |
| | | "aps_crm/pkg/logx" |
| | | "github.com/gin-gonic/gin" |
| | | "net/http" |
| | | ) |
| | | |
| | | type ( |
| | | Context struct { |
| | | ctx *gin.Context |
| | | paramsMap map[string]interface{} |
| | | } |
| | | |
| | | Response struct { |
| | | Code int `json:"code"` |
| | | Data interface{} `json:"data"` |
| | | Msg string `json:"msg"` |
| | | } |
| | | ) |
| | | |
| | | func NewContext(ctx *gin.Context, params interface{}) (r *Context, isAllow bool) { |
| | | r = &Context{ |
| | | ctx: ctx, |
| | | } |
| | | if r.ctx.Request.Method == "OPTIONS" { |
| | | r.ctx.String(http.StatusOK, "") |
| | | return |
| | | } |
| | | |
| | | defer func() { |
| | | query := r.ctx.Request.URL.RawQuery |
| | | if query != "" { |
| | | query = "?" + query |
| | | } |
| | | urlPath := r.ctx.Request.URL.Path |
| | | logx.Infof("%s | %s %s | uid: %s | %+v", ctx.ClientIP(), r.ctx.Request.Method, urlPath+query, r.GetUserId(), params) |
| | | }() |
| | | |
| | | // validate params |
| | | if params != nil { |
| | | if err := r.ctx.ShouldBind(params); err != nil { |
| | | logx.Errorf("bind param error: %v", err.Error()) |
| | | r.Fail(ecode.ParamsErr) |
| | | return |
| | | } |
| | | } |
| | | isAllow = true |
| | | return |
| | | } |
| | | |
| | | func (slf *Context) GetRequestPath() (r string) { |
| | | r = slf.ctx.Request.URL.Path |
| | | return |
| | | } |
| | | |
| | | func (slf *Context) GetUserId() (r string) { |
| | | v := slf.paramsMap["userId"] |
| | | switch v.(type) { |
| | | case string: |
| | | r = v.(string) |
| | | } |
| | | return |
| | | } |
| | | |
| | | func (slf *Context) Result(code int, data interface{}, msg string) { |
| | | slf.ctx.JSON(http.StatusOK, Response{ |
| | | Code: code, |
| | | Data: data, |
| | | Msg: msg, |
| | | }) |
| | | } |
| | | |
| | | func (slf *Context) Ok() { |
| | | slf.Result(ecode.OK, map[string]interface{}{}, "") |
| | | } |
| | | |
| | | func (slf *Context) OkWithDetailed(data interface{}) { |
| | | slf.Result(ecode.OK, data, "") |
| | | } |
| | | |
| | | func (slf *Context) Fail(errCode int) { |
| | | slf.Result(errCode, map[string]interface{}{}, ecode.GetMsg(errCode)) |
| | | } |
| | | |
| | | func (slf *Context) FailWithMsg(errCode int, msg string) { |
| | | slf.Result(errCode, map[string]interface{}{}, msg) |
| | | } |
| | | |
| | | func (slf *Context) FailWithDetailed(errCode int, data interface{}) { |
| | | slf.Result(errCode, data, ecode.GetMsg(errCode)) |
| | | } |
| | | |
| | | func (slf *Context) GetCtx() *gin.Context { |
| | | return slf.ctx |
| | | } |
| | | |
| | | func (slf *Context) SetCtx(c *gin.Context) *Context { |
| | | slf.ctx = c |
| | | return slf |
| | | } |
| | |
| | | PlanUpdateErr = 3200005 // 更新计划失败 |
| | | PlanDeleteErr = 3200006 // 删除计划失败 |
| | | |
| | | SContractExist = 3300001 // 服务合同已存在 |
| | | SContractNotExist = 3300002 // 服务合同不存在 |
| | | SContractListErr = 3300003 // 获取服务合同列表失败 |
| | | SContractSetErr = 3300004 // 设置服务合同失败 |
| | | SContractUpdateErr = 3300005 // 更新服务合同失败 |
| | | SContractDeleteErr = 3300006 // 删除服务合同失败 |
| | | SContractExist = 3300001 // 服务合同已存在 |
| | | SContractNotExist = 3300002 // 服务合同不存在 |
| | | SContractListErr = 3300003 // 获取服务合同列表失败 |
| | | SContractSetErr = 3300004 // 设置服务合同失败 |
| | | SContractUpdateErr = 3300005 // 更新服务合同失败 |
| | | SContractDeleteErr = 3300006 // 删除服务合同失败 |
| | | SContractProductPriceLowerThanInvoiceAmountErr = 3300007 //产品总价低于已开票金额 |
| | | SContractProductPriceLowerThanReceivedAmountErr = 3300008 //产品总价低于已收金额 |
| | | SContractInvoiceProductPriceGreaterThanReceivableAmountErr = 3300009 //开票总额高于应收金额 |
| | | |
| | | OrderManageExist = 3400001 // 订单管理已存在 |
| | | OrderManageNotExist = 3400002 // 订单管理不存在 |
| | |
| | | ChildrenExistErr: "存在子菜单", |
| | | MenuNotExist: "菜单不存在", |
| | | MenuNameExistErr: "菜单名已存在", |
| | | SContractProductPriceLowerThanInvoiceAmountErr: "产品总价低于已开票金额", |
| | | SContractProductPriceLowerThanReceivedAmountErr: "产品总价低于已收金额", |
| | | SContractInvoiceProductPriceGreaterThanReceivableAmountErr: "开票总额高于应收金额", |
| | | } |
| | | |
| | | func GetMsg(errCode int) (errMsg string) { |
| | |
| | | package service |
| | | |
| | | import ( |
| | | "aps_crm/constvar" |
| | | "aps_crm/model" |
| | | "aps_crm/model/request" |
| | | "aps_crm/pkg/ecode" |
| | | "github.com/shopspring/decimal" |
| | | "gorm.io/gorm" |
| | | ) |
| | | |
| | |
| | | |
| | | func (InvoiceService) AddInvoice(invoice *model.Invoice) int { |
| | | |
| | | err := model.WithTransaction(func(db *gorm.DB) error { |
| | | err := model.NewInvoiceSearch().Create(invoice) |
| | | if invoice.SourceType == constvar.InvoiceSourceTypeServiceContract { |
| | | serviceContract, err := model.NewServiceContractSearch().SetId(invoice.SourceId).SetPreload(true).First() |
| | | if err != nil { |
| | | return err |
| | | return ecode.DBErr |
| | | } |
| | | //if invoice.SourceType == constvar.InvoiceSourceTypeServiceContract { |
| | | // contract,err := model.NewServiceContractSearch().SetId(invoice.SourceId).First() |
| | | // if err != nil { |
| | | // return err |
| | | // } |
| | | // AmountInvoiced := contract.AmountReceived.Add() |
| | | // err := model.NewServiceContractSearch().SetId(invoice.SourceId).UpdateByMap(map[string]interface{}{ |
| | | // "amount_received" : |
| | | // }) |
| | | // if err != nil { |
| | | // return err |
| | | // } |
| | | //} |
| | | |
| | | return nil |
| | | }) |
| | | |
| | | if err != nil { |
| | | return ecode.DBErr |
| | | var amountInvoiced decimal.Decimal |
| | | rightProducts := NewProductsService().PickRightProducts(invoice.Products, serviceContract.Products) |
| | | for _, product := range rightProducts { |
| | | amountInvoiced = serviceContract.AmountInvoiced.Add(product.Amount.Mul(product.Price)) |
| | | } |
| | | amountInvoiced = amountInvoiced.Round(2) |
| | | if amountInvoiced.GreaterThan(serviceContract.AmountReceivable) { |
| | | return ecode.SContractInvoiceProductPriceGreaterThanReceivableAmountErr |
| | | } |
| | | err = model.WithTransaction(func(db *gorm.DB) error { |
| | | err = model.NewInvoiceSearch().Create(invoice) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | return model.NewServiceContractSearch().SetId(invoice.SourceId).UpdateByMap(map[string]interface{}{ |
| | | "amount_invoiced": amountInvoiced, |
| | | }) |
| | | }) |
| | | if err != nil { |
| | | return ecode.DBErr |
| | | } |
| | | } |
| | | |
| | | return ecode.OK |
| | |
| | | } |
| | | |
| | | func (InvoiceService) UpdateInvoice(invoice *model.Invoice) int { |
| | | err := model.NewInvoiceSearch().SetId(invoice.Id).Save(invoice) |
| | | if err != nil { |
| | | return ecode.DBErr |
| | | if invoice.SourceType == constvar.InvoiceSourceTypeServiceContract { |
| | | serviceContract, err := model.NewServiceContractSearch().SetId(invoice.SourceId).SetPreload(true).First() |
| | | if err != nil { |
| | | return ecode.DBErr |
| | | } |
| | | var amountInvoiced decimal.Decimal |
| | | newProducts, removedProducts := NewProductsService().PickDiffProducts(invoice.Products, serviceContract.Products) |
| | | for _, product := range newProducts { |
| | | amountInvoiced = serviceContract.AmountInvoiced.Add(product.Amount.Mul(product.Price)) |
| | | } |
| | | removedProductIds := make([]uint, 0, len(removedProducts)) |
| | | for _, product := range removedProducts { |
| | | amountInvoiced = serviceContract.AmountInvoiced.Sub(product.Amount.Mul(product.Price)) |
| | | removedProductIds = append(removedProductIds, product.Id) |
| | | } |
| | | amountInvoiced = amountInvoiced.Round(2) |
| | | if amountInvoiced.GreaterThan(serviceContract.AmountReceivable) { |
| | | return ecode.SContractInvoiceProductPriceGreaterThanReceivableAmountErr |
| | | } |
| | | err = model.WithTransaction(func(db *gorm.DB) error { |
| | | err = model.NewInvoiceSearch().SetId(invoice.Id).Save(invoice) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | if len(removedProductIds) > 0 { |
| | | err = model.NewInvoiceProductSearch().SetInvoiceId(invoice.Id).SetProductIds(removedProductIds).Delete() |
| | | if err != nil { |
| | | return err |
| | | } |
| | | } |
| | | return model.NewServiceContractSearch().SetId(invoice.SourceId).UpdateByMap(map[string]interface{}{ |
| | | "amount_invoiced": amountInvoiced, |
| | | }) |
| | | }) |
| | | if err != nil { |
| | | return ecode.DBErr |
| | | } |
| | | } |
| | | return ecode.OK |
| | | } |
New file |
| | |
| | | package service |
| | | |
| | | import ( |
| | | "aps_crm/model" |
| | | ) |
| | | |
| | | type ProductsService struct{} |
| | | |
| | | func NewProductsService() ProductsService { |
| | | return ProductsService{} |
| | | } |
| | | |
| | | func (slf ProductsService) PickRightProducts(products, sourceProducts []*model.Product) (rightProducts []*model.Product) { |
| | | productIdMap, productNumberMap := slf.getMappedProducts(sourceProducts) |
| | | for _, product := range products { |
| | | if p, ok := productIdMap[product.Id]; ok { |
| | | rightProducts = append(rightProducts, p) |
| | | } else if p, ok = productNumberMap[product.Number]; ok { |
| | | rightProducts = append(rightProducts, p) |
| | | } |
| | | } |
| | | return |
| | | } |
| | | |
| | | func (slf ProductsService) PickDiffProducts(products, sourceProducts []*model.Product) (newProducts, removedProducts []*model.Product) { |
| | | productIdMap, productNumberMap := slf.getMappedProducts(sourceProducts) |
| | | productNumberMap2 := make(map[string]*model.Product, len(products)) |
| | | for _, product := range products { |
| | | if productIdMap[product.Id] == nil && productNumberMap[product.Number] == nil { |
| | | newProducts = append(newProducts, product) |
| | | } |
| | | productNumberMap2[product.Number] = product |
| | | } |
| | | for productNumber, product := range productNumberMap { |
| | | if productNumberMap2[productNumber] == nil { |
| | | removedProducts = append(removedProducts, product) |
| | | } |
| | | } |
| | | return |
| | | } |
| | | |
| | | func (slf ProductsService) getMappedProducts(sourceProducts []*model.Product) (map[uint]*model.Product, map[string]*model.Product) { |
| | | productIdMap := make(map[uint]*model.Product, len(sourceProducts)) |
| | | productNumberMap := make(map[string]*model.Product, len(sourceProducts)) |
| | | for _, product := range sourceProducts { |
| | | productIdMap[product.Id] = product |
| | | productNumberMap[product.Number] = product |
| | | } |
| | | return productIdMap, productNumberMap |
| | | } |
| | |
| | | "aps_crm/constvar" |
| | | "aps_crm/model" |
| | | "aps_crm/pkg/ecode" |
| | | "github.com/shopspring/decimal" |
| | | ) |
| | | |
| | | type SContractService struct{} |
| | | |
| | | func (SContractService) AddServiceContract(serviceContract *model.ServiceContract) int { |
| | | serviceContract.AmountReceivable = decimal.Zero.Round(2) |
| | | serviceContract.AmountInvoiced = decimal.Zero.Round(2) |
| | | serviceContract.AmountReceived = decimal.Zero.Round(2) |
| | | for _, product := range serviceContract.Products { |
| | | serviceContract.AmountReceivable = serviceContract.AmountReceivable.Add(product.Amount.Mul(product.Price)) |
| | | } |
| | | serviceContract.AmountReceivable = serviceContract.AmountReceivable.Round(2) |
| | | err := model.NewServiceContractSearch().Create(serviceContract) |
| | | if err != nil { |
| | | return ecode.SContractExist |
| | |
| | | |
| | | func (SContractService) UpdateServiceContract(serviceContract *model.ServiceContract) int { |
| | | // check serviceContract exist |
| | | _, err := model.NewServiceContractSearch().SetId(serviceContract.Id).Find() |
| | | old, err := model.NewServiceContractSearch().SetId(serviceContract.Id).First() |
| | | if err != nil { |
| | | return ecode.SContractNotExist |
| | | } |
| | | |
| | | var amountReceivable decimal.Decimal |
| | | for _, product := range serviceContract.Products { |
| | | amountReceivable = serviceContract.AmountReceivable.Add(product.Amount.Mul(product.Price)) |
| | | } |
| | | if amountReceivable.LessThan(serviceContract.AmountInvoiced) { |
| | | return ecode.SContractProductPriceLowerThanInvoiceAmountErr |
| | | } |
| | | if amountReceivable.LessThan(serviceContract.AmountReceived) { |
| | | return ecode.SContractProductPriceLowerThanReceivedAmountErr |
| | | } |
| | | serviceContract.AmountInvoiced = old.AmountReceived |
| | | serviceContract.AmountReceived = old.AmountReceived |
| | | serviceContract.AmountReceivable = amountReceivable.Round(2) |
| | | err = model.NewServiceContractSearch().SetId(serviceContract.Id).Update(serviceContract) |
| | | if err != nil { |
| | | return ecode.SContractSetErr |
| | |
| | | SetKeyword(keyword). |
| | | SetKeywordType(keywordType). |
| | | SetQueryClass(queryClass). |
| | | SetPage(page, pageSize).FindAll() |
| | | SetPage(page, pageSize). |
| | | SetPreload(true). |
| | | Find() |
| | | if err != nil { |
| | | return nil, 0, ecode.SContractListErr |
| | | } |