activity.go 48 KB

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