广告平台(总站长使用)
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

hdl_sms.go 3.9 KiB

há 3 meses
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package hdl
  2. import (
  3. "applet/app/e"
  4. "applet/app/lib/validate"
  5. "applet/app/md"
  6. "applet/app/utils"
  7. db "code.fnuoos.com/zhimeng/model.git/src"
  8. "code.fnuoos.com/zhimeng/model.git/src/super/model"
  9. "github.com/gin-gonic/gin"
  10. )
  11. // SmsList
  12. // @Summary 列表
  13. // @Tags 短信中心
  14. // @Description 短信中心-列表
  15. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  16. // @Accept json
  17. // @Produce json
  18. // @Param args body md.SmsListReq true "请求参数"
  19. // @Success 200 {object} md.SmsListResp "具体看返回内容 这是data里面的数据"
  20. // @Failure 400 {object} md.Response "具体错误"
  21. // @Router /api/smsCenter/list [POST]
  22. func SmsList(c *gin.Context) {
  23. var req md.SmsListReq
  24. err := c.ShouldBindJSON(&req)
  25. if err != nil {
  26. err = validate.HandleValidateErr(err)
  27. err1 := err.(e.E)
  28. e.OutErr(c, err1.Code, err1.Error())
  29. return
  30. }
  31. var list []*md.MasterWithSmsNumList
  32. sess := db.Db.Where("1 = 1").Limit(req.Limit, (req.Page-1)*req.Limit)
  33. if req.Uuid != "" {
  34. sess.And("user_list.uuid=?", req.Uuid)
  35. }
  36. if req.Name != "" {
  37. sess.And("user_list.name like ?", "%"+req.Name+"%")
  38. }
  39. total, err := sess.Where("1 =1 ").
  40. Join("LEFT", "sms_num_list", "user_list.uuid = sms_num_list.uid").
  41. FindAndCount(&list)
  42. var resp = md.SmsListResp{
  43. Total: total,
  44. }
  45. for _, v := range list {
  46. resp.List = append(resp.List, md.SmsList{
  47. Uuid: utils.IntToStr(v.UserList.Uuid),
  48. Name: v.UserList.Name,
  49. Num: int64(v.SmsNumList.Num),
  50. })
  51. }
  52. e.OutSuc(c, resp, nil)
  53. return
  54. }
  55. // SmsDetail
  56. // @Summary 详情
  57. // @Tags 短信中心
  58. // @Description 短信中心-详情
  59. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  60. // @Accept json
  61. // @Produce json
  62. // @Param args body md.SmsDetailReq true "请求参数"
  63. // @Success 200 {object} md.SmsDetailResp "具体看返回内容 这是data里面的数据"
  64. // @Failure 400 {object} md.Response "具体错误"
  65. // @Router /api/smsCenter/detail [POST]
  66. func SmsDetail(c *gin.Context) {
  67. var req md.SmsDetailReq
  68. err := c.ShouldBindJSON(&req)
  69. if err != nil {
  70. err = validate.HandleValidateErr(err)
  71. err1 := err.(e.E)
  72. e.OutErr(c, err1.Code, err1.Error())
  73. return
  74. }
  75. var list []*model.SmsRecord
  76. sess := db.Db.Where("uid = ?", req.Uuid).Limit(req.Limit, (req.Page-1)*req.Limit)
  77. total, err := sess.FindAndCount(&list)
  78. var resp = md.SmsDetailResp{
  79. Total: total,
  80. }
  81. for _, v := range list {
  82. stateZh := "发送成功"
  83. if v.State != 1 {
  84. stateZh = "发送失败"
  85. }
  86. resp.List = append(resp.List, md.SmsDetail{
  87. Id: v.Id,
  88. Phone: v.Phone,
  89. StateZh: stateZh,
  90. CreateAt: v.CreateAt.Format("2006-01-02 15:04:05"),
  91. })
  92. }
  93. e.OutSuc(c, resp, nil)
  94. return
  95. }
  96. // SmsUpdate
  97. // @Summary 修改
  98. // @Tags 短信中心
  99. // @Description 短信中心-修改
  100. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  101. // @Accept json
  102. // @Produce json
  103. // @Param args body md.SmsDetailReq true "请求参数"
  104. // @Success 200 {string} "success"
  105. // @Failure 400 {object} md.Response "具体错误"
  106. // @Router /api/smsCenter/update [POST]
  107. func SmsUpdate(c *gin.Context) {
  108. var req md.SmsUpdateReq
  109. err := c.ShouldBindJSON(&req)
  110. if err != nil {
  111. err = validate.HandleValidateErr(err)
  112. err1 := err.(e.E)
  113. e.OutErr(c, err1.Code, err1.Error())
  114. return
  115. }
  116. m := new(model.SmsNumList)
  117. has, err := db.Db.Where("uid =?", req.Uuid).Get(m)
  118. if err != nil {
  119. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  120. return
  121. }
  122. if has == false {
  123. e.OutErr(c, e.ERR_NOT_FAN, "未查询到站长记录")
  124. return
  125. }
  126. m.Num = req.Num
  127. _, err = db.Db.Where("uid =?", req.Uuid).Cols("num").Update(m)
  128. if err != nil {
  129. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  130. return
  131. }
  132. e.OutSuc(c, "success", nil)
  133. return
  134. }