add
plan 计划
add, Delete, update, list
| | |
| | | SalesReturnApi |
| | | SalesRefundApi |
| | | ContractApi |
| | | PlanApi |
| | | } |
| | | |
| | | var ApiGroup = new(Group) |
| | |
| | | salesReturnService = service.ServiceGroup.SalesReturnService |
| | | salesRefundService = service.ServiceGroup.SalesRefundService |
| | | contractService = service.ServiceGroup.ContractService |
| | | planService = service.ServiceGroup.PlanService |
| | | ) |
New file |
| | |
| | | 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, ¶ms) |
| | | 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, ¶ms) |
| | | 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 |
| | | } |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/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": [ |
| | |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "quotation": { |
| | | "$ref": "#/definitions/model.Quotation" |
| | | }, |
| | | "quotationId": { |
| | | "type": "integer" |
| | | }, |
| | |
| | | }, |
| | | "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" |
| | | } |
| | | } |
| | | }, |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.AddPlan": { |
| | | "type": "object", |
| | | "properties": { |
| | | "plan": { |
| | | "$ref": "#/definitions/request.Plan" |
| | | } |
| | | } |
| | | }, |
| | | "request.AddPossibility": { |
| | | "type": "object", |
| | | "required": [ |
| | |
| | | "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" |
| | | } |
| | | } |
| | | }, |
| | |
| | | }, |
| | | "start_time": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdatePlan": { |
| | | "type": "object", |
| | | "properties": { |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "plan": { |
| | | "$ref": "#/definitions/request.Plan" |
| | | } |
| | | } |
| | | }, |
| | |
| | | } |
| | | } |
| | | }, |
| | | "response.PlanResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | | "list": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/model.Plan" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "response.PossibilityResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/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": [ |
| | |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "quotation": { |
| | | "$ref": "#/definitions/model.Quotation" |
| | | }, |
| | | "quotationId": { |
| | | "type": "integer" |
| | | }, |
| | |
| | | }, |
| | | "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" |
| | | } |
| | | } |
| | | }, |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.AddPlan": { |
| | | "type": "object", |
| | | "properties": { |
| | | "plan": { |
| | | "$ref": "#/definitions/request.Plan" |
| | | } |
| | | } |
| | | }, |
| | | "request.AddPossibility": { |
| | | "type": "object", |
| | | "required": [ |
| | |
| | | "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" |
| | | } |
| | | } |
| | | }, |
| | |
| | | }, |
| | | "start_time": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdatePlan": { |
| | | "type": "object", |
| | | "properties": { |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "plan": { |
| | | "$ref": "#/definitions/request.Plan" |
| | | } |
| | | } |
| | | }, |
| | |
| | | } |
| | | } |
| | | }, |
| | | "response.PlanResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | | "list": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/model.Plan" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "response.PossibilityResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | type: integer |
| | | number: |
| | | type: string |
| | | quotation: |
| | | $ref: '#/definitions/model.Quotation' |
| | | quotationId: |
| | | type: integer |
| | | statusId: |
| | |
| | | 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: |
| | |
| | | start_time: |
| | | type: string |
| | | type: object |
| | | request.AddPlan: |
| | | properties: |
| | | plan: |
| | | $ref: '#/definitions/request.Plan' |
| | | type: object |
| | | request.AddPossibility: |
| | | properties: |
| | | name: |
| | |
| | | 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: |
| | |
| | | start_time: |
| | | type: string |
| | | type: object |
| | | request.UpdatePlan: |
| | | properties: |
| | | id: |
| | | type: integer |
| | | plan: |
| | | $ref: '#/definitions/request.Plan' |
| | | type: object |
| | | request.UpdatePossibilities: |
| | | properties: |
| | | possibilities: |
| | |
| | | type: integer |
| | | total: |
| | | type: integer |
| | | type: object |
| | | response.PlanResponse: |
| | | properties: |
| | | list: |
| | | items: |
| | | $ref: '#/definitions/model.Plan' |
| | | type: array |
| | | type: object |
| | | response.PossibilityResponse: |
| | | properties: |
| | |
| | | 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: |
| | |
| | | SalesReturn{}, |
| | | SalesRefund{}, |
| | | Contract{}, |
| | | Plan{}, |
| | | ) |
| | | return err |
| | | } |
New file |
| | |
| | | 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 |
| | | } |
New file |
| | |
| | | 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"` |
| | | } |
| | |
| | | ContractResponse struct { |
| | | List []*model.Contract `json:"list"` |
| | | } |
| | | |
| | | PlanResponse struct { |
| | | List []*model.Plan `json:"list"` |
| | | } |
| | | ) |
| | |
| | | ContractSetErr = 3100004 // 设置合同失败 |
| | | ContractUpdateErr = 3100005 // 更新合同失败 |
| | | ContractDeleteErr = 3100006 // 删除合同失败 |
| | | |
| | | PlanExist = 3200001 // 计划已存在 |
| | | PlanNotExist = 3200002 // 计划不存在 |
| | | PlanListErr = 3200003 // 获取计划列表失败 |
| | | PlanSetErr = 3200004 // 设置计划失败 |
| | | PlanUpdateErr = 3200005 // 更新计划失败 |
| | | PlanDeleteErr = 3200006 // 删除计划失败 |
| | | ) |
| | |
| | | SalesReturnRouter |
| | | SalesRefundRouter |
| | | ContractRouter |
| | | PlanRouter |
| | | } |
| | | |
| | | func InitRouter() *gin.Engine { |
| | |
| | | routerGroup.InitSalesReturnRouter(PrivateGroup) // 注册salesReturn路由 |
| | | routerGroup.InitSalesRefundRouter(PrivateGroup) // 注册salesRefund路由 |
| | | routerGroup.InitContractRouter(PrivateGroup) // 注册contract路由 |
| | | routerGroup.InitPlanRouter(PrivateGroup) // 注册plan路由 |
| | | } |
| | | return Router |
| | | } |
New file |
| | |
| | | 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) // 获取计划列表 |
| | | } |
| | | } |
| | |
| | | SalesReturnService |
| | | SalesRefundService |
| | | ContractService |
| | | PlanService |
| | | } |
| | | |
| | | var ServiceGroup = new(Group) |
New file |
| | |
| | | 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 |
| | | } |