refactor: reorganize modules and add Linux build tooling
This commit is contained in:
44
module/ec/market/internal/logic/agency/approve.go
Normal file
44
module/ec/market/internal/logic/agency/approve.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package agency
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"bsm/full/module/ec/market/internal/models"
|
||||
pb "bsm/full/module/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
module/ec/market/internal/logic/agency/create.go
Normal file
59
module/ec/market/internal/logic/agency/create.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package agency
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"bsm/full/module/ec/market/internal/models"
|
||||
pb "bsm/full/module/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
module/ec/market/internal/logic/agency/delete.go
Normal file
36
module/ec/market/internal/logic/agency/delete.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package agency
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"bsm/full/module/ec/market/internal/models"
|
||||
pb "bsm/full/module/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
module/ec/market/internal/logic/agency/fetch.go
Normal file
50
module/ec/market/internal/logic/agency/fetch.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package agency
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"bsm/full/module/ec/market/internal/models"
|
||||
pb "bsm/full/module/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
module/ec/market/internal/logic/agency/get.go
Normal file
53
module/ec/market/internal/logic/agency/get.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package agency
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"bsm/full/module/ec/market/internal/models"
|
||||
pb "bsm/full/module/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
module/ec/market/internal/logic/agency/login.go
Normal file
74
module/ec/market/internal/logic/agency/login.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package agency
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"bsm/full/module/ec/market/internal/models"
|
||||
pb "bsm/full/module/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
module/ec/market/internal/logic/agency/modify.go
Normal file
55
module/ec/market/internal/logic/agency/modify.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package agency
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"bsm/full/module/ec/market/internal/models"
|
||||
pb "bsm/full/module/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
module/ec/market/internal/logic/agency/pending.go
Normal file
45
module/ec/market/internal/logic/agency/pending.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package agency
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"bsm/full/module/ec/market/internal/models"
|
||||
pb "bsm/full/module/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
module/ec/market/internal/logic/agency/ref.go
Normal file
40
module/ec/market/internal/logic/agency/ref.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package agency
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"bsm/full/module/ec/market/internal/models"
|
||||
pb "bsm/full/module/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
module/ec/market/internal/logic/agency/set_password.go
Normal file
60
module/ec/market/internal/logic/agency/set_password.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package agency
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"bsm/full/module/ec/market/internal/models"
|
||||
pb "bsm/full/module/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
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user