From 211b6c9bf7a176dbc29fde7f07a39686b86ad70c Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Wed, 20 Nov 2024 19:55:28 +0800 Subject: [PATCH] update --- app/hdl/home_page/hdl_basic.go | 70 ++++++++++++++++++++++++++++++++++ app/md/home_page/md_basic.go | 4 ++ app/router/router.go | 1 + docs/docs.go | 46 ++++++++++++++++++++++ docs/swagger.json | 46 ++++++++++++++++++++++ docs/swagger.yaml | 30 +++++++++++++++ 6 files changed, 197 insertions(+) diff --git a/app/hdl/home_page/hdl_basic.go b/app/hdl/home_page/hdl_basic.go index b28cc8a..a5a4cc8 100644 --- a/app/hdl/home_page/hdl_basic.go +++ b/app/hdl/home_page/hdl_basic.go @@ -337,3 +337,73 @@ func RealTimePrice(c *gin.Context) { e.OutSuc(c, resp, nil) } + +// IsCanSignIn +// @Summary 蛋蛋星球-主页-是否能签到(获取) +// @Tags 主页 +// @Description 是否能签到(获取) +// @Accept json +// @Produce json +// @param Authorization header string true "验证参数Bearer和token空格拼接" +// @Success 200 {object} md.IsCanSignInResp "具体数据" +// @Failure 400 {object} md.Response "具体错误" +// @Router /api/v1/homePage/isCanSignIn [get] +func IsCanSignIn(c *gin.Context) { + val, exists := c.Get("user") + if !exists { + e.OutErr(c, e.ERR_USER_CHECK_ERR, nil) + return + } + user, ok := val.(*model.User) + if !ok { + e.OutErr(c, e.ERR_USER_CHECK_ERR, nil) + return + } + + //1、查找 `OneCirclesPublicPlatoonBasicSetting` 基础设置 + energyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db) + eggEnergyBasicSetting, err := energyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{ + "key": "is_open", + "value": 1, + }) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + var videoRewardSystem *md2.VideoRewardSystemStruct + err = json.Unmarshal([]byte(eggEnergyBasicSetting.VideoRewardSystem), &videoRewardSystem) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + rewardTotalNum := utils.StrToInt(videoRewardSystem.RewardTotalNum) + + //2、查询当前用户观看视屏记录 + watchRecordsDb := implement.NewEggEnergyUserWatchRecordsDb(db.Db) + userWatchRecords, err := watchRecordsDb.EggEnergyUserWatchRecordsGetOneByParams(map[string]interface{}{ + "key": "uid", + "value": user.Id, + }) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + + var isCan bool + now := time.Now() + if userWatchRecords != nil && userWatchRecords.ResidueWatchAdNum == rewardTotalNum && userWatchRecords.NextWatchAdDate.After(now) { + isCan = true + } + + utils.FilePutContents("HomePageIsCanSignIn", utils.SerializeStr(map[string]interface{}{ + "user_phone": user.Phone, + "user_uid": user.Id, + "is_can": isCan, + "time": now.Format("2006-01-02 15:04:05"), + })) + resp := md.IsCanSignInResp{ + IsCan: isCan, + } + e.OutSuc(c, resp, nil) + return +} diff --git a/app/md/home_page/md_basic.go b/app/md/home_page/md_basic.go index a23febc..3bd2b4a 100644 --- a/app/md/home_page/md_basic.go +++ b/app/md/home_page/md_basic.go @@ -29,3 +29,7 @@ type RealTimePriceResp struct { IsRises bool `json:"is_rises"` Rises string `json:"rises"` } + +type IsCanSignInResp struct { + IsCan bool `json:"is_can_sign_in"` +} diff --git a/app/router/router.go b/app/router/router.go index dc203c8..066d46a 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -62,6 +62,7 @@ func route(r *gin.RouterGroup) { rHomePage.GET("/index", home_page.HomePage) // 主页 rHomePage.GET("/adRule", home_page.HomePageWatchAdRule) // 可以观看广告列表 rHomePage.GET("/realTimePrice", home_page.RealTimePrice) // 实时数据 + rHomePage.GET("/isCanSignIn", home_page.IsCanSignIn) // 是否可以观看广告 } } diff --git a/docs/docs.go b/docs/docs.go index ac000a9..92cb864 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -138,6 +138,44 @@ const docTemplate = `{ } } }, + "/api/v1/homePage/isCanSignIn": { + "get": { + "description": "是否能签到(获取)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "主页" + ], + "summary": "蛋蛋星球-主页-是否能签到(获取)", + "parameters": [ + { + "type": "string", + "description": "验证参数Bearer和token空格拼接", + "name": "Authorization", + "in": "header", + "required": true + } + ], + "responses": { + "200": { + "description": "具体数据", + "schema": { + "$ref": "#/definitions/md.IsCanSignInResp" + } + }, + "400": { + "description": "具体错误", + "schema": { + "$ref": "#/definitions/md.Response" + } + } + } + } + }, "/api/v1/homePage/realTimePrice": { "get": { "description": "实时数据(获取)", @@ -375,6 +413,14 @@ const docTemplate = `{ } } }, + "md.IsCanSignInResp": { + "type": "object", + "properties": { + "is_can_sign_in": { + "type": "boolean" + } + } + }, "md.LoginReq": { "type": "object", "required": [ diff --git a/docs/swagger.json b/docs/swagger.json index 2765d6c..022a9e1 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -132,6 +132,44 @@ } } }, + "/api/v1/homePage/isCanSignIn": { + "get": { + "description": "是否能签到(获取)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "主页" + ], + "summary": "蛋蛋星球-主页-是否能签到(获取)", + "parameters": [ + { + "type": "string", + "description": "验证参数Bearer和token空格拼接", + "name": "Authorization", + "in": "header", + "required": true + } + ], + "responses": { + "200": { + "description": "具体数据", + "schema": { + "$ref": "#/definitions/md.IsCanSignInResp" + } + }, + "400": { + "description": "具体错误", + "schema": { + "$ref": "#/definitions/md.Response" + } + } + } + } + }, "/api/v1/homePage/realTimePrice": { "get": { "description": "实时数据(获取)", @@ -369,6 +407,14 @@ } } }, + "md.IsCanSignInResp": { + "type": "object", + "properties": { + "is_can_sign_in": { + "type": "boolean" + } + } + }, "md.LoginReq": { "type": "object", "required": [ diff --git a/docs/swagger.yaml b/docs/swagger.yaml index e0179db..a9bc3dd 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -57,6 +57,11 @@ definitions: description: 奖励X个活跃积分 type: string type: object + md.IsCanSignInResp: + properties: + is_can_sign_in: + type: boolean + type: object md.LoginReq: properties: code: @@ -219,6 +224,31 @@ paths: summary: 蛋蛋星球-主页-基础信息(获取) tags: - 主页 + /api/v1/homePage/isCanSignIn: + get: + consumes: + - application/json + description: 是否能签到(获取) + parameters: + - description: 验证参数Bearer和token空格拼接 + in: header + name: Authorization + required: true + type: string + produces: + - application/json + responses: + "200": + description: 具体数据 + schema: + $ref: '#/definitions/md.IsCanSignInResp' + "400": + description: 具体错误 + schema: + $ref: '#/definitions/md.Response' + summary: 蛋蛋星球-主页-是否能签到(获取) + tags: + - 主页 /api/v1/homePage/realTimePrice: get: consumes: