Commit e5374786 authored by 姜登's avatar 姜登

page

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