|
@@ -8,11 +8,13 @@ import (
|
|
|
"github.com/gogf/gf/net/ghttp"
|
|
|
"github.com/gogf/gf/os/gtime"
|
|
|
"github.com/gogf/gf/util/gconv"
|
|
|
+ douyinUser "github.com/lin-jim-leon/douyin/open/user"
|
|
|
"github.com/lin-jim-leon/kuaishou/open/merchant"
|
|
|
"github.com/lin-jim-leon/kuaishou/open/user"
|
|
|
"log"
|
|
|
"time"
|
|
|
"youngmini_server/app/model/youngee_talent_model"
|
|
|
+ "youngmini_server/app/service/youngee_sectask_service"
|
|
|
"youngmini_server/app/utils"
|
|
|
)
|
|
|
|
|
@@ -37,7 +39,6 @@ func GetQrcode(r *ghttp.Request) *TalentHttpResult {
|
|
|
if err != nil {
|
|
|
return &TalentHttpResult{Code: -1, Msg: "Get talent id failed"}
|
|
|
}
|
|
|
- println("here")
|
|
|
// 记录开始时间
|
|
|
startTime := time.Now()
|
|
|
// 创建一个新的上下文
|
|
@@ -48,9 +49,9 @@ func GetQrcode(r *ghttp.Request) *TalentHttpResult {
|
|
|
if typePlatform == 4 { //快手电商
|
|
|
urlstr = fmt.Sprintf("https://open.kuaishou.com/oauth2/connect?state=%s&app_id=ks651333097154138217&redirect_uri=https://younggee.com/kuaishouauth&scope=merchant_distribution,merchant_refund,merchant_item,merchant_order,user_info,merchant_servicemarket,merchant_user,merchant_logistics&response_type=code", tid)
|
|
|
} else if typePlatform == 8 { //快手平台
|
|
|
- urlstr = fmt.Sprintf("https://open.kuaishou.com/oauth2/connect?state=%s&app_id=ks671599294546520767&redirect_uri=https://younggee.com/kuaishouauthVideo&scope=user_video_info,user_info&response_type=code", tid)
|
|
|
+ urlstr = fmt.Sprintf("https://open.kuaishou.com/oauth2/connect?state=%s&app_id=ks671599294546520767&redirect_uri=https://younggee.com/kuaishouVideoVideo&scope=user_video_info,user_info&response_type=code", tid)
|
|
|
} else if typePlatform == 2 { //抖音平台
|
|
|
- urlstr = fmt.Sprintf("https://open.kuaishou.com/oauth2/connect?state=%s&app_id=ks671599294546520767&redirect_uri=https://younggee.com/kuaishouauthVideo&scope=user_video_info,user_info&response_type=code", tid)
|
|
|
+ urlstr = fmt.Sprintf("https://open.kuaishou.com/oauth2/connect?state=%s&app_id=ks671599294546520767&redirect_uri=https://younggee.com/douyinauth&scope=user_info,data.external.user,video.list.bind&response_type=code", tid)
|
|
|
} else {
|
|
|
urlstr = "unknow"
|
|
|
}
|
|
@@ -123,55 +124,340 @@ func CheckAccount(r *ghttp.Request) *TalentHttpResult {
|
|
|
return &TalentHttpResult{Code: 0, Msg: "success", Data: userInfo}
|
|
|
}
|
|
|
|
|
|
-// 检查数据库表中是否有达人对应的数据,有就删掉,/kuaishouath中会插入。
|
|
|
-func CheckNewAccount(r *ghttp.Request) *TalentHttpResult {
|
|
|
+// / 抖音二维码绑定,轮询此接口,
|
|
|
+func CheckDyNewAccount(r *ghttp.Request) *TalentHttpResult {
|
|
|
//check到了更新时间在两秒内的插入的数据。则说明已绑定。弹窗消失。
|
|
|
- //达人id获取
|
|
|
- fmt.Println("***********into checknewaccount")
|
|
|
tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
|
|
|
+ redisDyBindStatusKey := fmt.Sprintf("DyBind:%s", tid)
|
|
|
+ bindStatus, err := g.Redis().DoVar("GET", redisDyBindStatusKey)
|
|
|
+ if bindStatus.String() == "bound_to_other" {
|
|
|
+ return &TalentHttpResult{Code: -1, Msg: "此账号已被其他达人绑定", Data: nil}
|
|
|
+ }
|
|
|
if err != nil {
|
|
|
return &TalentHttpResult{Code: -1, Msg: "Get talent id failed"}
|
|
|
}
|
|
|
// 获取当前时间
|
|
|
currentTime := gtime.Now()
|
|
|
- // 查询数据库中是否有符合条件的数据
|
|
|
- userInfo := &youngee_talent_model.KuaishouUserInfo{}
|
|
|
+ // 查询数据库中符合条件的所有记录
|
|
|
+ var userInfos []youngee_talent_model.KuaishouUserInfo
|
|
|
err = g.DB().Model("platform_kuaishou_user_info").
|
|
|
Where("talent_id = ?", tid).
|
|
|
- Scan(&userInfo)
|
|
|
+ Scan(&userInfos)
|
|
|
if err != nil {
|
|
|
- return &TalentHttpResult{Code: -2, Msg: "platform_kuaishou_user_info query failed"}
|
|
|
- }
|
|
|
- //找到数据,判断时间差
|
|
|
- if userInfo != nil {
|
|
|
- // 计算创建时间与当前时间的差值
|
|
|
- timeDiff := currentTime.Sub(userInfo.CreateTime)
|
|
|
- fmt.Println("***********kifasfa", timeDiff)
|
|
|
- if timeDiff <= 3*time.Second {
|
|
|
- return &TalentHttpResult{Code: 0, Msg: "success", Data: nil}
|
|
|
+ return &TalentHttpResult{Code: -4, Msg: "Database query failed"}
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(userInfos) == 0 {
|
|
|
+ // 如果没有符合条件的数据,返回失败
|
|
|
+ return &TalentHttpResult{Code: -5, Msg: "No valid data found"}
|
|
|
+ }
|
|
|
+
|
|
|
+ // 找到 CreateTime 最新的记录
|
|
|
+ latestUserInfo := userInfos[0]
|
|
|
+ for _, info := range userInfos[1:] {
|
|
|
+ if info.CreateTime.After(latestUserInfo.CreateTime) {
|
|
|
+ latestUserInfo = info
|
|
|
}
|
|
|
}
|
|
|
- // 如果没有符合条件的数据,返回失败
|
|
|
- return &TalentHttpResult{Code: -20, Msg: "No valid data found", Data: nil}
|
|
|
+
|
|
|
+ // 计算创建时间与当前时间的差值
|
|
|
+ timeDiff := currentTime.Sub(latestUserInfo.CreateTime)
|
|
|
+ if timeDiff <= 3*time.Second {
|
|
|
+ return &TalentHttpResult{Code: 0, Msg: "success"}
|
|
|
+ }
|
|
|
+
|
|
|
+ // 超过时间差,返回失败
|
|
|
+ return &TalentHttpResult{Code: -6, Msg: "Time difference exceeds 3 seconds"}
|
|
|
}
|
|
|
-func CheckTokenExp(r *ghttp.Request) *TalentHttpResult {
|
|
|
- //达人id获取
|
|
|
+
|
|
|
+// 用于轮询,检查数据库表中是否有达人对应的数据,有就删掉,/kuaishouath中会插入。
|
|
|
+func CheckKsNewAccount(r *ghttp.Request) *TalentHttpResult {
|
|
|
+ //check到了更新时间在两秒内的插入的数据。则说明已绑定。弹窗消失。
|
|
|
tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
|
|
|
if err != nil {
|
|
|
return &TalentHttpResult{Code: -1, Msg: "Get talent id failed"}
|
|
|
}
|
|
|
- key, err1 := g.DB().Model("platform_kuaishou_user_info").Fields("access_token").Where("talent_id = ?", tid).Value()
|
|
|
- if err1 != nil {
|
|
|
- return &TalentHttpResult{Code: -1, Msg: "query database fail"}
|
|
|
+ redisKsBindStatusKey := fmt.Sprintf("KsBind:%s", tid)
|
|
|
+ bindStatus, err := g.Redis().DoVar("GET", redisKsBindStatusKey)
|
|
|
+ if bindStatus.String() == "bound_to_other" {
|
|
|
+ return &TalentHttpResult{Code: -1, Msg: "此快手账号已被其他达人绑定", Data: nil}
|
|
|
}
|
|
|
- AccessToken := key.String()
|
|
|
- res_info, err2 := user.GetUserinfo(ClientKey, AccessToken)
|
|
|
- if err2 != nil {
|
|
|
- //前端接收code=-2表示token过期
|
|
|
- return &TalentHttpResult{Code: -2, Msg: "accessToken过期", Data: nil}
|
|
|
+ if err != nil {
|
|
|
+ return &TalentHttpResult{Code: -1, Msg: "Get talent id failed"}
|
|
|
}
|
|
|
- // 查询成功,返回成功结果和数据
|
|
|
- return &TalentHttpResult{Code: 0, Msg: "success", Data: res_info}
|
|
|
+
|
|
|
+ // 获取当前时间
|
|
|
+ currentTime := gtime.Now()
|
|
|
+ // 查询数据库中符合条件的所有记录
|
|
|
+ var userInfos []youngee_talent_model.KuaishouUserInfo
|
|
|
+ err = g.DB().Model("platform_kuaishou_user_info").
|
|
|
+ Where("talent_id = ?", tid).
|
|
|
+ Scan(&userInfos)
|
|
|
+ if err != nil {
|
|
|
+ return &TalentHttpResult{Code: -4, Msg: "Database query failed"}
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(userInfos) == 0 {
|
|
|
+ // 如果没有符合条件的数据,返回失败
|
|
|
+ return &TalentHttpResult{Code: -5, Msg: "No valid data found"}
|
|
|
+ }
|
|
|
+
|
|
|
+ // 找到 CreateTime 最新的记录
|
|
|
+ latestUserInfo := userInfos[0]
|
|
|
+ for _, info := range userInfos[1:] {
|
|
|
+ if info.CreateTime.After(latestUserInfo.CreateTime) {
|
|
|
+ latestUserInfo = info
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算创建时间与当前时间的差值
|
|
|
+ timeDiff := currentTime.Sub(latestUserInfo.CreateTime)
|
|
|
+ if timeDiff <= 3*time.Second {
|
|
|
+ return &TalentHttpResult{Code: 0, Msg: "success"}
|
|
|
+ }
|
|
|
+
|
|
|
+ // 超过时间差,返回失败
|
|
|
+ return &TalentHttpResult{Code: -6, Msg: "Time difference exceeds 3 seconds"}
|
|
|
+}
|
|
|
+
|
|
|
+func CheckTokenExp(openId string, platformId int, talentId string) int {
|
|
|
+ fmt.Println("into checktoken")
|
|
|
+ //检查平台8
|
|
|
+ if platformId == 8 {
|
|
|
+ key, err := g.DB().Model("platform_kuaishou_user_info").Fields("access_token").Where("talent_id = ? & platform_id = ? & open_id = ? ", talentId, platformId, openId).Value()
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("query database fail")
|
|
|
+ return -1
|
|
|
+ }
|
|
|
+ AccessToken := key.String()
|
|
|
+ _, err = user.GetUserinfo(ClientKey1, AccessToken)
|
|
|
+ if err != nil { //过期
|
|
|
+ fmt.Println("平台accessToken过期")
|
|
|
+ //前端接收code=-2表示token过期
|
|
|
+ return 0
|
|
|
+ } else {
|
|
|
+ fmt.Println("平台AT未过期")
|
|
|
+ return 1
|
|
|
+ }
|
|
|
+ //检查电商授权4
|
|
|
+ } else {
|
|
|
+ key, err := g.DB().Model("platform_kuaishou_user_info").Fields("access_token").Where("talent_id = ? & platform_id = ? & open_id = ? ", talentId, platformId, openId).Value()
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("query database fail")
|
|
|
+ return 2
|
|
|
+ }
|
|
|
+ AccessToken := key.String()
|
|
|
+ _, err = user.GetUserinfo(ClientKey, AccessToken)
|
|
|
+ if err != nil { //过期
|
|
|
+ //前端接收code=-2表示token过期
|
|
|
+ fmt.Println("电商accessToken过期")
|
|
|
+ return 3
|
|
|
+ } else {
|
|
|
+ fmt.Println("电商accessToken未过期")
|
|
|
+ return 4
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// func CheckTokenExp(r *ghttp.Request) *TalentHttpResult {
|
|
|
+// //达人id获取
|
|
|
+// tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
|
|
|
+// //平台id获取
|
|
|
+// platformId := r.GetInt("platform_id")
|
|
|
+// //openId获取
|
|
|
+// openId := r.GetString("open_id")
|
|
|
+// //检查平台授权
|
|
|
+// if platformId == 8 {
|
|
|
+// key, err := g.DB().Model("platform_kuaishou_user_info").Fields("access_token").Where("talent_id = ? & platform_id = ? & open_id = ? ", tid, platformId, openId).Value()
|
|
|
+// if err != nil {
|
|
|
+// return &TalentHttpResult{Code: -1, Msg: "query database fail"}
|
|
|
+// }
|
|
|
+// AccessToken := key.String()
|
|
|
+// res_info1, err := user.GetUserinfo(ClientKey1, AccessToken)
|
|
|
+// if err != nil { //过期
|
|
|
+// //前端接收code=-2表示token过期
|
|
|
+// return &TalentHttpResult{Code: -2, Msg: "平台accessToken过期", Data: nil}
|
|
|
+// } else {
|
|
|
+// return &TalentHttpResult{Code: 0, Msg: "平台accessToken未过期", Data: res_info1}
|
|
|
+// }
|
|
|
+// //检查电商授权
|
|
|
+// } else {
|
|
|
+// key, err := g.DB().Model("platform_kuaishou_user_info").Fields("access_token").Where("talent_id = ? & platform_id = ? & open_id = ? ", tid, platformId, openId).Value()
|
|
|
+// if err != nil {
|
|
|
+// return &TalentHttpResult{Code: -1, Msg: "query database fail"}
|
|
|
+// }
|
|
|
+// AccessToken := key.String()
|
|
|
+// res_info, err := user.GetUserinfo(ClientKey, AccessToken)
|
|
|
+// if err != nil { //过期
|
|
|
+// //前端接收code=-2表示token过期
|
|
|
+// return &TalentHttpResult{Code: -2, Msg: "电商accessToken过期", Data: nil}
|
|
|
+// } else {
|
|
|
+// return &TalentHttpResult{Code: 0, Msg: "平台accessToken未过期", Data: res_info}
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// if err != nil {
|
|
|
+// return &TalentHttpResult{Code: -3, Msg: "Get talent id failed"}
|
|
|
+// }
|
|
|
+// key, err1 := g.DB().Model("platform_kuaishou_user_info").Fields("access_token").Where("talent_id = ? & platform_id = ? & open_id = ? ", tid, platformId, openId).Value()
|
|
|
+// if err1 != nil {
|
|
|
+// return &TalentHttpResult{Code: -1, Msg: "query database fail"}
|
|
|
+// }
|
|
|
+// AccessToken := key.String()
|
|
|
+// res_info, err2 := user.GetUserinfo(ClientKey, AccessToken)
|
|
|
+// if err2 != nil {
|
|
|
+// //前端接收code=-2表示token过期
|
|
|
+// return &TalentHttpResult{Code: -2, Msg: "accessToken过期", Data: nil}
|
|
|
+// }
|
|
|
+// // 查询成功,返回成功结果和数据
|
|
|
+// return &TalentHttpResult{Code: 0, Msg: "success", Data: res_info}
|
|
|
+// }
|
|
|
+func AddWindowKuaishouList(r *ghttp.Request) *TalentHttpResult {
|
|
|
+ // 定义用于存储查询结果的结构体切片
|
|
|
+ var results []*youngee_talent_model.KuaishouUserInfo
|
|
|
+
|
|
|
+ // 获取talent_id
|
|
|
+ tid, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
|
|
|
+
|
|
|
+ // 查询此达人下,platform_id 为 8 或 4 的所有数据,并将结果扫描到结构体切片中
|
|
|
+ err := g.DB().Model(&youngee_talent_model.KuaishouUserInfo{}).
|
|
|
+ Where("talent_id = ?", tid).
|
|
|
+ Where("platform_id IN (?, ?)", 4, 8).
|
|
|
+ Order("open_id ASC, platform_id DESC"). // 按 open_id 排序,确保每组的数据连续,并且 platform_id=4 的数据排在前面
|
|
|
+ Scan(&results)
|
|
|
+ if err != nil {
|
|
|
+ return &TalentHttpResult{Code: 1, Msg: "查询失败", Data: nil}
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建一个 map,用于记录每个 open_id 对应的记录
|
|
|
+ //key是openid,value是数组,从而实现一对多
|
|
|
+ openIdMap := make(map[string][]*youngee_talent_model.KuaishouUserInfo)
|
|
|
+
|
|
|
+ // 将查询结果按 open_id 分组
|
|
|
+ for _, record := range results {
|
|
|
+ openIdMap[record.OpenId] = append(openIdMap[record.OpenId], record)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 筛选出 open_id 对应两条数据且 platform_id = 4 的记录
|
|
|
+ var resInfo []*youngee_talent_model.KuaishouUserInfo
|
|
|
+ for _, records := range openIdMap {
|
|
|
+ if len(records) == 2 { // 确保有两条数据,排除只有一个 platform_id 的情况
|
|
|
+ for _, record := range records {
|
|
|
+ if record.PlatformId == 4 { // 选取 platform_id = 4(电商) 的记录,含有粉丝数就好,因为需要加入橱窗
|
|
|
+ resInfo = append(resInfo, record)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 遍历 resInfo 检查过期和是否报名
|
|
|
+ for _, record := range resInfo {
|
|
|
+ // 调用 CheckKuaishouTokenExp 函数,检查 openId 是否过期
|
|
|
+ expired := CheckKuaishouTokenExp(record.OpenId)
|
|
|
+ // 将过期检查结果赋值给 expired 属性 ,过期则不能被选中用于加入橱窗
|
|
|
+ record.Expired = expired
|
|
|
+ }
|
|
|
+ return &TalentHttpResult{Code: 0, Msg: "加入橱窗成功", Data: resInfo}
|
|
|
+}
|
|
|
+
|
|
|
+func SignUpSecKuaishouList(r *ghttp.Request) *TalentHttpResult {
|
|
|
+ selectionId := r.GetString("selection_id")
|
|
|
+ // 定义用于存储查询结果的结构体切片
|
|
|
+ var results []*youngee_talent_model.KuaishouUserInfo
|
|
|
+
|
|
|
+ // 获取talent_id
|
|
|
+ tid, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
|
|
|
+
|
|
|
+ // 查询此达人下,platform_id 为 8 或 4 的所有数据,并将结果扫描到结构体切片中
|
|
|
+ err := g.DB().Model(&youngee_talent_model.KuaishouUserInfo{}).
|
|
|
+ Where("talent_id = ?", tid).
|
|
|
+ Where("platform_id IN (?, ?)", 4, 8).
|
|
|
+ Order("open_id ASC, platform_id DESC"). // 按 open_id 排序,确保每组的数据连续,并且 platform_id=4 的数据排在前面
|
|
|
+ Scan(&results)
|
|
|
+ if err != nil {
|
|
|
+ return &TalentHttpResult{Code: 1, Msg: "查询失败", Data: nil}
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建一个 map,用于记录每个 open_id 对应的记录
|
|
|
+ //key是openid,value是数组,从而实现一对多
|
|
|
+ openIdMap := make(map[string][]*youngee_talent_model.KuaishouUserInfo)
|
|
|
+
|
|
|
+ // 将查询结果按 open_id 分组
|
|
|
+ for _, record := range results {
|
|
|
+ openIdMap[record.OpenId] = append(openIdMap[record.OpenId], record)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 筛选出 open_id 对应两条数据且 platform_id = 4 的记录
|
|
|
+ var resInfo []*youngee_talent_model.KuaishouUserInfo
|
|
|
+ for _, records := range openIdMap {
|
|
|
+ if len(records) == 2 { // 确保有两条数据,排除只有一个 platform_id 的情况
|
|
|
+ for _, record := range records {
|
|
|
+ if record.PlatformId == 4 { // 选取 platform_id = 4(电商) 的记录,含有粉丝数就好,因为需要加入橱窗
|
|
|
+ resInfo = append(resInfo, record)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 遍历 resInfo 检查过期和是否报名
|
|
|
+ for _, record := range resInfo {
|
|
|
+ // 调用 CheckKuaishouTokenExp 函数,检查 openId 是否过期
|
|
|
+ expired := CheckKuaishouTokenExp(record.OpenId)
|
|
|
+ // 将过期检查结果赋值给 expired 属性 ,过期则不能被选中用于加入橱窗
|
|
|
+ record.Expired = expired
|
|
|
+ //是否报名
|
|
|
+ isSignResult, err := g.DB().Model("younggee_sec_task_info").Where("selection_id=? AND open_id=? talent_id=? sample_mode=?", selectionId, record.OpenId, tid, 1).One()
|
|
|
+ // 根据查询结果设置 IsSign 属性
|
|
|
+ if err != nil || isSignResult.IsEmpty() {
|
|
|
+ record.IsSign = 0 // 没有查到数据,设置为 0
|
|
|
+ } else {
|
|
|
+ record.IsSign = 1 // 查到数据,设置为 1
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return &TalentHttpResult{Code: 0, Msg: "加入橱窗成功", Data: resInfo}
|
|
|
+}
|
|
|
+
|
|
|
+// 只有绑定两个快手,且快手电商没有过期,才能访问到这
|
|
|
+func AddWindowWithKsAccount(r *ghttp.Request) *TalentHttpResult {
|
|
|
+ // 获取talent_id
|
|
|
+ tid, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
|
|
|
+ pId := r.GetString("product_id")
|
|
|
+ openId := r.GetString("open_id")
|
|
|
+ value, err := g.DB().Model("platform_kuaishou_user_info").Fields("open_id").Where("talent_id=? AND open_id = ?", tid, openId).Value()
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("query db fail")
|
|
|
+ }
|
|
|
+ accessToken := value.String()
|
|
|
+ //通过pId获取kuaishou_product_id
|
|
|
+ pIdSlice := []string{pId}
|
|
|
+ //如果此tId。此openId下已有此product的task则不
|
|
|
+ //res_info, err := merchant.AddItemsToShelf(ClientKey, SignSecret, accessToken, pIdSlice)
|
|
|
+ httpResult := youngee_sectask_service.IsCreateSecTask(r)
|
|
|
+ if httpResult.Code == 1 { //存在报名信息,仅添加橱窗
|
|
|
+ _, err := merchant.AddItemsToShelf(ClientKey, SignSecret, accessToken, pIdSlice)
|
|
|
+ if err != nil {
|
|
|
+ //表示添加失敗,沒有開通
|
|
|
+ return &TalentHttpResult{Code: -1, Msg: "快手未開通橱窗、商品不存在或已下线", Data: nil}
|
|
|
+ }
|
|
|
+ // 查询成功,返回成功结果和数据
|
|
|
+ return &TalentHttpResult{Code: 0, Msg: "无需创建任务,加入橱窗成功", Data: nil}
|
|
|
+ } else { //不存在报名信息
|
|
|
+ //创建并插入报名信息
|
|
|
+ code := youngee_sectask_service.SignUpSecTaskFromWindow(r).Code
|
|
|
+ if code != 0 {
|
|
|
+ fmt.Println("错误代码为----》", code)
|
|
|
+ }
|
|
|
+ //加入橱窗
|
|
|
+ _, err := merchant.AddItemsToShelf(ClientKey, SignSecret, accessToken, pIdSlice)
|
|
|
+ if err != nil {
|
|
|
+ //表示添加失敗,沒有開通
|
|
|
+ return &TalentHttpResult{Code: -1, Msg: "快手未開通橱窗、商品不存在或已下线", Data: nil}
|
|
|
+ }
|
|
|
+ // 查询成功,返回成功结果和数据
|
|
|
+ return &TalentHttpResult{Code: 0, Msg: "创建了任务,加入橱窗成功", Data: nil}
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
func AddWindow(r *ghttp.Request) *TalentHttpResult {
|
|
@@ -334,50 +620,6 @@ func QueryOkSaleNum(r *ghttp.Request) *TalentHttpResult {
|
|
|
return &TalentHttpResult{Code: 0, Msg: "获取30天销售量成功", Data: saleNum}
|
|
|
}
|
|
|
|
|
|
-func DyLikeCount(r *ghttp.Request) *TalentHttpResult {
|
|
|
- tid, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
|
|
|
- // 创建一个 KuaishouUserInfo 结构体的实例
|
|
|
- userInfo := &youngee_talent_model.KuaishouUserInfo{}
|
|
|
-
|
|
|
- // 查询数据库中的 access_token 字段
|
|
|
- // 使用 g.DB() 获取数据库连接,并执行查询
|
|
|
- key, err := g.DB().Model(userInfo).Fields("access_token").Where("talent_id = ? AND platform_id = ?", tid, 2).Value()
|
|
|
- AccessToken := key.String()
|
|
|
- if err != nil {
|
|
|
- // 处理错误
|
|
|
- fmt.Println("Error querying access_token:", err)
|
|
|
- }
|
|
|
- if key == nil {
|
|
|
- // 处理错误
|
|
|
- fmt.Println("can not find talentId's bindinfo :", err)
|
|
|
- }
|
|
|
- //todo : API
|
|
|
- count, err := GetLikeCount(ClientKey1, AccessToken)
|
|
|
- return &TalentHttpResult{Code: 0, Msg: "获取总点赞数成功", Data: count}
|
|
|
-}
|
|
|
-
|
|
|
-func DyVideoCount(r *ghttp.Request) *TalentHttpResult {
|
|
|
- tid, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
|
|
|
- // 创建一个 KuaishouUserInfo 结构体的实例
|
|
|
- userInfo := &youngee_talent_model.KuaishouUserInfo{}
|
|
|
-
|
|
|
- // 查询数据库中的 access_token 字段
|
|
|
- // 使用 g.DB() 获取数据库连接,并执行查询
|
|
|
- key, err := g.DB().Model(userInfo).Fields("access_token").Where("talent_id = ? AND platform_id = ?", tid, 2).Value()
|
|
|
- AccessToken := key.String()
|
|
|
- if err != nil {
|
|
|
- // 处理错误
|
|
|
- fmt.Println("Error querying access_token:", err)
|
|
|
- }
|
|
|
- if key == nil {
|
|
|
- // 处理错误
|
|
|
- fmt.Println("can not find talentId's bindinfo :", err)
|
|
|
- }
|
|
|
- //todo : API
|
|
|
- count, err := GetLikeCount(ClientKey1, AccessToken)
|
|
|
- return &TalentHttpResult{Code: 0, Msg: "获取总点赞数成功", Data: count}
|
|
|
-}
|
|
|
-
|
|
|
func VideoCount(r *ghttp.Request) *TalentHttpResult {
|
|
|
tid, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
|
|
|
// 创建一个 KuaishouUserInfo 结构体的实例
|
|
@@ -511,28 +753,85 @@ func GetKuaishouList(r *ghttp.Request) *TalentHttpResult {
|
|
|
return &TalentHttpResult{Code: 1, Msg: "返回快手列表成功", Data: ksListResult}
|
|
|
}
|
|
|
|
|
|
-// 获取用户快手平台账号列表
|
|
|
-func GetKuaishouListWithCondition(r *ghttp.Request) *TalentHttpResult {
|
|
|
- // 从 session 中获取 talent_id
|
|
|
- tid, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
|
|
|
- userInfo := &youngee_talent_model.KuaishouUserInfo{}
|
|
|
- //1.获取该tid下的所有账户信息
|
|
|
-
|
|
|
- //2.openid去重,遍历userInfoMap<openid,userInfo>openid对应了两个accesstokn就都去验证是否过期
|
|
|
+// 获取用户快手电商过期信息 肯定绑定两个码,因为只是用于加入橱窗---我只检查电商是否过期
|
|
|
+func CheckKuaishouTokenExp(openId string) int {
|
|
|
+ fmt.Println("into checktoken")
|
|
|
+ //一个openId同时对应了8和4,才进行过期检查,两个都检查,有一个过期则过期
|
|
|
+ key, err := g.DB().Model("platform_kuaishou_user_info").Fields("access_token").Where("open_id = ? ", openId).Value()
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("query database fail")
|
|
|
+ return -1
|
|
|
+ }
|
|
|
+ AccessToken := key.String()
|
|
|
+ _, err = douyinUser.GetUserInfo(openId, AccessToken)
|
|
|
+ if err != nil { //过期
|
|
|
+ fmt.Println("平台accessToken过期")
|
|
|
+ return 1
|
|
|
+ } else {
|
|
|
+ fmt.Println("未过期")
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
- //3.openId对应的accessToken调用是否过期接口,过期则use_code=1
|
|
|
+func CheckDouyinTokenExp(openId string) int {
|
|
|
+ fmt.Println("into checktoken")
|
|
|
+ key, err := g.DB().Model("platform_kuaishou_user_info").Fields("access_token").Where("open_id = ? ", openId).Value()
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("query database fail")
|
|
|
+ return -1
|
|
|
+ }
|
|
|
+ AccessToken := key.String()
|
|
|
+ _, err = douyinUser.GetUserInfo(openId, AccessToken)
|
|
|
+ if err != nil { //过期
|
|
|
+ fmt.Println("平台accessToken过期")
|
|
|
+ return 1
|
|
|
+ } else {
|
|
|
+ fmt.Println("未过期")
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
- //4.调用是否已领取接口 ,领取则use_code=2
|
|
|
+func GetDouyinList(r *ghttp.Request) *TalentHttpResult {
|
|
|
+ // 获取达人对应的平台为2的列表,含基本信息
|
|
|
+ tid, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
|
|
|
+ userInfo := &youngee_talent_model.KuaishouUserInfo{}
|
|
|
+ results, err := g.DB().Model(userInfo).Where("talent_id = ?", tid).
|
|
|
+ Where("platform_Id IN (?)", 2).
|
|
|
+ All()
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Error querying ", err)
|
|
|
+ return &TalentHttpResult{Code: 0, Msg: "查询抖音列表失败", Data: nil}
|
|
|
+ }
|
|
|
|
|
|
- //5.领样条件(粉丝数+橱窗销量)不满足 use_code=3
|
|
|
+ // 创建一个存储用户信息的切片
|
|
|
+ updatedUserInfoList := []*youngee_talent_model.KuaishouUserInfo{}
|
|
|
|
|
|
- // 创建 KSListResult 变量并赋值
|
|
|
- ksListResult := &youngee_talent_model.KSListResult{
|
|
|
- Count: uniqueOpenIDCount,
|
|
|
- UserInfo: userInfoList,
|
|
|
- }
|
|
|
- // 返回结果
|
|
|
- return &TalentHttpResult{Code: 1, Msg: "返回快手列表成功", Data: ksListResult}
|
|
|
+ // 遍历列表,判断是否过期并更新 Expired 属性
|
|
|
+ for _, record := range results.List() {
|
|
|
+ openID := gconv.String(record["open_id"])
|
|
|
+ // 调用 CheckDouyinTokenExp 函数,获取过期状态 0/1
|
|
|
+ expiredStatus := CheckDouyinTokenExp(openID)
|
|
|
+
|
|
|
+ // 更新 record 中的 Expired 字段值
|
|
|
+ record["Expired"] = expiredStatus
|
|
|
+ err := gconv.Struct(record, userInfo)
|
|
|
+ if err != nil {
|
|
|
+ return nil
|
|
|
+ } // 将 map 转换为 KuaishouUserInfo 结构体
|
|
|
+
|
|
|
+ // 添加到用户信息列表
|
|
|
+ updatedUserInfoList = append(updatedUserInfoList, userInfo)
|
|
|
+
|
|
|
+ // 如果需要将更新后的 record 保存到数据库中,请取消注释以下代码
|
|
|
+ // if _, err := g.DB().Model(userInfo).Where("open_id = ?", openID).Data(record).Update(); err != nil {
|
|
|
+ // fmt.Println("Error updating Expired status: ", err)
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ // 返回 DYListResult 类型
|
|
|
+ return &TalentHttpResult{Code: 1, Msg: "返回抖音列表成功", Data: &youngee_talent_model.DYListResult{
|
|
|
+ Count: len(updatedUserInfoList),
|
|
|
+ UserInfo: updatedUserInfoList,
|
|
|
+ }}
|
|
|
}
|
|
|
|
|
|
func QuerySalesFor90Days(r *ghttp.Request) *TalentHttpResult {
|