diff --git a/app/admin/apis/basic/cashier.go b/app/admin/apis/basic/cashier.go new file mode 100644 index 0000000..9c46add --- /dev/null +++ b/app/admin/apis/basic/cashier.go @@ -0,0 +1,218 @@ +package basic + +import ( + "errors" + "github.com/gin-gonic/gin" + "go-admin/app/admin/models" + "go-admin/logger" + "go-admin/tools" + "go-admin/tools/app" + "net/http" +) + +type CashierCreateRequest struct { + Name string `json:"name" binding:"required"` // 账号名称 + BankName string `json:"bank_name" binding:"required"` // 银行全称 + BankAccount string `json:"bank_account" binding:"required"` // 银行账号 + StoreNums []uint32 `json:"store_num" binding:"required"` // 门店编号 +} + +// CashierCreate 新增收付款账号 +// @Summary 新增收付款账号 +// @Tags 收付款账号设置 +// @Produce json +// @Accept json +// @Param request body CashierCreateRequest true "新增收付款账号模型" +// @Success 200 {object} app.Response +// @Router /api/v1/cashier/create [post] +func CashierCreate(c *gin.Context) { + var req = new(CashierCreateRequest) + + if err := c.ShouldBindJSON(&req); err != nil { + logger.Errorf("CashierCreate ShouldBindJSON err:", err.Error()) + app.Error(c, http.StatusBadRequest, errors.New("param err"), "参数错误") + return + } + + err := tools.Validate(req) + if err != nil { + app.Error(c, http.StatusBadRequest, err, err.Error()) + return + } + + if len(req.StoreNums) <= 0 { + app.Error(c, http.StatusBadRequest, errors.New("param err"), "有效店铺为空") + return + } + + cashier := &models.ErpCashier{ + Name: req.Name, + BankName: req.BankName, + BankAccount: req.BankAccount, + State: 1, + Remark: "", + } + + err = models.CreateAccount(cashier, req.StoreNums) + if err != nil { + app.Error(c, http.StatusBadRequest, err, err.Error()) + return + } + + app.OK(c, nil, "OK") + return +} + +type CashierEditRequest struct { + CashierId uint32 `json:"cashier_id" binding:"required"` // 账号id + CashierCreateRequest +} + +// CashierEdit 编辑收付款账号 +// @Summary 编辑收付款账号 +// @Tags 收付款账号设置 +// @Produce json +// @Accept json +// @Param request body CashierEditRequest true "编辑收付款账号模型" +// @Success 200 {object} app.Response +// @Router /api/v1/cashier/edit [post] +func CashierEdit(c *gin.Context) { + var req = new(CashierEditRequest) + + if err := c.ShouldBindJSON(&req); err != nil { + logger.Errorf("CashierEdit ShouldBindJSON err:", err.Error()) + app.Error(c, http.StatusBadRequest, errors.New("param err"), "参数错误") + return + } + + err := tools.Validate(req) + if err != nil { + app.Error(c, http.StatusBadRequest, err, err.Error()) + return + } + + if len(req.StoreNums) <= 0 { + app.Error(c, http.StatusBadRequest, errors.New("param err"), "有效店铺为空") + return + } + + cashier := &models.ErpCashier{ + Name: req.Name, + BankName: req.BankName, + BankAccount: req.BankAccount, + State: 1, + Remark: "", + } + cashier.ID = req.CashierId + err = models.UpdateAccount(cashier, req.StoreNums) + if err != nil { + app.Error(c, http.StatusBadRequest, err, err.Error()) + return + } + + app.OK(c, nil, "OK") + return +} + +// CashierDelete 删除收付款账号 +// @Summary 删除收付款账号 +// @Tags 收付款账号设置 +// @Produce json +// @Accept json +// @Param request body CashierDetailRequest true "删除收付款账号模型" +// @Success 200 {object} app.Response +// @Router /api/v1/cashier/delete [post] +func CashierDelete(c *gin.Context) { + var req = new(CashierDetailRequest) + + if err := c.ShouldBindJSON(&req); err != nil { + //logger.Error(err) + app.Error(c, http.StatusBadRequest, errors.New("param err"), "参数错误") + return + } + + err := tools.Validate(req) + if err != nil { + app.Error(c, http.StatusBadRequest, err, err.Error()) + return + } + + err = models.DeleteAccount(req.CashierId) + if err != nil { + app.Error(c, http.StatusBadRequest, err, err.Error()) + return + } + + app.OK(c, nil, "OK") + return +} + +type CashierListRequest struct { + StoreId uint32 `json:"store_id"` // 门店编号 + PageNum int `json:"page_num"` // 页码 + PageSize int `json:"page_size"` // 页条数 +} + +// CashierList 查询收付款账号列表 +// @Summary 查询收付款账号列表 +// @Tags 收付款账号设置 +// @Produce json +// @Accept json +// @Param request body CashierListRequest true "查询收付款账号列表模型" +// @Success 200 {object} models.ErpCashierListResp +// @Router /api/v1/cashier/list [post] +func CashierList(c *gin.Context) { + var req = new(CashierListRequest) + + if err := c.ShouldBindJSON(&req); err != nil { + //logger.Error(err) + app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误") + return + } + + list, err := models.GetAccountList(int(req.StoreId), req.PageSize, req.PageNum) + if err != nil { + app.Error(c, http.StatusBadRequest, err, err.Error()) + return + } + + app.OK(c, list, "OK") + return +} + +type CashierDetailRequest struct { + CashierId uint32 `json:"cashier_id" binding:"required"` // 账号id +} + +// CashierDetail 查询收付款账号详情 +// @Summary 查询收付款账号详情 +// @Tags 收付款账号设置 +// @Produce json +// @Accept json +// @Param request body CashierDetailRequest true "查询收付款账号详情模型" +// @Success 200 {object} models.ErpCashierDetail +// @Router /api/v1/cashier/detail [post] +func CashierDetail(c *gin.Context) { + var req = new(CashierDetailRequest) + + if err := c.ShouldBindJSON(&req); err != nil { + //logger.Error(err) + app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误") + return + } + + err := tools.Validate(req) + if err != nil { + app.Error(c, http.StatusBadRequest, err, err.Error()) + return + } + + list, err := models.GetAccountDetail(int(req.CashierId)) + if err != nil { + app.Error(c, http.StatusBadRequest, err, err.Error()) + return + } + + app.OK(c, list, "OK") + return +} diff --git a/app/admin/models/cashier.go b/app/admin/models/cashier.go new file mode 100644 index 0000000..6a878b8 --- /dev/null +++ b/app/admin/models/cashier.go @@ -0,0 +1,331 @@ +package models + +import ( + "errors" + "fmt" + orm "go-admin/common/global" +) + +//go:generate goqueryset -in cashier.go + +// ErpCashier 账号表 +type ErpCashier struct { + Model + + Name string `json:"name" gorm:"type:varchar(512)"` // 账号名称 + BankName string `json:"bank_name" gorm:"type:varchar(512)"` // 银行全称 + BankAccount string `json:"bank_account" gorm:"type:varchar(512)"` // 银行账号 + State uint32 `json:"state"` // 状态:1-使用 2-未用 + Remark string `json:"remark" gorm:"type:varchar(512)"` // 备注 + Type uint32 `json:"type"` // +} + +type ErpStoreCashier struct { + Model + + ErpCashierId uint32 `json:"erp_cashier_id" gorm:"index"` // 账号id + Name string `json:"name" gorm:"type:varchar(512)"` // 账号名称 + BankName string `json:"bank_name" gorm:"type:varchar(512)"` // 银行全称 + BankAccount string `json:"bank_account" gorm:"type:varchar(512)"` // 银行账号 + StoreId uint32 `json:"store_id" gorm:"index"` // 门店id + StoreName string `json:"store_name"` // 门店名称 + State uint32 `json:"state"` // 状态:1-使用 2-未用 + Remark string `json:"remark" gorm:"type:varchar(512)"` // 备注 +} + +// CashierStore 账号关联的门店信息 +type CashierStore struct { + StoreId uint32 `json:"store_id" gorm:"index"` // 门店id + StoreName string `json:"store_name"` // 门店名称 +} + +// ErpCashierList 账号信息 +type ErpCashierDetail struct { + ErpCashier // 账号表信息 + StoreList []CashierStore `json:"store_list"` // 账号关联的门店信息 +} + +type ErpCashierListResp struct { + Total int `json:"total"` + PageNum int `json:"page_num"` + PageSize int `json:"page_size"` + List []ErpCashier `json:"list"` +} + +// CreateAccount 创建账号 +func CreateAccount(req *ErpCashier, storeNums []uint32) error { + exist, err := QueryRecordExist(fmt.Sprintf("SELECT * FROM erp_cashier WHERE `name`='%s'", req.Name)) + if err != nil { + return fmt.Errorf("创建失败[QueryRecordExist err]:%v", err) + } + + if exist { + return errors.New("创建失败,账号名称重复") + } + + // 新建账号,并绑定有效店铺 + cashier := &ErpCashier{ + Name: req.Name, + BankName: req.BankName, + BankAccount: req.BankAccount, + State: 1, + Remark: "", + } + begin := orm.Eloquent.Begin() + if err = begin.Create(cashier).Error; err != nil { + return fmt.Errorf("创建失败[create cashier err]:%v", err) + } + + var stores []Store + err = orm.Eloquent.Table("store").Where("id IN (?)", storeNums).Find(&stores).Error + if err != nil { + return fmt.Errorf("创建失败[query store err]:%v", err) + } + + storeMap := make(map[uint32]string, len(stores)) + for i, _ := range stores { + storeMap[stores[i].ID] = stores[i].Name + } + for i, _ := range storeNums { + v, ok := storeMap[storeNums[i]] + + storeCategory := &ErpStoreCashier{ + ErpCashierId: cashier.ID, + Name: req.Name, + BankName: req.BankName, + BankAccount: req.BankAccount, + StoreId: storeNums[i], + State: 1, + Remark: "", + } + if ok { + storeCategory.StoreName = v + } + err := begin.Create(storeCategory).Error + if err != nil { + begin.Rollback() + return fmt.Errorf("创建失败[create store err]:%v", err) + } + } + err = begin.Commit().Error + if err != nil { + begin.Rollback() + return fmt.Errorf("创建失败[commit err]:%v", err) + } + + return nil +} + +// UpdateAccount 更新账号 +func UpdateAccount(req *ErpCashier, storeNums []uint32) error { + exist, err := QueryRecordExist(fmt.Sprintf("SELECT * FROM erp_cashier WHERE `name`='%s'", req.Name)) + if err != nil { + return fmt.Errorf("更新失败[QueryRecordExist err]:%v", err) + } + if !exist { + return errors.New("更新失败,账号不存在") + } + + tx := orm.Eloquent.Begin() + // 更新账号信息 + cashier := &ErpCashier{ + Name: req.Name, + BankName: req.BankName, + BankAccount: req.BankAccount, + State: 1, + } + if err := tx.Model(&ErpCashier{}).Where("id=?", req.ID).Updates(cashier).Error; err != nil { + tx.Rollback() + return fmt.Errorf("更新失败[update cashier err]:%v", err) + } + + // 更新账号关联的门店信息 + var stores []ErpStoreCashier + if err := tx.Model(&ErpStoreCashier{}).Where("erp_cashier_id=?", req.ID).Find(&stores).Error; err != nil { + tx.Rollback() + return fmt.Errorf("更新失败[query store_cashier err]:%v", err) + } + + matchedStoreIDs := make(map[uint32]bool) // 用于记录storeNums中已经匹配的门店ID + for i := range stores { + store := &stores[i] + store.Name = req.Name + store.BankName = req.BankName + store.BankAccount = req.BankAccount + + if containsStore(storeNums, store.StoreId) { // 更新门店状态 + store.State = 1 // 使用 + matchedStoreIDs[store.StoreId] = true + } else { + store.State = 2 // 未使用 + } + + if err := tx.Model(&ErpStoreCashier{}).Where("id = ?", store.ID).Updates(store).Error; err != nil { + tx.Rollback() + return fmt.Errorf("更新失败[update store err]:%v", err) + } + } + + // 处理storeNums中存在但在数据库中不存在的门店 + for _, v := range storeNums { + if _, exists := matchedStoreIDs[v]; !exists { + storeInfo := &Store{} + if err := tx.Table("store").Where("id = ?", v).First(storeInfo).Error; err != nil { + tx.Rollback() + return fmt.Errorf("更新失败[query store err]:%v", err) + } + // 新增门店数据 + newStore := ErpStoreCashier{ + StoreName: storeInfo.Name, + ErpCashierId: req.ID, + StoreId: v, + Name: req.Name, + BankName: req.BankName, + BankAccount: req.BankAccount, + State: 1, // 使用 + } + if err := tx.Create(&newStore).Error; err != nil { + tx.Rollback() + return fmt.Errorf("新增失败[create store err]:%v", err) + } + } + } + + if err := tx.Commit().Error; err != nil { + tx.Rollback() + return fmt.Errorf("更新失败[commit err]:%v", err) + } + return nil +} + +// containsStore 检查门店是否在切片中 +func containsStore(storeNums []uint32, storeID uint32) bool { + for _, v := range storeNums { + if v == storeID { + return true + } + } + return false +} + +// DeleteAccount 删除账号 +func DeleteAccount(cashierId uint32) error { + // 删除账号信息 + cashier := &ErpCashier{} + cashier.ID = cashierId + tx := orm.Eloquent.Begin() + if err := orm.Eloquent.Delete(cashier).Error; err != nil { + tx.Rollback() + return fmt.Errorf("删除失败[create cashier err]:%v", err) + } + + // 更新账号关联的门店信息 + var stores []ErpStoreCashier + err := orm.Eloquent.Table("erp_store_cashier").Where("erp_cashier_id=?", cashierId).Find(&stores).Error + if err != nil { + return fmt.Errorf("删除失败[query store_cashier err]:%v", err) + } + + err = orm.Eloquent.Delete(stores).Error + if err != nil { + tx.Rollback() + return fmt.Errorf("删除失败[delete store err]:%v", err) + } + + err = tx.Commit().Error + if err != nil { + tx.Rollback() + return fmt.Errorf("删除失败[commit err]:%v", err) + } + + return nil +} + +// GetAccountList 查询账号列表 +func GetAccountList(storeId, pageSize, pageNum int) (*ErpCashierListResp, error) { + resp := ErpCashierListResp{ + PageNum: pageNum, + PageSize: pageSize, + } + + page := pageNum - 1 + if page < 0 { + page = 0 + } + if pageSize == 0 { + pageSize = 10 + } + + qs := orm.Eloquent + if storeId == 0 { // 只查询账号信息 + qs = orm.Eloquent.Table("erp_cashier") + } else { // 查询账号信息及其关联的门店 + qs = orm.Eloquent.Table("erp_store_cashier").Where("store_id=? and state = 1", storeId) + } + + var count int64 + err := qs.Count(&count).Error + if err != nil { + return nil, fmt.Errorf("query count err:%v", err) + } + offset := page * pageSize + limit := pageSize + + resp.Total = int(count)/pageSize + 1 + var categories []ErpCashier + + if storeId == 0 { // 只查询账号信息 + err = qs.Order("id DESC").Offset(offset).Limit(limit).Find(&categories).Error + } else { // 查询账号信息及其关联的门店 + var storeCashiers []ErpStoreCashier + err = qs.Order("erp_cashier_id DESC").Offset(offset).Limit(limit).Find(&storeCashiers).Error + for _, v := range storeCashiers { + temp := ErpCashier{ + Name: v.Name, + BankName: v.BankName, + BankAccount: v.BankAccount, + State: v.State, + } + temp.Model.ID = v.ErpCashierId + categories = append(categories, temp) + } + } + + if err != nil && !errors.Is(err, RecordNotFound) { + //logger.Error("erp commodity list err:", err) + return nil, fmt.Errorf("query err:%v", err) + } + + resp.List = categories + return &resp, nil +} + +// GetAccountDetail 查询账号详情 +func GetAccountDetail(cashierId int) (*ErpCashierDetail, error) { + // 查账号信息 + var cashier ErpCashier + err := orm.Eloquent.Table("erp_cashier").Where("id=?", cashierId).First(&cashier).Error + if err != nil { + return nil, fmt.Errorf("erp_cashier query err:%v", err) + } + + // 查账号关联的门店信息 + var storeCashiers []ErpStoreCashier + err = orm.Eloquent.Table("erp_store_cashier"). + Where("erp_cashier_id =? and state=1", cashierId).Find(&storeCashiers).Error + if err != nil { + return nil, fmt.Errorf("erp_store_cashier query err:%v", err) + } + + var storeList []CashierStore + for _, v := range storeCashiers { + tmp := CashierStore{ + StoreId: v.StoreId, + StoreName: v.StoreName, + } + storeList = append(storeList, tmp) + } + + resp := ErpCashierDetail{cashier, storeList} + return &resp, nil +} diff --git a/app/admin/models/file.go b/app/admin/models/file.go index 7e17b26..00ed70e 100644 --- a/app/admin/models/file.go +++ b/app/admin/models/file.go @@ -58,7 +58,7 @@ func getJSONTagNames(s interface{}) []string { return tagNames } -// 预览excel数据(不做必填项校验) +// FileExcelReader 预览excel数据(不做必填项校验) func FileExcelReader(d []byte, cols []string) ([]byte, []map[string]interface{}, error) { reader, err := excelize.OpenReader(bytes.NewReader(d)) if err != nil { @@ -128,8 +128,8 @@ func FileExcelReader(d []byte, cols []string) ([]byte, []map[string]interface{}, return mCols, colsMap, nil } -// 导入excel数据(校验必填项) -func FileExcelImport(d []byte, cols []string, ntype int) ([]byte, []map[string]interface{}, error) { +// FileExcelImport 导入excel数据(校验必填项) +func FileExcelImport(d []byte, cols []string, nType int) ([]byte, []map[string]interface{}, error) { reader, err := excelize.OpenReader(bytes.NewReader(d)) if err != nil { return nil, nil, fmt.Errorf("open reader error: %v", err) @@ -156,7 +156,7 @@ func FileExcelImport(d []byte, cols []string, ntype int) ([]byte, []map[string]i var colsMap []map[string]interface{} if len(cols) == 0 { - switch ntype { // 导入类型:1 商品分类 2 商品资料 + switch nType { // 导入类型:1 商品分类 2 商品资料 case 1: if sheetList[0] != "导分类" { return nil, nil, errors.New("格式错误,不是分类模版excel") @@ -305,7 +305,7 @@ func transCategoryData(colsMap []map[string]interface{}) []CategoryExcel { return categories } -// 导入商品分类到数据库 +// ImportCategoryData 导入商品分类到数据库 // 规则:分类只有3级,所有分类不允许名称完全相同 func ImportCategoryData(colsMap []map[string]interface{}, businessId uint32) error { data := transCategoryData(colsMap) @@ -394,7 +394,7 @@ func isCategoryExists(categoryName string) bool { return count > 0 } -// 导入商品资料 +// ImportCommodityData 导入商品资料 func ImportCommodityData(colsMap []map[string]interface{}, businessId uint32) error { data, err := transCommodityData(colsMap) if err != nil { @@ -586,7 +586,7 @@ func getNumberOnCategory(categoryId uint32) int64 { return count } -// 生成商品编号 +// GenerateSerialNumber 生成商品编号 func GenerateSerialNumber(categoryId uint32) (string, error) { var category Category err := orm.Eloquent.Debug().Model(&Category{}). diff --git a/app/admin/models/store.go b/app/admin/models/store.go index cc717da..a496208 100644 --- a/app/admin/models/store.go +++ b/app/admin/models/store.go @@ -22,7 +22,7 @@ type Store struct { IsOnline uint32 `json:"is_online"` // 在线 CooperativeBusinessId uint32 `json:"cooperative_business_id" gorm:"index"` // 合作商id CooperativeName string `json:"cooperative_name"` // 合作商名称 - GameCardGoods + //GameCardGoods CooperativeAssistantMemberDeduct *CooperativeAssistantMemberDeduct `json:"cooperative_assistant_member_deduct" gorm:"-"` } diff --git a/app/admin/router/cashier.go b/app/admin/router/cashier.go new file mode 100644 index 0000000..86153ed --- /dev/null +++ b/app/admin/router/cashier.go @@ -0,0 +1,17 @@ +package router + +import ( + "github.com/gin-gonic/gin" + "go-admin/app/admin/apis/basic" + "go-admin/app/admin/middleware" + jwt "go-admin/pkg/jwtauth" +) + +func registerCashierRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { + r := v1.Group("/cashier").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole()) + r.POST("create", basic.CashierCreate) + r.POST("edit", basic.CashierEdit) + r.POST("delete", basic.CashierDelete) + r.POST("list", basic.CashierList) + r.POST("detail", basic.CashierDetail) +} diff --git a/app/admin/router/router.go b/app/admin/router/router.go index 9e46087..9dcfe40 100644 --- a/app/admin/router/router.go +++ b/app/admin/router/router.go @@ -100,4 +100,6 @@ func examplesCheckRoleRouter(r *gin.Engine, authMiddleware *jwtauth.GinJWTMiddle registerCategoryRouter(v1, authMiddleware) //商品资料 registerCommodityRouter(v1, authMiddleware) + //收付款账号设置 + registerCashierRouter(v1, authMiddleware) } diff --git a/cmd/cobra.go b/cmd/cobra.go index 865d2ab..5ab9650 100644 --- a/cmd/cobra.go +++ b/cmd/cobra.go @@ -23,7 +23,7 @@ var rootCmd = &cobra.Command{ Args: func(cmd *cobra.Command, args []string) error { if len(args) < 1 { tip() - return errors.New(tools.Red("requires at least one arg")) + return errors.New(tools.Red("requires at least one arg")) } return nil }, @@ -34,8 +34,6 @@ var rootCmd = &cobra.Command{ } func tip() { - - usageStr := `欢迎使用 ` + tools.Green(`go-admin `+global.Version) + ` 可以使用 ` + tools.Red(`-h`) + ` 查看命令` usageStr1 := `也可以参考 http://doc.zhangwj.com/go-admin-site/guide/ksks.html 里边的【启动】章节` @@ -52,7 +50,7 @@ func init() { rootCmd.AddCommand(config.StartCmd) } -//Execute : apply commands +// Execute : apply commands func Execute() { if err := rootCmd.Execute(); err != nil { os.Exit(-1) diff --git a/docs/docs.go b/docs/docs.go index a90ddd8..cfe06c9 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -19,6 +19,171 @@ const docTemplate = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { + "/api/v1/cashier/create": { + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "收付款账号设置" + ], + "summary": "新增收付款账号", + "parameters": [ + { + "description": "新增收付款账号模型", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/basic.CashierCreateRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/app.Response" + } + } + } + } + }, + "/api/v1/cashier/delete": { + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "收付款账号设置" + ], + "summary": "删除收付款账号", + "parameters": [ + { + "description": "删除收付款账号模型", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/basic.CashierDetailRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/app.Response" + } + } + } + } + }, + "/api/v1/cashier/detail": { + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "收付款账号设置" + ], + "summary": "查询收付款账号详情", + "parameters": [ + { + "description": "查询收付款账号详情模型", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/basic.CashierDetailRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.ErpCashierDetail" + } + } + } + } + }, + "/api/v1/cashier/edit": { + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "收付款账号设置" + ], + "summary": "编辑收付款账号", + "parameters": [ + { + "description": "编辑收付款账号模型", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/basic.CashierEditRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/app.Response" + } + } + } + } + }, + "/api/v1/cashier/list": { + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "收付款账号设置" + ], + "summary": "查询收付款账号列表", + "parameters": [ + { + "description": "查询收付款账号列表模型", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/basic.CashierListRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.ErpCashierListResp" + } + } + } + } + }, "/api/v1/category/create": { "post": { "consumes": [ @@ -3131,10 +3296,105 @@ const docTemplate = `{ "type": "string" }, "requestId": { + "description": "请求id", "type": "string" } } }, + "basic.CashierCreateRequest": { + "type": "object", + "required": [ + "bank_account", + "bank_name", + "name", + "store_num" + ], + "properties": { + "bank_account": { + "description": "银行账号", + "type": "string" + }, + "bank_name": { + "description": "银行全称", + "type": "string" + }, + "name": { + "description": "账号名称", + "type": "string" + }, + "store_num": { + "description": "门店编号", + "type": "array", + "items": { + "type": "integer" + } + } + } + }, + "basic.CashierDetailRequest": { + "type": "object", + "required": [ + "cashier_id" + ], + "properties": { + "cashier_id": { + "description": "账号id", + "type": "integer" + } + } + }, + "basic.CashierEditRequest": { + "type": "object", + "required": [ + "bank_account", + "bank_name", + "cashier_id", + "name", + "store_num" + ], + "properties": { + "bank_account": { + "description": "银行账号", + "type": "string" + }, + "bank_name": { + "description": "银行全称", + "type": "string" + }, + "cashier_id": { + "description": "账号id", + "type": "integer" + }, + "name": { + "description": "账号名称", + "type": "string" + }, + "store_num": { + "description": "门店编号", + "type": "array", + "items": { + "type": "integer" + } + } + } + }, + "basic.CashierListRequest": { + "type": "object", + "properties": { + "page_num": { + "description": "页码", + "type": "integer" + }, + "page_size": { + "description": "页条数", + "type": "integer" + }, + "store_id": { + "description": "门店编号", + "type": "integer" + } + } + }, "basic.CategoryDisplayRequest": { "type": "object", "properties": { @@ -3541,6 +3801,19 @@ const docTemplate = `{ } } }, + "models.CashierStore": { + "type": "object", + "properties": { + "store_id": { + "description": "门店id", + "type": "integer" + }, + "store_name": { + "description": "门店名称", + "type": "string" + } + } + }, "models.Category": { "type": "object", "properties": { @@ -3759,6 +4032,105 @@ const docTemplate = `{ } } }, + "models.ErpCashier": { + "type": "object", + "properties": { + "bank_account": { + "description": "银行账号", + "type": "string" + }, + "bank_name": { + "description": "银行全称", + "type": "string" + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "id": { + "description": "数据库记录编号", + "type": "integer" + }, + "name": { + "description": "账号名称", + "type": "string" + }, + "remark": { + "description": "备注", + "type": "string" + }, + "state": { + "description": "状态:1-使用 2-未用", + "type": "integer" + }, + "type": { + "type": "integer" + } + } + }, + "models.ErpCashierDetail": { + "type": "object", + "properties": { + "bank_account": { + "description": "银行账号", + "type": "string" + }, + "bank_name": { + "description": "银行全称", + "type": "string" + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "id": { + "description": "数据库记录编号", + "type": "integer" + }, + "name": { + "description": "账号名称", + "type": "string" + }, + "remark": { + "description": "备注", + "type": "string" + }, + "state": { + "description": "状态:1-使用 2-未用", + "type": "integer" + }, + "store_list": { + "description": "账号关联的门店信息", + "type": "array", + "items": { + "$ref": "#/definitions/models.CashierStore" + } + }, + "type": { + "type": "integer" + } + } + }, + "models.ErpCashierListResp": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/models.ErpCashier" + } + }, + "page_num": { + "type": "integer" + }, + "page_size": { + "type": "integer" + }, + "total": { + "type": "integer" + } + } + }, "models.ErpCategory": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index a857c8b..89cf7a6 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -11,6 +11,171 @@ "version": "1.0.1" }, "paths": { + "/api/v1/cashier/create": { + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "收付款账号设置" + ], + "summary": "新增收付款账号", + "parameters": [ + { + "description": "新增收付款账号模型", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/basic.CashierCreateRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/app.Response" + } + } + } + } + }, + "/api/v1/cashier/delete": { + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "收付款账号设置" + ], + "summary": "删除收付款账号", + "parameters": [ + { + "description": "删除收付款账号模型", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/basic.CashierDetailRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/app.Response" + } + } + } + } + }, + "/api/v1/cashier/detail": { + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "收付款账号设置" + ], + "summary": "查询收付款账号详情", + "parameters": [ + { + "description": "查询收付款账号详情模型", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/basic.CashierDetailRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.ErpCashierDetail" + } + } + } + } + }, + "/api/v1/cashier/edit": { + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "收付款账号设置" + ], + "summary": "编辑收付款账号", + "parameters": [ + { + "description": "编辑收付款账号模型", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/basic.CashierEditRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/app.Response" + } + } + } + } + }, + "/api/v1/cashier/list": { + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "收付款账号设置" + ], + "summary": "查询收付款账号列表", + "parameters": [ + { + "description": "查询收付款账号列表模型", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/basic.CashierListRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.ErpCashierListResp" + } + } + } + } + }, "/api/v1/category/create": { "post": { "consumes": [ @@ -3123,10 +3288,105 @@ "type": "string" }, "requestId": { + "description": "请求id", "type": "string" } } }, + "basic.CashierCreateRequest": { + "type": "object", + "required": [ + "bank_account", + "bank_name", + "name", + "store_num" + ], + "properties": { + "bank_account": { + "description": "银行账号", + "type": "string" + }, + "bank_name": { + "description": "银行全称", + "type": "string" + }, + "name": { + "description": "账号名称", + "type": "string" + }, + "store_num": { + "description": "门店编号", + "type": "array", + "items": { + "type": "integer" + } + } + } + }, + "basic.CashierDetailRequest": { + "type": "object", + "required": [ + "cashier_id" + ], + "properties": { + "cashier_id": { + "description": "账号id", + "type": "integer" + } + } + }, + "basic.CashierEditRequest": { + "type": "object", + "required": [ + "bank_account", + "bank_name", + "cashier_id", + "name", + "store_num" + ], + "properties": { + "bank_account": { + "description": "银行账号", + "type": "string" + }, + "bank_name": { + "description": "银行全称", + "type": "string" + }, + "cashier_id": { + "description": "账号id", + "type": "integer" + }, + "name": { + "description": "账号名称", + "type": "string" + }, + "store_num": { + "description": "门店编号", + "type": "array", + "items": { + "type": "integer" + } + } + } + }, + "basic.CashierListRequest": { + "type": "object", + "properties": { + "page_num": { + "description": "页码", + "type": "integer" + }, + "page_size": { + "description": "页条数", + "type": "integer" + }, + "store_id": { + "description": "门店编号", + "type": "integer" + } + } + }, "basic.CategoryDisplayRequest": { "type": "object", "properties": { @@ -3533,6 +3793,19 @@ } } }, + "models.CashierStore": { + "type": "object", + "properties": { + "store_id": { + "description": "门店id", + "type": "integer" + }, + "store_name": { + "description": "门店名称", + "type": "string" + } + } + }, "models.Category": { "type": "object", "properties": { @@ -3751,6 +4024,105 @@ } } }, + "models.ErpCashier": { + "type": "object", + "properties": { + "bank_account": { + "description": "银行账号", + "type": "string" + }, + "bank_name": { + "description": "银行全称", + "type": "string" + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "id": { + "description": "数据库记录编号", + "type": "integer" + }, + "name": { + "description": "账号名称", + "type": "string" + }, + "remark": { + "description": "备注", + "type": "string" + }, + "state": { + "description": "状态:1-使用 2-未用", + "type": "integer" + }, + "type": { + "type": "integer" + } + } + }, + "models.ErpCashierDetail": { + "type": "object", + "properties": { + "bank_account": { + "description": "银行账号", + "type": "string" + }, + "bank_name": { + "description": "银行全称", + "type": "string" + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "id": { + "description": "数据库记录编号", + "type": "integer" + }, + "name": { + "description": "账号名称", + "type": "string" + }, + "remark": { + "description": "备注", + "type": "string" + }, + "state": { + "description": "状态:1-使用 2-未用", + "type": "integer" + }, + "store_list": { + "description": "账号关联的门店信息", + "type": "array", + "items": { + "$ref": "#/definitions/models.CashierStore" + } + }, + "type": { + "type": "integer" + } + } + }, + "models.ErpCashierListResp": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/models.ErpCashier" + } + }, + "page_num": { + "type": "integer" + }, + "page_size": { + "type": "integer" + }, + "total": { + "type": "integer" + } + } + }, "models.ErpCategory": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 7ff2f37..135ca13 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -21,8 +21,77 @@ definitions: description: 消息 type: string requestId: + description: 请求id type: string type: object + basic.CashierCreateRequest: + properties: + bank_account: + description: 银行账号 + type: string + bank_name: + description: 银行全称 + type: string + name: + description: 账号名称 + type: string + store_num: + description: 门店编号 + items: + type: integer + type: array + required: + - bank_account + - bank_name + - name + - store_num + type: object + basic.CashierDetailRequest: + properties: + cashier_id: + description: 账号id + type: integer + required: + - cashier_id + type: object + basic.CashierEditRequest: + properties: + bank_account: + description: 银行账号 + type: string + bank_name: + description: 银行全称 + type: string + cashier_id: + description: 账号id + type: integer + name: + description: 账号名称 + type: string + store_num: + description: 门店编号 + items: + type: integer + type: array + required: + - bank_account + - bank_name + - cashier_id + - name + - store_num + type: object + basic.CashierListRequest: + properties: + page_num: + description: 页码 + type: integer + page_size: + description: 页条数 + type: integer + store_id: + description: 门店编号 + type: integer + type: object basic.CategoryDisplayRequest: properties: display: @@ -325,6 +394,15 @@ definitions: - id - name type: object + models.CashierStore: + properties: + store_id: + description: 门店id + type: integer + store_name: + description: 门店名称 + type: string + type: object models.Category: properties: cooperative_business_id: @@ -486,6 +564,76 @@ definitions: description: 更新时间 type: string type: object + models.ErpCashier: + properties: + bank_account: + description: 银行账号 + type: string + bank_name: + description: 银行全称 + type: string + createdAt: + description: 创建时间 + type: string + id: + description: 数据库记录编号 + type: integer + name: + description: 账号名称 + type: string + remark: + description: 备注 + type: string + state: + description: 状态:1-使用 2-未用 + type: integer + type: + type: integer + type: object + models.ErpCashierDetail: + properties: + bank_account: + description: 银行账号 + type: string + bank_name: + description: 银行全称 + type: string + createdAt: + description: 创建时间 + type: string + id: + description: 数据库记录编号 + type: integer + name: + description: 账号名称 + type: string + remark: + description: 备注 + type: string + state: + description: 状态:1-使用 2-未用 + type: integer + store_list: + description: 账号关联的门店信息 + items: + $ref: '#/definitions/models.CashierStore' + type: array + type: + type: integer + type: object + models.ErpCashierListResp: + properties: + list: + items: + $ref: '#/definitions/models.ErpCashier' + type: array + page_num: + type: integer + page_size: + type: integer + total: + type: integer + type: object models.ErpCategory: properties: createdAt: @@ -1466,6 +1614,111 @@ info: title: go-admin API version: 1.0.1 paths: + /api/v1/cashier/create: + post: + consumes: + - application/json + parameters: + - description: 新增收付款账号模型 + in: body + name: request + required: true + schema: + $ref: '#/definitions/basic.CashierCreateRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/app.Response' + summary: 新增收付款账号 + tags: + - 收付款账号设置 + /api/v1/cashier/delete: + post: + consumes: + - application/json + parameters: + - description: 删除收付款账号模型 + in: body + name: request + required: true + schema: + $ref: '#/definitions/basic.CashierDetailRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/app.Response' + summary: 删除收付款账号 + tags: + - 收付款账号设置 + /api/v1/cashier/detail: + post: + consumes: + - application/json + parameters: + - description: 查询收付款账号详情模型 + in: body + name: request + required: true + schema: + $ref: '#/definitions/basic.CashierDetailRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/models.ErpCashierDetail' + summary: 查询收付款账号详情 + tags: + - 收付款账号设置 + /api/v1/cashier/edit: + post: + consumes: + - application/json + parameters: + - description: 编辑收付款账号模型 + in: body + name: request + required: true + schema: + $ref: '#/definitions/basic.CashierEditRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/app.Response' + summary: 编辑收付款账号 + tags: + - 收付款账号设置 + /api/v1/cashier/list: + post: + consumes: + - application/json + parameters: + - description: 查询收付款账号列表模型 + in: body + name: request + required: true + schema: + $ref: '#/definitions/basic.CashierListRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/models.ErpCashierListResp' + summary: 查询收付款账号列表 + tags: + - 收付款账号设置 /api/v1/category/create: post: consumes: diff --git a/logger/logx.go b/logger/logx.go index 98f44c9..21d5115 100644 --- a/logger/logx.go +++ b/logger/logx.go @@ -33,6 +33,8 @@ func init() { // 设置最低loglevel l.SetLevel(logrus.DebugLevel) + + l.SetReportCaller(true) } func WithContext(ctx context.Context) { diff --git a/main.go b/main.go index 1ce5f4f..b6d72c5 100644 --- a/main.go +++ b/main.go @@ -4,70 +4,6 @@ import ( "go-admin/cmd" ) -// @title go-admin API -// @version 1.0.1 -// @description 基于Gin + Vue + Element UI的前后端分离权限管理系统的接口文档 -// @description 添加qq群: 74520518 进入技术交流群 请备注,谢谢! -// @license.name MIT -// @license.url https://github.com/wenjianzhang/go-admin/blob/master/LICENSE.md - -// @securityDefinitions.apikey Bearer -// @in header -// @name Authorization - -//func main() { -// configName := "settings" -// -// -// config.InitConfig(configName) -// -// gin.SetMode(gin.DebugMode) -// log.Println(config.DatabaseConfig.Port) -// -// err := gorm.AutoMigrate(orm.Eloquent) -// if err != nil { -// log.Fatalln("数据库初始化失败 err: %v", err) -// } -// -// if config.ApplicationConfig.IsInit { -// if err := models.InitDb(); err != nil { -// log.Fatal("数据库基础数据初始化失败!") -// } else { -// config.SetApplicationIsInit() -// } -// } -// -// r := router.InitRouter() -// -// defer orm.Eloquent.Close() -// -// srv := &http.Server{ -// Addr: config.ApplicationConfig.Host + ":" + config.ApplicationConfig.Port, -// Handler: r, -// } -// -// go func() { -// // 服务连接 -// if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { -// log.Fatalf("listen: %s\n", err) -// } -// }() -// log.Println("Server Run ", config.ApplicationConfig.Host+":"+config.ApplicationConfig.Port) -// log.Println("Enter Control + C Shutdown Server") -// // 等待中断信号以优雅地关闭服务器(设置 5 秒的超时时间) -// quit := make(chan os.Signal) -// signal.Notify(quit, os.Interrupt) -// <-quit -// log.Println("Shutdown Server ...") -// -// ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) -// defer cancel() -// if err := srv.Shutdown(ctx); err != nil { -// log.Fatal("Server Shutdown:", err) -// } -// log.Println("Server exiting") -//} - func main() { cmd.Execute() } diff --git a/tools/app/model.go b/tools/app/model.go index 0f88de4..0d08411 100644 --- a/tools/app/model.go +++ b/tools/app/model.go @@ -1,13 +1,10 @@ package app type Response struct { - // 代码 - Code int `json:"code" example:"200"` - // 数据集 - Data interface{} `json:"data"` - // 消息 - Msg string `json:"msg"` - RequestId string `json:"requestId"` + Code int `json:"code" example:"200"` // 代码 + Data interface{} `json:"data"` // 数据集 + Msg string `json:"msg"` // 消息 + RequestId string `json:"requestId"` // 请求id } type Page struct {