activity_special.go 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. package controllers
  2. import (
  3. "github.com/rdlucklib/rdluck_tools/paging"
  4. "hongze/hongze_cygx/models"
  5. "hongze/hongze_cygx/services"
  6. "hongze/hongze_cygx/utils"
  7. "strconv"
  8. "strings"
  9. )
  10. //专项调研活动
  11. type ActivitySpecialCoAntroller struct {
  12. BaseAuthController
  13. }
  14. // @Title 专项产业调研列表
  15. // @Description 获取专项产业调研列表接口
  16. // @Param PageSize query int true "每页数据条数"
  17. // @Param CurrentIndex query int true "当前页页码,从1开始"
  18. // @Success 200 {object} models.GetCygxActivitySpecialDetailListResp
  19. // @router /list [get]
  20. func (this *ActivitySpecialCoAntroller) SpecialList() {
  21. br := new(models.BaseResponse).Init()
  22. defer func() {
  23. this.Data["json"] = br
  24. this.ServeJSON()
  25. }()
  26. user := this.User
  27. if user == nil {
  28. br.Msg = "请登录"
  29. br.ErrMsg = "请登录,SysUser Is Empty"
  30. return
  31. }
  32. pageSize, _ := this.GetInt("PageSize")
  33. currentIndex, _ := this.GetInt("CurrentIndex")
  34. if pageSize <= 0 {
  35. pageSize = utils.PageSize20
  36. }
  37. if currentIndex <= 0 {
  38. currentIndex = 1
  39. }
  40. list, total, errList := services.GetActivitySpecialList(user, currentIndex, pageSize, "")
  41. if errList != nil {
  42. br.Msg = "获取失败"
  43. br.ErrMsg = "获取失败,Err:" + errList.Error()
  44. return
  45. }
  46. page := paging.GetPaging(currentIndex, pageSize, total)
  47. resp := new(models.GetCygxActivitySpecialDetailListResp)
  48. count, err := models.GetCygxUserFollowSpecial(user.UserId)
  49. if err != nil {
  50. br.Msg = "获取数据失败!"
  51. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  52. return
  53. }
  54. if count == 1 && user.UserId > 0 {
  55. resp.IsFollow = true
  56. }
  57. if user.Mobile != "" {
  58. resp.IsBindingMobile = true
  59. }
  60. resp.List = list
  61. resp.Paging = page
  62. br.Ret = 200
  63. br.Success = true
  64. br.Msg = "获取成功"
  65. br.Data = resp
  66. }
  67. // @Title 专项产业调研详情
  68. // @Description 获取专项产业调研详情接口
  69. // @Param ActivityId query int true "活动ID"
  70. // @Success Ret=200 {object} models.CygxActivitySpecialResp
  71. // @router /detail [get]
  72. func (this *ActivitySpecialCoAntroller) SpecialDetail() {
  73. br := new(models.BaseResponse).Init()
  74. defer func() {
  75. this.Data["json"] = br
  76. this.ServeJSON()
  77. }()
  78. user := this.User
  79. if user == nil {
  80. br.Msg = "请登录"
  81. br.ErrMsg = "请登录,用户信息为空"
  82. br.Ret = 408
  83. return
  84. }
  85. uid := user.UserId
  86. activityId, _ := this.GetInt("ActivityId")
  87. if activityId < 1 {
  88. br.Msg = "请输入活动ID"
  89. return
  90. }
  91. resp := new(models.CygxActivitySpecialResp)
  92. hasPermission := 0
  93. activityInfo, err := models.GetCygxActivitySpecialDetailById(uid, activityId)
  94. if err != nil && err.Error() != utils.ErrNoRow() {
  95. br.Msg = "获取信息失败"
  96. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  97. return
  98. }
  99. if activityInfo == nil {
  100. br.Msg = "活动不存在"
  101. br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
  102. return
  103. }
  104. applyCount, err := models.GetApplyRecordCount(uid)
  105. if err != nil && err.Error() != utils.ErrNoRow() {
  106. br.Msg = "获取信息失败"
  107. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  108. return
  109. }
  110. //获取FICC销售信息 如果是FICC的客户类型,则默认他申请过
  111. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  112. if err != nil && err.Error() != utils.ErrNoRow() {
  113. br.Msg = "获取信息失败"
  114. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  115. return
  116. }
  117. if user.CompanyId <= 1 {
  118. //companyDetailStatus = ""
  119. } else {
  120. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  121. if err != nil {
  122. br.Msg = "获取信息失败"
  123. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  124. return
  125. }
  126. if companyPermission == "" {
  127. if applyCount > 0 {
  128. hasPermission = 4
  129. } else {
  130. if sellerItem != nil {
  131. hasPermission = 5
  132. } else {
  133. //获取权益销售信息 如果是FICC的客户类型,则默认他申请过
  134. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  135. if err != nil && err.Error() != utils.ErrNoRow() {
  136. br.Msg = "获取信息失败"
  137. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  138. return
  139. }
  140. if sellerItemQy != nil {
  141. hasPermission = 2
  142. resp.SellerMobile = sellerItemQy.Mobile
  143. resp.SellerName = sellerItemQy.RealName
  144. } else {
  145. hasPermission = 3
  146. }
  147. }
  148. }
  149. resp.HasPermission = hasPermission
  150. resp.OperationMode = "Apply"
  151. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  152. br.Ret = 200
  153. br.Success = true
  154. br.Msg = "获取成功"
  155. br.Data = resp
  156. return
  157. }
  158. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  159. if err != nil {
  160. br.Msg = "获取信息失败!"
  161. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  162. return
  163. }
  164. if companyDetail == nil {
  165. br.Msg = "获取信息失败!"
  166. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId)
  167. return
  168. }
  169. }
  170. userType, permissionStr, err := services.GetUserType(user.CompanyId)
  171. if err != nil {
  172. br.Msg = "获取信息失败"
  173. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  174. return
  175. }
  176. itemAct := new(models.ActivityDetail)
  177. itemAct.CustomerTypeIds = activityInfo.CustomerTypeIds
  178. noPower, err := services.GetShareNoPowe(itemAct, permissionStr, userType, user)
  179. if err != nil {
  180. br.Msg = "获取信息失败"
  181. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  182. return
  183. }
  184. //获取用户的产业规模,判断是否允许可见
  185. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  186. if err != nil && err.Error() != utils.ErrNoRow() {
  187. br.Msg = "获取信息失败"
  188. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  189. return
  190. }
  191. if companyProduct != nil {
  192. if companyProduct.Scale != "" {
  193. if strings.Count(activityInfo.Scale, companyProduct.Scale) > 0 {
  194. noPower = false
  195. }
  196. }
  197. }
  198. if noPower {
  199. br.Msg = "您暂无查看该活动权限"
  200. br.ErrMsg = "被分享客户不可见,获取信息失败"
  201. br.IsSendEmail = false
  202. return
  203. }
  204. if userType == 1 && strings.Contains(activityInfo.ChartPermissionName, "研选") {
  205. br.Msg = "您暂无查看该活动权限"
  206. br.ErrMsg = "被分享客户不可见,永续客户无法查看研选行业"
  207. return
  208. }
  209. //判断是否已经申请过
  210. if user.CompanyId > 1 {
  211. permissionStr, err := models.GetCompanyPermissionByUser(user.CompanyId)
  212. if err != nil {
  213. br.Msg = "获取信息失败"
  214. br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  215. return
  216. }
  217. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  218. //冻结客户
  219. if err != nil {
  220. if err.Error() == utils.ErrNoRow() {
  221. if applyCount > 0 {
  222. hasPermission = 4
  223. } else {
  224. if sellerItem != nil {
  225. hasPermission = 5
  226. } else {
  227. //获取权益销售信息 如果是FICC的客户类型,则默认他申请过
  228. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  229. if err != nil && err.Error() != utils.ErrNoRow() {
  230. br.Msg = "获取信息失败"
  231. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  232. return
  233. }
  234. if sellerItemQy != nil {
  235. hasPermission = 2
  236. resp.SellerMobile = sellerItemQy.Mobile
  237. resp.SellerName = sellerItemQy.RealName
  238. } else {
  239. hasPermission = 3
  240. }
  241. }
  242. }
  243. resp.HasPermission = hasPermission
  244. resp.OperationMode = "Apply"
  245. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  246. br.Ret = 200
  247. br.Success = true
  248. br.Msg = "获取成功"
  249. br.Data = resp
  250. return
  251. } else {
  252. br.Msg = "获取信息失败"
  253. br.ErrMsg = "获取客户公司信息失败,Err:" + err.Error()
  254. return
  255. }
  256. }
  257. var havePower bool
  258. if strings.Contains(permissionStr, activityInfo.ActivityTypeName) {
  259. havePower = true
  260. }
  261. if havePower {
  262. hasPermission = 1
  263. resp.HaqveJurisdiction = true
  264. } else {
  265. if permissionStr == "专家" {
  266. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  267. resp.MsgType = "Type"
  268. } else {
  269. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  270. resp.MsgType = "Industry"
  271. }
  272. if companyItem.ProductId == 2 {
  273. resp.SellerMobile = companyItem.Mobile
  274. resp.SellerName = companyItem.SellerName
  275. resp.OperationMode = "Call"
  276. hasPermission = 2
  277. } else {
  278. hasPermission = 5
  279. }
  280. }
  281. } else { //潜在客户
  282. if applyCount > 0 {
  283. hasPermission = 4
  284. } else {
  285. if sellerItem != nil {
  286. hasPermission = 5
  287. } else {
  288. hasPermission = 3
  289. }
  290. }
  291. resp.OperationMode = "Apply"
  292. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  293. }
  294. if hasPermission == 1 {
  295. count, err := models.GetCygxUserFollowSpecial(user.UserId)
  296. if err != nil {
  297. br.Msg = "获取数据失败!"
  298. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  299. return
  300. }
  301. if count == 1 {
  302. resp.IsFollow = true
  303. }
  304. activityInfo, err := services.HandleActivitySpecialShow(activityInfo, user)
  305. if err != nil {
  306. br.Msg = "获取数据失败!"
  307. br.ErrMsg = "HandleActivitySpecialShow,Err:" + err.Error()
  308. return
  309. }
  310. activityInfo.ActivityTypeName = "专项调研"
  311. resp.Detail = activityInfo
  312. }
  313. resp.HasPermission = hasPermission
  314. br.Ret = 200
  315. br.Success = true
  316. br.Msg = "获取成功"
  317. br.Data = resp
  318. }