Commit 56e46f6d authored by 姜登's avatar 姜登

add

parents
'use strict';
module.exports = {
write: true,
prefix: '^',
plugin: 'autod-egg',
test: [
'test',
'benchmark',
],
dep: [
'egg',
'egg-scripts',
],
devdep: [
'egg-ci',
'egg-bin',
'egg-mock',
'autod',
'autod-egg',
'eslint',
'eslint-config-egg',
],
exclude: [
'./test/fixtures',
'./dist',
],
};
{
"extends": "eslint-config-egg"
}
logs/
npm-debug.log
yarn-error.log
node_modules/
package-lock.json
yarn.lock
coverage/
.idea/
run/
.DS_Store
*.sw*
*.un~
typings/
.nyc_output/
sudo: false
language: node_js
node_js:
- '10'
install:
- npm i npminstall && npminstall
script:
- npm run ci
after_script:
- npminstall codecov && codecov
# yizhi_platform
已知后台
## QuickStart
<!-- add docs here for user -->
see [egg docs][egg] for more detail.
### Development
```bash
$ npm i
$ npm run dev
$ open http://localhost:7001/
```
### Deploy
```bash
$ npm start
$ npm stop
```
### npm scripts
- Use `npm run lint` to check code style.
- Use `npm test` to run unit test.
- Use `npm run autod` to auto detect dependencies upgrade, see [autod](https://www.npmjs.com/package/autod) for more detail.
[egg]: https://eggjs.org
\ No newline at end of file
'use strict';
const Controller = require('egg').Controller;
class HomeController extends Controller {
async index() {
const { ctx } = this;
ctx.body = 'hi, egg';
}
}
module.exports = HomeController;
'use strict';
const Controller = require('egg').Controller;
class HomeController extends Controller {
async index() {
const { ctx } = this;
ctx.body = 'hi, egg';
}
}
module.exports = HomeController;
'use strict';
const Controller = require('egg').Controller;
class HomeController extends Controller {
async index() {
const { ctx } = this;
ctx.body = 'hi, egg';
}
}
module.exports = HomeController;
'use strict';
module.exports = () => {
return async function errorHandler(ctx, next) {
try {
await next();
} catch (err) {
// 所有的异常都在 app 上触发一个 error 事件,框架会记录一条错误日志
ctx.app.emit('error', err, ctx);
const status = err.status || 500;
// 生产环境时 500 错误的详细错误内容不返回给客户端,因为可能包含敏感信息
// const error = status === 500 && ctx.app.config.env === 'prod'
// ? 'Internal Server Error'
// : err.message;
const error = err.message;
// 从 error 对象上读出各个属性,设置到响应中
ctx.body = { error };
if (status === 422) {
ctx.body.detail = err.errors;
}
ctx.status = status;
}
};
};
'use strict';
module.exports = (options, app) => {
return async function(ctx, next) {
const { request } = ctx;
const start = new Date();
let ms = 0;
const { header } = request;
const ipStr = header['x-real-ip'] || header['x-forwarded-for'];
if (ipStr) {
request.ip = ipStr;
}
await next();
ms = new Date() - start;
app.logger.info(
`[middleware-response-time](${ms}ms) ${request.method} ${request.protocol}://${request.ip}${
request.originalUrl
} ${ctx.response.status}`
);
// const userId = ctx.user && ctx.user.id ? ctx.user.id : '';
// const userName = ctx.user && ctx.user.name ? ctx.user.name : '';
// const ip = ctx.ip && ctx.ip.split(':').pop() || '';
// const log = {
// ip,
// method: ctx.method,
// request: ctx.url.split('?')[0],
// time: ms,
// user: userName,
// created_by: userId,
// };
// ctx.service.system.requestLog.create(log);
// const changeMethod = [ 'PUT', 'POST', 'DELETE'];
// if (changeMethod.includes(ctx.method) && userId) {
// const changeLog = {
// ip,
// method: ctx.method,
// request: ctx.url.split('?')[0],
// time: ms,
// user: userName,
// params: ctx.request.body || {},
// status: ctx.response.status,
// respone: ctx.body || {},
// created_by: userId,
// };
// ctx.service.system.requestChangeLog.create(changeLog);
// }
};
};
'use strict';
module.exports = app => {
const { DataTypes } = app.Sequelize;
const account = app.yizhiModel.define('account', {
user_id: {
type: DataTypes.STRING(50),
allowNull: false,
primaryKey: true,
},
account: {
type: DataTypes.STRING(50),
allowNull: true,
},
name: {
type: DataTypes.STRING(50),
allowNull: true,
},
company: {
type: DataTypes.STRING(50),
allowNull: true,
},
dd_name: {
type: DataTypes.STRING(20),
allowNull: true,
},
dd_id: {
type: DataTypes.STRING(20),
allowNull: true,
},
status: {
type: DataTypes.INTEGER(2),
allowNull: false,
defaultValue: 1,
},
created_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
field: 'create_time',
},
updated_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
field: 'update_time',
},
}, {
tableName: 'account_list',
timestamps: false,
});
return account;
};
'use strict';
module.exports = app => {
const { DataTypes } = app.Sequelize;
const price = app.yizhiModel.define('price', {
id: {
type: DataTypes.INTEGER(8),
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
appkey: {
type: DataTypes.STRING(50),
allowNull: false,
},
pay_type: {
type: DataTypes.INTEGER(2),
allowNull: true,
},
price: {
type: DataTypes.DECIMAL(5, 2),
allowNull: true,
defaultValue: 0.00,
},
created_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
field: 'create_time',
},
start_time: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
field: 'start_time',
},
end_time: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
field: 'end_time',
},
operator: {
type: DataTypes.STRING(50),
allowNull: false,
},
}, {
tableName: 'price_detail',
timestamps: false,
});
return price;
};
'use strict';
module.exports = app => {
const { DataTypes } = app.Sequelize;
const recharge = app.yizhiModel.define('recharge', {
id: {
type: DataTypes.INTEGER(8),
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
user_id: {
type: DataTypes.STRING(50),
allowNull: false,
},
money: {
type: DataTypes.DECIMAL(10, 2),
allowNull: true,
},
remark: {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: 1,
},
operator: {
type: DataTypes.STRING(50),
allowNull: true,
},
created_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
field: 'create_time',
},
receive_time: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
field: 'receive_time',
},
}, {
tableName: 'recharge_detail',
timestamps: false,
});
recharge.associate = function() {
app.yizhiModel.Recharge.belongsTo(app.yizhiModel.Account, { foreignKey: 'user_id', targetKey: 'user_id' });
};
return recharge;
};
'use strict';
module.exports = app => {
const { DataTypes } = app.Sequelize;
const remission = app.yizhiModel.define('remission', {
id: {
type: DataTypes.INTEGER(8),
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
user_id: {
type: DataTypes.STRING(50),
allowNull: false,
},
service: {
type: DataTypes.STRING(50),
allowNull: true,
},
appkey: {
type: DataTypes.STRING(50),
allowNull: true,
},
status: {
type: DataTypes.INTEGER(2),
allowNull: false,
defaultValue: 1,
},
pay_type: {
type: DataTypes.STRING(20),
allowNull: true,
},
created_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
field: 'create_time',
},
updated_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
field: 'update_time',
},
}, {
tableName: 'remission_detail',
timestamps: false,
});
return remission;
};
'use strict';
module.exports = app => {
const { DataTypes } = app.Sequelize;
const userService = app.yizhiModel.define('userService', {
id: {
type: DataTypes.INTEGER(8),
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
user_id: {
type: DataTypes.STRING(50),
allowNull: false,
},
service: {
type: DataTypes.STRING(50),
allowNull: true,
},
appkey: {
type: DataTypes.STRING(50),
allowNull: true,
},
status: {
type: DataTypes.INTEGER(2),
allowNull: false,
defaultValue: 1,
},
pay_type: {
type: DataTypes.STRING(20),
allowNull: true,
},
created_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
field: 'create_time',
},
updated_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
field: 'update_time',
},
}, {
tableName: 'account_list',
timestamps: false,
});
userService.associate = function() {
app.yizhiModel.UserService.belongsTo(app.yizhiModel.Account, { foreignKey: 'user_id', targetKey: 'user_id' });
};
return userService;
};
'use strict';
/**
* @param {Egg.Application} app - egg application
*/
module.exports = app => {
const { controller } = app;
const router = app.router.namespace(app.config.projectRootPath);
router.get('/account', controller.user.index); // 获取合作方列表
router.put('/account', controller.user.index); // 修改合作方账号状态
router.get('/user_sercie', controller.user.index); // 获取合作方服务信息
router.get('/price_detail', controller.user.index); // 获取appKey价格明细
router.post('/price_detail', controller.user.index); // 增加价格明细
router.get('/recharge', controller.user.index); // 获取合作方充值信息
router.post('/recharge', controller.user.index); // 增加充值信息
router.get('/remission', controller.user.index); // 获取appKey减免信息
router.post('/remission', controller.user.index); // 增加充值信息
};
environment:
matrix:
- nodejs_version: '10'
install:
- ps: Install-Product node $env:nodejs_version
- npm i npminstall && node_modules\.bin\npminstall
test_script:
- node --version
- npm --version
- npm run test
build: off
/* eslint valid-jsdoc: "off" */
'use strict';
/**
* @param {Egg.EggAppInfo} appInfo app info
*/
module.exports = appInfo => {
/**
* built-in config
* @type {Egg.EggAppConfig}
**/
const config = exports = {};
// use for cookie sign key, should change to your own and keep security
config.keys = appInfo.name + '_1559722467295_3512';
config.projectRootPath = '/data_server/yizhi/api';
// add your middleware config here
config.middleware = [
'requestLog',
'errorHandler',
];
config.cors = {
origin: '*',
allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
credentials: true,
};
// 关闭csrf
config.security = {
csrf: {
enable: false,
},
};
return config;
};
'use strict';
module.exports = () => {
const config = {};
config.debug = true;
/**
* @member Config#
* @property {String} KEY - description
*/
config.sequelize = {
datasources: [{
// 东八时区
timezone: '+08:00',
delegate: 'yizhiModel',
baseDir: 'model/yizhi',
// other sequelize configurations
dialect: 'mysql',
host: 'rm-bp1272001633qc0x9o.mysql.rds.aliyuncs.com',
database: 'analysisdata',
username: 'hexin',
password: 'gYUHszn9#q',
port: 3306,
}],
};
return config;
};
'use strict';
module.exports = () => {
const config = {};
/**
* @member Config#
* @property {String} KEY - description
*/
config.sequelize = {
datasources: [{
// 东八时区
timezone: '+08:00',
delegate: 'yizhiModel',
baseDir: 'model/yizhi',
// other sequelize configurations
dialect: 'mysql',
host: 'rm-bp1272001633qc0x9.mysql.rds.aliyuncs.com',
database: 'analysisdata',
username: 'hexin',
password: 'gYUHszn9#q',
port: 3306,
}],
};
return config;
};
'use strict';
/** @type Egg.EggPlugin */
module.exports = {
routerPlus: {
enable: true,
package: 'egg-router-plus',
},
cors: {
enable: true,
package: 'egg-cors',
},
mysql: {
enable: false,
package: 'egg-mysql',
},
sequelize: {
enable: true,
package: 'egg-sequelize',
},
validate: {
enable: true,
package: 'egg-validate',
},
};
{
"include": [
"**/*"
]
}
\ No newline at end of file
{
"name": "yizhi_platform",
"version": "1.0.0",
"description": "已知后台",
"private": true,
"egg": {
"declarations": true
},
"dependencies": {
"egg": "^2.2.1",
"egg-cors": "^2.2.0",
"egg-mysql": "^3.0.0",
"egg-router-plus": "^1.3.0",
"egg-scripts": "^2.11.0",
"egg-sequelize": "^5.0.0",
"egg-validate": "^2.0.2",
"moment": "^2.24.0",
"mysql2": "^1.6.5"
},
"devDependencies": {
"autod": "^3.0.1",
"autod-egg": "^1.1.0",
"egg-bin": "^4.11.0",
"egg-ci": "^1.11.0",
"egg-mock": "^3.21.0",
"eslint": "^5.13.0",
"eslint-config-egg": "^7.1.0"
},
"engines": {
"node": ">=8.9.0"
},
"scripts": {
"start": "egg-scripts start --daemon --title=egg-server-yizhi_platform",
"stop": "egg-scripts stop --title=egg-server-yizhi_platform",
"dev": "egg-bin dev",
"debug": "egg-bin debug",
"test": "npm run lint -- --fix && npm run test-local",
"test-local": "egg-bin test",
"cov": "egg-bin cov",
"lint": "eslint .",
"ci": "npm run lint && npm run cov",
"autod": "autod"
},
"ci": {
"version": "8"
},
"repository": {
"type": "git",
"url": ""
},
"author": "jd",
"license": "MIT"
}
'use strict';
const { app, assert } = require('egg-mock/bootstrap');
describe('test/app/controller/home.test.js', () => {
it('should assert', () => {
const pkg = require('../../../package.json');
assert(app.config.keys.startsWith(pkg.name));
// const ctx = app.mockContext({});
// yield ctx.service.xx();
});
it('should GET /', () => {
return app.httpRequest()
.get('/')
.expect('hi, egg')
.expect(200);
});
});
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