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