实现商户注册、管理员审核商户申请接口
This commit is contained in:
83
internal/logic/merchant/merchant.go
Normal file
83
internal/logic/merchant/merchant.go
Normal file
@ -0,0 +1,83 @@
|
||||
package merchant
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"server/internal/consts"
|
||||
"server/internal/dao"
|
||||
"server/internal/model"
|
||||
"server/internal/model/do"
|
||||
"server/internal/service"
|
||||
"server/utility/ecode"
|
||||
)
|
||||
|
||||
type sMerchant struct {
|
||||
}
|
||||
|
||||
func New() service.IMerchant {
|
||||
return &sMerchant{}
|
||||
}
|
||||
|
||||
func init() {
|
||||
service.RegisterMerchant(New())
|
||||
}
|
||||
|
||||
func (s *sMerchant) List(ctx context.Context, in *model.MerchantListIn) (out *model.MerchantListOut, err error) {
|
||||
list := make([]model.Merchant, 0)
|
||||
var total int
|
||||
orm := dao.Merchants.Ctx(ctx)
|
||||
if in.Status != 0 {
|
||||
orm = orm.Where(dao.Merchants.Columns().Status, in.Status)
|
||||
}
|
||||
if in.AuditStatus != 0 {
|
||||
orm = orm.Where(dao.Merchants.Columns().AuditStatus, in.AuditStatus)
|
||||
}
|
||||
if err = orm.Page(in.Page, in.Size).ScanAndCount(&list, &total, false); err != nil {
|
||||
return nil, ecode.Fail.Sub("查询商户列表失败")
|
||||
}
|
||||
return &model.MerchantListOut{
|
||||
List: list,
|
||||
Total: total,
|
||||
}, nil
|
||||
}
|
||||
func (s *sMerchant) Audit(ctx context.Context, in *model.MerchantAuditIn) (out *model.MerchantAuditOut, err error) {
|
||||
merchant, err := dao.Merchants.Ctx(ctx).WherePri(in.Id).One()
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("查询商户失败")
|
||||
}
|
||||
if merchant.IsEmpty() {
|
||||
return nil, ecode.Params.Sub("商户不存在")
|
||||
}
|
||||
if merchant[dao.Merchants.Columns().AuditStatus].Int() != 0 {
|
||||
return nil, ecode.Params.Sub("商户已审核")
|
||||
}
|
||||
if err = dao.Merchants.Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) {
|
||||
if _, err = tx.Model(dao.Merchants.Table()).WherePri(in.Id).Data(do.Merchants{
|
||||
AuditBy: in.AdminId,
|
||||
AuditRemark: in.AuditRemark,
|
||||
AuditStatus: in.AuditStatus,
|
||||
AuditAt: gtime.Now(),
|
||||
Status: in.AuditStatus, // 暂定审核通过商户即可使用
|
||||
RejectReason: in.RejectReason,
|
||||
}).OmitEmptyData().Update(); err != nil {
|
||||
|
||||
return ecode.Fail.Sub("审核商户失败")
|
||||
}
|
||||
if _, err = tx.Model(dao.MerchantAdmins.Table()).Where(do.MerchantAdmins{MerchantId: in.Id, IsPrimary: true}).Data(do.MerchantAdmins{
|
||||
Status: consts.MerchantAdministratorEnable,
|
||||
}).Update(); err != nil {
|
||||
return ecode.Fail.Sub("审核商户失败")
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sMerchant) Create(ctx context.Context, in *model.MerchantCreateIn) (out *model.CreateOut, err error) {
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user