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.
57 lines
1.3 KiB
57 lines
1.3 KiB
package api
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
|
|
"yunyan/comm"
|
|
"yunyan/lego/sys/log"
|
|
"yunyan/pb"
|
|
)
|
|
|
|
const defaultFactoryContactMail = "358030594@qq.com"
|
|
|
|
// 添加品牌商
|
|
func (this *apiComp) AddBrand(session comm.IUserSession, req *pb.ApiAddBrandReq) (resp *pb.ApiAddBrandResp, errdata *pb.ErrorData) {
|
|
var (
|
|
err error
|
|
)
|
|
if req.Brand != nil {
|
|
req.Brand.Contactmails = ensureDefaultContactMail(req.Brand.Contactmails)
|
|
req.Brand.Createtime = time.Now().Unix()
|
|
}
|
|
if err = this.module.model.addfactory(req.Brand); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
this.module.Error("AddBrand Fail!", log.Field{Key: "req", Value: req.String()}, log.Field{Key: "err", Value: err.Error()})
|
|
return
|
|
}
|
|
|
|
resp = &pb.ApiAddBrandResp{
|
|
Brand: req.Brand,
|
|
}
|
|
return
|
|
}
|
|
|
|
// 确保品牌商联系邮箱中包含默认邮箱
|
|
func ensureDefaultContactMail(mails string) string {
|
|
parts := strings.Split(mails, ",")
|
|
cleaned := make([]string, 0, len(parts)+1)
|
|
has := false
|
|
for _, p := range parts {
|
|
m := strings.TrimSpace(p)
|
|
if m == "" {
|
|
continue
|
|
}
|
|
if strings.EqualFold(m, defaultFactoryContactMail) {
|
|
has = true
|
|
}
|
|
cleaned = append(cleaned, m)
|
|
}
|
|
if !has {
|
|
cleaned = append([]string{defaultFactoryContactMail}, cleaned...)
|
|
}
|
|
return strings.Join(cleaned, ",")
|
|
}
|
|
|