add order and pay support

This commit is contained in:
AceDataCloud committed 2023-01-24 12:28:34 +08:00
1 parent cfea244d28
commit 2ca68e2559
20 files changed
+490 -118

No files matched your search

+1
View File
@@ -40,6 +40,7 @@
"markdown-it": "^13.0.1",
"mustache": "^4.2.0",
"programming-languages-logos": "^0.0.3",
"qrcode.vue": "^3.3.3",
"query-string": "^8.1.0",
"typescript-cookie": "^1.0.3",
"url-join": "^5.0.0",
+9 -2
View File
@@ -1,7 +1,7 @@
<template>
<font-awesome-icon v-if="!copied" icon="fa-regular fa-copy" @click="onCopy" />
<font-awesome-icon v-if="!copied" icon="fa-regular fa-copy" class="icon-copy" @click="onCopy" />
<el-tooltip v-else :visible="copied" effect="dark" :content="$t('common.message.copied')" placement="top-start">
<font-awesome-icon icon="fa-solid fa-check" />
<font-awesome-icon icon="fa-solid fa-check" class="icon-check" />
</el-tooltip>
</template>
@@ -39,3 +39,10 @@ export default defineComponent({
}
});
</script>
<style lang="scss" scoped>
.icon-check,
.icon-copy {
margin-left: 5px;
}
</style>
+12 -18
View File
@@ -7,11 +7,13 @@
<el-row>
<el-col :span="24">
<div class="links">
<a
v-for="link in links"
:key="link.key"
:class="{ link: true, active: $route.path == link.href }"
@click="onClick(link.href)"
<router-link
v-for="(link, linkIndex) in links"
:key="linkIndex"
:to="{
name: link.name
}"
:class="{ link: true, active: $route.name === link.name }"
>
<span class="icon">
<el-icon class="icon">
@@ -22,7 +24,7 @@
</span>
<span class="text">{{ link.text }}</span>
<span class="suffix"></span>
</a>
</router-link>
</div>
</el-col>
</el-row>
@@ -30,12 +32,12 @@
<script lang="ts">
import { defineComponent } from 'vue';
import { Clock, MagicStick, Collection, VideoPlay, Goods, Loading, User, Postcard } from '@element-plus/icons-vue';
import { Clock, User, Postcard } from '@element-plus/icons-vue';
interface ILink {
key: string;
text: string;
href: string;
name: string;
icon: string;
}
@@ -47,11 +49,6 @@ export default defineComponent({
name: 'Navigator',
components: {
Clock,
Collection,
MagicStick,
VideoPlay,
Goods,
Loading,
Postcard,
User
},
@@ -61,13 +58,13 @@ export default defineComponent({
{
key: 'profile',
text: this.$t('console.menu.orderList'),
href: '/console/orders',
name: 'console-order-list',
icon: 'user'
},
{
key: 'verify',
text: this.$t('console.menu.applicationList'),
href: '/console/applications',
name: 'console-application-list',
icon: 'postcard'
}
]
@@ -80,9 +77,6 @@ export default defineComponent({
},
mounted() {},
methods: {
onClick(link: string) {
window.location.href = link;
},
onHome() {
this.$router.push({
name: 'home'
+95
View File
@@ -0,0 +1,95 @@
<template>
<el-dialog :model-value="visible" :title="$t('application.title.buyService')" width="60%" center>
<el-form label-width="120px">
<el-form-item v-if="application?.service?.title" :label="$t('application.field.service')">
{{ application?.service?.title }}
</el-form-item>
<el-form-item :label="$t('application.field.amount')">
<el-input-number v-model="form.amount" :min="1" :max="10" controls-position="right" />
</el-form-item>
<el-divider />
<el-form-item :label="$t('application.field.shouldPayPrice')">
<span class="price">¥{{ (getPrice() / 100).toFixed(2) }}</span>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="$emit('hide')">{{ $t('common.button.cancel') }}</el-button>
<el-button type="primary" :loading="creating" @click="onCreateOrder">
{{ $t('application.button.createOrder') }}
</el-button>
</span>
</template>
</el-dialog>
</template>
<script lang="ts">
import { IApplication, IOrderDetailResponse, orderOperator } from '@/operators';
import { defineComponent } from 'vue';
import { ElMessage } from 'element-plus';
export default defineComponent({
name: 'CreateOrderDialog',
props: {
application: {
type: Object as () => IApplication,
required: true
},
visible: {
type: Boolean,
required: false,
default: false
}
},
emits: ['hide'],
data() {
return {
form: {
amount: 1
},
creating: false
};
},
mounted() {},
methods: {
onCreateOrder() {
if (!this.application?.id) {
return;
}
this.creating = true;
orderOperator
.create({
application_id: this.application?.id,
amount: 10
})
.then(({ data: data }: { data: IOrderDetailResponse }) => {
this.creating = false;
const order = data;
this.$router.push({
name: 'console-order-detail',
params: {
id: order.id
}
});
})
.catch((error) => {
ElMessage.success(this.$t('order.message.createFailed'));
this.creating = false;
});
},
getPrice() {
if (this.application.service?.price && this.form.amount)
return this.form.amount * this.application.service?.price;
return 0;
}
}
});
</script>
<style lang="scss">
.price {
font-size: 20px;
font-weight: bold;
}
</style>
+2 -1
View File
@@ -1,4 +1,5 @@
export default {
goDocument: '查看文档',
buyMore: '购买更多'
buyMore: '购买更多',
createOrder: '创建订单'
};
+3 -1
View File
@@ -3,5 +3,7 @@ export default {
usedCount: '已使用次数',
apiKey: 'API Key',
service: '服务',
operation: '操作'
operation: '操作',
amount: '数量',
shouldPayPrice: '应付金额',
};
+3 -1
View File
@@ -1,9 +1,11 @@
import field from './field';
import button from './button';
import message from './message';
import title from './title';
export default {
field,
button,
message
message,
title
};
+3
View File
@@ -0,0 +1,3 @@
export default {
buyService: '购买服务'
};
+2 -1
View File
@@ -3,5 +3,6 @@ export default {
amount: '金额',
price: '金额',
description: '订单描述',
state: '状态'
state: '状态',
createdAt: '创建时间'
};
+3 -1
View File
@@ -1,9 +1,11 @@
import field from './field';
import button from './button';
import message from './message';
import state from './state';
export default {
field,
button,
message
message,
state
};
+4 -1
View File
@@ -1 +1,4 @@
export default {};
export default {
paidSuccessfully: '支付成功',
createFailed: '创建失败'
};
+6
View File
@@ -0,0 +1,6 @@
export default {
pending: '待支付',
paid: '已支付',
expired: '支付超时',
failed: '支付失败'
};
+10 -8
View File
@@ -1,21 +1,23 @@
import { IService } from '../service';
import { IApplication } from '../application';
export const ORDER_STATE_PENDING = 'Pending';
export const ORDER_STATE_PAID = 'Paid';
export const ORDER_STATE_EXPIRED = 'Expired';
export const ORDER_STATE_FAILED = 'Failed';
export enum OrderState {
PENDING = 'Pending',
PAID = 'Paid',
EXPIRED = 'Expired',
FAILED = 'Failed'
}
export interface IOrder {
id?: string;
description?: string;
state?: typeof ORDER_STATE_PENDING | typeof ORDER_STATE_PAID | typeof ORDER_STATE_EXPIRED | typeof ORDER_STATE_FAILED;
state?: OrderState;
price?: number;
amount?: number;
user_id?: number;
created_at?: string;
updated_at?: string;
service?: IService;
service_id?: string;
application?: IApplication;
application_id?: string;
wechatpay_url?: string;
alipay_url?: string;
}
+1
View File
@@ -6,6 +6,7 @@ export interface IOrderQuery {
user_id?: string;
offset?: number;
limit?: number;
ordering: string;
}
class OrderService {
+28 -41
View File
@@ -39,10 +39,10 @@
<el-table-column>
<template #default="scope">
<div class="float-right">
<el-button @click="onGoDocument(scope.row.service)">
<el-button v-if="false" @click="onGoDocument(scope.row)">
{{ $t('application.button.goDocument') }}
</el-button>
<el-button type="primary" @click="onBuyMore(scope.row.service)">
<el-button type="primary" @click="onBuyMore(scope.row)">
{{ $t('application.button.buyMore') }}
</el-button>
</div>
@@ -61,37 +61,26 @@
</el-row>
</el-col>
</el-row>
<el-dialog v-model="buying" title="Warning" width="30%" center>
<span> It should be noted that the content will not be aligned in center by default </span>
<template #footer>
<span class="dialog-footer">
<el-button @click="buying = false">Cancel</el-button>
<el-button type="primary" @click="onCreateOrder()"> Confirm </el-button>
</span>
</template>
</el-dialog>
<create-order v-if="active.application" :visible="buying" :application="active.application" @hide="buying = false" />
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import {
applicationOperator,
IApplication,
IApplicationListResponse,
IOrderDetailResponse,
IService,
orderOperator
} from '@/operators';
import { applicationOperator, IApplication, IApplicationListResponse, IService } from '@/operators';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import Pagination from '@/components/common/Pagination.vue';
import CopyToClipboard from '@/components/common/CopyToClipboard.vue';
import CreateOrder from '@/components/order/Create.vue';
interface IData {
applications: IApplication[];
loading: boolean;
total: number | undefined;
limit: number;
page: number;
buying: boolean;
form: {
amount: number | undefined;
};
active: {
service: IService | undefined;
application: IApplication | undefined;
@@ -103,7 +92,8 @@ export default defineComponent({
components: {
FontAwesomeIcon,
Pagination,
CopyToClipboard
CopyToClipboard,
CreateOrder
},
data(): IData {
return {
@@ -112,41 +102,39 @@ export default defineComponent({
total: undefined,
buying: false,
limit: 8,
form: {
amount: 1
},
active: {
service: undefined,
application: undefined
},
page: parseInt(this.$route.query.page?.toString() || '1')
}
};
},
computed: {
redirect() {
return this.$route.query.redirect;
},
page() {
return parseInt(this.$route.query.page?.toString() || '1');
}
},
watch: {
page: {
handler() {
this.onFetchData();
}
}
},
watch: {},
mounted() {
this.onFetchData();
},
methods: {
onBuyMore(service: IService) {
this.active.service = service;
onGoDocument(application: IApplication) {},
onBuyMore(application: IApplication) {
this.active.application = application;
this.buying = true;
},
onGoDocument(service: IService) {},
onCreateOrder() {
if (!this.active?.service?.id) {
return;
}
orderOperator
.create({
service_id: this.active?.service?.id,
amount: 10
})
.then(({ data: data }: { data: IOrderDetailResponse }) => {
console.log('data', data);
});
},
onPageChange(page: number) {
this.$router.push({
name: this.$route.name?.toString(),
@@ -154,7 +142,6 @@ export default defineComponent({
page: page
}
});
this.onFetchData();
},
onFetchData() {
this.loading = true;
+223
View File
@@ -0,0 +1,223 @@
<template>
<el-row class="wrapper">
<el-col :span="24">
<el-row>
<el-col :span="24">
<h2 class="title">{{ $t('common.title.allOrders') }}</h2>
</el-col>
</el-row>
<el-row class="panel">
<el-col :span="24">
<el-card shadow="hover">
<el-row>
<el-col :span="12" :offset="6">
<div class="order">
<el-descriptions :title="$t('course.title.orderInfo')" :column="1">
<el-descriptions-item :label="$t('course.title.orderId')">{{ order?.id }}</el-descriptions-item>
<el-descriptions-item :label="$t('course.title.orderDescription')">
{{ order?.description }}
</el-descriptions-item>
<el-descriptions-item v-if="order?.price" :label="$t('course.title.orderPrice')">
<span class="price">¥{{ (order?.price / 100).toFixed(2) }}</span>
</el-descriptions-item>
</el-descriptions>
</div>
</el-col>
</el-row>
<el-row>
<el-col :span="12" :offset="6">
<el-divider border-style="dashed" />
<div class="payways">
<div
:class="{
payway: true,
wechat: true,
active: payWay === PayWay.WechatPay
}"
>
<span class="payicon wechat"></span>
{{ $t('course.title.payWayWechat') }}
</div>
</div>
</el-col>
</el-row>
<el-row>
<el-col :span="12" :offset="6">
<el-row class="paycodes">
<el-col :span="12">
<div class="paycode wechat">
<qr-code v-if="order?.wechatpay_url" :value="order?.wechatpay_url" :size="200" class="m-auto" />
<p class="help-text">{{ $t('course.message.wechatPayHelp') }}</p>
</div>
</el-col>
<el-col :span="12">
<div class="help-img">
<img src="https://midas.gtimg.cn/enterprise/images/ep_sys_wx_tip.jpg" />
</div>
</el-col>
</el-row>
</el-col>
</el-row>
</el-card>
</el-col>
</el-row>
</el-col>
</el-row>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { IOrder, IOrderDetailResponse, orderOperator, OrderState } from '@/operators/order';
import QrCode from 'qrcode.vue';
import { ElMessage } from 'element-plus';
enum PayWay {
WechatPay = 'WechatPay',
AliPay = 'AliPay'
}
interface IData {
PayWay: typeof PayWay;
payWay: PayWay | undefined;
order: IOrder | undefined;
loading: boolean;
}
export default defineComponent({
name: 'ConsoleOrderDetail',
components: {
QrCode
},
data(): IData {
return {
PayWay: PayWay,
payWay: PayWay.WechatPay,
order: undefined,
loading: false
};
},
computed: {
id() {
return this.$route.params.id.toString();
},
redirect() {
return this.$route.query.redirect;
}
},
watch: {},
mounted() {
this.onFetchData();
this.onCheck();
},
methods: {
onFetchData() {
this.loading = true;
orderOperator
.get(this.id)
.then(({ data: data }: { data: IOrderDetailResponse }) => {
this.order = data;
this.loading = false;
})
.catch(() => {
this.loading = false;
});
},
onCheck() {
orderOperator
.get(this.id)
.then(({ data: data }: { data: IOrderDetailResponse }) => {
this.order = data;
if (this.order.state === OrderState.PAID) {
ElMessage.success(this.$t('order.message.paidSuccessfully'));
setTimeout(() => {
if (this.redirect) {
window.location.replace(this.redirect?.toString());
}
}, 2000);
return;
}
setTimeout(() => {
this.onCheck();
}, 2000);
})
.catch(() => {
setTimeout(() => {
this.onCheck();
}, 2000);
});
}
}
});
</script>
<style lang="scss" scoped>
.title {
font-size: 26px;
font-weight: bold;
margin-bottom: 20px;
color: #333;
}
.wrapper {
padding: 30px;
.panel {
.order {
.price {
font-size: 20px;
font-weight: bold;
}
}
.payways {
overflow: hidden;
.payway {
cursor: pointer;
font-size: 14px;
float: left;
width: 120px;
line-height: 40px;
text-align: center;
height: 40px;
border: 1px solid #eee;
&.active {
border: 1px solid #3879d1;
}
}
.payicon {
width: 20px;
height: 20px;
margin-top: 2px;
display: inline-block;
&.wechat {
position: relative;
top: 3px;
width: 22px;
height: 19px;
background-image: url(//midas.gtimg.cn/enterprise/images/ep_new_sprites@2x.png);
background-repeat: no-repeat;
background-size: 60px 250px;
background-position: 0 -50px;
}
}
}
.paycodes {
padding: 30px 0;
.wechat {
.help-text {
display: block;
background-color: #00c800;
color: white;
font-size: 14px;
height: 35px;
width: 240px;
text-align: center;
line-height: 35px;
margin: 10px auto 0 auto;
}
}
}
}
}
</style>
+62 -39
View File
@@ -1,16 +1,16 @@
<template>
<el-row class="panel">
<el-row class="wrapper">
<el-col :span="24">
<el-row>
<el-col :span="24">
<h2 class="title">{{ $t('common.title.allOrders') }}</h2>
</el-col>
</el-row>
<el-row>
<el-row class="panel">
<el-col :span="24">
<el-card shadow="hover">
<el-table v-loading="loading" :data="orders" stripe>
<el-table-column prop="id" :label="$t('order.field.id')" class-name="text-center">
<el-table-column prop="id" :label="$t('order.field.id')" class-name="text-center" width="350px">
<template #default="scope">
<span class="key">{{ scope.row.id }}</span>
<span class="copy">
@@ -18,17 +18,53 @@
</span>
</template>
</el-table-column>
<el-table-column prop="price" :label="$t('order.field.price')">
<el-table-column :label="$t('order.field.price')">
<template #default="scope">
<span class="key">{{ scope.row.price }}</span>
<span class="price">¥{{ (scope.row?.price / 100).toFixed(2) }}</span>
</template>
</el-table-column>
<el-table-column :label="$t('order.field.createdAt')">
<template #default="scope">
<span class="created-at">{{ scope.row.created_at }}</span>
</template>
</el-table-column>
<el-table-column :label="$t('order.field.description')">
<template #default="scope">
<span class="description">{{ scope.row.description }}</span>
</template>
</el-table-column>
<el-table-column prop="state" :label="$t('order.field.state')" class-name="text-center">
<template #default="scope">
<span v-if="scope.row.state === OrderState?.PENDING">
<el-tag type="info" class="mx-1" effect="dark">{{ $t('order.state.pending') }}</el-tag>
</span>
<span v-else-if="scope.row.state === OrderState?.PAID" class="state state-paid">
<el-tag type="success" class="mx-1" effect="dark">{{ $t('order.state.paid') }}</el-tag>
</span>
<span v-else-if="scope.row.state === OrderState?.EXPIRED" class="state state-expired">
<el-tag type="warning" class="mx-1" effect="dark">{{ $t('order.state.expired') }}</el-tag>
</span>
<span v-else-if="scope.row.state === OrderState?.FAILED" class="state state-failed">
<el-tag type="danger" class="mx-1" effect="dark"> {{ $t('order.state.failed') }}</el-tag>
</span>
</template>
</el-table-column>
<el-table-column prop="state" :label="$t('order.field.state')" class-name="text-center" />
<el-table-column>
<template #default="scope">
<div class="float-right">
<el-button type="primary" @click="onContinuePay(scope.row)">
{{ $t('application.button.continuePay') }}
<el-button
v-if="scope.row.state !== OrderState.PAID"
type="primary"
@click="
$router.push({
name: 'console-order-detail',
params: {
id: scope.row.id
}
})
"
>
{{ $t('order.button.continuePay') }}
</el-button>
</div>
</template>
@@ -46,69 +82,56 @@
</el-row>
</el-col>
</el-row>
<el-dialog v-model="paying" title="Warning" width="30%" center>
<span> It should be noted that the content will not be aligned in center by default </span>
<template #footer>
{{ active.order?.wechatpay_url }}
</template>
</el-dialog>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { IOrder, IOrderListResponse, IOrderDetailResponse, orderOperator } from '@/operators/order';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { IOrder, IOrderListResponse, IOrderDetailResponse, orderOperator, OrderState } from '@/operators/order';
import Pagination from '@/components/common/Pagination.vue';
import CopyToClipboard from '@/components/common/CopyToClipboard.vue';
import { IService } from '@/operators/service/models';
interface IData {
orders: IOrder[];
loading: boolean;
total: number | undefined;
limit: number;
page: number;
paying: boolean;
active: {
service: IService | undefined;
order: IOrder | undefined;
};
OrderState: typeof OrderState;
}
export default defineComponent({
name: 'OrderList',
name: 'ConsoleOrderList',
components: {
FontAwesomeIcon,
Pagination,
CopyToClipboard
},
data(): IData {
return {
OrderState: OrderState,
orders: [],
loading: false,
total: undefined,
paying: false,
limit: 8,
active: {
service: undefined,
order: undefined
},
page: parseInt(this.$route.query.page?.toString() || '1')
limit: 8
};
},
computed: {
redirect() {
return this.$route.query.redirect;
},
page() {
return parseInt(this.$route.query.page?.toString() || '1');
}
},
watch: {
page: {
handler() {
this.onFetchData();
}
}
},
watch: {},
mounted() {
this.onFetchData();
},
methods: {
onContinuePay(order: IOrder) {
this.active.order = order;
this.paying = true;
},
onPageChange(page: number) {
this.$router.push({
name: this.$route.name?.toString(),
@@ -116,12 +139,12 @@ export default defineComponent({
page: page
}
});
this.onFetchData();
},
onFetchData() {
this.loading = true;
orderOperator
.getAll({
ordering: '-created_at',
limit: this.limit,
offset: (this.page - 1) * this.limit,
user_id: this.$store.getters.user.id
@@ -151,7 +174,7 @@ export default defineComponent({
margin-bottom: 50px;
}
.panel {
.wrapper {
padding: 30px;
.api-key {
.copy {
+13 -4
View File
@@ -90,7 +90,6 @@ interface IData {
loading: boolean;
total: number | undefined;
limit: number;
page: number;
}
export default defineComponent({
name: 'ServiceList',
@@ -103,10 +102,21 @@ export default defineComponent({
services: [],
loading: true,
total: undefined,
limit: 8,
page: parseInt(this.$route.query.page?.toString() || '1')
limit: 8
};
},
computed: {
page() {
return parseInt(this.$route.query.page?.toString() || '1');
}
},
watch: {
page: {
handler() {
this.onFetchData();
}
}
},
async mounted() {
this.onFetchData();
},
@@ -118,7 +128,6 @@ export default defineComponent({
page: page
}
});
this.onFetchData();
},
onFetchData() {
this.loading = true;
+5
View File
@@ -11,6 +11,11 @@ export default {
name: 'console-order-list',
component: () => import('@/pages/console/order/List.vue')
},
{
path: 'orders/:id',
name: 'console-order-detail',
component: () => import('@/pages/console/order/Detail.vue')
},
{
path: 'applications',
name: 'console-application-list',
+5
View File
@@ -2930,6 +2930,11 @@ purgecss@^4.0.3:
postcss "^8.3.5"
postcss-selector-parser "^6.0.6"
qrcode.vue@^3.3.3:
version "3.3.3"
resolved "https://registry.yarnpkg.com/qrcode.vue/-/qrcode.vue-3.3.3.tgz#00262244311a0ee1956fb7a0e238197ff7e14cfa"
integrity sha512-OsD4tQjIbxg/K6D5ZkWjBdYI9eg9K2i8qeYILdEAX5mdAydSAxV7xKmmZSP/hA12olLqEMZ9ryqDQrwa9jEMgw==
query-string@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/query-string/-/query-string-8.1.0.tgz#e7f95367737219544cd360a11a4f4ca03836e115"