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.
 
 
 
 
 
 

102 lines
2.8 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
}
// 解绑冲正 -1:绑定数是「当日净增」口径,只加不减会让绑了又解的设备永久留在统计里。
// 产品/渠道取被解绑设备自身的归属(绑定时固化),保证 +1 与 -1 落在同一分区。
// 激活不冲正:激活是设备一生一次的事件,解绑也不会把授权码 status 归零。
if this.module.analyze != nil {
this.module.analyze.Report(&comm.StatEvent{
Type: comm.StatEventDeviceBind,
Uid: session.GetUserId(),
ProductId: uint32(divice.Productid),
ChannelId: divice.Channelid,
Count: -1,
})
}
resp = &pb.UserUnBindDeviceResp{}
return
}