feat: update
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
"quyun/app/jobs"
|
||||
"quyun/app/model"
|
||||
"quyun/app/requests"
|
||||
"quyun/database/conds"
|
||||
"quyun/database/fields"
|
||||
"quyun/providers/ali"
|
||||
"quyun/providers/job"
|
||||
@@ -39,10 +38,10 @@ type posts struct {
|
||||
// @Bind query query
|
||||
// @Bind user local
|
||||
func (ctl *posts) List(ctx fiber.Ctx, pagination *requests.Pagination, query *ListQuery, user *model.Users) (*requests.Pager, error) {
|
||||
conds := []conds.Cond{
|
||||
conds.Post_NotDeleted(),
|
||||
conds.Post_Status(fields.PostStatusPublished),
|
||||
conds.Post_Like(query.Keyword),
|
||||
conds := []model.Cond{
|
||||
model.PostsModel().CondNotDeleted(),
|
||||
model.PostsModel().CondStatus(fields.PostStatusPublished),
|
||||
model.PostsModel().CondLike(query.Keyword),
|
||||
}
|
||||
|
||||
pager, err := model.PostsModel().List(ctx.Context(), pagination, conds...)
|
||||
@@ -118,7 +117,7 @@ type PostItem struct {
|
||||
func (ctl *posts) Show(ctx fiber.Ctx, id int64, user *model.Users) (*PostItem, error) {
|
||||
log.Infof("Fetching post with ID: %d", id)
|
||||
|
||||
post, err := model.PostsModel().GetByID(ctx.Context(), id, conds.Post_NotDeleted(), conds.Post_Status(fields.PostStatusPublished))
|
||||
post, err := model.PostsModel().GetByID(ctx.Context(), id, model.PostsModel().CondNotDeleted(), model.PostsModel().CondStatus(fields.PostStatusPublished))
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("GetByID err: %v", err)
|
||||
return nil, err
|
||||
@@ -217,11 +216,12 @@ func (ctl *posts) Play(ctx fiber.Ctx, id int64, user *model.Users) (*PlayUrl, er
|
||||
func (ctl *posts) Mine(ctx fiber.Ctx, pagination *requests.Pagination, query *ListQuery, user *model.Users) (*requests.Pager, error) {
|
||||
log.Infof("Fetching posts for user with pagination: %+v and keyword: %v", pagination, query.Keyword)
|
||||
|
||||
conds := []conds.Cond{
|
||||
conds.Post_NotDeleted(),
|
||||
conds.Post_Status(fields.PostStatusPublished),
|
||||
conds.Post_Like(query.Keyword),
|
||||
conds := []model.Cond{
|
||||
model.PostsModel().CondNotDeleted(),
|
||||
model.PostsModel().CondStatus(fields.PostStatusPublished),
|
||||
model.PostsModel().CondLike(query.Keyword),
|
||||
}
|
||||
|
||||
pager, err := model.UsersModel().PostList(ctx.Context(), user.ID, pagination, conds...)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("post list err: %v", err)
|
||||
@@ -283,16 +283,16 @@ func (ctl *posts) Buy(ctx fiber.Ctx, id int64, user *model.Users) (*wechat.JSAPI
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, " failed to get post: %d", id)
|
||||
}
|
||||
payPrice := post.Price * int64(post.Discount) / 100
|
||||
// payPrice := post.PayPrice()
|
||||
|
||||
order, err := model.OrdersModel().Create(ctx.Context(), user.ID, post.ID)
|
||||
order, err := model.OrdersModel().CreateFromUserPostID(ctx.Context(), user.ID, post.ID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "订单创建失败")
|
||||
}
|
||||
|
||||
if user.Balance >= payPrice {
|
||||
if user.Balance >= post.PayPrice() {
|
||||
if err := order.SetMeta(ctx.Context(), func(om fields.OrderMeta) fields.OrderMeta {
|
||||
om.CostBalance = payPrice
|
||||
om.CostBalance = post.PayPrice()
|
||||
return om
|
||||
}); err != nil {
|
||||
return nil, errors.Wrap(err, "订单创建失败")
|
||||
@@ -308,7 +308,7 @@ func (ctl *posts) Buy(ctx fiber.Ctx, id int64, user *model.Users) (*wechat.JSAPI
|
||||
}, nil
|
||||
}
|
||||
|
||||
payPrice = payPrice - user.Balance
|
||||
payPrice := post.PayPrice() - user.Balance
|
||||
if err := order.SetMeta(ctx.Context(), func(om fields.OrderMeta) fields.OrderMeta {
|
||||
om.CostBalance = user.Balance
|
||||
return om
|
||||
|
||||
Reference in New Issue
Block a user