feat: update
This commit is contained in:
@@ -19,8 +19,7 @@ type medias struct {
|
||||
// @Bind pagination query
|
||||
// @Bind query query
|
||||
func (ctl *medias) List(ctx fiber.Ctx, pagination *requests.Pagination, query *ListQuery) (*requests.Pager, error) {
|
||||
cond := model.MediasModel().BuildConditionWithKey(query.Keyword)
|
||||
return model.MediasModel().List(ctx.Context(), pagination, cond)
|
||||
return model.MediasModel().List(ctx.Context(), pagination, model.MediasModel().Like(query.Keyword))
|
||||
}
|
||||
|
||||
// Show media
|
||||
@@ -55,7 +54,7 @@ func (ctl *medias) Delete(ctx fiber.Ctx, id int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := model.MediasModel().Delete(ctx.Context(), id); err != nil {
|
||||
if err := media.ForceDelete(ctx.Context()); err != nil {
|
||||
return err
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusNoContent)
|
||||
|
||||
@@ -3,7 +3,6 @@ package admin
|
||||
import (
|
||||
"quyun/app/model"
|
||||
"quyun/app/requests"
|
||||
"quyun/database/conds"
|
||||
"quyun/database/fields"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
@@ -23,10 +22,10 @@ type posts struct{}
|
||||
// @Bind pagination query
|
||||
// @Bind query query
|
||||
func (ctl *posts) List(ctx fiber.Ctx, pagination *requests.Pagination, query *ListQuery) (*requests.Pager, error) {
|
||||
conds := []conds.Cond{
|
||||
conds := []model.Cond{
|
||||
// conds.Post_NotDeleted(),
|
||||
// conds.Post_Status(fields.PostStatusPublished),
|
||||
conds.Post_Like(query.Keyword),
|
||||
model.PostsModel().CondLike(query.Keyword),
|
||||
}
|
||||
pager, err := model.PostsModel().List(ctx.Context(), pagination, conds...)
|
||||
if err != nil {
|
||||
@@ -158,7 +157,7 @@ func (ctl *posts) Delete(ctx fiber.Ctx, id int64) error {
|
||||
return fiber.ErrNotFound
|
||||
}
|
||||
|
||||
if err := post.Delete(ctx.Context()); err != nil {
|
||||
if err := post.ForceDelete(ctx.Context()); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -29,11 +29,11 @@ func (s *statistics) statistics(ctx fiber.Ctx) (*StatisticsResponse, error) {
|
||||
|
||||
var err error
|
||||
|
||||
statistics.PostDraft, err = model.PostsModel().Count(ctx.Context(), table.Posts.Status.EQ(Int(int64(fields.PostStatusDraft))))
|
||||
statistics.PostDraft, err = model.PostsModel().Count(ctx.Context(), model.ExprCond(table.Posts.Status.EQ(Int(int64(fields.PostStatusDraft)))))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
statistics.PostPublished, err = model.PostsModel().Count(ctx.Context(), table.Posts.Status.EQ(Int(int64(fields.PostStatusPublished))))
|
||||
statistics.PostPublished, err = model.PostsModel().Count(ctx.Context(), model.ExprCond(table.Posts.Status.EQ(Int(int64(fields.PostStatusPublished)))))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -43,12 +43,12 @@ func (s *statistics) statistics(ctx fiber.Ctx) (*StatisticsResponse, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
statistics.Order, err = model.OrdersModel().Count(ctx.Context(), table.Orders.Status.EQ(Int(int64(fields.OrderStatusCompleted))))
|
||||
statistics.Order, err = model.OrdersModel().Count(ctx.Context(), model.ExprCond(table.Orders.Status.EQ(Int(int64(fields.OrderStatusCompleted)))))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
statistics.User, err = model.UsersModel().Count(ctx.Context(), BoolExp(Bool(true)))
|
||||
statistics.User, err = model.UsersModel().Count(ctx.Context())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -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