quanshi.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. package yb
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "github.com/tealeg/xlsx"
  7. "hongze/hz_crm_api/models"
  8. "hongze/hz_crm_api/models/yb"
  9. "hongze/hz_crm_api/models/yb/request"
  10. ybResp "hongze/hz_crm_api/models/yb/response"
  11. ybService "hongze/hz_crm_api/services/yb"
  12. "hongze/hz_crm_api/utils"
  13. "os"
  14. "path/filepath"
  15. "time"
  16. )
  17. // CreateQs
  18. // @Title 创建全时会议
  19. // @Description 创建全时会议接口
  20. // @Param request body request.CreateQsReq true "type json string"
  21. // @router /activity/create_qs [post]
  22. func (this *ActivityController) CreateQs() {
  23. br := new(models.BaseResponse).Init()
  24. defer func() {
  25. this.Data["json"] = br
  26. this.ServeJSON()
  27. }()
  28. sysUser := this.SysUser
  29. if sysUser == nil {
  30. br.Msg = "请登录"
  31. br.ErrMsg = "请登录,SysUser Is Empty"
  32. br.Ret = 408
  33. return
  34. }
  35. var req request.CreateQsReq
  36. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  37. if err != nil {
  38. br.Msg = "参数解析异常!"
  39. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  40. return
  41. }
  42. if req.ActivityId <= 0 {
  43. br.Msg = "请选择活动!"
  44. br.ErrMsg = "活动ID有误!"
  45. return
  46. }
  47. if req.Time <= 0 {
  48. br.Msg = "请输入大于0的会议时长!"
  49. br.ErrMsg = "请输入大于0的会议时长!"
  50. return
  51. }
  52. err, errMsg := ybService.CreateQsEvent(req)
  53. if err != nil {
  54. br.Msg = "创建全时会议失败!" + errMsg
  55. br.ErrMsg = "创建全时会议失败,Err:" + err.Error()
  56. return
  57. }
  58. msg := "创建成功"
  59. br.Ret = 200
  60. br.Success = true
  61. br.Msg = msg
  62. }
  63. // CancelQs
  64. // @Title 取消全时会议
  65. // @Description 取消全时会议解耦
  66. // @Param request body request.CancelQsReq true "type json string"
  67. // @Success 200 {object} 取消发布成功
  68. // @router /activity/cancel_qs [post]
  69. func (this *ActivityController) CancelQs() {
  70. br := new(models.BaseResponse).Init()
  71. defer func() {
  72. this.Data["json"] = br
  73. this.ServeJSON()
  74. }()
  75. sysUser := this.SysUser
  76. if sysUser == nil {
  77. br.Msg = "请登录"
  78. br.ErrMsg = "请登录,SysUser Is Empty"
  79. br.Ret = 408
  80. return
  81. }
  82. var req request.CancelQsReq
  83. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  84. if err != nil {
  85. br.Msg = "参数解析异常!"
  86. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  87. return
  88. }
  89. if req.ActivityId <= 0 {
  90. br.Msg = "活动ID异常!"
  91. br.ErrMsg = "活动ID异常"
  92. return
  93. }
  94. err, errMsg := ybService.CancelQsEvent(req.ActivityId)
  95. if err != nil {
  96. br.Msg = "创建全时会议失败!" + errMsg
  97. br.ErrMsg = "创建全时会议失败,Err:" + err.Error()
  98. return
  99. }
  100. msg := "取消会议成功"
  101. br.Ret = 200
  102. br.Success = true
  103. br.Msg = msg
  104. }
  105. // QsList
  106. // @Title 获取到会列表
  107. // @Description 获取到会列表
  108. // @Param Keyword query string false "搜索关键字"
  109. // @Param ActivityTypeIds query string false "活动类别ids,多个用英文逗号分割"
  110. // @Param ActiveStatus query int8 false "活动进行状态,枚举值:1:未开始;2:进行中;3:已结束"
  111. // @Param StartDate query string false "活动开始日期,格式:2021-11-09"
  112. // @Param EndDate query string false "活动结束日期,格式:2021-11-10"
  113. // @Success 200 {object} []yb.QsListResp
  114. // @router /activity/quanshi/list [get]
  115. func (this *ActivityController) QsList() {
  116. br := new(models.BaseResponse).Init()
  117. defer func() {
  118. this.Data["json"] = br
  119. this.ServeJSON()
  120. }()
  121. sysUser := this.SysUser
  122. if sysUser == nil {
  123. br.Msg = "请登录"
  124. br.ErrMsg = "请登录,SysUser Is Empty"
  125. br.Ret = 408
  126. return
  127. }
  128. keyword := this.GetString("Keyword")
  129. activityTypeIds := this.GetString("ActivityTypeIds", "")
  130. activeStatus, _ := this.GetInt("ActiveStatus", 0)
  131. //publishStatus, _ := this.GetInt("PublishStatus", 0)
  132. startDate := this.GetString("StartDate")
  133. endDate := this.GetString("EndDate")
  134. pageSize, _ := this.GetInt("PageSize")
  135. currentIndex, _ := this.GetInt("CurrentIndex")
  136. var startSize int
  137. if pageSize <= 0 {
  138. pageSize = utils.PageSize20
  139. }
  140. if currentIndex <= 0 {
  141. currentIndex = 1
  142. }
  143. startSize = paging.StartIndex(currentIndex, pageSize)
  144. condition := ""
  145. pars := make([]interface{}, 0)
  146. //关键字
  147. if keyword != "" {
  148. condition += ` AND a.activity_name LIKE '%` + keyword + `%' `
  149. }
  150. //活动类别ids
  151. if activityTypeIds != "" {
  152. condition += ` AND a.activity_type_id IN (` + activityTypeIds + `)`
  153. }
  154. //活动开始与否状态
  155. order := ""
  156. if activeStatus > 0 {
  157. nowTime := time.Now().Format(utils.FormatDateTime)
  158. //1:未开始;2:进行中;3:已结束"
  159. switch activeStatus {
  160. case 1:
  161. condition += ` AND a.start_time > ? `
  162. pars = append(pars, nowTime)
  163. case 2:
  164. condition += ` AND a.start_time <= ? and end_time >= ? `
  165. pars = append(pars, nowTime, nowTime)
  166. order = " a.start_time DESC"
  167. case 3:
  168. condition += ` AND a.end_time < ? `
  169. pars = append(pars, nowTime)
  170. order = " a.start_time DESC"
  171. }
  172. }
  173. //活动是否发布
  174. //if publishStatus >= 0 {
  175. // condition += ` AND a.publish_status = ? `
  176. // pars = append(pars, publishStatus)
  177. //}
  178. //活动时间
  179. if startDate != "" && endDate != "" {
  180. condition += ` AND a.start_time >= ? and a.end_time <= ?`
  181. pars = append(pars, startDate+" 00:00:00", endDate+" 23:59:59")
  182. }
  183. // 获取所有的分类
  184. total, list, err := yb.GetQsList(condition, order, pars, startSize, pageSize)
  185. if err != nil {
  186. br.Msg = "获取活动列表失败!"
  187. br.ErrMsg = "获取活动列表失败,Err:" + err.Error()
  188. return
  189. }
  190. //if len(list) > 0 {
  191. // for _, activityQs := range list {
  192. // if activityQs.QsStatus == 2 {
  193. // activityQs.RealTime = activityQs.EventEndTime.Unix() - activityQs.EventStartTime.Unix()
  194. // }
  195. // }
  196. //}
  197. page := paging.GetPaging(currentIndex, pageSize, total)
  198. resp := ybResp.QsListResp{
  199. List: list,
  200. Paging: page,
  201. }
  202. br.Ret = 200
  203. br.Success = true
  204. br.Msg = "获取成功"
  205. br.Data = resp
  206. }
  207. // QsUserList
  208. // @Title 获取到会用户列表
  209. // @Description 获取到会用户列表
  210. // @Param QsId query int false "全时会议与活动的关联id"
  211. // @Param DataType query int8 false "活动进行状态,枚举值:1:已知联系人;2:未知联系人"
  212. // @Success 200 {object} []yb.QsUserListResp
  213. // @router /activity/quanshi/user_list [get]
  214. func (this *ActivityController) QsUserList() {
  215. br := new(models.BaseResponse).Init()
  216. defer func() {
  217. this.Data["json"] = br
  218. this.ServeJSON()
  219. }()
  220. sysUser := this.SysUser
  221. if sysUser == nil {
  222. br.Msg = "请登录"
  223. br.ErrMsg = "请登录,SysUser Is Empty"
  224. br.Ret = 408
  225. return
  226. }
  227. dataType, _ := this.GetInt("DataType", 0)
  228. qsId, _ := this.GetInt("QsId", 0)
  229. if qsId <= 0 {
  230. br.Msg = "请选择活动"
  231. br.ErrMsg = "请选择活动"
  232. return
  233. }
  234. if dataType <= 0 {
  235. br.Msg = "请选择类型"
  236. br.ErrMsg = "请选择类型"
  237. return
  238. }
  239. pageSize, _ := this.GetInt("PageSize")
  240. currentIndex, _ := this.GetInt("CurrentIndex")
  241. var startSize int
  242. if pageSize <= 0 {
  243. pageSize = utils.PageSize20
  244. }
  245. if currentIndex <= 0 {
  246. currentIndex = 1
  247. }
  248. startSize = paging.StartIndex(currentIndex, pageSize)
  249. condition := ""
  250. pars := make([]interface{}, 0)
  251. condition += ` AND a.qs_id = ? `
  252. pars = append(pars, qsId)
  253. switch dataType {
  254. case 1:
  255. condition += ` AND a.product_id = ? `
  256. pars = append(pars, 1)
  257. case 2:
  258. condition += ` AND a.product_id = ? `
  259. pars = append(pars, 2)
  260. case 3:
  261. condition += ` AND a.product_id = ? `
  262. pars = append(pars, 0)
  263. }
  264. // 获取所有的用户
  265. total, list, err := yb.GetQsUserList(condition, pars, startSize, pageSize)
  266. if err != nil {
  267. br.Msg = "获取活动列表失败!"
  268. br.ErrMsg = "获取活动列表失败,Err:" + err.Error()
  269. return
  270. }
  271. page := paging.GetPaging(currentIndex, pageSize, total)
  272. resp := ybResp.QsUserListResp{
  273. List: list,
  274. Paging: page,
  275. }
  276. br.Ret = 200
  277. br.Success = true
  278. br.Msg = "获取成功"
  279. br.Data = resp
  280. }
  281. // ExportQsUserList
  282. // @Title 导出全时用户列表
  283. // @Description 导出全时用户列表
  284. // @Param QsId query int false "全时会议与活动的关联id"
  285. // @Success 200 导出成功
  286. // @router /activity/quanshi/user_list/export [get]
  287. func (this *ActivityController) ExportQsUserList() {
  288. br := new(models.BaseResponse).Init()
  289. defer func() {
  290. this.Data["json"] = br
  291. this.ServeJSON()
  292. }()
  293. sysUser := this.SysUser
  294. if sysUser == nil {
  295. br.Msg = "请登录"
  296. br.ErrMsg = "请登录,SysUser Is Empty"
  297. br.Ret = 408
  298. return
  299. }
  300. qsId, _ := this.GetInt("QsId", 0)
  301. if qsId <= 0 {
  302. br.Msg = "请选择活动"
  303. br.ErrMsg = "请选择活动"
  304. return
  305. }
  306. dir, _ := os.Executable()
  307. exPath := filepath.Dir(dir)
  308. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  309. xlsxFile := xlsx.NewFile()
  310. for i := 1; i <= 3; i++ {
  311. var sheetName string
  312. switch i {
  313. case 1:
  314. sheetName = "ficc联系人"
  315. case 2:
  316. sheetName = "权益联系人"
  317. case 3:
  318. sheetName = "未知联系人"
  319. }
  320. sheet, err := xlsxFile.AddSheet(sheetName)
  321. if err != nil {
  322. fmt.Println("新增Sheet失败", err.Error())
  323. br.Msg = "新增Sheet失败"
  324. br.ErrMsg = "新增Sheet失败," + err.Error()
  325. br.Ret = 408
  326. return
  327. }
  328. row := sheet.AddRow()
  329. row.AddCell().SetValue("手机号")
  330. row.AddCell().SetValue("姓名")
  331. row.AddCell().SetValue("注册时间")
  332. row.AddCell().SetValue("累计阅读")
  333. row.AddCell().SetValue("最近阅读")
  334. row.AddCell().SetValue("客户名称")
  335. row.AddCell().SetValue("类型")
  336. row.AddCell().SetValue("状态")
  337. row.AddCell().SetValue("销售")
  338. row.AddCell().SetValue("阅读")
  339. row.AddCell().SetValue("路演")
  340. // 获取所有的用户
  341. condition := ""
  342. pars := make([]interface{}, 0)
  343. condition += ` AND a.qs_id = ? `
  344. pars = append(pars, qsId)
  345. switch i {
  346. case 1:
  347. condition += ` AND a.product_id = ? `
  348. pars = append(pars, 1)
  349. case 2:
  350. condition += ` AND a.product_id = ? `
  351. pars = append(pars, 2)
  352. case 3:
  353. condition += ` AND a.product_id = ? `
  354. pars = append(pars, 0)
  355. }
  356. total, list, err := yb.GetQsUserListForExport(condition, pars)
  357. if err != nil {
  358. br.Msg = "获取活动列表失败!"
  359. br.ErrMsg = "获取活动列表失败,Err:" + err.Error()
  360. return
  361. }
  362. if len(list) <= 0 {
  363. for n := 0; n < total; n++ {
  364. rowIndex := n + 1
  365. row := sheet.Row(rowIndex)
  366. row.AddCell()
  367. row.AddCell()
  368. row.AddCell()
  369. }
  370. } else {
  371. for j, item := range list {
  372. row := sheet.Row(j + 1)
  373. row.AddCell().SetValue(item.Mobile)
  374. row.AddCell().SetValue(item.Name)
  375. row.AddCell().SetValue(item.RegisterTime)
  376. row.AddCell().SetValue(item.ViewTotal)
  377. row.AddCell().SetValue(item.LastViewTime)
  378. row.AddCell().SetValue(item.CompanyName)
  379. productName := ""
  380. switch item.ProductId {
  381. case 1:
  382. productName = "FICC"
  383. case 2:
  384. productName = "权益"
  385. }
  386. row.AddCell().SetValue(productName)
  387. row.AddCell().SetValue(item.Status)
  388. row.AddCell().SetValue(item.SellerName)
  389. row.AddCell().SetValue(item.CompanyViewTotal)
  390. row.AddCell().SetValue(item.CompanyRoadTotal)
  391. }
  392. }
  393. }
  394. err := xlsxFile.Save(downLoadnFilePath)
  395. if err != nil {
  396. br.Msg = "保存文件失败"
  397. br.ErrMsg = "保存文件失败"
  398. return
  399. }
  400. fileName := `全时到会详情`
  401. fileName += time.Now().Format("06.01.02") + `.xlsx` //文件名称
  402. this.Ctx.Output.Download(downLoadnFilePath, fileName)
  403. defer func() {
  404. os.Remove(downLoadnFilePath)
  405. }()
  406. br.Ret = 200
  407. br.Success = true
  408. br.Msg = "success"
  409. }
  410. // QsShare2Seller
  411. // @Title 全时会议-分享给销售
  412. // @Description 全时会议-分享给销售
  413. // @Param request body request.QsShare2SellerReq true "type json string"
  414. // @router /activity/qs_share2seller [post]
  415. func (this *ActivityController) QsShare2Seller() {
  416. br := new(models.BaseResponse).Init()
  417. defer func() {
  418. this.Data["json"] = br
  419. this.ServeJSON()
  420. }()
  421. sysUser := this.SysUser
  422. if sysUser == nil {
  423. br.Msg = "请登录"
  424. br.ErrMsg = "请登录,SysUser Is Empty"
  425. br.Ret = 408
  426. return
  427. }
  428. var req request.QsShare2SellerReq
  429. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  430. if err != nil {
  431. br.Msg = "参数解析异常!"
  432. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  433. return
  434. }
  435. if req.QsId <= 0 {
  436. br.Msg = "参数异常!"
  437. return
  438. }
  439. if req.SellerId <= 0 {
  440. br.Msg = "请选择销售"
  441. return
  442. }
  443. item, e := yb.GetQsEventByQsId(req.QsId)
  444. if e != nil {
  445. br.Msg = "操作失败"
  446. br.ErrMsg = "获取全时会议信息失败, Err: " + e.Error()
  447. return
  448. }
  449. item.ShareSellerId = req.SellerId
  450. item.ModifyTime = time.Now().Local()
  451. if e = item.Update([]string{"ShareSellerId", "ModifyTime"}); e != nil {
  452. br.Msg = "操作失败"
  453. br.ErrMsg = "更新全时会议销售失败, Err: " + e.Error()
  454. return
  455. }
  456. br.Ret = 200
  457. br.Success = true
  458. br.Msg = "操作成功"
  459. }