Skip to content

Commit

Permalink
支持卡和模型的付费标志
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurunsoft committed Sep 15, 2023
1 parent 39fe592 commit fd912a3
Show file tree
Hide file tree
Showing 23 changed files with 369 additions and 121 deletions.
13 changes: 10 additions & 3 deletions admin/src/service/api/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const fetchCardList = async (
type = 0,
activationed: boolean | undefined = undefined,
expired: boolean | undefined = undefined,
paying: boolean | undefined = undefined,
page = 1,
limit = 15
) => {
Expand All @@ -46,12 +47,17 @@ export const fetchCardList = async (
if (expired !== undefined) {
expiredParam = expired ? '1' : '0';
}
let payingParam;
if (paying !== undefined) {
payingParam = paying ? '1' : '0';
}
return request.get<Card.CardListResponse>('/admin/card/list', {
params: {
memberId,
type,
activationed: activationedParam,
expired: expiredParam,
paying: payingParam,
page,
limit
}
Expand Down Expand Up @@ -120,15 +126,16 @@ export const updateCardType = async (
});
};

export const generateCard = async (type: number, count: number, remark = '') => {
export const generateCard = async (type: number, count: number, remark = '', paying = false) => {
return request.post<Card.GenerateCardResponse>('/admin/card/generate', {
type,
count,
remark
remark,
paying
});
};

export const updateCard = async (id: number, data: { remark?: string }) => {
export const updateCard = async (id: number, data: { remark?: string; enable?: boolean; paying?: boolean }) => {
return request.post<Api.BaseResponse>('/admin/card/update', {
id,
...data
Expand Down
2 changes: 2 additions & 0 deletions admin/src/typings/card.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ declare namespace Card {
expireTime: number;
cardType: CardType;
expired: boolean;
enable: boolean;
paying: boolean;
memberInfo: Member.MemberInfo;
ex: CardEx | null;
}
Expand Down
1 change: 1 addition & 0 deletions admin/src/typings/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ declare namespace Config {
interface Model {
model: string;
enable: boolean;
paying: boolean;
inputTokenMultiple: string | number;
outputTokenMultiple: string | number;
maxTokens: number;
Expand Down
13 changes: 11 additions & 2 deletions admin/src/views/card/list/components/generate-card-modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<n-form-item-grid-item label="备注">
<n-input v-model:value="formModel.remark" type="textarea" rows="3" />
</n-form-item-grid-item>
<n-form-item-grid-item label="付费标志">
<n-switch v-model:value="formModel.paying" />
</n-form-item-grid-item>
</n-grid>
</n-form>
</template>
Expand Down Expand Up @@ -62,7 +65,8 @@ const rules: Record<string, FormItemRule | FormItemRule[]> = {
const formModelDefault = {
count: 1,
remark: ''
remark: '',
paying: false
};
const formModel = ref(formModelDefault);
Expand All @@ -76,7 +80,12 @@ async function handleSubmit() {
return;
}
await formRef.value?.validate();
const { data } = await generateCard(props.cardType, formModel.value.count, formModel.value.remark);
const { data } = await generateCard(
props.cardType,
formModel.value.count,
formModel.value.remark,
formModel.value.paying
);
if (data?.code === 0) {
nextTick(() => {
result.value = data.list.join('\r\n');
Expand Down
97 changes: 92 additions & 5 deletions admin/src/views/card/list/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@
value-field="value"
/>
</n-form-item>
<n-form-item label="付费标志">
<n-select
v-model:value="listParams.paying"
class="!w-[140px]"
:options="[
{
text: '全部',
value: -1
},
{
text: '免费',
value: 0
},
{
text: '付费',
value: 1
}
]"
label-field="text"
value-field="value"
/>
</n-form-item>
<n-form-item>
<n-button attr-type="submit" type="primary" @click="getTableData">
<n-icon :component="SearchSharp" size="20" />
Expand All @@ -68,7 +90,7 @@
:loading="loading"
:pagination="pagination"
:row-key="row => row.id"
scroll-x="1024"
scroll-x="1280"
flex-height
remote
class="flex-1-hidden"
Expand All @@ -94,15 +116,17 @@ import { ref, watch } from 'vue';
import type { Ref } from 'vue';
import { useRoute } from 'vue-router';
import type { DataTableColumns } from 'naive-ui';
import { useDialog } from 'naive-ui';
import { CreateOutline, List, SearchSharp } from '@vicons/ionicons5';
import { fetchCardList } from '@/service';
import { fetchCardList, updateCard } from '@/service';
import { useLoading } from '@/hooks';
import { useAdminEnums } from '~/src/store';
import { defaultPaginationProps } from '~/src/utils';
import { useRouterPush } from '~/src/composables';
import GenerateCardModal from './components/generate-card-modal.vue';
import EditRemarkModal from './components/edit-remark-modal.vue';
const dialog = useDialog();
const { routerPush } = useRouterPush();
const route = useRoute();
const { loading, startLoading, endLoading } = useLoading(false);
Expand All @@ -111,6 +135,7 @@ const enums = ref<any>({});
const listParams = ref({
memberId: parseInt(route.query.memberId?.toString() ?? '0'),
expired: 0,
paying: -1,
activationed: -1,
type: parseInt(route.query.type?.toString() ?? '0')
});
Expand Down Expand Up @@ -139,6 +164,7 @@ async function getTableData() {
listParams.value.type,
listParams.value.activationed >= 0 ? Boolean(listParams.value.activationed) : undefined,
listParams.value.expired >= 0 ? Boolean(listParams.value.expired) : undefined,
listParams.value.paying >= 0 ? Boolean(listParams.value.paying) : undefined,
pagination.page,
pagination.pageSize
);
Expand Down Expand Up @@ -227,18 +253,78 @@ const columns: Ref<DataTableColumns<Card.Card>> = ref([
);
}
},
{
title: '付费标志',
key: 'paying',
width: 100,
render(row) {
return (
<n-switch
value={row.paying}
on-update:value={async (value: boolean) => {
dialog.warning({
title: '询问',
content: `是否改为${value ? '付费' : '免费'}标志?`,
positiveText: '确定',
negativeText: '取消',
onPositiveClick: async () => {
const { data } = await updateCard(row.id, { paying: value });
if (data?.code === 0) {
getTableData();
}
}
});
}}
v-slots={{
checked: () => '付费',
unchecked: () => '免费'
}}
/>
);
}
},
{
key: 'enable',
title: '状态',
width: 100,
render: row => {
return (
<n-switch
value={row.enable}
on-update:value={async (value: boolean) => {
dialog.warning({
title: '询问',
content: `是否${value ? '启用' : '禁用'}该卡?`,
positiveText: '确定',
negativeText: '取消',
onPositiveClick: async () => {
const { data } = await updateCard(row.id, { enable: value });
if (data?.code === 0) {
getTableData();
}
}
});
}}
v-slots={{
checked: () => '启用',
unchecked: () => '禁用'
}}
/>
);
}
},
{
title: '创建时间',
key: 'activationTime',
width: 200,
width: 180,
render(row) {
return new Date(row.createTime * 1000).toLocaleString();
}
},
{
title: '激活时间',
key: 'activationTime',
width: 200,
width: 180,
render(row) {
if (row.activationTime > 0) return new Date(row.activationTime * 1000).toLocaleString();
return '未激活';
Expand All @@ -247,7 +333,7 @@ const columns: Ref<DataTableColumns<Card.Card>> = ref([
{
title: '过期时间',
key: 'expireTime',
width: 250,
width: 180,
render(row) {
return row.expireTime > 0
? new Date(row.expireTime * 1000).toLocaleString() + (row.expired ? '(已过期)' : '')
Expand All @@ -274,6 +360,7 @@ const columns: Ref<DataTableColumns<Card.Card>> = ref([
key: 'actions',
title: '操作',
width: 100,
align: 'center',
render: row => {
return (
<n-space>
Expand Down
2 changes: 2 additions & 0 deletions admin/src/views/config/components/model-manager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<th width="130">Token 输入倍率</th>
<th width="130">Token 输出倍率</th>
<th width="130">最大 Token</th>
<th width="70">付费标志</th>
<th>选中提示</th>
<th width="70">启用</th>
<th width="70">删除</th>
Expand All @@ -24,6 +25,7 @@
<n-input-number v-model:value="item.outputTokenMultiple" :min="0" />
</td>
<td><n-input-number v-model:value="item.maxTokens" :min="0" /></td>
<td class="text-center"><n-switch v-model:value="item.paying" /></td>
<td><n-input v-model:value="item.tips" type="textarea" :rows="2" /></td>
<td class="text-center"><n-switch v-model:value="item.enable" /></td>
<td>
Expand Down
12 changes: 6 additions & 6 deletions server/Module/Card/ApiController/Admin/CardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class CardController extends HttpController
Action,
AdminLoginRequired()
]
public function list(int $memberId = 0, int $type = 0, ?bool $activationed = null, ?bool $expired = null, int $page = 1, int $limit = 15): array
public function list(int $memberId = 0, int $type = 0, ?bool $activationed = null, ?bool $expired = null, ?bool $paying = null, int $page = 1, int $limit = 15): array
{
return $this->memberCardService->adminList($memberId, $type, $activationed, $expired, $page, $limit);
return $this->memberCardService->adminList($memberId, $type, $activationed, $expired, $paying, $page, $limit);
}

#[
Expand Down Expand Up @@ -69,9 +69,9 @@ public function memberDetails(int $memberId, int $operationType = 0, int $busine
Route(method: RequestMethod::POST),
AdminLoginRequired()
]
public function generate(int $type, int $count, string $remark = ''): array
public function generate(int $type, int $count, string $remark = '', bool $paying = false): array
{
$cardIds = $this->cardService->generate($type, $count, $remark, AdminMemberUtil::getMemberSession()->getMemberId(), IPUtil::getIP());
$cardIds = $this->cardService->generate($type, $count, $remark, $paying, AdminMemberUtil::getMemberSession()->getMemberId(), IPUtil::getIP());

return [
'list' => $cardIds,
Expand All @@ -86,8 +86,8 @@ public function generate(int $type, int $count, string $remark = ''): array
Route(method: RequestMethod::POST),
AdminLoginRequired()
]
public function update(int $id, ?string $remark = null)
public function update(int $id, ?string $remark = null, ?bool $enable = null, ?bool $paying = null)
{
$this->cardService->update($id, $remark, AdminMemberUtil::getMemberSession()->getMemberId(), IPUtil::getIP());
$this->cardService->update($id, $remark, $enable, $paying, AdminMemberUtil::getMemberSession()->getMemberId(), IPUtil::getIP());
}
}
8 changes: 1 addition & 7 deletions server/Module/Card/ApiController/CardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use app\Module\Member\Annotation\LoginRequired;
use app\Module\Member\Util\MemberUtil;
use app\Module\VCode\Service\VCodeService;
use app\Util\TokensUtil;
use Imi\Aop\Annotation\Inject;
use Imi\Server\Http\Controller\HttpController;
use Imi\Server\Http\Route\Annotation\Action;
Expand Down Expand Up @@ -37,12 +36,7 @@ public function info(): array
{
$memberSession = MemberUtil::getMemberSession();

$balance = $this->memberCardService->getBalance($memberSession->getIntMemberId());

return [
'balance' => $balance,
'balanceText' => TokensUtil::formatChinese($balance),
];
return $this->memberCardService->getMemberBalance($memberSession->getIntMemberId());
}

#[
Expand Down
33 changes: 32 additions & 1 deletion server/Module/Card/Model/Base/CardBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
*
* @Table(name=@ConfigValue(name="@app.models.app\Module\Card\Model\Card.name", default="tb_card"), usePrefix=false, id={"id"}, dbPoolName=@ConfigValue(name="@app.models.app\Module\Card\Model\Card.poolName"))
*
* @DDL(sql="CREATE TABLE `tb_card` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `type` int unsigned NOT NULL COMMENT '卡类型', `member_id` int unsigned NOT NULL DEFAULT '0' COMMENT '用户ID', `amount` bigint NOT NULL COMMENT '初始金额', `left_amount` bigint NOT NULL COMMENT '剩余金额', `enable` bit(1) NOT NULL DEFAULT b'1' COMMENT '是否启用', `create_time` int unsigned NOT NULL COMMENT '创建时间', `activation_time` int unsigned NOT NULL DEFAULT '0' COMMENT '激活时间', `expire_time` int unsigned NOT NULL COMMENT '过期时间', PRIMARY KEY (`id`) USING BTREE, KEY `type` (`member_id`,`type`) USING BTREE, KEY `member_id` (`member_id`,`expire_time`,`left_amount`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=COMPACT COMMENT='卡'")
* @DDL(sql="CREATE TABLE `tb_card` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `type` int unsigned NOT NULL COMMENT '卡类型', `member_id` int unsigned NOT NULL DEFAULT '0' COMMENT '用户ID', `amount` bigint NOT NULL COMMENT '初始金额', `left_amount` bigint NOT NULL COMMENT '剩余金额', `enable` bit(1) NOT NULL DEFAULT b'1' COMMENT '是否启用', `paying` bit(1) NOT NULL DEFAULT b'0' COMMENT '付费标识', `create_time` int unsigned NOT NULL COMMENT '创建时间', `activation_time` int unsigned NOT NULL DEFAULT '0' COMMENT '激活时间', `expire_time` int unsigned NOT NULL COMMENT '过期时间', PRIMARY KEY (`id`) USING BTREE, KEY `type` (`member_id`,`type`) USING BTREE, KEY `member_id` (`member_id`,`expire_time`,`enable`,`paying`,`left_amount`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=COMPACT COMMENT='卡'")
*
* @property int|null $id
* @property int|null $type 卡类型
* @property int|null $memberId 用户ID
* @property int|null $amount 初始金额
* @property int|null $leftAmount 剩余金额
* @property bool|null $enable 是否启用
* @property bool|null $paying 付费标识
* @property int|null $createTime 创建时间
* @property int|null $activationTime 激活时间
* @property int|null $expireTime 过期时间
Expand Down Expand Up @@ -221,6 +222,36 @@ public function setEnable($enable)
return $this;
}

/**
* 付费标识.
* paying.
*
* @Column(name="paying", type="bit", length=1, accuracy=0, nullable=false, default="b'0'", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false)
*/
protected ?bool $paying = false;

/**
* 获取 paying - 付费标识.
*/
public function getPaying(): ?bool
{
return $this->paying;
}

/**
* 赋值 paying - 付费标识.
*
* @param bool|null $paying paying
*
* @return static
*/
public function setPaying($paying)
{
$this->paying = null === $paying ? null : (bool) $paying;

return $this;
}

/**
* 创建时间.
* create_time.
Expand Down
Loading

0 comments on commit fd912a3

Please sign in to comment.