refactor(card-redeem-jd): 优化账户和订单相关接口
- 为 AccountStatusReq 和 PlaceOrderReq 添加结构体注释 - 在账户添加和更新时对 Cookie 和名称进行空格trim处理 - 优化苹果充值日志记录顺序 - 改进订单创建逻辑,增加错误日志记录 - 修正京东订单创建失败的错误信息
This commit is contained in:
@@ -63,7 +63,7 @@ type AccountDeleteReq struct {
|
||||
|
||||
type AccountDeleteRes struct{}
|
||||
|
||||
// 修改状态
|
||||
// AccountStatusReq 修改状态
|
||||
type AccountStatusReq struct {
|
||||
g.Meta `path:"/cookieInfo/jd/account/status" tags:"京东ck账户" method:"put" summary:"修改京东ck状态"`
|
||||
commonApi.CommonIntId
|
||||
|
||||
@@ -25,7 +25,7 @@ type OrderListRes struct {
|
||||
commonApi.CommonPageRes[*OrderListSchema]
|
||||
}
|
||||
|
||||
// 下单接口
|
||||
// PlaceOrderReq 下单接口
|
||||
type PlaceOrderReq struct {
|
||||
g.Meta `path:"/cookieInfo/jd/order/placeOrder" tags:"京东ck订单" method:"post" summary:"下单"`
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package card_redeem_jd
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
v1 "kami/api/card_redeem_jd/v1"
|
||||
"kami/internal/consts"
|
||||
"kami/internal/model"
|
||||
@@ -10,6 +10,8 @@ import (
|
||||
)
|
||||
|
||||
func (c *ControllerV1) AccountAdd(ctx context.Context, req *v1.AccountAddReq) (res *v1.AccountAddRes, err error) {
|
||||
req.Cookie = gstr.TrimAll(req.Cookie)
|
||||
req.Name = gstr.TrimAll(req.Name)
|
||||
err = service.CardReddemCookie().Save(ctx, &model.CardRedeemCookieCreatedInput{
|
||||
Category: consts.CardRedeemCookieCategoryJD,
|
||||
AccountEntity: req.AccountEntity,
|
||||
|
||||
@@ -2,6 +2,7 @@ package card_redeem_jd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
|
||||
v1 "kami/api/card_redeem_jd/v1"
|
||||
"kami/internal/model"
|
||||
@@ -9,6 +10,8 @@ import (
|
||||
)
|
||||
|
||||
func (c *ControllerV1) AccountUpdate(ctx context.Context, req *v1.AccountUpdateReq) (res *v1.AccountUpdateRes, err error) {
|
||||
req.Cookie = gstr.TrimAll(req.Cookie)
|
||||
req.Name = gstr.TrimAll(req.Name)
|
||||
err = service.CardReddemCookie().Update(ctx, &model.CardRedeemCookieUpdatedInput{
|
||||
Id: req.ID,
|
||||
AccountEntity: req.AccountEntity,
|
||||
|
||||
@@ -74,7 +74,6 @@ func (s *sCardReddemCookie) placeNewOrder(ctx context.Context, input *model.Card
|
||||
}
|
||||
|
||||
err = m.Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
||||
|
||||
status := consts.CardRedeemCookieOrderStatusInit
|
||||
_, err = m.Ctx(ctx).TX(tx).Insert(do.V1CardRedeemCookieOrder{
|
||||
OrderNo: orderNo,
|
||||
@@ -96,9 +95,10 @@ func (s *sCardReddemCookie) placeNewOrder(ctx context.Context, input *model.Card
|
||||
|
||||
accountInfo, jdOrder, err := s.placeJdOrder(ctx, orderNo, input.UserAgent, input.OrderAmount, tx)
|
||||
if err != nil {
|
||||
glog.Error(ctx, "下单失败", err)
|
||||
cookieOrderDo.Status = consts.CardRedeemCookieOrderStatusPlaceFail
|
||||
} else if pointer.IsNil(jdOrder) || pointer.IsNil(accountInfo) {
|
||||
err = gerror.New("下单失败")
|
||||
glog.Error(ctx, "下单失败,jdOrder", jdOrder)
|
||||
cookieOrderDo.Status = consts.CardRedeemCookieOrderStatusPlaceFail
|
||||
} else {
|
||||
cookieOrderDo.Status = consts.CardRedeemCookieOrderStatusPlaceSuccess
|
||||
@@ -107,6 +107,7 @@ func (s *sCardReddemCookie) placeNewOrder(ctx context.Context, input *model.Card
|
||||
cookieOrderDo.Cookie = accountInfo.Cookie
|
||||
cookieOrderDo.CookieId = accountInfo.Id
|
||||
}
|
||||
|
||||
_, err = m.Where(
|
||||
dao.V1CardRedeemCookieOrder.Columns().OrderNo, orderNo,
|
||||
).Update(cookieOrderDo)
|
||||
|
||||
@@ -65,8 +65,8 @@ func (s *sCardReddemCookie) placeJdOrder(ctx context.Context, orderNo string, us
|
||||
})
|
||||
|
||||
glog.Info(ctx, "下单成功", "jdOrder", jdOrder)
|
||||
if pointer.IsNil(jdOrder) {
|
||||
return nil, nil, gerror.New("下单失败")
|
||||
if pointer.IsNil(jdOrder) || jdOrder.OrderId == "" {
|
||||
return nil, nil, gerror.New("京东返回订单信息为空")
|
||||
}
|
||||
|
||||
jdCookieInfo.ResponseData = gconv.String(jdOrder)
|
||||
|
||||
@@ -20,15 +20,15 @@ func (c *Client) AppleRecharge(ctx context.Context, input *AppleRechargeReq) (*A
|
||||
}
|
||||
|
||||
clientResp := &AppleRechargeClientResp{}
|
||||
glog.Info(ctx, "苹果权益充值", "clientResp", clientResp, response.ReadAllString())
|
||||
err = json.Unmarshal(response.ReadAll(), clientResp)
|
||||
glog.Info(ctx, "苹果权益充值", "clientResp", clientResp, response.ReadAllString())
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
|
||||
resp.Msg = clientResp.Msg
|
||||
resp.Code = clientResp.Code.JDOrderStatus()
|
||||
if clientResp.Code != 100 {
|
||||
if clientResp.Code != Success {
|
||||
return resp, errors.New("苹果权益充值失败")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user