// 控制接口-微信小程序登录
// 秒寻科技
// 周涛
//2024-02-03

package usermobilehandler

import (
	"ipsomc/core/gin/bind"
	"ipsomc/core/gin/resp"
	"ipsomc/core/usermobile/usermobilelogic"
	"ipsomc/core/usermobile/usermobilemodel"
	"ipsomc/core/wxminilogin/wxminiloginmodel"

	"github.com/gin-gonic/gin"
)

type UserMobileHan struct {
	bindApi       bind.BindApi
	userMobileLgc usermobilelogic.UserMobileLgc
}

// 增加注册用户
func (obj *UserMobileHan) CheckUserLoginHan(c *gin.Context) {
	dataModel := new(usermobilemodel.UserMobile)

	//把前端数据绑定到模型
	if err := obj.bindApi.Bind2Model(c, dataModel); err != nil {
		resp.RespFail(c, "数据错误")
		return
	}

	//保存数据
	if err := obj.userMobileLgc.CheckUserLoginLgc(dataModel); err != nil {
		resp.RespFail(c, err.Error())
		return
	}

	//返回数据
	var respModel wxminiloginmodel.UserMobileLoginResp
	respModel.UserID = dataModel.ID
	respModel.Token = dataModel.Token
	resp.RespData(c, respModel)
}
