feat: import services and standardize Go 1.26.5
This commit is contained in:
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
|
||||
}
|
||||
Reference in New Issue
Block a user