b6cc44140f
CI / changes (push) Successful in 39s
CI / ad (push) Successful in 0s
CI / admin (push) Successful in 0s
CI / bff (push) Successful in 0s
CI / chore (push) Successful in 0s
CI / equipment (push) Successful in 0s
CI / express (push) Successful in 0s
CI / factory (push) Successful in 0s
CI / payment (push) Successful in 0s
CI / product (push) Successful in 0s
CI / record (push) Successful in 0s
CI / sale (push) Successful in 0s
CI / task (push) Successful in 0s
CI / user (push) Successful in 0s
CI / wecom (push) Successful in 0s
77 lines
1.9 KiB
Go
77 lines
1.9 KiB
Go
package logic
|
||
|
||
import (
|
||
"lone-services/pkg/modelbase"
|
||
"lone-services/pkg/utils"
|
||
"lone-services/pkg/validate"
|
||
store "lone-services/rpc/store/pb"
|
||
"reflect"
|
||
"strconv"
|
||
|
||
jsoniter "github.com/json-iterator/go"
|
||
)
|
||
|
||
type BaseLogic struct {
|
||
}
|
||
|
||
func (l *BaseLogic) checkParams(in interface{}, v validate.IValidator) *store.Response {
|
||
rv := reflect.ValueOf(in)
|
||
if rv.Kind() != reflect.Ptr || rv.IsNil() {
|
||
return &store.Response{
|
||
Code: utils.ErrorParams.Code,
|
||
Msg: "request must be non‑nil proto pointer",
|
||
}
|
||
}
|
||
|
||
resp := validate.ValidateFromProto(in, v)
|
||
if resp != utils.StringEmpty {
|
||
return &store.Response{
|
||
Code: utils.ErrorParams.Code,
|
||
Msg: resp,
|
||
}
|
||
}
|
||
return nil
|
||
}
|
||
|
||
func (l *BaseLogic) fail(status utils.Status) (*store.Response, error) {
|
||
return l.out(status, status.Msg)
|
||
}
|
||
func (l *BaseLogic) out(status utils.Status, msg string) (*store.Response, error) {
|
||
return &store.Response{Code: status.Code, Msg: msg}, nil
|
||
}
|
||
|
||
func (l *BaseLogic) outData(status utils.Status, msg, data string) (*store.Response, error) {
|
||
return &store.Response{Code: status.Code, Msg: msg, Data: data}, nil
|
||
}
|
||
|
||
func (l *BaseLogic) ok(data any) (*store.Response, error) {
|
||
buf, _ := jsoniter.Marshal(data)
|
||
return &store.Response{Code: utils.Ok.Code, Msg: utils.Ok.Msg, Data: string(buf)}, nil
|
||
}
|
||
|
||
func (s BaseLogic) SetWhere(w *modelbase.Params, u utils.UserInfo) {
|
||
if u.Type == utils.SaleType {
|
||
s.SetGroupWhere(w, u, false)
|
||
}
|
||
}
|
||
|
||
func (s BaseLogic) SetGroupWhere(w *modelbase.Params, u utils.UserInfo, checkProvince bool) {
|
||
if w.Eq == nil {
|
||
w.Eq = make(map[string]string)
|
||
}
|
||
if u.GroupId < utils.NumberOne {
|
||
return
|
||
}
|
||
|
||
//如果是公司销售
|
||
if u.Type == utils.SaleType {
|
||
w.Eq["group_id"] = strconv.Itoa(int(u.GroupId))
|
||
} else if u.SaleProvince > utils.NumberZero {
|
||
if checkProvince {
|
||
w.Eq["sale_province"] = strconv.Itoa(int(u.SaleProvince))
|
||
} else {
|
||
w.Eq["group_id"] = strconv.Itoa(int(u.GroupId))
|
||
}
|
||
}
|
||
}
|