作者 唐旭辉

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/oppmg into dev

... ... @@ -103,3 +103,12 @@ func GetAuditTemplateByTypeId(chanceTypeId int) (v []*AuditTemplate, err error)
}
return
}
func GetAuditTemplateByCode(companyId int64, code string) (v *ChanceType, err error) {
o := orm.NewOrm()
sql := "select * from audit_template where code=? and company_id=?"
if err = o.Raw(sql, code, companyId).QueryRow(&v); err == nil {
return
}
return
}
... ...
... ... @@ -92,3 +92,12 @@ func GetChanceTypeByCompany(companyId int) (v []*ChanceType, err error) {
}
return
}
func GetChanceTypeByCode(companyId int64, code string) (v *ChanceType, err error) {
o := orm.NewOrm()
sql := "select * from chance_type where code=? and company_id=?"
if err = o.Raw(sql, code, companyId).QueryRow(&v); err == nil {
return
}
return
}
... ...
... ... @@ -115,6 +115,7 @@ type TemplateList struct {
Id int `json:"id"`
Name string `json:"name"`
Icon string `json:"icon"`
Code string `json:"code"`
Templates []*TemplateItem `json:"templates"`
}
... ... @@ -123,6 +124,7 @@ type TemplateItem struct {
Name string `json:"name"`
Doc string `json:"doc"`
Icon string `json:"icon"`
Code string `json:"code"` //编码
EnableStatus int8 `json:"enableStatus"` //禁用状态
Sort int `json:"sort"` //序号
VisibleType int8 `json:"visibleType"`
... ... @@ -146,8 +148,8 @@ type TemplateEditVisibleResponse struct {
/*TemplateAddCategory */
type TemplateOperateCategoryRequest struct {
Id int `json:"id"`
Name string `json:"name"`
Code string `json:"code"`
Name string `json:"name" valid:"Required"`
Code string `json:"code" valid:"Required"`
Icon string `json:"icon"`
}
type TemplateOperateCategoryResponse struct {
... ...
... ... @@ -42,6 +42,8 @@ var errmessge ErrorMap = map[string]string{
"10061": "请先删除该分类下的二级分类",
"10062": "该分类已被使用无法删除",
"10063": "该分类已被使用无法禁用",
"10064": "编码已存在",
"10065": "编码长度为6个字符",
}
//错误码转换 ,兼容需要
... ...
... ... @@ -26,6 +26,14 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs
log.Error("chance_type_id:%v 不存在 ,err:%v", request.Template.ChanceTypeId, err.Error())
return
}
if len([]rune(request.Template.Code)) != 6 {
err = protocol.NewErrWithMessage("10065")
return
}
if _, err = models.GetAuditTemplateByCode(companyId, request.Template.Code); err == nil {
err = protocol.NewErrWithMessage("10064")
return
}
orm := orm2.NewOrm()
//模板
{
... ... @@ -199,6 +207,7 @@ func TemplateList(uid, companyId int64, request *protocol.TemplateListRequest) (
Id: t.Id,
Name: t.Name,
Icon: t.Icon,
Code: t.Code,
}
rsp.List = append(rsp.List, item)
if templates, err = models.GetAuditTemplateByTypeId(t.Id); err != nil {
... ... @@ -222,6 +231,7 @@ func TemplateList(uid, companyId int64, request *protocol.TemplateListRequest) (
Id: temp.Id,
Name: temp.Name,
Doc: temp.Doc,
Code: temp.Code,
Icon: temp.Icon,
EnableStatus: temp.EnableStatus,
Sort: temp.SortNum,
... ... @@ -423,6 +433,10 @@ func TemplateOperateCategory(uid, companyId int64, request *protocol.TemplateOpe
}
return
}
if len([]rune(request.Code)) != 6 {
err = protocol.NewErrWithMessage("10065")
return
}
chanceType = &models.ChanceType{
Name: request.Name,
Icon: request.Icon,
... ... @@ -431,6 +445,10 @@ func TemplateOperateCategory(uid, companyId int64, request *protocol.TemplateOpe
CreateAt: time.Now(),
UpdateAt: time.Now(),
}
if _, err = models.GetChanceTypeByCode(companyId, chanceType.Code); err == nil {
err = protocol.NewErrWithMessage("10064")
return
}
if _, err = models.AddChanceType(chanceType); err != nil {
log.Error(err.Error())
}
... ...