Commit f4a4226f authored by 姜登's avatar 姜登

home

parent 2005bb33
Pipeline #21972 passed with stage
in 2 seconds
......@@ -9,7 +9,9 @@ class AccountController extends Controller {
}
async home() {
const { ctx, service } = this;
const acount_info = await service.user.accountInfo(ctx.userId);
ctx.body = acount_info;
}
async analyse() {
......
......@@ -87,7 +87,7 @@ class UserController extends Controller {
await service.user.getUserInfo();
const { id } = ctx.params;
const { status } = ctx.request.body;
await service.user.update({ user_id: id }, { status });
await service.user.update({ user_id: id }, { status }, 'Account');
ctx.success({ user_id: id });
}
......@@ -104,11 +104,15 @@ class UserController extends Controller {
const { service, ctx } = this;
const input_params = ctx.request.body;
ctx.validate(this.loginRule, input_params);
const user = await service.user.findOne('Account', { account: input_params.passport }, ['user_id', 'password']);
if (!user || user.password !== input_params.password) {
const user = await service.user.findOne('Account', { account: input_params.passport }, ['user_id', 'password', 'status']);
if (!user || user.password !== ctx.helper.Md5(input_params.password)) {
ctx.throw(400, '用户名、密码错误');
}
if (user.status === 0) { //判断账号是否开通
ctx.throw(400, '账户未开通,请联系商务');
}
const token = await service.jwt.apply({ user_id: user.user_id });
ctx.body = { token };
}
......@@ -119,7 +123,24 @@ class UserController extends Controller {
}
async changePwd() {
const { service, ctx } = this;
const input_params = ctx.request.body;
const rule = {
password: {
required: true,
type: 'string'
},
confirm_password: {
required: true,
type: 'string'
},
}
ctx.validate(rule, input_params);
if (input_params.password !== input_params.confirm_password) {
ctx.throw(400, '两次输入密码不一致');
}
await service.user.update({ user_id: ctx.userId }, { password: ctx.helper.Md5(input_params.password) }, 'Account');
ctx.body = { "msg": "修改成功" };
}
}
......
'use strict';
const crypto = require('crypto');
module.exports = {
switchQueryToWhere(data = {}, format = {}, whereList = []) {
const tem = {};
......@@ -15,4 +17,7 @@ module.exports = {
});
return tem;
},
Md5(str) {
return crypto.createHash('md5').update(str, 'utf8').digest('hex');
}
};
......@@ -4,19 +4,19 @@ module.exports = () => {
return async (ctx, next) => {
const token = ctx.request.get('authorization').replace(/Bearer /, '') || '';
if (!token) {
const token_data = await ctx.service.jwt.decode_token(token);
if (!token || !token_data) {
ctx.throw(400, 'jwt failed');
}
const token_data = await ctx.service.jwt.decode_token(token);
const token_black = await ctx.app.memcache.get('yizhi_server_token' + token_data.data.user_id);
// ctx.logger.info('【token_black:】', token_black, token);
if (token_black) ctx.app.logger.info('【sso token black:】', token_black, token);
// if (token_black === token) {
// ctx.failed('token 已失效');
// }
if (token_black === token) {
ctx.failed('token 已失效');
}
ctx.token = token || '';
ctx.userId = token_data.data.user_id || '';
ctx.logger.info('userId:', ctx.userId);
next();
await next();
}
}
\ No newline at end of file
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL } = app.Sequelize;
const yzbillBalance = app.dataModel.define('yzbillBalance', {
user_id: { type: INTEGER, primaryKey: true },
month: INTEGER,
recharge_hs: STRING,
cost_hs: STRING,
balance_bg: STRING,
recharge_m: STRING,
cost_m: STRING,
balance_fn: STRING,
account: STRING,
company: STRING,
name: STRING,
update_time: {
type: DATE,
get() {
const date = this.getDataValue('update_time');
return (date && date.toString() !== 'Invalid Date') ? moment(date).format('YYYY-MM-DD HH:mm:ss') : '0000-00-00 00:00:00';
},
},
}, {
timestamps: false,
tableName: 'yzbill_balance',
});
return yzbillBalance;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL } = app.Sequelize;
const billCost = app.dataModel.define('billCost', {
appKey: { type: INTEGER, primaryKey: true },
service: STRING,
day: STRING,
query_volume: INTEGER,
succ_volume: INTEGER,
pull_volume: INTEGER,
pay_type: INTEGER,
price: DECIMAL,
pay_volume: INTEGER,
less_given: INTEGER,
less_used: INTEGER,
less_balance: INTEGER,
cost: STRING,
user_id: STRING,
account: STRING,
company: STRING,
name: STRING,
update_time: {
type: DATE,
get() {
const date = this.getDataValue('update_time');
return (date && date.toString() !== 'Invalid Date') ? moment(date).format('YYYY-MM-DD HH:mm:ss') : '0000-00-00 00:00:00';
},
},
}, {
timestamps: false,
tableName: 'yzbill_cost',
});
return billCost;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL } = app.Sequelize;
const billCostMonth = app.dataModel.define('billCostMonth', {
appKey: { type: INTEGER, primaryKey: true },
service: STRING,
day_month: STRING,
query_volume: INTEGER,
succ_volume: INTEGER,
pull_volume: INTEGER,
pay_type: INTEGER,
price: DECIMAL,
pay_volume: INTEGER,
less_given: INTEGER,
less_used: INTEGER,
less_balance: INTEGER,
cost: STRING,
user_id: STRING,
account: STRING,
company: STRING,
name: STRING,
update_time: {
type: DATE,
get() {
const date = this.getDataValue('update_time');
return (date && date.toString() !== 'Invalid Date') ? moment(date).format('YYYY-MM-DD HH:mm:ss') : '0000-00-00 00:00:00';
},
},
}, {
timestamps: false,
tableName: 'yzbill_cost_month',
});
return billCostMonth;
};
......@@ -11,5 +11,6 @@ module.exports = app => {
router.resources('/price', controller.price); // 价格明细
router.resources('/recharge', controller.recharge); // 充值信息
router.resources('/remission', controller.remission); // 减免信息
require('./router/user')(app);
require('./router/account')(app);
};
......@@ -4,10 +4,11 @@
* @param {Egg.Application} app - egg application
*/
module.exports = app => {
const { controller } = app;
const { controller, middleware } = app;
const router = app.router.namespace(app.config.projectRootPath + '/account');
router.get('/home', controller.account.home); // 合作方首页信息
router.get('/analyse', controller.account.analyse); // 调用明细
router.put('/analyse/download', controller.account.analyseDownload); // 调用明细下载
const authInit = middleware.authInit();
router.get('/home', authInit, controller.account.home); // 合作方首页信息
router.get('/analyse', authInit, controller.account.analyse); // 调用明细
router.put('/analyse/download', authInit, controller.account.analyseDownload); // 调用明细下载
};
......@@ -4,10 +4,11 @@
* @param {Egg.Application} app - egg application
*/
module.exports = app => {
const { controller } = app;
const { controller, middleware } = app;
const router = app.router.namespace(app.config.projectRootPath + '/user');
const authInit = middleware.authInit();
router.post('/login', controller.user.login); // 用户登录
router.delete('/logout', controller.user.logout); // 用户登出
router.put('/password', controller.user.changePwd); // 修改密码
router.delete('/logout', authInit, controller.user.logout); // 用户登出
router.put('/password', authInit, controller.user.changePwd); // 修改密码
};
'use strict';
const Service = require('egg').Service;
const moment = require('moment');
class UserService extends Service {
......@@ -60,9 +61,9 @@ class UserService extends Service {
return ret.get('total');
}
async update(where, params) {
async update(where, params, type) {
const { ctx } = this;
const ret = await ctx.yizhiModel.Account.findOne({
const ret = await ctx.yizhiModel[type].findOne({
where,
});
if (!ret) {
......@@ -79,5 +80,70 @@ class UserService extends Service {
});
}
async accountInfo(user_id) {
const { ctx } = this;
const { account } = await this.findOne('Account', { user_id }, ['account']);
const account_info = { account_name: account, product: [] };
const product = await ctx.yizhiModel.UserService.findAll({
attributes: ['service', 'appkey'],
where: { user_id },
distinct: true,
});
for (let i = 0; i < product.length; i++) {
account_info.product.push({
id: i,
name: product[i].service
});
}
//昨日调用信息
const lastday_info = {
use_amount: 0,
use_money: 0,
left_money: 0
}
const last_day = moment(new Date()).subtract(1, 'day').format('YYYY-MM-DD');
const last_month = moment(new Date()).subtract(1, 'day').format('YYYYMM');
const lastday_data = await ctx.dataModel.yzBillCost.findOne({
attributes: [
[ctx.model.fn('SUM', 'pull_volumn'), 'amount'],
[ctx.model.fn('SUM', 'cost'), 'cost'],
],
where: { user_id, day: last_day },
})
lastday_info.use_amount = lastday_data.amount || 0;
lastday_info.use_money = lastday_data.cost || 0;
const left_money = await ctx.dataModel.YzBillBalance.findOne({
attributes: ['balance_fn'],
where: { user_id, month: last_month },
})
lastday_info.left_money = left_money.balance_fn || 0;
const detail = []
const bill = await ctx.dataModel.YzBillBalance.findAll({
attributes: ['month', 'company', 'balance_bg', 'recharge_m', 'cost_m', 'balance_fn'],
where: { user_id },
order: [['month', 'DESC']],
})
for (let i = 0; i < bill.length; i++) {
detail.push({
name:bill[i].company,
date:bill[i].month,
start_left:bill[i].balance_bg,
middle_recharge:bill[i].recharge_m,
middlefee:bill[i].cost_m,
endfee:bill[i].balance_fn,
})
}
return {
account_info,
lastday_info,
detail
}
}
}
module.exports = UserService;
......@@ -34,7 +34,7 @@ module.exports = appInfo => {
'/yizhi_server/api/user_service',
'/yizhi_server/api/recharge',
'/yizhi_server/api/remission',
'/yizhi_server/api/user/login'
'/yizhi_server/api/user/login',
],
}
......@@ -48,7 +48,9 @@ module.exports = appInfo => {
'/yizhi_server/api/user_service',
'/yizhi_server/api/recharge',
'/yizhi_server/api/remission',
'/yizhi_server/api/user/login'
'/yizhi_server/api/user/login',
'/yizhi_server/api/user/logout',
'/yizhi_server/api/user/password',
],
};
......
......@@ -25,6 +25,19 @@ module.exports = () => {
username: process.env.MYSQL_USER || 'hexin',
password: process.env.MYSQL_PWD || 'gYUHszn9#q',
port: process.env.MYSQL_PORT || 3306,
},
{
// 东八时区
timezone: '+08:00',
delegate: 'dataModel',
baseDir: 'model/data',
// other sequelize configurations
dialect: 'mysql',
host: process.env.MYSQL_SJZX_HOST || 'rds-jb-17.mysql.rds.aliyuncs.com',
database: process.env.MYSQL_SJZX_DB_NAME || 'rsync_sjzx',
username: process.env.MYSQL_SJZX_USER || 'rsync_sjzx',
password: process.env.MYSQL_SJZX_PWD || 'sNHYdXp2Hd46F5CRvYa63',
port: 3306,
}],
};
......
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