calendar.go 36 KB

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