53d203ee14
CI / changes (push) Successful in 14s
CI / docker-bff (push) Successful in 3s
CI / docker-product (push) Successful in 24s
CI / docker-admin (push) Has been skipped
CI / docker-user (push) Has been skipped
CI / docker-ad (push) Has been skipped
CI / docker-chore (push) Successful in 25s
CI / docker-express (push) Has been skipped
CI / docker-sale (push) Successful in 26s
158 lines
3.8 KiB
Go
158 lines
3.8 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/rpcclient"
|
|
"lone-services/pkg/utils"
|
|
chore "lone-services/rpc/chore/pb"
|
|
"lone-services/services/sale/internal/dao"
|
|
"lone-services/services/sale/internal/model"
|
|
"lone-services/services/sale/validator"
|
|
)
|
|
|
|
func saleTypeOptions() []dao.SaleTypeOption {
|
|
return []dao.SaleTypeOption{
|
|
{Value: dao.SaleTypeStaff, Label: "销售人员"},
|
|
{Value: dao.SaleTypeAgentCorp, Label: "销售商(法人)"},
|
|
{Value: dao.SaleTypeAgentPerson, Label: "销售商(个人)"},
|
|
}
|
|
}
|
|
|
|
func buildRegion(province, city, district string) dao.RegionNames {
|
|
return dao.RegionNames{
|
|
Province: province,
|
|
City: city,
|
|
District: district,
|
|
}
|
|
}
|
|
|
|
func fetchRegionNames(ctx context.Context, choreSvcName string, ids ...int64) (map[int64]string, error) {
|
|
seen := make(map[int64]struct{}, len(ids))
|
|
reqIds := make([]int64, 0, len(ids))
|
|
for _, id := range ids {
|
|
if id < utils.NumberOne {
|
|
continue
|
|
}
|
|
if _, ok := seen[id]; ok {
|
|
continue
|
|
}
|
|
seen[id] = struct{}{}
|
|
reqIds = append(reqIds, id)
|
|
}
|
|
result := make(map[int64]string, len(reqIds))
|
|
if len(reqIds) < utils.NumberOne {
|
|
return result, nil
|
|
}
|
|
|
|
cli, err := rpcclient.Get(choreSvcName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
res, err := chore.NewChoreClient(cli.Conn()).RegionsByIds(ctx, &chore.RegionsByIdsReq{Ids: reqIds})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
for _, item := range res.GetItems() {
|
|
result[item.GetId()] = item.GetName()
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func querySaleNames(req validator.NamesValidator) ([]dao.SaleNameItem, error) {
|
|
w := modelbase.Params{
|
|
Eq: map[string]string{"status": strconv.Itoa(int(dao.SaleStatusApproved))},
|
|
Order: "id desc",
|
|
Like: map[string]string{},
|
|
}
|
|
if req.Type > utils.NumberZero {
|
|
w.Eq["type"] = strconv.Itoa(int(req.Type))
|
|
}
|
|
if req.Level == utils.NumberOne {
|
|
w.Eq["sale_id"] = strconv.Itoa(utils.NumberZero)
|
|
}
|
|
if req.Name != utils.StringEmpty {
|
|
w.Like["name LIKE ?"] = "%" + req.Name + "%"
|
|
}
|
|
|
|
var items []dao.SaleNameItem
|
|
m := model.SaleModel{}.Init()
|
|
if err := m.Items(w, &items); err != nil {
|
|
return nil, err
|
|
}
|
|
if items == nil {
|
|
items = []dao.SaleNameItem{}
|
|
}
|
|
maskSaleNameItems(items)
|
|
return items, nil
|
|
}
|
|
|
|
func maskSaleMobile(info *dao.SaleInfo) {
|
|
if info == nil {
|
|
return
|
|
}
|
|
info.OriginMobile = info.Mobile
|
|
mobile, err := utils.DecryptPhone(info.Mobile)
|
|
if err != nil {
|
|
return
|
|
}
|
|
info.Mobile = utils.DecryptPhoneReplace(mobile)
|
|
}
|
|
|
|
// querySaleInfo 查询销售详情并附带分组;mobile 脱敏,origin_mobile 为加密串。
|
|
// 未找到时返回 (nil, nil)。
|
|
func querySaleInfo(id int64) (*dao.SaleInfo, error) {
|
|
var info dao.SaleInfo
|
|
if err := (model.SaleModel{}.Init().GetOne(modelbase.Params{
|
|
Eq: map[string]string{"id": strconv.FormatInt(id, 10)},
|
|
}, &info)); err != nil {
|
|
return nil, err
|
|
}
|
|
if info.Id < utils.NumberOne {
|
|
return nil, nil
|
|
}
|
|
maskSaleMobile(&info)
|
|
|
|
if info.GroupId > utils.NumberZero {
|
|
var group dao.SaleGroupNameItem
|
|
if err := (model.SaleGroupModel{}.Init().GetOne(modelbase.Params{
|
|
Eq: map[string]string{"id": strconv.FormatInt(info.GroupId, 10)},
|
|
}, &group)); err != nil {
|
|
return nil, err
|
|
}
|
|
if group.Id > utils.NumberZero {
|
|
info.Group = &group
|
|
}
|
|
}
|
|
return &info, nil
|
|
}
|
|
|
|
func maskSaleNameItems(items []dao.SaleNameItem) {
|
|
for i := range items {
|
|
mobile, err := utils.DecryptPhone(items[i].Mobile)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
items[i].Mobile = utils.DecryptPhoneReplace(mobile)
|
|
}
|
|
}
|
|
|
|
func validateSaleTypeRules(saleType uint32, account, businessLicense string) string {
|
|
switch uint8(saleType) {
|
|
case dao.SaleTypeAgentCorp:
|
|
if account == utils.StringEmpty {
|
|
return "缺少账户信息"
|
|
}
|
|
if businessLicense == utils.StringEmpty {
|
|
return "缺少营业执照"
|
|
}
|
|
case dao.SaleTypeAgentPerson:
|
|
if account == utils.StringEmpty {
|
|
return "缺少账户信息"
|
|
}
|
|
}
|
|
return utils.StringEmpty
|
|
}
|