official_user.go 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "github.com/tealeg/xlsx"
  6. "hongze/hz_crm_api/models"
  7. "hongze/hz_crm_api/utils"
  8. "os"
  9. "path/filepath"
  10. "time"
  11. )
  12. // 官网试用用户管理
  13. type OfficialUserController struct {
  14. BaseAuthController
  15. }
  16. // @Title 官网试用用户列表
  17. // @Description 官网试用用户列表接口
  18. // @Param PageSize query int true "每页数据条数"
  19. // @Param CurrentIndex query int true "当前页页码,从1开始"
  20. // @Param KeyWord query string true "搜索关键词"
  21. // @Param SourceType query string true "申请来源,枚举值:可选范围:'中文官网','英文官网'"
  22. // @Success 200 {object} models.UserTrialApplyListResp
  23. // @router /official/user/list [get]
  24. func (this *OfficialUserController) OfficialUserList() {
  25. br := new(models.BaseResponse).Init()
  26. defer func() {
  27. this.Data["json"] = br
  28. this.ServeJSON()
  29. }()
  30. sysUser := this.SysUser
  31. if sysUser == nil {
  32. br.Msg = "请登录"
  33. br.ErrMsg = "请登录,SysUser Is Empty"
  34. br.Ret = 408
  35. return
  36. }
  37. pageSize, _ := this.GetInt("PageSize")
  38. currentIndex, _ := this.GetInt("CurrentIndex")
  39. keyWord := this.GetString("KeyWord")
  40. sourceType := this.GetString("SourceType")
  41. markGroup := this.GetString("MarkGroup")
  42. startDate := this.GetString("StartDate")
  43. endDate := this.GetString("EndDate")
  44. if sourceType == "" {
  45. br.Msg = "获取失败"
  46. br.ErrMsg = "请选择类型"
  47. return
  48. }
  49. var startSize int
  50. if pageSize <= 0 {
  51. pageSize = utils.PageSize20
  52. }
  53. if currentIndex <= 0 {
  54. currentIndex = 1
  55. }
  56. startSize = utils.StartIndex(currentIndex, pageSize)
  57. var condition string
  58. var pars []interface{}
  59. startTime := "2022-01-01"
  60. condition += `source_type = ? and create_time > ? `
  61. pars = append(pars, sourceType)
  62. pars = append(pars, startTime)
  63. if keyWord != "" {
  64. condition += ` and (company_name LIKE '%` + keyWord + `%' OR phone LIKE '%` + keyWord + `%' OR email LIKE '%` + keyWord + `%' OR real_name LIKE '%` + keyWord + `%') `
  65. }
  66. if markGroup != "" {
  67. condition += `AND mark_group = `+"'"+markGroup+"'"
  68. }
  69. if startDate != "" {
  70. startDate += " 00:00:00"
  71. condition += ` AND create_time >= '` + startDate + `' `
  72. }
  73. if endDate != "" {
  74. endDate += " 23:59:59"
  75. condition += ` AND create_time <= '` + endDate + `' `
  76. }
  77. //获取总数据数
  78. total, err := models.GetOfficialApplyUserListListCount(condition, pars)
  79. if err != nil {
  80. br.Msg = "获取失败"
  81. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  82. return
  83. }
  84. list, err := models.GetOfficialApplyUserListList(condition, pars, startSize, pageSize)
  85. if err != nil {
  86. br.Msg = "获取失败"
  87. br.ErrMsg = "获取失败,Err:" + err.Error()
  88. return
  89. }
  90. lenList := len(list)
  91. for i := 0; i < lenList; i++ {
  92. list[i].CreateTimeStr = list[i].CreateTime.Format(utils.FormatDateTime)
  93. list[i].ModifyTimeStr = list[i].ModifyTime.Format(utils.FormatDateTime)
  94. }
  95. page := paging.GetPaging(currentIndex, pageSize, int(total))
  96. resp := new(models.UserTrialApplyListResp)
  97. resp.List = list
  98. resp.Paging = page
  99. br.Ret = 200
  100. br.Success = true
  101. br.Msg = "获取成功"
  102. br.Data = resp
  103. }
  104. // @Title 官网试用用户确认
  105. // @Description 官网试用用户确认接口
  106. // @Param Id query int true "申请记录id"
  107. // @Success Ret=200 确认成功
  108. // @router /official/user/confirm [post]
  109. func (this *OfficialUserController) OfficialUserConfirm() {
  110. br := new(models.BaseResponse).Init()
  111. defer func() {
  112. this.Data["json"] = br
  113. this.ServeJSON()
  114. }()
  115. sysUser := this.SysUser
  116. if sysUser == nil {
  117. br.Msg = "请登录"
  118. br.ErrMsg = "请登录,SysUser Is Empty"
  119. br.Ret = 408
  120. return
  121. }
  122. //参数拼接
  123. var req models.UserTrialApplyConfirmReq
  124. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  125. id := req.Id
  126. //查询记录信息,并做初步判断
  127. info, err := models.GetOfficialApplyUserById(id)
  128. if err != nil && err.Error() == utils.ErrNoRow() {
  129. br.Msg = "确认失败"
  130. br.ErrMsg = "确认失败,记录异常"
  131. return
  132. }
  133. if info.Status != "待处理" {
  134. br.Msg = "确认失败"
  135. br.ErrMsg = "确认失败,当前记录状态信息异常,请刷新页面"
  136. return
  137. }
  138. err = models.ConfirmOfficialApplyUser(id, sysUser.AdminId, sysUser.RealName)
  139. if err != nil {
  140. br.Msg = "确认失败"
  141. br.ErrMsg = "确认失败,Err:" + err.Error()
  142. return
  143. }
  144. br.Ret = 200
  145. br.Success = true
  146. br.Msg = "确认成功"
  147. //br.Data = resp
  148. }
  149. // @Title 官网试用用户列表导出
  150. // @Description 官网试用用户列表接口
  151. // @Param PageSize query int true "每页数据条数"
  152. // @Param CurrentIndex query int true "当前页页码,从1开始"
  153. // @Param KeyWord query string true "搜索关键词"
  154. // @Param SourceType query string true "申请来源,枚举值:可选范围:'中文官网','英文官网'"
  155. // @Success Ret=200 导出成功
  156. // @router /official/user/list/export [get]
  157. func (this *OfficialUserController) OfficialUserListExport() {
  158. br := new(models.BaseResponse).Init()
  159. defer func() {
  160. this.Data["json"] = br
  161. this.ServeJSON()
  162. }()
  163. sysUser := this.SysUser
  164. if sysUser == nil {
  165. br.Msg = "请登录"
  166. br.ErrMsg = "请登录,SysUser Is Empty"
  167. br.Ret = 408
  168. return
  169. }
  170. keyWord := this.GetString("KeyWord")
  171. sourceType := this.GetString("SourceType")
  172. if sourceType == "" {
  173. br.Msg = "获取失败"
  174. br.ErrMsg = "请选择类型"
  175. return
  176. }
  177. var condition string
  178. var pars []interface{}
  179. //管理员才让导出数据
  180. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  181. br.Msg = "没有权限"
  182. br.ErrMsg = "没有权限"
  183. return
  184. }
  185. startTime := "2022-01-01"
  186. condition += `source_type = ? and create_time > ? `
  187. pars = append(pars, sourceType)
  188. pars = append(pars, startTime)
  189. if keyWord != "" {
  190. condition += ` and (company_name LIKE '%` + keyWord + `%' OR phone LIKE '%` + keyWord + `%' OR email LIKE '%` + keyWord + `%' OR real_name LIKE '%` + keyWord + `%') `
  191. }
  192. list, err := models.GetOfficialApplyUserListListExport(condition, pars)
  193. if err != nil {
  194. br.Msg = "获取失败"
  195. br.ErrMsg = "获取失败,Err:" + err.Error()
  196. return
  197. }
  198. dir, err := os.Executable()
  199. exPath := filepath.Dir(dir)
  200. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  201. xlsxFile := xlsx.NewFile()
  202. if err != nil {
  203. br.Msg = "生成文件失败"
  204. br.ErrMsg = "生成文件失败"
  205. return
  206. }
  207. style := xlsx.NewStyle()
  208. alignment := xlsx.Alignment{
  209. Horizontal: "center",
  210. Vertical: "center",
  211. WrapText: true,
  212. }
  213. style.Alignment = alignment
  214. style.ApplyAlignment = true
  215. sheel, err := xlsxFile.AddSheet("客户数据")
  216. if err != nil {
  217. br.Msg = "新增Sheet失败"
  218. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  219. return
  220. }
  221. titleRow := sheel.AddRow()
  222. if sourceType == "中文官网" {
  223. titleRow.AddCell().SetValue("企业名称")
  224. titleRow.AddCell().SetValue("姓名")
  225. titleRow.AddCell().SetValue("手机号/邮箱")
  226. titleRow.AddCell().SetValue("所属行业")
  227. titleRow.AddCell().SetValue("申请时间")
  228. titleRow.AddCell().SetValue("申请品种")
  229. for _, v := range list {
  230. dataRow := sheel.AddRow()
  231. dataRow.SetHeight(20)
  232. dataRow.AddCell().SetString(v.CompanyName)
  233. dataRow.AddCell().SetString(v.RealName)
  234. if v.Phone != "" {
  235. dataRow.AddCell().SetString(v.Phone)
  236. } else {
  237. dataRow.AddCell().SetString(v.Email)
  238. }
  239. dataRow.AddCell().SetString(v.Industry)
  240. dataRow.AddCell().SetString(v.CreateTime.Format(utils.FormatDateTime))
  241. dataRow.AddCell().SetString(v.ProductInfo)
  242. }
  243. } else {
  244. titleRow.AddCell().SetValue("企业名称")
  245. titleRow.AddCell().SetValue("姓名")
  246. titleRow.AddCell().SetValue("邮箱")
  247. titleRow.AddCell().SetValue("信息")
  248. titleRow.AddCell().SetValue("发送时间")
  249. for _, v := range list {
  250. dataRow := sheel.AddRow()
  251. dataRow.SetHeight(20)
  252. dataRow.AddCell().SetString(v.CompanyName)
  253. dataRow.AddCell().SetString(v.RealName)
  254. dataRow.AddCell().SetString(v.Email)
  255. dataRow.AddCell().SetString(v.Message)
  256. dataRow.AddCell().SetString(v.CreateTime.Format(utils.FormatDateTime))
  257. }
  258. }
  259. err = xlsxFile.Save(downLoadnFilePath)
  260. if err != nil {
  261. br.Msg = "保存文件失败"
  262. br.ErrMsg = "保存文件失败"
  263. return
  264. }
  265. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  266. downloadFileName := "官网试用申请列表_" + sourceType + "_" + randStr + ".xlsx"
  267. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  268. defer func() {
  269. _ = os.Remove(downLoadnFilePath)
  270. }()
  271. br.Ret = 200
  272. br.Success = true
  273. br.Msg = "导出成功"
  274. }
  275. // @Title 官网试用用户确认
  276. // @Description 官网试用用户确认接口
  277. // @Param Id query int true "申请记录id"
  278. // @Success Ret=200 确认成功
  279. // @router /official/user/mark_group [post]
  280. func (this *OfficialUserController) OfficialUserMarkGroup() {
  281. br := new(models.BaseResponse).Init()
  282. defer func() {
  283. this.Data["json"] = br
  284. this.ServeJSON()
  285. }()
  286. sysUser := this.SysUser
  287. if sysUser == nil {
  288. br.Msg = "请登录"
  289. br.ErrMsg = "请登录,SysUser Is Empty"
  290. br.Ret = 408
  291. return
  292. }
  293. //参数拼接
  294. var req models.UserTrialApplyMarkGroupReq
  295. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  296. id := req.Id
  297. //查询记录信息,并做初步判断
  298. info, err := models.GetOfficialApplyUserById(id)
  299. if err != nil && err.Error() == utils.ErrNoRow() {
  300. br.Msg = "确认失败"
  301. br.ErrMsg = "确认失败,记录异常"
  302. return
  303. }
  304. if info.Status != "待处理" {
  305. br.Msg = "确认失败"
  306. br.ErrMsg = "确认失败,当前记录状态信息异常,请刷新页面"
  307. return
  308. }
  309. err = models.OfficialApplyUserMarkGroup(id, sysUser.AdminId, sysUser.RealName, req.GroupName)
  310. if err != nil {
  311. br.Msg = "确认失败"
  312. br.ErrMsg = "确认失败,Err:" + err.Error()
  313. return
  314. }
  315. br.Ret = 200
  316. br.Success = true
  317. br.Msg = "标记成功"
  318. //br.Data = resp
  319. }