From 8bf268af0a550be16d6a92effa4b885e7834e337 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Sat, 5 Aug 2023 15:44:49 +0800 Subject: [PATCH] sqlx: fixed wallet logic for HandlePostAttachmentBought error --- internal/dao/sakila/wallet.go | 2 +- internal/dao/sakila/yesql/cc/yesql.go | 24 +++++------------------- internal/dao/sakila/yesql/yesql.sql | 5 +++-- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/internal/dao/sakila/wallet.go b/internal/dao/sakila/wallet.go index 29ad1cd1..68d4042e 100644 --- a/internal/dao/sakila/wallet.go +++ b/internal/dao/sakila/wallet.go @@ -100,7 +100,7 @@ func (s *walletSrv) HandlePostAttachmentBought(post *ms.Post, user *ms.User) err } // 新增附件购买记录 args = []any{post.ID, user.ID, post.AttachmentPrice, now} - if _, err = tx.Stmtx(s.q.NewPostBill).Exec(args...); err != nil { + if _, err = tx.Stmtx(s.q.NewPostAttachmentBill).Exec(args...); err != nil { return err } // 对附件主新增账单 diff --git a/internal/dao/sakila/yesql/cc/yesql.go b/internal/dao/sakila/yesql/cc/yesql.go index b1da4914..4730e234 100644 --- a/internal/dao/sakila/yesql/cc/yesql.go +++ b/internal/dao/sakila/yesql/cc/yesql.go @@ -12,7 +12,6 @@ import ( ) const ( - _NewPostAttachmentBill = `INSERT INTO @post_attachment_bill (post_id, user_id, paid_amount) VALUES (?, ?, ?)` _AuthorizationManage_BeFriendIds = `SELECT user_id FROM @contact WHERE friend_id=? AND status=2 AND is_del=0` _AuthorizationManage_IsFriend = `SELECT status FROM @contact WHERE user_id=? AND friend_id=? AND is_del=0` _AuthorizationManage_MyFriendSet = `SELECT friend_id FROM @contact WHERE user_id=? AND status=2 AND is_del=0` @@ -134,13 +133,10 @@ const ( _Wallet_GetUserWalletBills = `SELECT * FROM @wallet_statement WHERE user_id=? AND is_del=0 ORDER BY id DESC LIMIT ? OFFSET ?` _Wallet_MarkSuccessRecharge = `UPDATE @wallet_recharge SET trade_no=?, trade_status='TRADE_SUCCESS', modified_on=? WHERE id=? AND is_del=0` _Wallet_MinusUserBalance = `UPDATE @user SET balance=balance-?, modified_on=? WHERE id=? AND is_del=0` + _Wallet_NewPostAttachmentBill = `INSERT INTO @post_attachment_bill (post_id, user_id, paid_amount, created_on) VALUES (?, ?, ?, ?)` _Wallet_NewPostBill = `INSERT INTO @wallet_statement (post_id, user_id, change_amount, balance_snapshot, reason, created_on) VALUES (?, ?, ?, ?, ?, ?)` ) -type Yesql struct { - NewPostAttachmentBill *sqlx.Stmt `yesql:"new_post_attachment_bill"` -} - type AuthorizationManage struct { yesql.Namespace `yesql:"authorization_manage"` BeFriendIds *sqlx.Stmt `yesql:"be_friend_ids"` @@ -352,23 +348,10 @@ type Wallet struct { GetUserWalletBills *sqlx.Stmt `yesql:"get_user_wallet_bills"` MarkSuccessRecharge *sqlx.Stmt `yesql:"mark_success_recharge"` MinusUserBalance *sqlx.Stmt `yesql:"minus_user_balance"` + NewPostAttachmentBill *sqlx.Stmt `yesql:"new_post_attachment_bill"` NewPostBill *sqlx.Stmt `yesql:"new_post_bill"` } -func BuildYesql(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Yesql, err error) { - var c context.Context - if len(ctx) > 0 && ctx[0] != nil { - c = ctx[0] - } else { - c = context.Background() - } - obj = &Yesql{} - if obj.NewPostAttachmentBill, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_NewPostAttachmentBill))); err != nil { - return - } - return -} - func BuildAuthorizationManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *AuthorizationManage, err error) { var c context.Context if len(ctx) > 0 && ctx[0] != nil { @@ -955,6 +938,9 @@ func BuildWallet(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Wallet, if obj.MinusUserBalance, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_MinusUserBalance))); err != nil { return } + if obj.NewPostAttachmentBill, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_NewPostAttachmentBill))); err != nil { + return + } if obj.NewPostBill, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_NewPostBill))); err != nil { return } diff --git a/internal/dao/sakila/yesql/yesql.sql b/internal/dao/sakila/yesql/yesql.sql index 6c6c941f..84596ec0 100644 --- a/internal/dao/sakila/yesql/yesql.sql +++ b/internal/dao/sakila/yesql/yesql.sql @@ -665,9 +665,10 @@ UPDATE @wallet_recharge SET trade_no=?, trade_status='TRADE_SUCCESS', modified_on=? WHERE id=? AND is_del=0; --- name: new_post_attachment_bill +-- name: new_post_attachment_bill@wallet -- prepare: stmt -INSERT INTO @post_attachment_bill (post_id, user_id, paid_amount) VALUES (?, ?, ?); +INSERT INTO @post_attachment_bill (post_id, user_id, paid_amount, created_on) +VALUES (?, ?, ?, ?); -- name: new_post_bill@wallet -- prepare: stmt