广告平台(总站长使用)
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

145 satır
3.9 KiB

  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. }