apply_record.go 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hz_crm_api/controllers"
  6. "hongze/hz_crm_api/models"
  7. "hongze/hz_crm_api/models/cygx"
  8. "hongze/hz_crm_api/services"
  9. cygxService "hongze/hz_crm_api/services/cygx"
  10. "hongze/hz_crm_api/utils"
  11. "strconv"
  12. )
  13. // 权益小程序
  14. type ApplyRecordController struct {
  15. controllers.BaseAuthController
  16. }
  17. // @Title 权益申请记录列表
  18. // @Description权益申请记录接口
  19. // @Param PageSize query int true "每页数据条数"
  20. // @Param CurrentIndex query int true "当前页页码,从1开始"
  21. // @Param KeyWord query string true "搜索关键词"
  22. // @Param CustomType query int true "用户类型1:潜在用户,2:现有客户"
  23. // @Success 200 {object} cygx.CygxApplyRecordListResp
  24. // @router /apply/record/list [get]
  25. func (this *ApplyRecordController) ListSysRole() {
  26. br := new(models.BaseResponse).Init()
  27. defer func() {
  28. this.Data["json"] = br
  29. this.ServeJSON()
  30. }()
  31. sysUser := this.SysUser
  32. if sysUser == nil {
  33. br.Msg = "请登录"
  34. br.ErrMsg = "请登录,SysUser Is Empty"
  35. return
  36. }
  37. pageSize, _ := this.GetInt("PageSize")
  38. currentIndex, _ := this.GetInt("CurrentIndex")
  39. keyWord := this.GetString("KeyWord")
  40. var startSize int
  41. if pageSize <= 0 {
  42. pageSize = utils.PageSize20
  43. }
  44. if currentIndex <= 0 {
  45. currentIndex = 1
  46. }
  47. startSize = utils.StartIndex(currentIndex, pageSize)
  48. var condition string
  49. var pars []interface{}
  50. if keyWord != "" {
  51. //condition += ` AND (b.seller_name LIKE '%` + keyWord + `%' OR a.mobile LIKE '%` + keyWord + `%' OR c.email LIKE '%` + keyWord + `%' ) `
  52. condition += ` AND a.mobile LIKE '%` + keyWord + `%' `
  53. }
  54. customType, _ := this.GetInt("CustomType")
  55. if customType > 0 {
  56. if customType == 1 {
  57. condition += ` AND a.company_id_type=1 `
  58. } else if customType == 3 {
  59. condition += ` AND a.company_id_type = 3 `
  60. } else {
  61. condition += ` AND a.company_id_type NOT IN (1,3) `
  62. }
  63. }
  64. //权益申请销售只能看到自己名下的客户的申请 查研观向11.1
  65. companyIds, err := cygxService.GetAdminLookUserCompanyIdsBySelf(sysUser)
  66. if err != nil {
  67. br.Msg = "获取失败"
  68. br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error()
  69. return
  70. }
  71. lencompanyIds := len(companyIds)
  72. if lencompanyIds > 0 {
  73. condition += ` AND a.company_id_pay IN (` + utils.GetOrmInReplace(lencompanyIds) + `)`
  74. pars = append(pars, companyIds)
  75. }
  76. total, err := cygx.GetCygxApplyRecordCount(condition, pars)
  77. if err != nil {
  78. br.Msg = "获取失败"
  79. br.ErrMsg = "获取失败,Err:" + err.Error()
  80. return
  81. }
  82. list, err := cygx.GetCygxApplyRecord(condition, pars, startSize, pageSize)
  83. if err != nil {
  84. br.Msg = "获取失败"
  85. br.ErrMsg = "获取失败,Err:" + err.Error()
  86. return
  87. }
  88. var sellerCompanyIds []int
  89. var microvideoIds []int
  90. var userIds []int
  91. for _, v := range list {
  92. if v.Source == "roadshow" {
  93. microvideoIds = append(microvideoIds, v.SourceId)
  94. }
  95. sellerCompanyIds = append(sellerCompanyIds, v.CompanyIdPay)
  96. userIds = append(userIds, v.UserId)
  97. }
  98. sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds)
  99. lenmicrovideoIds := len(microvideoIds)
  100. mapmicrovideoChartPermissionId := make(map[int]int) //产业视频ID所对应的行业ID
  101. mapmicrovideoIndustryId := make(map[int]int) //产业视频ID所对应的行业ID
  102. if lenmicrovideoIds > 0 {
  103. var conditionmicrovideo string
  104. var parsmicrovideo []interface{}
  105. conditionmicrovideo = ` AND video_id IN (` + utils.GetOrmInReplace(lenmicrovideoIds) + `)`
  106. parsmicrovideo = append(parsmicrovideo, microvideoIds)
  107. listmicrovideo, err := cygx.GetMicroRoadshowVideoList(conditionmicrovideo, "", parsmicrovideo, 0, lenmicrovideoIds)
  108. if err != nil {
  109. br.Msg = "获取失败"
  110. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  111. return
  112. }
  113. for _, v := range listmicrovideo {
  114. mapmicrovideoChartPermissionId[v.VideoId] = v.ChartPermissionId
  115. mapmicrovideoIndustryId[v.VideoId] = v.IndustryId
  116. }
  117. }
  118. //处理用户的邮箱
  119. mapUserEmail := make(map[int]string) //用户UserId所对应的邮箱
  120. lenUserId := len(userIds)
  121. if lenUserId > 0 {
  122. userList, err := models.GetWxUserByUserIds(userIds)
  123. if err != nil {
  124. br.Msg = "获取失败"
  125. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  126. return
  127. }
  128. for _, v := range userList {
  129. mapUserEmail[int(v.UserId)] = v.Email
  130. }
  131. }
  132. for i, v := range list {
  133. v.Email = mapUserEmail[v.UserId]
  134. if list[i].SellerName == "/" {
  135. list[i].SellerName = ""
  136. }
  137. if v.InviteeCompanyNum == 1 {
  138. list[i].IsInviteeComanyExistence = true
  139. }
  140. if v.InviteeMobile == "" && v.InviteeEmail != "" {
  141. list[i].InviteeMobile = v.InviteeEmail
  142. }
  143. if v.InviteeCompany != "" {
  144. list[i].ApplySource = "免费送月卡"
  145. }
  146. list[i].SellerName = sellNameMap[v.CompanyIdPay]
  147. //用户状态,1:潜在客户 、2:现有客户 、3:FICC客户 、4:现有客户(正式,无对应权限) 、5:现有客户(试用,无对应权限) 、6:现有客户(试用暂停) 、7:现有客户(冻结) 、8:现有客户(流失)
  148. switch v.CompanyIdType {
  149. case 1:
  150. list[i].CompanyIdTypeName = "潜在客户"
  151. case 2:
  152. list[i].CompanyIdTypeName = "现有客户"
  153. case 3:
  154. list[i].CompanyIdTypeName = "FICC客户"
  155. case 4:
  156. list[i].CompanyIdTypeName = "现有客户(正式,无对应权限) "
  157. case 5:
  158. list[i].CompanyIdTypeName = "现有客户(试用,无对应权限)"
  159. case 6:
  160. list[i].CompanyIdTypeName = "现有客户(试用暂停)"
  161. case 7:
  162. list[i].CompanyIdTypeName = "现有客户(冻结)"
  163. case 8:
  164. list[i].CompanyIdTypeName = "现有客户(流失)"
  165. }
  166. switch v.RegisterPlatform {
  167. case 1:
  168. list[i].ApplicationSource = "查研小程序"
  169. case 2:
  170. list[i].ApplicationSource = "网页版"
  171. case 5:
  172. list[i].ApplicationSource = "研选小程序"
  173. }
  174. switch v.InviteCompanySource {
  175. case 2:
  176. list[i].ApplicationSource += "(络町)"
  177. }
  178. switch v.Source {
  179. case "article": //文章详情
  180. list[i].HttpUrl = utils.CYGX_WEB_URL + "/material/info/" + strconv.Itoa(v.SourceId)
  181. case "activity": //活动详情
  182. list[i].HttpUrl = utils.CYGX_WEB_URL + "/activity/detail/" + strconv.Itoa(v.SourceId)
  183. case "activityvoice": //活动音频详情
  184. list[i].HttpUrl = utils.CYGX_WEB_URL + "/activity/detail/" + strconv.Itoa(v.SourceId)
  185. case "activityvideo": //活动视频详情
  186. list[i].HttpUrl = utils.CYGX_WEB_URL + "/activity/detail/" + strconv.Itoa(v.SourceId)
  187. case "productinterior": //产品内测
  188. list[i].HttpUrl = utils.CYGX_WEB_URL + "/internal/article/" + strconv.Itoa(v.SourceId)
  189. case "roadshow": //产业视频
  190. list[i].HttpUrl = utils.CYGX_WEB_URL + "/indepth/info/" + strconv.Itoa(mapmicrovideoChartPermissionId[v.SourceId]) + "/" + strconv.Itoa(mapmicrovideoIndustryId[v.SourceId])
  191. case "researchsummary": //本周研究汇总
  192. list[i].HttpUrl = utils.CYGX_WEB_URL + "/summary/2/" + strconv.Itoa(v.SourceId)
  193. case "minutessummary": //上周纪要汇总
  194. list[i].HttpUrl = utils.CYGX_WEB_URL + "/summary/1/" + strconv.Itoa(v.SourceId)
  195. case "reportselection": //报告精选(重点公司)
  196. list[i].HttpUrl = utils.CYGX_WEB_URL + "/recent/" + strconv.Itoa(v.SourceId)
  197. case "yanxuanspecial": //研选专栏
  198. list[i].HttpUrl = utils.CYGX_WEB_URL + "/column/detail/" + strconv.Itoa(v.SourceId)
  199. case utils.CYGX_OBJ_FICC_REPORT: //FICC研报
  200. list[i].HttpUrl = utils.CYGX_WEB_URL + "/material/ricc/yb/report/" + strconv.Itoa(v.SourceId)
  201. case utils.CYGX_OBJ_FICC_REPORT_XCX: //FICC研报
  202. list[i].IsGray = true
  203. }
  204. }
  205. page := paging.GetPaging(currentIndex, pageSize, total)
  206. resp := new(cygx.CygxApplyRecordListResp)
  207. resp.List = list
  208. resp.Paging = page
  209. br.Ret = 200
  210. br.Success = true
  211. br.Msg = "获取成功"
  212. br.Data = resp
  213. }
  214. // @Title 处理
  215. // @Description 处理接口
  216. // @Param request body cygx.CygxDealReq true "type json string"
  217. // @Success 200 删除成功
  218. // @router /apply/record/deal [post]
  219. func (this *ApplyRecordController) Delete() {
  220. br := new(models.BaseResponse).Init()
  221. defer func() {
  222. this.Data["json"] = br
  223. this.ServeJSON()
  224. }()
  225. var req cygx.CygxDealReq
  226. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  227. if err != nil {
  228. br.Msg = "参数解析异常!"
  229. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  230. return
  231. }
  232. if req.ApplyRecordId <= 0 {
  233. br.Msg = "参数错误"
  234. br.ErrMsg = "参数错误,ApplyRecordId 小于等于0 "
  235. return
  236. }
  237. err = cygx.DealCygxApplyRecord(req.ApplyRecordId, this.SysUser.AdminId)
  238. if err != nil {
  239. br.Msg = "处理失败"
  240. br.ErrMsg = "处理失败,Err:" + err.Error()
  241. return
  242. }
  243. br.Ret = 200
  244. br.Success = true
  245. br.Msg = "处理成功"
  246. }