calendar.go 32 KB

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