zksu
/
API
forked from yoone/API
1
0
Fork 0

客户评星

This commit is contained in:
cll 2025-07-23 17:29:00 +08:00
parent 343379519b
commit 0fc9554c7f
3 changed files with 39 additions and 6 deletions

View File

@ -6,6 +6,7 @@ import {
Get,
Inject,
Post,
Put,
Query,
} from '@midwayjs/core';
import { CustomerService } from '../service/customer.service';
@ -67,4 +68,16 @@ export class CustomerController {
return errorResponse(error?.message || error);
}
}
@ApiOkResponse({ type: BooleanRes })
@Put('/rate')
async setRate(@Body() params: { id: number; rate: number }) {
try {
await this.customerService.setRate(params);
return successResponse(true);
} catch (error) {
return errorResponse(error?.message || error);
}
}
}

View File

@ -7,4 +7,7 @@ export class Customer {
@Column({ unique: true })
email: string;
@Column()
rate: number;
}

View File

@ -3,6 +3,7 @@ import { InjectEntityModel } from '@midwayjs/typeorm';
import { Order } from '../entity/order.entity';
import { Repository } from 'typeorm';
import { CustomerTag } from '../entity/customer_tag.entity';
import { Customer } from '../entity/customer.entity';
@Provide()
export class CustomerService {
@ -12,6 +13,9 @@ export class CustomerService {
@InjectEntityModel(CustomerTag)
customerTagModel: Repository<CustomerTag>;
@InjectEntityModel(Customer)
customerModel: Repository<Customer>;
async getCustomerList(param: Record<string, any>) {
const {
current = 1,
@ -23,6 +27,7 @@ export class CustomerService {
state,
first_purchase_date,
customerId,
rate,
} = param;
const whereConds: string[] = [];
const havingConds: string[] = [];
@ -42,6 +47,13 @@ export class CustomerService {
)
`);
}
if (rate) {
whereConds.push(`
o.customer_email = (
SELECT email FROM customer WHERE rate = ${Number(rate)}
)
`);
}
if (tags) {
const tagList = tags
@ -85,6 +97,9 @@ export class CustomerService {
(
SELECT id FROM customer c WHERE c.email = o.customer_email
) as customerId,
(
SELECT rate FROM customer c WHERE c.email = o.customer_email
) as rate,
yoone_stats.yoone_orders,
yoone_stats.yoone_total
FROM \`order\` o
@ -99,10 +114,8 @@ export class CustomerService {
GROUP BY oo.customer_email
) yoone_stats ON yoone_stats.customer_email = o.customer_email
${baseQuery}
${
sorterKey
? `ORDER BY ${sorterKey} ${
sorterValue === 'descend' ? 'DESC' : 'ASC'
${sorterKey
? `ORDER BY ${sorterKey} ${sorterValue === 'descend' ? 'DESC' : 'ASC'
}`
: 'ORDER BY orders ASC, yoone_total DESC'
}
@ -148,4 +161,8 @@ export class CustomerService {
.getRawMany();
return tags.map(t => t.tag);
}
async setRate(params: { id: number; rate: number }) {
return await this.customerModel.update(params.id, { rate: params.rate });
}
}