From 32ae12002f89b089cb96849950759d2378d1729a Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期四, 13 七月 2023 11:00:52 +0800
Subject: [PATCH] add
---
api/v1/index.go | 2
api/v1/serviceContracts.go | 174 ++++++++
service/serviceContracts.go | 63 +++
model/request/serviceContracts.go | 33 +
pkg/ecode/code.go | 7
docs/swagger.yaml | 195 +++++++++
model/serviceContracts.go | 87 ++++
router/serviceContracts.go | 19
docs/docs.go | 304 +++++++++++++++
docs/swagger.json | 304 +++++++++++++++
model/response/response.go | 4
service/index.go | 1
model/index.go | 1
logs/aps-admin.err.log | 2
router/index.go | 2
15 files changed, 1,198 insertions(+), 0 deletions(-)
diff --git a/api/v1/index.go b/api/v1/index.go
index e3b75f6..98aa66f 100644
--- a/api/v1/index.go
+++ b/api/v1/index.go
@@ -39,6 +39,7 @@
SalesRefundApi
ContractApi
PlanApi
+ ServiceContractApi
}
var ApiGroup = new(Group)
@@ -77,4 +78,5 @@
salesRefundService = service.ServiceGroup.SalesRefundService
contractService = service.ServiceGroup.ContractService
planService = service.ServiceGroup.PlanService
+ serviceContractService = service.ServiceGroup.SContractService
)
diff --git a/api/v1/serviceContracts.go b/api/v1/serviceContracts.go
new file mode 100644
index 0000000..a4ad8c5
--- /dev/null
+++ b/api/v1/serviceContracts.go
@@ -0,0 +1,174 @@
+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
+}
diff --git a/docs/docs.go b/docs/docs.go
index 6c4e9ba..d8a6f92 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -3639,6 +3639,125 @@
}
}
},
+ "/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": [
@@ -5148,6 +5267,65 @@
}
}
},
+ "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": {
@@ -5837,6 +6015,62 @@
"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"
}
}
},
@@ -7262,6 +7496,65 @@
}
}
},
+ "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": [
@@ -7643,6 +7936,17 @@
}
}
},
+ "response.ServiceContractsResponse": {
+ "type": "object",
+ "properties": {
+ "list": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/model.ServiceContract"
+ }
+ }
+ }
+ },
"response.SubOrderResponse": {
"type": "object",
"properties": {
diff --git a/docs/swagger.json b/docs/swagger.json
index 36036ed..6a007ec 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -3627,6 +3627,125 @@
}
}
},
+ "/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": [
@@ -5136,6 +5255,65 @@
}
}
},
+ "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": {
@@ -5825,6 +6003,62 @@
"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"
}
}
},
@@ -7250,6 +7484,65 @@
}
}
},
+ "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": [
@@ -7631,6 +7924,17 @@
}
}
},
+ "response.ServiceContractsResponse": {
+ "type": "object",
+ "properties": {
+ "list": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/model.ServiceContract"
+ }
+ }
+ }
+ },
"response.SubOrderResponse": {
"type": "object",
"properties": {
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 2452796..9e073d8 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -684,6 +684,45 @@
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:
@@ -1151,6 +1190,43 @@
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:
@@ -2116,6 +2192,45 @@
$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:
@@ -2358,6 +2473,13 @@
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:
@@ -4598,6 +4720,79 @@
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:
diff --git a/logs/aps-admin.err.log b/logs/aps-admin.err.log
index 1071cdb..c3683ac 100644
--- a/logs/aps-admin.err.log
+++ b/logs/aps-admin.err.log
@@ -346,3 +346,5 @@
[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`"}
diff --git a/model/index.go b/model/index.go
index 2002ea9..263d837 100644
--- a/model/index.go
+++ b/model/index.go
@@ -55,6 +55,7 @@
SalesRefund{},
Contract{},
Plan{},
+ ServiceContract{},
)
return err
}
diff --git a/model/request/serviceContracts.go b/model/request/serviceContracts.go
new file mode 100644
index 0000000..2334df5
--- /dev/null
+++ b/model/request/serviceContracts.go
@@ -0,0 +1,33 @@
+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
+}
diff --git a/model/response/response.go b/model/response/response.go
index 8a41e2d..2bcb7f9 100644
--- a/model/response/response.go
+++ b/model/response/response.go
@@ -153,4 +153,8 @@
PlanResponse struct {
List []*model.Plan `json:"list"`
}
+
+ ServiceContractsResponse struct {
+ List []*model.ServiceContract `json:"list"`
+ }
)
diff --git a/model/serviceContracts.go b/model/serviceContracts.go
new file mode 100644
index 0000000..68d1ecd
--- /dev/null
+++ b/model/serviceContracts.go
@@ -0,0 +1,87 @@
+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:璐熻矗浜篿d"`
+ ContactId int `json:"contactId" gorm:"column:contact_id;type:int;comment:鑱旂郴浜篿d"`
+ SaleChanceId int `json:"saleChanceId" gorm:"column:sale_chance_id;type:int;comment:閿�鍞満浼歩d"`
+ ContractId int `json:"contractId" gorm:"column:contract_id;type:int;comment:鍚堝悓id"`
+ QuotationId int `json:"quotationId" gorm:"column:quotation_id;type:int;comment:鎶ヤ环鍗昳d"`
+ 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:鍚堝悓鐘舵�乮d"`
+ 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
+}
diff --git a/pkg/ecode/code.go b/pkg/ecode/code.go
index c895394..3ad6c13 100644
--- a/pkg/ecode/code.go
+++ b/pkg/ecode/code.go
@@ -232,4 +232,11 @@
PlanSetErr = 3200004 // 璁剧疆璁″垝澶辫触
PlanUpdateErr = 3200005 // 鏇存柊璁″垝澶辫触
PlanDeleteErr = 3200006 // 鍒犻櫎璁″垝澶辫触
+
+ SContractExist = 3300001 // 鏈嶅姟鍚堝悓宸插瓨鍦�
+ SContractNotExist = 3300002 // 鏈嶅姟鍚堝悓涓嶅瓨鍦�
+ SContractListErr = 3300003 // 鑾峰彇鏈嶅姟鍚堝悓鍒楄〃澶辫触
+ SContractSetErr = 3300004 // 璁剧疆鏈嶅姟鍚堝悓澶辫触
+ SContractUpdateErr = 3300005 // 鏇存柊鏈嶅姟鍚堝悓澶辫触
+ SContractDeleteErr = 3300006 // 鍒犻櫎鏈嶅姟鍚堝悓澶辫触
)
diff --git a/router/index.go b/router/index.go
index 7e4ef85..d1e3491 100644
--- a/router/index.go
+++ b/router/index.go
@@ -45,6 +45,7 @@
SalesRefundRouter
ContractRouter
PlanRouter
+ ServiceContractRouter
}
func InitRouter() *gin.Engine {
@@ -107,6 +108,7 @@
routerGroup.InitSalesRefundRouter(PrivateGroup) // 娉ㄥ唽salesRefund璺敱
routerGroup.InitContractRouter(PrivateGroup) // 娉ㄥ唽contract璺敱
routerGroup.InitPlanRouter(PrivateGroup) // 娉ㄥ唽plan璺敱
+ routerGroup.InitServiceContractRouter(PrivateGroup) // 娉ㄥ唽serviceContract璺敱
}
return Router
}
diff --git a/router/serviceContracts.go b/router/serviceContracts.go
new file mode 100644
index 0000000..51f4030
--- /dev/null
+++ b/router/serviceContracts.go
@@ -0,0 +1,19 @@
+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) // 鑾峰彇鏈嶅姟鍚堝悓鍒楄〃
+ }
+}
diff --git a/service/index.go b/service/index.go
index 4116a99..53f805d 100644
--- a/service/index.go
+++ b/service/index.go
@@ -34,6 +34,7 @@
SalesRefundService
ContractService
PlanService
+ SContractService
}
var ServiceGroup = new(Group)
diff --git a/service/serviceContracts.go b/service/serviceContracts.go
new file mode 100644
index 0000000..81a4456
--- /dev/null
+++ b/service/serviceContracts.go
@@ -0,0 +1,63 @@
+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
+}
--
Gitblit v1.8.0