瀏覽代碼

feat(coupon): 更新优惠券管理接口并优化库存校验逻辑

- 删除无用的 thali 相关接口调用
- 新增删除优惠券接口 delCouponById
- 新增更新优惠券状态接口 updateCouponStatus
- 新增更新优惠券单个库存接口 updateCouponSingleQty
- 优化库存输入校验,新增剩余库存对比检查
- 统一导入接口名称,避免命名冲突
- 修复代金券删除接口调用错误
- 区分代金券与优惠券的上下架逻辑处理
- 区分代金券与优惠券的库存更新逻辑处理
congxuesong 4 周之前
父節點
當前提交
c71a2bd769
共有 2 個文件被更改,包括 33 次插入28 次删除
  1. 6 12
      src/api/modules/couponManagement.ts
  2. 27 16
      src/views/ticketManagement/index.vue

+ 6 - 12
src/api/modules/couponManagement.ts

@@ -2,17 +2,14 @@ import { ResPage, StoreUser } from "@/api/interface/index";
 import { PORT_NONE } from "@/api/config/servicePort";
 import http from "@/api";
 
-export const getThaliList = params => {
-  return http.get<ResPage<StoreUser.ResStoreUserList>>(PORT_NONE + `/PcGroupBuy/getThaliList`, params);
+export const delCouponById = (params: { id: string }) => {
+  return http.get(PORT_NONE + `/discountCouponPlatform/deleteDiscountCoupon`, params);
 };
-export const delThaliById = (params: { id: string }) => {
-  return http.get(PORT_NONE + `/PcGroupBuy/deleteThali`, params);
+export const updateCouponStatus = params => {
+  return http.get(PORT_NONE + `/discountCouponPlatform/cutDiscountCouponStatus`, params);
 };
-export const updateStatus = params => {
-  return http.get(PORT_NONE + `/PcGroupBuy/updateStatus1`, params);
-};
-export const updateNum = params => {
-  return http.get(PORT_NONE + `/PcGroupBuy/updateNum1`, params);
+export const updateCouponSingleQty = params => {
+  return http.get(PORT_NONE + `/discountCouponPlatform/updateCouponSingleQty`, params);
 };
 export const addDiscountCoupon = params => {
   return http.post(PORT_NONE + `/discountCouponPlatform/addDiscountCoupon`, params);
@@ -20,9 +17,6 @@ export const addDiscountCoupon = params => {
 export const editDiscountCoupon = params => {
   return http.post(PORT_NONE + `/discountCouponPlatform/editDiscountCoupon`, params);
 };
-export const getHolidayList = (params: any) => {
-  return http.get<StoreUser.ResStoreUserList>(PORT_NONE + `/couponPlatform/getHolidayList`, params);
-};
 export const getCouponDetail = (params: StoreUser.ReqUserParams) => {
   return http.get<StoreUser.ResStoreUserList>(PORT_NONE + `/discountCouponPlatform/getCounponDetailById`, params);
 };

+ 27 - 16
src/views/ticketManagement/index.vue

@@ -164,13 +164,8 @@ import { ElMessage } from "element-plus";
 import ProTable from "@/components/ProTable/index.vue";
 import { ColumnProps, ProTableInstance } from "@/components/ProTable/interface";
 import { Plus } from "@element-plus/icons-vue";
-import {
-  delThaliById as delVoucherById,
-  getThaliList,
-  updateNum,
-  updateStatus as updateVoucherStatus
-} from "@/api/modules/voucherManagement";
-import { delThaliById as delCouponById, updateStatus as updateCouponStatus } from "@/api/modules/couponManagement";
+import { delThaliById, getThaliList, updateNum, updateStatus } from "@/api/modules/voucherManagement";
+import { delCouponById, updateCouponSingleQty, updateCouponStatus } from "@/api/modules/couponManagement";
 import { ElMessageBox } from "element-plus/es";
 import { localGet, usePermission } from "@/utils";
 
@@ -211,6 +206,12 @@ const rules = reactive<FormRules<RuleForm>>({
             callback(new Error("库存不得大于10000"));
             return;
           }
+          // 验证新库存值不能小于剩余库存
+          const currentQty = Number(formInventory.value.singleQty) || 0;
+          if (numValue < currentQty) {
+            callback(new Error(`库存不能小于剩余库存(${currentQty})`));
+            return;
+          }
         }
         callback();
       },
@@ -563,7 +564,7 @@ const deleteRow = (row: any) => {
           id: row.id,
           groupType: localGet("businessSection")
         };
-        return delVoucherById(params);
+        return delThaliById(params);
       } else {
         // 优惠券删除逻辑
         const params = {
@@ -591,14 +592,14 @@ const handleClick = () => {
 const changeTypes = async (row: any, status: number) => {
   if (isVoucher.value) {
     // 代金券上架/下架逻辑
-    const res = await updateVoucherStatus({ id: row.id, status: status, approvalComments: "" });
+    const res = await updateStatus({ id: row.id, status: status, approvalComments: "" });
     if (res && res.code == 200) {
       ElMessage.success("操作成功");
       proTable.value?.getTableList();
     }
   } else {
     // 优惠券上架/下架逻辑
-    const res = await updateCouponStatus({ id: row.id, status: status, approvalComments: "" });
+    const res = await updateCouponStatus({ counponId: row.id });
     if (res && res.code == 200) {
       ElMessage.success("操作成功");
       proTable.value?.getTableList();
@@ -621,14 +622,24 @@ const handleSubmit = async () => {
   if (!ruleFormRef.value) return;
   await ruleFormRef.value.validate(async valid => {
     if (valid) {
-      const res = await updateNum({
+      const params = {
         id: formInventory.value.id,
         singleQty: formInventory.value.newInventory
-      });
-      if (res && res.code == 200) {
-        ElMessage.success("修改成功");
-        closeDialog();
-        proTable.value?.getTableList();
+      };
+      if (isVoucher.value) {
+        const res = await updateNum(params);
+        if (res && res.code == 200) {
+          ElMessage.success("修改成功");
+          closeDialog();
+          proTable.value?.getTableList();
+        }
+      } else {
+        const res = await updateCouponSingleQty(params);
+        if (res && res.code == 200) {
+          ElMessage.success("修改成功");
+          closeDialog();
+          proTable.value?.getTableList();
+        }
       }
     }
   });