package api import ( "fmt" "yunyan/comm" "yunyan/pb" "yunyan/utils/devcode" ) // 批量重置License状态 func (this *apiComp) BatchResetLicenseStatus(session comm.IUserSession, req *pb.ApiBatchResetLicenseStatusReq) (resp *pb.ApiBatchResetLicenseStatusResp, errdata *pb.ErrorData) { resp = &pb.ApiBatchResetLicenseStatusResp{} for _, code := range req.Licenses { if err := this.resetOneLicense(req.Productid, code); err != nil { resp.FailCount++ } else { resp.SuccessCount++ } } return } // resetOneLicense 重置单条设备码(license 或 MAC)到初始状态(供单条和批量共享)。 // // productid 由调用方给;传 0 才从设备码反解。 // ⚠️ 别把反解失败回退成写死的 PID:那会去改另一个产品的分表。宁可报错。 func (this *apiComp) resetOneLicense(productid uint32, licenseCode string) error { pid := productid if pid == 0 { p, err := devcode.ProductID(licenseCode) if err != nil { return fmt.Errorf("无法确定该设备码所属产品,请带上 productid: %s", licenseCode) } pid = uint32(p) } model, err := this.module.model.factoryDevic(pid, licenseCode) if err != nil { return err } wasActivated := model.Uid != "" if wasActivated { if err = this.module.model.deluserdevice(model.Uid); err != nil { return err } } model.Status = 0 model.Uid = "" // ⚠️ 只有认证码(AUTHCODE)的 devicemac 是绑定时填进去的,重置要清掉。 // 设备码(DEVICECODE)的 devicemac 是这台设备出厂就定死的身份——2026-09-02 起 code 就是它—— // 清掉等于把设备从库里抹了:按 MAC 反查绑定的路径再也找不到它,而 code 那一列还留着, // 两列从此对不上。解绑路径(api_unbinddevice.go)一直是按这个规则做的,这里以前漏了。 // ⚠️ 不清 devicemac:设备码 = MAC = 分表主键 code(授权码字符串已于 2026-09-02 移除), // 清掉等于把这台设备从库里抹掉——按 MAC 反查绑定的路径再也找不到它, // 而 code 那一列还留着,两列从此对不上。 model.Usedtime = 0 if err = this.module.model.updatefactoryDevic(pid, model); err != nil { return err } if wasActivated && model.Productid > 0 { _ = this.module.model.decrProductStatActivated(model.Productid) } return nil }