fix:提交修复6个问题
This commit is contained in:
@@ -61,6 +61,7 @@ async function main() {
|
||||
bankAccountName: '郑州合伙人公司',
|
||||
bankAccountNo: '6222021234567890',
|
||||
bankBranch: '工商银行郑州分行',
|
||||
weeklyStoreTarget: 20,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -150,6 +151,22 @@ async function main() {
|
||||
},
|
||||
});
|
||||
|
||||
const primaryAccount = await prisma.partnerAccount.findUniqueOrThrow({
|
||||
where: { phone: '13700000001' },
|
||||
});
|
||||
|
||||
await prisma.partnerAccount.create({
|
||||
data: {
|
||||
partnerId: partner.id,
|
||||
phone: '13700000002',
|
||||
name: '拓店员小李',
|
||||
isPrimary: 0,
|
||||
parentAccountId: primaryAccount.id,
|
||||
staffRole: 'INTERNAL',
|
||||
status: 'DISABLED',
|
||||
},
|
||||
});
|
||||
|
||||
const storeDefs = [
|
||||
{
|
||||
name: '郑州老城店',
|
||||
@@ -173,6 +190,7 @@ async function main() {
|
||||
},
|
||||
];
|
||||
|
||||
const createdStores: { id: bigint; name: string }[] = [];
|
||||
for (const def of storeDefs) {
|
||||
const store = await prisma.store.create({
|
||||
data: {
|
||||
@@ -201,8 +219,42 @@ async function main() {
|
||||
data: { storeId: store.id, phone: def.phone, name: def.name },
|
||||
});
|
||||
}
|
||||
createdStores.push({ id: store.id, name: def.name });
|
||||
}
|
||||
|
||||
const weekStart = (() => {
|
||||
const d = new Date();
|
||||
d.setHours(12, 0, 0, 0);
|
||||
const day = d.getDay();
|
||||
const diff = day === 0 ? 6 : day - 1;
|
||||
d.setDate(d.getDate() - diff);
|
||||
d.setHours(10, 0, 0, 0);
|
||||
return d;
|
||||
})();
|
||||
|
||||
const newWeekStore = await prisma.store.create({
|
||||
data: {
|
||||
cityId: city.id,
|
||||
partnerId: partner.id,
|
||||
categoryId: categories[0].id,
|
||||
name: '本周新签体验店',
|
||||
phone: '13910000003',
|
||||
province: '河南省',
|
||||
cityName: '郑州市',
|
||||
district: '中原区',
|
||||
address: '建设路88号',
|
||||
intro: '本周新签约门店',
|
||||
status: 'OPEN',
|
||||
openTime: '10:00',
|
||||
closeTime: '22:00',
|
||||
bankAccountName: '本周新签体验店',
|
||||
bankAccountNo: '6222029876543211',
|
||||
bankBranch: '农业银行郑州分行',
|
||||
createdAt: new Date(weekStart.getTime() + 2 * 24 * 60 * 60 * 1000),
|
||||
},
|
||||
});
|
||||
createdStores.push({ id: newWeekStore.id, name: newWeekStore.name });
|
||||
|
||||
await prisma.user.create({
|
||||
data: {
|
||||
userNo: 'DK88293401',
|
||||
@@ -244,6 +296,91 @@ async function main() {
|
||||
},
|
||||
});
|
||||
|
||||
const user = await prisma.user.findUniqueOrThrow({ where: { phone: '13800000001' } });
|
||||
const product = products[0];
|
||||
|
||||
const orderDefs = [
|
||||
{ dayOffset: 0, payAmount: 1198, quantity: 2 },
|
||||
{ dayOffset: 1, payAmount: 599, quantity: 1 },
|
||||
{ dayOffset: 2, payAmount: 1760, quantity: 2 },
|
||||
{ dayOffset: 4, payAmount: 1299, quantity: 1 },
|
||||
{ dayOffset: 5, payAmount: 880, quantity: 1 },
|
||||
];
|
||||
|
||||
const coupons: { id: bigint; balance: number }[] = [];
|
||||
for (const [index, def] of orderDefs.entries()) {
|
||||
const paidAt = new Date(weekStart.getTime() + def.dayOffset * 24 * 60 * 60 * 1000 + 14 * 60 * 60 * 1000);
|
||||
const listAmount = def.payAmount;
|
||||
const order = await prisma.order.create({
|
||||
data: {
|
||||
orderNo: `WK${Date.now()}${index}`,
|
||||
userId: user.id,
|
||||
cityId: city.id,
|
||||
status: 'COMPLETED',
|
||||
payStatus: 'PAID',
|
||||
deliveryType: 'LOCAL',
|
||||
productId: product.id,
|
||||
barcode69: product.barcode69,
|
||||
productName: product.name,
|
||||
productSpec: product.spec,
|
||||
quantity: def.quantity,
|
||||
listUnitPrice: product.price,
|
||||
listAmount,
|
||||
productAmount: listAmount,
|
||||
payAmount: listAmount,
|
||||
benefitAmount: listAmount,
|
||||
receiverName: '测试用户',
|
||||
receiverPhone: user.phone,
|
||||
receiverAddress: '郑州市金水区测试路1号',
|
||||
receiverProvince: '河南省',
|
||||
receiverCity: '郑州市',
|
||||
receiverDistrict: '金水区',
|
||||
paidAt,
|
||||
completedAt: paidAt,
|
||||
},
|
||||
});
|
||||
const coupon = await prisma.benefitCoupon.create({
|
||||
data: {
|
||||
couponNo: `CPN${Date.now()}${index}`,
|
||||
userId: user.id,
|
||||
orderId: order.id,
|
||||
totalAmount: listAmount,
|
||||
balance: listAmount,
|
||||
sourceProduct: product.name,
|
||||
},
|
||||
});
|
||||
coupons.push({ id: coupon.id, balance: listAmount });
|
||||
}
|
||||
|
||||
const redeemDefs = [
|
||||
{ storeIndex: 0, amount: 42800, dayOffset: 1 },
|
||||
{ storeIndex: 1, amount: 38400, dayOffset: 2 },
|
||||
{ storeIndex: 2, amount: 31200, dayOffset: 3 },
|
||||
];
|
||||
for (const [index, def] of redeemDefs.entries()) {
|
||||
const coupon = coupons[index];
|
||||
const store = createdStores[def.storeIndex];
|
||||
const createdAt = new Date(weekStart.getTime() + def.dayOffset * 24 * 60 * 60 * 1000 + 16 * 60 * 60 * 1000);
|
||||
await prisma.redeemRecord.create({
|
||||
data: {
|
||||
redeemNo: `RD${Date.now()}${index}`,
|
||||
userId: user.id,
|
||||
couponId: coupon.id,
|
||||
storeId: store.id,
|
||||
amount: def.amount,
|
||||
settleAmount: Math.round(def.amount * 0.6 * 100) / 100,
|
||||
createdAt,
|
||||
},
|
||||
});
|
||||
await prisma.benefitCoupon.update({
|
||||
where: { id: coupon.id },
|
||||
data: {
|
||||
usedAmount: def.amount,
|
||||
balance: Math.max(0, coupon.balance - def.amount),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
const periodStart = new Date(now.getFullYear(), now.getMonth(), 1);
|
||||
const periodEnd = new Date(now.getFullYear(), now.getMonth() + 1, 0);
|
||||
|
||||
Reference in New Issue
Block a user