import request from '@/utils/request'; import type { ApiResult, PageResult } from '@/api'; import {ShopGift, ShopGiftParam, GiftRedeemParam, GiftUseParam, QRCodeParam} from './model'; /** * 分页查询礼品卡 */ export async function pageShopGift(params: ShopGiftParam) { const res = await request.get>>( '/shop/shop-gift/page', params ); if (res.code === 0) { return res.data; } return Promise.reject(new Error(res.message)); } /** * 查询礼品卡列表 */ export async function listShopGift(params?: ShopGiftParam) { const res = await request.get>( '/shop/shop-gift', params ); if (res.code === 0 && res.data) { return res.data; } return Promise.reject(new Error(res.message)); } /** * 添加礼品卡 */ export async function addShopGift(data: ShopGift) { const res = await request.post>( '/shop/shop-gift', data ); if (res.code === 0) { return res.message; } } /** * 生成礼品卡 */ export async function makeShopGift(data: ShopGift) { const res = await request.post>( '/shop/shop-gift/make', data ); if (res.code === 0) { return res.message; } return Promise.reject(new Error(res.message)); } /** * 修改礼品卡 */ export async function updateShopGift(data: ShopGift) { const res = await request.put>( '/shop/shop-gift', data ); if (res.code === 0) { return res.message; } return Promise.reject(new Error(res.message)); } /** * 删除礼品卡 */ export async function removeShopGift(id?: number) { const res = await request.del>( '/shop/shop-gift/' + id ); if (res.code === 0) { return res.message; } return Promise.reject(new Error(res.message)); } /** * 批量删除礼品卡 */ export async function removeBatchShopGift(data: (number | undefined)[]) { const res = await request.del>( '/shop/shop-gift/batch', { data } ); if (res.code === 0) { return res.message; } return Promise.reject(new Error(res.message)); } /** * 根据id查询礼品卡 */ export async function getShopGift(id: number) { const res = await request.get>( '/shop/shop-gift/' + id ); if (res.code === 0 && res.data) { return res.data; } return Promise.reject(new Error(res.message)); } /** * 根据code查询礼品卡 * @param code */ export async function getShopGiftByCode(code: string) { const res = await request.get>( '/shop/shop-gift/by-code/' + code ); if (res.code === 0 && res.data) { return res.data; } return Promise.reject(new Error(res.message)); } /** * 兑换礼品卡 */ export async function redeemGift(params: GiftRedeemParam) { const res = await request.post>( '/shop/shop-gift/redeem', params ); if (res.code === 0) { return res.data; } return Promise.reject(new Error(res.message)); } /** * 使用礼品卡 */ export async function useGift(params: GiftUseParam) { const res = await request.post>( '/shop/shop-gift/use', params ); if (res.code === 0) { return res.message; } return Promise.reject(new Error(res.message)); } /** * 获取用户的礼品卡列表 */ export async function getUserGifts(params: ShopGiftParam) { const res = await request.get>>( '/shop/shop-gift/page', params ); if (res.code === 0) { return res.data; } return Promise.reject(new Error(res.message)); } /** * 验证礼品卡兑换码 */ export async function validateGiftCode(code: string) { const res = await request.get>( `/shop/shop-gift/validate/${code}` ); if (res.code === 0) { return res.data; } return Promise.reject(new Error(res.message)); } export async function exportShopGift(ids?: number[]) { const res = await request.post>( '/shop/shop-gift/export', ids ); if (res.code === 0) { return res.data; } return Promise.reject(new Error(res.message)); } /** * 生成礼品卡核销码(可用) */ export async function generateVerificationCode(data: QRCodeParam) { const res = await request.post>( '/qr-code/create-encrypted-qr-code', data ); if (res.code === 0) { return res.data; } return Promise.reject(new Error(res.message)); } /** * 验证核销码 */ export async function verifyGiftCard(params: { verificationCode?: string; giftCode?: string }) { const res = await request.post>( '/shop/shop-gift/verify', params ); if (res.code === 0) { return res.data; } return Promise.reject(new Error(res.message)); } /** * 完成礼品卡核销 */ export async function completeVerification(params: { giftId: number; verificationCode: string; storeId?: number; storeName?: string; operatorId?: number; operatorName?: string; }) { const res = await request.post>( '/shop/shop-gift/complete-verification', params ); if (res.code === 0) { return res.data; } return Promise.reject(new Error(res.message)); } /** * 解密二维码数据 */ export async function decryptQrData(params: { token: string; encryptedData: string }) { const res = await request.post>( '/qr-code/decrypt-qr-data', params ); if (res.code === 0) { return res.data; } return Promise.reject(new Error(res.message)); }