activity_attendance_detail.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hongze_mfyx/utils"
  6. "time"
  7. )
  8. type CygxActivityAttendanceDetail struct {
  9. AttendanceId int `orm:"column(attendance_id);pk;"description:"主键ID"`
  10. ActivityId int `description:"活动ID"`
  11. RealName string `description:"姓名"`
  12. Mobile string `description:"手机号"`
  13. CompanyName string `description:"公司名称"`
  14. CompanyId int `description:"公司id 不在数据库的用户为0"`
  15. SellerName string `description:"销售姓名"`
  16. FirstMeetingTime string `description:"首次入会时间"`
  17. LastMeetingTime string `description:"最后退出时间"`
  18. Duration string `description:"参会时长"`
  19. MeetingTypeStr string `description:"参会方式"`
  20. MeetingAuthentication string `description:"参会权鉴"`
  21. MeetingStatusStr string `description:"参会状态"`
  22. CreateTime time.Time `description:"创建时间"`
  23. Position string `description:"职位"`
  24. IsMeetingStr int `description:"是否到会,1到会,0未到会"`
  25. UseridEntity int `description:"参会者身份. 1:主讲人, 2:主持人, 3:嘉宾, 4:普通参会者, 5:联席主讲人, 6:会议助理"`
  26. ActivityTime string `description:"活动时间"`
  27. CrmCompanyMapStatusId int `description:"转换后的对应状态信息:1=正式客户, 2=曾使用客户, 3=其他"`
  28. }
  29. // 添加会议提醒信息
  30. func AddCygxActivityAttendanceDetail(item *CygxActivityAttendanceDetail) (lastId int64, err error) {
  31. o, err := orm.NewOrm().Begin()
  32. defer func() {
  33. fmt.Println(err)
  34. if err == nil {
  35. o.Commit()
  36. } else {
  37. o.Rollback()
  38. }
  39. }()
  40. var count int
  41. var countMySchedule int
  42. sql := `SELECT COUNT(1) AS count FROM cygx_my_schedule WHERE user_id=? AND activity_id=? `
  43. err = o.Raw(sql, item, item.ActivityId).QueryRow(&countMySchedule)
  44. if err != nil {
  45. return
  46. }
  47. if countMySchedule == 0 {
  48. itemMy := new(CygxMySchedule)
  49. itemMy.ActivityId = item.ActivityId
  50. itemMy.CreateTime = time.Now()
  51. itemMy.Mobile = item.Mobile
  52. itemMy.CompanyId = item.CompanyId
  53. itemMy.CompanyName = item.CompanyName
  54. lastId, err = o.Insert(itemMy)
  55. if err != nil {
  56. return
  57. }
  58. }
  59. sql = `SELECT COUNT(1) AS count FROM cygx_activity_meeting_reminder WHERE user_id=? AND activity_id=? `
  60. err = o.Raw(sql, item, item.ActivityId).QueryRow(&count)
  61. if err != nil {
  62. return
  63. }
  64. if count > 0 {
  65. sql := `UPDATE cygx_activity_meeting_reminder SET is_cancel = 0 WHERE user_id=? AND activity_id=? `
  66. _, err = o.Raw(sql, item, item.ActivityId).Exec()
  67. } else {
  68. lastId, err = o.Insert(item)
  69. }
  70. itemLog := new(CygxActivityMeetingReminderLog)
  71. //itemLog.UserId = item.UserId
  72. itemLog.ActivityId = item.ActivityId
  73. itemLog.CreateTime = time.Now()
  74. itemLog.Mobile = item.Mobile
  75. //itemLog.Email = item.Email
  76. itemLog.CompanyId = item.CompanyId
  77. itemLog.CompanyName = item.CompanyName
  78. itemLog.Type = 1
  79. lastId, err = o.Insert(itemLog)
  80. return
  81. }
  82. func AddAttendancDetail(items []*CygxActivityAttendanceDetail, activityId int, mobileStr string) (err error) {
  83. if len(items) == 0 {
  84. return
  85. }
  86. o := orm.NewOrm()
  87. //修改活动是否上传到会信息字段
  88. sql := `UPDATE cygx_activity SET is_submit_meeting=1 WHERE activity_id=? `
  89. _, err = o.Raw(sql, activityId).Exec()
  90. if err != nil {
  91. return
  92. }
  93. //修改单个报名信息是否到会
  94. sql = `UPDATE cygx_activity_signup SET is_meeting=0 WHERE activity_id=? `
  95. _, err = o.Raw(sql, activityId).Exec()
  96. if err != nil {
  97. return
  98. }
  99. sql = `UPDATE cygx_activity_signup SET is_meeting=1 WHERE activity_id=? AND ( outbound_mobile IN (` + mobileStr + `) OR mobile IN (` + mobileStr + `) )`
  100. _, err = o.Raw(sql, activityId).Exec()
  101. if err != nil {
  102. return
  103. }
  104. //二次上传时删除原有数据
  105. sql = ` DELETE FROM cygx_activity_attendance_detail WHERE activity_id = ?`
  106. _, err = o.Raw(sql, activityId).Exec()
  107. if err != nil {
  108. return
  109. }
  110. //
  111. ////插入提交信息
  112. //for _, v := range items {
  113. // _, err = o.Insert(v)
  114. // if err != nil {
  115. // return
  116. // }
  117. //}
  118. _, err = o.InsertMulti(len(items), items)
  119. return
  120. }
  121. // 获取用户参会列表
  122. func GetRoadshowDataList(title, findStartDate, findEndDate string) (list []*RoadshowData, err error) {
  123. o := orm.NewOrmUsingDB("comein_data")
  124. sql := `SELECT * FROM roadshow_data WHERE roadshow_title LIKE '%` + title + `%' AND roadshow_begin_time >= '` + findStartDate + `' AND roadshow_begin_time <= '` + findEndDate + `'`
  125. _, err = o.Raw(sql).QueryRows(&list)
  126. return
  127. }
  128. // 获取这个时段内的进门财经参会活动
  129. func GetRoadshowDataListByDateTime(findStartDate, findEndDate string) (list []*RoadshowData, err error) {
  130. o := orm.NewOrmUsingDB("comein_data")
  131. sql := `SELECT * FROM roadshow_data WHERE roadshow_begin_time >= '` + findStartDate + `' AND roadshow_begin_time <= '` + findEndDate + `' GROUP BY roadshow_title `
  132. _, err = o.Raw(sql).QueryRows(&list)
  133. return
  134. }
  135. type WxUserOutboundMobile struct {
  136. RealName string `description:"姓名"`
  137. Mobile string `description:"手机号"`
  138. OutboundMobile string `description:"外呼手机号"`
  139. CompanyId int `description:"公司ID"`
  140. CompanyName string `description:"公司名称"`
  141. SellerName string `description:"所属销售"`
  142. }
  143. func GetWxUserOutboundMobile(mobileStr string) (item []*WxUserOutboundMobile, err error) {
  144. o := orm.NewOrmUsingDB("weekly_report")
  145. sql := `SELECT u.real_name,u.mobile,u.outbound_mobile,u.company_id,p.company_name ,GROUP_CONCAT( DISTINCT p.seller_name SEPARATOR '/' ) AS seller_name
  146. FROM wx_user as u
  147. INNER JOIN company_product AS p ON p.company_id = u.company_id
  148. WHERE outbound_mobile IN (` + mobileStr + `) OR mobile IN (` + mobileStr + `) GROUP BY u.user_id`
  149. _, err = o.Raw(sql).QueryRows(&item)
  150. return
  151. }
  152. // 我的日程列表
  153. func GetActivityAttendanceDetailList(activityIds string) (items []*CygxActivityAttendanceDetail, err error) {
  154. o := orm.NewOrm()
  155. sql := `SELECT * FROM cygx_activity_attendance_detail WHERE activity_id IN (` + activityIds + `) `
  156. _, err = o.Raw(sql).QueryRows(&items)
  157. return
  158. }
  159. // 我的日程列表
  160. func GetActivityAttendanceDetailListAll() (items []*CygxActivityAttendanceDetail, err error) {
  161. o := orm.NewOrm()
  162. sql := `SELECT * FROM cygx_activity_attendance_detail WHERE activity_id >= 1000 ORDER BY activity_id ASC `
  163. _, err = o.Raw(sql).QueryRows(&items)
  164. return
  165. }
  166. // 列表
  167. func GetActivityAttendanceDetailListCondition(condition string, pars []interface{}) (items []*CygxActivityAttendanceDetail, err error) {
  168. o := orm.NewOrm()
  169. sql := `SELECT * FROM cygx_activity_attendance_detail WHERE 1= 1 `
  170. if condition != "" {
  171. sql += condition
  172. }
  173. _, err = o.Raw(sql, pars).QueryRows(&items)
  174. return
  175. }
  176. func AddAttendancDetailNew(items []*CygxActivityAttendanceDetail, activityIds []int) (err error) {
  177. if len(items) == 0 {
  178. return
  179. }
  180. o := orm.NewOrm()
  181. //修改活动是否上传到会信息字段
  182. sql := `UPDATE cygx_activity SET is_submit_meeting=1 WHERE activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `) `
  183. _, err = o.Raw(sql, activityIds).Exec()
  184. if err != nil {
  185. return
  186. }
  187. _, err = o.InsertMulti(len(items), items)
  188. return
  189. }