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.
111 lines
2.2 KiB
111 lines
2.2 KiB
package upgrade
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"math/rand"
|
|
"recook/internal/back"
|
|
"recook/internal/cache"
|
|
"recook/internal/v2/controller/app/message"
|
|
"recook/internal/v2/lib/common"
|
|
"recook/internal/v2/logic/app/upgrade"
|
|
"recook/internal/v2/model/recook/user"
|
|
"recook/tools"
|
|
"strings"
|
|
"time"
|
|
|
|
"git.oa00.com/go/mysql"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type Proxy struct {
|
|
}
|
|
|
|
func (o Proxy) List(c *gin.Context) {
|
|
args := upgrade.ApplyList{}
|
|
|
|
if err := tools.ParseParams(&args, c); err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
|
|
userID, _ := common.GetAppUserId(c)
|
|
args.UserID = userID
|
|
|
|
res := upgrade.Logic.List(args)
|
|
|
|
back.Suc(c, "获取成功", res)
|
|
}
|
|
|
|
func (o Proxy) Create(c *gin.Context) {
|
|
args := upgrade.ApplyCreate{}
|
|
|
|
if err := tools.ParseParams(&args, c); err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
|
|
userID, _ := common.GetAppUserId(c)
|
|
|
|
args.UserID = userID
|
|
|
|
if err := upgrade.Logic.Create(args); err != nil {
|
|
back.Fail(c, err.Error())
|
|
} else {
|
|
back.Suc(c, "申请成功", "")
|
|
}
|
|
}
|
|
|
|
type ArgsSend struct {
|
|
Mobile string `json:"mobile"`
|
|
}
|
|
|
|
func (o Proxy) Send(c *gin.Context) {
|
|
|
|
args := ArgsSend{}
|
|
|
|
if err := tools.ParseParams(&args, c); err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
|
|
if len(args.Mobile) != 11 || !strings.HasPrefix(args.Mobile, "1") {
|
|
back.Fail(c, fmt.Errorf("手机格式异常").Error())
|
|
return
|
|
}
|
|
|
|
id, _ := common.GetAppUserId(c)
|
|
|
|
var u user.RecookUserInfoModel
|
|
if err := mysql.Db.Table(u.TableName()).Where("id = ?", id).First(&u).Error; err != nil {
|
|
back.Err(c, err.Error())
|
|
return
|
|
}
|
|
|
|
randString := fmt.Sprintf("%04v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000))
|
|
request := message.ReturnRequest(args.Mobile, randString)
|
|
response, err := message.Client.ProcessCommonRequest(request)
|
|
if err != nil {
|
|
back.Err(c, err.Error())
|
|
return
|
|
}
|
|
|
|
if response.IsSuccess() {
|
|
cache.SetUpgradeSMSCode(u.Id, args.Mobile, randString)
|
|
|
|
var p message.AliResp
|
|
if err = json.Unmarshal(response.GetHttpContentBytes(), &p); err != nil {
|
|
back.Err(c, err.Error())
|
|
return
|
|
}
|
|
if p.Message != "OK" {
|
|
back.Err(c, "短信发送失败"+p.Message)
|
|
return
|
|
}
|
|
|
|
back.Suc(c, "发送成功", nil)
|
|
} else {
|
|
back.Err(c, "短信发送失败")
|
|
}
|
|
}
|