calendar.go 39 KB

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