Ver código fonte

✨ feat(wechat-coupon): 增加可用数量字段并自动设置初始值

- 在创建微信代金券批次DTO中添加availableQuantity字段,用于记录可用数量
- 前端创建时自动将可用数量设置为总数量,简化用户操作流程
yourname 3 meses atrás
pai
commit
79e7a91d1b

+ 6 - 1
src/client/admin-shadcn/pages/WechatCouponStocks.tsx

@@ -118,7 +118,12 @@ export const WechatCouponStocksPage = () => {
   // 提交创建
   const handleCreateSubmit = async (values: CreateRequest) => {
     try {
-      const res = await wechatCouponStockClient.$post({ json: values })
+      const res = await wechatCouponStockClient.$post({
+        json: {
+          ...values,
+          availableQuantity: values.couponQuantity // 自动设置可用数量等于总数量
+        }
+      })
       if (res.status !== 201) throw new Error('创建失败')
       toast.success('创建成功')
       setIsModalOpen(false)

+ 1 - 0
src/server/modules/wechat-pay/wechat-coupon-stock.schema.ts

@@ -30,6 +30,7 @@ export const CreateWechatCouponStockDto = z.object({
   stockSendRule: z.any().openapi({ description: '批次发放规则' }),
   couponAmount: z.number().int().positive().openapi({ description: '代金券面额(分)', example: 100 }),
   couponQuantity: z.number().int().positive().openapi({ description: '代金券数量', example: 1000 }),
+  availableQuantity: z.number().int().min(0).optional().openapi({ description: '可用数量', example: 1000 }),
   startTime: z.coerce.date().openapi({ description: '开始时间', example: '2024-01-01T00:00:00Z' }),
   endTime: z.coerce.date().openapi({ description: '结束时间', example: '2024-12-31T23:59:59Z' }),
   configId: z.number().int().positive().openapi({ description: '微信支付配置ID', example: 1 })