From f1fbbbf99f7fa820f51cb47aee4df7e7cf3df6f0 Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期一, 10 七月 2023 19:43:57 +0800
Subject: [PATCH] add
---
api/v1/index.go | 2
service/qutation.go | 54 +++
pkg/ecode/code.go | 6
model/quotation.go | 90 +++++
docs/swagger.yaml | 147 ++++++++
docs/docs.go | 232 +++++++++++++
docs/swagger.json | 232 +++++++++++++
model/response/response.go | 4
service/index.go | 1
api/v1/qutation.go | 168 +++++++++
model/index.go | 1
router/index.go | 2
router/qutation.go | 19 +
model/request/quotation.go | 22 +
14 files changed, 980 insertions(+), 0 deletions(-)
diff --git a/api/v1/index.go b/api/v1/index.go
index 54ebbba..ccc3d5e 100644
--- a/api/v1/index.go
+++ b/api/v1/index.go
@@ -31,6 +31,7 @@
RegularCustomersApi
PossibilityApi
StatusApi
+ QuotationApi
}
var ApiGroup = new(Group)
@@ -61,4 +62,5 @@
regularCustomersService = service.ServiceGroup.RegularCustomersService
possibilityService = service.ServiceGroup.PossibilityService
statusService = service.ServiceGroup.StatusService
+ quotationService = service.ServiceGroup.QuotationService
)
diff --git a/api/v1/qutation.go b/api/v1/qutation.go
new file mode 100644
index 0000000..739681f
--- /dev/null
+++ b/api/v1/qutation.go
@@ -0,0 +1,168 @@
+package v1
+
+import (
+ "aps_crm/model"
+ "aps_crm/model/request"
+ "aps_crm/model/response"
+ "aps_crm/pkg/contextx"
+ "aps_crm/pkg/ecode"
+ "github.com/gin-gonic/gin"
+ "strconv"
+)
+
+type QuotationApi struct{}
+
+// Add
+//
+// @Tags Quotation
+// @Summary 娣诲姞鎶ヤ环鍗�
+// @Produce application/json
+// @Param object body request.AddQuotation true "鏌ヨ鍙傛暟"
+// @Success 200 {object} contextx.Response{}
+// @Router /api/quotation/add [post]
+func (s *QuotationApi) Add(c *gin.Context) {
+ var params request.AddQuotation
+ ctx, ok := contextx.NewContext(c, ¶ms)
+ if !ok {
+ return
+ }
+
+ errCode, quotation := checkQuotationParams(params.Quotation)
+ if errCode != ecode.OK {
+ ctx.Fail(errCode)
+ return
+ }
+
+ errCode = quotationService.AddQuotation("ation)
+ if errCode != ecode.OK {
+ ctx.Fail(errCode)
+ return
+ }
+
+ ctx.Ok()
+}
+
+// Delete
+//
+// @Tags Quotation
+// @Summary 鍒犻櫎鎶ヤ环鍗�
+// @Produce application/json
+// @Param id path int true "鏌ヨ鍙傛暟"
+// @Success 200 {object} contextx.Response{}
+// @Router /api/quotation/delete/{id} [delete]
+func (s *QuotationApi) Delete(c *gin.Context) {
+ ctx, ok := contextx.NewContext(c, nil)
+ if !ok {
+ return
+ }
+
+ id, _ := strconv.Atoi(c.Param("id"))
+ errCode := quotationService.DeleteQuotation(id)
+ if errCode != ecode.OK {
+ ctx.Fail(errCode)
+ return
+ }
+
+ ctx.Ok()
+}
+
+// Update
+//
+// @Tags Quotation
+// @Summary 鏇存柊鎶ヤ环鍗�
+// @Produce application/json
+// @Param object body request.UpdateQuotation true "鏌ヨ鍙傛暟"
+// @Success 200 {object} contextx.Response{}
+// @Router /api/quotation/update [put]
+func (s *QuotationApi) Update(c *gin.Context) {
+ var params request.UpdateQuotation
+ ctx, ok := contextx.NewContext(c, ¶ms)
+ if !ok {
+ return
+ }
+
+ errCode, quotation := checkQuotationParams(params.Quotation)
+ if errCode != ecode.OK {
+ ctx.Fail(errCode)
+ return
+ }
+
+ quotation.Id = params.Id
+
+ errCode = quotationService.UpdateQuotation("ation)
+ if errCode != ecode.OK {
+ ctx.Fail(errCode)
+ return
+ }
+
+ ctx.Ok()
+}
+
+// List
+//
+// @Tags Quotation
+// @Summary 鎶ヤ环鍗曞垪琛�
+// @Produce application/json
+// @Success 200 {object} contextx.Response{data=response.QuotationResponse}
+// @Router /api/quotation/list [get]
+func (s *QuotationApi) List(c *gin.Context) {
+ ctx, ok := contextx.NewContext(c, nil)
+ if !ok {
+ return
+ }
+
+ list, errCode := quotationService.GetQuotationList()
+ if errCode != ecode.OK {
+ ctx.Fail(errCode)
+ return
+ }
+
+ ctx.OkWithDetailed(response.QuotationResponse{
+ List: list,
+ })
+}
+
+// checkQuotationParams
+func checkQuotationParams(quotation request.Quotation) (int, model.Quotation) {
+ var errCode int
+ var quotationModel model.Quotation
+
+ if quotation.ClientId == 0 {
+ errCode = ecode.InvalidParams
+ return errCode, quotationModel
+ }
+
+ if quotation.QuotationStatusId == 0 {
+ errCode = ecode.InvalidParams
+ return errCode, quotationModel
+ }
+
+ if quotation.Number == "" {
+ errCode = ecode.InvalidParams
+ return errCode, quotationModel
+ }
+
+ if quotation.MemberId == 0 {
+ errCode = ecode.InvalidParams
+ return errCode, quotationModel
+ }
+
+ t, err := checkTimeFormat(quotation.ValidityDate)
+ if err != nil {
+ errCode = ecode.InvalidParams
+ return errCode, quotationModel
+ }
+
+ quotationModel.ValidityDate = t
+ quotationModel.ClientId = quotation.ClientId
+ quotationModel.QuotationStatusId = quotation.QuotationStatusId
+ quotationModel.Number = quotation.Number
+ quotationModel.MemberId = quotation.MemberId
+ quotationModel.SaleChanceId = quotation.SaleChanceId
+ quotationModel.ContactId = quotation.ContactId
+ quotationModel.Conditions = quotation.Conditions
+ quotationModel.File = quotation.File
+
+ return ecode.OK, quotationModel
+
+}
diff --git a/docs/docs.go b/docs/docs.go
index 6cbada4..9a8241c 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -1848,6 +1848,125 @@
}
}
},
+ "/api/quotation/add": {
+ "post": {
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Quotation"
+ ],
+ "summary": "娣诲姞鎶ヤ环鍗�",
+ "parameters": [
+ {
+ "description": "鏌ヨ鍙傛暟",
+ "name": "object",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/request.AddQuotation"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/contextx.Response"
+ }
+ }
+ }
+ }
+ },
+ "/api/quotation/delete/{id}": {
+ "delete": {
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Quotation"
+ ],
+ "summary": "鍒犻櫎鎶ヤ环鍗�",
+ "parameters": [
+ {
+ "type": "integer",
+ "description": "鏌ヨ鍙傛暟",
+ "name": "id",
+ "in": "path",
+ "required": true
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/contextx.Response"
+ }
+ }
+ }
+ }
+ },
+ "/api/quotation/list": {
+ "get": {
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Quotation"
+ ],
+ "summary": "鎶ヤ环鍗曞垪琛�",
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "allOf": [
+ {
+ "$ref": "#/definitions/contextx.Response"
+ },
+ {
+ "type": "object",
+ "properties": {
+ "data": {
+ "$ref": "#/definitions/response.QuotationResponse"
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ }
+ },
+ "/api/quotation/update": {
+ "put": {
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Quotation"
+ ],
+ "summary": "鏇存柊鎶ヤ环鍗�",
+ "parameters": [
+ {
+ "description": "鏌ヨ鍙傛暟",
+ "name": "object",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/request.UpdateQuotation"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/contextx.Response"
+ }
+ }
+ }
+ }
+ },
"/api/region/add": {
"post": {
"produces": [
@@ -3698,6 +3817,41 @@
}
}
},
+ "model.Quotation": {
+ "type": "object",
+ "properties": {
+ "client_id": {
+ "type": "integer"
+ },
+ "conditions": {
+ "type": "string"
+ },
+ "contact_id": {
+ "type": "integer"
+ },
+ "file": {
+ "type": "string"
+ },
+ "id": {
+ "type": "integer"
+ },
+ "member_id": {
+ "type": "integer"
+ },
+ "number": {
+ "type": "string"
+ },
+ "quotation_status_id": {
+ "type": "integer"
+ },
+ "sale_chance_id": {
+ "type": "integer"
+ },
+ "validity_date": {
+ "type": "string"
+ }
+ }
+ },
"model.Region": {
"type": "object",
"properties": {
@@ -4292,6 +4446,38 @@
"properties": {
"name": {
"description": "鐪佷唤鍚嶇О",
+ "type": "string"
+ }
+ }
+ },
+ "request.AddQuotation": {
+ "type": "object",
+ "properties": {
+ "client_id": {
+ "type": "integer"
+ },
+ "conditions": {
+ "type": "string"
+ },
+ "contact_id": {
+ "type": "integer"
+ },
+ "file": {
+ "type": "string"
+ },
+ "member_id": {
+ "type": "integer"
+ },
+ "number": {
+ "type": "string"
+ },
+ "quotation_status_id": {
+ "type": "integer"
+ },
+ "sale_chance_id": {
+ "type": "integer"
+ },
+ "validity_date": {
"type": "string"
}
}
@@ -5274,6 +5460,41 @@
}
}
},
+ "request.UpdateQuotation": {
+ "type": "object",
+ "properties": {
+ "client_id": {
+ "type": "integer"
+ },
+ "conditions": {
+ "type": "string"
+ },
+ "contact_id": {
+ "type": "integer"
+ },
+ "file": {
+ "type": "string"
+ },
+ "id": {
+ "type": "integer"
+ },
+ "member_id": {
+ "type": "integer"
+ },
+ "number": {
+ "type": "string"
+ },
+ "quotation_status_id": {
+ "type": "integer"
+ },
+ "sale_chance_id": {
+ "type": "integer"
+ },
+ "validity_date": {
+ "type": "string"
+ }
+ }
+ },
"request.UpdateRegion": {
"type": "object",
"properties": {
@@ -5806,6 +6027,17 @@
}
}
},
+ "response.QuotationResponse": {
+ "type": "object",
+ "properties": {
+ "list": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/model.Quotation"
+ }
+ }
+ }
+ },
"response.RegisteredCapitalResponse": {
"type": "object",
"properties": {
diff --git a/docs/swagger.json b/docs/swagger.json
index 9805666..f5a60ea 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -1836,6 +1836,125 @@
}
}
},
+ "/api/quotation/add": {
+ "post": {
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Quotation"
+ ],
+ "summary": "娣诲姞鎶ヤ环鍗�",
+ "parameters": [
+ {
+ "description": "鏌ヨ鍙傛暟",
+ "name": "object",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/request.AddQuotation"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/contextx.Response"
+ }
+ }
+ }
+ }
+ },
+ "/api/quotation/delete/{id}": {
+ "delete": {
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Quotation"
+ ],
+ "summary": "鍒犻櫎鎶ヤ环鍗�",
+ "parameters": [
+ {
+ "type": "integer",
+ "description": "鏌ヨ鍙傛暟",
+ "name": "id",
+ "in": "path",
+ "required": true
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/contextx.Response"
+ }
+ }
+ }
+ }
+ },
+ "/api/quotation/list": {
+ "get": {
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Quotation"
+ ],
+ "summary": "鎶ヤ环鍗曞垪琛�",
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "allOf": [
+ {
+ "$ref": "#/definitions/contextx.Response"
+ },
+ {
+ "type": "object",
+ "properties": {
+ "data": {
+ "$ref": "#/definitions/response.QuotationResponse"
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ }
+ },
+ "/api/quotation/update": {
+ "put": {
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "Quotation"
+ ],
+ "summary": "鏇存柊鎶ヤ环鍗�",
+ "parameters": [
+ {
+ "description": "鏌ヨ鍙傛暟",
+ "name": "object",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/request.UpdateQuotation"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/contextx.Response"
+ }
+ }
+ }
+ }
+ },
"/api/region/add": {
"post": {
"produces": [
@@ -3686,6 +3805,41 @@
}
}
},
+ "model.Quotation": {
+ "type": "object",
+ "properties": {
+ "client_id": {
+ "type": "integer"
+ },
+ "conditions": {
+ "type": "string"
+ },
+ "contact_id": {
+ "type": "integer"
+ },
+ "file": {
+ "type": "string"
+ },
+ "id": {
+ "type": "integer"
+ },
+ "member_id": {
+ "type": "integer"
+ },
+ "number": {
+ "type": "string"
+ },
+ "quotation_status_id": {
+ "type": "integer"
+ },
+ "sale_chance_id": {
+ "type": "integer"
+ },
+ "validity_date": {
+ "type": "string"
+ }
+ }
+ },
"model.Region": {
"type": "object",
"properties": {
@@ -4280,6 +4434,38 @@
"properties": {
"name": {
"description": "鐪佷唤鍚嶇О",
+ "type": "string"
+ }
+ }
+ },
+ "request.AddQuotation": {
+ "type": "object",
+ "properties": {
+ "client_id": {
+ "type": "integer"
+ },
+ "conditions": {
+ "type": "string"
+ },
+ "contact_id": {
+ "type": "integer"
+ },
+ "file": {
+ "type": "string"
+ },
+ "member_id": {
+ "type": "integer"
+ },
+ "number": {
+ "type": "string"
+ },
+ "quotation_status_id": {
+ "type": "integer"
+ },
+ "sale_chance_id": {
+ "type": "integer"
+ },
+ "validity_date": {
"type": "string"
}
}
@@ -5262,6 +5448,41 @@
}
}
},
+ "request.UpdateQuotation": {
+ "type": "object",
+ "properties": {
+ "client_id": {
+ "type": "integer"
+ },
+ "conditions": {
+ "type": "string"
+ },
+ "contact_id": {
+ "type": "integer"
+ },
+ "file": {
+ "type": "string"
+ },
+ "id": {
+ "type": "integer"
+ },
+ "member_id": {
+ "type": "integer"
+ },
+ "number": {
+ "type": "string"
+ },
+ "quotation_status_id": {
+ "type": "integer"
+ },
+ "sale_chance_id": {
+ "type": "integer"
+ },
+ "validity_date": {
+ "type": "string"
+ }
+ }
+ },
"request.UpdateRegion": {
"type": "object",
"properties": {
@@ -5794,6 +6015,17 @@
}
}
},
+ "response.QuotationResponse": {
+ "type": "object",
+ "properties": {
+ "list": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/model.Quotation"
+ }
+ }
+ }
+ },
"response.RegisteredCapitalResponse": {
"type": "object",
"properties": {
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 6c8e6f6..d6bb274 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -349,6 +349,29 @@
name:
type: string
type: object
+ model.Quotation:
+ properties:
+ client_id:
+ type: integer
+ conditions:
+ type: string
+ contact_id:
+ type: integer
+ file:
+ type: string
+ id:
+ type: integer
+ member_id:
+ type: integer
+ number:
+ type: string
+ quotation_status_id:
+ type: integer
+ sale_chance_id:
+ type: integer
+ validity_date:
+ type: string
+ type: object
model.Region:
properties:
id:
@@ -752,6 +775,27 @@
properties:
name:
description: 鐪佷唤鍚嶇О
+ type: string
+ type: object
+ request.AddQuotation:
+ properties:
+ client_id:
+ type: integer
+ conditions:
+ type: string
+ contact_id:
+ type: integer
+ file:
+ type: string
+ member_id:
+ type: integer
+ number:
+ type: string
+ quotation_status_id:
+ type: integer
+ sale_chance_id:
+ type: integer
+ validity_date:
type: string
type: object
request.AddRegion:
@@ -1426,6 +1470,29 @@
$ref: '#/definitions/request.UpdateProvince'
type: array
type: object
+ request.UpdateQuotation:
+ properties:
+ client_id:
+ type: integer
+ conditions:
+ type: string
+ contact_id:
+ type: integer
+ file:
+ type: string
+ id:
+ type: integer
+ member_id:
+ type: integer
+ number:
+ type: string
+ quotation_status_id:
+ type: integer
+ sale_chance_id:
+ type: integer
+ validity_date:
+ type: string
+ type: object
request.UpdateRegion:
properties:
id:
@@ -1774,6 +1841,13 @@
list:
items:
$ref: '#/definitions/model.Province'
+ type: array
+ type: object
+ response.QuotationResponse:
+ properties:
+ list:
+ items:
+ $ref: '#/definitions/model.Quotation'
type: array
type: object
response.RegisteredCapitalResponse:
@@ -2952,6 +3026,79 @@
summary: 鏇存柊鐪佷唤
tags:
- Province
+ /api/quotation/add:
+ post:
+ parameters:
+ - description: 鏌ヨ鍙傛暟
+ in: body
+ name: object
+ required: true
+ schema:
+ $ref: '#/definitions/request.AddQuotation'
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ $ref: '#/definitions/contextx.Response'
+ summary: 娣诲姞鎶ヤ环鍗�
+ tags:
+ - Quotation
+ /api/quotation/delete/{id}:
+ delete:
+ parameters:
+ - description: 鏌ヨ鍙傛暟
+ in: path
+ name: id
+ required: true
+ type: integer
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ $ref: '#/definitions/contextx.Response'
+ summary: 鍒犻櫎鎶ヤ环鍗�
+ tags:
+ - Quotation
+ /api/quotation/list:
+ get:
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ allOf:
+ - $ref: '#/definitions/contextx.Response'
+ - properties:
+ data:
+ $ref: '#/definitions/response.QuotationResponse'
+ type: object
+ summary: 鎶ヤ环鍗曞垪琛�
+ tags:
+ - Quotation
+ /api/quotation/update:
+ put:
+ parameters:
+ - description: 鏌ヨ鍙傛暟
+ in: body
+ name: object
+ required: true
+ schema:
+ $ref: '#/definitions/request.UpdateQuotation'
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ $ref: '#/definitions/contextx.Response'
+ summary: 鏇存柊鎶ヤ环鍗�
+ tags:
+ - Quotation
/api/region/add:
post:
parameters:
diff --git a/model/index.go b/model/index.go
index 0601b4d..584e114 100644
--- a/model/index.go
+++ b/model/index.go
@@ -46,6 +46,7 @@
RegularCustomers{},
Possibility{},
Status{},
+ Quotation{},
)
return err
}
diff --git a/model/quotation.go b/model/quotation.go
new file mode 100644
index 0000000..d5fdec8
--- /dev/null
+++ b/model/quotation.go
@@ -0,0 +1,90 @@
+package model
+
+import (
+ "aps_crm/pkg/mysqlx"
+ "gorm.io/gorm"
+ "time"
+)
+
+type (
+ // Quotation 鎶ヤ环鍗�
+ Quotation struct {
+ Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+ ClientId int `json:"client_id" gorm:"column:client_id;type:int;comment:瀹㈡埛id"`
+ Number string `json:"number" gorm:"column:number;type:varchar(255);comment:鎶ヤ环鍗曞彿"`
+ QuotationStatusId int `json:"quotation_status_id" gorm:"column:quotation_status_id;type:int;comment:鎶ヤ环鍗曠姸鎬乮d"`
+ ValidityDate time.Time `json:"validity_date" gorm:"column:validity_date;type:datetime;comment:鏈夋晥鏈�"`
+ ContactId int `json:"contact_id" gorm:"column:contact_id;type:int;comment:鑱旂郴浜篿d"`
+ MemberId int `json:"member_id" gorm:"column:member_id;type:int;comment:璐熻矗浜篿d"`
+ SaleChanceId int `json:"sale_chance_id" gorm:"column:sale_chance_id;type:int;comment:鍟嗘満id"`
+ Conditions string `json:"conditions" gorm:"column:conditions;type:text;comment:鎶ヤ环鏉′欢"`
+ File string `json:"file" gorm:"column:file;type:varchar(255);comment:闄勪欢"`
+ Client Client `json:"client" gorm:"foreignKey:ClientId"`
+ Contact Contact `json:"contact" gorm:"foreignKey:ContactId"`
+ SaleChance SaleChance `json:"sale_chance" gorm:"foreignKey:SaleChanceId"`
+ }
+
+ // QuotationSearch 鎶ヤ环鍗曟悳绱㈡潯浠�
+ QuotationSearch struct {
+ Quotation
+ Orm *gorm.DB
+ }
+)
+
+func (Quotation) TableName() string {
+ return "quotation"
+}
+
+func NewQuotationSearch() *QuotationSearch {
+ return &QuotationSearch{
+ Orm: mysqlx.GetDB(),
+ }
+}
+
+func (slf *QuotationSearch) build() *gorm.DB {
+ var db = slf.Orm.Model(&Quotation{})
+ if slf.Id != 0 {
+ db = db.Where("id = ?", slf.Id)
+ }
+
+ return db
+}
+
+func (slf *QuotationSearch) Create(record *Quotation) error {
+ var db = slf.build()
+ return db.Create(record).Error
+}
+
+func (slf *QuotationSearch) Delete() error {
+ var db = slf.build()
+ return db.Delete(&Quotation{}).Error
+}
+
+func (slf *QuotationSearch) Update(record *Quotation) error {
+ var db = slf.build()
+ return db.Updates(record).Error
+}
+
+func (slf *QuotationSearch) Find() (*Quotation, error) {
+ var db = slf.build()
+ var record Quotation
+ err := db.Preload("Client").Preload("Contact").Preload("SaleChance").First(&record).Error
+ return &record, err
+}
+
+func (slf *QuotationSearch) FindAll() ([]*Quotation, error) {
+ var db = slf.build()
+ var records []*Quotation
+ err := db.Find(&records).Error
+ return records, err
+}
+
+func (slf *QuotationSearch) SetId(id int) *QuotationSearch {
+ slf.Id = id
+ return slf
+}
+
+func (slf *QuotationSearch) Updates(data map[string]interface{}) error {
+ var db = slf.build()
+ return db.Updates(data).Error
+}
diff --git a/model/request/quotation.go b/model/request/quotation.go
new file mode 100644
index 0000000..91654de
--- /dev/null
+++ b/model/request/quotation.go
@@ -0,0 +1,22 @@
+package request
+
+type AddQuotation struct {
+ Quotation
+}
+
+type Quotation struct {
+ ClientId int `json:"client_id"`
+ Number string `json:"number"`
+ QuotationStatusId int `json:"quotation_status_id"`
+ ValidityDate string `json:"validity_date"`
+ ContactId int `json:"contact_id"`
+ MemberId int `json:"member_id"`
+ SaleChanceId int `json:"sale_chance_id"`
+ Conditions string `json:"conditions"`
+ File string `json:"file"`
+}
+
+type UpdateQuotation struct {
+ Id int `json:"id"`
+ Quotation
+}
diff --git a/model/response/response.go b/model/response/response.go
index 07ce959..51423c7 100644
--- a/model/response/response.go
+++ b/model/response/response.go
@@ -121,4 +121,8 @@
StatusResponse struct {
List []*model.Status `json:"list"`
}
+
+ QuotationResponse struct {
+ List []*model.Quotation `json:"list"`
+ }
)
diff --git a/pkg/ecode/code.go b/pkg/ecode/code.go
index 73faad0..d0f5a81 100644
--- a/pkg/ecode/code.go
+++ b/pkg/ecode/code.go
@@ -177,4 +177,10 @@
StatusUpdateErr = 2400005 // 鏇存柊閿�鍞満浼氱姸鎬佸け璐�
StatusDeleteErr = 2400006 // 鍒犻櫎閿�鍞満浼氱姸鎬佸け璐�
+ QuotationExist = 2500001 // 鎶ヤ环鍗曞凡瀛樺湪
+ QuotationNotExist = 2500002 // 鎶ヤ环鍗曚笉瀛樺湪
+ QuotationListErr = 2500003 // 鑾峰彇鎶ヤ环鍗曞垪琛ㄥけ璐�
+ QuotationSetErr = 2500004 // 璁剧疆鎶ヤ环鍗曞け璐�
+ QuotationUpdateErr = 2500005 // 鏇存柊鎶ヤ环鍗曞け璐�
+ QuotationDeleteErr = 2500006 // 鍒犻櫎鎶ヤ环鍗曞け璐�
)
diff --git a/router/index.go b/router/index.go
index d9f823d..be18007 100644
--- a/router/index.go
+++ b/router/index.go
@@ -37,6 +37,7 @@
RegularCustomersRouter
PossibilityRouter
StatusRouter
+ QuotationRouter
}
func InitRouter() *gin.Engine {
@@ -91,6 +92,7 @@
routerGroup.InitRegularCustomersRouter(PrivateGroup) // 娉ㄥ唽regularCustomers璺敱
routerGroup.InitPossibilityRouter(PrivateGroup) // 娉ㄥ唽possibility璺敱
routerGroup.InitStatusRouter(PrivateGroup) // 娉ㄥ唽status璺敱
+ routerGroup.InitQuotationRouter(PrivateGroup) // 娉ㄥ唽quotation璺敱
}
return Router
}
diff --git a/router/qutation.go b/router/qutation.go
new file mode 100644
index 0000000..d5fc559
--- /dev/null
+++ b/router/qutation.go
@@ -0,0 +1,19 @@
+package router
+
+import (
+ v1 "aps_crm/api/v1"
+ "github.com/gin-gonic/gin"
+)
+
+type QuotationRouter struct{}
+
+func (s *QuotationRouter) InitQuotationRouter(router *gin.RouterGroup) {
+ quotationRouter := router.Group("quotation")
+ quotationApi := v1.ApiGroup.QuotationApi
+ {
+ quotationRouter.POST("add", quotationApi.Add) // 娣诲姞鎶ヤ环鍗�
+ quotationRouter.DELETE("delete/:id", quotationApi.Delete) // 鍒犻櫎鎶ヤ环鍗�
+ quotationRouter.PUT("update", quotationApi.Update) // 鏇存柊鎶ヤ环鍗�
+ quotationRouter.GET("list", quotationApi.List) // 鑾峰彇鎶ヤ环鍗曞垪琛�
+ }
+}
diff --git a/service/index.go b/service/index.go
index 0e56603..c055e22 100644
--- a/service/index.go
+++ b/service/index.go
@@ -26,6 +26,7 @@
RegularCustomersService
PossibilityService
StatusService
+ QuotationService
}
var ServiceGroup = new(Group)
diff --git a/service/qutation.go b/service/qutation.go
new file mode 100644
index 0000000..247f4e8
--- /dev/null
+++ b/service/qutation.go
@@ -0,0 +1,54 @@
+package service
+
+import (
+ "aps_crm/model"
+ "aps_crm/pkg/ecode"
+)
+
+type QuotationService struct{}
+
+func (QuotationService) AddQuotation(quotation *model.Quotation) int {
+ err := model.NewQuotationSearch().Create(quotation)
+ if err != nil {
+ return ecode.QuotationExist
+ }
+
+ return ecode.OK
+}
+
+func (QuotationService) DeleteQuotation(id int) int {
+ _, err := model.NewQuotationSearch().SetId(id).Find()
+ if err != nil {
+ return ecode.QuotationNotExist
+ }
+
+ err = model.NewQuotationSearch().SetId(id).Delete()
+ if err != nil {
+ return ecode.QuotationNotExist
+ }
+ return ecode.OK
+}
+
+func (QuotationService) GetQuotationList() ([]*model.Quotation, int) {
+ list, err := model.NewQuotationSearch().FindAll()
+ if err != nil {
+ return nil, ecode.QuotationListErr
+ }
+
+ return list, ecode.OK
+}
+
+func (QuotationService) UpdateQuotation(quotation *model.Quotation) int {
+ // check quotation exist
+ _, err := model.NewQuotationSearch().SetId(quotation.Id).Find()
+ if err != nil {
+ return ecode.QuotationNotExist
+ }
+
+ err = model.NewQuotationSearch().SetId(quotation.Id).Update(quotation)
+ if err != nil {
+ return ecode.QuotationSetErr
+ }
+
+ return ecode.OK
+}
--
Gitblit v1.8.0