// 操作接口-移动端用户
// 秒寻科技
// zt
//2024-02-22

package usermobileapi

import (
	"ipsomc/core/dao/mysql/mysqlapi"
	"ipsomc/core/usermobile/usermobilemodel"
)

type UserMobileApi struct {
	mySqlApi mysqlapi.MySqlApi
}

func (obj *UserMobileApi) AddUserByOpenId(dataModel *usermobilemodel.UserMobile) error {
	if err := obj.mySqlApi.AddItem(dataModel); err != nil {
		return err
	}
	return nil
}

// 根据用户openid获取用户信息
func (obj *UserMobileApi) GetUserByOpenId(dataModel *usermobilemodel.UserMobile) error {
	modelUser := new(usermobilemodel.UserMobile)
	var count uint8
	if err := obj.mySqlApi.GetDb().Model(modelUser).Where("open_id=?", dataModel.OpenID).Count(&count).Error; err != nil {
		return err
	}

	if count > 0 {
		if err := obj.mySqlApi.GetDb().Model(modelUser).Where("open_id=?", dataModel.OpenID).First(dataModel).Error; err != nil {
			return err
		}
	}

	return nil
}
