|
- package hdl
-
- import (
- "applet/app/e"
- "applet/app/lib/validate"
- "applet/app/md"
- "applet/app/utils"
- db "code.fnuoos.com/zhimeng/model.git/src"
- "code.fnuoos.com/zhimeng/model.git/src/super/model"
- "github.com/gin-gonic/gin"
- )
-
- // SmsList
- // @Summary 列表
- // @Tags 短信中心
- // @Description 短信中心-列表
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Accept json
- // @Produce json
- // @Param args body md.SmsListReq true "请求参数"
- // @Success 200 {object} md.SmsListResp "具体看返回内容 这是data里面的数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/smsCenter/list [POST]
- func SmsList(c *gin.Context) {
- var req md.SmsListReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
-
- var list []*md.MasterWithSmsNumList
- sess := db.Db.Where("1 = 1").Limit(req.Limit, (req.Page-1)*req.Limit)
- if req.Uuid != "" {
- sess.And("user_list.uuid=?", req.Uuid)
- }
- if req.Name != "" {
- sess.And("user_list.name like ?", "%"+req.Name+"%")
- }
- total, err := sess.Where("1 =1 ").
- Join("LEFT", "sms_num_list", "user_list.uuid = sms_num_list.uid").
- FindAndCount(&list)
-
- var resp = md.SmsListResp{
- Total: total,
- }
- for _, v := range list {
- resp.List = append(resp.List, md.SmsList{
- Uuid: utils.IntToStr(v.UserList.Uuid),
- Name: v.UserList.Name,
- Num: int64(v.SmsNumList.Num),
- })
- }
- e.OutSuc(c, resp, nil)
- return
- }
-
- // SmsDetail
- // @Summary 详情
- // @Tags 短信中心
- // @Description 短信中心-详情
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Accept json
- // @Produce json
- // @Param args body md.SmsDetailReq true "请求参数"
- // @Success 200 {object} md.SmsDetailResp "具体看返回内容 这是data里面的数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/smsCenter/detail [POST]
- func SmsDetail(c *gin.Context) {
- var req md.SmsDetailReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
-
- var list []*model.SmsRecord
- sess := db.Db.Where("uid = ?", req.Uuid).Limit(req.Limit, (req.Page-1)*req.Limit)
- total, err := sess.FindAndCount(&list)
-
- var resp = md.SmsDetailResp{
- Total: total,
- }
- for _, v := range list {
- stateZh := "发送成功"
- if v.State != 1 {
- stateZh = "发送失败"
- }
- resp.List = append(resp.List, md.SmsDetail{
- Id: v.Id,
- Phone: v.Phone,
- StateZh: stateZh,
- CreateAt: v.CreateAt.Format("2006-01-02 15:04:05"),
- })
- }
- e.OutSuc(c, resp, nil)
- return
- }
-
- // SmsUpdate
- // @Summary 修改
- // @Tags 短信中心
- // @Description 短信中心-修改
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Accept json
- // @Produce json
- // @Param args body md.SmsDetailReq true "请求参数"
- // @Success 200 {string} "success"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/smsCenter/update [POST]
- func SmsUpdate(c *gin.Context) {
- var req md.SmsUpdateReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
-
- m := new(model.SmsNumList)
- has, err := db.Db.Where("uid =?", req.Uuid).Get(m)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if has == false {
- e.OutErr(c, e.ERR_NOT_FAN, "未查询到站长记录")
- return
- }
- m.Num = req.Num
- _, err = db.Db.Where("uid =?", req.Uuid).Cols("num").Update(m)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- e.OutSuc(c, "success", nil)
- return
- }
|