|
@@ -73,14 +73,12 @@ func GetQrcode(r *ghttp.Request) *TalentHttpResult {
|
|
|
// 构建包含 tid 的 urlstr
|
|
|
var urlstr string
|
|
|
typePlatform := r.GetInt("platform_id")
|
|
|
- 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 { //快手平台
|
|
|
+ if typePlatform == 8 { //快手平台
|
|
|
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/douyinauth&scope=user_info,data.external.user,video.list.bind&response_type=code", tid)
|
|
|
+ urlstr = fmt.Sprintf("https://open.douyin.com/platform/oauth/connect/?state=%s&client_key=awi77xl5kpl16hmi&response_type=code&scope=user_info,data.external.user,video.list.bind&redirect_uri=https://www.younggee.com/douyinauth", tid)
|
|
|
} else {
|
|
|
- urlstr = "unknow"
|
|
|
+ return &TalentHttpResult{Code: -1, Msg: "platform_id值不合法"}
|
|
|
}
|
|
|
// 执行任务
|
|
|
//var buf []byte
|
|
@@ -115,7 +113,6 @@ func GetQrcode(r *ghttp.Request) *TalentHttpResult {
|
|
|
}
|
|
|
|
|
|
func GetKsEcomQrcode(r *ghttp.Request) *TalentHttpResult {
|
|
|
- fmt.Println("GetKsEcomQrcode-----")
|
|
|
//达人id获取
|
|
|
tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
|
|
|
fmt.Println("tid:", tid, "err:", err)
|
|
@@ -231,6 +228,8 @@ func HandleAfterRedirect(r *ghttp.Request) *TalentHttpResult {
|
|
|
}
|
|
|
//点击后授权成功
|
|
|
err = chromedp.Run(ctx, chromedp.Click(`#root > div > div > div > div > div.flex.f-jc-c.UcUNDIrRp1R3a9EnEbQE > div > div.f-1.f-fs-0.Zcms9k6vZGxKICWMIrdG > div.wNrvV7C_9L5FB2oxmyLe > button`))
|
|
|
+ fmt.Println("ok")
|
|
|
+
|
|
|
} else {
|
|
|
fmt.Println("已经被后端API捕捉。")
|
|
|
fmt.Println("currentURL-----:", currentURL)
|
|
@@ -322,12 +321,12 @@ func CheckDyNewAccount(r *ghttp.Request) *TalentHttpResult {
|
|
|
func CheckKsNewAccount(r *ghttp.Request) *TalentHttpResult {
|
|
|
//check到了更新时间在两秒内的插入的数据。则说明已绑定。弹窗消失。
|
|
|
tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
|
|
|
- if err != nil {
|
|
|
- return &TalentHttpResult{Code: -2, Msg: "Get talent id failed"}
|
|
|
- }
|
|
|
redisKsBindStatusKey := fmt.Sprintf("KsBind:%s", tid)
|
|
|
bindStatus, err := g.Redis().DoVar("GET", redisKsBindStatusKey)
|
|
|
- if bindStatus.String() == "bound_to_other" {
|
|
|
+ //if bindStatus == nil {
|
|
|
+ //
|
|
|
+ //}
|
|
|
+ if bindStatus != nil && bindStatus.String() == "bound_to_other" {
|
|
|
return &TalentHttpResult{Code: -1, Msg: "此快手账号已被其他达人绑定", Data: nil}
|
|
|
}
|
|
|
if err != nil {
|
|
@@ -348,6 +347,8 @@ func CheckKsNewAccount(r *ghttp.Request) *TalentHttpResult {
|
|
|
//当前达人没有绑定过账号
|
|
|
if len(userInfos) == 0 {
|
|
|
// 如果没有符合条件的数据,返回失败
|
|
|
+ // 如果没有符合条件的数据,返回继续轮询的提示
|
|
|
+ return &TalentHttpResult{Code: -5, Msg: "没有数据,继续轮询"}
|
|
|
}
|
|
|
|
|
|
// 找到 CreateTime 最新的记录
|
|
@@ -365,7 +366,7 @@ func CheckKsNewAccount(r *ghttp.Request) *TalentHttpResult {
|
|
|
}
|
|
|
|
|
|
// 超过时间差,返回失败
|
|
|
- return &TalentHttpResult{Code: -6, Msg: "Time difference exceeds 3 seconds"}
|
|
|
+ return &TalentHttpResult{Code: -2, Msg: "数据还没进来,继续轮训"}
|
|
|
}
|
|
|
|
|
|
func CheckTokenExp(openId string, platformId int, talentId string) int {
|
|
@@ -486,7 +487,7 @@ func AddWindowKuaishouList(r *ghttp.Request) *TalentHttpResult {
|
|
|
openIdMap[record.OpenId] = append(openIdMap[record.OpenId], record)
|
|
|
}
|
|
|
|
|
|
- // 筛选出 open_id 对应两条数据且 platform_id = 4 的记录
|
|
|
+ //筛选出 open_id 对应两条数据且 platform_id = 4 的记录
|
|
|
var resInfo []*youngee_talent_model.KuaishouUserInfo
|
|
|
for _, records := range openIdMap {
|
|
|
if len(records) == 2 { // 确保有两条数据,排除只有一个 platform_id 的情况
|
|
@@ -510,14 +511,15 @@ func AddWindowKuaishouList(r *ghttp.Request) *TalentHttpResult {
|
|
|
|
|
|
func SignUpSecKuaishouList(r *ghttp.Request) *TalentHttpResult {
|
|
|
selectionId := r.GetString("selection_id")
|
|
|
- // 定义用于存储查询结果的结构体切片
|
|
|
- var results []*youngee_talent_model.KuaishouUserInfo
|
|
|
+ //领样条件
|
|
|
+ //todo
|
|
|
+ var recruitStrategies []*youngee_talent_model.FreeStrategy
|
|
|
+ err := g.DB().Model("free_strategy").Where("selection_id = ?", selectionId).Scan(&recruitStrategies)
|
|
|
|
|
|
- // 获取talent_id
|
|
|
+ var results []*youngee_talent_model.KuaishouUserInfo
|
|
|
tid, _ := utils.SessionTalentInfo.GetTalentIdFromSession(r)
|
|
|
-
|
|
|
// 查询此达人下,platform_id 为 8 或 4 的所有数据,并将结果扫描到结构体切片中
|
|
|
- err := g.DB().Model(&youngee_talent_model.KuaishouUserInfo{}).
|
|
|
+ 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 的数据排在前面
|
|
@@ -547,7 +549,7 @@ func SignUpSecKuaishouList(r *ghttp.Request) *TalentHttpResult {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- // 遍历 resInfo 检查过期和是否报名
|
|
|
+ // 遍历 resInfo 检查过期、是否报名、是否满足领养条件
|
|
|
for _, record := range resInfo {
|
|
|
// 调用 CheckKuaishouTokenExp 函数,检查 openId 是否过期
|
|
|
expired := CheckKuaishouTokenExp(record.OpenId)
|
|
@@ -561,42 +563,36 @@ func SignUpSecKuaishouList(r *ghttp.Request) *TalentHttpResult {
|
|
|
} else {
|
|
|
record.IsSign = 1 // 查到数据,设置为 1
|
|
|
}
|
|
|
+ //fanNum := record.Fan
|
|
|
+ //saleNum30 := record.SaleNum30day
|
|
|
+ //todo
|
|
|
|
|
|
}
|
|
|
- return &TalentHttpResult{Code: 0, Msg: "加入橱窗成功", Data: resInfo}
|
|
|
+ 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")
|
|
|
- selectionDetail := youngee_talent_model.SelectionDetail{}
|
|
|
- err2 := g.DB().Model("younggee_selection_info").Where("selection_id=?", selectionDetail.SelectionId).Scan(&selectionDetail)
|
|
|
- if err2 != nil {
|
|
|
- fmt.Println("err--", err2.Error())
|
|
|
+
|
|
|
+ var signSecTaskReq *youngee_talent_model.SignSecTaskFromWindowReq
|
|
|
+ err := r.ParseForm(&signSecTaskReq)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("err--", err.Error())
|
|
|
+ return &TalentHttpResult{Code: -1, Msg: "POST参数解析失败", Data: err.Error()}
|
|
|
}
|
|
|
- value, err := g.DB().Model("platform_kuaishou_user_info").Fields("open_id").Where("talent_id=? AND open_id = ?", tid, openId).Value()
|
|
|
+
|
|
|
+ value, err := g.DB().Model("platform_kuaishou_user_info").Fields("access_token").Where("talent_id=? AND open_id = ?", tid, signSecTaskReq.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)
|
|
|
+ pIdSlice := []string{signSecTaskReq.ProductId}
|
|
|
httpResult := youngee_sectask_service.IsCreateSecTask(r)
|
|
|
+
|
|
|
if httpResult.Code == 1 { //存在报名信息,仅添加橱窗
|
|
|
- updateData := g.Map{
|
|
|
- "enroll_num": selectionDetail.EnrollNum + 1, // enroll_num + 1
|
|
|
- }
|
|
|
- // 执行更新操作
|
|
|
- _, err = g.DB().Model("younggee_selection_info").Where("selection_id=?", selectionDetail.SelectionId).Data(updateData).Update()
|
|
|
- if err != nil {
|
|
|
- // 错误处理
|
|
|
- fmt.Println(err.Error())
|
|
|
- }
|
|
|
_, err := merchant.AddItemsToShelf(ClientKey, SignSecret, accessToken, pIdSlice)
|
|
|
if err != nil {
|
|
|
//表示添加失敗,沒有開通
|
|
@@ -605,11 +601,10 @@ func AddWindowWithKsAccount(r *ghttp.Request) *TalentHttpResult {
|
|
|
// 查询成功,返回成功结果和数据
|
|
|
return &TalentHttpResult{Code: 0, Msg: "无需创建任务,加入橱窗成功", Data: nil}
|
|
|
} else { //不存在报名信息
|
|
|
-
|
|
|
//创建并插入报名信息
|
|
|
code := youngee_sectask_service.SignUpSecTaskFromWindow(r).Code
|
|
|
if code != 0 {
|
|
|
- fmt.Println("错误代码为----》", code)
|
|
|
+ return &TalentHttpResult{Code: -1, Msg: "创建报名信息失败", Data: nil}
|
|
|
}
|
|
|
//加入橱窗
|
|
|
_, err := merchant.AddItemsToShelf(ClientKey, SignSecret, accessToken, pIdSlice)
|
|
@@ -617,7 +612,15 @@ func AddWindowWithKsAccount(r *ghttp.Request) *TalentHttpResult {
|
|
|
//表示添加失敗,沒有開通
|
|
|
return &TalentHttpResult{Code: -1, Msg: "快手未開通橱窗、商品不存在或已下线", Data: nil}
|
|
|
}
|
|
|
- // 查询成功,返回成功结果和数据
|
|
|
+ //报名人数加一
|
|
|
+ _, err = g.DB().Model("younggee_selection_info").
|
|
|
+ Where("selection_id=?", signSecTaskReq.SelectionId).
|
|
|
+ Increment("enroll_num", 1)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ // 错误处理
|
|
|
+ fmt.Println(err.Error())
|
|
|
+ }
|
|
|
return &TalentHttpResult{Code: 0, Msg: "创建了任务,加入橱窗成功", Data: nil}
|
|
|
}
|
|
|
|
|
@@ -835,7 +838,7 @@ func GetKuaishouList(r *ghttp.Request) *TalentHttpResult {
|
|
|
|
|
|
// 查询 platformId 为 8 或 4 的所有数据
|
|
|
results, err := g.DB().Model(userInfo).Where("talent_id = ?", tid).
|
|
|
- Where("platform_Id IN (?, ?)", 4, 8).
|
|
|
+ Where("platform_id IN (?, ?)", 4, 8).
|
|
|
Order("platform_Id DESC").
|
|
|
All()
|
|
|
if err != nil {
|
|
@@ -844,19 +847,20 @@ func GetKuaishouList(r *ghttp.Request) *TalentHttpResult {
|
|
|
}
|
|
|
|
|
|
// 检查查询结果是否为空
|
|
|
- if results.IsEmpty() {
|
|
|
+ if len(results) == 0 {
|
|
|
return &TalentHttpResult{Code: -2, Msg: "此达人无快手账号绑定", Data: nil}
|
|
|
}
|
|
|
|
|
|
// 使用集合来存储唯一的 open_id,并计算不同的 open_id 的个数
|
|
|
openIDSet := make(map[string]struct{})
|
|
|
+ //key--openId value--对应的信息
|
|
|
userInfoMap := make(map[string]*youngee_talent_model.KuaishouUserInfo)
|
|
|
|
|
|
for _, record := range results.List() {
|
|
|
openID := gconv.String(record["open_id"])
|
|
|
platformID := record["platform_id"] //int类型
|
|
|
status := 0 //初始化
|
|
|
- // 检查 userInfoMap 中是否已经存在 openID
|
|
|
+ //检查 userInfoMap 中是否已经存在 openID
|
|
|
//肯定会先处理8,所以遇到重复情况肯定是两个都授权了
|
|
|
_, exists := userInfoMap[openID]
|
|
|
if exists {
|
|
@@ -887,6 +891,9 @@ func GetKuaishouList(r *ghttp.Request) *TalentHttpResult {
|
|
|
OpenId: openID,
|
|
|
HeadUri: gconv.String(record["head_uri"]),
|
|
|
NickName: gconv.String(record["nick_name"]),
|
|
|
+ Skill: gconv.String(record["skill"]),
|
|
|
+ Gender: gconv.String(record["gender"]),
|
|
|
+
|
|
|
// 添加其他需要的字段
|
|
|
Fan: gconv.Int(record["fan"]),
|
|
|
//这两个值默认为0
|