feat: import services and standardize Go 1.26.5
This commit is contained in:
41
apps/ec/market/internal/config/config.go
Normal file
41
apps/ec/market/internal/config/config.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/conf"
|
||||
"git.apinb.com/bsm-sdk/core/crypto/encipher"
|
||||
"git.apinb.com/bsm-sdk/core/env"
|
||||
)
|
||||
|
||||
var (
|
||||
Spec SrvConfig
|
||||
)
|
||||
|
||||
type SrvConfig struct {
|
||||
conf.Base `yaml:",inline"`
|
||||
Databases *conf.DBConf `yaml:"Databases"`
|
||||
MicroService *conf.MicroServiceConf `yaml:"MicroService"`
|
||||
Rpc map[string]conf.RpcConf `yaml:"Rpc"`
|
||||
Gateway *conf.GatewayConf `yaml:"Gateway"`
|
||||
Apm *conf.ApmConf `yaml:"APM"`
|
||||
Etcd *conf.EtcdConf `yaml:"Etcd"`
|
||||
}
|
||||
|
||||
func New(srvKey string) {
|
||||
// 初始化配置 创建一个新的配置实例,用于服务配置
|
||||
conf.New(srvKey, &Spec)
|
||||
|
||||
// 配置校验 服务IP,端口; 端口如果不合规,则随机分配端口
|
||||
Spec.Port = conf.CheckPort(Spec.Port)
|
||||
Spec.BindIP = conf.CheckIP(Spec.BindIP)
|
||||
Spec.Addr = net.JoinHostPort(Spec.BindIP, Spec.Port)
|
||||
|
||||
// 配置校验 服务名称地址及监听地址不能为空
|
||||
conf.NotNil(Spec.Service, Spec.Cache)
|
||||
|
||||
// 初始化加密SecretKey
|
||||
encipher.New(env.Runtime.JwtSecretKey)
|
||||
|
||||
conf.PrintInfo(Spec.Addr)
|
||||
}
|
||||
12
apps/ec/market/internal/impl/impl.go
Normal file
12
apps/ec/market/internal/impl/impl.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package impl
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
)
|
||||
|
||||
func NewImpl() {
|
||||
// with activating
|
||||
withRedisCache(vars.ServiceKey) // redis cache
|
||||
withDatabases() // model
|
||||
withEtcd() // etcd
|
||||
}
|
||||
84
apps/ec/market/internal/impl/with.go
Normal file
84
apps/ec/market/internal/impl/with.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package impl
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-ec/market/internal/config"
|
||||
"git.apinb.com/bsm-ec/market/internal/models"
|
||||
"git.apinb.com/bsm-sdk/core/cache/redis"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
"go.etcd.io/etcd/client/pkg/v3/transport"
|
||||
clientv3 "go.etcd.io/etcd/client/v3"
|
||||
)
|
||||
|
||||
var (
|
||||
RedisCache *redis.RedisClient
|
||||
Etcd *clientv3.Client
|
||||
)
|
||||
|
||||
func withRedisCache(srvKey string) {
|
||||
if config.Spec.Cache != "" {
|
||||
RedisCache = redis.New(config.Spec.Cache, srvKey)
|
||||
}
|
||||
|
||||
// print inform.
|
||||
printer.Info("[BSM - %s] Cache: %s, DBIndex: %d", vars.ServiceKey, config.Spec.Cache, RedisCache.DB)
|
||||
}
|
||||
|
||||
func withDatabases() {
|
||||
if config.Spec.Databases == nil || len(config.Spec.Databases.Source) == 0 {
|
||||
panic("No Database Source Found !")
|
||||
}
|
||||
|
||||
// print inform.
|
||||
printer.Info("[BSM - %s] Databases: %v", vars.ServiceKey, config.Spec.Databases)
|
||||
|
||||
err := models.New(config.Spec.Databases.Driver, config.Spec.Databases.Source, nil)
|
||||
if err != nil {
|
||||
printer.Error("Database Init Failed !")
|
||||
panic(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func withEtcd() {
|
||||
if config.Spec.Etcd != nil {
|
||||
if len(config.Spec.Etcd.Endpoints) == 0 {
|
||||
panic(errcode.ErrNotFound(0, "Etcd Endpoints"))
|
||||
}
|
||||
cfg := clientv3.Config{
|
||||
Endpoints: config.Spec.Etcd.Endpoints,
|
||||
DialTimeout: 5 * time.Second,
|
||||
}
|
||||
if config.Spec.Etcd.Passwd != nil {
|
||||
cfg.Username = config.Spec.Etcd.Passwd.Account
|
||||
cfg.Password = config.Spec.Etcd.Passwd.Password
|
||||
}
|
||||
if config.Spec.Etcd.TLS != nil {
|
||||
tlsInfo := transport.TLSInfo{
|
||||
TrustedCAFile: config.Spec.Etcd.TLS.CaFile,
|
||||
CertFile: config.Spec.Etcd.TLS.CertFile,
|
||||
KeyFile: config.Spec.Etcd.TLS.KeyFile,
|
||||
}
|
||||
tlsConfig, err := tlsInfo.ClientConfig()
|
||||
if err != nil {
|
||||
printer.Error(errcode.ErrEtcd.Error())
|
||||
panic(err)
|
||||
}
|
||||
cfg.TLS = tlsConfig
|
||||
}
|
||||
etcd, err := clientv3.New(cfg)
|
||||
|
||||
if err != nil {
|
||||
printer.Error(errcode.ErrEtcd.Error())
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Etcd = etcd
|
||||
|
||||
// print inform.
|
||||
printer.Info("[BSM - %s] Service Center: %v", vars.ServiceKey, config.Spec.Etcd.Endpoints)
|
||||
}
|
||||
}
|
||||
44
apps/ec/market/internal/logic/agency/approve.go
Normal file
44
apps/ec/market/internal/logic/agency/approve.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package agency
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"git.apinb.com/bsm-ec/market/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/market/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
)
|
||||
|
||||
// 审核
|
||||
func Approve(ctx context.Context, in *pb.ApproveRequest) (reply *pb.StatusReply, err error) {
|
||||
var data *models.MarketAgency
|
||||
if in.GetIdentity() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
if err := models.DBService.Where("identity = ?", in.GetIdentity()).First(&data).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if data.Status != 1 {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
switch in.GetApprove() {
|
||||
case 1:
|
||||
if err := models.DBService.Model(&data).Update("approve", 2).Error; err != nil {
|
||||
log.Println("更新代理商数据失败:", err)
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
case 2:
|
||||
if err := models.DBService.Model(&data).Update("approve", -2).Error; err != nil {
|
||||
log.Println("更新代理商数据失败:", err)
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Identity: data.Identity,
|
||||
}, nil
|
||||
|
||||
}
|
||||
59
apps/ec/market/internal/logic/agency/create.go
Normal file
59
apps/ec/market/internal/logic/agency/create.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package agency
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-ec/market/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/market/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
)
|
||||
|
||||
// 新增代理商
|
||||
func Create(ctx context.Context, in *pb.MarketAgenctyItem) (reply *pb.StatusReply, err error) {
|
||||
// _, err = service.ParseMetaCtx(ctx, nil)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
if in.GetName() == "" || in.GetAccount() == "" || in.GetPassword() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
salt := utils.RandomString(8)
|
||||
mktModel := &models.MarketAgency{
|
||||
Std_IICUDS: types.Std_IICUDS{Identity: utils.ULID(), Status: 1},
|
||||
Name: in.GetName(),
|
||||
Avatar: in.GetAvatar(),
|
||||
Account: in.GetAccount(),
|
||||
Phone: in.GetPhone(),
|
||||
Password: utils.Md5(in.Password + salt),
|
||||
Salt: salt,
|
||||
OrgName: in.GetOrgName(),
|
||||
OrgPhoto: in.GetOrgPhoto(),
|
||||
IDName: in.GetIdName(),
|
||||
IDBefore: in.GetIdBefore(),
|
||||
IDAfter: in.GetIdAfter(),
|
||||
Remark: in.GetRemark(),
|
||||
CommissionRate: in.GetCommissionRate(),
|
||||
AgencyType: in.GetAgencyType(),
|
||||
Email: in.GetEmail(),
|
||||
Country: in.GetCountry(),
|
||||
Area: in.GetArea(),
|
||||
}
|
||||
fmt.Println("mktModel = ", mktModel)
|
||||
if err := models.DBService.Create(&mktModel).Error; err != nil {
|
||||
fmt.Println("err = ", err)
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Identity: mktModel.Identity,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
36
apps/ec/market/internal/logic/agency/delete.go
Normal file
36
apps/ec/market/internal/logic/agency/delete.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package agency
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-ec/market/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/market/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
)
|
||||
|
||||
// 删除一个代理商
|
||||
func Delete(ctx context.Context, in *pb.IdentRequest) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
// _, err = service.ParseMetaCtx(ctx, nil)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
if in.Id == 0 && in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
if err := models.DBService.Where("id = ? or identity = ?", in.GetId(), in.GetIdentity()).Delete(&models.MarketAgency{}).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Identity: in.GetIdentity(),
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
50
apps/ec/market/internal/logic/agency/fetch.go
Normal file
50
apps/ec/market/internal/logic/agency/fetch.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package agency
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.apinb.com/bsm-ec/market/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/market/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 代理商列表
|
||||
func Fetch(ctx context.Context, in *pb.FetchRequest) (reply *pb.AgencyReply, err error) {
|
||||
var (
|
||||
cnt int64 = 0
|
||||
Offset int64 = (in.GetPageNo() - 1) * in.GetPageSize()
|
||||
data = make([]*models.MarketAgency, 0)
|
||||
)
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.GetPageNo() < 1 {
|
||||
in.PageNo = 1
|
||||
}
|
||||
if in.GetPageSize() < 10 {
|
||||
in.PageSize = 50
|
||||
}
|
||||
tx := models.DBService.Model(&models.MarketAgency{})
|
||||
if in.GetIdentity() != "" {
|
||||
tx.Where("identity = ?", in.GetIdentity())
|
||||
}
|
||||
if in.GetApprove() != 0 {
|
||||
tx = tx.Where("approve = ?", in.GetApprove())
|
||||
}
|
||||
if in.GetStatus() != 0 {
|
||||
tx = tx.Where("status = ?", in.GetStatus())
|
||||
}
|
||||
if err := tx.Order("created_at desc").Count(&cnt).Limit(int(in.GetPageSize())).Offset(int(Offset)).Find(&data).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.AgencyReply{
|
||||
Data: ref(data),
|
||||
Count: int64(len(data)),
|
||||
}, nil
|
||||
}
|
||||
53
apps/ec/market/internal/logic/agency/get.go
Normal file
53
apps/ec/market/internal/logic/agency/get.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package agency
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-ec/market/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/market/pb"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 获取一个代理商
|
||||
func Get(ctx context.Context, in *pb.IdentRequest) (reply *pb.MarketAgenctyItem, err error) {
|
||||
var (
|
||||
identity string
|
||||
)
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
identity = auth.Identity
|
||||
if in.GetIdentity() != "" {
|
||||
identity = in.GetIdentity()
|
||||
}
|
||||
mktModel := models.MarketAgency{}
|
||||
if err := models.DBService.Where("identity=?", identity).First(&mktModel).Error; err != nil {
|
||||
log.Println("获取代理商数据失败:", err)
|
||||
return nil, err
|
||||
}
|
||||
reply = &pb.MarketAgenctyItem{
|
||||
Identity: mktModel.Identity,
|
||||
Name: mktModel.Name,
|
||||
Avatar: mktModel.Avatar,
|
||||
Account: mktModel.Account,
|
||||
Phone: mktModel.Phone,
|
||||
OrgName: mktModel.OrgName,
|
||||
OrgPhoto: mktModel.OrgPhoto,
|
||||
IdName: mktModel.IDName,
|
||||
IdBefore: mktModel.IDBefore,
|
||||
IdAfter: mktModel.IDAfter,
|
||||
Remark: mktModel.Remark,
|
||||
Status: int32(mktModel.Status),
|
||||
AgencyType: int32(mktModel.AgencyType),
|
||||
CreatedAt: mktModel.CreatedAt.Format(time.DateTime),
|
||||
Email: mktModel.Email,
|
||||
Country: mktModel.Country,
|
||||
Area: mktModel.Area,
|
||||
Approve: int32(mktModel.Approve),
|
||||
}
|
||||
|
||||
return reply, nil
|
||||
}
|
||||
74
apps/ec/market/internal/logic/agency/login.go
Normal file
74
apps/ec/market/internal/logic/agency/login.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package agency
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-ec/market/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/market/pb"
|
||||
"git.apinb.com/bsm-sdk/core/crypto/encipher"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// 登录
|
||||
func Login(ctx context.Context, in *pb.LoginRequest) (reply *pb.LoginReply, err error) {
|
||||
var marketData models.MarketAgency
|
||||
|
||||
if in.Account == "" || in.Password == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
err = models.DBService.Where("account=? and id<>0", in.Account).First(&marketData).Error
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, errcode.ErrAccountNotFound
|
||||
}
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
// 密码校验
|
||||
if marketData.Password != utils.Md5(in.Password+marketData.Salt) {
|
||||
return nil, errcode.ErrPassword
|
||||
}
|
||||
|
||||
// 账号状态校验
|
||||
if marketData.Status == models.DisabledStatus {
|
||||
return nil, errcode.ErrAccountDisabled
|
||||
}
|
||||
|
||||
// 认证状态校验
|
||||
if marketData.Approve != 2 {
|
||||
return nil, errcode.ErrDisabled
|
||||
}
|
||||
|
||||
market := models.Std_Market{
|
||||
Market_ID: marketData.ID,
|
||||
Market_Identity: marketData.Identity,
|
||||
}
|
||||
|
||||
token, err := encipher.GenerateTokenAes(marketData.ID, marketData.Identity, "", "", market, map[string]string{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 更新登录时间
|
||||
marketData.LastLoginAt = time.Now()
|
||||
err = models.DBService.Debug().Where("id = ?", marketData.ID).Select("last_login_at").Updates(marketData).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.LoginReply{
|
||||
Token: token,
|
||||
Identity: marketData.Identity,
|
||||
Name: marketData.Name,
|
||||
Account: marketData.Account,
|
||||
MarketName: marketData.OrgName,
|
||||
MarketIdentity: marketData.Identity,
|
||||
Status: int32(marketData.Status),
|
||||
CreatedAt: marketData.CreatedAt.Format(time.DateTime),
|
||||
}, nil
|
||||
|
||||
}
|
||||
55
apps/ec/market/internal/logic/agency/modify.go
Normal file
55
apps/ec/market/internal/logic/agency/modify.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package agency
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-ec/market/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/market/pb"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 更新代理商数据
|
||||
func Modify(ctx context.Context, in *pb.MarketAgenctyItem) (reply *pb.StatusReply, err error) {
|
||||
var (
|
||||
identity string
|
||||
)
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
identity = auth.Identity
|
||||
if in.GetIdentity() != "" {
|
||||
identity = in.GetIdentity()
|
||||
}
|
||||
mktModel := &models.MarketAgency{
|
||||
Name: in.GetName(),
|
||||
Avatar: in.GetAvatar(),
|
||||
Account: in.GetAccount(),
|
||||
Phone: in.GetPhone(),
|
||||
OrgName: in.GetOrgName(),
|
||||
OrgPhoto: in.GetOrgPhoto(),
|
||||
IDName: in.GetIdName(),
|
||||
IDBefore: in.GetIdBefore(),
|
||||
IDAfter: in.GetIdAfter(),
|
||||
Remark: in.GetRemark(),
|
||||
CommissionRate: in.GetCommissionRate(),
|
||||
AgencyType: in.GetAgencyType(),
|
||||
Email: in.GetEmail(),
|
||||
Country: in.GetCountry(),
|
||||
Area: in.GetArea(),
|
||||
}
|
||||
if err := models.DBService.Where("identity=?", identity).Updates(&mktModel).Error; err != nil {
|
||||
log.Println("更新代理商数据失败:", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Identity: mktModel.Identity,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
45
apps/ec/market/internal/logic/agency/pending.go
Normal file
45
apps/ec/market/internal/logic/agency/pending.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package agency
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.apinb.com/bsm-ec/market/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/market/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 待审核
|
||||
func Pending(ctx context.Context, in *pb.FetchRequest) (reply *pb.AgencyReply, err error) {
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var (
|
||||
cnt int64 = 0
|
||||
Offset int64 = (in.GetPageNo() - 1) * in.GetPageSize()
|
||||
data = make([]*models.MarketAgency, 0)
|
||||
)
|
||||
|
||||
if in.GetPageNo() < 1 {
|
||||
in.PageNo = 1
|
||||
}
|
||||
if in.GetPageSize() < 0 {
|
||||
in.PageSize = 50
|
||||
}
|
||||
tx := models.DBService.Model(&models.MarketAgency{}).Where("approve = 0").Order("created_at desc")
|
||||
if in.GetIdentity() != "" {
|
||||
tx.Where("identity = ?", in.GetIdentity())
|
||||
}
|
||||
if err := tx.Count(&cnt).Limit(int(in.GetPageSize())).Offset(int(Offset)).Find(&data).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.AgencyReply{
|
||||
Data: ref(data),
|
||||
Count: int64(len(data)),
|
||||
}, nil
|
||||
}
|
||||
40
apps/ec/market/internal/logic/agency/ref.go
Normal file
40
apps/ec/market/internal/logic/agency/ref.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package agency
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-ec/market/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/market/pb"
|
||||
)
|
||||
|
||||
func ref(data []*models.MarketAgency) (list []*pb.MarketAgenctyItem) {
|
||||
if len(data) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
for _, in := range data {
|
||||
row := pb.MarketAgenctyItem{
|
||||
Identity: in.Identity,
|
||||
Name: in.Name,
|
||||
Avatar: in.Avatar,
|
||||
Account: in.Account,
|
||||
Phone: in.Phone,
|
||||
OrgName: in.OrgName,
|
||||
OrgPhoto: in.OrgPhoto,
|
||||
IdName: in.IDName,
|
||||
IdBefore: in.IDBefore,
|
||||
IdAfter: in.IDAfter,
|
||||
Remark: in.Remark,
|
||||
CommissionRate: in.CommissionRate,
|
||||
Status: int32(in.Status),
|
||||
CreatedAt: in.CreatedAt.Format(time.DateTime),
|
||||
AgencyType: int32(in.AgencyType),
|
||||
Email: in.Email,
|
||||
Country: in.Country,
|
||||
Area: in.Area,
|
||||
}
|
||||
|
||||
list = append(list, &row)
|
||||
}
|
||||
return
|
||||
}
|
||||
60
apps/ec/market/internal/logic/agency/set_password.go
Normal file
60
apps/ec/market/internal/logic/agency/set_password.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package agency
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-ec/market/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/market/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
)
|
||||
|
||||
// 更新密码
|
||||
func SetPassword(ctx context.Context, in *pb.SetPasswordRequest) (reply *pb.StatusReply, err error) {
|
||||
var (
|
||||
identity string
|
||||
)
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
identity = auth.Identity
|
||||
fmt.Println("identity:", auth.Identity)
|
||||
if in.GetIdentity() != "" {
|
||||
identity = in.GetIdentity()
|
||||
}
|
||||
if in.GetOldPassword() == "" || in.GetNewPassword() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
// 获取当前角色数据
|
||||
mktModel := models.MarketAgency{}
|
||||
if err := models.DBService.Where("identity = ?", identity).First(&mktModel).Error; err != nil {
|
||||
log.Println("获取代理商数据失败:", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 判断旧密码是否匹配
|
||||
if utils.Md5(in.GetOldPassword()+mktModel.Salt) != mktModel.Password {
|
||||
return nil, errors.New("旧密码错误")
|
||||
}
|
||||
|
||||
// 设置新密码
|
||||
newPwd := utils.Md5(in.GetNewPassword() + mktModel.Salt)
|
||||
if err := models.DBService.Model(&mktModel).Update("password", newPwd).Error; err != nil {
|
||||
log.Println("更新密码失败:", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Identity: identity,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
26
apps/ec/market/internal/logic/data/member_details.go
Normal file
26
apps/ec/market/internal/logic/data/member_details.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"context"
|
||||
pb "git.apinb.com/bsm-ec/market/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 会员详情
|
||||
func MemberDetails(ctx context.Context, in *pb.IdentRequest) (reply *pb.KeyVal, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// valildate request id,identity.
|
||||
if in.Id == 0 && in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
}
|
||||
28
apps/ec/market/internal/logic/data/member_fetch.go
Normal file
28
apps/ec/market/internal/logic/data/member_fetch.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"context"
|
||||
pb "git.apinb.com/bsm-ec/market/pb"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 会员列表
|
||||
func MemberFetch(ctx context.Context, in *pb.FetchRequest) (reply *pb.DataReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// valildate request page_no,page_size.
|
||||
if in.GetPageNo() < 1 {
|
||||
in.PageNo = 1
|
||||
}
|
||||
if in.GetPageSize() < 10 {
|
||||
in.PageSize = 50
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
}
|
||||
26
apps/ec/market/internal/logic/data/order_details.go
Normal file
26
apps/ec/market/internal/logic/data/order_details.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"context"
|
||||
pb "git.apinb.com/bsm-ec/market/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 订单详情
|
||||
func OrderDetails(ctx context.Context, in *pb.IdentRequest) (reply *pb.KeyVal, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// valildate request id,identity.
|
||||
if in.Id == 0 && in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
}
|
||||
28
apps/ec/market/internal/logic/data/order_fetch.go
Normal file
28
apps/ec/market/internal/logic/data/order_fetch.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"context"
|
||||
pb "git.apinb.com/bsm-ec/market/pb"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 订单列表
|
||||
func OrderFetch(ctx context.Context, in *pb.FetchRequest) (reply *pb.DataReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// valildate request page_no,page_size.
|
||||
if in.GetPageNo() < 1 {
|
||||
in.PageNo = 1
|
||||
}
|
||||
if in.GetPageSize() < 10 {
|
||||
in.PageSize = 50
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
}
|
||||
22
apps/ec/market/internal/logic/data/overview.go
Normal file
22
apps/ec/market/internal/logic/data/overview.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"context"
|
||||
pb "git.apinb.com/bsm-ec/market/pb"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 概况
|
||||
func Overview(ctx context.Context, in *pb.Empty) (reply *pb.OverviewReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: valid code
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
}
|
||||
48
apps/ec/market/internal/logic/supply/create.go
Normal file
48
apps/ec/market/internal/logic/supply/create.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package supply
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-ec/market/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/market/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
)
|
||||
|
||||
// 新增供应商
|
||||
func Create(ctx context.Context, in *pb.MarketSupplyItem) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
// _, err = service.ParseMetaCtx(ctx, nil)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
if in.GetName() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
salt := utils.RandomString(8)
|
||||
mktModel := &models.MarketSupply{
|
||||
Std_IICUDS: types.Std_IICUDS{Identity: utils.ULID(), Status: 1},
|
||||
Name: in.GetName(),
|
||||
// Avatar: in.GetAvatar(),
|
||||
Account: in.GetAccount(),
|
||||
Phone: in.GetPhone(),
|
||||
Password: utils.Md5(in.Password + salt),
|
||||
Salt: salt,
|
||||
OrgName: in.GetOrgName(),
|
||||
Remark: in.GetRemark(),
|
||||
CommissionRate: in.GetCommissionRate(),
|
||||
}
|
||||
if err := models.DBService.Create(&mktModel).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Identity: mktModel.Identity,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
38
apps/ec/market/internal/logic/supply/delete.go
Normal file
38
apps/ec/market/internal/logic/supply/delete.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package supply
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-ec/market/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/market/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 删除一个供应商
|
||||
func Delete(ctx context.Context, in *pb.IdentRequest) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// valildate request id,identity.
|
||||
if in.Id == 0 && in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
if err := models.DBService.Where("id = ? or identity = ?", in.GetId(), in.GetIdentity()).Delete(&models.MarketSupply{}).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixNano(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
43
apps/ec/market/internal/logic/supply/fetch.go
Normal file
43
apps/ec/market/internal/logic/supply/fetch.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package supply
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.apinb.com/bsm-ec/market/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/market/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 供应商列表
|
||||
func Fetch(ctx context.Context, in *pb.FetchRequest) (reply *pb.SupplyReply, err error) {
|
||||
var (
|
||||
cnt int64 = 0
|
||||
Offset int64 = (in.GetPageNo() - 1) * in.GetPageSize()
|
||||
data = make([]*models.MarketSupply, 0)
|
||||
)
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.GetPageNo() < 1 {
|
||||
in.PageNo = 1
|
||||
}
|
||||
if in.GetPageSize() < 10 {
|
||||
in.PageSize = 50
|
||||
}
|
||||
tx := models.DBService.Model(&models.MarketSupply{}).Where("status = ?", 1)
|
||||
if in.GetIdentity() != "" {
|
||||
tx.Where("identity = ?", in.GetIdentity())
|
||||
}
|
||||
if err := tx.Order("created_at desc").Count(&cnt).Limit(int(in.GetPageSize())).Offset(int(Offset)).Find(&data).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
return &pb.SupplyReply{
|
||||
Data: ref(data),
|
||||
Count: int64(len(data)),
|
||||
}, nil
|
||||
}
|
||||
40
apps/ec/market/internal/logic/supply/get.go
Normal file
40
apps/ec/market/internal/logic/supply/get.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package supply
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"git.apinb.com/bsm-ec/market/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/market/pb"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 获取一个供应商
|
||||
func Get(ctx context.Context, in *pb.IdentRequest) (reply *pb.MarketSupplyItem, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mktModel := models.MarketSupply{}
|
||||
if err := models.DBService.Where("identity=?", in.GetIdentity()).First(&mktModel).Error; err != nil {
|
||||
log.Println("获取供应商数据失败:", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.MarketSupplyItem{
|
||||
Id: int32(mktModel.ID),
|
||||
Identity: mktModel.Identity,
|
||||
Name: mktModel.Name,
|
||||
Avatar: mktModel.Avatar,
|
||||
Account: mktModel.Account,
|
||||
Phone: mktModel.Phone,
|
||||
OrgName: mktModel.OrgName,
|
||||
OrgPhoto: mktModel.OrgPhoto,
|
||||
IdName: mktModel.IDName,
|
||||
IdBefore: mktModel.IDBefore,
|
||||
IdAfter: mktModel.IDAfter,
|
||||
Remark: mktModel.Remark,
|
||||
}, nil
|
||||
}
|
||||
48
apps/ec/market/internal/logic/supply/modify.go
Normal file
48
apps/ec/market/internal/logic/supply/modify.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package supply
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-ec/market/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/market/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 更新供应商数据
|
||||
func Modify(ctx context.Context, in *pb.MarketSupplyItem) (reply *pb.StatusReply, err error) {
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.GetIdentity() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
mktModel := &models.MarketSupply{
|
||||
Name: in.GetName(),
|
||||
Avatar: in.GetAvatar(),
|
||||
Account: in.GetAccount(),
|
||||
Phone: in.GetPhone(),
|
||||
OrgName: in.GetOrgName(),
|
||||
OrgPhoto: in.GetOrgPhoto(),
|
||||
IDName: in.GetIdName(),
|
||||
IDBefore: in.GetIdBefore(),
|
||||
IDAfter: in.GetIdAfter(),
|
||||
Remark: in.GetRemark(),
|
||||
CommissionRate: in.GetCommissionRate(),
|
||||
}
|
||||
if err := models.DBService.Where("identity=?", in.GetIdentity()).Updates(&mktModel).Error; err != nil {
|
||||
log.Println("更新供应商数据失败:", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Identity: mktModel.Identity,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
34
apps/ec/market/internal/logic/supply/ref.go
Normal file
34
apps/ec/market/internal/logic/supply/ref.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package supply
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-ec/market/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/market/pb"
|
||||
)
|
||||
|
||||
func ref(data []*models.MarketSupply) (list []*pb.MarketSupplyItem) {
|
||||
if len(data) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
for _, in := range data {
|
||||
row := pb.MarketSupplyItem{
|
||||
Id: int32(in.ID),
|
||||
Identity: in.Identity,
|
||||
Name: in.Name,
|
||||
Avatar: in.Avatar,
|
||||
Account: in.Account,
|
||||
Phone: in.Phone,
|
||||
OrgName: in.OrgName,
|
||||
OrgPhoto: in.OrgPhoto,
|
||||
IdName: in.IDName,
|
||||
IdBefore: in.IDBefore,
|
||||
IdAfter: in.IDAfter,
|
||||
Remark: in.Remark,
|
||||
CommissionRate: in.CommissionRate,
|
||||
Status: int32(in.Status),
|
||||
}
|
||||
|
||||
list = append(list, &row)
|
||||
}
|
||||
return
|
||||
}
|
||||
86
apps/ec/market/internal/models/impl.go
Normal file
86
apps/ec/market/internal/models/impl.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/database/sql"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var DBService *gorm.DB
|
||||
|
||||
var migrateTables = []any{
|
||||
&MarketAgency{},
|
||||
&MarketSupply{},
|
||||
}
|
||||
|
||||
func New(driver string, dsn []string, options *types.SqlOptions) (err error) {
|
||||
driver = strings.ToLower(driver)
|
||||
|
||||
switch driver {
|
||||
case "mysql":
|
||||
DBService, err = NewMysql(dsn, options)
|
||||
case "postgres":
|
||||
DBService, err = NewPostgres(dsn, options)
|
||||
default:
|
||||
log.Fatalln("Unsupported database driver:", driver)
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
return err
|
||||
}
|
||||
|
||||
// auto migrate table.
|
||||
err = DBService.AutoMigrate(migrateTables...)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func NewMysql(dsn []string, options *types.SqlOptions) (gormDb *gorm.DB, err error) {
|
||||
//set connection default val.
|
||||
options = sql.SetOptions(options)
|
||||
|
||||
gormDb, err = gorm.Open(mysql.Open(dsn[0]), &gorm.Config{
|
||||
SkipDefaultTransaction: true,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if options.Debug {
|
||||
gormDb = gormDb.Debug()
|
||||
}
|
||||
|
||||
// 获取通用数据库对象 sql.DB ,然后使用其提供的功能
|
||||
sqlDB, _ := gormDb.DB()
|
||||
// SetMaxIdleConns 用于设置连接池中空闲连接的最大数量。
|
||||
sqlDB.SetMaxIdleConns(options.MaxIdleConns)
|
||||
// SetMaxOpenConns 设置打开数据库连接的最大数量。
|
||||
sqlDB.SetMaxOpenConns(options.MaxOpenConns)
|
||||
// SetConnMaxLifetime 设置了连接可复用的最大时间。
|
||||
sqlDB.SetConnMaxLifetime(options.ConnMaxLifetime)
|
||||
|
||||
return gormDb, nil
|
||||
}
|
||||
|
||||
func NewPostgres(dsn []string, options *types.SqlOptions) (gormDb *gorm.DB, err error) {
|
||||
//set connection default val.
|
||||
options = sql.SetOptions(options)
|
||||
|
||||
db, err := sql.NewPostgreSql(dsn[0], options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
db = db.Debug()
|
||||
|
||||
return db, nil
|
||||
}
|
||||
37
apps/ec/market/internal/models/market_agency.go
Normal file
37
apps/ec/market/internal/models/market_agency.go
Normal file
@@ -0,0 +1,37 @@
|
||||
// Models generated by mesh dev cli,@Author: David Yan(david.yan@qq.com).
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
)
|
||||
|
||||
// 省代公司
|
||||
type MarketAgency struct {
|
||||
types.Std_IICUDS
|
||||
Name string `gorm:"type:varchar(255);not null;"` // 名称
|
||||
Avatar string `gorm:"column:avatar;type:varchar(255);default:'';" json:"avatar"` // 头像
|
||||
Account string `gorm:"column:account;type:varchar(255);default:'';" json:"account"` // 帐号
|
||||
Phone string `gorm:"column:phone;type:varchar(20);not null;" json:"phone"` // 手机号
|
||||
Password string `gorm:"column:password;type:varchar(255);" json:"password"` // 密码
|
||||
Salt string `gorm:"type:varchar(255);default:'';"` // 密码盐值
|
||||
Email string `gorm:"column:email;type:varchar(255);default:'';" json:"email"` // 邮箱
|
||||
Country string `gorm:"column:country;type:varchar(255);default:'';" json:"country"` // 国家
|
||||
Area string `gorm:"column:area;type:varchar(255);default:'';" json:"area"` // 地区
|
||||
OrgName string `gorm:"column:org_name;type:varchar(255);default:'';" json:"org_name"` // 机构名称
|
||||
OrgPhoto string `gorm:"column:org_photo;type:varchar(255);default:'';" json:"org_photo"` // 机构照片
|
||||
IDName string `gorm:"column:id_name;type:varchar(255);default:'';" json:"id_name"` // 证件姓名
|
||||
IDBefore string `gorm:"column:id_before;type:varchar(255);default:'';" json:"id_before"` // 证件照片
|
||||
IDAfter string `gorm:"column:id_after;type:varchar(255);default:'';" json:"id_after"` // 证件照片
|
||||
Remark string `gorm:"type:varchar(255);default:'';"` // 备注
|
||||
CommissionRate int32 `gorm:"column:commission_rate;default:0;" json:"commission_rate"` // 佣金比例
|
||||
AgencyType int32 `gorm:"column:agency_type;default:0;" json:"agency_type"` // 服务 状态:1:代理商 2:安装商
|
||||
Approve int8 `gorm:"column:approve;default:0;" json:"approve"` // 状态:-2,认证未通过,0为未认证,2为认证成功
|
||||
LastLoginAt time.Time
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (table *MarketAgency) TableName() string {
|
||||
return "market_agency" //对应数据库表名
|
||||
}
|
||||
32
apps/ec/market/internal/models/market_supply.go
Normal file
32
apps/ec/market/internal/models/market_supply.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
)
|
||||
|
||||
// 供应商
|
||||
type MarketSupply struct {
|
||||
types.Std_IICUDS
|
||||
Name string `gorm:"type:varchar(255);not null;"` // 名称
|
||||
Avatar string `gorm:"column:avatar;type:varchar(255);default:'';" json:"avatar"` // 头像
|
||||
Account string `gorm:"column:account;type:varchar(255);default:'';" json:"account"` // 帐号
|
||||
Phone string `gorm:"column:phone;type:varchar(20);not null;" json:"phone"` // 手机号
|
||||
Password string `gorm:"column:password;type:varchar(255);not null;" json:"password"` // 密码
|
||||
Salt string `gorm:"type:varchar(255);default:'';"` // 密码盐值
|
||||
OrgName string `gorm:"column:org_name;type:varchar(255);default:'';" json:"org_name"` // 机构名称
|
||||
OrgPhoto string `gorm:"column:org_photo;type:varchar(255);default:'';" json:"org_photo"` // 机构照片
|
||||
IDName string `gorm:"column:id_name;type:varchar(255);default:'';" json:"id_name"` // 证件姓名
|
||||
IDBefore string `gorm:"column:id_before;type:varchar(255);default:'';" json:"id_before"` // 证件照片
|
||||
IDAfter string `gorm:"column:id_after;type:varchar(255);default:'';" json:"id_after"` // 证件照片
|
||||
Remark string `gorm:"type:varchar(255);default:'';"` // 备注
|
||||
CommissionRate int32 `gorm:"column:commission_rate;default:0;" json:"commission_rate"` // 佣金比例
|
||||
Approve int8 `gorm:"column:approve;default:0;" json:"approve"` // 状态:-2,认证未通过,0为未认证,1为审核中,2为认证成功
|
||||
LastLoginAt time.Time
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (table *MarketSupply) TableName() string {
|
||||
return "market_supply" //对应数据库表名
|
||||
}
|
||||
13
apps/ec/market/internal/models/query.go
Normal file
13
apps/ec/market/internal/models/query.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package models
|
||||
|
||||
const (
|
||||
// NormalStatus .
|
||||
NormalStatus = 1
|
||||
// DisabledStatus .
|
||||
DisabledStatus = -1
|
||||
)
|
||||
|
||||
type Std_Market struct {
|
||||
Market_ID uint `gorm:"primarykey;" json:"market_id"` // 代理商ID
|
||||
Market_Identity string `gorm:"column:market_identity;type:varchar(36);index;" json:"market_identity"` // 代理商唯一标识,24位NanoID,36位为ULID
|
||||
}
|
||||
61
apps/ec/market/internal/server/agency_server.go
Normal file
61
apps/ec/market/internal/server/agency_server.go
Normal file
@@ -0,0 +1,61 @@
|
||||
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.apinb.com/bsm-ec/market/internal/logic/agency"
|
||||
pb "git.apinb.com/bsm-ec/market/pb"
|
||||
)
|
||||
|
||||
type AgencyServer struct {
|
||||
pb.UnimplementedAgencyServer
|
||||
}
|
||||
|
||||
func NewAgencyServer() *AgencyServer {
|
||||
return &AgencyServer{}
|
||||
}
|
||||
|
||||
// 登录
|
||||
func (s *AgencyServer) Login(ctx context.Context, in *pb.LoginRequest) (*pb.LoginReply, error) {
|
||||
return agency.Login(ctx, in)
|
||||
}
|
||||
|
||||
// 新增代理商
|
||||
func (s *AgencyServer) Create(ctx context.Context, in *pb.MarketAgenctyItem) (*pb.StatusReply, error) {
|
||||
return agency.Create(ctx, in)
|
||||
}
|
||||
|
||||
// 获取一个代理商
|
||||
func (s *AgencyServer) Get(ctx context.Context, in *pb.IdentRequest) (*pb.MarketAgenctyItem, error) {
|
||||
return agency.Get(ctx, in)
|
||||
}
|
||||
|
||||
// 代理商列表
|
||||
func (s *AgencyServer) Fetch(ctx context.Context, in *pb.FetchRequest) (*pb.AgencyReply, error) {
|
||||
return agency.Fetch(ctx, in)
|
||||
}
|
||||
|
||||
// 更新代理商数据
|
||||
func (s *AgencyServer) Modify(ctx context.Context, in *pb.MarketAgenctyItem) (*pb.StatusReply, error) {
|
||||
return agency.Modify(ctx, in)
|
||||
}
|
||||
|
||||
// 删除一个代理商
|
||||
func (s *AgencyServer) Delete(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
|
||||
return agency.Delete(ctx, in)
|
||||
}
|
||||
|
||||
// 更新密码
|
||||
func (s *AgencyServer) SetPassword(ctx context.Context, in *pb.SetPasswordRequest) (*pb.StatusReply, error) {
|
||||
return agency.SetPassword(ctx, in)
|
||||
}
|
||||
|
||||
// 待审核
|
||||
func (s *AgencyServer) Pending(ctx context.Context, in *pb.FetchRequest) (*pb.AgencyReply, error) {
|
||||
return agency.Pending(ctx, in)
|
||||
}
|
||||
|
||||
// 审核
|
||||
func (s *AgencyServer) Approve(ctx context.Context, in *pb.ApproveRequest) (*pb.StatusReply, error) {
|
||||
return agency.Approve(ctx, in)
|
||||
}
|
||||
41
apps/ec/market/internal/server/data_server.go
Normal file
41
apps/ec/market/internal/server/data_server.go
Normal file
@@ -0,0 +1,41 @@
|
||||
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.apinb.com/bsm-ec/market/internal/logic/data"
|
||||
pb "git.apinb.com/bsm-ec/market/pb"
|
||||
)
|
||||
|
||||
type DataServer struct {
|
||||
pb.UnimplementedDataServer
|
||||
}
|
||||
|
||||
func NewDataServer() *DataServer {
|
||||
return &DataServer{}
|
||||
}
|
||||
|
||||
// 概况
|
||||
func (s *DataServer) Overview(ctx context.Context, in *pb.Empty) (*pb.OverviewReply, error) {
|
||||
return data.Overview(ctx, in)
|
||||
}
|
||||
|
||||
// 会员列表
|
||||
func (s *DataServer) MemberFetch(ctx context.Context, in *pb.FetchRequest) (*pb.DataReply, error) {
|
||||
return data.MemberFetch(ctx, in)
|
||||
}
|
||||
|
||||
// 会员详情
|
||||
func (s *DataServer) MemberDetails(ctx context.Context, in *pb.IdentRequest) (*pb.KeyVal, error) {
|
||||
return data.MemberDetails(ctx, in)
|
||||
}
|
||||
|
||||
// 订单列表
|
||||
func (s *DataServer) OrderFetch(ctx context.Context, in *pb.FetchRequest) (*pb.DataReply, error) {
|
||||
return data.OrderFetch(ctx, in)
|
||||
}
|
||||
|
||||
// 订单详情
|
||||
func (s *DataServer) OrderDetails(ctx context.Context, in *pb.IdentRequest) (*pb.KeyVal, error) {
|
||||
return data.OrderDetails(ctx, in)
|
||||
}
|
||||
75
apps/ec/market/internal/server/new.go
Normal file
75
apps/ec/market/internal/server/new.go
Normal file
@@ -0,0 +1,75 @@
|
||||
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
pb "git.apinb.com/bsm-ec/market/pb"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
gwRuntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/reflection"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
Grpc *grpc.Server
|
||||
Ctx context.Context
|
||||
Mux *gwRuntime.ServeMux
|
||||
}
|
||||
|
||||
func New(addr string) *Server {
|
||||
srv := &Server{Ctx: context.Background(), Grpc: grpc.NewServer(), Mux: gwRuntime.NewServeMux(
|
||||
gwRuntime.WithForwardResponseRewriter(responseEnvelope),
|
||||
)}
|
||||
|
||||
// register service to grpc.Server
|
||||
pb.RegisterAgencyServer(srv.Grpc, NewAgencyServer())
|
||||
pb.RegisterDataServer(srv.Grpc, NewDataServer())
|
||||
pb.RegisterSupplyServer(srv.Grpc, NewSupplyServer())
|
||||
|
||||
reflection.Register(srv.Grpc)
|
||||
|
||||
// 将服务注册到Gateway
|
||||
opts := []grpc.DialOption{grpc.WithInsecure()}
|
||||
pb.RegisterAgencyHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
|
||||
pb.RegisterDataHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
|
||||
pb.RegisterSupplyHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
|
||||
|
||||
// Register services swagger
|
||||
srv.RegisterSwagger()
|
||||
|
||||
return srv
|
||||
}
|
||||
|
||||
// RegisterSwagger 注册swagger
|
||||
func (s *Server) RegisterSwagger() {
|
||||
srvKey := strings.ToLower(vars.ServiceKey)
|
||||
s.Mux.HandlePath("GET", "/"+srvKey+".swagger.json", func(w http.ResponseWriter, r *http.Request, pathParams map[string]string) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
bytes, err := os.ReadFile("./swagger/" + srvKey + ".swagger.json")
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
w.Write(bytes)
|
||||
return
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
// response envelope
|
||||
func responseEnvelope(_ context.Context, response proto.Message) (interface{}, error) {
|
||||
name := string(response.ProtoReflect().Descriptor().Name())
|
||||
if name == "Status" || name == "Error" || name == "StatusReply" {
|
||||
return response, nil
|
||||
}
|
||||
return map[string]any{
|
||||
"code": 0,
|
||||
"message": "OK",
|
||||
"result": response,
|
||||
}, nil
|
||||
}
|
||||
41
apps/ec/market/internal/server/supply_server.go
Normal file
41
apps/ec/market/internal/server/supply_server.go
Normal file
@@ -0,0 +1,41 @@
|
||||
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.apinb.com/bsm-ec/market/internal/logic/supply"
|
||||
pb "git.apinb.com/bsm-ec/market/pb"
|
||||
)
|
||||
|
||||
type SupplyServer struct {
|
||||
pb.UnimplementedSupplyServer
|
||||
}
|
||||
|
||||
func NewSupplyServer() *SupplyServer {
|
||||
return &SupplyServer{}
|
||||
}
|
||||
|
||||
// 新增供应商
|
||||
func (s *SupplyServer) Create(ctx context.Context, in *pb.MarketSupplyItem) (*pb.StatusReply, error) {
|
||||
return supply.Create(ctx, in)
|
||||
}
|
||||
|
||||
// 获取一个供应商
|
||||
func (s *SupplyServer) Get(ctx context.Context, in *pb.IdentRequest) (*pb.MarketSupplyItem, error) {
|
||||
return supply.Get(ctx, in)
|
||||
}
|
||||
|
||||
// 供应商列表
|
||||
func (s *SupplyServer) Fetch(ctx context.Context, in *pb.FetchRequest) (*pb.SupplyReply, error) {
|
||||
return supply.Fetch(ctx, in)
|
||||
}
|
||||
|
||||
// 更新供应商数据
|
||||
func (s *SupplyServer) Modify(ctx context.Context, in *pb.MarketSupplyItem) (*pb.StatusReply, error) {
|
||||
return supply.Modify(ctx, in)
|
||||
}
|
||||
|
||||
// 删除一个供应商
|
||||
func (s *SupplyServer) Delete(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
|
||||
return supply.Delete(ctx, in)
|
||||
}
|
||||
Reference in New Issue
Block a user