Commit e5374786 authored by 姜登's avatar 姜登

page

parent 98b6f3e1
# yizhi_platform
# yizhi_server
已知后台
......
......@@ -41,8 +41,9 @@ class PriceController extends Controller {
async index() {
const { ctx, service } = this;
ctx.validate(this.indexRule, ctx.query);
const ret = await service.userDetail.findAll(this.model, { appkey: ctx.query.appKey }, ['pay_type', 'price', 'start_time', 'end_time', 'operator']);
ctx.success(ret);
const ret = await service.userDetail.findAll(this.model, { appkey: ctx.query.appKey }, ['pay_type', 'price', 'start_time', 'end_time', 'operator'], ctx.pagination);
const total = await service.userDetail.count(this.model, { appkey: ctx.query.appKey });
ctx.success({ data: ret, total, ...ctx.pagination });
}
async create() {
......
......@@ -36,8 +36,9 @@ class RechargeController extends Controller {
const { ctx, service } = this;
ctx.validate(this.indexRule, ctx.query);
await service.user.getUserInfo();
const ret = await service.userDetail.findAll(this.model, { user_id: ctx.query.user_id }, ['user_id', 'money', 'receive_time', 'remark', 'operator']);
ctx.success(ret);
const ret = await service.userDetail.findAll(this.model, { user_id: ctx.query.user_id }, ['user_id', 'money', 'receive_time', 'remark', 'operator'], ctx.pagination);
const total = await service.userDetail.count(this.model, { user_id: ctx.query.user_id });
ctx.success({ data: ret, total, ...ctx.pagination });
}
async create() {
......
......@@ -32,8 +32,9 @@ class RemissionController extends Controller {
async index() {
const { ctx, service } = this;
ctx.validate(this.indexRule, ctx.query);
const ret = await service.userDetail.findAll(this.model, { appkey: ctx.query.appKey }, ['appkey', 'start_time', 'count', 'operator']);
ctx.success(ret);
const ret = await service.userDetail.findAll(this.model, { appkey: ctx.query.appKey }, ['appkey', 'start_time', 'count', 'operator'], ctx.pagination);
const total = await service.userDetail.count(this.model, { appkey: ctx.query.appKey });
ctx.success({ data: ret, total, ...ctx.pagination });
}
async create() {
......
......@@ -47,7 +47,12 @@ class UserController extends Controller {
const { ctx, service } = this;
const Op = ctx.app.Sequelize.Op;
ctx.validate(this.indexRule, ctx.query);
const { type } = ctx.query;
const user = await service.user.getUserInfo();
const where = {};
if (type !== 'all') {
where.dd_id = user.id;
where.dd_name = user.name;
Object.keys(ctx.query).forEach(key => {
if (ctx.query[key] && this.indexRule.hasOwnProperty(key)) {
if (key === 'status') {
......@@ -59,8 +64,8 @@ class UserController extends Controller {
}
}
});
const user = await service.user.getUserInfo();
const accountData = await service.user.fetchAccount({ dd_id: user.id, dd_name: user.name, ...where }, ctx.pagination);
}
const accountData = await service.user.fetchAccount(where, ctx.pagination);
const total = await service.user.count({ dd_id: user.id, dd_name: user.name, ...where });
ctx.success({ data: accountData, total, ...ctx.pagination });
}
......
......@@ -4,11 +4,13 @@ const Service = require('egg').Service;
class UserDetailService extends Service {
async findAll(type, where, attributes) {
async findAll(type, where, attributes, { size, page }) {
const { ctx } = this;
return await ctx.yizhiModel[type].findAll({
attributes,
where,
offset: size * (page - 1),
limit: size,
});
}
......@@ -25,6 +27,19 @@ class UserDetailService extends Service {
});
}
async count(type, where = {}) {
const { ctx } = this;
const ret = await ctx.yizhiModel[type].findOne({
attributes: [
[
ctx.yizhiModel.fn('COUNT', ctx.yizhiModel.col('id')), 'total',
],
],
where,
});
return ret.get('total');
}
}
module.exports = UserDetailService;
{
"name": "yizhi_platform",
"name": "yizhi_server",
"version": "1.0.0",
"description": "已知后台",
"private": true,
......@@ -31,8 +31,8 @@
"node": ">=8.9.0"
},
"scripts": {
"start": "egg-scripts start --daemon --title=egg-server-yizhi_platform",
"stop": "egg-scripts stop --title=egg-server-yizhi_platform",
"start": "egg-scripts start --daemon --title=egg-server-yizhi_server",
"stop": "egg-scripts stop --title=egg-server-yizhi_server",
"dev": "egg-bin dev",
"debug": "egg-bin debug",
"test": "npm run lint -- --fix && npm run test-local",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment