|
@@ -267,6 +267,10 @@ class CActService {
|
|
|
|
|
|
// оплата за всю регистрацию
|
|
// оплата за всю регистрацию
|
|
if (activity.paymentConfig === "PER_REGISTRATION") {
|
|
if (activity.paymentConfig === "PER_REGISTRATION") {
|
|
|
|
+const isPaid = await this.checkActivityRegPayment({
|
|
|
|
+ activityRegId,
|
|
|
|
+ });
|
|
|
|
+ if (isPaid) {
|
|
await updPool.query(sql.unsafe`
|
|
await updPool.query(sql.unsafe`
|
|
update act.activity_regs
|
|
update act.activity_regs
|
|
set is_paid = true
|
|
set is_paid = true
|
|
@@ -285,6 +289,7 @@ class CActService {
|
|
'Оплачено'
|
|
'Оплачено'
|
|
)
|
|
)
|
|
`);
|
|
`);
|
|
|
|
+}
|
|
|
|
|
|
// TODO: QR
|
|
// TODO: QR
|
|
}
|
|
}
|
|
@@ -295,34 +300,12 @@ class CActService {
|
|
throw Error("peId not found");
|
|
throw Error("peId not found");
|
|
}
|
|
}
|
|
|
|
|
|
- const members = await selPool.any(sql.type(
|
|
|
|
- z.object({
|
|
|
|
- peMemberId: DbSchema.act.peMembers.peMemberId,
|
|
|
|
- userId: DbSchema.act.peMembers.userId,
|
|
|
|
- }),
|
|
|
|
- )`
|
|
|
|
- select
|
|
|
|
- pm.pe_member_id "peMemberId",
|
|
|
|
- pm.user_id "userId"
|
|
|
|
- from
|
|
|
|
- act.pe_members pm
|
|
|
|
- where
|
|
|
|
- pm.pe_id = ${actReg.peId}
|
|
|
|
- `);
|
|
|
|
-
|
|
|
|
- const memberIds = members.map((member) => member.peMemberId);
|
|
|
|
-
|
|
|
|
- const paidMemberRows = await selPool.any(sql.unsafe`
|
|
|
|
- select distinct
|
|
|
|
- oi.pe_member_id -- Выбираем ID тех, кто заплатил
|
|
|
|
- from
|
|
|
|
- shop.order_items oi
|
|
|
|
- where
|
|
|
|
- oi.pe_member_id = ANY(${sql.array(memberIds, "uuid")})
|
|
|
|
- and oi.status = 'PAID'
|
|
|
|
- `);
|
|
|
|
|
|
+ const isAllPaid = await this.checkMembersPayment({
|
|
|
|
+ activityRegId,
|
|
|
|
+ peId: actReg.peId,
|
|
|
|
+ });
|
|
|
|
|
|
- if (memberIds.length !== paidMemberRows.length) {
|
|
|
|
|
|
+ if (isAllPaid) {
|
|
await updPool.query(sql.unsafe`
|
|
await updPool.query(sql.unsafe`
|
|
update act.activity_regs
|
|
update act.activity_regs
|
|
set is_paid = false
|
|
set is_paid = false
|
|
@@ -350,6 +333,55 @@ class CActService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ async checkMembersPayment({
|
|
|
|
+ peId,
|
|
|
|
+ activityRegId,
|
|
|
|
+ }: {
|
|
|
|
+ peId: string;
|
|
|
|
+ activityRegId: string;
|
|
|
|
+ }) {
|
|
|
|
+ const members = await selPool.any(sql.type(
|
|
|
|
+ z.object({
|
|
|
|
+ peMemberId: DbSchema.act.peMembers.peMemberId,
|
|
|
|
+ userId: DbSchema.act.peMembers.userId,
|
|
|
|
+ }),
|
|
|
|
+ )`
|
|
|
|
+ select
|
|
|
|
+ pm.pe_member_id "peMemberId",
|
|
|
|
+ pm.user_id "userId"
|
|
|
|
+ from
|
|
|
|
+ act.pe_members pm
|
|
|
|
+ where
|
|
|
|
+ pm.pe_id = ${peId}
|
|
|
|
+ `);
|
|
|
|
+
|
|
|
|
+ const memberIds = members.map((member) => member.peMemberId);
|
|
|
|
+
|
|
|
|
+ const paidMemberRows = await selPool.any(sql.unsafe`
|
|
|
|
+ select distinct
|
|
|
|
+ oi.pe_member_id -- Выбираем ID тех, кто заплатил
|
|
|
|
+ from
|
|
|
|
+ shop.order_items oi
|
|
|
|
+ where
|
|
|
|
+ oi.pe_member_id = ANY(${sql.array(memberIds, "uuid")})
|
|
|
|
+ and oi.status = 'PAID'
|
|
|
|
+ and oi.activity_reg_id = ${activityRegId}
|
|
|
|
+ `);
|
|
|
|
+
|
|
|
|
+ return memberIds.length === paidMemberRows.length;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async checkActivityRegPayment({ activityRegId }: { activityRegId: string }) {
|
|
|
|
+ const isPaid = await selPool.exists(sql.unsafe`
|
|
|
|
+ select 1
|
|
|
|
+ from shop.order_items oi
|
|
|
|
+ where oi.activity_reg_id = ${activityRegId}
|
|
|
|
+ and oi.status = 'PAID'
|
|
|
|
+ `);
|
|
|
|
+
|
|
|
|
+ return !!isPaid;
|
|
|
|
+ }
|
|
|
|
+
|
|
async checkActRegOwner(userId: string, activityRegId: string) {
|
|
async checkActRegOwner(userId: string, activityRegId: string) {
|
|
const actReg = await this.getActReg(activityRegId);
|
|
const actReg = await this.getActReg(activityRegId);
|
|
if (!actReg) {
|
|
if (!actReg) {
|