add
wangpengfei
2023-07-10 f1fbbbf99f7fa820f51cb47aee4df7e7cf3df6f0
add

Quotation 报价单
add, Delete, update, list
5个文件已添加
9个文件已修改
980 ■■■■■ 已修改文件
api/v1/index.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/qutation.go 168 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 232 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 232 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 147 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/index.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/quotation.go 90 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/quotation.go 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/response/response.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pkg/ecode/code.go 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/index.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/qutation.go 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/index.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/qutation.go 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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
)
api/v1/qutation.go
New file
@@ -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, &params)
    if !ok {
        return
    }
    errCode, quotation := checkQuotationParams(params.Quotation)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    errCode = quotationService.AddQuotation(&quotation)
    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, &params)
    if !ok {
        return
    }
    errCode, quotation := checkQuotationParams(params.Quotation)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    quotation.Id = params.Id
    errCode = quotationService.UpdateQuotation(&quotation)
    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
}
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": {
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": {
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:
model/index.go
@@ -46,6 +46,7 @@
        RegularCustomers{},
        Possibility{},
        Status{},
        Quotation{},
    )
    return err
}
model/quotation.go
New file
@@ -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:报价单状态id"`
        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:联系人id"`
        MemberId          int        `json:"member_id" gorm:"column:member_id;type:int;comment:负责人id"`
        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
}
model/request/quotation.go
New file
@@ -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
}
model/response/response.go
@@ -121,4 +121,8 @@
    StatusResponse struct {
        List []*model.Status `json:"list"`
    }
    QuotationResponse struct {
        List []*model.Quotation `json:"list"`
    }
)
pkg/ecode/code.go
@@ -177,4 +177,10 @@
    StatusUpdateErr = 2400005 // 更新销售机会状态失败
    StatusDeleteErr = 2400006 // 删除销售机会状态失败
    QuotationExist     = 2500001 // 报价单已存在
    QuotationNotExist  = 2500002 // 报价单不存在
    QuotationListErr   = 2500003 // 获取报价单列表失败
    QuotationSetErr    = 2500004 // 设置报价单失败
    QuotationUpdateErr = 2500005 // 更新报价单失败
    QuotationDeleteErr = 2500006 // 删除报价单失败
)
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
}
router/qutation.go
New file
@@ -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)            // 获取报价单列表
    }
}
service/index.go
@@ -26,6 +26,7 @@
    RegularCustomersService
    PossibilityService
    StatusService
    QuotationService
}
var ServiceGroup = new(Group)
service/qutation.go
New file
@@ -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
}