f
This commit is contained in:
@@ -50,7 +50,7 @@ Wxpay:
|
|||||||
MchPublicKeyPath: "etc/merchant/wxpay/XXXXXXXXXXXX_XXXXXXXXXXXX_cert/pub_key.pem"
|
MchPublicKeyPath: "etc/merchant/wxpay/XXXXXXXXXXXX_XXXXXXXXXXXX_cert/pub_key.pem"
|
||||||
MchPlatformRAS: "xxxx"
|
MchPlatformRAS: "xxxx"
|
||||||
NotifyUrl: "https://www.XXXXXXXXXXXXXX.com/api/v1/pay/wechat/callback"
|
NotifyUrl: "https://www.XXXXXXXXXXXXXX.com/api/v1/pay/wechat/callback"
|
||||||
RefundNotifyUrl: "https://www.XXXXXXXXXXXXXX.com/api/v1/wechat/refund_callback"
|
RefundNotifyUrl: "https://www.XXXXXXXXXXXXXX.com/api/v1/pay/wechat/refund_callback"
|
||||||
Applepay:
|
Applepay:
|
||||||
ProductionVerifyURL: "https://api.storekit.itunes.apple.com/inApps/v1/transactions/receipt"
|
ProductionVerifyURL: "https://api.storekit.itunes.apple.com/inApps/v1/transactions/receipt"
|
||||||
SandboxVerifyURL: "https://api.storekit-sandbox.itunes.apple.com/inApps/v1/transactions/receipt"
|
SandboxVerifyURL: "https://api.storekit-sandbox.itunes.apple.com/inApps/v1/transactions/receipt"
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
package admin_product
|
package admin_product
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"bdrp-server/app/main/api/internal/svc"
|
"bdrp-server/app/main/api/internal/svc"
|
||||||
"bdrp-server/app/main/api/internal/types"
|
"bdrp-server/app/main/api/internal/types"
|
||||||
"bdrp-server/app/main/model"
|
"bdrp-server/app/main/model"
|
||||||
"bdrp-server/common/xerr"
|
"bdrp-server/common/xerr"
|
||||||
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"math"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AdminCreateProductLogic struct {
|
type AdminCreateProductLogic struct {
|
||||||
@@ -27,7 +29,7 @@ func NewAdminCreateProductLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *AdminCreateProductLogic) AdminCreateProduct(req *types.AdminCreateProductReq) (resp *types.AdminCreateProductResp, err error) {
|
func (l *AdminCreateProductLogic) AdminCreateProduct(req *types.AdminCreateProductReq) (resp *types.AdminCreateProductResp, err error) {
|
||||||
// 1. 数据转换
|
// 1. 构建产品数据
|
||||||
data := &model.Product{
|
data := &model.Product{
|
||||||
ProductName: req.ProductName,
|
ProductName: req.ProductName,
|
||||||
ProductEn: req.ProductEn,
|
ProductEn: req.ProductEn,
|
||||||
@@ -37,14 +39,37 @@ func (l *AdminCreateProductLogic) AdminCreateProduct(req *types.AdminCreateProdu
|
|||||||
SellPrice: req.SellPrice,
|
SellPrice: req.SellPrice,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 数据库操作
|
// 2. 开启事务,确保产品与代理产品配置同步创建
|
||||||
result, err := l.svcCtx.ProductModel.Insert(l.ctx, nil, data)
|
var id int64
|
||||||
|
err = l.svcCtx.ProductModel.Trans(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||||
|
result, txErr := l.svcCtx.ProductModel.Insert(ctx, session, data)
|
||||||
|
if txErr != nil {
|
||||||
|
return txErr
|
||||||
|
}
|
||||||
|
|
||||||
|
productID, txErr := result.LastInsertId()
|
||||||
|
if txErr != nil {
|
||||||
|
return txErr
|
||||||
|
}
|
||||||
|
id = productID
|
||||||
|
|
||||||
|
priceRangeMax := math.Max(req.CostPrice, req.SellPrice)
|
||||||
|
agentConfig := &model.AgentProductConfig{
|
||||||
|
ProductId: productID,
|
||||||
|
CostPrice: req.CostPrice,
|
||||||
|
PriceRangeMin: req.CostPrice,
|
||||||
|
PriceRangeMax: priceRangeMax,
|
||||||
|
PricingStandard: priceRangeMax,
|
||||||
|
OverpricingRatio: 0.10,
|
||||||
|
}
|
||||||
|
_, txErr = l.svcCtx.AgentProductConfigModel.Insert(ctx, session, agentConfig)
|
||||||
|
return txErr
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR),
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR),
|
||||||
"创建产品失败, err: %v, req: %+v", err, req)
|
"创建产品及代理产品配置失败, err: %v, req: %+v", err, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 返回结果
|
// 3. 返回结果
|
||||||
id, _ := result.LastInsertId()
|
|
||||||
return &types.AdminCreateProductResp{Id: id}, nil
|
return &types.AdminCreateProductResp{Id: id}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
package admin_product
|
package admin_product
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"bdrp-server/app/main/api/internal/svc"
|
"bdrp-server/app/main/api/internal/svc"
|
||||||
"bdrp-server/app/main/api/internal/types"
|
"bdrp-server/app/main/api/internal/types"
|
||||||
|
"bdrp-server/app/main/model"
|
||||||
"bdrp-server/common/xerr"
|
"bdrp-server/common/xerr"
|
||||||
|
"context"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AdminDeleteProductLogic struct {
|
type AdminDeleteProductLogic struct {
|
||||||
@@ -25,15 +27,27 @@ func NewAdminDeleteProductLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *AdminDeleteProductLogic) AdminDeleteProduct(req *types.AdminDeleteProductReq) (resp *types.AdminDeleteProductResp, err error) {
|
func (l *AdminDeleteProductLogic) AdminDeleteProduct(req *types.AdminDeleteProductReq) (resp *types.AdminDeleteProductResp, err error) {
|
||||||
// 1. 查询记录是否存在
|
// 1. 查询产品是否存在
|
||||||
record, err := l.svcCtx.ProductModel.FindOne(l.ctx, req.Id)
|
record, err := l.svcCtx.ProductModel.FindOne(l.ctx, req.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR),
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR),
|
||||||
"查找产品失败, err: %v, id: %d", err, req.Id)
|
"查找产品失败, err: %v, id: %d", err, req.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 执行软删除
|
// 2. 事务内执行物理删除,保持 product 与 agent_product_config 同步
|
||||||
err = l.svcCtx.ProductModel.DeleteSoft(l.ctx, nil, record)
|
err = l.svcCtx.ProductModel.Trans(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||||
|
agentCfg, findErr := l.svcCtx.AgentProductConfigModel.FindOneByProductId(ctx, req.Id)
|
||||||
|
if findErr != nil && !errors.Is(findErr, model.ErrNotFound) {
|
||||||
|
return findErr
|
||||||
|
}
|
||||||
|
if findErr == nil {
|
||||||
|
if deleteCfgErr := l.svcCtx.AgentProductConfigModel.Delete(ctx, session, agentCfg.Id); deleteCfgErr != nil {
|
||||||
|
return deleteCfgErr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return l.svcCtx.ProductModel.Delete(ctx, session, record.Id)
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR),
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR),
|
||||||
"删除产品失败, err: %v, id: %d", err, req.Id)
|
"删除产品失败, err: %v, id: %d", err, req.Id)
|
||||||
|
|||||||
Reference in New Issue
Block a user