diff --git a/app/admin/apis/storemanage/store.go b/app/admin/apis/storemanage/store.go index bba0f61..595d81f 100644 --- a/app/admin/apis/storemanage/store.go +++ b/app/admin/apis/storemanage/store.go @@ -63,6 +63,14 @@ func StoreDel(c *gin.Context) { app.OK(c, nil, "删除成功") } +// StoreAdd 新增门店 +// @Summary 新增门店 +// @Tags 门店管理 +// @Produce json +// @Accept json +// @Param request body models.Store true "新增门店模型" +// @Success 200 {object} app.Response +// @Router /api/v1/store/add [post] func StoreAdd(c *gin.Context) { store := &models.Store{} if c.ShouldBindJSON(store) != nil { diff --git a/app/admin/models/store.go b/app/admin/models/store.go index a496208..71a3841 100644 --- a/app/admin/models/store.go +++ b/app/admin/models/store.go @@ -22,6 +22,8 @@ type Store struct { IsOnline uint32 `json:"is_online"` // 在线 CooperativeBusinessId uint32 `json:"cooperative_business_id" gorm:"index"` // 合作商id CooperativeName string `json:"cooperative_name"` // 合作商名称 + MemberService uint32 `json:"member_service"` // 会员服务:1 开启 2 不开启 + SalesCommRate float64 `json:"sales_comm_rate"` // 门店销售提成比例 //GameCardGoods CooperativeAssistantMemberDeduct *CooperativeAssistantMemberDeduct `json:"cooperative_assistant_member_deduct" gorm:"-"` } diff --git a/config/settings.yml b/config/settings.yml index fd75b4f..6225b41 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -40,7 +40,7 @@ settings: # 数据库类型 mysql,sqlite3, postgres driver: mysql # 数据库连接字符串 mysql 缺省信息 charset=utf8&parseTime=True&loc=Local&timeout=1000ms - source: mh_dev:m5h4parZsXjbeiFh@tcp(39.108.188.218:3306)/mh_dev?charset=utf8&parseTime=True&loc=Local&timeout=1000ms + source: mh_dev:d9qy46ONI0ZTF9eH@tcp(39.108.188.218:3306)/mh_dev?charset=utf8&parseTime=True&loc=Local&timeout=1000ms # source: mh_pro:fLeytnBFCRB553ab@tcp(39.108.188.218:3306)/mh_pro?charset=utf8&parseTime=True&loc=Local&timeout=1000ms gen: diff --git a/docs/docs.go b/docs/docs.go index 693cfb9..d768526 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -2745,6 +2745,39 @@ const docTemplate = `{ } } }, + "/api/v1/store/add": { + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "门店管理" + ], + "summary": "新增门店", + "parameters": [ + { + "description": "新增门店模型", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.Store" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/app.Response" + } + } + } + } + }, "/api/v1/supplier/create": { "post": { "consumes": [ @@ -4249,6 +4282,49 @@ const docTemplate = `{ } } }, + "models.CooperativeAssistantMemberDeduct": { + "type": "object", + "properties": { + "black_gold_deduct": { + "description": "黑金金会员提成", + "type": "integer" + }, + "cooperative_business_id": { + "type": "integer" + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "gold_deduct": { + "description": "黄金会员提成", + "type": "integer" + }, + "id": { + "description": "数据库记录编号", + "type": "integer" + }, + "platinum_deduct": { + "description": "白金会员提成", + "type": "integer" + }, + "renewal_black_gold_deduct": { + "description": "续费黑金金会员提成", + "type": "integer" + }, + "renewal_gold_deduct": { + "description": "续费黄金会员提成", + "type": "integer" + }, + "renewal_platinum_deduct": { + "description": "续费白金会员提成", + "type": "integer" + }, + "store_id": { + "type": "integer" + } + } + }, "models.DictType": { "type": "object", "properties": { @@ -5296,6 +5372,83 @@ const docTemplate = `{ } } }, + "models.Store": { + "type": "object", + "properties": { + "address": { + "description": "详细地址", + "type": "string" + }, + "city": { + "description": "市", + "type": "string" + }, + "cooperative_assistant_member_deduct": { + "description": "GameCardGoods", + "allOf": [ + { + "$ref": "#/definitions/models.CooperativeAssistantMemberDeduct" + } + ] + }, + "cooperative_business_id": { + "description": "合作商id", + "type": "integer" + }, + "cooperative_name": { + "description": "合作商名称", + "type": "string" + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "district": { + "description": "区", + "type": "string" + }, + "id": { + "description": "数据库记录编号", + "type": "integer" + }, + "img": { + "description": "门面图", + "type": "string" + }, + "is_online": { + "description": "在线", + "type": "integer" + }, + "latitude": { + "description": "纬度", + "type": "number" + }, + "longitude": { + "description": "经度", + "type": "number" + }, + "member_service": { + "description": "会员服务:1 开启 2 不开启", + "type": "integer" + }, + "name": { + "description": "门店名称", + "type": "string" + }, + "province": { + "description": "省", + "type": "string" + }, + "sales_comm_rate": { + "description": "门店销售提成比例", + "type": "number" + }, + "tel": { + "description": "电话", + "type": "string" + } + } + }, "models.StoreInfo": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index 0fcebbf..96b6d1a 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -2734,6 +2734,39 @@ } } }, + "/api/v1/store/add": { + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "门店管理" + ], + "summary": "新增门店", + "parameters": [ + { + "description": "新增门店模型", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.Store" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/app.Response" + } + } + } + } + }, "/api/v1/supplier/create": { "post": { "consumes": [ @@ -4238,6 +4271,49 @@ } } }, + "models.CooperativeAssistantMemberDeduct": { + "type": "object", + "properties": { + "black_gold_deduct": { + "description": "黑金金会员提成", + "type": "integer" + }, + "cooperative_business_id": { + "type": "integer" + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "gold_deduct": { + "description": "黄金会员提成", + "type": "integer" + }, + "id": { + "description": "数据库记录编号", + "type": "integer" + }, + "platinum_deduct": { + "description": "白金会员提成", + "type": "integer" + }, + "renewal_black_gold_deduct": { + "description": "续费黑金金会员提成", + "type": "integer" + }, + "renewal_gold_deduct": { + "description": "续费黄金会员提成", + "type": "integer" + }, + "renewal_platinum_deduct": { + "description": "续费白金会员提成", + "type": "integer" + }, + "store_id": { + "type": "integer" + } + } + }, "models.DictType": { "type": "object", "properties": { @@ -5285,6 +5361,83 @@ } } }, + "models.Store": { + "type": "object", + "properties": { + "address": { + "description": "详细地址", + "type": "string" + }, + "city": { + "description": "市", + "type": "string" + }, + "cooperative_assistant_member_deduct": { + "description": "GameCardGoods", + "allOf": [ + { + "$ref": "#/definitions/models.CooperativeAssistantMemberDeduct" + } + ] + }, + "cooperative_business_id": { + "description": "合作商id", + "type": "integer" + }, + "cooperative_name": { + "description": "合作商名称", + "type": "string" + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "district": { + "description": "区", + "type": "string" + }, + "id": { + "description": "数据库记录编号", + "type": "integer" + }, + "img": { + "description": "门面图", + "type": "string" + }, + "is_online": { + "description": "在线", + "type": "integer" + }, + "latitude": { + "description": "纬度", + "type": "number" + }, + "longitude": { + "description": "经度", + "type": "number" + }, + "member_service": { + "description": "会员服务:1 开启 2 不开启", + "type": "integer" + }, + "name": { + "description": "门店名称", + "type": "string" + }, + "province": { + "description": "省", + "type": "string" + }, + "sales_comm_rate": { + "description": "门店销售提成比例", + "type": "number" + }, + "tel": { + "description": "电话", + "type": "string" + } + } + }, "models.StoreInfo": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 11c7661..1c6a058 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -579,6 +579,37 @@ definitions: - sys_generate - wholesale_price type: object + models.CooperativeAssistantMemberDeduct: + properties: + black_gold_deduct: + description: 黑金金会员提成 + type: integer + cooperative_business_id: + type: integer + createdAt: + description: 创建时间 + type: string + gold_deduct: + description: 黄金会员提成 + type: integer + id: + description: 数据库记录编号 + type: integer + platinum_deduct: + description: 白金会员提成 + type: integer + renewal_black_gold_deduct: + description: 续费黑金金会员提成 + type: integer + renewal_gold_deduct: + description: 续费黄金会员提成 + type: integer + renewal_platinum_deduct: + description: 续费白金会员提成 + type: integer + store_id: + type: integer + type: object models.DictType: properties: createBy: @@ -1336,6 +1367,61 @@ definitions: description: 更新时间 type: string type: object + models.Store: + properties: + address: + description: 详细地址 + type: string + city: + description: 市 + type: string + cooperative_assistant_member_deduct: + allOf: + - $ref: '#/definitions/models.CooperativeAssistantMemberDeduct' + description: GameCardGoods + cooperative_business_id: + description: 合作商id + type: integer + cooperative_name: + description: 合作商名称 + type: string + createdAt: + description: 创建时间 + type: string + district: + description: 区 + type: string + id: + description: 数据库记录编号 + type: integer + img: + description: 门面图 + type: string + is_online: + description: 在线 + type: integer + latitude: + description: 纬度 + type: number + longitude: + description: 经度 + type: number + member_service: + description: 会员服务:1 开启 2 不开启 + type: integer + name: + description: 门店名称 + type: string + province: + description: 省 + type: string + sales_comm_rate: + description: 门店销售提成比例 + type: number + tel: + description: 电话 + type: string + type: object models.StoreInfo: properties: expireTime: @@ -3739,6 +3825,27 @@ paths: summary: 系统信息 tags: - system/系统信息 + /api/v1/store/add: + post: + consumes: + - application/json + parameters: + - description: 新增门店模型 + in: body + name: request + required: true + schema: + $ref: '#/definitions/models.Store' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/app.Response' + summary: 新增门店 + tags: + - 门店管理 /api/v1/supplier/create: post: consumes: diff --git a/go.mod b/go.mod index 0b3b6ec..a3f452f 100644 --- a/go.mod +++ b/go.mod @@ -57,6 +57,7 @@ require ( golang.org/x/sync v0.4.0 golang.org/x/tools v0.14.0 // indirect google.golang.org/protobuf v1.31.0 // indirect + gopkg.in/natefinch/lumberjack.v2 v2.2.1 gorm.io/driver/mysql v0.3.2 gorm.io/driver/postgres v0.2.9 gorm.io/driver/sqlite v1.0.9 diff --git a/go.sum b/go.sum index 5b664b2..188cac7 100644 --- a/go.sum +++ b/go.sum @@ -843,6 +843,8 @@ gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno= gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/kyokomi/emoji.v1 v1.5.1 h1:beetH5mWDMzFznJ+Qzd5KVHp79YKhVUMcdO8LpRLeGw= gopkg.in/kyokomi/emoji.v1 v1.5.1/go.mod h1:N9AZ6hi1jHOPn34PsbpufQZUcKftSD7WgS2pgpmH4Lg= +gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= +gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= diff --git a/logger/logx.go b/logger/logx.go index 21d5115..625c2a9 100644 --- a/logger/logx.go +++ b/logger/logx.go @@ -2,8 +2,14 @@ package logger import ( "context" + "fmt" "github.com/sirupsen/logrus" + "go-admin/tools/config" + "gopkg.in/natefinch/lumberjack.v2" + "io" "os" + "path/filepath" + "time" ) var l *Logx @@ -27,14 +33,34 @@ func init() { ctx: &ctx, } + // 设置json格式 l.SetFormatter(&logrus.JSONFormatter{TimestampFormat: "2006-01-02 15:04:05"}) - // 设置输出 - l.SetOutput(os.Stdout) // 设置最低loglevel - l.SetLevel(logrus.DebugLevel) + l.SetLevel(logrus.InfoLevel) - l.SetReportCaller(true) + // 设置输出到文件 + logFileName := getLogFileName() + fileLogger := &lumberjack.Logger{ + Filename: logFileName, + MaxSize: 100, // 每个日志文件的最大尺寸,单位为 MB + MaxBackups: 5, // 保留旧日志文件的最大个数 + MaxAge: 60, // 保留旧日志文件的最大天数 + Compress: true, // 是否压缩旧日志文件 + } + defer fileLogger.Close() + + // 将日志同时输出到文件和控制台 + l.SetOutput(io.MultiWriter(os.Stdout, fileLogger)) +} + +// 获取日志文件名,按照 server-2023-12-01.log 的格式 +func getLogFileName() string { + currentTime := time.Now().Format("2006-01-02") + logFileName := fmt.Sprintf("server-%s.log", currentTime) + // 可以指定日志文件存储的路径 + logFilePath := config.LoggerConfig.Path + return filepath.Join(logFilePath, logFileName) } func WithContext(ctx context.Context) { diff --git a/test/gen_test.go b/test/gen_test.go index 2d0f7c1..c56b562 100644 --- a/test/gen_test.go +++ b/test/gen_test.go @@ -337,7 +337,7 @@ func TestKuaiDiStatePush(t *testing.T) { unescape, err := url.ParseQuery(body) if err != nil { - logger.Error("err:", err) + logger.Error("err:", logger.Field("err", err)) } //unescapeJson, _ := json.Marshal(unescape) @@ -380,7 +380,7 @@ func TestTimeZeroData(t *testing.T) { "receipt_time": time.Time{}, }).Error if err != nil { - logger.Error("err:", err) + logger.Error("err:", logger.Field("err", err)) } //NewShareCardRetrieveCardQuerySet(DB).IDEq(189).GetUpdater().SetStoreId() @@ -444,7 +444,7 @@ func TestUpdateStorePassWd(t *testing.T) { var sysUsers models.SysUser err := orm.Eloquent.Table("sys_user").Where("username=?", list[i]).Find(&sysUsers).Error if err != nil { - logger.Error("find sys users err:", err) + logger.Error("find sys users err:", logger.Field("err", err)) } fmt.Println("list:", list[i], " ", passes[i]) @@ -468,7 +468,7 @@ func TestUpdateStorePassWdTest(t *testing.T) { var sysUsers []models.SysUser err := orm.Eloquent.Debug().Table("sys_user").Where("username IN (?)", []string{"wxjm"}).Find(&sysUsers).Error if err != nil { - logger.Error("find sys users err:", err) + logger.Error("find sys users err:", logger.Field("err", err)) } passes := []string{"JlPP2ZnAT1"} for i, _ := range sysUsers { @@ -490,7 +490,7 @@ func TestUpdateStorePassWdTest(t *testing.T) { err = orm.Eloquent.Table("sys_user").Where("user_id=?", sysUsers[i].UserId).Update("password", string(hash)).Error if err != nil { - logger.Error("update err:", err) + logger.Error("update err:", logger.Field("err", err)) } } }