activity.go 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hongze_cygx/utils"
  7. "strings"
  8. "time"
  9. )
  10. // 活动详情
  11. type CygxActivity struct {
  12. ActivityId int `orm:"column(activity_id);pk";description:"活动ID 等于0新增活动,大于0修改活动"`
  13. ActivityTypeId int `description:"活动类型id"`
  14. ActivityTypeName string `description:"活动类型名称"`
  15. ChartPermissionId int `description:"行业id"`
  16. ChartPermissionName string `description:"行业名称"`
  17. ChartPermissionNames string `description:"行业名称辅助字段,区分研选子分类"`
  18. Body string `description:"内容"`
  19. CreateTime time.Time `description:"创建时间"`
  20. IsLimitPeople int `description:"是否限制人数 1是,0否"`
  21. LimitPeopleNum int `description:"限制的人数数量"`
  22. CustomerTypeIds string `description:"活动可见的客户类型,多个ID用 , 隔开"`
  23. PublishStatus int `description:"发布状态 1已发布,0未发布"`
  24. LastUpdatedTime time.Time `description:"更新时间"`
  25. ActivityTime string `description:"活动时间"`
  26. ActivityTimeText string `description:"活动时间带文字"`
  27. DistinguishedGuest string `description:"嘉宾"`
  28. Host string `description:"主持人"`
  29. MainlandTell string `description:"大陆拨入号"`
  30. HongKongTell string `description:"香港拨入号"`
  31. TaiwanTell string `description:"台湾拨入号"`
  32. AmericaTell string `description:"美国拨入号"`
  33. ParticipationCode string `description:"参会密码"`
  34. Theme string `description:"主题"`
  35. Expert string `description:"专家"`
  36. ActivityName string `description:"活动名称"`
  37. ActivityNameTask string `description:"活动名称定时任务同步的时候使用"`
  38. OnlineParticipation string `description:"网络参会"`
  39. ReportLink string `description:"报告链接"`
  40. City string `description:"城市"`
  41. Address string `description:"活动地址"`
  42. Highlights string `description:"活动亮点"`
  43. Remarks string `description:"备注"`
  44. Speaker string `description:"主讲人"`
  45. ArticleId int `description:"关联报告id"`
  46. Label string `description:"标签"`
  47. LinkParticipants string `description:"链接参会"`
  48. AppAttendance string `description:"App参会"`
  49. ConferencePassword string `description:"会议密码"`
  50. TemporaryLabel string `description:"临时标签"`
  51. IsMakerShow int `description:"是否仅决策人可见 0,否 、1,是"`
  52. VisibleRange int `description:"可见范围 1,仅本组可见 、2,全部客户可见"`
  53. Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。多个用, 隔开"`
  54. IsShowSubjectName int `description:"小程序内是否展示标的名称 1是 ,0 否 默认0 "`
  55. IsHideAppointment int `description:"是否隐藏预约纪要按钮 1是 ,0 否 默认0 "`
  56. AdminId int `description:"销售/管理员ID"`
  57. AdminName string `description:"销售/管理员姓名"`
  58. IsCanAppointmentMinutes int `description:"是否可预约纪要 1是 ,0 否 默认0 "`
  59. YidongActivityId string `description:"易董活动ID"`
  60. YidongActivityUrl string `description:"易董活动跳转地址"`
  61. YidongActivityEndTime string `description:"易董活动截止时间"`
  62. ActivityJoinType string `description:"活动入会类型01报名审核后可入会 02预约即可入会 03仅定向邀请人员可入会"`
  63. YidongSignUpEnd string `description:"易董活动截止时间"` // 报名结束时间,适应于报名审核后可入会,为空表示不限制报名时间
  64. YidongSignUpStart string `description:"易董活动截止时间"` // 报名开始时间,适应于报名审核后可入会,为空表示不限制报名时间
  65. }
  66. type Activity struct {
  67. ActivityTypeId int `description:"活动类型id"`
  68. ActivityTypeName string `description:"活动名称"`
  69. TemplateP string `description:"活动模板,带P标签"`
  70. Template string `description:"活动模板"`
  71. ShowType string `description:"人数限制类型,1不展示限制,2可选限制,3强制限制"`
  72. }
  73. type ActivityIdRep struct {
  74. ActivityId int `description:"活动id"`
  75. PlaySeconds int `description:"播放时长"`
  76. }
  77. type ActivitySingnupRep struct {
  78. ActivityId int `description:"活动id"`
  79. SignupType int `description:"报名方式,1预约外呼,2自主拨入,3我要报名"`
  80. }
  81. type ActivityCcustomerType struct {
  82. CustomerTypeId int `description:"活动类型id"`
  83. CustomerName string `description:"活动名称"`
  84. PermissionValue string `description:"用户权限对应的值"`
  85. }
  86. type ActivityCcustomerTypeList struct {
  87. List []*ActivityCcustomerType
  88. }
  89. // 列表
  90. func GetActivityCcustomerTypeList() (items []*ActivityCcustomerType, err error) {
  91. o := orm.NewOrm()
  92. sql := `SELECT * FROM cygx_customer_type ORDER BY sort DESC`
  93. _, err = o.Raw(sql).QueryRows(&items)
  94. return
  95. }
  96. // 活动添加、修改入参
  97. type ActivityRep struct {
  98. ActivityTypeId int `description:"活动类型id"`
  99. ChartPermissionId int `description:"行业id"`
  100. Body string `description:"内容"`
  101. LimitPeopleNum int `description:"限制的人数数量"`
  102. CustomerTypeIds string `description:"活动可见的客户类型,多个ID用 , 隔开"`
  103. ActivityId int `description:"活动ID 等于0新增活动,大于0修改活动"`
  104. DoType int `description:"操作类型 0,保存 、1,发布"`
  105. }
  106. type ActivityArticleResp struct {
  107. ReportLink string `description:"报告链接"`
  108. ArticleId int `description:"报告id(报告链接跳转使用)"`
  109. }
  110. // 活动详情
  111. type ActivityDetail struct {
  112. ActivityId int `orm:"column(activity_id);pk";description:"活动ID "`
  113. ActivityTypeId int `description:"活动类型id"`
  114. ActivityTypeName string `description:"活动类型名称"`
  115. ChartPermissionId int `description:"行业id"`
  116. ChartPermissionName string `description:"行业名称"`
  117. ChartPermissionNames string `description:"行业名称辅助字段,区分研选子分类"`
  118. Body string `description:"内容"`
  119. CreateTime string `description:"创建时间"`
  120. IsLimitPeople int `description:"是否限制人数 1是,0否"`
  121. LimitPeopleNum int `description:"限制的人数数量"`
  122. LastUpdatedTime string `description:"更新时间"`
  123. ActivityTime string `description:"活动时间"`
  124. ActivityTimeText string `description:"活动时间带文字"`
  125. DistinguishedGuest string `description:"嘉宾"`
  126. Host string `description:"主持人"`
  127. Speaker string `description:"主讲人"`
  128. MainlandTell string `description:"大陆拨入号"`
  129. HongKongTell string `description:"香港拨入号"`
  130. TaiwanTell string `description:"台湾拨入号"`
  131. AmericaTell string `description:"美国拨入号"`
  132. ParticipationCode string `description:"参会密码"`
  133. Theme string `description:"主题"`
  134. Expert string `description:"专家"`
  135. ActivityName string `description:"活动名称"`
  136. OnlineParticipation string `description:"网络参会"`
  137. ReportLink string `description:"报告链接"`
  138. City string `description:"城市"`
  139. Address string `description:"活动地址"`
  140. Highlights string `description:"活动亮点"`
  141. Remarks string `description:"备注"`
  142. ShowType string `description:"人数限制类型,1不展示限制,2可选限制,3强制限制"`
  143. IsSignup int `description:"是否已报名 1是 ,0 否"`
  144. IsAppointment int `description:"是否已预约纪要 1是 ,0 否"`
  145. SignupNum int `description:"已报名人数"`
  146. SignupType int `description:"报名方式,1预约外呼,2自主拨入,3我要报名"`
  147. ActiveState string `description:"活动进行状态 未开始:1、进行中2、已结束3"`
  148. IsCancelMeetingReminder int `description:"是否取消会议提醒 1展示取消会议提醒 ,0展示会议提醒"`
  149. ArticleId int `description:"报告id(报告链接跳转使用)"`
  150. CustomerTypeIds string `description:"活动可见的客户类型,多个ID用 , 隔开"`
  151. IsShowSustainable bool `description:"是否展示限免标签"`
  152. Description string `description:"研选内容说明"`
  153. IsResearch bool `description:"是否属于研选"`
  154. LinkParticipants string `description:"链接参会"`
  155. AppAttendance string `description:"App参会"`
  156. ConferencePassword string `description:"会议密码"`
  157. Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。多个用, 隔开"`
  158. IsShowAppointment bool `description:"是否展示预约纪要"`
  159. IsHideAppointment int `description:"是否隐藏预约纪要按钮 1是,0 否"`
  160. IsCClassMeeting bool `description:"是否是c类电话会"`
  161. ArticleList []*ActivityArticleResp // 下面是列表添加的部分结构体
  162. IsBrackets int `description:"是否有方括号 1是 ,0 否"`
  163. Label string `description:"主题标签"`
  164. ImgUrl string `description:"图片链接"`
  165. ImgUrlText string `description:"图片链接文字"`
  166. ActivityType int `description:"活动线上线下类型 1线上,0 线下"`
  167. JmcjRoadshowTitle string `description:"进门财经手动匹配的活动名称"`
  168. Listndustrial []*IndustrialManagementRep `description:"活动关联的产业信息"`
  169. IsShowOutboundCall bool `description:"是否展示预约外呼"`
  170. IsShowMeetingReminder bool `description:"是否展示会议提醒"`
  171. IsShowHelpSsk bool `description:"是否展示帮我带问"`
  172. IsShowSignup bool `description:"是否展示我要报名"`
  173. IsShowDetails bool `description:"是否展示查看详情按钮"`
  174. TemporaryLabel string `description:"临时标签"`
  175. IsCanAppointmentMinutes int `description:"是否可预约纪要 1是 ,0 否 默认0 "`
  176. YidongActivityId string `description:"易董活动ID"`
  177. YidongActivityUrl string `description:"易董活动跳转地址"`
  178. AudioLink bool `description:"是否展示回放按钮"`
  179. VoiceList *CygxActivityVoiceReq `description:"音频数据"`
  180. AdminId int `description:"管理员、销售ID "`
  181. IsMakerShow int `description:"是否仅决策人可见 0,否 、1,是"`
  182. VisibleRange int `description:"可见范围 1,仅本组可见 、2,全部客户可见"`
  183. VideoDetail *CygxActivityVideoListResp `description:"视频数据"`
  184. FileType int `description:"类型: 1-音频; 2-视频"`
  185. SourceType int `description:"活动来源。 1:活动 、2:专项产业调研"`
  186. TripImgLink string `description:"专项产业调研行程链接"`
  187. ActivityTimeEnd string `description:"专项产业调研活动预期结束时间"`
  188. IsCollect bool `description:"是否收藏"`
  189. IsShowFollowButton bool `description:"是否展示关注取关按钮"`
  190. IsFollowButton bool `description:"是否关注"`
  191. ListArticle []*ArticleIdAndTitle `description:"活动关联的文章"`
  192. }
  193. type ListArticleActivity struct {
  194. Title string `description:"文章标题"`
  195. ArtleId int `description:"产业id"`
  196. }
  197. type CygxActivityResp struct {
  198. HaqveJurisdiction bool `description:"是否有权限"`
  199. OperationMode string `description:"操作方式 Apply:立即申请、Call:拨号 为空则为有权限"`
  200. HasPermission int `description:"操作方式,1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请,5:有IFCC、无权益"`
  201. PopupMsg string `description:"权限弹窗信息"`
  202. MsgType string `description:"Type : 类型 , Industry : 行业"`
  203. SellerMobile string `description:"销售电话"`
  204. SellerName string `description:"销售姓名"`
  205. Detail *ActivityDetail
  206. }
  207. // 通过纪要ID获取活动详情
  208. func GetAddActivityInfoById(ActivityId int) (item *ActivityDetail, err error) {
  209. o := orm.NewOrm()
  210. sql := `SELECT * FROM cygx_activity WHERE activity_id=? AND publish_status = 1 `
  211. err = o.Raw(sql, ActivityId).QueryRow(&item)
  212. return
  213. }
  214. // 通过活动名称获取活动详情
  215. func GetAddActivityInfoByTitle(title, startDate, endDate string) (item *ActivityDetail, err error) {
  216. o := orm.NewOrm()
  217. sql := `SELECT * FROM cygx_activity WHERE activity_time > '` + startDate + `' AND activity_time < '` + endDate + `' AND (activity_name_task LIKE '%` + title + `%' OR jmcj_roadshow_title LIKE '%` + title + `%') AND activity_id NOT IN (1328) LIMIT 1 `
  218. err = o.Raw(sql).QueryRow(&item)
  219. return
  220. }
  221. // 通过纪要ID获取活动详情
  222. func GetAddActivityInfoByIdShow(uid, ActivityId int) (item *ActivityDetail, err error) {
  223. o := orm.NewOrm()
  224. sql := `SELECT *,( SELECT COUNT( 1 ) FROM cygx_activity_signup AS s WHERE s.activity_id = a.activity_id AND s.user_id = ? AND s.is_cancel = 0 AND s.do_fail_type = 0) AS is_signup,
  225. ( SELECT COUNT( DISTINCT user_id ) FROM cygx_activity_signup AS s WHERE s.activity_id = a.activity_id AND s.is_cancel = 0 AND s.do_fail_type = 0) AS signup_num,
  226. ( SELECT COUNT( 1 ) FROM cygx_activity_meeting_reminder AS m WHERE m.activity_id = a.activity_id AND m.user_id = ? AND m.is_cancel = 0 ) AS is_cancel_meeting_reminder,
  227. ( SELECT COUNT( 1 ) FROM cygx_activity_appointment AS ap WHERE ap.activity_id = a.activity_id AND ap.user_id = ? ) AS is_appointment
  228. FROM cygx_activity AS a WHERE activity_id=? AND publish_status = 1 `
  229. err = o.Raw(sql, uid, uid, uid, ActivityId).QueryRow(&item)
  230. return
  231. }
  232. // 活动列表
  233. type CygxActivityList struct {
  234. ActivityId int `orm:"column(activity_id);pk";description:"活动ID 等于0新增活动,大于0修改活动"`
  235. ActivityTypeId int `description:"活动类型id"`
  236. ActivityName string `description:"活动名称"`
  237. ActivityTypeName string `description:"活动类型名称"`
  238. Speaker string `description:"主讲人"`
  239. SignupType int `description:"报名方式,1预约外呼,2我要报名"`
  240. ChartPermissionId int `description:"行业id"`
  241. ChartPermissionName string `description:"行业名称"`
  242. IsLimitPeople int `description:"是否限制人数 1是,0否"`
  243. LimitPeopleNum int `description:"限制的人数数量"`
  244. ActivityTime string `description:"活动时间"`
  245. ActivityTimeText string `description:"活动时间带文字"`
  246. City string `description:"城市"`
  247. Address string `description:"活动地址"`
  248. DistinguishedGuest string `description:"嘉宾"`
  249. Expert string `description:"专家"`
  250. IsSignup int `description:"是否已报名 1是 ,0 否"`
  251. IsAppointment int `description:"是否已预约纪要 1是 ,0 否"`
  252. IsShowAppointment bool `description:"是否展示预约纪要"`
  253. SignupNum int `description:"已报名人数"`
  254. ActiveState string `description:"活动进行状态 未开始:1、进行中2、已结束3"`
  255. IsCancelMeetingReminder int `description:"是否取消会议提醒 1展示取消会议提醒 ,0展示会议提醒"`
  256. IsBrackets int `description:"是否有方括号 1是 ,0 否"`
  257. Label string `description:"主题标签"`
  258. IsShowSustainable bool `description:"是否展示限免标签"`
  259. ImgUrl string `description:"图片链接"`
  260. ImgUrlText string `description:"图片链接文字"`
  261. ActivityType int `description:"活动线上线下类型 1线上,0 线下"`
  262. IsHideAppointment int `description:"是否隐藏预约纪要按钮 1是,0 否"`
  263. JmcjRoadshowTitle string `description:"进门财经手动匹配的活动名称"`
  264. IsCClassMeeting bool `description:"是否是c类电话会"`
  265. }
  266. type GetCygxActivityListRep struct {
  267. Paging *paging.PagingItem `description:"分页数据"`
  268. List []*ActivityDetail
  269. Label string `description:"主题"`
  270. ImgUrl string `description:"图片路径"`
  271. IsResearch bool `description:"是否属于研选"`
  272. IsJump bool `description:"是否跳转"`
  273. IndustrialManagementId int `description:"产业ID"`
  274. IndustryNewLabel bool `description:"产业是否新标签"`
  275. }
  276. // 列表
  277. func GetActivityListAll(condition string, pars []interface{}, uid, startSize, pageSize, playBack int) (items []*ActivityDetail, err error) {
  278. var sqlJiontable string
  279. if playBack == 1 {
  280. //sqlJiontable = ` INNER JOIN cygx_activity_voice AS ac ON ac.activity_id = art.activity_id `
  281. }
  282. o := orm.NewOrm()
  283. sql := `SELECT art.* ,t.activity_type,t.img_url_text,c.image_url as img_url,
  284. ( SELECT COUNT( 1 ) FROM cygx_activity_signup AS s WHERE s.activity_id = art.activity_id AND s.user_id = ? AND s.is_cancel = 0 AND s.do_fail_type = 0) AS is_signup,
  285. ( SELECT COUNT( DISTINCT user_id ) FROM cygx_activity_signup AS s WHERE s.activity_id = art.activity_id AND s.is_cancel = 0 AND s.do_fail_type = 0) AS signup_num,
  286. ( SELECT COUNT( 1 ) FROM cygx_activity_meeting_reminder AS m WHERE m.activity_id = art.activity_id AND m.user_id = ? AND m.is_cancel = 0 ) AS is_cancel_meeting_reminder,
  287. ( SELECT COUNT( 1 ) FROM cygx_activity_appointment AS ap WHERE ap.activity_id = art.activity_id AND ap.user_id = ? ) AS is_appointment
  288. FROM cygx_activity as art
  289. INNER JOIN cygx_activity_type as t ON t.activity_type_id = art.activity_type_id
  290. INNER JOIN chart_permission AS c ON c.chart_permission_id = art.chart_permission_id ` + sqlJiontable + ` WHERE 1= 1 `
  291. if condition != "" {
  292. sql += condition
  293. }
  294. sql += ` LIMIT ?,?`
  295. _, err = o.Raw(sql, pars, uid, uid, uid, startSize, pageSize).QueryRows(&items)
  296. return
  297. }
  298. // 列表
  299. func GetActivityListByDateTime(startDate, endDate, activityIds, activityIdsLongTime string) (items []*CygxActivityList, err error) {
  300. o := orm.NewOrm()
  301. sql := `SELECT * FROM cygx_activity WHERE activity_time > '` + startDate + `' AND activity_time < '` + endDate + `' `
  302. activityIds = strings.TrimRight(activityIds, ",")
  303. if activityIds != "" {
  304. sql += ` AND activity_id NOT IN (` + activityIds + `,1328 ) `
  305. }
  306. sql += ` OR activity_id IN (` + activityIdsLongTime + `)`
  307. _, err = o.Raw(sql).QueryRows(&items)
  308. return
  309. }
  310. // 获取我的日程数量
  311. func GetSpecialScheduleCount(uid int) (count int, err error) {
  312. o := orm.NewOrm()
  313. sqlCount := `
  314. SELECT COUNT( 1 ) AS count FROM
  315. cygx_activity_special AS art
  316. INNER JOIN cygx_activity_special_trip AS my ON my.activity_id = art.activity_id
  317. WHERE
  318. 1 = 1 AND my.user_id = ? AND my.is_cancel = 0`
  319. err = o.Raw(sqlCount, uid).QueryRow(&count)
  320. return
  321. }
  322. // 获取数量
  323. func GetActivityCount(condition string, playBack int, pars []interface{}, filter int) (count int, err error) {
  324. var sqlJiontable string
  325. if playBack == 1 {
  326. //sqlJiontable = ` INNER JOIN cygx_activity_voice AS ac ON ac.activity_id = art.activity_id `
  327. }
  328. if filter == 1 {
  329. sqlJiontable = ` INNER JOIN cygx_activity_video AS av ON av.activity_id = art.activity_id `
  330. } else if filter == 2 {
  331. sqlJiontable = ` INNER JOIN cygx_activity_voice AS ac ON ac.activity_id = art.activity_id `
  332. }
  333. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_activity as art ` + sqlJiontable + ` WHERE 1= 1 `
  334. if condition != "" {
  335. sqlCount += condition
  336. }
  337. o := orm.NewOrm()
  338. err = o.Raw(sqlCount, pars).QueryRow(&count)
  339. return
  340. }
  341. // 获取我的日程数量
  342. func GetScheduleCount(condition string, uid int) (count int, err error) {
  343. o := orm.NewOrm()
  344. sqlCount := `SELECT COUNT( 1 ) AS count
  345. FROM cygx_my_schedule AS m
  346. INNER JOIN cygx_activity AS art ON art.activity_id = m.activity_id
  347. WHERE
  348. user_id = ?`
  349. if condition != "" {
  350. sqlCount += condition
  351. }
  352. err = o.Raw(sqlCount, uid).QueryRow(&count)
  353. return
  354. }
  355. // 我的日程列表
  356. func GetScheduleList(condition string, pars []interface{}, uid, startSize, pageSize int) (items []*ActivityDetail, err error) {
  357. o := orm.NewOrm()
  358. sql := `SELECT art.*,t.activity_type,t.img_url_text,c.image_url as img_url,
  359. ( SELECT COUNT( 1 ) FROM cygx_activity_signup AS s WHERE s.activity_id = art.activity_id AND s.user_id = ? AND s.is_cancel = 0 AND s.do_fail_type = 0) AS is_signup,
  360. ( SELECT COUNT( DISTINCT user_id ) FROM cygx_activity_signup AS s WHERE s.activity_id = art.activity_id AND s.is_cancel = 0 AND s.do_fail_type = 0) AS signup_num ,
  361. ( SELECT COUNT( 1 ) FROM cygx_activity_appointment AS ap WHERE ap.activity_id = art.activity_id AND ap.user_id = ? ) AS is_appointment,
  362. ( SELECT COUNT( 1 ) FROM cygx_activity_meeting_reminder AS m WHERE m.activity_id = art.activity_id AND m.is_cancel = 0 AND m.user_id = ? ) AS is_cancel_meeting_reminder
  363. FROM cygx_activity AS art
  364. INNER JOIN cygx_my_schedule as my ON my.activity_id = art.activity_id
  365. INNER JOIN cygx_activity_type as t ON t.activity_type_id = art.activity_type_id
  366. INNER JOIN chart_permission AS c ON c.chart_permission_id = art.chart_permission_id
  367. WHERE 1=1 AND my.user_id = ? `
  368. if condition != "" {
  369. sql += condition
  370. }
  371. sql += ` ORDER BY art.active_state ASC,art.activity_time ASC LIMIT ?,?`
  372. _, err = o.Raw(sql, pars, uid, uid, uid, uid, startSize, pageSize).QueryRows(&items)
  373. return
  374. }
  375. // 我的日程列表 活动以及专项调研一起
  376. func GetScheduleAndSpecilList(condition string, pars []interface{}, conditionSpecil string, parsSpecil []interface{}, startSize, pageSize int) (items []*ActivityDetail, err error) {
  377. o := orm.NewOrm()
  378. sql := `SELECT
  379. art.activity_id,
  380. art.activity_time_text,
  381. art.activity_name,
  382. art.chart_permission_id,
  383. art.active_state,
  384. t.activity_type,
  385. art.chart_permission_name,
  386. art.distinguished_guest,
  387. art.expert,
  388. art.speaker,
  389. "" AS trip_img_link,
  390. "" AS activity_time_end,
  391. art.yidong_activity_id,
  392. art.is_can_appointment_minutes,
  393. art.activity_type_id,
  394. art.limit_people_num,
  395. art.is_limit_people,
  396. 1 AS source_type,
  397. art.activity_time,
  398. art.city
  399. FROM
  400. cygx_activity AS art
  401. INNER JOIN cygx_my_schedule AS my ON my.activity_id = art.activity_id
  402. INNER JOIN cygx_activity_type AS t ON t.activity_type_id = art.activity_type_id
  403. INNER JOIN chart_permission AS c ON c.chart_permission_id = art.chart_permission_id
  404. WHERE
  405. 1 = 1 `
  406. if condition != `` {
  407. sql += condition
  408. }
  409. sql += ` UNION ALL
  410. SELECT
  411. art.activity_id,
  412. art.activity_time_text_by_day AS activity_time_text,
  413. art.research_theme AS activity_name,
  414. art.chart_permission_id,
  415. "",
  416. art.special_type AS activity_type,
  417. art.chart_permission_name,
  418. "",
  419. "",
  420. "",
  421. art.trip_img_link_fix AS trip_img_link,
  422. art.activity_time_end,
  423. "",
  424. "",
  425. "",
  426. "",
  427. "",
  428. 2 AS source_type,
  429. art.activity_time,
  430. ""
  431. FROM
  432. cygx_activity_special AS art
  433. INNER JOIN cygx_activity_special_trip AS my ON my.activity_id = art.activity_id
  434. WHERE
  435. 1 = 1`
  436. if conditionSpecil != "" {
  437. sql += conditionSpecil
  438. }
  439. sql += ` ORDER BY activity_time DESC LIMIT ?,?`
  440. _, err = o.Raw(sql, pars, parsSpecil, startSize, pageSize).QueryRows(&items)
  441. return
  442. }
  443. // 获取数量
  444. func GetActivityCountById(activityId int) (count int, err error) {
  445. o := orm.NewOrm()
  446. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity WHERE activity_id = ?`
  447. err = o.Raw(sqlCount, activityId).QueryRow(&count)
  448. return
  449. }
  450. // 删除数据
  451. func DeleteActivity(activityId int) (err error) {
  452. o := orm.NewOrm()
  453. sql := ` DELETE FROM cygx_activity WHERE activity_id = ?`
  454. _, err = o.Raw(sql, activityId).Exec()
  455. return
  456. }
  457. // 修改活动状态至进行中
  458. func UpdateActivitySattusToHaveInHand() (err error) {
  459. defer func() {
  460. if err != nil {
  461. fmt.Println(err)
  462. go utils.SendAlarmMsg("修改活动状态至进行中失败"+err.Error(), 2)
  463. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "修改活动状态至进行中失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  464. }
  465. }()
  466. o := orm.NewOrm()
  467. resultTime_30 := time.Now().Add(-time.Minute * 30).Format("2006-01-02 15:04:05")
  468. resultTime_60 := time.Now().Add(-time.Minute * 60).Format("2006-01-02 15:04:05")
  469. var sqlOr string
  470. var condition string
  471. condition += ` AND activity_time < NOW()`
  472. sqlOr = condition
  473. condition += ` AND (activity_type_id IN ( 1, 2, 3, 7 ) AND activity_time > ` + "'" + resultTime_30 + "'" + ")"
  474. condition += ` OR(activity_type_id IN ( 4, 5, 6 ) AND activity_time > ` + "'" + resultTime_60 + "'" + sqlOr + ")"
  475. msql := " UPDATE cygx_activity SET active_state = 2 WHERE 1 = 1 " + condition
  476. _, err = o.Raw(msql).Exec()
  477. return
  478. }
  479. // 修改活动状态至已结束
  480. func UpdateActivitySattusToComplete() (err error) {
  481. defer func() {
  482. if err != nil {
  483. fmt.Println(err)
  484. go utils.SendAlarmMsg("修改活动状态至已结束"+err.Error(), 2)
  485. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "修改活动状态至已结束 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  486. }
  487. }()
  488. o := orm.NewOrm()
  489. resultTime_30 := time.Now().Add(-time.Minute * 30).Format("2006-01-02 15:04:05")
  490. resultTime_60 := time.Now().Add(-time.Minute * 60).Format("2006-01-02 15:04:05")
  491. //var sqlOr string
  492. var condition string
  493. //condition += ` AND activity_time < NOW()`
  494. //sqlOr = condition
  495. condition += ` AND (activity_type_id IN ( 1, 2, 3, 7 ) AND activity_time < ` + "'" + resultTime_30 + "'" + ")"
  496. condition += ` OR(activity_type_id IN ( 4, 5, 6 ) AND activity_time < ` + "'" + resultTime_60 + "'" + ")"
  497. msql := " UPDATE cygx_activity SET active_state = 3 WHERE 1 = 1 " + condition
  498. _, err = o.Raw(msql).Exec()
  499. return
  500. }
  501. // 活动详情
  502. type WxMsgCygxActivityList struct {
  503. Id int `description:"报名ID"`
  504. UserId int `description:"用户ID"`
  505. ActivityId int `description:"活动ID 等于0新增活动,大于0修改活动"`
  506. ActivityTypeId int `description:"活动类型id"`
  507. ActivityName string `description:"活动名称"`
  508. ActivityTypeName string `description:"活动类型名称"`
  509. Speaker string `description:"主讲人"`
  510. SignupType int `description:"报名方式,1预约外呼,2我要报名"`
  511. ChartPermissionId int `description:"行业id"`
  512. ChartPermissionName string `description:"行业名称"`
  513. IsLimitPeople int `description:"是否限制人数 1是,0否"`
  514. LimitPeopleNum int `description:"限制的人数数量"`
  515. ActivityTime string `description:"活动时间"`
  516. ActivityTimeText string `description:"活动时间带文字"`
  517. City string `description:"城市"`
  518. Address string `description:"活动地址"`
  519. DistinguishedGuest string `description:"嘉宾"`
  520. Expert string `description:"专家"`
  521. IsSignup int `description:"是否已报名 1是 ,0 否"`
  522. SignupNum int `description:"已报名人数"`
  523. ActiveState string `description:"活动进行状态 未开始:1、进行中2、已结束3"`
  524. IsCancelMeetingReminder int `description:"是否取消会议提醒 1展示取消会议提醒 ,0展示会议提醒"`
  525. IsBrackets int `description:"是否有方括号 1是 ,0 否"`
  526. OpenId string `description:"OenId"`
  527. FailType int `description:"失败原因,0,未失败,1总人数已满,2单机构超限制,3,爽约次数超限"`
  528. }
  529. // 列表 3o分钟
  530. func GetActivitySendMsgListAll(endDate string) (items []*WxMsgCygxActivityList, err error) {
  531. o := orm.NewOrm()
  532. sql := `SELECT
  533. s.id,
  534. s.user_id,
  535. s.fail_type,
  536. cr.open_id,
  537. a.*
  538. FROM
  539. cygx_activity AS a
  540. INNER JOIN cygx_activity_signup AS s ON s.activity_id = a.activity_id
  541. INNER JOIN user_record AS c ON c.bind_account = s.mobile
  542. INNER JOIN cygx_user_record AS cr ON cr.union_id = c.union_id
  543. WHERE
  544. 1 = 1
  545. AND s.is_send_wx_msg = 0
  546. AND s.do_fail_type = 0
  547. AND a.publish_status = 1
  548. AND c.create_platform = 4
  549. AND a.activity_time <= ? AND a.activity_time >= NOW()
  550. AND s.is_cancel = 0
  551. AND( a.activity_type_id IN (4,5,6) OR (a.activity_type_id = 3 AND a.is_limit_people = 1 )) GROUP BY s.id`
  552. _, err = o.Raw(sql, endDate).QueryRows(&items)
  553. return
  554. }
  555. // 列表 15分钟提醒
  556. func GetActivitySendMsgListAllMeeting(endDate string) (items []*WxMsgCygxActivityList, err error) {
  557. o := orm.NewOrm()
  558. sql := `SELECT
  559. m.id,
  560. cr.open_id,
  561. a.*
  562. FROM
  563. cygx_activity AS a
  564. INNER JOIN cygx_activity_meeting_reminder AS m ON m.activity_id = a.activity_id
  565. INNER JOIN user_record AS c ON c.bind_account = m.mobile
  566. INNER JOIN cygx_user_record AS cr ON cr.union_id = c.union_id
  567. WHERE
  568. 1 = 1
  569. AND m.is_send_wx_msg = 0
  570. AND a.publish_status = 1
  571. AND a.activity_time <= ? AND a.activity_time >= NOW()
  572. AND m.is_cancel = 0
  573. AND c.create_platform = 4
  574. AND (
  575. a.activity_type_id IN ( 1, 2 )
  576. OR ( a.activity_type_id = 3 AND a.is_limit_people = 0 ))
  577. GROUP BY m.id`
  578. _, err = o.Raw(sql, endDate).QueryRows(&items)
  579. return
  580. }
  581. // 修改是否推送消息状态
  582. func UPdateSendedMsgStatus(signupIds string) (err error) {
  583. sql := ` UPDATE cygx_activity_signup SET is_send_wx_msg= 1 WHERE id IN(` + signupIds + `)`
  584. o := orm.NewOrm()
  585. _, err = o.Raw(sql).Exec()
  586. return
  587. }
  588. // 修改是否推送消息状态
  589. func UPdateSendedMsgMeetingStatus(signupIds string) (err error) {
  590. sql := ` UPDATE cygx_activity_meeting_reminder SET is_send_wx_msg= 1 WHERE id IN(` + signupIds + `)`
  591. o := orm.NewOrm()
  592. _, err = o.Raw(sql).Exec()
  593. return
  594. }
  595. // 获取满足推送的活动ID数量
  596. func GetCountActivityIdToSendFile(endDate string) (count int, err error) {
  597. o := orm.NewOrm()
  598. sql := `SELECT
  599. COUNT(1) count
  600. FROM
  601. cygx_activity AS a
  602. INNER JOIN cygx_activity_signup AS s ON s.activity_id = a.activity_id
  603. WHERE
  604. 1 = 1
  605. AND s.signup_type = 1
  606. AND s.fail_type = 0
  607. AND a.is_send_file_toemail = 0
  608. AND a.activity_time <= ? AND a.activity_time >= NOW() GROUP BY a.activity_id `
  609. err = o.Raw(sql, endDate).QueryRow(&count)
  610. return
  611. }
  612. // 获取满足推送的活动ID
  613. func GetActivityIdToSendFile(endDate string) (items []*ActivityIdRep, err error) {
  614. o := orm.NewOrm()
  615. sql := `SELECT
  616. *
  617. FROM
  618. cygx_activity AS a
  619. INNER JOIN cygx_activity_signup AS s ON s.activity_id = a.activity_id
  620. INNER JOIN cygx_activity_type AS t ON a.activity_type_id = t.activity_type_id
  621. WHERE
  622. 1 = 1
  623. AND s.signup_type = 1
  624. AND a.yidong_activity_id = ''
  625. AND t.activity_type = 1
  626. AND s.fail_type = 0
  627. AND a.is_send_file_toemail = 0
  628. AND a.activity_time <= ? AND a.activity_time >= NOW() GROUP BY a.activity_id `
  629. _, err = o.Raw(sql, endDate).QueryRows(&items)
  630. return
  631. }
  632. type SignupExportRep struct {
  633. Mobile string `description:"手机号"`
  634. CompanyName string `description:"公司名称"`
  635. RealName string `description:"姓名"`
  636. CountryCode string `description:"区号"`
  637. OutboundMobile string `description:"外呼手机号"`
  638. SellerName string `description:"销售姓名"`
  639. }
  640. type ActivityMsgExportRep struct {
  641. UserId int `description:"用户ID"`
  642. RealName string `description:"姓名"`
  643. CompanyName string `description:"公司名称"`
  644. CompanyId int `description:"公司ID"`
  645. Content string `description:"内容"`
  646. CreateTime string `description:"提交时间"`
  647. }
  648. func GetSignupExport(activityId int) (item []*SignupExportRep, err error) {
  649. o := orm.NewOrm()
  650. sql := ` SELECT s.outbound_mobile,
  651. s.country_code,
  652. a.is_limit_people,
  653. u.real_name,
  654. ( SELECT p.seller_name FROM company_product AS p WHERE p.company_id = u.company_id AND p.product_id = 2 ) AS seller_name,
  655. ( SELECT c.company_name FROM company AS c WHERE c.company_id = u.company_id ) AS company_name
  656. FROM
  657. cygx_activity_signup AS s
  658. LEFT JOIN wx_user AS u ON u.user_id = s.user_id
  659. LEFT JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  660. LEFT JOIN company_product AS p ON p.company_id = u.company_id
  661. WHERE a.activity_id = ? AND s.do_fail_type = 0 AND s.signup_type = 1 GROUP BY s.id `
  662. _, err = o.Raw(sql, activityId).QueryRows(&item)
  663. return
  664. }
  665. // 修改文件是否推送状态
  666. func UPdateActivityIdToSendFile(activityId int) (err error) {
  667. sql := ` UPDATE cygx_activity SET is_send_file_toemail= 1 WHERE activity_id = ?`
  668. o := orm.NewOrm()
  669. _, err = o.Raw(sql, activityId).Exec()
  670. return
  671. }
  672. // 活动详情
  673. type CygxActivityLabelList struct {
  674. KeyWord string `orm:"column(label)";description:"主题"`
  675. Timesort string `description:"最大时间"`
  676. Mintimesort string `description:"最小时间"`
  677. ImgUrlBg string `description:"背景图片"`
  678. ActivityId int `description:"活动ID "`
  679. IsShowSubjectName int `description:"小程序内是否展示标的名称 1是 ,0否 默认0 "`
  680. Resource int `description:"位置 ,1:活动 ,2:专项产业调研"`
  681. TemporaryLabel string `description:"临时标签"`
  682. IsNew bool `description:"是否为新:活动存在关联的的产业所关联的报告均在3个月内/无报告则标记新"`
  683. YidongActivityId int `description:"易董活动ID"`
  684. IsExternalLabel bool `description:"是否为外部资源"`
  685. TripStatus int `description:"行程进行状态 1:预报名,2:确定行程"`
  686. City string `description:"城市"`
  687. Days int `description:"天数"`
  688. ActivityTypeId int `description:"活动类型id"`
  689. }
  690. // 主题列表
  691. func GetActivityLabelListAll(condition, sortTime string, pars []interface{}, startSize, pageSize int) (items []*CygxActivityLabelList, err error) {
  692. o := orm.NewOrm()
  693. sql := `SELECT activity_id,activity_type_id, label,temporary_label,is_show_subject_name, MAX( art.activity_time ) AS timesort, MIn( art.activity_time ) AS mintimesort , yidong_activity_id,city
  694. FROM cygx_activity as art WHERE 1= 1 `
  695. if condition != "" {
  696. sql += condition
  697. }
  698. sql += ` GROUP BY art.label ORDER BY ` + sortTime + ` ,art.activity_id DESC LIMIT ?,? `
  699. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  700. return
  701. }
  702. type GetCygxActivityLabelListRep struct {
  703. Label string `description:"主题"`
  704. ImgUrl string `description:"图片路径"`
  705. List []*CygxActivityLabelList
  706. }
  707. // 获取研选系列专家电话会,会前1小时,满足推送的活动ID数量
  708. func GetCountActivityResearchToSendFile(condition, endDate string) (count int, err error) {
  709. o := orm.NewOrm()
  710. sql := `SELECT
  711. COUNT(1) count
  712. FROM
  713. cygx_activity AS a
  714. INNER JOIN cygx_activity_help_ask AS k ON k.activity_id = a.activity_id
  715. WHERE
  716. 1 = 1 ` + condition + `
  717. AND a.is_send_ask_msg = 0
  718. AND a.activity_time <= ?
  719. AND a.activity_time >= NOW()`
  720. err = o.Raw(sql, endDate).QueryRow(&count)
  721. return
  722. }
  723. // 获取研选系列专家电话会,会前1小时,满足推送的活动ID
  724. func GetActivityResearchToSendFile(condition, endDate string) (items []*ActivityIdRep, err error) {
  725. o := orm.NewOrm()
  726. sql := `SELECT
  727. *
  728. FROM
  729. cygx_activity AS a
  730. INNER JOIN cygx_activity_help_ask AS k ON k.activity_id = a.activity_id
  731. WHERE
  732. 1 = 1 ` + condition + `
  733. AND a.is_send_ask_msg = 0
  734. AND a.activity_time <= ?
  735. AND a.activity_time >= NOW()
  736. GROUP BY
  737. a.activity_id `
  738. _, err = o.Raw(sql, endDate).QueryRows(&items)
  739. return
  740. }
  741. func GetActivityMsgExport(activityId int) (item []*ActivityMsgExportRep, err error) {
  742. o := orm.NewOrm()
  743. sql := `SELECT
  744. k.*,
  745. u.real_name
  746. FROM
  747. cygx_activity_help_ask AS k
  748. LEFT JOIN wx_user AS u ON u.user_id = k.user_id
  749. WHERE
  750. k.activity_id = ?
  751. GROUP BY
  752. k.ask_id`
  753. _, err = o.Raw(sql, activityId).QueryRows(&item)
  754. return
  755. }
  756. // 修改文件带问消息是否推送状态
  757. func UPdateActivityMsgToSendFile(activityId int) (err error) {
  758. sql := ` UPDATE cygx_activity SET is_send_ask_msg= 1 WHERE activity_id = ?`
  759. o := orm.NewOrm()
  760. _, err = o.Raw(sql, activityId).Exec()
  761. return
  762. }
  763. type AskEmailRep struct {
  764. Name string `description:"姓名"`
  765. Email string `description:"邮箱"`
  766. Mobile string `description:"手机号"`
  767. }
  768. func GetAskEmail() (item []*AskEmailRep, err error) {
  769. o := orm.NewOrm()
  770. sql := `SELECT * FROM cygx_activity_ask_email`
  771. _, err = o.Raw(sql).QueryRows(&item)
  772. return
  773. }
  774. // 主题列表
  775. func GetActivityLabelSpecialListAll(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivityLabelList, err error) {
  776. o := orm.NewOrm()
  777. sql := `SELECT label,activity_id,is_show_subject_name,days
  778. FROM cygx_activity_special as art WHERE 1= 1 `
  779. if condition != "" {
  780. sql += condition
  781. }
  782. sql += ` LIMIT ?,? `
  783. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  784. return
  785. }
  786. type GetCygxActivitySpecialDetailListResp struct {
  787. IsFollow bool `description:"是否关注新调研通知"`
  788. IsBindingMobile bool `description:"是否绑定了手机号"`
  789. Paging *paging.PagingItem `description:"分页数据"`
  790. List []*CygxActivitySpecialDetail
  791. }
  792. type CygxActivitySpecialResp struct {
  793. HaqveJurisdiction bool `description:"是否有权限"`
  794. OperationMode string `description:"操作方式 Apply:立即申请、Call:拨号 为空则为有权限"`
  795. HasPermission int `description:"操作方式,1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请,5:有IFCC、无权益"`
  796. PopupMsg string `description:"权限弹窗信息"`
  797. MsgType string `description:"Type : 类型 , Industry : 行业"`
  798. SellerMobile string `description:"销售电话"`
  799. SellerName string `description:"销售姓名"`
  800. IsFollow bool `description:"是否关注新调研通知"`
  801. Detail *CygxActivitySpecialDetail
  802. }
  803. // 获取专项调研活动列表
  804. func GetCygxActivitySpecialDetailList(condition string, pars []interface{}, uid, startSize, pageSize int) (items []*CygxActivitySpecialDetail, err error) {
  805. o := orm.NewOrm()
  806. sql := ` SELECT
  807. art.*,
  808. c.image_url AS img_url,
  809. (
  810. SELECT
  811. COUNT( 1 )
  812. FROM
  813. cygx_activity_special_signup AS s
  814. WHERE
  815. s.activity_id = art.activity_id
  816. AND s.user_id = ?
  817. ) AS is_signup
  818. FROM
  819. cygx_activity_special AS art
  820. INNER JOIN chart_permission AS c ON c.chart_permission_id = art.chart_permission_id
  821. WHERE
  822. 1 = 1 `
  823. if condition != "" {
  824. sql += condition
  825. }
  826. sql += ` LIMIT ?,? `
  827. _, err = o.Raw(sql, uid, pars, startSize, pageSize).QueryRows(&items)
  828. return
  829. }
  830. // 通过活动ID获取活动详情
  831. func GetCygxActivitySpecialDetailById(uid, ActivityId int) (item *CygxActivitySpecialDetail, err error) {
  832. o := orm.NewOrm()
  833. sql := `SELECT *,( SELECT COUNT( 1 ) FROM cygx_activity_special_signup AS s WHERE s.activity_id = a.activity_id AND s.user_id = ? ) AS is_signup
  834. FROM
  835. cygx_activity_special AS a
  836. WHERE
  837. activity_id = ?
  838. AND publish_status = 1 AND is_offline = 0 `
  839. err = o.Raw(sql, uid, ActivityId).QueryRow(&item)
  840. return
  841. }
  842. // 通过活动ID获取活动详情
  843. func GetCygxActivitySpecialDetail(ActivityId int) (item *CygxActivitySpecialDetail, err error) {
  844. o := orm.NewOrm()
  845. sql := `SELECT * FROM cygx_activity_special WHERE activity_id=? AND publish_status = 1 `
  846. err = o.Raw(sql, ActivityId).QueryRow(&item)
  847. return
  848. }
  849. func UpdateCygxActivityName(activityId int, Name string) (err error) {
  850. o := orm.NewOrm()
  851. sql := `UPDATE cygx_activity SET activity_name_task = ? WHERE activity_id=? `
  852. _, err = o.Raw(sql, Name, activityId).Exec()
  853. return
  854. }
  855. // 获取已发布但是为开始活动的权限
  856. func GetActivityWeekPermission() (permission string, err error) {
  857. o := orm.NewOrm()
  858. sql := ` SELECT
  859. GROUP_CONCAT( DISTINCT chart_permission_name SEPARATOR ',' ) AS permission
  860. FROM
  861. cygx_activity
  862. WHERE
  863. active_state = 1`
  864. err = o.Raw(sql).QueryRow(&permission)
  865. return
  866. }
  867. // 列表
  868. func GetIndustrialActivityGroupManagementList(activityId int) (items []*IndustrialManagementRep, err error) {
  869. o := orm.NewOrm()
  870. sql := `SELECT
  871. p.permission_name,
  872. p.chart_permission_id,
  873. m.industrial_management_id,
  874. m.industry_name
  875. FROM
  876. cygx_industrial_activity_group_management AS am
  877. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = am.industrial_management_id
  878. INNER JOIN chart_permission AS p ON p.chart_permission_id = m.chart_permission_id
  879. WHERE
  880. am.activity_id = ? AND am.source = 1`
  881. _, err = o.Raw(sql, activityId).QueryRows(&items)
  882. return
  883. }
  884. // GetActivityListByYiDong 获取易董同步过来的活动列表
  885. func GetActivityListByYiDong() (items []*CygxActivity, err error) {
  886. o := orm.NewOrm()
  887. sql := ` SELECT * FROM cygx_activity WHERE yidong_activity_id != '' `
  888. _, err = o.Raw(sql).QueryRows(&items)
  889. return
  890. }
  891. // AddCygxActivity 添加活动
  892. func AddCygxActivity(item *CygxActivity) (lastId int64, err error) {
  893. o := orm.NewOrm()
  894. lastId, err = o.Insert(item)
  895. return
  896. }
  897. // 列表
  898. func GetActivityListByYidong(condition string) (items []*ActivityDetail, err error) {
  899. o := orm.NewOrm()
  900. sql := `SELECT * FROM cygx_activity WHERE yidong_activity_id != '' `
  901. if condition != "" {
  902. sql += condition
  903. }
  904. _, err = o.Raw(sql).QueryRows(&items)
  905. return
  906. }
  907. // UpdateCygxActivitySubmitMeetingByYidong ,跟易董返回的用户状态修改活动以提交到会状态
  908. func UpdateCygxActivitySubmitMeetingByYidong(yidongActivityId string) (err error) {
  909. o := orm.NewOrm()
  910. sql := `UPDATE cygx_activity SET is_submit_meeting = 1 WHERE yidong_activity_id=? `
  911. _, err = o.Raw(sql, yidongActivityId).Exec()
  912. return
  913. }
  914. // UpdateActivityshowSubject 根据易董推过来的匹配信息,判断临时标签是否展示
  915. func UpdateActivityshowSubject(activityId int) (err error) {
  916. sql := ` UPDATE cygx_activity SET is_show_subject_name= 1 , temporary_label = '' WHERE activity_id = ?`
  917. o := orm.NewOrm()
  918. _, err = o.Raw(sql, activityId).Exec()
  919. return
  920. }
  921. // GetActivitySpecialSearcheList 活动与专项调研的搜索
  922. func GetActivitySpecialSearcheList(condition string, pars []interface{}, conditionSpecil string, parsSpecil []interface{}, startSize, pageSize int) (items []*ActivityDetail, total int, err error) {
  923. o := orm.NewOrm()
  924. sql := `SELECT
  925. art.activity_id,
  926. art.activity_time_text,
  927. art.activity_name,
  928. art.chart_permission_id,
  929. art.active_state,
  930. t.activity_type,
  931. art.chart_permission_name,
  932. art.distinguished_guest,
  933. art.expert,
  934. art.speaker,
  935. "" AS trip_img_link,
  936. "" AS activity_time_end,
  937. art.yidong_activity_id,
  938. art.is_can_appointment_minutes,
  939. art.activity_type_id,
  940. art.limit_people_num,
  941. art.is_limit_people,
  942. 1 AS source_type,
  943. art.activity_time
  944. FROM
  945. cygx_activity AS art
  946. INNER JOIN cygx_activity_type AS t ON t.activity_type_id = art.activity_type_id
  947. WHERE
  948. 1 = 1 `
  949. if condition != `` {
  950. sql += condition
  951. }
  952. sql += ` UNION ALL
  953. SELECT
  954. art.activity_id,
  955. art.activity_time_text_by_day AS activity_time_text,
  956. art.research_theme AS activity_name,
  957. art.chart_permission_id,
  958. "",
  959. art.special_type AS activity_type,
  960. art.chart_permission_name,
  961. "",
  962. "",
  963. "",
  964. art.trip_img_link_fix AS trip_img_link,
  965. art.activity_time_end,
  966. "",
  967. "",
  968. "",
  969. "",
  970. "",
  971. 2 AS source_type,
  972. art.activity_time
  973. FROM
  974. cygx_activity_special AS art
  975. WHERE
  976. 1 = 1 `
  977. if conditionSpecil != "" {
  978. sql += conditionSpecil
  979. }
  980. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  981. err = o.Raw(totalSql, pars, parsSpecil).QueryRow(&total)
  982. if err != nil {
  983. return
  984. }
  985. sql += ` ORDER BY activity_time DESC LIMIT ?,?`
  986. _, err = o.Raw(sql, pars, parsSpecil, startSize, pageSize).QueryRows(&items)
  987. return
  988. }
  989. // 列表
  990. func GetActivityListNew(condition string, pars []interface{}, uid, startSize, pageSize, playBack, filter int, typeName string) (items []*ActivityDetail, err error) {
  991. var sqlJiontable string
  992. if playBack == 1 {
  993. //sqlJiontable = ` INNER JOIN cygx_activity_voice AS ac ON ac.activity_id = art.activity_id `
  994. }
  995. if filter == 1 {
  996. sqlJiontable = ` INNER JOIN cygx_activity_video AS av ON av.activity_id = art.activity_id `
  997. } else if filter == 2 {
  998. sqlJiontable = ` INNER JOIN cygx_activity_voice AS ac ON ac.activity_id = art.activity_id `
  999. }
  1000. o := orm.NewOrm()
  1001. sql := `SELECT art.* ,t.activity_type,t.img_url_text,c.image_url as img_url,
  1002. ( SELECT COUNT( 1 ) FROM cygx_activity_signup AS s WHERE s.activity_id = art.activity_id AND s.user_id = ? AND s.is_cancel = 0 AND s.do_fail_type = 0) AS is_signup,
  1003. ( SELECT COUNT( DISTINCT user_id ) FROM cygx_activity_signup AS s WHERE s.activity_id = art.activity_id AND s.is_cancel = 0 AND s.do_fail_type = 0) AS signup_num,
  1004. ( SELECT COUNT( 1 ) FROM cygx_activity_meeting_reminder AS m WHERE m.activity_id = art.activity_id AND m.user_id = ? AND m.is_cancel = 0 ) AS is_cancel_meeting_reminder,
  1005. ( SELECT COUNT( 1 ) FROM cygx_activity_appointment AS ap WHERE ap.activity_id = art.activity_id AND ap.user_id = ? ) AS is_appointment
  1006. FROM cygx_activity as art
  1007. INNER JOIN cygx_activity_type as t ON t.activity_type_id = art.activity_type_id
  1008. INNER JOIN chart_permission AS c ON c.chart_permission_id = art.chart_permission_id ` + sqlJiontable + ` WHERE 1= 1 `
  1009. if condition != "" {
  1010. sql += condition
  1011. }
  1012. sql += ` LIMIT ?,?`
  1013. if typeName != "" {
  1014. typeSlice := strings.Split(typeName, ",")
  1015. tempCondition := ""
  1016. for _, s := range typeSlice {
  1017. if s == "1" {
  1018. tempCondition += "'专家电话会',"
  1019. } else if s == "2" {
  1020. tempCondition += "'分析师电话会',"
  1021. } else if s == "1,2" {
  1022. tempCondition += "'专家电话会','分析师电话会',"
  1023. }
  1024. }
  1025. tempCondition = strings.TrimRight(tempCondition, ",")
  1026. sql = `SELECT * FROM(` + sql + `) AS t WHERE t.activity_type_name IN (` + tempCondition + `)`
  1027. }
  1028. _, err = o.Raw(sql, uid, uid, uid, pars, startSize, pageSize).QueryRows(&items)
  1029. return
  1030. }
  1031. // 列表
  1032. func GetActivityListHomeNew(condition string, startSize, pageSize int) (items []*ActivityDetail, err error) {
  1033. o := orm.NewOrm()
  1034. sql := `SELECT activity_id
  1035. FROM cygx_activity as art
  1036. INNER JOIN cygx_activity_type as t ON t.activity_type_id = art.activity_type_id
  1037. INNER JOIN chart_permission AS c ON c.chart_permission_id = art.chart_permission_id WHERE 1= 1 `
  1038. if condition != "" {
  1039. sql += condition
  1040. }
  1041. sql += ` LIMIT ?,?`
  1042. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  1043. return
  1044. }
  1045. // 主题列表
  1046. func GetActivityLabelListAllNoLimit(condition, sortTime string, pars []interface{}, conditionSpecial string) (items []*CygxActivityLabelList, err error) {
  1047. o := orm.NewOrm()
  1048. sql := `SELECT activity_id, label,temporary_label,is_show_subject_name, art.activity_time, 1 AS resource, yidong_activity_id
  1049. FROM cygx_activity as art WHERE 1= 1 `
  1050. if condition != "" {
  1051. sql += condition
  1052. }
  1053. sql += ` UNION ALL `
  1054. sql += ` SELECT
  1055. art.activity_id,
  1056. art.label,
  1057. art.temporary_label,
  1058. is_show_subject_name,
  1059. art.activity_time,
  1060. 2 AS resource,
  1061. '' AS yidong_activity_id
  1062. FROM
  1063. cygx_activity_special AS art WHERE 1= 1 ` + conditionSpecial
  1064. sql += ` GROUP BY label,resource ORDER BY ` + sortTime + ` , activity_id DESC `
  1065. _, err = o.Raw(sql, pars).QueryRows(&items)
  1066. return
  1067. }