feat: update pay notify
This commit is contained in:
@@ -2,12 +2,11 @@ package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"quyun/app/requests"
|
||||
"quyun/database/fields"
|
||||
"quyun/database/schemas/public/model"
|
||||
"quyun/database/schemas/public/table"
|
||||
"time"
|
||||
|
||||
. "github.com/go-jet/jet/v2/postgres"
|
||||
"github.com/samber/lo"
|
||||
|
||||
@@ -5,14 +5,13 @@ import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"quyun/app/requests"
|
||||
"quyun/app/service/testx"
|
||||
"quyun/database"
|
||||
"quyun/database/schemas/public/model"
|
||||
"quyun/database/schemas/public/table"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"go.ipao.vip/atom/contracts"
|
||||
|
||||
@@ -3,12 +3,11 @@ package models
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"quyun/app/requests"
|
||||
"quyun/database/fields"
|
||||
"quyun/database/schemas/public/model"
|
||||
"quyun/database/schemas/public/table"
|
||||
"time"
|
||||
|
||||
. "github.com/go-jet/jet/v2/postgres"
|
||||
"github.com/pkg/errors"
|
||||
@@ -243,3 +242,68 @@ func (m *ordersModel) SumAmount(ctx context.Context) (int64, error) {
|
||||
|
||||
return cnt.Cnt, nil
|
||||
}
|
||||
|
||||
// GetByOrderNo
|
||||
func (m *ordersModel) GetByOrderNo(ctx context.Context, orderNo string) (*model.Orders, error) {
|
||||
tbl := table.Orders
|
||||
stmt := tbl.
|
||||
SELECT(tbl.AllColumns).
|
||||
WHERE(
|
||||
tbl.OrderNo.EQ(String(orderNo)),
|
||||
)
|
||||
m.log.Infof("sql: %s", stmt.DebugSql())
|
||||
|
||||
var order model.Orders
|
||||
err := stmt.QueryContext(ctx, db, &order)
|
||||
if err != nil {
|
||||
m.log.Errorf("error querying order by orderNo: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &order, nil
|
||||
}
|
||||
|
||||
// SetTranscationID
|
||||
func (m *ordersModel) SetTranscationID(ctx context.Context, id int64, transactionID string) error {
|
||||
tbl := table.Orders
|
||||
stmt := tbl.
|
||||
UPDATE(tbl.TransactionID).
|
||||
SET(String(transactionID)).
|
||||
WHERE(
|
||||
tbl.ID.EQ(Int64(id)),
|
||||
)
|
||||
m.log.Infof("sql: %s", stmt.DebugSql())
|
||||
|
||||
if _, err := stmt.ExecContext(ctx, db); err != nil {
|
||||
m.log.Errorf("error set order transaction ID: %v", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update
|
||||
func (m *ordersModel) Update(ctx context.Context, order *model.Orders) error {
|
||||
tbl := table.Orders
|
||||
stmt := tbl.
|
||||
UPDATE(
|
||||
tbl.MutableColumns.Except(
|
||||
tbl.OrderNo,
|
||||
tbl.Price,
|
||||
tbl.Discount,
|
||||
tbl.SubOrderNo,
|
||||
tbl.PostID,
|
||||
tbl.UserID,
|
||||
),
|
||||
).
|
||||
MODEL(order).
|
||||
WHERE(
|
||||
tbl.ID.EQ(Int64(order.ID)),
|
||||
)
|
||||
m.log.Infof("sql: %s", stmt.DebugSql())
|
||||
|
||||
if _, err := stmt.ExecContext(ctx, db); err != nil {
|
||||
m.log.Errorf("error updating order: %v", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -2,11 +2,10 @@ package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"quyun/app/service/testx"
|
||||
"quyun/database"
|
||||
"quyun/database/schemas/public/table"
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"go.ipao.vip/atom/contracts"
|
||||
|
||||
@@ -3,11 +3,10 @@ package models
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"quyun/app/requests"
|
||||
"quyun/database/schemas/public/model"
|
||||
"quyun/database/schemas/public/table"
|
||||
"time"
|
||||
|
||||
. "github.com/go-jet/jet/v2/postgres"
|
||||
"github.com/go-jet/jet/v2/qrm"
|
||||
|
||||
@@ -4,13 +4,12 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"quyun/app/service/testx"
|
||||
"quyun/database"
|
||||
"quyun/database/fields"
|
||||
"quyun/database/schemas/public/model"
|
||||
"quyun/database/schemas/public/table"
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"go.ipao.vip/atom/contracts"
|
||||
|
||||
@@ -2,12 +2,12 @@ package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"database/sql"
|
||||
"quyun/app/requests"
|
||||
"quyun/database/fields"
|
||||
"quyun/database/schemas/public/model"
|
||||
"quyun/database/schemas/public/table"
|
||||
"time"
|
||||
|
||||
. "github.com/go-jet/jet/v2/postgres"
|
||||
"github.com/go-jet/jet/v2/qrm"
|
||||
@@ -16,6 +16,10 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func Transaction(ctx context.Context) (*sql.Tx, error) {
|
||||
return db.Begin()
|
||||
}
|
||||
|
||||
// @provider
|
||||
type usersModel struct {
|
||||
log *logrus.Entry `inject:"false"`
|
||||
@@ -404,3 +408,25 @@ func (m *usersModel) UpdateUserToken(ctx context.Context, id int64, token fields
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// BuyPosts
|
||||
func (m *usersModel) BuyPosts(ctx context.Context, userID, postID, price int64) error {
|
||||
tbl := table.UserPosts
|
||||
stmt := tbl.
|
||||
INSERT(tbl.MutableColumns).
|
||||
MODEL(&model.UserPosts{
|
||||
UserID: userID,
|
||||
PostID: postID,
|
||||
Price: price,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
})
|
||||
|
||||
m.log.Infof("sql: %s", stmt.DebugSql())
|
||||
|
||||
if _, err := stmt.ExecContext(ctx, db); err != nil {
|
||||
m.log.Errorf("error inserting user post: %v", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -2,13 +2,12 @@ package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"quyun/app/service/testx"
|
||||
"quyun/database"
|
||||
"quyun/database/fields"
|
||||
"quyun/database/schemas/public/model"
|
||||
"quyun/database/schemas/public/table"
|
||||
"testing"
|
||||
|
||||
"github.com/samber/lo"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
|
||||
Reference in New Issue
Block a user