This commit is contained in:
@@ -37,7 +37,12 @@ type posts struct {
|
||||
// @Bind pagination query
|
||||
// @Bind query query
|
||||
// @Bind user local
|
||||
func (ctl *posts) List(ctx fiber.Ctx, pagination *requests.Pagination, query *ListQuery, user *model.Users) (*requests.Pager, error) {
|
||||
func (ctl *posts) List(
|
||||
ctx fiber.Ctx,
|
||||
pagination *requests.Pagination,
|
||||
query *ListQuery,
|
||||
user *model.Users,
|
||||
) (*requests.Pager, error) {
|
||||
conds := []model.Cond{
|
||||
model.PostsModel().CondNotDeleted(),
|
||||
model.PostsModel().CondStatus(fields.PostStatusPublished),
|
||||
@@ -117,7 +122,8 @@ 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, model.PostsModel().CondNotDeleted(), model.PostsModel().CondStatus(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
|
||||
@@ -196,7 +202,11 @@ func (ctl *posts) Play(ctx fiber.Ctx, id int64, user *model.Users) (*PlayUrl, er
|
||||
if asset.Metas.Duration == 0 {
|
||||
duration = 60 * 5
|
||||
}
|
||||
url, err := ctl.oss.GetSignedUrl(ctx.Context(), media.Path, ali.WithExpire(time.Second*time.Duration(duration)))
|
||||
url, err := ctl.oss.GetSignedUrl(
|
||||
ctx.Context(),
|
||||
media.Path,
|
||||
ali.WithExpire(time.Second*time.Duration(duration)),
|
||||
)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("media GetSignedUrl err: %v", err)
|
||||
return nil, err
|
||||
@@ -213,7 +223,12 @@ func (ctl *posts) Play(ctx fiber.Ctx, id int64, user *model.Users) (*PlayUrl, er
|
||||
// @Bind pagination query
|
||||
// @Bind query query
|
||||
// @Bind user local
|
||||
func (ctl *posts) Mine(ctx fiber.Ctx, pagination *requests.Pagination, query *ListQuery, user *model.Users) (*requests.Pager, error) {
|
||||
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 := []model.Cond{
|
||||
@@ -307,6 +322,7 @@ func (ctl *posts) Buy(ctx fiber.Ctx, id int64, user *model.Users) (*wechat.JSAPI
|
||||
AppId: "balance",
|
||||
}, nil
|
||||
}
|
||||
return nil, errors.Errorf("账户余额不足, 当前余额:%0.2f, 请联系管理员购买或充值", float64(user.Balance)/100)
|
||||
|
||||
payPrice := post.PayPrice() - user.Balance
|
||||
if err := order.SetMeta(ctx.Context(), func(om fields.OrderMeta) fields.OrderMeta {
|
||||
|
||||
@@ -100,43 +100,45 @@ const handleBuy = async () => {
|
||||
|
||||
const payData = response.data;
|
||||
|
||||
if (payData.appId != "balance") {
|
||||
// 调用微信支付
|
||||
window.WeixinJSBridge.invoke(
|
||||
"getBrandWCPayRequest",
|
||||
{
|
||||
...payData,
|
||||
},
|
||||
async function (res) {
|
||||
if (res.err_msg === "get_brand_wcpay_request:ok") {
|
||||
// 支付成功,刷新文章数据
|
||||
fetchArticle();
|
||||
await updateMediaSource();
|
||||
} else if (res.err_msg === "get_brand_wcpay_request:cancel") {
|
||||
// 用户取消支付
|
||||
console.log("Payment cancelled");
|
||||
alert("支付已取消");
|
||||
} else {
|
||||
// 支付失败或取消
|
||||
console.error("Payment failed:", res.err_msg);
|
||||
alert(
|
||||
"支付失败:" +
|
||||
(res.err_msg === "get_brand_wcpay_request:cancel"
|
||||
? "支付已取消"
|
||||
: "支付异常")
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
return
|
||||
}
|
||||
// 暂停使用微支付
|
||||
// if (payData.appId != "balance") {
|
||||
// // 调用微信支付
|
||||
// window.WeixinJSBridge.invoke(
|
||||
// "getBrandWCPayRequest",
|
||||
// {
|
||||
// ...payData,
|
||||
// },
|
||||
// async function (res) {
|
||||
// if (res.err_msg === "get_brand_wcpay_request:ok") {
|
||||
// // 支付成功,刷新文章数据
|
||||
// fetchArticle();
|
||||
// await updateMediaSource();
|
||||
// } else if (res.err_msg === "get_brand_wcpay_request:cancel") {
|
||||
// // 用户取消支付
|
||||
// console.log("Payment cancelled");
|
||||
// alert("支付已取消");
|
||||
// } else {
|
||||
// // 支付失败或取消
|
||||
// console.error("Payment failed:", res.err_msg);
|
||||
// alert(
|
||||
// "支付失败:" +
|
||||
// (res.err_msg === "get_brand_wcpay_request:cancel"
|
||||
// ? "支付已取消"
|
||||
// : "支付异常")
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
// return
|
||||
// }
|
||||
|
||||
alert("余额支付成功");
|
||||
fetchArticle();
|
||||
await updateMediaSource();
|
||||
} catch (error) {
|
||||
console.error("Failed to initiate payment:", error);
|
||||
alert("发起支付失败,请稍后重试");
|
||||
// alert("发起支付失败,请稍后重试");
|
||||
alert(error.response?.data?.message || "发起支付失败,请稍后重试");
|
||||
} finally {
|
||||
buying.value = false;
|
||||
}
|
||||
@@ -229,6 +231,9 @@ onUnmounted(() => {
|
||||
<div class="text-sm bg-orange-500 text-white px-4 py-2">
|
||||
注意:未购买视频仅可预览 1 分钟,购买后可观看全集。
|
||||
</div>
|
||||
<div class="bg-orange-300 text-white px-4 py-4">
|
||||
账户充值购买联系微信:<span class="font-bold">13932043996</span>
|
||||
</div>
|
||||
<div class="flex items-center justify-between max-w-md mx-auto p-4">
|
||||
<div class="text-orange-600 text-2xl">
|
||||
<span class="mr-2 text-xl">¥</span>
|
||||
|
||||
Reference in New Issue
Block a user