Browse Source

fix:全时异步通知调整

Roc 2 years ago
parent
commit
b8b2b14e84

+ 13 - 0
controllers/quanshi.go

@@ -2,6 +2,7 @@ package controllers
 
 import (
 	"fmt"
+	"hongze/hongze_open_api/services/quanshi"
 	"hongze/hongze_open_api/utils"
 )
 
@@ -15,7 +16,19 @@ type QuanShiControllerCommon struct {
 // @Description 全时回调接口
 // @router /callback [post]
 func (c *QuanShiControllerCommon) CallBack() {
+	//回调中url参数要做签名(get请求中的参数,按照自己的方式签名,避免链接被别人拿去随意请求)
 	utils.FileLog.Info(fmt.Sprintf("全时回调参数:%s", string(c.Ctx.Input.RequestBody)))
 	//c.OkDetailed("ok", "获取成功")
+
+	activityId, _ := c.GetInt("activity_id")
+	timeInt, _ := c.GetInt("time")
+	paramStr := fmt.Sprintf(`activity_id=%d&time=%d`, activityId, timeInt)
+	signStr := quanshi.GetSign(paramStr)
+	ownSign := c.GetString("sign")
+	if ownSign != signStr {
+		c.FailWithMessage("请求异常")
+		return
+	}
+
 	c.Ok()
 }

+ 1 - 3
main.go

@@ -4,7 +4,7 @@ import (
 	"fmt"
 	"github.com/beego/beego/v2/adapter/logs"
 	"github.com/beego/beego/v2/server/web/context"
-	"hongze/hongze_open_api/models"
+	_ "hongze/hongze_open_api/models"
 	_ "hongze/hongze_open_api/routers"
 	"hongze/hongze_open_api/services/alarm_msg"
 	"hongze/hongze_open_api/utils"
@@ -21,8 +21,6 @@ func main() {
 	}
 
 	web.BConfig.RecoverFunc = Recover
-	//数据库初始化
-	models.InitDb()
 	web.Run()
 }
 

+ 26 - 3
models/db_init.go

@@ -6,8 +6,12 @@ import (
 	"hongze/hongze_open_api/models/tables/admin"
 	"hongze/hongze_open_api/models/tables/article"
 	"hongze/hongze_open_api/models/tables/company"
+	"hongze/hongze_open_api/models/tables/company_product"
 	"hongze/hongze_open_api/models/tables/open_api_user"
+	"hongze/hongze_open_api/models/tables/qs_event"
+	"hongze/hongze_open_api/models/tables/qs_event_user"
 	"hongze/hongze_open_api/models/tables/wx_user"
+	"hongze/hongze_open_api/models/tables/yb_activity"
 	"hongze/hongze_open_api/utils"
 	"time"
 )
@@ -31,12 +35,31 @@ func init() {
 	//注册对象
 	orm.RegisterModel(
 		new(open_api_user.OpenApiUser),    //开放API用户表
-		new(company.Company),              //company客户表
-		new(wx_user.WxUser),               //微信用户表
 		new(admin.Admin),                  //系统用户表
 		new(article.CygxArticleCeluePush), //策略平台推送过来更新的文章
 	)
 
+	// 注册研报相关的表
+	initYb()
+
+	// 注册客户相关的表
+	initCompany()
+}
+
+// initYb 研报活动相关
+func initYb() {
+	orm.RegisterModel(
+		new(yb_activity.Activity),      //研报活动
+		new(qs_event.QsEvent),          //全时与ficc研报活动的关系表
+		new(qs_event_user.QsEventUser), //全时参会信息
+	)
 }
 
-func InitDb() {}
+// initCompany 注册客户相关的
+func initCompany() {
+	orm.RegisterModel(
+		new(company.Company),                //company客户表
+		new(company_product.CompanyProduct), //company_product客户产品表
+		new(wx_user.WxUser),                 //微信用户表
+	)
+}

+ 15 - 0
models/tables/user_view_statistics/user_view_statistics.go

@@ -34,3 +34,18 @@ func GetUserViewListByDate(dayStr string) (list []*UserViewMobileTotalSlice, err
 	_, err = o.Raw(sql, dayStr).QueryRows(&list)
 	return
 }
+
+// UserViewStatisticsInfo 根据用户手机号字符串获取用户的浏览数和最晚阅读次数
+type UserViewStatisticsInfo struct {
+	Mobile       string    `description:"用户手机号"`
+	Total        int       `description:"总阅读数"`
+	LastViewTime time.Time `description:"用户浏览时间"`
+}
+
+// GetUserViewStatisticsByMobile 根据手机号获取联系人的浏览次数
+func GetUserViewStatisticsByMobile(mobile string) (item *UserViewStatisticsInfo, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT mobile,sum(view_num) view_total,max(last_view_time) last_view_time FROM  user_view_statistics  WHERE mobile = ? `
+	err = o.Raw(sql, mobile).QueryRow(&item)
+	return
+}

+ 10 - 0
models/tables/wx_user/wx_user.go

@@ -87,3 +87,13 @@ func GetWxUserByMobileStr(mobile string) (item *WxUserItem, err error) {
 	err = orm.NewOrm().Raw(sql).QueryRow(&item)
 	return
 }
+
+// GetWxUserByMobileCountryCode 根据手机号和区号获取用户信息
+func GetWxUserByMobileCountryCode(mobile, countryCode string) (item *WxUser, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM wx_user WHERE mobile = ? `
+	sql += ` and country_code in ("","` + countryCode + `") `
+	sql += ` LIMIT 1 `
+	err = o.Raw(sql, mobile).QueryRow(&item)
+	return
+}