calendar.go 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  1. package roadshow
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hz_crm_api/models/company"
  7. "hongze/hz_crm_api/models/system"
  8. "hongze/hz_crm_api/utils"
  9. "strings"
  10. "time"
  11. )
  12. type AddActivityReq struct {
  13. ActivityType string `description:"活动类型"`
  14. RoadshowType string `description:"路演形式"`
  15. RoadshowPlatform string `description:"路演平台"`
  16. CompanyId int `description:"客户id"`
  17. CompanyName string `description:"客户名称"`
  18. Province string `description:"省"`
  19. ProvinceCode string `description:"省编码"`
  20. City string `description:"市"`
  21. CityCode string `description:"市编码"`
  22. District string `description:"区"`
  23. Theme string `description:"会议主题"`
  24. CooperationName string `description:"合作方名称"`
  25. ActivityCategory string `description:"活动类别"`
  26. ResearcherList []*CalendarResearcher
  27. EnglishCompany int `description:"是否为英文客户"`
  28. }
  29. type CalendarResearcher struct {
  30. ResearcherId int `description:"研究员id"`
  31. ResearcherName string `description:"研究员名称"`
  32. StartDate string `description:"开始日期"`
  33. EndDate string `description:"结束日期"`
  34. StartTime string `description:"开始时间"`
  35. EndTime string `description:"结束时间"`
  36. StartWeek string `description:"开始日期对应周"`
  37. EndWeek string `description:"结束日期对应周"`
  38. }
  39. type RsCalendar struct {
  40. RsCalendarId int `orm:"column(rs_calendar_id);pk"`
  41. SysUserId int `description:"创建人id"`
  42. SysUserRealName string `description:"创建人名称"`
  43. ActivityType string `description:"活动类型"`
  44. RoadshowType string `description:"路演形式"`
  45. RoadshowPlatform string `description:"路演平台"`
  46. CompanyId int `description:"客户id"`
  47. CompanyName string `description:"客户名称"`
  48. Province string `description:"省"`
  49. ProvinceCode string `description:"省编码"`
  50. City string `description:"市"`
  51. CityCode string `description:"市编码"`
  52. District string `description:"区"`
  53. Theme string `description:"会议主题"`
  54. CooperationName string `description:"合作方名称"`
  55. Title string `description:"展示在日历的标题"`
  56. Source int8 `description:"来源,0:自系统,1:上海方的"`
  57. CreateTime time.Time
  58. ModifyTime time.Time
  59. ActivityCategory string `description:"活动类别"`
  60. IsSynced int `description:"是否与上海同步 0:未同步 1:已同步"`
  61. UnionCode string `description:"公开会议联合编码"`
  62. EnglishCompany int `description:"是否为英文客户: 0-否; 1-是"`
  63. SellerId int `description:"销售id"`
  64. ShareSellerId int `description:"共享销售员id"`
  65. }
  66. type RsCalendarResearcher struct {
  67. RsCalendarResearcherId int `orm:"column(rs_calendar_researcher_id);pk"`
  68. RsCalendarId int `description:"日历活动id"`
  69. ResearcherId int `description:"研究员id"`
  70. ResearcherName string `description:"研究员名称"`
  71. StartDate string `description:"开始日期"`
  72. EndDate string `description:"结束日期"`
  73. StartTime string `description:"开始时间"`
  74. EndTime string `description:"结束时间"`
  75. StartWeek string `description:"开始日期对应周"`
  76. EndWeek string `description:"结束日期对应周"`
  77. CreateTime time.Time
  78. ModifyTime time.Time
  79. Status int `description:"状态:1:待接受,2:已接受,3:已拒绝,4:已删除,5:已撤回,6:已结束"`
  80. RefuseReason string `description:"拒绝理由"`
  81. RefuseTime time.Time `description:"拒绝时间"`
  82. DeleteReason string `description:"删除理由"`
  83. DeleteTime time.Time `description:"删除时间"`
  84. ApproveTime time.Time `description:"接受时间"`
  85. IsSynced int `description:"是否与上海同步 0:未同步 1:已同步"`
  86. ResearcherSort int `description:"研究员新增排序"`
  87. UnionCode string `description:"公开会议联合编码"`
  88. }
  89. func GetRsCalendarById(rsCalendarId int) (item *RsCalendar, err error) {
  90. o := orm.NewOrm()
  91. sql := `SELECT * FROM rs_calendar WHERE rs_calendar_id=? `
  92. err = o.Raw(sql, rsCalendarId).QueryRow(&item)
  93. return
  94. }
  95. func GetRsCalendarResearcherById(rsCalendarResearcherId int) (item *RsCalendarResearcher, err error) {
  96. o := orm.NewOrm()
  97. sql := `SELECT * FROM rs_calendar_researcher WHERE rs_calendar_researcher_id=? `
  98. err = o.Raw(sql, rsCalendarResearcherId).QueryRow(&item)
  99. return
  100. }
  101. // Update 更新路演用户信息
  102. func (item *RsCalendarResearcher) Update(cols []string) (err error) {
  103. o := orm.NewOrm()
  104. _, err = o.Update(item, cols...)
  105. return
  106. }
  107. func GetRsCalendarResearcherListById(rsCalendarId int) (item []*RsCalendarResearcher, err error) {
  108. o := orm.NewOrm()
  109. sql := `SELECT * FROM rs_calendar_researcher WHERE rs_calendar_id=? `
  110. _, err = o.Raw(sql, rsCalendarId).QueryRows(&item)
  111. return
  112. }
  113. // 根据多个路演ID获取研究员信息
  114. func GetRsCalendarResearcherListByIds(rsCalendarIds []int) (item []*RsCalendarResearcher, err error) {
  115. if len(rsCalendarIds) == 0 {
  116. return
  117. }
  118. o := orm.NewOrm()
  119. sql := `SELECT * FROM rs_calendar_researcher WHERE rs_calendar_id IN (` + utils.GetOrmInReplace(len(rsCalendarIds)) + `) `
  120. _, err = o.Raw(sql, rsCalendarIds).QueryRows(&item)
  121. return
  122. }
  123. func GetRsCalendarResearcherListByCalendarResearcherId(rsCalendarResearcherId int) (item []*RsCalendarResearcher, err error) {
  124. o := orm.NewOrm()
  125. sql := `SELECT * FROM rs_calendar_researcher WHERE rs_calendar_researcher_id=? `
  126. _, err = o.Raw(sql, rsCalendarResearcherId).QueryRows(&item)
  127. return
  128. }
  129. // 添加RsCalendar
  130. func AddRsCalendar(item *RsCalendar) (lastId int64, err error) {
  131. o := orm.NewOrm()
  132. lastId, err = o.Insert(item)
  133. return
  134. }
  135. // 添加RsCalendarResearcher
  136. func AddRsCalendarResearcher(item *RsCalendarResearcher) (lastId int64, err error) {
  137. o := orm.NewOrm()
  138. lastId, err = o.Insert(item)
  139. return
  140. }
  141. // 添加RsCalendarResearcher
  142. func AddRsCalendarResearcherFromSH(item *RsCalendarResearcher) (bool bool, id int64, err error) {
  143. o := orm.NewOrm()
  144. bool, id, err = o.ReadOrCreate(item, "rs_calendar_id")
  145. return
  146. }
  147. type Researcher struct {
  148. AdminId int `description:"研究员id"`
  149. RealName string `description:"研究员名称"`
  150. GroupId int `description:"分组id"`
  151. GroupName string `description:"分组名称"`
  152. RoleTypeCode string `description:"角色编码"`
  153. }
  154. type ResearcherIds struct {
  155. AdminIds string `description:"研究员id"`
  156. }
  157. type ResearcherGroup struct {
  158. GroupId int `description:"分组id"`
  159. GroupName string `description:"分组名称"`
  160. AdminId int `description:"研究员id"`
  161. RealName string `description:"研究员名称"`
  162. RoleTypeCode string `description:"角色编码"`
  163. ResearcherList []*ResearcherGroup
  164. }
  165. func GetResearcherGroup() (list []*ResearcherGroup, err error) {
  166. o := orm.NewOrm()
  167. sql := ` SELECT group_id,group_name FROM admin AS a
  168. WHERE a.role_type_code IN('researcher','ficc_researcher','ficc_admin')
  169. AND a.enabled=1
  170. AND a.group_id>0
  171. AND a.group_name<>'无'
  172. GROUP BY a.group_id
  173. ORDER BY a.group_id ASC `
  174. _, err = o.Raw(sql).QueryRows(&list)
  175. return
  176. }
  177. func GetResearcher() (list []*ResearcherGroup, err error) {
  178. o := orm.NewOrm()
  179. sql := ` SELECT * FROM admin AS a
  180. WHERE a.role_type_code IN('researcher','rai_researcher','ficc_researcher','ficc_admin')
  181. AND a.enabled=1 AND a.real_name<>'于菲' `
  182. _, err = o.Raw(sql).QueryRows(&list)
  183. return
  184. }
  185. func GetChoiceResearcher(adminIds string) (list []*Researcher, err error) {
  186. o := orm.NewOrm()
  187. sql := ` SELECT * FROM admin WHERE admin_id IN ( ` + adminIds + ` ); `
  188. _, err = o.Raw(sql).QueryRows(&list)
  189. return
  190. }
  191. // GetResearcherV2 获取研究员列表(冻结的也要)
  192. func GetResearcherV2() (list []*ResearcherGroup, err error) {
  193. o := orm.NewOrm()
  194. sql := ` SELECT * FROM admin AS a
  195. WHERE a.role_type_code IN('researcher','rai_researcher','ficc_researcher','ficc_admin')
  196. AND a.enabled=1 and admin_id !=92 `
  197. _, err = o.Raw(sql).QueryRows(&list)
  198. return
  199. }
  200. // GetSellerGroup 获取销售分组
  201. func GetSellerGroup() (list []*ResearcherGroup, err error) {
  202. o := orm.NewOrm()
  203. sql := ` SELECT group_id,group_name FROM admin AS a
  204. WHERE a.role_type_code IN('ficc_seller','ficc_group')
  205. AND a.enabled=1
  206. AND a.group_id>0
  207. AND a.group_name<>'无'
  208. GROUP BY a.group_id
  209. ORDER BY a.group_id ASC `
  210. _, err = o.Raw(sql).QueryRows(&list)
  211. return
  212. }
  213. // GetSellerList 获取销售列表(冻结的也要)
  214. func GetSellerList(roleTypeCode string, groupIds string) (list []*Researcher, err error) {
  215. o := orm.NewOrm()
  216. sql := ` SELECT * FROM admin AS a
  217. WHERE a.role_type_code IN ` + roleTypeCode + `
  218. AND a.enabled=1 `
  219. if groupIds != "" {
  220. sql += "and group_id in " + groupIds
  221. }
  222. _, err = o.Raw(sql).QueryRows(&list)
  223. return
  224. }
  225. // GetRaiSellerList 获取权益销售列表(冻结的也要)
  226. func GetRaiSellerList(roleTypeCode string, groupIds string) (list []*Researcher, err error) {
  227. o := orm.NewOrm()
  228. sql := ` SELECT * FROM admin AS a
  229. WHERE a.role_type_code IN ` + roleTypeCode + `
  230. AND a.enabled=1 `
  231. if groupIds != "" {
  232. sql += "and group_id in " + groupIds
  233. }
  234. _, err = o.Raw(sql).QueryRows(&list)
  235. return
  236. }
  237. type CalendarListView struct {
  238. RsCalendarId int `orm:"column(rs_calendar_id);pk"`
  239. SysUserId int `description:"创建人id"`
  240. SysUserRealName string `description:"创建人名称"`
  241. ActivityType string `description:"活动类型"`
  242. RoadshowType string `description:"路演形式"`
  243. RoadshowPlatform string `description:"路演平台"`
  244. CompanyId int `description:"客户id"`
  245. CompanyName string `description:"客户名称"`
  246. RsCalendarResearcherId int `description:"活动研究员id"`
  247. ResearcherId string `description:"研究员id"`
  248. ResearcherName string `description:"研究员名称"`
  249. StartDate string `description:"开始日期"`
  250. EndDate string `description:"结束日期"`
  251. StartTime string `description:"开始时间"`
  252. EndTime string `description:"结束时间"`
  253. StartWeek string `description:"开始日期对应周"`
  254. EndWeek string `description:"结束日期对应周"`
  255. CreateTime string
  256. ModifyTime string
  257. Status int `description:"状态:1:待接受,2:已接受,3:已拒绝,4:已删除,5:已撤回,6:已结束"`
  258. RefuseReason string `description:"拒绝理由"`
  259. RefuseTime string `description:"拒绝时间"`
  260. DeleteReason string `description:"删除原因"`
  261. Province string `description:"省"`
  262. ProvinceCode string `description:"省编码"`
  263. City string `description:"市"`
  264. CityCode string `description:"市编码"`
  265. District string `description:"区"`
  266. Theme string `description:"会议主题"`
  267. CooperationName string `description:"合作方名称"`
  268. ActivityCategory string `description:"活动类别"`
  269. Source int `description:"来源,0:自系统,1:上海方的"`
  270. Title string `description:"日历展示标题"`
  271. CompanyStatus string `description:"新增客户状态"`
  272. UnionCode string `description:"公开会议联合编码"`
  273. EnglishCompany int `description:"是否为英文客户: 0-否; 1-是"`
  274. EnglishCountry string `description:"英文客户-国家"`
  275. EnglishViewTotal int `description:"英文客户-累计点击量"`
  276. SubmitButton bool `description:"提交按钮是否展示"`
  277. ViewButton bool `description:"查看按钮是否展示"`
  278. EditButton bool `description:"修改按钮是否展示"`
  279. }
  280. type CalendarListResp struct {
  281. Paging *paging.PagingItem
  282. List []*CalendarListView
  283. }
  284. func GetCalendarListCount(condition string, pars []interface{}, calendarType int) (count int, err error) {
  285. o := orm.NewOrm()
  286. if calendarType == 3 || calendarType == 4 {
  287. sql := `SELECT COUNT(1) AS count FROM(SELECT COUNT(1) AS count
  288. FROM rs_calendar AS a
  289. INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id=b.rs_calendar_id
  290. WHERE 1=1 `
  291. if condition != "" {
  292. sql += condition
  293. }
  294. sql += ` GROUP BY a.rs_calendar_id ) AS t `
  295. err = o.Raw(sql, pars).QueryRow(&count)
  296. } else {
  297. sql := `SELECT COUNT(1) AS count FROM rs_calendar AS a
  298. INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id=b.rs_calendar_id
  299. WHERE 1=1 `
  300. if condition != "" {
  301. sql += condition
  302. }
  303. err = o.Raw(sql, pars).QueryRow(&count)
  304. }
  305. return
  306. }
  307. func GetCalendarList(condition string, pars []interface{}, startSize, pageSize, calendarType int) (list []*CalendarListView, err error) {
  308. o := orm.NewOrm()
  309. if calendarType == 3 || calendarType == 4 {
  310. sql := ` SELECT a.rs_calendar_id,a.activity_type,a.roadshow_type,a.activity_category,a.roadshow_platform,b.create_time,a.district,
  311. b.modify_time,GROUP_CONCAT(b.researcher_id ORDER BY researcher_sort ASC) AS researcher_id,GROUP_CONCAT(b.researcher_name ORDER BY researcher_sort ASC) AS researcher_name,
  312. b.rs_calendar_researcher_id,b.start_date,
  313. b.end_date,b.start_time,b.end_time,b.start_week,b.end_week,b.status,b.refuse_reason,b.refuse_time,
  314. b.delete_reason,a.sys_user_real_name,a.city,a.province,a.company_name,a.company_id,
  315. a.cooperation_name,a.theme,a.activity_category,a.english_company
  316. FROM rs_calendar AS a
  317. INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id=b.rs_calendar_id
  318. WHERE 1=1
  319. `
  320. if condition != "" {
  321. sql += condition
  322. }
  323. if calendarType == 1 {
  324. sql += ` GROUP BY a.rs_calendar_id
  325. ORDER BY b.create_time ASC LIMIT ?,? `
  326. } else {
  327. sql += ` GROUP BY a.rs_calendar_id
  328. ORDER BY b.create_time DESC LIMIT ?,? `
  329. }
  330. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  331. } else {
  332. sql := `SELECT a.rs_calendar_id,a.activity_type,a.roadshow_type,a.activity_category,a.roadshow_platform,b.create_time,a.district,a.sys_user_id,
  333. b.modify_time,b.researcher_id,b.researcher_name,
  334. b.rs_calendar_researcher_id,b.start_date,
  335. b.end_date,b.start_time,b.end_time,b.start_week,b.end_week,b.status,b.refuse_reason,b.refuse_time,
  336. b.delete_reason,a.sys_user_real_name,a.city,a.province,a.company_name,a.company_id,a.cooperation_name,a.theme,a.activity_category,a.english_company
  337. FROM rs_calendar AS a
  338. INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id=b.rs_calendar_id
  339. WHERE 1=1 `
  340. if condition != "" {
  341. sql += condition
  342. }
  343. if calendarType == 1 {
  344. sql += ` ORDER BY b.create_time ASC LIMIT ?,? `
  345. } else {
  346. //sql += ` ORDER BY b.create_time DESC LIMIT ?,? `
  347. sql += ` ORDER BY b.start_date DESC , b.start_time DESC LIMIT ?,? ` // 已处理申请,按照活动开始时间倒序(包括ficc的)
  348. }
  349. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  350. }
  351. return
  352. }
  353. type AcceptReq struct {
  354. RsCalendarId int `description:"日历活动id"`
  355. RsCalendarResearcherId int `description:"活动研究员id"`
  356. }
  357. type DeleteReq struct {
  358. RsCalendarId int `description:"日历活动id"`
  359. RsCalendarResearcherId int `description:"活动研究员id"`
  360. DeleteReason string `description:"删除原因"`
  361. }
  362. type RefuseReq struct {
  363. RsCalendarId int `description:"日历活动id"`
  364. RsCalendarResearcherId int `description:"活动研究员id"`
  365. RefuseReason string `description:"拒绝原因"`
  366. }
  367. // 更新
  368. func UpdateCalendarResearcher(where, updateParams map[string]interface{}) error {
  369. o := orm.NewOrm()
  370. ptrStructOrTableName := "rs_calendar_researcher"
  371. qs := o.QueryTable(ptrStructOrTableName)
  372. for expr, exprV := range where {
  373. qs = qs.Filter(expr, exprV)
  374. }
  375. _, err := qs.Update(updateParams)
  376. return err
  377. }
  378. // 更新
  379. func UpdateCalendarResearcherFromSH(item *RsCalendarResearcher) error {
  380. o := orm.NewOrm()
  381. _, err := o.Update(item, "")
  382. return err
  383. }
  384. type AddMattersReq struct {
  385. StartDate string `description:"开始日期"`
  386. EndDate string `description:"结束日期"`
  387. StartTime string `description:"开始时间"`
  388. EndTime string `description:"结束时间"`
  389. StartWeek string `description:"开始日期周"`
  390. EndWeek string `description:"结束日期周"`
  391. MatterContent string `description:"事项内容"`
  392. }
  393. type RsMatters struct {
  394. RsMattersId int `orm:"column(rs_matters_id);pk"`
  395. SysUserId int `description:"添加事项人id"`
  396. SysUserRealName string `description:"创建人姓名"`
  397. StartDate string `description:"开始日期"`
  398. EndDate string `description:"结束日期"`
  399. StartTime string `description:"开始时间"`
  400. EndTime string `description:"结束时间"`
  401. StartWeek string `description:"开始日期周"`
  402. EndWeek string `description:"结束日期周"`
  403. MatterContent string `description:"事项内容"`
  404. Status int8 `description:"状态:1:进行中,6:已结束"`
  405. CreateTime time.Time `description:"创建时间"`
  406. ModifyTime time.Time `description:"修改时间"`
  407. IsSynced int `description:"是否与上海同步 0:未同步 1:已同步"`
  408. EditReason string `description:"修改原因"`
  409. IsSeller int `description:"是否为销售事项: 0-否; 1-是"`
  410. }
  411. // 添加RsCalendarResearcher
  412. func AddRsMatters(item *RsMatters) (id int64, err error) {
  413. o := orm.NewOrm()
  414. id, err = o.Insert(item)
  415. return
  416. }
  417. type UpdateMattersReq struct {
  418. RsMattersId int `orm:"column(rs_matters_id);pk"`
  419. StartDate string `description:"开始日期"`
  420. EndDate string `description:"结束日期"`
  421. StartTime string `description:"开始时间"`
  422. EndTime string `description:"结束时间"`
  423. StartWeek string `description:"开始日期周"`
  424. EndWeek string `description:"结束日期周"`
  425. MatterContent string `description:"事项内容"`
  426. EditReason string `description:"修改原因"`
  427. }
  428. // 更新
  429. func UpdateRsMatters(where, updateParams map[string]interface{}) error {
  430. o := orm.NewOrm()
  431. ptrStructOrTableName := "rs_matters"
  432. qs := o.QueryTable(ptrStructOrTableName)
  433. for expr, exprV := range where {
  434. qs = qs.Filter(expr, exprV)
  435. }
  436. _, err := qs.Update(updateParams)
  437. return err
  438. }
  439. type DeleteMattersReq struct {
  440. RsMattersId int `description:"事项id"`
  441. }
  442. // 删除事项
  443. func DeleteRsMatters(rsMattersId int) (err error) {
  444. o := orm.NewOrm()
  445. sql := ` DELETE FROM rs_matters WHERE rs_matters_id=? `
  446. _, err = o.Raw(sql, rsMattersId).Exec()
  447. return err
  448. }
  449. type RsMattersView struct {
  450. RsMattersId int `orm:"column(rs_matters_id);pk"`
  451. SysUserId int `description:"添加事项人id"`
  452. SysUserRealName string `description:"创建人姓名"`
  453. StartDate string `description:"开始日期"`
  454. EndDate string `description:"结束日期"`
  455. StartTime string `description:"开始时间"`
  456. EndTime string `description:"结束时间"`
  457. StartWeek string `description:"开始日期周"`
  458. EndWeek string `description:"结束日期周"`
  459. MatterContent string `description:"事项内容"`
  460. Status int8 `description:"状态:1:进行中,6:已结束"`
  461. CreateTime string `description:"创建时间"`
  462. ModifyTime string `description:"修改时间"`
  463. IsSynced int `description:"是否与上海同步 0:未同步 1:已同步"`
  464. EditReason string `description:"修改原因"`
  465. ButtonAuth RsMatterButton `description:"按钮权限"`
  466. }
  467. // RsMatterButton
  468. type RsMatterButton struct {
  469. EditDisabled bool `description:"禁用编辑"`
  470. RemoveDisabled bool `description:"禁用删除"`
  471. }
  472. func GetCalendarDetailList(condition string, pars []interface{}) (list []*CalendarListView, err error) {
  473. o := orm.NewOrm()
  474. sql := `SELECT a.*,b.*,c.status AS company_status FROM rs_calendar AS a
  475. INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id=b.rs_calendar_id
  476. LEFT JOIN company_product AS c ON a.company_id=c.company_id AND c.product_id=1
  477. WHERE 1=1 `
  478. if condition != "" {
  479. sql += condition
  480. }
  481. sql += ` ORDER BY a.create_time DESC `
  482. _, err = o.Raw(sql, pars).QueryRows(&list)
  483. return
  484. }
  485. func GetCalendarDetailListinit() (list []*CalendarListView, err error) {
  486. o := orm.NewOrm()
  487. sql := `SELECT
  488. a.rs_calendar_id,
  489. b.researcher_name , b.start_date , b.start_time,a.company_name ,sys_user_real_name
  490. FROM
  491. rs_calendar AS a
  492. INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id = b.rs_calendar_id
  493. WHERE
  494. 1 = 1
  495. AND a.sys_user_id IN (SELECT admin_id FROM admin WHERE role_type_code IN ('rai_group','rai_seller') and role_id NOT IN (28,69,70) AND enabled = 1 )
  496. AND a.rs_calendar_id NOT IN (SELECT rs_calendar_id FROM rs_calendar_meeting_user GROUP BY rs_calendar_id )
  497. AND a.activity_type = '路演'
  498. AND b.start_date >= '2024-01-01'
  499. AND b.end_date <='2024-10-07'
  500. AND a.company_name !=''
  501. AND b.status IN (2,6)
  502. ORDER BY start_date ASC ,start_time ASC `
  503. _, err = o.Raw(sql).QueryRows(&list)
  504. return
  505. }
  506. func GetRsMattersList(startDate, endDate string, researcherId int) (list []*RsMatters, err error) {
  507. o := orm.NewOrm()
  508. //sql := `SELECT * FROM rs_matters AS a WHERE a.start_date>=? AND a.end_date<=? AND sys_user_id=? `
  509. sql := `SELECT * FROM rs_matters AS a WHERE sys_user_id=? `
  510. sql += ` ORDER BY a.create_time DESC `
  511. //_, err = o.Raw(sql, startDate, endDate, researcherId).QueryRows(&list)
  512. _, err = o.Raw(sql, researcherId).QueryRows(&list)
  513. return
  514. }
  515. type CalendarDetailResp struct {
  516. CalendarList []*CalendarListView
  517. RsMattersList []*RsMatters
  518. }
  519. type EditActivityReq struct {
  520. EditType int `description:"修改方式: 1:修改,2:修改重提"`
  521. RsCalendarId int `description:"路演活动id"`
  522. RsCalendarResearcherId int `description:"活动研究员id"`
  523. ActivityType string `description:"活动类型"`
  524. RoadshowType string `description:"路演形式"`
  525. RoadshowPlatform string `description:"路演平台"`
  526. CompanyId int `description:"客户id"`
  527. CompanyName string `description:"客户名称"`
  528. Province string `description:"省"`
  529. ProvinceCode string `description:"省编码"`
  530. City string `description:"市"`
  531. CityCode string `description:"市编码"`
  532. District string `description:"区"`
  533. Theme string `description:"会议主题"`
  534. CooperationName string `description:"合作方名称"`
  535. ActivityCategory string `description:"活动类别"`
  536. ResearcherList []*CalendarResearcher
  537. EnglishCompany int `description:"是否为英文客户"`
  538. }
  539. // 更新活动信息
  540. func UpdateRsCalendar(where, updateParams map[string]interface{}) error {
  541. o := orm.NewOrm()
  542. ptrStructOrTableName := "rs_calendar"
  543. qs := o.QueryTable(ptrStructOrTableName)
  544. for expr, exprV := range where {
  545. qs = qs.Filter(expr, exprV)
  546. }
  547. _, err := qs.Update(updateParams)
  548. return err
  549. }
  550. func GetMattersListCount(condition string, pars []interface{}) (count int, err error) {
  551. o := orm.NewOrm()
  552. sql := `SELECT COUNT(1) AS count FROM rs_matters AS a
  553. WHERE 1=1 `
  554. if condition != "" {
  555. sql += condition
  556. }
  557. err = o.Raw(sql, pars).QueryRow(&count)
  558. return
  559. }
  560. func GetMattersList(condition string, pars []interface{}, pageLimit ...int) (list []*RsMattersView, err error) {
  561. o := orm.NewOrm()
  562. sql := `SELECT * FROM rs_matters AS a
  563. WHERE 1=1 `
  564. if condition != "" {
  565. sql += condition
  566. }
  567. sql += ` ORDER BY a.create_time DESC LIMIT ?,? `
  568. _, err = o.Raw(sql, pars, pageLimit).QueryRows(&list)
  569. return
  570. }
  571. type MattersListResp struct {
  572. Paging *paging.PagingItem
  573. List []*RsMattersView
  574. }
  575. // 删除
  576. func DeleteCalendar(rsCalendarId, rsCalendarResearcherId int) (err error) {
  577. o := orm.NewOrm()
  578. sql := ` DELETE FROM rs_calendar_researcher WHERE rs_calendar_id=? `
  579. _, err = o.Raw(sql, rsCalendarId).Exec()
  580. if err != nil {
  581. return err
  582. }
  583. //var count int
  584. //sql = ` SELECT COUNT(1) AS count FROM rs_calendar_researcher WHERE rs_calendar_id=? `
  585. //err = o.Raw(sql, rsCalendarId).QueryRow(&count)
  586. //if err != nil && err.Error() != utils.ErrNoRow() {
  587. // return err
  588. //}
  589. //if count <= 0 {
  590. // sql := ` DELETE FROM rs_calendar WHERE rs_calendar_id=? `
  591. // _, err = o.Raw(sql, rsCalendarId).Exec()
  592. // if err != nil {
  593. // return err
  594. // }
  595. //}
  596. sql = ` DELETE FROM rs_calendar WHERE rs_calendar_id=? `
  597. _, err = o.Raw(sql, rsCalendarId).Exec()
  598. return err
  599. }
  600. // 删除
  601. func DeleteRsCalendarResearcher(rsCalendarId int) (err error) {
  602. o := orm.NewOrm()
  603. sql := ` DELETE FROM rs_calendar_researcher WHERE rs_calendar_id=? `
  604. _, err = o.Raw(sql, rsCalendarId).Exec()
  605. return err
  606. }
  607. func CheckMattersCount(condition string, pars []interface{}) (count int, err error) {
  608. o := orm.NewOrm()
  609. sql := `SELECT COUNT(1) AS count FROM rs_matters AS a
  610. WHERE 1=1 `
  611. if condition != "" {
  612. sql += condition
  613. }
  614. err = o.Raw(sql, pars).QueryRow(&count)
  615. return
  616. }
  617. func CheckCalendarResearcherCount(condition string, pars []interface{}) (count int, err error) {
  618. o := orm.NewOrm()
  619. sql := `SELECT COUNT(1) AS count FROM rs_calendar_researcher AS a
  620. WHERE 1=1 `
  621. if condition != "" {
  622. sql += condition
  623. }
  624. err = o.Raw(sql, pars).QueryRow(&count)
  625. return
  626. }
  627. func GetResearcherFromAdmin(condition string, pars []interface{}) (lists []*system.Admin, err error) {
  628. o := orm.NewOrm()
  629. sql := `SELECT * FROM admin WHERE 1=1 `
  630. if condition != "" {
  631. sql += condition
  632. }
  633. _, err = o.Raw(sql, pars).QueryRows(&lists)
  634. return
  635. }
  636. func GetCreditCodeFromCompany(companyId int) (creditCode string, err error) {
  637. o := orm.NewOrm()
  638. companyItem := company.Company{CompanyId: companyId}
  639. err = o.Read(&companyItem)
  640. if err != nil {
  641. return "", err
  642. }
  643. creditCode = companyItem.CreditCode
  644. return
  645. }
  646. type SHCalendar struct {
  647. CalendarId int `description:"日历id"`
  648. UserPhone string `description:"创建人手机号"`
  649. ResearcherPhone string `description:"研究员手机号"`
  650. IndustryName string `description:"行业名称"`
  651. CreditCode string `description:"社会信用码"`
  652. content string `description:"日历内容"`
  653. StartTime string `description:"开始时间"`
  654. EndTime string `description:"结束时间"`
  655. }
  656. func GetRsCalendarResearcherByRsCalendarIdAndResearcherId(rsCalendarId, researcherId int) (item *RsCalendarResearcher, err error) {
  657. o := orm.NewOrm()
  658. sql := `SELECT * FROM rs_calendar_researcher WHERE rs_calendar_id=? AND researcher_id=? `
  659. err = o.Raw(sql, rsCalendarId, researcherId).QueryRow(&item)
  660. return
  661. }
  662. // GetRsCalendarResearcherListByRsCalendarId 根据路演id获取路演研究员列表
  663. func GetRsCalendarResearcherListByRsCalendarId(rsCalendarId int) (items []*RsCalendarResearcher, err error) {
  664. o := orm.NewOrm()
  665. sql := `SELECT * FROM rs_calendar_researcher WHERE rs_calendar_id=? `
  666. _, err = o.Raw(sql, rsCalendarId).QueryRows(&items)
  667. return
  668. }
  669. func GetMattersById(rsMatters int) (item *RsMatters, err error) {
  670. o := orm.NewOrm()
  671. sql := `SELECT * FROM rs_matters
  672. WHERE rs_matters_id=? `
  673. err = o.Raw(sql, rsMatters).QueryRow(&item)
  674. return
  675. }
  676. func GetRsCalendarResearcherExist(rsCalendarResearcherId, rsCalendarId, researcherId int) (count int, err error) {
  677. o := orm.NewOrm()
  678. sql := `SELECT COUNT(1) AS count FROM rs_calendar_researcher WHERE rs_calendar_researcher_id=? AND rs_calendar_id=? AND researcher_id=? `
  679. err = o.Raw(sql, rsCalendarResearcherId, rsCalendarId, researcherId).QueryRow(&count)
  680. return
  681. }
  682. func GetRsCalendarResearcherByCalendarId(rsCalendarId int) (item []*RsCalendarResearcher, err error) {
  683. o := orm.NewOrm()
  684. sql := `SELECT * FROM rs_calendar_researcher WHERE rs_calendar_id=? `
  685. _, err = o.Raw(sql, rsCalendarId).QueryRows(&item)
  686. return
  687. }
  688. type PublicMeetingDetailResp struct {
  689. Group []*PublicMeetingGroup
  690. }
  691. type PublicMeetingGroup struct {
  692. UnionCode string
  693. MinTime string
  694. MaxTime string
  695. CalendarList []*CalendarListView
  696. }
  697. func GetPublicCalendarDetailList(condition string, pars []interface{}) (list []*CalendarListView, err error) {
  698. o := orm.NewOrm()
  699. sql := `SELECT a.*,b.*,c.status AS company_status FROM rs_calendar AS a
  700. INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id=b.rs_calendar_id
  701. LEFT JOIN company_product AS c ON a.company_id=c.company_id AND c.product_id=1
  702. INNER JOIN admin AS d ON b.researcher_id=d.admin_id
  703. WHERE 1=1 AND d.enabled=1 `
  704. if condition != "" {
  705. sql += condition
  706. }
  707. sql += ` ORDER BY a.create_time DESC `
  708. _, err = o.Raw(sql, pars).QueryRows(&list)
  709. return
  710. }
  711. type AdminInfo struct {
  712. AdminId int
  713. RealName string
  714. }
  715. func GetOverseaCustomCalendarSellerList() (list []*AdminInfo, err error) {
  716. o := orm.NewOrm()
  717. sql1 := `SELECT a.sys_user_id FROM rs_calendar AS a
  718. INNER JOIN rs_report_record AS b ON a.rs_calendar_id=b.rs_calendar_id
  719. JOIN company_product AS c ON a.company_id=c.company_id AND c.product_id=1
  720. JOIN company AS d ON c.company_id=d.company_id
  721. INNER JOIN overseas_custom_seller AS f ON c.seller_id=f.seller_id
  722. where c.is_overseas = 0 and a.english_company= 0 AND a.source = 0 AND b.rs_calendar_researcher_status=2 AND a.sys_user_id != 0 `
  723. sql2 := `SELECT aa.sys_user_id FROM rs_calendar AS aa
  724. INNER JOIN rs_report_record AS bb ON aa.rs_calendar_id=bb.rs_calendar_id
  725. where aa.english_company= 1 AND aa.source = 0 AND bb.rs_calendar_researcher_status=2 AND aa.sys_user_id != 0`
  726. sql := `SELECT n.admin_id,n.real_name FROM (` + sql1 + ` UNION ALL ` + sql2
  727. sql += ` ) AS m
  728. JOIN admin n on m.sys_user_id=n.admin_id
  729. WHERE 1=1 Group by sys_user_id order by sys_user_id asc`
  730. _, err = o.Raw(sql).QueryRows(&list)
  731. return
  732. }
  733. func GetOverseaCustomCalendarResearcherList() (list []*AdminInfo, err error) {
  734. o := orm.NewOrm()
  735. sql1 := `SELECT b.researcher_id FROM rs_calendar AS a
  736. INNER JOIN rs_report_record AS b ON a.rs_calendar_id=b.rs_calendar_id
  737. JOIN company_product AS c ON a.company_id=c.company_id AND c.product_id=1
  738. JOIN company AS d ON c.company_id=d.company_id
  739. INNER JOIN overseas_custom_seller AS f ON c.seller_id=f.seller_id
  740. where c.is_overseas = 0 and a.english_company= 0 AND a.source = 0 AND b.rs_calendar_researcher_status=2 AND b.researcher_id != 0`
  741. sql2 := `SELECT bb.researcher_id FROM rs_calendar AS aa
  742. INNER JOIN rs_report_record AS bb ON aa.rs_calendar_id=bb.rs_calendar_id
  743. where aa.english_company= 1 AND aa.source = 0 AND bb.rs_calendar_researcher_status=2 AND bb.researcher_id != 0 `
  744. sql := `SELECT n.admin_id,n.real_name FROM (` + sql1 + ` UNION ALL ` + sql2
  745. sql += ` ) AS m
  746. JOIN admin n on m.researcher_id=n.admin_id
  747. WHERE 1=1 Group by researcher_id order by researcher_id asc`
  748. _, err = o.Raw(sql).QueryRows(&list)
  749. return
  750. }
  751. type OverseaCustomRecordInfoResp struct {
  752. Paging *paging.PagingItem
  753. List []*OverseaCustomRecordInfo
  754. }
  755. type OverseaCustomRecordInfo struct {
  756. RsCalendarId int
  757. CompanyId int
  758. Source int
  759. RoadshowType string
  760. RoadshowPlatform string
  761. SellerName string
  762. ResearcherName string
  763. CompanyName string
  764. CompanyStatus string
  765. StartDate string
  766. }
  767. func GetOverseaCustomCalendarList(keyword, sellerId, researcherId, startDate, endDate, companyStatus, sortField, sortDesc string, startSize, pageSize int) (total int, list []*OverseaCustomRecordInfo, err error) {
  768. var databaseName string
  769. if utils.RunMode == "debug" {
  770. databaseName = "test_v2_hongze_rddp"
  771. } else {
  772. databaseName = "hongze_rddp"
  773. }
  774. companyStatusList := make([]string, 0)
  775. if companyStatus != "" {
  776. companyStatusList = strings.Split(companyStatus, ",")
  777. }
  778. lenCompanyStatusList := len(companyStatusList)
  779. o := orm.NewOrm()
  780. pars := make([]interface{}, 0)
  781. sql1 := `SELECT d.company_name,d.overseas_status company_status,b.start_date,a.rs_calendar_id,a.roadshow_type,a.roadshow_platform,a.sys_user_real_name seller_name,b.researcher_name as base_researcher_name,2 AS source,d.company_id FROM rs_calendar AS a
  782. INNER JOIN rs_report_record AS b ON a.rs_calendar_id=b.rs_calendar_id
  783. JOIN company_product AS c ON a.company_id=c.company_id AND c.product_id=1
  784. JOIN company AS d ON c.company_id=d.company_id
  785. INNER JOIN overseas_custom_seller AS f ON c.seller_id=f.seller_id
  786. where c.is_overseas = 0 and a.english_company= 0 AND a.source = 0 AND b.rs_calendar_researcher_status=2 AND b.researcher_id != 0`
  787. if keyword != "" {
  788. sql1 += ` AND d.company_name like ? `
  789. pars = utils.GetLikeKeywordPars(pars, keyword, 1)
  790. }
  791. if sellerId != "" {
  792. sql1 += fmt.Sprintf(` AND a.sys_user_id in (%s) `, sellerId)
  793. }
  794. if startDate != "" {
  795. sql1 += ` AND b.start_date >= ? `
  796. pars = append(pars, startDate)
  797. }
  798. if endDate != "" {
  799. sql1 += ` AND b.start_date <= ? `
  800. pars = append(pars, endDate)
  801. }
  802. if lenCompanyStatusList > 0 {
  803. sql1 += ` AND d.overseas_status in (` + utils.GetOrmInReplace(lenCompanyStatusList) + ") "
  804. pars = append(pars, companyStatusList)
  805. }
  806. sql2 := fmt.Sprintf(`SELECT cc.company_name,cc.overseas_status company_status,bb.start_date,aa.rs_calendar_id,aa.roadshow_type,aa.roadshow_platform,aa.sys_user_real_name seller_name,bb.researcher_name as base_researcher_name,1 AS source,cc.company_id+10000000 FROM rs_calendar AS aa
  807. INNER JOIN rs_report_record AS bb ON aa.rs_calendar_id=bb.rs_calendar_id
  808. INNER JOIN %s.english_company AS cc ON aa.company_id=cc.company_id
  809. where aa.english_company= 1 AND aa.source = 0 AND cc.is_deleted=0 AND bb.rs_calendar_researcher_status=2 AND bb.researcher_id != 0 `, databaseName)
  810. if keyword != "" {
  811. sql2 += ` AND cc.company_name like ? `
  812. pars = utils.GetLikeKeywordPars(pars, keyword, 1)
  813. }
  814. if sellerId != "" {
  815. sql2 += fmt.Sprintf(` AND aa.sys_user_id in (%s) `, sellerId)
  816. }
  817. if startDate != "" {
  818. sql2 += ` AND bb.start_date >= ? `
  819. pars = append(pars, startDate)
  820. }
  821. if endDate != "" {
  822. sql2 += ` AND bb.start_date <= ? `
  823. pars = append(pars, endDate)
  824. }
  825. if lenCompanyStatusList > 0 {
  826. sql2 += ` AND cc.overseas_status in (` + utils.GetOrmInReplace(lenCompanyStatusList) + ") "
  827. pars = append(pars, companyStatusList)
  828. }
  829. rsCalendarIdList := make([]int, 0)
  830. if researcherId != `` {
  831. rsCalendarIdSql := fmt.Sprintf("select rs_calendar_id from rs_calendar_researcher where researcher_id in (%s) group by rs_calendar_id", researcherId)
  832. _, err = o.Raw(rsCalendarIdSql).QueryRows(&rsCalendarIdList)
  833. if err != nil {
  834. return
  835. }
  836. }
  837. rsCalendarIdNum := len(rsCalendarIdList)
  838. // 汇总数据
  839. totalSql := `SELECT COUNT(1) FROM (SELECT rs_calendar_id FROM (` + sql1 + ` UNION ALL ` + sql2
  840. totalSql += ` ) AS m WHERE 1=1 `
  841. if rsCalendarIdNum > 0 {
  842. totalSql += fmt.Sprintf(` AND rs_calendar_id IN (` + utils.GetOrmInReplace(rsCalendarIdNum) + `)`)
  843. pars = append(pars, rsCalendarIdList)
  844. }
  845. totalSql += ` Group by rs_calendar_id) fff`
  846. err = o.Raw(totalSql, pars).QueryRow(&total)
  847. if err != nil {
  848. return
  849. }
  850. // 列表数据
  851. sql := `SELECT m.*,GROUP_CONCAT(DISTINCT base_researcher_name ORDER BY rs_calendar_id ASC SEPARATOR ',') AS researcher_name FROM (` + sql1 + ` UNION ALL ` + sql2
  852. sql += ` ) AS m WHERE 1=1 `
  853. if rsCalendarIdNum > 0 {
  854. sql += fmt.Sprintf(` AND rs_calendar_id IN (` + utils.GetOrmInReplace(rsCalendarIdNum) + `)`)
  855. }
  856. sql += fmt.Sprintf(` Group by rs_calendar_id order by %s %s `, sortField, sortDesc)
  857. sql += ` LIMIT ?,? `
  858. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  859. return
  860. }
  861. func GetOverseaCustomCalendarList2(sellerId, researcherId, startDate, endDate, companyStatus string) (list []*RsReportRecordList, err error) {
  862. var databaseName string
  863. if utils.RunMode == "debug" {
  864. databaseName = "test_v2_hongze_rddp"
  865. } else {
  866. databaseName = "hongze_rddp"
  867. }
  868. companyStatusList := make([]string, 0)
  869. if companyStatus != "" {
  870. companyStatusList = strings.Split(companyStatus, ",")
  871. }
  872. lenCompanyStatusList := len(companyStatusList)
  873. o := orm.NewOrm()
  874. pars := make([]interface{}, 0)
  875. sql1 := `SELECT b.start_date,b.end_date,b.start_time,b.end_time,a.rs_calendar_id,b.seller_id,b.seller_name,b.researcher_name,b.company_name,b.company_id,d.overseas_status as company_status,b.roadshow_type,a.theme,a.roadshow_platform,a.province as province,a.city as city FROM rs_calendar AS a
  876. INNER JOIN rs_report_record AS b ON a.rs_calendar_id=b.rs_calendar_id
  877. JOIN company_product AS c ON a.company_id=c.company_id AND c.product_id=1
  878. JOIN company AS d ON c.company_id=d.company_id
  879. INNER JOIN overseas_custom_seller AS f ON c.seller_id=f.seller_id
  880. where c.is_overseas = 0 and a.english_company= 0 AND a.source = 0 AND b.rs_calendar_researcher_status=2 AND b.researcher_id != 0`
  881. if startDate != "" {
  882. sql1 += ` AND b.start_date >= ? `
  883. pars = append(pars, startDate)
  884. }
  885. if endDate != "" {
  886. sql1 += ` AND b.start_date <= ? `
  887. pars = append(pars, endDate)
  888. }
  889. if lenCompanyStatusList > 0 {
  890. sql1 += ` AND d.overseas_status in (` + utils.GetOrmInReplace(lenCompanyStatusList) + ") "
  891. pars = append(pars, companyStatusList)
  892. }
  893. if sellerId != "" {
  894. sql1 += fmt.Sprintf(` AND b.seller_id in (%s) `, sellerId)
  895. }
  896. if researcherId != "" {
  897. sql1 += fmt.Sprintf(` AND b.researcher_id in (%s) `, researcherId)
  898. }
  899. sql2 := fmt.Sprintf(`SELECT bb.start_date,bb.end_date,bb.start_time,bb.end_time,aa.rs_calendar_id,bb.seller_id,bb.seller_name,bb.researcher_name,aa.company_name,aa.company_id,cc.overseas_status as company_status,bb.roadshow_type,aa.theme,aa.roadshow_platform,aa.province as province,aa.city as city FROM rs_calendar AS aa
  900. INNER JOIN rs_report_record AS bb ON aa.rs_calendar_id=bb.rs_calendar_id
  901. INNER JOIN %s.english_company AS cc ON aa.company_id=cc.company_id
  902. where aa.english_company= 1 AND aa.source = 0 AND cc.is_deleted=0 AND bb.rs_calendar_researcher_status=2 AND bb.researcher_id != 0 `, databaseName)
  903. if startDate != "" {
  904. sql2 += ` AND bb.start_date >= ? `
  905. pars = append(pars, startDate)
  906. }
  907. if endDate != "" {
  908. sql2 += ` AND bb.start_date <= ? `
  909. pars = append(pars, endDate)
  910. }
  911. if lenCompanyStatusList > 0 {
  912. sql2 += ` AND cc.overseas_status in (` + utils.GetOrmInReplace(lenCompanyStatusList) + ") "
  913. pars = append(pars, companyStatusList)
  914. }
  915. if sellerId != "" {
  916. sql2 += fmt.Sprintf(` AND bb.seller_id in (%s) `, sellerId)
  917. }
  918. if researcherId != "" {
  919. sql2 += fmt.Sprintf(` AND bb.researcher_id in (%s) `, researcherId)
  920. }
  921. // 列表数据
  922. sql := `SELECT m.* FROM (` + sql1 + ` UNION ALL ` + sql2
  923. sql += ` ) AS m WHERE 1=1 `
  924. sql += ` Group by rs_calendar_id `
  925. _, err = o.Raw(sql, pars).QueryRows(&list)
  926. return
  927. }
  928. func GetRsCalendarResearcherListInit16_2() (item []*RsCalendar, err error) {
  929. o := orm.NewOrm()
  930. sql := `SELECT * FROM rs_calendar WHERE activity_type = '路演' AND company_id > 0 AND sys_user_id IN (SELECT admin_id FROM admin WHERE role_type_code IN ('rai_seller','rai_group','rai_admin') ) AND seller_id = 0 `
  931. _, err = o.Raw(sql).QueryRows(&item)
  932. return
  933. }
  934. // 修改可见范围
  935. func UpdateRsCalendarSeller(seller_id, share_seller_id, rs_calendar_id int) (err error) {
  936. o := orm.NewOrm()
  937. sql := `UPDATE rs_calendar SET seller_id=?, share_seller_id= ? WHERE rs_calendar_id =? `
  938. _, err = o.Raw(sql, seller_id, share_seller_id, rs_calendar_id).Exec()
  939. return
  940. }
  941. func GetCalendarListInit(condition string, pars []interface{}) (list []*CalendarListView, err error) {
  942. o := orm.NewOrm()
  943. sql := `SELECT
  944. *
  945. FROM
  946. rs_calendar_researcher AS r
  947. INNER JOIN rs_calendar AS c ON r.rs_calendar_id = c.rs_calendar_id
  948. WHERE
  949. 1 = 1
  950. AND c.activity_type = '路演'
  951. AND c.company_name != ''
  952. AND r.start_date >= '2024-09-01'
  953. AND r.start_date <= '2024-12-31'
  954. AND r.STATUS IN ( 2, 6 ) ` + condition + `
  955. ORDER BY
  956. r.start_date DESC,
  957. r.start_time DESC`
  958. _, err = o.Raw(sql, pars).QueryRows(&list)
  959. return
  960. }