|
@@ -3,6 +3,7 @@ package services
|
|
|
import (
|
|
|
"context"
|
|
|
"encoding/json"
|
|
|
+ "errors"
|
|
|
"fmt"
|
|
|
"hongze/hongze_cygx/models"
|
|
|
"hongze/hongze_cygx/utils"
|
|
@@ -134,7 +135,7 @@ func GetYiDongToken() (token string, err error) {
|
|
|
utils.FileLog.Info(err.Error())
|
|
|
}
|
|
|
}()
|
|
|
- cacheKey := utils.YD_TOKEN
|
|
|
+ cacheKey := utils.YI_DONG_ZHENG_TONG_YUN_TOKEN_KEY
|
|
|
ttlTime := utils.Rc.GetRedisTTL(cacheKey)
|
|
|
if ttlTime > 0 {
|
|
|
token, _ = utils.Rc.RedisString(cacheKey)
|
|
@@ -245,6 +246,19 @@ func GetYiDongActivity(cont context.Context) (err error) {
|
|
|
mapOldYiDong[v.YidongActivityId] = v.YidongActivityId
|
|
|
mapOldYiDongBody[v.YidongActivityId] = fmt.Sprint(v.ActivityName, v.Label, v.ChartPermissionId, v.ActivityTime, v.YidongActivityEndTime, v.DistinguishedGuest)
|
|
|
}
|
|
|
+
|
|
|
+ // 通过查研观向观向建会的易董活动
|
|
|
+ yiDongByCygxList, err := models.GetActivityListByYiDongByCygx()
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ utils.FileLog.Info(string(err.Error()))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ yiDongByCygxMap := make(map[string]string)
|
|
|
+ for _, v := range yiDongByCygxList {
|
|
|
+ yiDongByCygxMap[v.YidongActivityIdByCygx] = v.YidongActivityIdByCygx
|
|
|
+ }
|
|
|
+
|
|
|
var itemsAdd []*models.CygxActivity
|
|
|
if len(ApifoxModal.Result) > 0 {
|
|
|
actList := ApifoxModal.Result
|
|
@@ -253,6 +267,10 @@ func GetYiDongActivity(cont context.Context) (err error) {
|
|
|
if v.SyncFlag == "0" {
|
|
|
continue
|
|
|
}
|
|
|
+ //如果是通过查研观向观向建会的易董活动,就不进行更新的操作
|
|
|
+ if _, ok := yiDongByCygxMap[v.ID]; ok {
|
|
|
+ continue
|
|
|
+ }
|
|
|
var item = new(models.CygxActivity)
|
|
|
item.YidongActivityId = v.ID
|
|
|
item.ActivityTypeId = 3
|
|
@@ -524,46 +542,27 @@ func GetActivityTextTime(timeYidong string) (timeText string) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func init232() {
|
|
|
- //YidongActivityGroup("美团", 1623)
|
|
|
- //GetYiDongActivityMeeting()
|
|
|
- //GetYiDongActivity()
|
|
|
- //var timeText string
|
|
|
- //strTime := "2022-08-18 12:34:00"
|
|
|
- //startTime := utils.StrTimeToTime(strTime)
|
|
|
- //week := utils.StrDateTimeToWeek(strTime)
|
|
|
- //timeStrYmd := startTime.Format(utils.FormatDate)
|
|
|
- //timeStrHmm := startTime.Format(utils.FormatTime)
|
|
|
- //timeYmd := utils.StrTimeToTime(timeStrYmd + " 12:00:00") //拼接当天中午12点的时间
|
|
|
- //var amOrPm string
|
|
|
- //if startTime.After(timeYmd) {
|
|
|
- // amOrPm = " PM"
|
|
|
- //} else {
|
|
|
- // amOrPm = " AM"
|
|
|
- //}
|
|
|
- //timeText = timeStrYmd + "(" + week + ")" + timeStrHmm
|
|
|
- //fmt.Println(week)
|
|
|
- //fmt.Println(amOrPm)
|
|
|
- //fmt.Println(strTime)
|
|
|
- //fmt.Println(timeText)
|
|
|
-}
|
|
|
+//func init() {
|
|
|
+// GetYiDongActivityMeeting()
|
|
|
+//}
|
|
|
|
|
|
// GetYiDongActivityMeeting获取易董到会详情
|
|
|
func GetYiDongActivityMeeting(cont context.Context) (err error) {
|
|
|
+ //func GetYiDongActivityMeeting() (err error) {
|
|
|
var condition string
|
|
|
-
|
|
|
- startDate := time.Now().AddDate(0, 0, -2).Format(utils.FormatDateTime)
|
|
|
+ startDate := time.Now().AddDate(0, 0, -1).Format(utils.FormatDateTime)
|
|
|
endDate := time.Now().Add(-time.Minute * 120).Format(utils.FormatDateTime)
|
|
|
condition += ` AND activity_time > ` + "'" + startDate + "'"
|
|
|
condition += ` AND activity_time < ` + "'" + endDate + "'"
|
|
|
//fmt.Println(startDate)
|
|
|
- //fmt.Println(endDate)
|
|
|
- condition = ` `
|
|
|
+
|
|
|
artivityListYidong, err := models.GetActivityListByYidong(condition)
|
|
|
if err != nil {
|
|
|
fmt.Println("GetActivityListByYidong Err:", err.Error())
|
|
|
return err
|
|
|
}
|
|
|
+ //fmt.Println(artivityListYidong)
|
|
|
+ //return
|
|
|
//fmt.Println("artivityListYidong", artivityListYidong)
|
|
|
//return err
|
|
|
if len(artivityListYidong) == 0 {
|
|
@@ -579,9 +578,16 @@ func GetYiDongActivityMeeting(cont context.Context) (err error) {
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
+ var yidongActivityId string
|
|
|
+ if v.YidongActivityId != "" {
|
|
|
+ yidongActivityId = v.YidongActivityId
|
|
|
+ } else if v.YidongActivityIdByCygx != "" {
|
|
|
+ yidongActivityId = v.YidongActivityIdByCygx
|
|
|
+ }
|
|
|
+
|
|
|
url := utils.YiDongZhengTongYunUrl + "interact/activityManageApi/getAttendPersonList?access_token=" + token
|
|
|
method := "POST"
|
|
|
- payload := strings.NewReader(`{"activityId":"` + v.YidongActivityId + `"}`)
|
|
|
+ payload := strings.NewReader(`{"activityId":"` + yidongActivityId + `"}`)
|
|
|
client := &http.Client{}
|
|
|
req, err := http.NewRequest(method, url, payload)
|
|
|
if err != nil {
|
|
@@ -614,15 +620,17 @@ func GetYiDongActivityMeeting(cont context.Context) (err error) {
|
|
|
}
|
|
|
|
|
|
//跟易董返回的用户状态修改活动以提交到会状态
|
|
|
- err = models.UpdateCygxActivitySubmitMeetingByYidong(v.YidongActivityId)
|
|
|
+ err = models.UpdateCygxActivitySubmitMeetingByYidong(yidongActivityId)
|
|
|
if err != nil {
|
|
|
fmt.Println("UpdateCygxActivitySubmitMeetingByYidong Err:", err.Error())
|
|
|
return err
|
|
|
}
|
|
|
var mobiles []string
|
|
|
+ var mobileStr string
|
|
|
+ mapActivityAttendanceDetail := make(map[string]*models.CygxActivityAttendanceDetail)
|
|
|
if len(ApifoxModal.Result) > 0 {
|
|
|
itemlog := new(models.CygxYidongActivityMeetingApiLog)
|
|
|
- itemlog.YidongActivityId = v.YidongActivityId
|
|
|
+ itemlog.YidongActivityId = yidongActivityId
|
|
|
itemlog.Data = string(body)
|
|
|
itemlog.CreateTime = time.Now()
|
|
|
err = models.AddCygxYidongActivityMeetingApiLog(itemlog)
|
|
@@ -631,7 +639,7 @@ func GetYiDongActivityMeeting(cont context.Context) (err error) {
|
|
|
return err
|
|
|
}
|
|
|
var itemsUpdate []*models.CygxActivitySignupDetail
|
|
|
-
|
|
|
+ needAddAttendanc := make([]*models.CygxActivityAttendanceDetail, 0)
|
|
|
for _, vresult := range ApifoxModal.Result {
|
|
|
if vresult.EndTime != "" {
|
|
|
mobiles = append(mobiles, vresult.PersonTelephone)
|
|
@@ -648,10 +656,14 @@ func GetYiDongActivityMeeting(cont context.Context) (err error) {
|
|
|
itemDetail.Duration = vresult.Duration
|
|
|
itemDetail.IsMeeting = 1
|
|
|
itemDetail.ActivityId = v.ActivityId
|
|
|
+ mapActivityAttendanceDetail[vresult.PersonTelephone] = new(models.CygxActivityAttendanceDetail)
|
|
|
+ mapActivityAttendanceDetail[vresult.PersonTelephone].FirstMeetingTime = vresult.StartTime
|
|
|
+ mapActivityAttendanceDetail[vresult.PersonTelephone].LastMeetingTime = vresult.EndTime
|
|
|
+ mapActivityAttendanceDetail[vresult.PersonTelephone].Duration = utils.GetAttendanceDetailSecondsByYiDong(vresult.Duration)
|
|
|
itemsUpdate = append(itemsUpdate, itemDetail)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ fmt.Println(mobiles)
|
|
|
lenmobiles := len(mobiles)
|
|
|
if lenmobiles > 0 {
|
|
|
var parsYd []interface{}
|
|
@@ -668,9 +680,73 @@ func GetYiDongActivityMeeting(cont context.Context) (err error) {
|
|
|
fmt.Println("UpdateActivitySignupDetailMultiByYiDong Err:", err.Error())
|
|
|
return err
|
|
|
}
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+ condition = ` AND do_fail_type = 0 AND mobile IN (` + utils.GetOrmInReplace(lenmobiles) + `) AND activity_id = ?`
|
|
|
+ pars = append(pars, mobiles, v.ActivityId)
|
|
|
+ listSignup, e := models.GetActivitySignupList(condition, pars)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetActivitySignupList, Err: " + e.Error())
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, vSignup := range listSignup {
|
|
|
+ item := new(models.CygxActivityAttendanceDetail)
|
|
|
+ item.ActivityId = vSignup.ActivityId
|
|
|
+ item.RealName = vSignup.RealName
|
|
|
+ item.Mobile = vSignup.Mobile
|
|
|
+ item.CompanyName = vSignup.CompanyName
|
|
|
+ if mapActivityAttendanceDetail[vSignup.Mobile] != nil {
|
|
|
+ item.FirstMeetingTime = mapActivityAttendanceDetail[vSignup.Mobile].FirstMeetingTime
|
|
|
+ item.LastMeetingTime = mapActivityAttendanceDetail[vSignup.Mobile].LastMeetingTime
|
|
|
+ item.Duration = mapActivityAttendanceDetail[vSignup.Mobile].Duration
|
|
|
+ item.IsMeetingStr = 1
|
|
|
+ mobileStr += "'" + vSignup.Mobile + "'" + ","
|
|
|
+ }
|
|
|
+ item.CreateTime = time.Now()
|
|
|
+ needAddAttendanc = append(needAddAttendanc, item)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ mobileStr = strings.TrimRight(mobileStr, ",")
|
|
|
+ if mobileStr == "" {
|
|
|
+ mobileStr = "1"
|
|
|
+ }
|
|
|
+ listUser, err := models.GetWxUserOutboundMobile(mobileStr)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("GetWxUserOutboundMobile Err:", err.Error())
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ for k, v := range needAddAttendanc {
|
|
|
+ for _, v2 := range listUser {
|
|
|
+ if v2.OutboundMobile == v.Mobile || v2.Mobile == v.Mobile {
|
|
|
+ if needAddAttendanc[k].CompanyId == 0 {
|
|
|
+ needAddAttendanc[k].CompanyId = v2.CompanyId
|
|
|
+ needAddAttendanc[k].SellerName = v2.SellerName
|
|
|
+ needAddAttendanc[k].CompanyName = v2.CompanyName
|
|
|
+ needAddAttendanc[k].IsMeetingStr = 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //fmt.Println(mobileStr)
|
|
|
+ //参会记录
|
|
|
+ err = models.AddAttendancDetail(needAddAttendanc, v.ActivityId, mobileStr)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("AddAttendancDetail Err:", err.Error())
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ ////处理是否限制报名
|
|
|
+ err = AddCygxActivityRestrictSignupByAdmin(v.ActivityId)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("AddCygxActivityRestrictSignupByAdmin Err:", err.Error())
|
|
|
+ return err
|
|
|
}
|
|
|
+
|
|
|
+ go AddctivitySignupDetailByJmcj(needAddAttendanc, v.ActivityId)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -718,3 +794,121 @@ func YidongActivityGroup(subjectName string, activityId int) (err error) {
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// 会前一小时将,报名信息同步到易董
|
|
|
+func YiDongSignAppointmentsForThird(cont context.Context) (err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ go utils.SendAlarmMsg("会前一小时将,报名信息同步到易董,同步失败"+err.Error(), 2)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ var pars []interface{}
|
|
|
+ var condition string
|
|
|
+ startDate := time.Now().Add(+time.Minute * 45).Format(utils.FormatDateTime)
|
|
|
+ endDate := time.Now().Add(+time.Minute * 60).Format(utils.FormatDateTime)
|
|
|
+ condition = " AND yidong_activity_id_by_cygx != '' AND activity_time BETWEEN ? AND ? "
|
|
|
+ pars = append(pars, startDate, endDate)
|
|
|
+ activityList, err := models.GetActivityListByCondition(condition, pars)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ url := utils.YiDongHuaWeiYunUrl + "app/hz/signAppointmentsForThird"
|
|
|
+ var outCallStatus string
|
|
|
+ for _, v := range activityList {
|
|
|
+ var parsSignUp []interface{}
|
|
|
+ var conditionSignUp string
|
|
|
+ conditionSignUp += ` AND activity_id = ?`
|
|
|
+ parsSignUp = append(parsSignUp, v.ActivityId)
|
|
|
+ conditionSignUp += ` AND do_fail_type = 0 `
|
|
|
+ listSignUp, e := models.GetActivitySignuListByUser(conditionSignUp, parsSignUp)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetActivitySignuListByUser, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(listSignUp) == 0 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ for _, vS := range listSignUp {
|
|
|
+ if vS.SignupType == 1 {
|
|
|
+ outCallStatus = "1"
|
|
|
+ } else {
|
|
|
+ outCallStatus = "0"
|
|
|
+ }
|
|
|
+ params := SignAppointmentsForThirdParam{
|
|
|
+ ActivityId: v.YidongActivityIdByCygx,
|
|
|
+ MobileCountryCode: "+" + vS.CountryCode,
|
|
|
+ PersonTelephone: vS.OutboundMobile,
|
|
|
+ ThirdPartySource: "01",
|
|
|
+ InvestorType: "0",
|
|
|
+ PersonName: vS.RealName,
|
|
|
+ JoinRole: "2",
|
|
|
+ CompanyName: vS.CompanyName,
|
|
|
+ OutCallStatus: outCallStatus,
|
|
|
+ }
|
|
|
+ postData, e := json.Marshal(params)
|
|
|
+ if e != nil {
|
|
|
+ err = e
|
|
|
+ fmt.Println("PostData json.Marshal Err:" + err.Error())
|
|
|
+ utils.FileLog.Info("PostData json.Marshal Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ method := "POST"
|
|
|
+ client := &http.Client{}
|
|
|
+ req, e := http.NewRequest(method, url, strings.NewReader(string(postData)))
|
|
|
+ if e != nil {
|
|
|
+ err = e
|
|
|
+ fmt.Println(err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ req.Header.Add("Content-Type", "application/json")
|
|
|
+ res, e := client.Do(req)
|
|
|
+ if e != nil {
|
|
|
+ err = e
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer res.Body.Close()
|
|
|
+ body, e := ioutil.ReadAll(res.Body)
|
|
|
+ if e != nil {
|
|
|
+ err = e
|
|
|
+ return
|
|
|
+ }
|
|
|
+ itemApiLog := new(models.CygxThreeApiLog)
|
|
|
+ itemApiLog.CreateTime = time.Now()
|
|
|
+ itemApiLog.Source = 1
|
|
|
+ itemApiLog.Url = url
|
|
|
+ itemApiLog.Body = string(postData)
|
|
|
+ itemApiLog.Result = string(body)
|
|
|
+ go models.AddCygxThreeApiLog(itemApiLog)
|
|
|
+ var yidongResp *YiDongSignAppointmentsForThirdResp
|
|
|
+ err = json.Unmarshal(body, &yidongResp)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if !yidongResp.Success {
|
|
|
+ err = errors.New(" 会前一小时将,报名信息同步到易董,同步失败," + yidongResp.ErrorCode + yidongResp.ErrorMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+type SignAppointmentsForThirdParam struct {
|
|
|
+ ActivityId string `description:"易董活动ID" json:"activityId"`
|
|
|
+ MobileCountryCode string `description:"国际区号注意要带前面+号 " json:"mobileCountryCode"`
|
|
|
+ PersonTelephone string `description:"手机号" json:"personTelephone"`
|
|
|
+ ThirdPartySource string `description:"第三方来源;弘则固定:01" json:"thirdPartySource"`
|
|
|
+ InvestorType string `description:"投资者类型 0个人1机构" json:"investorType"`
|
|
|
+ PersonName string `description:"姓名" json:"personName"`
|
|
|
+ CompanyName string `description:"公司名" json:"companyName"`
|
|
|
+ JoinRole string `description:"1:嘉宾, 2:普通参会人员, 3:会议助理。不传默认取值2" json:"joinRole"`
|
|
|
+ OutCallStatus string `description:"1:需要,0:不需要。不传取默认值0" json:"outCallStatus"`
|
|
|
+}
|
|
|
+
|
|
|
+type YiDongSignAppointmentsForThirdResp struct {
|
|
|
+ ErrorCode string `json:"errorCode"` // 错误码,001:活动不存在;002:该活动不支持此渠道报名;003:该手机号或邮箱已经被其他账号提交报名;004:不在报名时间;005:报名人数已满
|
|
|
+ ErrorMsg string `json:"errorMsg"` // 错误信息
|
|
|
+ Success bool `json:"success"` // 成功标识,true:成功;false:失败。可作为判断报名是否成功的标识
|
|
|
+ Timestamp float64 `json:"timestamp"` // 时间戳
|
|
|
+}
|