calendar.go 34 KB

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