add
wangpengfei
2023-07-12 5d2b172ae64789fc371afa8eb14a3ef2c0ba90ab
add

plan 计划
add, Delete, update, list
5个文件已添加
9个文件已修改
941 ■■■■■ 已修改文件
api/v1/index.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/plan.go 155 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 225 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 225 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 142 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/index.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/plan.go 82 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/plan.go 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/response/response.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pkg/ecode/code.go 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/index.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/plan.go 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/index.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/plan.go 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/index.go
@@ -38,6 +38,7 @@
    SalesReturnApi
    SalesRefundApi
    ContractApi
    PlanApi
}
var ApiGroup = new(Group)
@@ -75,4 +76,5 @@
    salesReturnService       = service.ServiceGroup.SalesReturnService
    salesRefundService       = service.ServiceGroup.SalesRefundService
    contractService          = service.ServiceGroup.ContractService
    planService              = service.ServiceGroup.PlanService
)
api/v1/plan.go
New file
@@ -0,0 +1,155 @@
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 PlanApi struct{}
// Add
//
//    @Tags        Plan
//    @Summary    添加计划
//    @Produce    application/json
//    @Param        object    body        request.AddPlan    true    "查询参数"
//    @Success    200        {object}    contextx.Response{}
//    @Router        /api/plan/add [post]
func (s *PlanApi) Add(c *gin.Context) {
    var params request.AddPlan
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    errCode, plan := checkPlanParams(params.Plan)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    errCode = planService.AddPlan(&plan)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
// Delete
//
//    @Tags        Plan
//    @Summary    删除计划
//    @Produce    application/json
//    @Param        id    path        int    true    "查询参数"
//    @Success    200    {object}    contextx.Response{}
//    @Router        /api/plan/delete/{id} [delete]
func (s *PlanApi) Delete(c *gin.Context) {
    ctx, ok := contextx.NewContext(c, nil)
    if !ok {
        return
    }
    id, _ := strconv.Atoi(c.Param("id"))
    errCode := planService.DeletePlan(id)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
// Update
//
//    @Tags        Plan
//    @Summary    更新计划
//    @Produce    application/json
//    @Param        object    body        request.UpdatePlan    true    "查询参数"
//    @Success    200        {object}    contextx.Response{}
//    @Router        /api/plan/update [put]
func (s *PlanApi) Update(c *gin.Context) {
    var params request.UpdatePlan
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    errCode, plan := checkPlanParams(params.Plan)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    errCode = planService.UpdatePlan(&plan)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
// List
//
//    @Tags        Plan
//    @Summary    获取计划列表
//    @Produce    application/json
//    @Success    200    {object}    contextx.Response{data=response.PlanResponse}
//    @Router        /api/plan/list [get]
func (s *PlanApi) List(c *gin.Context) {
    ctx, ok := contextx.NewContext(c, nil)
    if !ok {
        return
    }
    list, errCode := planService.GetPlanList()
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.OkWithDetailed(response.PlanResponse{
        List: list,
    })
}
func checkPlanParams(plan request.Plan) (errCode int, p model.Plan) {
    if plan.Number == "" {
        return ecode.InvalidParams, p
    }
    if plan.MemberId == 0 {
        return ecode.InvalidParams, p
    }
    t, err := checkTimeFormat(plan.StartTime)
    if err != nil {
        return ecode.InvalidParams, p
    }
    p.StartTime = t
    t, err = checkTimeFormat(plan.EndTime)
    if err != nil {
        return ecode.InvalidParams, p
    }
    p.EndTime = t
    p.ClientId = plan.ClientId
    p.Number = plan.Number
    p.MemberId = plan.MemberId
    p.SubOrderId = plan.SubOrderId
    p.SalesDetailsId = plan.SalesDetailsId
    p.Content = plan.Content
    p.File = plan.File
    return ecode.OK, p
}
docs/docs.go
@@ -1818,6 +1818,125 @@
                }
            }
        },
        "/api/plan/add": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Plan"
                ],
                "summary": "添加计划",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.AddPlan"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/plan/delete/{id}": {
            "delete": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Plan"
                ],
                "summary": "删除计划",
                "parameters": [
                    {
                        "type": "integer",
                        "description": "查询参数",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/plan/list": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Plan"
                ],
                "summary": "获取计划列表",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/contextx.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/definitions/response.PlanResponse"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api/plan/update": {
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Plan"
                ],
                "summary": "更新计划",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.UpdatePlan"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/possibility/add": {
            "post": {
                "produces": [
@@ -4409,6 +4528,9 @@
                "number": {
                    "type": "string"
                },
                "quotation": {
                    "$ref": "#/definitions/model.Quotation"
                },
                "quotationId": {
                    "type": "integer"
                },
@@ -4540,6 +4662,47 @@
                },
                "start_time": {
                    "type": "string"
                }
            }
        },
        "model.Plan": {
            "type": "object",
            "properties": {
                "clientId": {
                    "type": "integer"
                },
                "content": {
                    "type": "string"
                },
                "endTime": {
                    "type": "string"
                },
                "file": {
                    "type": "string"
                },
                "id": {
                    "type": "integer"
                },
                "memberId": {
                    "type": "integer"
                },
                "number": {
                    "type": "string"
                },
                "salesDetails": {
                    "$ref": "#/definitions/model.SalesDetails"
                },
                "salesDetailsId": {
                    "type": "integer"
                },
                "startTime": {
                    "type": "string"
                },
                "subOrder": {
                    "$ref": "#/definitions/model.SubOrder"
                },
                "subOrderId": {
                    "type": "integer"
                }
            }
        },
@@ -5382,6 +5545,14 @@
                }
            }
        },
        "request.AddPlan": {
            "type": "object",
            "properties": {
                "plan": {
                    "$ref": "#/definitions/request.Plan"
                }
            }
        },
        "request.AddPossibility": {
            "type": "object",
            "required": [
@@ -5896,6 +6067,38 @@
                "username": {
                    "description": "用户名",
                    "type": "string"
                }
            }
        },
        "request.Plan": {
            "type": "object",
            "properties": {
                "clientId": {
                    "type": "integer"
                },
                "content": {
                    "type": "string"
                },
                "endTime": {
                    "type": "string"
                },
                "file": {
                    "type": "string"
                },
                "memberId": {
                    "type": "integer"
                },
                "number": {
                    "type": "string"
                },
                "salesDetailsId": {
                    "type": "integer"
                },
                "startTime": {
                    "type": "string"
                },
                "subOrderId": {
                    "type": "integer"
                }
            }
        },
@@ -6579,6 +6782,17 @@
                },
                "start_time": {
                    "type": "string"
                }
            }
        },
        "request.UpdatePlan": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "plan": {
                    "$ref": "#/definitions/request.Plan"
                }
            }
        },
@@ -7286,6 +7500,17 @@
                }
            }
        },
        "response.PlanResponse": {
            "type": "object",
            "properties": {
                "list": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.Plan"
                    }
                }
            }
        },
        "response.PossibilityResponse": {
            "type": "object",
            "properties": {
docs/swagger.json
@@ -1806,6 +1806,125 @@
                }
            }
        },
        "/api/plan/add": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Plan"
                ],
                "summary": "添加计划",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.AddPlan"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/plan/delete/{id}": {
            "delete": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Plan"
                ],
                "summary": "删除计划",
                "parameters": [
                    {
                        "type": "integer",
                        "description": "查询参数",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/plan/list": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Plan"
                ],
                "summary": "获取计划列表",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/contextx.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/definitions/response.PlanResponse"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api/plan/update": {
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Plan"
                ],
                "summary": "更新计划",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.UpdatePlan"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/possibility/add": {
            "post": {
                "produces": [
@@ -4397,6 +4516,9 @@
                "number": {
                    "type": "string"
                },
                "quotation": {
                    "$ref": "#/definitions/model.Quotation"
                },
                "quotationId": {
                    "type": "integer"
                },
@@ -4528,6 +4650,47 @@
                },
                "start_time": {
                    "type": "string"
                }
            }
        },
        "model.Plan": {
            "type": "object",
            "properties": {
                "clientId": {
                    "type": "integer"
                },
                "content": {
                    "type": "string"
                },
                "endTime": {
                    "type": "string"
                },
                "file": {
                    "type": "string"
                },
                "id": {
                    "type": "integer"
                },
                "memberId": {
                    "type": "integer"
                },
                "number": {
                    "type": "string"
                },
                "salesDetails": {
                    "$ref": "#/definitions/model.SalesDetails"
                },
                "salesDetailsId": {
                    "type": "integer"
                },
                "startTime": {
                    "type": "string"
                },
                "subOrder": {
                    "$ref": "#/definitions/model.SubOrder"
                },
                "subOrderId": {
                    "type": "integer"
                }
            }
        },
@@ -5370,6 +5533,14 @@
                }
            }
        },
        "request.AddPlan": {
            "type": "object",
            "properties": {
                "plan": {
                    "$ref": "#/definitions/request.Plan"
                }
            }
        },
        "request.AddPossibility": {
            "type": "object",
            "required": [
@@ -5884,6 +6055,38 @@
                "username": {
                    "description": "用户名",
                    "type": "string"
                }
            }
        },
        "request.Plan": {
            "type": "object",
            "properties": {
                "clientId": {
                    "type": "integer"
                },
                "content": {
                    "type": "string"
                },
                "endTime": {
                    "type": "string"
                },
                "file": {
                    "type": "string"
                },
                "memberId": {
                    "type": "integer"
                },
                "number": {
                    "type": "string"
                },
                "salesDetailsId": {
                    "type": "integer"
                },
                "startTime": {
                    "type": "string"
                },
                "subOrderId": {
                    "type": "integer"
                }
            }
        },
@@ -6567,6 +6770,17 @@
                },
                "start_time": {
                    "type": "string"
                }
            }
        },
        "request.UpdatePlan": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "plan": {
                    "$ref": "#/definitions/request.Plan"
                }
            }
        },
@@ -7274,6 +7488,17 @@
                }
            }
        },
        "response.PlanResponse": {
            "type": "object",
            "properties": {
                "list": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.Plan"
                    }
                }
            }
        },
        "response.PossibilityResponse": {
            "type": "object",
            "properties": {
docs/swagger.yaml
@@ -278,6 +278,8 @@
        type: integer
      number:
        type: string
      quotation:
        $ref: '#/definitions/model.Quotation'
      quotationId:
        type: integer
      statusId:
@@ -364,6 +366,33 @@
        type: string
      start_time:
        type: string
    type: object
  model.Plan:
    properties:
      clientId:
        type: integer
      content:
        type: string
      endTime:
        type: string
      file:
        type: string
      id:
        type: integer
      memberId:
        type: integer
      number:
        type: string
      salesDetails:
        $ref: '#/definitions/model.SalesDetails'
      salesDetailsId:
        type: integer
      startTime:
        type: string
      subOrder:
        $ref: '#/definitions/model.SubOrder'
      subOrderId:
        type: integer
    type: object
  model.Possibility:
    properties:
@@ -928,6 +957,11 @@
      start_time:
        type: string
    type: object
  request.AddPlan:
    properties:
      plan:
        $ref: '#/definitions/request.Plan'
    type: object
  request.AddPossibility:
    properties:
      name:
@@ -1278,6 +1312,27 @@
      username:
        description: 用户名
        type: string
    type: object
  request.Plan:
    properties:
      clientId:
        type: integer
      content:
        type: string
      endTime:
        type: string
      file:
        type: string
      memberId:
        type: integer
      number:
        type: string
      salesDetailsId:
        type: integer
      startTime:
        type: string
      subOrderId:
        type: integer
    type: object
  request.Register:
    properties:
@@ -1744,6 +1799,13 @@
      start_time:
        type: string
    type: object
  request.UpdatePlan:
    properties:
      id:
        type: integer
      plan:
        $ref: '#/definitions/request.Plan'
    type: object
  request.UpdatePossibilities:
    properties:
      possibilities:
@@ -2206,6 +2268,13 @@
        type: integer
      total:
        type: integer
    type: object
  response.PlanResponse:
    properties:
      list:
        items:
          $ref: '#/definitions/model.Plan'
        type: array
    type: object
  response.PossibilityResponse:
    properties:
@@ -3406,6 +3475,79 @@
      summary: 更新主订单
      tags:
      - MasterOrder
  /api/plan/add:
    post:
      parameters:
      - description: 查询参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.AddPlan'
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 添加计划
      tags:
      - Plan
  /api/plan/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:
      - Plan
  /api/plan/list:
    get:
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            allOf:
            - $ref: '#/definitions/contextx.Response'
            - properties:
                data:
                  $ref: '#/definitions/response.PlanResponse'
              type: object
      summary: 获取计划列表
      tags:
      - Plan
  /api/plan/update:
    put:
      parameters:
      - description: 查询参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.UpdatePlan'
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 更新计划
      tags:
      - Plan
  /api/possibility/add:
    post:
      parameters:
model/index.go
@@ -54,6 +54,7 @@
        SalesReturn{},
        SalesRefund{},
        Contract{},
        Plan{},
    )
    return err
}
model/plan.go
New file
@@ -0,0 +1,82 @@
package model
import (
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
    "time"
)
type (
    Plan 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"`
        SubOrderId     int          `json:"subOrderId" gorm:"column:sub_order_id;type:int;comment:子订单id"`
        SubOrder       SubOrder     `json:"subOrder" gorm:"foreignKey:SubOrderId"`
        SalesDetailsId int          `json:"salesDetailsId" gorm:"column:sales_details_id;type:int;comment:销售明细id"`
        SalesDetails   SalesDetails `json:"salesDetails" gorm:"foreignKey:SalesDetailsId"`
        StartTime      time.Time    `json:"startTime" gorm:"column:start_time;type:datetime;comment:开始时间"`
        EndTime        time.Time    `json:"endTime" gorm:"column:end_time;type:datetime;comment:结束时间"`
        Content        string       `json:"content" gorm:"column:content;type:varchar(255);comment:计划内容"`
        File           string       `json:"file" gorm:"column:file;type:varchar(255);comment:附件"`
    }
    PlanSearch struct {
        Plan
        Orm *gorm.DB
    }
)
func (Plan) TableName() string {
    return "plan"
}
func NewPlanSearch() *PlanSearch {
    return &PlanSearch{
        Orm: mysqlx.GetDB(),
    }
}
func (slf *PlanSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&Plan{})
    if slf.Id != 0 {
        db = db.Where("id = ?", slf.Id)
    }
    return db
}
func (slf *PlanSearch) Create(record *Plan) error {
    var db = slf.build()
    return db.Create(record).Error
}
func (slf *PlanSearch) Delete() error {
    var db = slf.build()
    return db.Delete(&Plan{}).Error
}
func (slf *PlanSearch) Update(record *Plan) error {
    var db = slf.build()
    return db.Updates(record).Error
}
func (slf *PlanSearch) Find() (*Plan, error) {
    var db = slf.build()
    var record = &Plan{}
    err := db.First(record).Error
    return record, err
}
func (slf *PlanSearch) FindAll() ([]*Plan, error) {
    var db = slf.build()
    var record = make([]*Plan, 0)
    err := db.Find(&record).Error
    return record, err
}
func (slf *PlanSearch) SetId(id int) *PlanSearch {
    slf.Id = id
    return slf
}
model/request/plan.go
New file
@@ -0,0 +1,22 @@
package request
type AddPlan struct {
    Plan Plan `json:"plan"`
}
type Plan struct {
    ClientId       int    `json:"clientId"`
    Number         string `json:"number"`
    MemberId       int    `json:"memberId"`
    SubOrderId     int    `json:"subOrderId"`
    SalesDetailsId int    `json:"salesDetailsId"`
    StartTime      string `json:"startTime"`
    EndTime        string `json:"endTime"`
    Content        string `json:"content"`
    File           string `json:"file"`
}
type UpdatePlan struct {
    Id   int  `json:"id"`
    Plan Plan `json:"plan"`
}
model/response/response.go
@@ -149,4 +149,8 @@
    ContractResponse struct {
        List []*model.Contract `json:"list"`
    }
    PlanResponse struct {
        List []*model.Plan `json:"list"`
    }
)
pkg/ecode/code.go
@@ -225,4 +225,11 @@
    ContractSetErr    = 3100004 // 设置合同失败
    ContractUpdateErr = 3100005 // 更新合同失败
    ContractDeleteErr = 3100006 // 删除合同失败
    PlanExist     = 3200001 // 计划已存在
    PlanNotExist  = 3200002 // 计划不存在
    PlanListErr   = 3200003 // 获取计划列表失败
    PlanSetErr    = 3200004 // 设置计划失败
    PlanUpdateErr = 3200005 // 更新计划失败
    PlanDeleteErr = 3200006 // 删除计划失败
)
router/index.go
@@ -44,6 +44,7 @@
    SalesReturnRouter
    SalesRefundRouter
    ContractRouter
    PlanRouter
}
func InitRouter() *gin.Engine {
@@ -105,6 +106,7 @@
        routerGroup.InitSalesReturnRouter(PrivateGroup)       // 注册salesReturn路由
        routerGroup.InitSalesRefundRouter(PrivateGroup)       // 注册salesRefund路由
        routerGroup.InitContractRouter(PrivateGroup)          // 注册contract路由
        routerGroup.InitPlanRouter(PrivateGroup)              // 注册plan路由
    }
    return Router
}
router/plan.go
New file
@@ -0,0 +1,19 @@
package router
import (
    v1 "aps_crm/api/v1"
    "github.com/gin-gonic/gin"
)
type PlanRouter struct{}
func (p *PlanRouter) InitPlanRouter(router *gin.RouterGroup) {
    planRouter := router.Group("plan")
    planApi := v1.ApiGroup.PlanApi
    {
        planRouter.POST("add", planApi.Add)             // 添加计划
        planRouter.DELETE("delete/:id", planApi.Delete) // 删除计划
        planRouter.PUT("update", planApi.Update)        // 更新计划
        planRouter.GET("list", planApi.List)            // 获取计划列表
    }
}
service/index.go
@@ -33,6 +33,7 @@
    SalesReturnService
    SalesRefundService
    ContractService
    PlanService
}
var ServiceGroup = new(Group)
service/plan.go
New file
@@ -0,0 +1,54 @@
package service
import (
    "aps_crm/model"
    "aps_crm/pkg/ecode"
)
type PlanService struct{}
func (PlanService) AddPlan(plan *model.Plan) int {
    err := model.NewPlanSearch().Create(plan)
    if err != nil {
        return ecode.PlanExist
    }
    return ecode.OK
}
func (PlanService) DeletePlan(id int) int {
    _, err := model.NewPlanSearch().SetId(id).Find()
    if err != nil {
        return ecode.PlanNotExist
    }
    err = model.NewPlanSearch().SetId(id).Delete()
    if err != nil {
        return ecode.PlanNotExist
    }
    return ecode.OK
}
func (PlanService) GetPlanList() ([]*model.Plan, int) {
    list, err := model.NewPlanSearch().FindAll()
    if err != nil {
        return nil, ecode.PlanListErr
    }
    return list, ecode.OK
}
func (PlanService) UpdatePlan(plan *model.Plan) int {
    // check plan exist
    _, err := model.NewPlanSearch().SetId(plan.Id).Find()
    if err != nil {
        return ecode.PlanNotExist
    }
    err = model.NewPlanSearch().SetId(plan.Id).Update(plan)
    if err != nil {
        return ecode.PlanSetErr
    }
    return ecode.OK
}