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.
 
 
 
 
 
 

90 lines
2.2 KiB

package user
import (
"yunyan/comm"
"yunyan/lego/sys/mysql"
"yunyan/pb"
"yunyan/utils/license"
)
// @Summary 解绑定耳机设备
// @Description 绑定耳机设备
// @Tags User
// @Accept json
// @Produce json
// @Security BearerAuth
// @Param user body pb.UserUnBindDeviceReq true "发送绑定请求"
// @Success 200 {object} comm.HttpResult{data=pb.UserUnBindDeviceResp} "成功返回"
// @Router /api/home/user_unbinddevice [post]
func (this *apiComp) UnBindDevice(session comm.IUserSession, req *pb.UserUnBindDeviceReq) (resp *pb.UserUnBindDeviceResp, errdata *pb.ErrorData) {
var (
divice *pb.DBUserDivice
model *pb.DBAuthCode
pid uint16
err error
)
if divice, err = this.module.model.getDevice(req.Id); err != nil {
if err == mysql.ErrNoDocuments {
resp = &pb.UserUnBindDeviceResp{}
} else {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Message: err.Error(),
}
}
return
}
if divice.Uid != session.GetUserId() {
resp = &pb.UserUnBindDeviceResp{}
return
}
pid, err = license.ProductID(divice.License)
if err != nil {
// errdata = &pb.ErrorData{
// Code: pb.ErrorCode_AuthorizeIllegal,
// Message: err.Error(),
// }
// return
err = nil
pid = uint16(45058)
}
if model, err = this.module.model.getFactoryDevice(uint32(pid), divice.License); err != nil { //设备已被注册
errdata = &pb.ErrorData{
Code: pb.ErrorCode_AuthorizeNoCanUse,
Message: err.Error(),
}
return
}
// if model.Status != 1 { //授权码已被使用
// errdata = &pb.ErrorData{
// Code: pb.ErrorCode_DeviceUnBinded,
// Message: "设备未绑定",
// }
// return
// }
if model.Uid == session.GetUserId() {
// model.Status = 0 //已绑定
model.Uid = ""
if model.Codetype == pb.Codetype_AUTHCODE { //认证码 才清理设备地址
model.Devicemac = ""
}
if err = this.module.model.saveFactoryDevice(model.Productid, model); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Message: err.Error(),
}
return
}
}
if err = this.module.model.delDevice(divice.Id); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Message: err.Error(),
}
return
}
resp = &pb.UserUnBindDeviceResp{}
return
}