1
This commit is contained in:
@@ -3,6 +3,20 @@ const { build_search_where } = require("../utils/query_helpers");
|
||||
const logic = require("../service/biz_subscription_logic");
|
||||
const audit = require("../utils/biz_audit");
|
||||
|
||||
function subscription_rows_with_names(instances) {
|
||||
return instances.map((r) => {
|
||||
const j = r.toJSON();
|
||||
const u = j.biz_user;
|
||||
const p = j.biz_plan;
|
||||
const { biz_user, biz_plan, ...rest } = j;
|
||||
return {
|
||||
...rest,
|
||||
user_name: u ? [u.name, u.mobile].filter(Boolean).join(" ").trim() : "",
|
||||
plan_name: p ? String(p.plan_name || p.plan_code || "").trim() : "",
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
"POST /biz_subscription/page": async (ctx) => {
|
||||
const body = ctx.getBody();
|
||||
@@ -19,8 +33,13 @@ module.exports = {
|
||||
offset,
|
||||
limit: page_size,
|
||||
order: [["id", "DESC"]],
|
||||
include: [
|
||||
{ model: baseModel.biz_user, as: "biz_user", attributes: ["name", "mobile"] },
|
||||
{ model: baseModel.biz_plan, as: "biz_plan", attributes: ["plan_name", "plan_code"] },
|
||||
],
|
||||
distinct: true,
|
||||
});
|
||||
ctx.success({ rows, count });
|
||||
ctx.success({ rows: subscription_rows_with_names(rows), count });
|
||||
},
|
||||
"GET /biz_subscription/detail": async (ctx) => {
|
||||
const q = ctx.query || {};
|
||||
@@ -95,7 +114,11 @@ module.exports = {
|
||||
where,
|
||||
limit: 10000,
|
||||
order: [["id", "DESC"]],
|
||||
include: [
|
||||
{ model: baseModel.biz_user, as: "biz_user", attributes: ["name", "mobile"] },
|
||||
{ model: baseModel.biz_plan, as: "biz_plan", attributes: ["plan_name", "plan_code"] },
|
||||
],
|
||||
});
|
||||
ctx.success({ rows });
|
||||
ctx.success({ rows: subscription_rows_with_names(rows) });
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user