蛋蛋星球 后台端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hdl_aliyun_sms.go 11 KiB

2 weeks ago
2 weeks ago
4 weeks ago
2 weeks ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. package notice
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/md"
  6. svc2 "applet/app/svc"
  7. svc "applet/app/svc/member_center"
  8. "applet/app/svc/notice"
  9. "applet/app/utils"
  10. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  11. "github.com/gin-gonic/gin"
  12. )
  13. // AliyunSmsFilePhone
  14. // @Summary 消息中心-短信推送记录-通知模板
  15. // @Tags 消息中心
  16. // @Description 短信推送记录-通知模板
  17. // @Accept json
  18. // @Produce json
  19. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  20. // @Param file formData string true "参数 file-----文件上传格式"
  21. // @Success 200 {string} "phone 一个数组"
  22. // @Failure 400 {object} md.Response "具体错误"
  23. // @Router /api/notice/aliyunSms/file/phone [post]
  24. func AliyunSmsFilePhone(c *gin.Context) {
  25. notice.AliyunSmsFilePhone(c)
  26. }
  27. //
  28. //// AliyunSmsList
  29. //// @Summary 消息中心-短信推送记录-通知模板(跟app推送记录的通知模板一样的效果)
  30. //// @Tags 消息中心
  31. //// @Description 短信推送记录-通知模板
  32. //// @Accept json
  33. //// @Produce json
  34. //// @param Authorization header string true "验证参数Bearer和token空格拼接"
  35. //// @Param req body md.NoticeAliyunSmsListReq true "(分页信息必填)"
  36. //// @Success 200 {object} md.NoticeAliyunSmsListResp "具体数据"
  37. //// @Failure 400 {object} md.Response "具体错误"
  38. //// @Router /api/notice/aliyunSms/list [get]
  39. //func AliyunSmsList(c *gin.Context) {
  40. // notice.AliyunSmsList(c)
  41. //}
  42. //
  43. //// AliyunSmsSave
  44. //// @Summary 消息中心-短信推送记录-通知模板添加编辑
  45. //// @Tags 消息中心
  46. //// @Description 短信推送记录-通知模板添加编辑
  47. //// @Accept json
  48. //// @Produce json
  49. //// @param Authorization header string true "验证参数Bearer和token空格拼接"
  50. //// @Param req body md.NoticeAliyunSmsSaveReq true "参数"
  51. //// @Success 200 {string} "具体数据"
  52. //// @Failure 400 {object} md.Response "具体错误"
  53. //// @Router /api/notice/aliyunSms/save [post]
  54. //func AliyunSmsSave(c *gin.Context) {
  55. // notice.AliyunSmsSave(c)
  56. //}
  57. //
  58. //// AliyunSmsDel
  59. //// @Summary 消息中心-短信推送记录-通知模板删除
  60. //// @Tags 消息中心
  61. //// @Description 短信推送记录-通知模板删除
  62. //// @Accept json
  63. //// @Produce json
  64. //// @param Authorization header string true "验证参数Bearer和token空格拼接"
  65. //// @Param req body md.NoticeDelReq true "(分页信息必填)"
  66. //// @Success 200 {string} "具体数据"
  67. //// @Failure 400 {object} md.Response "具体错误"
  68. //// @Router /api/notice/aliyunSms/del [post]
  69. //func AliyunSmsDel(c *gin.Context) {
  70. // notice.AliyunSmsDel(c)
  71. //}
  72. // AliyunSmsSaleBase
  73. // @Summary 消息中心-短信推送记录-营销短信-通知模板
  74. // @Tags 消息中心
  75. // @Description 短信推送记录-营销短信-通知模板
  76. // @Accept json
  77. // @Produce json
  78. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  79. // @Success 200 {object} md.NoticeAliyunSmsListResp "具体数据"
  80. // @Failure 400 {object} md.Response "具体错误"
  81. // @Router /api/notice/aliyunSms/sale/base [get]
  82. func AliyunSmsSaleBase(c *gin.Context) {
  83. notice.AliyunSmsSaleBase(c)
  84. }
  85. // AliyunSmsSaleSave
  86. // @Summary 消息中心-短信推送记录-营销短信-通知模板添加编辑
  87. // @Tags 消息中心
  88. // @Description 短信推送记录-营销短信-通知模板添加编辑
  89. // @Accept json
  90. // @Produce json
  91. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  92. // @Param req body string true "数组 把列表的数组传过来"
  93. // @Success 200 {string} "具体数据"
  94. // @Failure 400 {object} md.Response "具体错误"
  95. // @Router /api/notice/aliyunSms/sale/save [post]
  96. func AliyunSmsSaleSave(c *gin.Context) {
  97. notice.AliyunSmsSaleSave(c)
  98. }
  99. // AliyunSmsPushList
  100. // @Summary 消息中心-短信推送记录-推送记录列表
  101. // @Tags 消息中心
  102. // @Description 短信推送记录-推送记录列表
  103. // @Accept json
  104. // @Produce json
  105. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  106. // @Param req body md.NoticeAliyunSmsListReq true "(分页信息必填)"
  107. // @Success 200 {object} md.NoticePushListResp "具体数据"
  108. // @Failure 400 {object} md.Response "具体错误"
  109. // @Router /api/notice/aliyunSms/push/list [post]
  110. func AliyunSmsPushList(c *gin.Context) {
  111. notice.AliyunSmsPushList(c)
  112. }
  113. // AliyunSmsPushSave
  114. // @Summary 消息中心-短信推送记录-推送记录添加-发送(不做编辑了)
  115. // @Tags 消息中心
  116. // @Description 短信推送记录-推送记录添加-发送 (不做编辑了)
  117. // @Accept json
  118. // @Produce json
  119. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  120. // @Param req body md.NoticeAliyunSmsSaveReq true "(分页信息必填)"
  121. // @Success 200 {string} "具体数据"
  122. // @Failure 400 {object} md.Response "具体错误"
  123. // @Router /api/notice/aliyunSms/push/save [post]
  124. func AliyunSmsPushSave(c *gin.Context) {
  125. notice.AliyunSmsPushSave(c)
  126. }
  127. // AliyunSmsGetUserList
  128. // @Summary 消息中心-短信推送记录-获取用户信息
  129. // @Tags 消息中心
  130. // @Description 获取用户信息
  131. // @Accept json
  132. // @Produce json
  133. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  134. // @Param req body md.JPushGetUserListReq true "(分页信息必填)"
  135. // @Success 200 {Object} md.JPushGetUserListResp "具体数据"
  136. // @Failure 400 {object} md.Response "具体错误"
  137. // @Router /api/notice/aliyunSms/getUserList [post]
  138. func AliyunSmsGetUserList(c *gin.Context) {
  139. var req *md.AliyunSmsUserListReq
  140. if err := c.ShouldBindJSON(&req); err != nil {
  141. e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
  142. return
  143. }
  144. levelDb := implement.NewUserLevelDb(db.Db)
  145. levels, err1 := levelDb.UserLevelAllByAsc()
  146. if err1 != nil {
  147. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  148. return
  149. }
  150. levelsList := make([]map[string]interface{}, 0)
  151. levelsMap := make(map[int]string)
  152. for _, level := range levels {
  153. levelsList = append(levelsList, map[string]interface{}{
  154. "id": level.Id,
  155. "name": level.LevelName,
  156. })
  157. levelsMap[level.Id] = level.LevelName
  158. }
  159. tagDb := implement.NewUserTagDb(db.Db)
  160. tags, err2 := tagDb.UserTagAllByAsc()
  161. if err2 != nil {
  162. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  163. return
  164. }
  165. tagsList := make([]map[string]interface{}, 0)
  166. tagsMap := make(map[int]string)
  167. for _, tag := range tags {
  168. tagsList = append(tagsList, map[string]interface{}{
  169. "id": tag.Id,
  170. "name": tag.TagName,
  171. })
  172. tagsMap[tag.Id] = tag.TagName
  173. }
  174. stateList := []map[string]interface{}{
  175. {
  176. "name": "正常",
  177. "value": "1",
  178. },
  179. {
  180. "name": "冻结",
  181. "value": "2",
  182. },
  183. }
  184. userMemberRequest := req.ToUserMemberRequest()
  185. users, total, err3 := svc.UserManagementGetUsers(userMemberRequest)
  186. if err3 != nil {
  187. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  188. return
  189. }
  190. userIDs := make([]int64, len(users))
  191. for i, user := range users {
  192. userIDs[i] = user.Id
  193. }
  194. recordsDb := implement.NewUserTagRecordsDb(db.Db)
  195. records, err := recordsDb.UserTagRecordsFindByParams(map[string]interface{}{
  196. "key": "uid",
  197. "value": userIDs,
  198. })
  199. if err != nil {
  200. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  201. return
  202. }
  203. var levelCounts []md.LevelCount
  204. err4 := db.Db.Table("user").Select("level, Count(*) AS count").GroupBy("level").Find(&levelCounts)
  205. if err4 != nil {
  206. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  207. return
  208. }
  209. userMap := make(map[int64]int, len(users))
  210. list := make([]md.GetUserListNode, len(users))
  211. for i, user := range users {
  212. list[i] = md.GetUserListNode{
  213. ID: user.Id,
  214. Sex: user.Sex,
  215. Avatar: svc2.GetOssUrl(user.Avatar),
  216. Nickname: user.Nickname,
  217. Phone: user.Phone,
  218. IsRealName: user.IsRealName,
  219. InviteCode: user.SystemInviteCode,
  220. ParentID: user.ParentUid,
  221. ParentInviteCode: user.ParentSystemInviteCode,
  222. ParentPhone: user.Phone,
  223. RegisterTime: user.CreateAt,
  224. Memo: user.Memo,
  225. Wechat: user.UnionId,
  226. RegisterType: user.RegisterType,
  227. State: user.State,
  228. LastLoginAt: user.UpdateAt,
  229. }
  230. var tempTagList []md.TagNode
  231. list[i].Tag = tempTagList
  232. userMap[user.Id] = i
  233. level, ok := levelsMap[user.Level]
  234. if ok {
  235. list[i].LevelName = level
  236. }
  237. }
  238. for _, record := range *records {
  239. tempTagNode := md.TagNode{
  240. TagID: record.TagId,
  241. TagName: tagsMap[record.TagId],
  242. }
  243. list[userMap[record.Uid]].Tag = append(list[userMap[record.Uid]].Tag, tempTagNode)
  244. }
  245. resp := md.AliyunSmsGetUserListResp{
  246. LevelsList: levelsList,
  247. TagsList: tagsList,
  248. StateList: stateList,
  249. List: list,
  250. Paginate: md.Paginate{
  251. Limit: req.Limit,
  252. Page: req.Page,
  253. Total: total,
  254. },
  255. }
  256. e.OutSuc(c, resp, nil)
  257. }
  258. // AliyunSmsTagList
  259. // @Summary 消息中心-短信推送记录-标签管理(获取)
  260. // @Tags 消息中心
  261. // @Description 标签管理(获取)
  262. // @Accept json
  263. // @Produce json
  264. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  265. // @Param limit query int true "每页大小"
  266. // @Param page query int true "页数"
  267. // @Success 200 {object} md.AliyunSmsGetTagListResp "具体数据"
  268. // @Failure 400 {object} md.Response "具体错误"
  269. // @Router /api/notice/aliyunSms/getTagList [get]
  270. func AliyunSmsTagList(c *gin.Context) {
  271. page := c.DefaultQuery("page", "1")
  272. limit := c.DefaultQuery("limit", "10")
  273. list, total, err := svc.TagManagementGetList(page, limit)
  274. if err != nil {
  275. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  276. return
  277. }
  278. resp := md.AliyunSmsGetTagListResp{
  279. List: list,
  280. Paginate: md.Paginate{
  281. Limit: utils.StrToInt(limit),
  282. Page: utils.StrToInt(page),
  283. Total: total,
  284. },
  285. }
  286. e.OutSuc(c, resp, nil)
  287. }
  288. // AliyunSmsGetLevelList
  289. // @Summary 消息中心-短信推送记录-等级管理(获取)
  290. // @Tags 消息中心
  291. // @Description 等级管理(获取)
  292. // @Accept json
  293. // @Produce json
  294. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  295. // @Param limit query int true "每页大小"
  296. // @Param page query int true "页数"
  297. // @Success 200 {object} md.AliyunSmsGetLevelListResp "具体数据"
  298. // @Failure 400 {object} md.Response "具体错误"
  299. // @Router /api/notice/aliyunSms/getLevelList [get]
  300. func AliyunSmsGetLevelList(c *gin.Context) {
  301. page := c.DefaultQuery("page", "1")
  302. limit := c.DefaultQuery("limit", "10")
  303. list, total, err := svc.LevelManagementGetLevelList(page, limit)
  304. if err != nil {
  305. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  306. return
  307. }
  308. resp := md.AliyunSmsGetLevelListResp{
  309. List: list,
  310. Paginate: md.Paginate{
  311. Limit: utils.StrToInt(limit),
  312. Page: utils.StrToInt(page),
  313. Total: total,
  314. },
  315. }
  316. e.OutSuc(c, resp, nil)
  317. }