Привилегии
This commit is contained in:
parent
aeb6a879eb
commit
4904775397
@ -1,145 +1,144 @@
|
||||
import { ServiceType, Privilege, Tariff } from "./tariff";
|
||||
|
||||
|
||||
interface DiscountBase {
|
||||
_id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
/** Этап применения скидки */
|
||||
layer?: number;
|
||||
disabled?: boolean;
|
||||
_id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
/** Этап применения скидки */
|
||||
layer?: number;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
export interface PurchasesAmountDiscount extends DiscountBase {
|
||||
conditionType: "purchasesAmount";
|
||||
condition: {
|
||||
purchasesAmount: number;
|
||||
};
|
||||
/** Множитель, на который умножается сумма при применении скидки */
|
||||
factor: number;
|
||||
conditionType: "purchasesAmount";
|
||||
condition: {
|
||||
purchasesAmount: number;
|
||||
};
|
||||
/** Множитель, на который умножается сумма при применении скидки */
|
||||
factor: number;
|
||||
}
|
||||
|
||||
export interface CartPurchasesAmountDiscount extends DiscountBase {
|
||||
conditionType: "cartPurchasesAmount";
|
||||
condition: {
|
||||
cartPurchasesAmount: number;
|
||||
};
|
||||
/** Множитель, на который умножается сумма при применении скидки */
|
||||
factor: number;
|
||||
conditionType: "cartPurchasesAmount";
|
||||
condition: {
|
||||
cartPurchasesAmount: number;
|
||||
};
|
||||
/** Множитель, на который умножается сумма при применении скидки */
|
||||
factor: number;
|
||||
}
|
||||
|
||||
export interface PrivilegeDiscount extends DiscountBase {
|
||||
conditionType: "privilege";
|
||||
condition: {
|
||||
privilege: {
|
||||
id: string;
|
||||
/** Скидка применяется, если значение больше или равно этому значению */
|
||||
value: number;
|
||||
};
|
||||
};
|
||||
target: {
|
||||
products: Array<{
|
||||
privilegeId: string;
|
||||
/** Множитель, на который умножается сумма при применении скидки */
|
||||
factor: number;
|
||||
}>;
|
||||
conditionType: "privilege";
|
||||
condition: {
|
||||
privilege: {
|
||||
id: string;
|
||||
/** Скидка применяется, если значение больше или равно этому значению */
|
||||
value: number;
|
||||
};
|
||||
};
|
||||
target: {
|
||||
products: Array<{
|
||||
privilegeId: string;
|
||||
/** Множитель, на который умножается сумма при применении скидки */
|
||||
factor: number;
|
||||
}>;
|
||||
};
|
||||
}
|
||||
|
||||
export interface ServiceDiscount extends DiscountBase {
|
||||
conditionType: "service";
|
||||
condition: {
|
||||
service: {
|
||||
id: ServiceType;
|
||||
/** Скидка применяется, если значение больше или равно этому значению */
|
||||
value: number;
|
||||
};
|
||||
};
|
||||
target: {
|
||||
service: ServiceType;
|
||||
/** Множитель, на который умножается сумма при применении скидки */
|
||||
factor: number;
|
||||
conditionType: "service";
|
||||
condition: {
|
||||
service: {
|
||||
id: ServiceType;
|
||||
/** Скидка применяется, если значение больше или равно этому значению */
|
||||
value: number;
|
||||
};
|
||||
};
|
||||
target: {
|
||||
service: ServiceType;
|
||||
/** Множитель, на который умножается сумма при применении скидки */
|
||||
factor: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface UserTypeDiscount extends DiscountBase {
|
||||
conditionType: "userType";
|
||||
condition: {
|
||||
userType: string;
|
||||
};
|
||||
target: {
|
||||
IsAllProducts: boolean;
|
||||
/** Множитель, на который умножается сумма при применении скидки */
|
||||
factor: number;
|
||||
};
|
||||
overwhelm: boolean;
|
||||
conditionType: "userType";
|
||||
condition: {
|
||||
userType: string;
|
||||
};
|
||||
target: {
|
||||
IsAllProducts: boolean;
|
||||
/** Множитель, на который умножается сумма при применении скидки */
|
||||
factor: number;
|
||||
};
|
||||
overwhelm: boolean;
|
||||
}
|
||||
|
||||
export interface UserDiscount extends DiscountBase {
|
||||
conditionType: "user";
|
||||
condition: {
|
||||
coupon: string;
|
||||
user: string;
|
||||
};
|
||||
target: {
|
||||
products: Array<{
|
||||
privilegeId: string;
|
||||
/** Множитель, на который умножается сумма при применении скидки */
|
||||
factor: number;
|
||||
}>;
|
||||
};
|
||||
overwhelm: boolean;
|
||||
conditionType: "user";
|
||||
condition: {
|
||||
coupon: string;
|
||||
user: string;
|
||||
};
|
||||
target: {
|
||||
products: Array<{
|
||||
privilegeId: string;
|
||||
/** Множитель, на который умножается сумма при применении скидки */
|
||||
factor: number;
|
||||
}>;
|
||||
};
|
||||
overwhelm: boolean;
|
||||
}
|
||||
|
||||
export type AnyDiscount =
|
||||
| PurchasesAmountDiscount
|
||||
| CartPurchasesAmountDiscount
|
||||
| PrivilegeDiscount
|
||||
| ServiceDiscount
|
||||
| UserTypeDiscount
|
||||
| UserDiscount;
|
||||
| PurchasesAmountDiscount
|
||||
| CartPurchasesAmountDiscount
|
||||
| PrivilegeDiscount
|
||||
| ServiceDiscount
|
||||
| UserTypeDiscount
|
||||
| UserDiscount;
|
||||
|
||||
export type DiscountConditionType = AnyDiscount["conditionType"];
|
||||
|
||||
export interface Promocode {
|
||||
id: string;
|
||||
name: string;
|
||||
endless: boolean;
|
||||
from: string;
|
||||
dueTo: string;
|
||||
privileges: Privilege[];
|
||||
id: string;
|
||||
name: string;
|
||||
endless: boolean;
|
||||
from: string;
|
||||
dueTo: string;
|
||||
privileges: Privilege[];
|
||||
}
|
||||
|
||||
export interface CartItem {
|
||||
id: string;
|
||||
tariff: Tariff;
|
||||
/** Посчитанная цена пункта корзины */
|
||||
price: number;
|
||||
id: string;
|
||||
tariff: Tariff;
|
||||
/** Посчитанная цена пункта корзины */
|
||||
price: number;
|
||||
}
|
||||
|
||||
/** Пункт корзины с уже примененными скидками */
|
||||
export interface CartItemTotal {
|
||||
/** Массив с id примененных скидок */
|
||||
envolvedDiscounts: (PrivilegeDiscount | UserDiscount)[];
|
||||
totalPrice: number;
|
||||
tariff: Tariff;
|
||||
/** Массив с id примененных скидок */
|
||||
envolvedDiscounts: (PrivilegeDiscount | UserDiscount)[];
|
||||
totalPrice: number;
|
||||
tariff: Tariff;
|
||||
}
|
||||
|
||||
export type ServiceToPriceMap = {
|
||||
[Key in ServiceType]: number;
|
||||
[Key in ServiceType]: number;
|
||||
};
|
||||
|
||||
export type ServiceToDiscountMap = {
|
||||
[Key in ServiceType]: ServiceDiscount | null;
|
||||
[Key in ServiceType]: ServiceDiscount | null;
|
||||
};
|
||||
|
||||
export interface CartTotal {
|
||||
items: CartItemTotal[];
|
||||
totalPrice: number;
|
||||
priceByService: ServiceToPriceMap;
|
||||
/** Скидки по сервисам */
|
||||
discountsByService: ServiceToDiscountMap;
|
||||
/** Учтенные скидки типов userType, cartPurchasesAmount, totalPurchasesAmount */
|
||||
envolvedCartDiscounts: (UserTypeDiscount | CartPurchasesAmountDiscount | PurchasesAmountDiscount)[];
|
||||
couponState: "applied" | "not found" | null;
|
||||
items: CartItemTotal[];
|
||||
totalPrice: number;
|
||||
priceByService: ServiceToPriceMap;
|
||||
/** Скидки по сервисам */
|
||||
discountsByService: ServiceToDiscountMap;
|
||||
/** Учтенные скидки типов userType, cartPurchasesAmount, totalPurchasesAmount */
|
||||
envolvedCartDiscounts: (UserTypeDiscount | CartPurchasesAmountDiscount | PurchasesAmountDiscount)[];
|
||||
couponState: "applied" | "not found" | null;
|
||||
}
|
44
src/model/discount.ts
Normal file
44
src/model/discount.ts
Normal file
@ -0,0 +1,44 @@
|
||||
export type Discount = {
|
||||
ID: string;
|
||||
Name: string;
|
||||
Layer: number;
|
||||
Description: string;
|
||||
Condition: {
|
||||
Period?: {
|
||||
From: string;
|
||||
To: string;
|
||||
};
|
||||
User?: string;
|
||||
UserType?: string;
|
||||
Coupon?: string;
|
||||
PurchasesAmount?: number;
|
||||
CartPurchasesAmount?: number;
|
||||
Product?: string;
|
||||
Term?: string;
|
||||
Usage?: string;
|
||||
PriceFrom?: number;
|
||||
Group?: string;
|
||||
};
|
||||
Target: {
|
||||
Products?: {
|
||||
ID: string;
|
||||
Factor: number;
|
||||
Overhelm: boolean;
|
||||
}[];
|
||||
Factor?: number;
|
||||
TargetScope?: string;
|
||||
TargetGroup?: string;
|
||||
Overhelm?: boolean;
|
||||
};
|
||||
Audit: {
|
||||
UpdatedAt: string;
|
||||
CreatedAt: string;
|
||||
DeletedAt: string;
|
||||
Deleted: boolean;
|
||||
};
|
||||
Deprecated: boolean;
|
||||
};
|
||||
|
||||
export type DiscountData = {
|
||||
Discounts: Discount[];
|
||||
};
|
@ -1,3 +1,5 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
import { Box, Button, styled, useTheme } from "@mui/material";
|
||||
import { DataGrid, GridColDef, GridRowsProp, GridToolbar } from "@mui/x-data-grid";
|
||||
import { findDiscountFactor, formatDiscountFactor } from "@root/kitUI/Cart/calc";
|
||||
@ -8,8 +10,8 @@ import {
|
||||
useDiscountStore,
|
||||
} from "@root/stores/discounts";
|
||||
import axios from "axios";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import type { DiscountData } from "@root/model/discount";
|
||||
|
||||
const BoxButton = styled("div")(({ theme }) => ({
|
||||
[theme.breakpoints.down(400)]: {
|
||||
@ -64,17 +66,21 @@ const columns: GridColDef[] = [
|
||||
|
||||
export default function DiscountDataGrid() {
|
||||
const theme = useTheme();
|
||||
const discounts = useDiscountStore((state) => state.discounts);
|
||||
const exampleDiscounts = useDiscountStore((state) => state.discounts);
|
||||
const selectedDiscountIds = useDiscountStore((state) => state.selectedDiscountIds);
|
||||
|
||||
const [discount, setDiscount] = useState();
|
||||
const [discount, setDiscount] = useState<DiscountData>();
|
||||
|
||||
const mergeDiscount = [...(discount?.Discounts ?? []), ...exampleDiscounts];
|
||||
|
||||
console.log(mergeDiscount);
|
||||
|
||||
useEffect(() => {
|
||||
const axiosDiscount = async () => {
|
||||
try {
|
||||
const { data } = await axios({
|
||||
method: "get",
|
||||
url: "https://penahub.gitlab.yandexcloud.net/price/discount/all",
|
||||
url: "https://admin.pena.digital/price/discounts",
|
||||
});
|
||||
setDiscount(data);
|
||||
console.log(data);
|
||||
@ -86,7 +92,7 @@ export default function DiscountDataGrid() {
|
||||
axiosDiscount();
|
||||
}, []);
|
||||
|
||||
const discountsGridData: GridRowsProp = discounts.map((discount) => {
|
||||
const discountsGridData: GridRowsProp = exampleDiscounts.map((discount) => {
|
||||
const value =
|
||||
(discount.condition as any).purchasesAmount ??
|
||||
(discount.condition as any).cartPurchasesAmount ??
|
||||
|
Loading…
Reference in New Issue
Block a user