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