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.
49 lines
1.4 KiB
49 lines
1.4 KiB
package api
|
|
|
|
import (
|
|
"yunyan/comm"
|
|
"yunyan/lego/sys/log"
|
|
"yunyan/pb"
|
|
)
|
|
|
|
// 更新品牌商信息
|
|
func (this *apiComp) UpdateBrand(session comm.IUserSession, req *pb.ApiUpdateBrandReq) (resp *pb.ApiUpdateBrandResp, errdata *pb.ErrorData) {
|
|
var (
|
|
old *pb.DBBrand
|
|
err error
|
|
)
|
|
if req.Brand == nil || req.Brand.Id == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Message: "brand id is required",
|
|
}
|
|
return
|
|
}
|
|
if old, err = this.module.model.factory(req.Brand.Id); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
this.module.Error("UpdateBrand Fail!", log.Field{Key: "req", Value: req.String()}, log.Field{Key: "err", Value: err.Error()})
|
|
return
|
|
}
|
|
// 仅允许客户端覆盖可编辑字段,productlists 等由服务端维护的字段不接受前端写入,
|
|
// 防止前端表单缺字段或携带陈旧值时把产品列表覆盖回旧值。
|
|
old.Brand = req.Brand.Brand
|
|
old.Providerid = req.Brand.Providerid
|
|
old.Description = req.Brand.Description
|
|
old.Contactmails = req.Brand.Contactmails
|
|
if err = this.module.model.savefactory(old); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
this.module.Error("UpdateBrand Fail!", log.Field{Key: "req", Value: req.String()}, log.Field{Key: "err", Value: err.Error()})
|
|
return
|
|
}
|
|
|
|
resp = &pb.ApiUpdateBrandResp{
|
|
Brand: old,
|
|
}
|
|
return
|
|
}
|
|
|