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.
 
 
 
 
 
 

62 lines
1.9 KiB

package api
import (
"yunyan/comm"
"yunyan/pb"
)
// 更新产品
func (this *apiComp) UpdateProduct(session comm.IUserSession, req *pb.ApiUpdateProductReq) (resp *pb.ApiUpdateProductResp, errdata *pb.ErrorData) {
var err error
if req.Product.Bassfilter > 1000 {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Message: "bassfilter 取值范围为 0-1000",
}
return
}
var old *pb.DBProduct
if old, err = this.module.model.product(req.Product.Id); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Message: pb.ErrorCode_ReqParameterError.String(),
}
return
}
// 归属方案商(即方案ID BID;芯片ID CID 由它的 vendor 推出):更新是全字段 Save,没传就会被清空,
// 所以传 0 视为「不改」,沿用原绑定。绑定与校验统一在 console 后台做。
if req.Product.Providerid == 0 && old != nil {
req.Product.Providerid = old.Providerid
}
// 创建时间同理:只在新增时写一次,更新没回传就沿用旧值。
if req.Product.Createtime == 0 && old != nil {
req.Product.Createtime = old.Createtime
}
// 指定了 versionid 时,从版本表同步版本/描述/升级包地址,前端无需重复传
if req.Product.Versionid != 0 {
ver, verr := this.module.model.productversion(req.Product.Versionid)
if verr != nil || ver == nil || ver.Productid != req.Product.Id {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Message: "versionid 无效",
}
return
}
req.Product.Version = ver.Version
req.Product.Updatedescription = ver.Description
req.Product.Updatepackageaddress = ver.Updatepackageaddress
}
if err = this.module.model.updateproducts(req.Product); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Message: pb.ErrorCode_DBError.String(),
}
return
}
resp = &pb.ApiUpdateProductResp{}
return
}