feat: import services and standardize Go 1.26.5
This commit is contained in:
29
apps/ec/mall/internal/logic/store/apply_join.go
Normal file
29
apps/ec/mall/internal/logic/store/apply_join.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 申请加入店铺
|
||||
func ApplyJoin(ctx context.Context, in *pb.ApplyJoinRequest) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: valid code
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
34
apps/ec/mall/internal/logic/store/get_email.go
Normal file
34
apps/ec/mall/internal/logic/store/get_email.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.apinb.com/bsm-ec/mall/internal/impl"
|
||||
"git.apinb.com/bsm-ec/mall/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 获取邮件服务器配置
|
||||
func GetEmail(ctx context.Context, in *pb.IdentRequest) (reply *pb.ConfigsReply, err error) {
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.Id == 0 && in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
sotre := models.MallStore{}
|
||||
if err := impl.DBService.Model(&models.MallStore{}).Select("mail_configs").Where("id=? or identity=?", in.GetId(), in.GetIdentity()).Find(&sotre).Error; err != nil {
|
||||
print(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.ConfigsReply{
|
||||
Configs: sotre.MailConfigs,
|
||||
}, nil
|
||||
|
||||
}
|
||||
33
apps/ec/mall/internal/logic/store/get_payment.go
Normal file
33
apps/ec/mall/internal/logic/store/get_payment.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.apinb.com/bsm-ec/mall/internal/impl"
|
||||
"git.apinb.com/bsm-ec/mall/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 获取支付方式配置
|
||||
func GetPayment(ctx context.Context, in *pb.IdentRequest) (reply *pb.ConfigsReply, 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
|
||||
}
|
||||
|
||||
sotre := models.MallStore{}
|
||||
if err := impl.DBService.Model(&models.MallStore{}).Select("pay_configs").Where("id=? or identity=?", in.GetId(), in.GetIdentity()).Find(&sotre).Error; err != nil {
|
||||
print(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.ConfigsReply{Configs: sotre.PayConfigs}, nil
|
||||
|
||||
}
|
||||
39
apps/ec/mall/internal/logic/store/get_setting.go
Normal file
39
apps/ec/mall/internal/logic/store/get_setting.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-ec/mall/internal/impl"
|
||||
"git.apinb.com/bsm-ec/mall/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
)
|
||||
|
||||
// 获取店铺基础配置
|
||||
func GetSetting(ctx context.Context, in *pb.IdentRequest) (reply *pb.StoreBasic, err error) {
|
||||
// valildate request id,identity.
|
||||
if in.Id == 0 && in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
var data models.MallStore
|
||||
if err := impl.DBService.Where("id=? or identity=?", in.GetId(), in.GetIdentity()).First(&data).Error; err != nil {
|
||||
print(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.StoreBasic{
|
||||
Id: int64(data.ID),
|
||||
Identity: data.Identity,
|
||||
Logo: data.Logo,
|
||||
Title: data.Title,
|
||||
Intro: data.Intro,
|
||||
Template: data.Template,
|
||||
Subdomain: data.Subdomain,
|
||||
Configs: data.Configs,
|
||||
CreatedAt: data.CreatedAt.Format(time.DateTime),
|
||||
Keywords: data.Keywords,
|
||||
Approve: int32(data.Approve),
|
||||
}, nil
|
||||
}
|
||||
49
apps/ec/mall/internal/logic/store/licensing.go
Normal file
49
apps/ec/mall/internal/logic/store/licensing.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-ec/mall/internal/impl"
|
||||
"git.apinb.com/bsm-ec/mall/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
)
|
||||
|
||||
// 店铺许可授权
|
||||
func Licensing(ctx context.Context, in *pb.LicensingRequest) (reply *pb.StatusReply, err error) {
|
||||
var identity string
|
||||
licenseType := strings.ToUpper(in.GetLicenseType())
|
||||
|
||||
switch licenseType {
|
||||
case "DOMAIN":
|
||||
identity, err = LicensingDomain(in.Domain)
|
||||
default:
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
// TODO: valid code
|
||||
if identity == "" {
|
||||
return nil, errcode.ErrNotFound(404, "store not found")
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Identity: identity,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func LicensingDomain(domain string) (string, error) {
|
||||
var store models.MallStore
|
||||
err := impl.DBService.Model(&models.MallStore{}).Where("subdomain=?", domain).First(&store).Error
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return store.Identity, nil
|
||||
}
|
||||
23
apps/ec/mall/internal/logic/store/mini_code.go
Normal file
23
apps/ec/mall/internal/logic/store/mini_code.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 获取小程序推荐码
|
||||
func MiniCode(ctx context.Context, in *pb.MiniCodeRequest) (reply *pb.MiniCodeReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: valid code
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
}
|
||||
73
apps/ec/mall/internal/logic/store/search.go
Normal file
73
apps/ec/mall/internal/logic/store/search.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-ec/mall/internal/impl"
|
||||
"git.apinb.com/bsm-ec/mall/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 店铺搜索
|
||||
func Search(ctx context.Context, in *pb.MallSearchRequest) (reply *pb.MallSearchReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var (
|
||||
cnt int64 = 0
|
||||
pageNo int64 = in.GetPageNo()
|
||||
pageSize int64 = in.GetPageSize()
|
||||
offset int64 = (pageNo - 1) * pageSize
|
||||
)
|
||||
|
||||
if pageNo < 1 {
|
||||
pageNo = 1
|
||||
offset = 0
|
||||
}
|
||||
if pageSize < 50 {
|
||||
pageSize = 50
|
||||
offset = (pageNo - 1) * pageSize
|
||||
}
|
||||
var data []*models.MallStore
|
||||
if err := impl.DBService.Model(&models.MallStore{}).Where("keyword = ?", in.GetKeyword()).Order("created_at desc").Count(&cnt).
|
||||
Offset(int(offset)).Limit(int(pageSize)).Find(&data).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.MallSearchReply{
|
||||
Count: cnt,
|
||||
List: ModelToReply(data),
|
||||
}, nil
|
||||
}
|
||||
func ModelToReply(data []*models.MallStore) (list []*pb.StoreBasic) {
|
||||
if len(data) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
for _, in := range data {
|
||||
row := pb.StoreBasic{
|
||||
Id: int64(in.ID),
|
||||
Identity: in.Identity,
|
||||
Logo: in.Logo,
|
||||
Title: in.Title,
|
||||
Intro: in.Intro,
|
||||
Template: in.Template,
|
||||
Subdomain: in.Subdomain,
|
||||
Configs: in.Configs,
|
||||
CreatedAt: in.CreatedAt.Format(time.DateTime),
|
||||
Approve: int32(in.Approve),
|
||||
Keywords: in.Keywords,
|
||||
}
|
||||
|
||||
list = append(list, &row)
|
||||
}
|
||||
return
|
||||
}
|
||||
37
apps/ec/mall/internal/logic/store/set_email.go
Normal file
37
apps/ec/mall/internal/logic/store/set_email.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-ec/mall/internal/impl"
|
||||
"git.apinb.com/bsm-ec/mall/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 设置邮件服务器配置
|
||||
func SetEmail(ctx context.Context, in *pb.SettingRequest) (reply *pb.StatusReply, err error) {
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.GetIdentity() == "" || in.GetConfigs() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
if err := impl.DBService.Model(&models.MallStore{}).Where("identity = ?", in.GetIdentity()).Update("mail_configs", in.GetConfigs()).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
37
apps/ec/mall/internal/logic/store/set_payment.go
Normal file
37
apps/ec/mall/internal/logic/store/set_payment.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-ec/mall/internal/impl"
|
||||
"git.apinb.com/bsm-ec/mall/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 设置支付方式配置
|
||||
func SetPayment(ctx context.Context, in *pb.SettingRequest) (reply *pb.StatusReply, err error) {
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.GetIdentity() == "" || in.GetConfigs() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
if err := impl.DBService.Model(&models.MallStore{}).Where("identity = ?", in.GetIdentity()).Update("pay_configs", in.GetConfigs()).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
46
apps/ec/mall/internal/logic/store/set_setting.go
Normal file
46
apps/ec/mall/internal/logic/store/set_setting.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-ec/mall/internal/impl"
|
||||
"git.apinb.com/bsm-ec/mall/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 设置店铺基础配置
|
||||
func SetSetting(ctx context.Context, in *pb.StoreBasic) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.Id == 0 && in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
data := &models.MallStore{
|
||||
Logo: in.Logo,
|
||||
Title: in.Title,
|
||||
Intro: in.Intro,
|
||||
Template: in.Template,
|
||||
Subdomain: in.Subdomain,
|
||||
Configs: in.Configs,
|
||||
}
|
||||
|
||||
if err := impl.DBService.Model(&models.MallStore{}).Where("id=? or identity=?", in.GetId(), in.GetIdentity()).Updates(data).Error; err != nil {
|
||||
print(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user