From 823296cc595b3167c31a6257352c136568d0aaaf Mon Sep 17 00:00:00 2001 From: wangpengfei <274878379@qq.com> Date: 星期五, 21 七月 2023 11:43:20 +0800 Subject: [PATCH] add --- api/v1/index.go | 2 router/isInvoice.go | 20 + service/dataServer.go | 5 service/isInvoice.go | 69 ++++ pkg/ecode/code.go | 9 api/v1/isInvoice.go | 113 ++++++++ docs/swagger.yaml | 118 ++++++++ docs/docs.go | 188 +++++++++++++ docs/swagger.json | 188 +++++++++++++ model/response/response.go | 8 service/index.go | 1 model/index.go | 1 model/isInvoice.go | 85 ++++++ router/index.go | 2 model/request/isInvoice.go | 15 + 15 files changed, 822 insertions(+), 2 deletions(-) diff --git a/api/v1/index.go b/api/v1/index.go index 99416d6..6b430b3 100644 --- a/api/v1/index.go +++ b/api/v1/index.go @@ -5,6 +5,7 @@ ) type Group struct { + IsInvoiceApi RefundMethodApi ServiceContractTypeApi ServiceContractStatusApi @@ -116,4 +117,5 @@ serviceContractStatusService = service.ServiceGroup.ServiceContractStatusService serviceContractTypeService = service.ServiceGroup.ServiceContractTypeService refundMethodService = service.ServiceGroup.RefundMethodService + isInvoiceService = service.ServiceGroup.IsInvoiceService ) \ No newline at end of file diff --git a/api/v1/isInvoice.go b/api/v1/isInvoice.go new file mode 100644 index 0000000..e837bec --- /dev/null +++ b/api/v1/isInvoice.go @@ -0,0 +1,113 @@ + +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 IsInvoiceApi struct{} + +// Add +// +// @Tags IsInvoice +// @Summary 娣诲姞鏄惁寮�绁� +// @Produce application/json +// @Param object body request.AddIsInvoice true "鏌ヨ鍙傛暟" +// @Success 200 {object} contextx.Response{} +// @Router /api/isInvoice/add [post] +func (s *IsInvoiceApi) Add(c *gin.Context) { + var params request.AddIsInvoice + ctx, ok := contextx.NewContext(c, ¶ms) + if !ok { + return + } + + isInvoice := new(model.IsInvoice) + isInvoice.Name = params.Name + + errCode := isInvoiceService.AddIsInvoice(isInvoice) + if errCode != ecode.OK { + ctx.Fail(errCode) + return + } + + ctx.Ok() +} + +// Delete +// +// @Tags IsInvoice +// @Summary 鍒犻櫎鏄惁寮�绁� +// @Produce application/json +// @Param id path int true "鏌ヨ鍙傛暟" +// @Success 200 {object} contextx.Response{} +// @Router /api/isInvoice/delete/{id} [delete] +func (s *IsInvoiceApi) Delete(c *gin.Context) { + ctx, ok := contextx.NewContext(c, nil) + if !ok { + return + } + + id, _ := strconv.Atoi(c.Param("id")) + errCode := isInvoiceService.DeleteIsInvoice(id) + if errCode != ecode.OK { + ctx.Fail(errCode) + return + } + + ctx.Ok() +} + +// Update +// +// @Tags IsInvoice +// @Summary 鏇存柊鏄惁寮�绁� +// @Produce application/json +// @Param object body request.UpdateIsInvoices true "鏌ヨ鍙傛暟" +// @Success 200 {object} contextx.Response{} +// @Router /api/isInvoice/update [put] +func (s *IsInvoiceApi) Update(c *gin.Context) { + var params request.UpdateIsInvoices + ctx, ok := contextx.NewContext(c, ¶ms) + if !ok { + return + } + + errCode := isInvoiceService.UpdateIsInvoice(params.IsInvoices) + if errCode != ecode.OK { + ctx.Fail(errCode) + return + } + + ctx.Ok() +} + +// List +// +// @Tags IsInvoice +// @Summary 鑾峰彇鏄惁寮�绁ㄥ垪琛� +// @Produce application/json +// @Success 200 {object} contextx.Response{data=response.IsInvoiceResponse} +// @Router /api/isInvoice/list [get] +func (s *IsInvoiceApi) List(c *gin.Context) { + ctx, ok := contextx.NewContext(c, nil) + if !ok { + return + } + + isInvoices, errCode := isInvoiceService.GetIsInvoiceList() + if errCode != ecode.OK { + ctx.Fail(errCode) + return + } + + ctx.OkWithDetailed(response.IsInvoiceResponse{ + List: isInvoices, + }) +} diff --git a/docs/docs.go b/docs/docs.go index 3a94799..c6d453c 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -2040,6 +2040,125 @@ } } }, + "/api/isInvoice/add": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "IsInvoice" + ], + "summary": "娣诲姞鏄惁寮�绁�", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.AddIsInvoice" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, + "/api/isInvoice/delete/{id}": { + "delete": { + "produces": [ + "application/json" + ], + "tags": [ + "IsInvoice" + ], + "summary": "鍒犻櫎鏄惁寮�绁�", + "parameters": [ + { + "type": "integer", + "description": "鏌ヨ鍙傛暟", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, + "/api/isInvoice/list": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "IsInvoice" + ], + "summary": "鑾峰彇鏄惁寮�绁ㄥ垪琛�", + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/contextx.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/response.IsInvoiceResponse" + } + } + } + ] + } + } + } + } + }, + "/api/isInvoice/update": { + "put": { + "produces": [ + "application/json" + ], + "tags": [ + "IsInvoice" + ], + "summary": "鏇存柊鏄惁寮�绁�", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.UpdateIsInvoices" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, "/api/isVisit/add": { "post": { "produces": [ @@ -6698,6 +6817,17 @@ } } }, + "model.IsInvoice": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, "model.IsVisit": { "type": "object", "properties": { @@ -7914,6 +8044,17 @@ } }, "request.AddIndustry": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string" + } + } + }, + "request.AddIsInvoice": { "type": "object", "required": [ "name" @@ -9615,6 +9756,35 @@ } } }, + "request.UpdateIsInvoice": { + "type": "object", + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, + "request.UpdateIsInvoices": { + "type": "object", + "required": [ + "is_invoice" + ], + "properties": { + "is_invoice": { + "type": "array", + "items": { + "$ref": "#/definitions/request.UpdateIsInvoice" + } + } + } + }, "request.UpdateIsVisit": { "type": "object", "required": [ @@ -10832,6 +11002,13 @@ "$ref": "#/definitions/model.Industry" } }, + "isInvoice": { + "description": "鏄惁寮�绁�", + "type": "array", + "items": { + "$ref": "#/definitions/model.IsInvoice" + } + }, "isVisit": { "description": "鏈嶅姟浜哄憳鏄惁鏉ヨ繃", "type": "array", @@ -11008,6 +11185,17 @@ } } }, + "response.IsInvoiceResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/model.IsInvoice" + } + } + } + }, "response.IsVisitResponse": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index d23d994..148c7e1 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -2028,6 +2028,125 @@ } } }, + "/api/isInvoice/add": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "IsInvoice" + ], + "summary": "娣诲姞鏄惁寮�绁�", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.AddIsInvoice" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, + "/api/isInvoice/delete/{id}": { + "delete": { + "produces": [ + "application/json" + ], + "tags": [ + "IsInvoice" + ], + "summary": "鍒犻櫎鏄惁寮�绁�", + "parameters": [ + { + "type": "integer", + "description": "鏌ヨ鍙傛暟", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, + "/api/isInvoice/list": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "IsInvoice" + ], + "summary": "鑾峰彇鏄惁寮�绁ㄥ垪琛�", + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/contextx.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/response.IsInvoiceResponse" + } + } + } + ] + } + } + } + } + }, + "/api/isInvoice/update": { + "put": { + "produces": [ + "application/json" + ], + "tags": [ + "IsInvoice" + ], + "summary": "鏇存柊鏄惁寮�绁�", + "parameters": [ + { + "description": "鏌ヨ鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.UpdateIsInvoices" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, "/api/isVisit/add": { "post": { "produces": [ @@ -6686,6 +6805,17 @@ } } }, + "model.IsInvoice": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, "model.IsVisit": { "type": "object", "properties": { @@ -7902,6 +8032,17 @@ } }, "request.AddIndustry": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string" + } + } + }, + "request.AddIsInvoice": { "type": "object", "required": [ "name" @@ -9603,6 +9744,35 @@ } } }, + "request.UpdateIsInvoice": { + "type": "object", + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, + "request.UpdateIsInvoices": { + "type": "object", + "required": [ + "is_invoice" + ], + "properties": { + "is_invoice": { + "type": "array", + "items": { + "$ref": "#/definitions/request.UpdateIsInvoice" + } + } + } + }, "request.UpdateIsVisit": { "type": "object", "required": [ @@ -10820,6 +10990,13 @@ "$ref": "#/definitions/model.Industry" } }, + "isInvoice": { + "description": "鏄惁寮�绁�", + "type": "array", + "items": { + "$ref": "#/definitions/model.IsInvoice" + } + }, "isVisit": { "description": "鏈嶅姟浜哄憳鏄惁鏉ヨ繃", "type": "array", @@ -10996,6 +11173,17 @@ } } }, + "response.IsInvoiceResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/model.IsInvoice" + } + } + } + }, "response.IsVisitResponse": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index e35ef28..b55b2b0 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -402,6 +402,13 @@ name: type: string type: object + model.IsInvoice: + properties: + id: + type: integer + name: + type: string + type: object model.IsVisit: properties: id: @@ -1211,6 +1218,13 @@ - follow_record type: object request.AddIndustry: + properties: + name: + type: string + required: + - name + type: object + request.AddIsInvoice: properties: name: type: string @@ -2361,6 +2375,25 @@ - id - name type: object + request.UpdateIsInvoice: + properties: + id: + type: integer + name: + type: string + required: + - id + - name + type: object + request.UpdateIsInvoices: + properties: + is_invoice: + items: + $ref: '#/definitions/request.UpdateIsInvoice' + type: array + required: + - is_invoice + type: object request.UpdateIsVisit: properties: id: @@ -3172,6 +3205,11 @@ items: $ref: '#/definitions/model.Industry' type: array + isInvoice: + description: 鏄惁寮�绁� + items: + $ref: '#/definitions/model.IsInvoice' + type: array isVisit: description: 鏈嶅姟浜哄憳鏄惁鏉ヨ繃 items: @@ -3291,6 +3329,13 @@ list: items: $ref: '#/definitions/model.Industry' + type: array + type: object + response.IsInvoiceResponse: + properties: + list: + items: + $ref: '#/definitions/model.IsInvoice' type: array type: object response.IsVisitResponse: @@ -4759,6 +4804,79 @@ summary: 鏇存柊琛屼笟 tags: - Industry + /api/isInvoice/add: + post: + parameters: + - description: 鏌ヨ鍙傛暟 + in: body + name: object + required: true + schema: + $ref: '#/definitions/request.AddIsInvoice' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/contextx.Response' + summary: 娣诲姞鏄惁寮�绁� + tags: + - IsInvoice + /api/isInvoice/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: + - IsInvoice + /api/isInvoice/list: + get: + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/contextx.Response' + - properties: + data: + $ref: '#/definitions/response.IsInvoiceResponse' + type: object + summary: 鑾峰彇鏄惁寮�绁ㄥ垪琛� + tags: + - IsInvoice + /api/isInvoice/update: + put: + parameters: + - description: 鏌ヨ鍙傛暟 + in: body + name: object + required: true + schema: + $ref: '#/definitions/request.UpdateIsInvoices' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/contextx.Response' + summary: 鏇存柊鏄惁寮�绁� + tags: + - IsInvoice /api/isVisit/add: post: parameters: diff --git a/model/index.go b/model/index.go index 5c19858..9a4e4b7 100644 --- a/model/index.go +++ b/model/index.go @@ -73,6 +73,7 @@ ServiceContractStatus{}, ServiceContractType{}, RefundMethod{}, + IsInvoice{}, ) return err } \ No newline at end of file diff --git a/model/isInvoice.go b/model/isInvoice.go new file mode 100644 index 0000000..1c7c293 --- /dev/null +++ b/model/isInvoice.go @@ -0,0 +1,85 @@ +package model + +import ( + "aps_crm/pkg/mysqlx" + "gorm.io/gorm" +) + +type ( + // IsInvoice 鍟嗘満闃舵 + IsInvoice struct { + Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` + Name string `json:"name" gorm:"column:name;type:varchar(255);comment:鍟嗘満闃舵鍚嶇О"` + } + + IsInvoiceSearch struct { + IsInvoice + Orm *gorm.DB + } +) + +func (IsInvoice) TableName() string { + return "is_invoice" +} + +func NewIsInvoiceSearch() *IsInvoiceSearch { + return &IsInvoiceSearch{ + Orm: mysqlx.GetDB(), + } +} + +func (slf *IsInvoiceSearch) build() *gorm.DB { + var db = slf.Orm.Model(&IsInvoice{}) + if slf.Id != 0 { + db = db.Where("id = ?", slf.Id) + } + if slf.Name != "" { + db = db.Where("name = ?", slf.Name) + } + + return db +} + +func (slf *IsInvoiceSearch) Create(record *IsInvoice) error { + var db = slf.build() + return db.Create(record).Error +} + +func (slf *IsInvoiceSearch) Delete() error { + var db = slf.build() + return db.Delete(&IsInvoice{}).Error +} + +func (slf *IsInvoiceSearch) Update(record *IsInvoice) error { + var db = slf.build() + return db.Updates(record).Error +} + +func (slf *IsInvoiceSearch) Find() (*IsInvoice, error) { + var db = slf.build() + var record = new(IsInvoice) + err := db.First(record).Error + return record, err +} + +func (slf *IsInvoiceSearch) FindAll() ([]*IsInvoice, error) { + var db = slf.build() + var records = make([]*IsInvoice, 0) + err := db.Find(&records).Error + return records, err +} + +func (slf *IsInvoiceSearch) SetId(id int) *IsInvoiceSearch { + slf.Id = id + return slf +} + +func (slf *IsInvoiceSearch) SetName(name string) *IsInvoiceSearch { + slf.Name = name + return slf +} + +func (slf *IsInvoiceSearch) Updates(data map[string]interface{}) error { + var db = slf.build() + return db.Updates(data).Error +} diff --git a/model/request/isInvoice.go b/model/request/isInvoice.go new file mode 100644 index 0000000..c36c30b --- /dev/null +++ b/model/request/isInvoice.go @@ -0,0 +1,15 @@ + +package request + +type AddIsInvoice struct { + Name string ` json:"name" binding:"required"` +} + +type UpdateIsInvoice struct { + Id int `json:"id" binding:"required"` + Name string `json:"name" binding:"required"` +} + +type UpdateIsInvoices struct { + IsInvoices []*UpdateIsInvoice `json:"is_invoice" binding:"required"` +} diff --git a/model/response/response.go b/model/response/response.go index 290110c..8fff1d9 100644 --- a/model/response/response.go +++ b/model/response/response.go @@ -180,6 +180,10 @@ DataResponse struct { + // 鏄惁寮�绁� + IsInvoice []*model.IsInvoice `json:"isInvoice"` + + // 閫�娆炬柟寮� RefundMethod []*model.RefundMethod `json:"refundMethod"` @@ -286,4 +290,8 @@ RefundMethodResponse struct { List []*model.RefundMethod `json:"list"` } + + IsInvoiceResponse struct { + List []*model.IsInvoice `json:"list"` + } ) \ No newline at end of file diff --git a/pkg/ecode/code.go b/pkg/ecode/code.go index 0a058bd..c2efed0 100644 --- a/pkg/ecode/code.go +++ b/pkg/ecode/code.go @@ -340,11 +340,16 @@ ServiceContractTypeSetErr = 4900004 // 璁剧疆鏈嶅姟鍚堝悓绫诲瀷澶辫触 ServiceContractTypeUpdateErr = 4900005 // 鏇存柊鏈嶅姟鍚堝悓绫诲瀷澶辫触 - RefundMethodExist = 5000001 // 閫�娆炬柟寮忓凡瀛樺湪 RefundMethodNotExist = 5000002 // 閫�娆炬柟寮忎笉瀛樺湪 RefundMethodListErr = 5000003 // 鑾峰彇閫�娆炬柟寮忓垪琛ㄥけ璐� RefundMethodSetErr = 5000004 // 璁剧疆閫�娆炬柟寮忓け璐� RefundMethodUpdateErr = 5000005 // 鏇存柊閫�娆炬柟寮忓け璐� -) \ No newline at end of file + IsInvoiceExist = 5100001 // 鏄惁寮�绁ㄥ凡瀛樺湪 + IsInvoiceNotExist = 5100002 // 鏄惁寮�绁ㄤ笉瀛樺湪 + IsInvoiceListErr = 5100003 // 鑾峰彇鏄惁寮�绁ㄥ垪琛ㄥけ璐� + IsInvoiceSetErr = 5100004 // 璁剧疆鏄惁寮�绁ㄥけ璐� + IsInvoiceUpdateErr = 5100005 // 鏇存柊鏄惁寮�绁ㄥけ璐� + +) diff --git a/router/index.go b/router/index.go index fff931f..8adce2d 100644 --- a/router/index.go +++ b/router/index.go @@ -11,6 +11,7 @@ ) type Group struct { + IsInvoiceRouter RefundMethodRouter ServiceContractTypeRouter ServiceContractStatusRouter @@ -145,6 +146,7 @@ routerGroup.InitServiceContractStatusRouter(PrivateGroup) routerGroup.InitServiceContractTypeRouter(PrivateGroup) routerGroup.InitRefundMethodRouter(PrivateGroup) + routerGroup.InitIsInvoiceRouter(PrivateGroup) } return Router } \ No newline at end of file diff --git a/router/isInvoice.go b/router/isInvoice.go new file mode 100644 index 0000000..8633134 --- /dev/null +++ b/router/isInvoice.go @@ -0,0 +1,20 @@ + +package router + +import ( + v1 "aps_crm/api/v1" + "github.com/gin-gonic/gin" +) + +type IsInvoiceRouter struct{} + +func (s *IsInvoiceRouter) InitIsInvoiceRouter(router *gin.RouterGroup) { + isInvoiceRouter := router.Group("isInvoice") + isInvoiceApi := v1.ApiGroup.IsInvoiceApi + { + isInvoiceRouter.POST("add", isInvoiceApi.Add) // 娣诲姞$CName$ + isInvoiceRouter.DELETE("delete/:id", isInvoiceApi.Delete) // 鍒犻櫎$CName$ + isInvoiceRouter.PUT("update", isInvoiceApi.Update) // 鏇存柊$CName$ + isInvoiceRouter.GET("list", isInvoiceApi.List) // 鑾峰彇$CName$鍒楄〃 + } +} \ No newline at end of file diff --git a/service/dataServer.go b/service/dataServer.go index 501fd7c..cc1595f 100644 --- a/service/dataServer.go +++ b/service/dataServer.go @@ -121,6 +121,11 @@ data.RefundMethod = refundMethodList + // get IsInvoice list + isInvoiceList, _ := ServiceGroup.GetIsInvoiceList() + data.IsInvoice = isInvoiceList + + errCode = ecode.OK return diff --git a/service/index.go b/service/index.go index d934cc0..84214db 100644 --- a/service/index.go +++ b/service/index.go @@ -54,6 +54,7 @@ ServiceContractStatusService ServiceContractTypeService RefundMethodService + IsInvoiceService } var ServiceGroup = new(Group) \ No newline at end of file diff --git a/service/isInvoice.go b/service/isInvoice.go new file mode 100644 index 0000000..2f8f856 --- /dev/null +++ b/service/isInvoice.go @@ -0,0 +1,69 @@ + +package service + +import ( + "aps_crm/model" + "aps_crm/model/request" + "aps_crm/pkg/ecode" +) + +type IsInvoiceService struct{} + +func (IsInvoiceService) AddIsInvoice(isInvoice *model.IsInvoice) int { + err := model.NewIsInvoiceSearch().Create(isInvoice) + if err != nil { + return ecode.IsInvoiceExist + } + + return ecode.OK +} + +func (IsInvoiceService) DeleteIsInvoice(id int) int { + _, err := model.NewIsInvoiceSearch().SetId(id).Find() + if err != nil { + return ecode.IsInvoiceNotExist + } + + err = model.NewIsInvoiceSearch().SetId(id).Delete() + if err != nil { + return ecode.IsInvoiceNotExist + } + return ecode.OK +} + +func (IsInvoiceService) GetIsInvoiceList() ([]*model.IsInvoice, int) { + list, err := model.NewIsInvoiceSearch().FindAll() + if err != nil { + return nil, ecode.IsInvoiceListErr + } + + return list, ecode.OK +} + +func (IsInvoiceService) UpdateIsInvoice(isInvoices []*request.UpdateIsInvoice) int { + for _, v := range isInvoices { + // check isInvoice exist + _, err := model.NewIsInvoiceSearch().SetId(v.Id).Find() + if err != nil { + return ecode.IsInvoiceNotExist + } + + err = model.NewIsInvoiceSearch().SetId(v.Id).Updates(map[string]interface{}{ + "name": v.Name, + }) + if err != nil { + return ecode.IsInvoiceSetErr + } + } + + return ecode.OK +} + +func (IsInvoiceService) GetIsInvoiceDetail(id int) (*model.IsInvoice, int) { + isInvoice, err := model.NewIsInvoiceSearch().SetId(id).Find() + if err != nil { + return nil, ecode.IsInvoiceNotExist + } + + return isInvoice, ecode.OK +} -- Gitblit v1.8.0