|
@@ -3,11 +3,12 @@ package models
|
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/beego/beego/v2/client/orm"
|
|
|
+ "strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
-//报名
|
|
|
+// 报名
|
|
|
type CygxActivityMeetDetailLog struct {
|
|
|
AttendanceId int `orm:"column(attendance_id);pk;"description:"主键ID"`
|
|
|
ActivityId int `description:"活动ID"`
|
|
@@ -37,7 +38,7 @@ func GetOfflineMeetingDetailListCompanyName(companyName string) (item []*CygxAct
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//添加
|
|
|
+// 添加
|
|
|
func AddCygxActivityMeetDetailLog(item *CygxActivityMeetDetailLog) (lastId int64, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
lastId, err = o.Insert(item)
|
|
@@ -62,7 +63,7 @@ func GetActivityMeetDetailLogByMobile() (item []*CygxActivityMeetDetailLog, err
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//获取数量
|
|
|
+// 获取数量
|
|
|
func GetActivityMeetDetailLogCount(condition string) (count int, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
sqlCount := ` SELECT COUNT(1) AS count FROM cygx_activity_meet_detail_log WHERE 1=1 `
|
|
@@ -73,7 +74,7 @@ func GetActivityMeetDetailLogCount(condition string) (count int, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//修改公司参会数量
|
|
|
+// 修改公司参会数量
|
|
|
func UpdateActivityMeetDetailLog(companyName string, num int) (err error) {
|
|
|
sql := ` UPDATE cygx_activity_meet_detail_log SET company_meet_num= ? WHERE company_name = ?`
|
|
|
o := orm.NewOrm()
|
|
@@ -81,7 +82,7 @@ func UpdateActivityMeetDetailLog(companyName string, num int) (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//修改个人参会数量
|
|
|
+// 修改个人参会数量
|
|
|
func UpdateActivityMeetDetailLogByUser(mobile string, num int) (err error) {
|
|
|
sql := ` UPDATE cygx_activity_meet_detail_log SET user_meet_num= ? WHERE mobile = ?`
|
|
|
o := orm.NewOrm()
|
|
@@ -89,7 +90,7 @@ func UpdateActivityMeetDetailLogByUser(mobile string, num int) (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//添加线上到会记录(下载使用)
|
|
|
+// 添加线上到会记录(下载使用)
|
|
|
func AddCygxActivityMeetDetailLogOnline(list []*CygxActivityAttendanceDetail, activityId int) (err error) {
|
|
|
o, err := orm.NewOrm().Begin()
|
|
|
if err != nil {
|
|
@@ -167,7 +168,7 @@ func AddCygxActivityMeetDetailLogOnline(list []*CygxActivityAttendanceDetail, ac
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//添加线上到会记录
|
|
|
+// 添加线上到会记录
|
|
|
func AddCygxActivityMeetDetailLogOnlineByList(list []*CygxActivityAttendanceDetail, activityIds string) (err error) {
|
|
|
o, err := orm.NewOrm().Begin()
|
|
|
if err != nil {
|
|
@@ -255,3 +256,111 @@ func AddCygxActivityMeetDetailLogOnlineByList(list []*CygxActivityAttendanceDeta
|
|
|
fmt.Println("user_end")
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// 添加线下到会记录
|
|
|
+func AddCygxActivityMeetDetailLogOffline(activityId int) (err error) {
|
|
|
+ o := orm.NewOrm()
|
|
|
+ to, err := o.Begin()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ _ = to.Rollback()
|
|
|
+ } else {
|
|
|
+ _ = to.Commit()
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+ condition = ` AND activity_id = ? `
|
|
|
+ pars = append(pars, activityId)
|
|
|
+ listOfflineMeeting, err := GetOfflineMeetingList(condition, pars)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var meetingUids string
|
|
|
+ for _, v := range listOfflineMeeting {
|
|
|
+ meetingUids += strconv.Itoa(v.UserId) + ","
|
|
|
+ }
|
|
|
+ meetingUids = strings.TrimRight(meetingUids, ",")
|
|
|
+ if meetingUids == "" {
|
|
|
+ meetingUids = "-1"
|
|
|
+ }
|
|
|
+ var CompanyIdStr string
|
|
|
+ var MobileStr string
|
|
|
+ var items []*CygxActivityMeetDetailLog
|
|
|
+ list, err := GetOfflineMeetingListByUser(meetingUids, activityId)
|
|
|
+ fmt.Println(len(list))
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //删除原有数据
|
|
|
+ sql := ` DELETE FROM cygx_activity_meet_detail_log WHERE activity_id = ?`
|
|
|
+ _, err = to.Raw(sql, activityId).Exec()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //插入新的数据
|
|
|
+ for _, v := range list {
|
|
|
+ item := new(CygxActivityMeetDetailLog)
|
|
|
+ item.ActivityId = v.ActivityId
|
|
|
+ item.Mobile = v.Mobile
|
|
|
+ item.CompanyName = v.CompanyName
|
|
|
+ item.CompanyId = v.CompanyId
|
|
|
+ item.CreateTime = v.CreateTime
|
|
|
+ CompanyIdStr += strconv.Itoa(v.CompanyId) + ","
|
|
|
+ if v.Mobile != "" {
|
|
|
+ MobileStr += v.Mobile + ","
|
|
|
+ }
|
|
|
+ items = append(items, item)
|
|
|
+ }
|
|
|
+ CompanyIdStr = strings.TrimRight(CompanyIdStr, ",")
|
|
|
+ MobileStr = strings.TrimRight(MobileStr, ",")
|
|
|
+ for _, v := range items {
|
|
|
+ _, err = to.Insert(v)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ listCompanyId, err := GetOfflineMeetingDetailListCompanyIdStr(CompanyIdStr)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //修改公司对应的数量
|
|
|
+ //var condition string
|
|
|
+ for _, v := range listCompanyId {
|
|
|
+ var total int
|
|
|
+ condition = ` AND company_name = '` + v.CompanyName + `' `
|
|
|
+ total, err = GetActivityMeetDetailLogCount(condition)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ sql := ` UPDATE cygx_activity_meet_detail_log SET company_meet_num= ? WHERE company_name = ?`
|
|
|
+ _, err = to.Raw(sql, total, v.CompanyName).Exec()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ listMobile, err := GetActivityMeetDetailLog(MobileStr)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //修改个人对应的数量
|
|
|
+ for _, v := range listMobile {
|
|
|
+ var total int
|
|
|
+ condition = ` AND mobile = '` + v.Mobile + `' `
|
|
|
+ total, err = GetActivityMeetDetailLogCount(condition)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ sql := ` UPDATE cygx_activity_meet_detail_log SET user_meet_num= ? WHERE mobile = ?`
|
|
|
+ _, err = to.Raw(sql, total, v.Mobile).Exec()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|