Commit 397d0e51 authored by 任国军's avatar 任国军

init & add myLoans&myCreditCards

parent 883d130d
module.exports = {
extends: 'eslint-config-egg',
rules: {
'linebreak-style': 'off',
}
};
\ No newline at end of file
......@@ -12,3 +12,5 @@ run/
*.un~
typings/
.nyc_output/
.travis.yml
appveyor.yml
'use strict';
const Controller = require('egg').Controller;
class MineController extends Controller {
// 我的贷款
async getMyLoans() {
const { service, ctx } = this;
const ret = await service.gjj.mine.getMyLoans();
ctx.success(ret);
}
// 我的信用卡
async getMyCreditCards() {
const { service, ctx } = this;
const ret = await service.gjj.mine.getMyCreditCards();
ctx.success(ret);
}
}
module.exports = MineController;
'use strict';
const REDIS_CACHE = Symbol('Context#RedisCache');
const NODE_CACHE = Symbol('Context#NodeCache');
const NodeCache = require('node-cache');
class Cache {
constructor(app) {
this.app = app;
this.name = 'unknown-cache';
}
async val(key, next, ttl) {
let data = await this.get(key);
if (data) {
return data;
}
data = await next(key);
await this.set(key, data, ttl);
return data;
}
async get(key) {
const startTime = +new Date();
const ret = await this._get(key);
let jsonText = JSON.stringify(ret);
if (jsonText === undefined) {
jsonText = 'undefined';
} else if (jsonText.length >= 128) {
if (/^\{/.test(jsonText)) {
jsonText = '{...}';
} else if (/^\[/.test(jsonText)) {
jsonText = '[...]';
} else {
jsonText = jsonText.substr(0, 125) + '...';
}
}
this.app.logger.info(`[cache](${+new Date() - startTime}ms) ${this.name}.${key}: ${jsonText}`);
return ret;
}
async set(key, value, ttl = 60) {
return await this._set(key, value, ttl);
}
}
class RedisCacheWrap extends Cache {
constructor(app, redis) {
super(app);
this.redis = redis;
this.name = 'redis-cache';
}
async _get(key) {
const { redis } = this;
let value = await redis.get(key);
if (value === null) {
value = undefined;
}
if (value) {
value = JSON.parse(value);
}
return value;
}
async _set(key, value, ttl) {
const { redis } = this;
value = JSON.stringify(value);
if (ttl > 0) {
await redis.set(key, value, 'EX', ttl);
} else {
await redis.set(key, value);
}
}
}
class NodeCacheWrap extends Cache {
constructor(app) {
super(app);
this.cache = new NodeCache();
this.name = 'node-cache';
}
async _get(key) {
return this.cache.get(key);
}
async _set(key, value, ttl) {
const { cache } = this;
value = JSON.parse(JSON.stringify(value));
if (ttl > 0) {
cache.set(key, value, ttl);
} else {
cache.set(key, value);
}
}
}
module.exports = {
get memcache() {
if (!this[REDIS_CACHE]) {
this[REDIS_CACHE] = new RedisCacheWrap(this, this.redis);
}
return this[REDIS_CACHE];
},
get cache() {
if (!this[NODE_CACHE]) {
this[NODE_CACHE] = new NodeCacheWrap(this);
}
return this[NODE_CACHE];
},
};
'use strict';
const USER_SID = Symbol('Context#user_sid');
const TOKEN = Symbol('Context#token');
const FROM = Symbol('Context#from');
const APPUSERID = Symbol('Context#userUserId');
const DEVICEID = Symbol('Context#deviceId');
const DEVICELOGINID = Symbol('Context#deviceLoginId');
const APPID = Symbol('Context#appId');
const APPTYPEID = Symbol('Context#appTypeId');
const OLDUSERID = Symbol('Context#oldUserId');
const USERID = Symbol('Context#userId');
const OLDCOOKIE = Symbol('Context#oldCookie');
module.exports = {
failed(message) {
const method = this.request.method.toLowerCase();
if (method === 'post') {
this.throw(422, message);
} else {
this.throw(400, message);
}
},
success(data = false) {
const method = this.request.method.toLowerCase();
if (method === 'get') {
this.status = 200;
this.body = data || {};
} else if (method === 'post') {
this.status = 201;
this.body = data || {};
} else if (method === 'put' || method === 'delete') {
this.status = data ? 200 : 204;
this.body = data ? data : '';
} else {
this.status = 204;
this.body = '';
}
},
login(params) {
const { cookies, session } = this;
const moment = require('moment');
const date = new Date();
params = params || [];
this[FROM] = 'unknown';
if (cookies.get('jianbing_customer_id', { signed: false }) && cookies.get('auth_token', { signed: false })) {
this[FROM] = 'app';
} else if (session.user_sid && session.token) {
this[FROM] = 'session';
}
switch (this[FROM]) {
case 'app':
const user_sid = cookies.get('jianbing_customer_id', { signed: false });
let auth_token = cookies.get('auth_token', { signed: false });
const auth_calc = this.helper.md5(String(user_sid) + moment(date).format('MDYYYY') + 'f74jkdsy83sjf', 'utf8');
if (auth_token != auth_calc) {
const y_auth_calc = this.helper.md5(String(user_sid) + moment(new Date(date.getTime() - 86400000)).format('MDYYYY') + 'f74jkdsy83sjf', 'utf8');
if (auth_token != y_auth_calc) {
this.throw(403, 'login failed app ' + String(user_sid));
}
auth_token = auth_calc;
cookies.set('auth_token', auth_token, {
httpOnly: false,
signed: false,
maxAge: 7200 * 1000,
});
}
this[USER_SID] = user_sid;
this[TOKEN] = auth_token;
session.user_sid = user_sid;
session.token = auth_token;
session.from = this[FROM];
break;
case 'session':
this[USER_SID] = session.user_sid;
this[TOKEN] = session.token;
this[FROM] = session.from;
break;
default:
break;
}
},
// 注意,symbol && getter, 必须有get函数
get user_sid() {
this.login();
return this[USER_SID];
const token = this.request.header.authorization;
if (!token) {
return '';
}
const decode_ret = this.app.jwt.decode(token.replace('Bearer ', ''), this.app.config.jwt.secret);
this.helper.debug(decode_ret.data);
return decode_ret.data.user_sid;
// return this[USER_SID];
},
get token() {
return this[TOKEN];
},
get from() {
return this[FROM];
},
// 注意,symbol && getter, 必须有get函数
get appUserId() {
return this[APPUSERID];
},
get deviceId() {
return this[DEVICEID];
},
get deviceLoginId() {
return this[DEVICELOGINID];
},
get appId() {
return this[APPID];
},
get appTypeId() {
return this[APPTYPEID];
},
get oldUserId() {
return this[OLDUSERID];
},
get userId() {
return this[USERID];
},
get oldCookie() {
return this[OLDCOOKIE];
},
setAppUserId(app_user_id) {
this[APPUSERID] = app_user_id;
},
setDeviceId(device_id) {
this[DEVICEID] = device_id;
},
setDeviceLoginId(device_login_id) {
this[DEVICELOGINID] = device_login_id;
},
setAppId(app_id) {
this[APPID] = app_id;
},
setAppTypeId(app_type_id) {
this[APPTYPEID] = app_type_id;
},
setOldUserId(old_user_id) {
this[OLDUSERID] = old_user_id;
},
setUserId(uid) {
this[USERID] = uid;
},
setOldCookie(cookie) {
this[OLDCOOKIE] = cookie;
},
};
'use strict';
module.exports = {
// 获取 Token
get_jwt() {
const { ctx } = this;
let bearerToken = ctx.request.header.authorization;
if (!bearerToken) {
ctx.failed('error auth');
}
return bearerToken && bearerToken.replace("Bearer ", "");
},
// 校验 Token
async verify_token(ctx) {
let token = this.get_jwt(ctx);
let decode_res = await ctx.service.jwt.decode_token(token);
ctx.logger.info('decode_res', decode_res)
let token_black = await this.app.memcache.get('auth_token_' + decode_res.data.user_id);
ctx.logger.info('token_black', token_black, token);
if (token_black == token) {
ctx.failed('token 已失效');
}
// if (ctx.request.body.user_id != decode_res.data.user_id) {
// ctx.failed('用户 ID 与 Token 不一致');
// }
return decode_res;
},
md5(str) {
if (!str) {
return '';
}
const crypto = require('crypto');
const hash = crypto.createHash('md5');
const ret = hash.update(String(str), 'utf8');
return ret.digest('hex');
},
//发送请求 注意params和options都为对象
async send_request(url, params, input_options) {
const { ctx } = this;
/***
example_options = {
//是否开启请求各阶段的时间测量
timing: false,
//method
method: 'POST',
//发送数据格式,默认以application/x-www-form-urlencoded格式发送请求
contentType: 'json',
//参数
data: {
id: 5,
name: 'test',
}
//设置响应数据格式,默认不对响应数据做任何处理,直接返回原始的 buffer 格式数据。 支持 text 和 json 两种格式。
//注意:设置成 json 时,如果响应数据解析失败会抛 JSONResponseFormatError 异常
dataType: 'json',
}
***/
let default_options = {
timeout: 3000,
timing: true,
method: 'POST',
contentType: 'json',
dataType: 'json',
};
let options = input_options ? Object.assign({}, default_options, input_options) : default_options;
options.data = params;
//测试接口:个税获取话题列表
//var url = 'https://b.jianbing.com/app/geshui/social/get_topics';
var resp = await ctx.curl(url, options);
return resp;
},
aes256_cbc_encrypt(key, data) {
const iv = '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0';
const crypto = require('crypto');
const cipher = crypto.createCipheriv('aes-256-cbc', key, iv);
let crypted = cipher.update(data, 'utf8', 'binary');
crypted += cipher.final('binary');
crypted = new Buffer(crypted, 'binary').toString('base64');
return crypted;
},
aes256_cbc_decrypt(key, crypted) {
const iv = '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0';
const crypto = require('crypto');
crypted = new Buffer(crypted, 'base64').toString('binary');
const decipher = crypto.createDecipheriv('aes-256-cbc', key, iv);
let decoded = decipher.update(crypted, 'binary', 'utf8');
decoded += decipher.final('utf8');
return decoded;
},
aes256_cbc_decrypt_weixin(key, crypted) {
let aesKey = Buffer.from(key + '=', 'base64');
const cipherEncoding = 'base64';
const clearEncoding = 'utf8';
const cipher = crypto.createDecipheriv('aes-256-cbc', aesKey, aesKey.slice(0, 16));
cipher.setAutoPadding(false); // 是否取消自动填充 不取消
let decoded = cipher.update(crypted, cipherEncoding, clearEncoding) + cipher.final(clearEncoding);
return {
noncestr: decoded.substring(0, 16),
msg_len: decoded.substring(16, 20),
msg: decoded.substring(20, decoded.lastIndexOf("}") + 1)
}
},
toInt(str) {
if (typeof str === 'number') return str;
if (!str) return str;
return parseInt(str, 10) || 0;
},
//校验经纬度 部分存入的gps地址经纬度混乱,输出使用时进行校验修复
//longitude 经线 latitude 纬度 纬度从南到北,范围为-90 - 90
//示例:北纬N29°57′28.20″ 东经E119°42′32.30″ gps:29.9578340000,119.7089730000
async parseGps(gps) {
if (!gps || gps.indexOf(',') === -1) {
return '';
}
let gps_arr = gps.split(',');
if (Math.abs(gps_arr[0]) >= 90) {
gps_arr.reverse();
gps = gps_arr.join(',');
};
let data = {
ak: '3TBenWOhPygtFFazaR5kSibU',
pois: 0,
output: 'json',
location: gps,
};
const { ctx } = this;
const resp = await ctx.curl('http://api.map.baidu.com/geocoder/v2/', { timeout: 3000, dataType: 'json', method: 'GET', data: data });
const ret = resp.data;
if (ret.status != 0) {
return {};
}
return ret;
},
async check_submit_frequent(redis_key, expire = 5) {
const { ctx, app } = this;
const redis_value = await app.memcache.get(redis_key);
if (redis_value) {
ctx.failed('提交太频繁了,过会在试吧~');
}
app.memcache.set(redis_key, 1, expire);
return true;
},
randomsort(a, b) {//数组随机排序
return Math.random() > .5 ? -1 : 1; //通过随机产生0到1的数,然后判断是否大于0.5从而影响排序,产生随机性的效果。
},
debug(data, mark = '') {
var str = '';
for (let i = 0; i <= 60; i++) {
str += mark;
}
console.log(str);
console.log(data);
console.log(str);
},
sha1(...data) {
if (!data) {
return '';
}
const crypto = require('crypto');
return crypto.createHash('sha1').update(data.sort().join('')).digest('hex');
},
unique(arr) {
var res = arr.filter(function (item, index, array) {
return array.indexOf(item) === index;
});
return res;
},
//校验身份证
verify_id_card(id_card) {
const id_card_reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
if (id_card_reg.test(id_card) === false) {//身份证号码校验
return false;
}
/*1、从第一位到第十七位的系数分别为:
7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2
将这17位数字和系数相乘的结果相加。 */
const arr = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
let sum = 0;
for (let i = 0; i < arr.length; i++) {
sum += parseInt(id_card.charAt(i)) * arr[i];
}
//2、用加出来和除以11,看余数,
const c = sum % 11;
//3、分别对应的最后一位身份证的号码为:1-0-X-9-8-7-6-5-4-3-2
const ch = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
const code = ch[c];
let last = id_card.charAt(17);
last = last == 'x' ? 'X' : last;
return last == code;
},
//随机化原数组
shuffle(array) {
var m = array.length,
t, i;
// 如果还剩有元素…
while (m) {
// 随机选取一个元素…
i = Math.floor(Math.random() * m--);
// 与当前元素进行交换
t = array[m];
array[m] = array[i];
array[i] = t;
}
return array;
},
};
'use strict';
module.exports = () => {
return async function deviceInit(ctx, next) {
const method = ctx.request.method;
let input_params = {};
switch (method) {
case 'GET':
input_params = ctx.request.query;
break;
case 'POST':
input_params = ctx.request.body;
break;
case 'PUT':
input_params = ctx.request.body;
break;
default:
break;
}
const stack = ctx.app.router.stack;
const current_path_list = ctx.request.url.split('?');
const current_path = current_path_list[0];
let current_url_eq_path = 1;
for (const element in stack) {
const path_index = stack[element].path.split(':');
const path = path_index[0];
current_url_eq_path = current_path.includes(path) ? 1 : 0;
if (current_url_eq_path == 1 && stack[element].name != null && stack[element].methods.includes(ctx.request.method)) {
if (input_params.app_user_id != undefined) {
ctx.setAppUserId(input_params.app_user_id);
}
if (input_params.device_id != undefined) {
ctx.setDeviceId(input_params.device_id);
}
if (input_params.device_login_id != undefined) {
ctx.setDeviceLoginId(input_params.device_login_id);
}
await next();
return;
}
}
// 优先从cookie中取,取不到再从header中取
let appUserId = ctx.cookies.get('app_user_id', { signed: false });
let token = ctx.cookies.get('token', { signed: false });
let userId = ctx.cookies.get('user_id', { signed: false });
let deviceId = ctx.cookies.get('device_id', { signed: false });
let deviceLoginId = ctx.cookies.get('device_login_id', { signed: false });
let appTypeId = '2150d0f1-ee07-4d17-a019-251be3699bd1';
let appId = 'DE78A9AC-0407-4998-AE4D-B7F5A64EAC19';
let oldUserId;
if (!deviceId || deviceId.length === 0) {
deviceId = ctx.deviceId;
}
if (!deviceLoginId || deviceLoginId.length === 0) {
deviceLoginId = ctx.deviceLoginId;
}
if (!appUserId || appUserId.length === 0) {
appUserId = typeof (ctx.request.header.app_user_id) !== 'undefined' ? ctx.request.header.app_user_id : undefined;
}
if (!token || token.length === 0) {
token = typeof (ctx.request.header.token) !== 'undefined' ? ctx.request.header.token : undefined;
}
if (!userId || userId.length === 0) {
userId = typeof (ctx.request.header.uid) !== 'undefined' ? ctx.request.header.uid : undefined;
}
if (!deviceId || deviceId.length === 0) {
deviceId = typeof (ctx.request.header.device_id) !== 'undefined' ? ctx.request.header.device_id : undefined;
}
if (!deviceLoginId || deviceLoginId.length === 0) {
deviceLoginId = typeof (ctx.request.header.device_login_id) !== 'undefined' ? ctx.request.header.device_login_id : undefined;
}
// if((deviceId == undefined || !deviceId || deviceId.length === 0) && input_params.device_id != undefined){
// deviceId = input_params.device_id;
// }
// 校验
const params = {
app_user_id: appUserId,
token,
uid: userId,
device_id: deviceId,
device_login_id: deviceLoginId,
};
const result = await ctx.helper.send_request(ctx.app.config.NODE_URL + '/user_api/v1/user/auth', params, {
method: 'POST',
});
// ctx.logger.info('appUserId: ' + appUserId);
ctx.logger.info('request_header: ' + JSON.stringify(ctx.request.header));
ctx.logger.info('user_auth_params: ' + JSON.stringify(params));
ctx.logger.info('user_auth_result: ' + JSON.stringify(result));
console.log(result);
// if (result.status !== 201) {
// ctx.failed('无效用户');
// return;
// }
// const data = result.data.data;
let data = result.data.data;
if (result.data == undefined || result.data.data == undefined) {
data = {};
}
// const data = {};
// 所有数据以校验后返回的为准
appUserId = data.app_user_id || undefined;
userId = data.uid || undefined;
deviceId = data.device_id || undefined;
deviceLoginId = data.device_login_logs_id || undefined;
appId = data.app_id || undefined;
appTypeId = data.app_type_id || undefined;
oldUserId = data.oid || undefined;
// 写入常量
ctx.setAppUserId(appUserId);
ctx.setUserId(userId);
ctx.setDeviceId(deviceId);
ctx.setDeviceLoginId(deviceLoginId);
ctx.setAppId(appId);
ctx.setAppTypeId(appTypeId);
ctx.setOldUserId(oldUserId);
// 设置旧cookie
let authToken = '';
if (oldUserId) {
const moment = require('moment');
authToken = ctx.helper.md5(String(oldUserId) + moment(new Date()).format('MDYYYY') + 'f74jkdsy83sjf', 'utf8');
}
ctx.setOldCookie('jianbing_customer_id=' + oldUserId + ';auth_token=' + authToken);
await next();
};
};
'use strict';
module.exports = (options, app) => {
return async function (ctx, next) {//
//给第三方用的 跳过 设备判断
const stack = ctx.app.router.stack;
const current_path_list = ctx.request.url.split('?');
const current_path = current_path_list[0];
let current_url_eq_path = 1;
for (const element in stack) {
const path_index = stack[element].path.split(':');
const path = path_index[0];
current_url_eq_path = current_path.includes(path) ? 1 : 0;
if (current_url_eq_path == 1 && stack[element].name != null && stack[element].methods.includes(ctx.request.method)) {
await next();
return;
}
}
const deviceId = ctx.cookies.get('device_id', { signed: false });
const deviceLoginId = ctx.cookies.get('device_login_id', { signed: false });
if (!deviceId || deviceId.length === 0 || !deviceLoginId || deviceLoginId.length === 0) {//如果cookie中不存在device_id和device_login_id 先做设备登录 针对H5
let pastDeviceno = ctx.cookies.get('past_deviceno', { signed: false });
let deviceNo = ctx.cookies.get('device_no', { signed: false });
let channelAlias = ctx.cookies.get('channel_alias', { signed: false });
if (!pastDeviceno || pastDeviceno.length == 0) {//cookie中取不到从头部中获取
pastDeviceno = ctx.request.header.past_deviceno || undefined;
}
if (!deviceNo || deviceNo.length == 0) {
deviceNo = ctx.request.header.device_no || undefined;
}
if (!channelAlias || channelAlias.length == 0) {
channelAlias = ctx.request.header.channel_alias || undefined;
}
ctx.logger.info('middleware_device_login_params: ' + JSON.stringify({pastDeviceno, deviceNo, channelAlias}));
//和H5约定 从cookie中获取设备编号和渠道号 做设备登录;H5调接口前就会把这三个参数存到cookies中,如果没有device_init中将会出现 无效用户
if (pastDeviceno && pastDeviceno.length !== 0 && deviceNo && deviceNo.length !== 0 && deviceNo && channelAlias && channelAlias.length !== 0) {
const app_channel_info = await ctx.blockModel.AppChannel.one({ where: { alias: channelAlias } });
if (!app_channel_info || Object.keys(app_channel_info).length == 0) {
ctx.failed('渠道未配置');
}
if (!app_channel_info.app_id) {
ctx.failed('渠道未配置');
}
const params = {
past_deviceno: pastDeviceno, // description: '原设备编号'
device_no: deviceNo, // description: '设备编号'
channel_alias: channelAlias,//description:'渠道别名'
channel_id: app_channel_info.channel_id, // description: '‘渠道编号’,即之前的place_cid'
app_id: app_channel_info.app_id,// description: 'app编号'
device_info: {},
};
ctx.logger.info('middleware_device_login_params: ' + JSON.stringify(params));
const result_device_login = await ctx.helper.send_request(ctx.app.config.NODE_URL + '/login/device', params, { method: 'POST' });//设备登录
const device_login_data = result_device_login.data;
ctx.logger.info('middleware_device_login_result: ' + JSON.stringify(device_login_data));
if (!device_login_data || Object.keys(device_login_data).length === 0) {
ctx.failed('device login error, device_login_data empty');
}
if (!device_login_data.past_deviceno) {//使用设备码+时间+随机数产生的一个尽量避免重复的字符串,类似游客版h5
ctx.failed('device login error, past_deviceno empty');
}
if (!device_login_data.device_no) {//设备指纹
ctx.failed('device login error, device_no empty');
}
if (!device_login_data.device_id) {//Devices字段表主键ID
ctx.failed('device login error, device_id empty');
}
if (!device_login_data.device_login_logs_id) {//DeviceLoginLogs字段表主键ID
ctx.failed('device login error, device_login_logs_id empty');
}
const device_id = device_login_data.device_id;
const device_login_id = device_login_data.device_login_logs_id;
const expire = 7200 * 1000;
const date = new Date();
ctx.setDeviceId(device_id);
ctx.setDeviceLoginId(device_login_id);
ctx.cookies.set('device_id', device_id, { httpOnly: false, signed: false, maxAge: expire, expires: date, path: '/', });
ctx.cookies.set('device_login_id', device_login_id, { httpOnly: false, signed: false, maxAge: expire, expires: date, path: '/', });
}
}
await next();
};
};
\ No newline at end of file
'use strict';
/**
* Controller 和 Service 抛出异常处理
* @author bin fong
* @return {function} function
*/
module.exports = () => {
return async function errorHandler(ctx, next) {
let transaction;
try {
//可以从这边文章了解到原理
//http://www.cnblogs.com/cloud-/p/7239819.html
//有点类似,中间件执行的时候会一个一个被装载,然后当执行到next 之后,会执行下一个中间件,等该中间件执行完成之后,又会返回执行next下面的代码
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'
? '系统内部错误'
: 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 { cookies } = ctx;
if(options.type == 'new'){//node新框架下的登录判断
if(!ctx.appUserId || !ctx.deviceId || !ctx.deviceLoginId || !ctx.userId){
const msg = 'bad request';
ctx.throw(403, msg);
return;
}
}
if(options.type == 'old'){//php老框架下登录判断
if (!ctx.user_sid) {
const msg = 'bad request';
ctx.throw(403, msg);
return;
}
}
await next();
};
};
'use strict';
module.exports = (options, app) => {
return async function(ctx, next) {
ctx.set('Cache-Control', 'no-store, no-cache, must-revalidate');
await next();
};
};
'use strict';
module.exports = () => {
return async function auth(ctx, next) {
await ctx.helper.verify_token(ctx);
await next();
};
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const AppUpdateInfo = app.blockModel.define('app_update_info', {
id: { type: INTEGER, primaryKey: true },
app_id: STRING,
url: STRING,
title: STRING,
subhead: STRING,
content: INTEGER,
size: STRING,
type: INTEGER,
target_version: STRING,
start_version: STRING,
end_version: STRING,
status: INTEGER,
update_time: {
type: DATE,
get() {
const date = this.getDataValue('update_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'app_update_info',
});
return AppUpdateInfo;
};
'use strict';
module.exports = app => {
const { STRING, INTEGER } = app.Sequelize;
const AppVerifyStatus = app.blockModel.define('app_verify_status', {
id: { type: INTEGER, primaryKey: true },
version: STRING,
app_channel_alias: STRING,
status: INTEGER,
}, {
timestamps: false,
tableName: 'app_verify_status',
});
return AppVerifyStatus;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, ENUM} = app.Sequelize;
const AppChannel = app.blockModel.define('app_channel', {
id: { type: STRING, primaryKey: true },
app_id: STRING,
channel_id: STRING,
alias: STRING,
url: STRING,
android_url: STRING,
ios_url: STRING,
}, {
timestamps: false,
tableName: 'app_channel',
});
AppChannel.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await AppChannel.findOne({
attributes: attributes,
where : where,
});
}
AppChannel.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await AppChannel.findAll({
attributes: attributes,
where : where,
});
}
AppChannel.list = async (data = {}) => {
const limit = data.limit ? data.limit : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where: where,
order: order,
attributes: attributes,
};
const { count, rows } = await AppChannel.findAndCountAll(condition);
return { page, count, rows };
}
AppChannel.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await AppChannel.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch(error) {
ctx.status = 500;
throw (error);
}
}
AppChannel.edit = async (data) => {
const where = data.where;
const params = data.params;
AppChannel.update(params, {
where: where
}).catch( e => res.json({status: 500, error: e}));
}
return AppChannel;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, ENUM } = app.Sequelize;
const Block = app.blockModel.define('block', {
id: { type: STRING, primaryKey: true },
app_id: INTEGER,
channel_id: STRING,
city_id: STRING,
position_id: STRING,
title: STRING,
subtitle: STRING,
description: STRING,
status: ENUM('online', 'offline'),
tags: STRING,
valid: INTEGER,
start_time: DATE,
expire_time: DATE,
}, {
timestamps: false,
tableName: 'block',
});
Block.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await Block.findOne({
attributes,
where,
});
};
Block.all = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await Block.findAll({
attributes,
where,
});
};
Block.list = async (data = {}) => {
const limit = data.limit ? data.limit : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where,
order,
attributes,
};
const { count, rows } = await Block.findAndCountAll(condition);
return { page, count, rows };
};
Block.add = async data => {
try {
// 返回promise对象实力 instance
const res = await Block.create(data);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
ctx.status = 500;
throw (error);
}
};
Block.edit = async data => {
const where = data.where;
const params = data.params;
Block.update(params, {
where,
}).catch(e => res.json({ status: 500, error: e }));
};
return Block;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, ENUM} = app.Sequelize;
const Channel = app.blockModel.define('channel', {
id: { type: STRING, primaryKey: true },
app_id: STRING,
name: STRING,
alias: STRING,
status: ENUM('online','offline'),
valid: INTEGER,
}, {
timestamps: false,
tableName: 'channel',
});
Channel.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await Channel.findOne({
attributes: attributes,
where : where,
});
}
Channel.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await Channel.findAll({
attributes: attributes,
where : where,
});
}
Channel.list = async (data = {}) => {
const limit = data.limit ? data.limit : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where: where,
order: order,
attributes: attributes,
};
console.log(condition);
const { count, rows } = await Channel.findAndCountAll(condition);
return { page, count, rows };
}
Channel.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await Channel.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch(error) {
ctx.status = 500;
throw (error);
}
}
Channel.edit = async (data) => {
const where = data.where;
const params = data.params;
Channel.update(params, {
where: where
}).catch( e => res.json({status: 500, error: e}));
}
return Channel;
};
'use strict';
module.exports = app => {
const { STRING, INTEGER } = app.Sequelize;
const City = app.blockModel.define('city', {
id: {
type: INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
name: STRING,
code: INTEGER,
level: INTEGER,
parent: INTEGER,
fword: STRING,
hot: INTEGER,
}, {
timestamps: false,
tableName: 'city',
freezeTableName: true,
});
City.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await City.findOne({
attributes: attributes,
where : where,
});
}
City.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await City.findAll({
attributes: attributes,
where : where,
});
}
City.list = async (data = {}) => {
const limit = data.limit ? data.limit : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where: where,
order: order,
attributes: attributes,
};
console.log(condition);
const { count, rows } = await City.findAndCountAll(condition);
return { page, count, rows };
}
City.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await City.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch(error) {
ctx.status = 500;
throw (error);
}
}
City.edit = async (data) => {
const where = data.where;
const params = data.params;
City.update(params, {
where: where
}).catch( e => res.json({status: 500, error: e}));
}
return City;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, ENUM } = app.Sequelize;
const Icon = app.blockModel.define('icon', {
id: { type: STRING, primaryKey: true },
block_id: STRING,
title: STRING,
subtitle: STRING,
description: STRING,
link: STRING,
logo: STRING,
sort: INTEGER,
status: ENUM('online', 'offline'),
tags: STRING,
start_time: DATE,
expire_time: DATE,
valid: INTEGER,
field1: STRING,
field2: STRING,
field3: STRING,
extends: STRING,
}, {
timestamps: false,
tableName: 'icon',
});
Icon.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await Icon.findOne({
attributes,
where,
});
};
Icon.all = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await Icon.findAll({
attributes,
where,
});
};
Icon.list = async (data = {}) => {
const limit = data.limit ? data.limit : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where,
order,
attributes,
};
const { count, rows } = await Icon.findAndCountAll(condition);
return { page, count, rows };
};
Icon.add = async data => {
try {
// 返回promise对象实力 instance
const res = await Icon.create(data);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
ctx.status = 500;
throw (error);
}
};
Icon.edit = async data => {
const where = data.where;
const params = data.params;
Icon.update(params, {
where,
}).catch(e => res.json({ status: 500, error: e }));
};
return Icon;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, ENUM} = app.Sequelize;
const OfficialJob = app.blockModel.define('zhiren_job', {
id: { type: STRING, primaryKey: true, autoIncrement: true },
job_type: INTEGER,
job_type_id: INTEGER,
name: STRING,
duty: STRING,
demand: STRING,
salary: STRING,
exprence: STRING,
grade: STRING,
status: INTEGER,
is_deleted: INTEGER,
created_time: {
type: DATE,
get() {
const date = this.getDataValue('created_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_time: {
type: DATE,
get() {
const date = this.getDataValue('updated_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'zhiren_job',
});
OfficialJob.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await OfficialJob.findOne({
attributes: attributes,
where : where,
});
}
OfficialJob.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await OfficialJob.findAll({
attributes: attributes,
where : where,
});
}
OfficialJob.list = async (data = {}) => {
const limit = data.limit ? data.limit : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where: where,
order: order,
attributes: attributes,
};
console.log(condition);
const { count, rows } = await OfficialJob.findAndCountAll(condition);
return { page, count, rows };
}
OfficialJob.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await OfficialJob.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch(error) {
ctx.status = 500;
throw (error);
}
}
OfficialJob.edit = async (data) => {
const where = data.where;
const params = data.params;
OfficialJob.update(params, {
where: where
}).catch( e => res.json({status: 500, error: e}));
}
return OfficialJob;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, ENUM} = app.Sequelize;
const OfficialJobApply = app.blockModel.define('zhiren_job_apply', {
id: { type: STRING, primaryKey: true, autoIncrement: true },
job_id: INTEGER,
name: STRING,
telephone: STRING,
email: STRING,
school: STRING,
major: STRING,
resume: STRING,
status: INTEGER,
is_deleted: INTEGER,
created_time: {
type: DATE,
get() {
const date = this.getDataValue('created_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_time: {
type: DATE,
get() {
const date = this.getDataValue('updated_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'zhiren_job_apply',
});
OfficialJobApply.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await OfficialJobApply.findOne({
attributes: attributes,
where : where,
});
}
OfficialJobApply.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await OfficialJobApply.findAll({
attributes: attributes,
where : where,
});
}
OfficialJobApply.list = async (data = {}) => {
const limit = data.limit ? data.limit : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where: where,
order: order,
attributes: attributes,
};
console.log(condition);
const { count, rows } = await OfficialJobApply.findAndCountAll(condition);
return { page, count, rows };
}
OfficialJobApply.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await OfficialJobApply.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
console.log(res);
return res.id;
} catch(error) {
ctx.status = 500;
throw (error);
}
}
OfficialJobApply.edit = async (data) => {
const where = data.where;
const params = data.params;
OfficialJobApply.update(params, {
where: where
}).catch( e => res.json({status: 500, error: e}));
}
return OfficialJobApply;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, ENUM} = app.Sequelize;
const OfficialJobType = app.blockModel.define('zhiren_job_type', {
id: { type: STRING, primaryKey: true, autoIncrement: true },
job_type: INTEGER,
name: STRING,
icon: STRING,
background: STRING,
status: INTEGER,
is_deleted: INTEGER,
created_time: {
type: DATE,
get() {
const date = this.getDataValue('created_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_time: {
type: DATE,
get() {
const date = this.getDataValue('updated_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'zhiren_job_type',
});
OfficialJobType.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await OfficialJobType.findOne({
attributes: attributes,
where : where,
});
}
OfficialJobType.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await OfficialJobType.findAll({
attributes: attributes,
where : where,
});
}
OfficialJobType.list = async (data = {}) => {
const limit = data.limit ? data.limit : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where: where,
order: order,
attributes: attributes,
};
console.log(condition);
const { count, rows } = await OfficialJobType.findAndCountAll(condition);
return { page, count, rows };
}
OfficialJobType.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await OfficialJobType.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch(error) {
ctx.status = 500;
throw (error);
}
}
OfficialJobType.edit = async (data) => {
const where = data.where;
const params = data.params;
OfficialJobType.update(params, {
where: where
}).catch( e => res.json({status: 500, error: e}));
}
return OfficialJobType;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, TEXT } = app.Sequelize;
const Position = app.blockModel.define('position', {
id: { type: INTEGER, primaryKey: true, autoIncrement: true },
user_sid: INTEGER,
type: STRING,
state: INTEGER,
status: STRING,
// 注意,需要转成string
created_time: {
type: DATE,
get() {
const date = this.getDataValue('created_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'position',
});
Position.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await Position.findOne({
attributes,
where,
});
};
Position.all = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await Position.findAll({
attributes,
where,
});
};
Position.list = async (data = {}) => {
const limit = data.limit ? data.limit : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where,
order,
attributes,
};
const { count, rows } = await Position.findAndCountAll(condition);
return { page, count, rows };
};
Position.add = async data => {
try {
// 返回promise对象实力 instance
const res = await Position.create(data);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
ctx.status = 500;
throw (error);
}
};
Position.edit = async data => {
const where = data.where;
const params = data.params;
Position.update(params, {
where,
}).catch(e => res.json({ status: 500, error: e }));
};
return Position;
};
'use strict';
module.exports = app => {
const { INTEGER, STRING, TEXT } = app.Sequelize;
const Setting = app.blockModel.define('setting', {
id: { type: INTEGER, primaryKey: true, autoIncrement: true },
code: STRING(32),
keyword: STRING(64),
value: TEXT,
is_json: INTEGER(2),
}, {
timestamps: false,
tableName: 'setting',
});
Setting.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await Setting.findOne({
attributes,
where,
});
};
return Setting;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, ENUM, FLOAT } = app.Sequelize;
const Bank = app.businessModel.define('bank', {
id: { type: STRING, primaryKey: true },
name: STRING,
product_cid: INTEGER,
yys_cid: INTEGER,
slag: STRING,
logo: STRING,
interest_title: STRING,
interest_type: INTEGER,
interest_rate: STRING,
terms_title: STRING,
terms_show: STRING,
terms_limit: STRING,
tags: STRING,
tag_images: STRING,
date_added: DATE,
sort_order: INTEGER,
status:INTEGER,
consis_month:INTEGER,
exist_month:INTEGER,
loan_min:FLOAT,
loan_max:FLOAT,
deposit_base:INTEGER,
deposit:INTEGER,
type:INTEGER,
card_front:STRING,
card_back:STRING,
card_background:STRING,
applys:INTEGER,
partner:STRING,
partner_url:STRING,
hot:INTEGER,
recommend:INTEGER,
joins:INTEGER,
new:INTEGER,
redpaper:INTEGER,
server_status:INTEGER,
suspend_end_time:INTEGER,
suspend_message:STRING,
suspend_start_time:INTEGER,
server_time:STRING,
reject:STRING,
credit_status:INTEGER,
age_min:INTEGER,
age_max:INTEGER,
kind:STRING,
certification_status:INTEGER,
date_open:DATE,
point:STRING,
cities:STRING,
cities_cid:STRING,
pass:INTEGER,
pass_rate:INTEGER,
deposit_base_status:INTEGER,
high:INTEGER,
current:INTEGER,
authentication:STRING,
insurance:STRING,
question:STRING,
low:INTEGER,
offer:INTEGER,
suit_people:STRING,
card_level:STRING,
url:STRING,
reason:STRING,
perferential:STRING,
point_image:STRING,
loan_max_title:STRING,
loan_min_title:STRING,
advantages:STRING,
notice:STRING,
description:STRING,
activity:STRING,
privilege:STRING,
matches:STRING,
sort_order_yongbei:INTEGER,
sort_order_jiebei:INTEGER,
loan_credit:STRING,
loan_period:STRING,
is_old_business:INTEGER,
loan_credit_text:STRING,
loan_period_text:STRING,
final_credit_text:STRING,
final_period_text:STRING,
final_credit:STRING,
final_period:STRING,
bank_groups:STRING,
is_new_button:INTEGER,
is_show_app_index:INTEGER,
v_apply_num:INTEGER,
peak_time_growth:STRING,
trough_time_growth:STRING,
bank_key:STRING,
bank_secret:STRING,
daily_suspend_start:STRING,
daily_suspend_end:STRING,
submit_status:INTEGER,
repay_status:INTEGER,
bill_exist_month:INTEGER,
bill_card_limit:INTEGER,
bill_continue_month:INTEGER,
}, {
timestamps: false,
tableName: 'cfg_bank',
});
Bank.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await Bank.findOne({
attributes,
where,
});
};
Bank.all = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await Bank.findAll({
attributes,
where,
order,
});
};
Bank.list = async (data = {}) => {
const limit = data.limit ? data.limit : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where,
order,
attributes,
};
const { count, rows } = await Bank.findAndCountAll(condition);
return { page, count, rows };
};
return Bank;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER} = app.Sequelize;
const MessageType = app.huodongModel.define('cfg_messages_type', {
id: { type: STRING, primaryKey: true },
name: STRING,
icon: STRING,
description: STRING,
app_id: STRING,
app_type_id: STRING,
validate: INTEGER,
is_system: INTEGER,
}, {
timestamps: false,
tableName: 'cfg_messages_type',
});
MessageType.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await MessageType.findOne({
attributes: attributes,
where : where,
});
}
MessageType.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await MessageType.findAll({
attributes: attributes,
where : where,
});
}
MessageType.list = async (data = {}) => {
const limit = data.limit ? data.limit : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where: where,
order: order,
attributes: attributes,
};
console.log(condition);
const { count, rows } = await MessageType.findAndCountAll(condition);
return { page, count, rows };
}
MessageType.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await MessageType.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch(error) {
ctx.status = 500;
throw (error);
}
}
MessageType.edit = async (data) => {
const where = data.where;
const params = data.params;
MessageType.update(params, {
where: where
}).catch( e => res.json({status: 500, error: e}));
}
return MessageType;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { INTEGER, STRING, DATE } = app.Sequelize;
const UserAppFeedback = app.huodongModel.define('sys_user_app_feedback', {
id: {
type: INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
user_sid: {
type: INTEGER,
allowNull: false,
},
score: {
type: INTEGER,
allowNull: false,
},
content: {
type: STRING,
allowNull: false,
},
system: {
type: STRING,
allowNull: false,
},
phone_type: {
type: STRING,
allowNull: true,
defaultValue: '',
},
app_version: {
type: STRING,
allowNull: true,
defaultValue: '',
},
tags: {
type: STRING,
allowNull: true,
defaultValue: '',
},
product_id: {
type: INTEGER,
allowNull: true,
defaultValue: 1,
},
is_deleted: {
type: INTEGER,
allowNull: false,
defaultValue: 0,
},
created_time: {
type: DATE,
get() {
const date = this.getDataValue('created_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_time: {
type: DATE,
get() {
const date = this.getDataValue('updated_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
tableName: 'sys_user_app_feedback',
timestamps: false,
freezeTableName: true
});
UserAppFeedback.get = async function (id, options = {}) {
const default_options = { where: {}, orders: [] };//to add other condition
options.where = options.where ? Object.assign(default_options.where, options.where) : default_options.where;
options = Object.assign(default_options, options);
options.order = this.formatOrders(options.orders);
delete options.orders;
return await this.findByPk(id, options);
}
UserAppFeedback.getOne = async function (options) {
const default_options = { where: {}, orders: [] };//to add other condition
options.where = options.where ? Object.assign(default_options.where, options.where) : default_options.where;
options = Object.assign(default_options, options);
options.order = this.formatOrders(options.orders);
delete options.orders;
return await this.findOne(options);
};
UserAppFeedback.getAll = async function (options) {
const default_options = { where: { is_deleted: 0 }, orders: [{ id: 'desc' }] };//to add other condition
options.where = options.where ? Object.assign(default_options.where, options.where) : default_options.where;
options = Object.assign(default_options, options);
options.order = this.formatOrders(options.orders);
delete options.orders;
return await this.findAll(options);
};
UserAppFeedback.getList = async function (options) {
const default_options = { limit: 10, page: 1, where: { is_deleted: 0 }, orders: [{ id: 'desc' }] };//to add other condition
options.where = options.where ? Object.assign(default_options.where, options.where) : default_options.where;
options = Object.assign(default_options, options);
options.offset = (options.page - 1) * options.limit;
options.order = this.formatOrders(options.orders);
delete options.orders;
return await this.findAndCountAll(options);
};
UserAppFeedback.updateData = async function (data, options) {
const default_options = { where: {} };//to add other condition
options.where = options.where ? Object.assign(default_options.where, options.where) : default_options.where;
options = Object.assign(default_options, options);
return await this.update(data, options);
};
UserAppFeedback.add = async function (data) {
return await this.create(data);
};
UserAppFeedback.formatOrders = function (data) {
const orders = [];
if (data && Array.isArray(data)) {
for (let i in data) {
let item = data[i];
const sorts = Object.keys(item);
if (!sorts[0]) continue;
const sort = sorts[0];
const order = item[sort];
orders.push([sort, order]);
}
}
return orders
};
return UserAppFeedback;
};
\ No newline at end of file
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const Banner = app.huodongModel.define('cfg_banner_images', {
sid: { type: INTEGER, primaryKey: true, autoIncrement: true },
banner_id: INTEGER,
link: STRING,
image: STRING,
sort_order: INTEGER,
title: STRING,
description: STRING,
filed1: STRING,
filed2: STRING,
filed3: STRING,
start_time: {
type: DATE,
get() {
const date = this.getDataValue('start_time');
return (date && date.toString() !== 'Invalid Date') ? moment(date).format('YYYY-MM-DD HH:mm:ss') : '0000-00-00 00:00:00';
},
},
end_time: {
type: DATE,
get() {
const date = this.getDataValue('end_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: 'cfg_banner_images',
});
return Banner;
};
'use strict';
module.exports = app => {
const { STRING, INTEGER } = app.Sequelize;
const BannerType = app.huodongModel.define('cfg_banner', {
sid: { type: INTEGER, primaryKey: true, autoIncrement: true },
name: STRING,
location: STRING,
status: INTEGER,
valid: INTEGER,
}, {
timestamps: false,
tableName: 'cfg_banner',
});
return BannerType;
};
'use strict';
module.exports = app => {
const { INTEGER, STRING } = app.Sequelize;
const GiftToUser = app.huodongModel.define('sys_gifts_to_user', {
sid: { type: INTEGER, primaryKey: true, autoIncrement: true },
gift_id: INTEGER(11),
activity_id: INTEGER(11),
title: STRING(60),
user_sid: INTEGER(11),
phone: STRING(40),
}, {
timestamps: false,
tableName: 'sys_gifts_to_user',
});
return GiftToUser;
};
'use strict';
module.exports = app => {
const { STRING, INTEGER } = app.Sequelize;
const Icon = app.huodongModel.define('cfg_icon_content', {
icon_content_id: { type: INTEGER, primaryKey: true, autoIncrement: true },
icon_cat_id: INTEGER,
href: STRING,
image: STRING,
slag: STRING,
title: STRING,
description: STRING,
status: INTEGER,
sort_order: INTEGER,
version: INTEGER,
ios: INTEGER,
android: INTEGER,
}, {
timestamps: false,
tableName: 'cfg_icon_content',
});
return Icon;
};
'use strict';
module.exports = app => {
const { STRING, INTEGER } = app.Sequelize;
const IconType = app.huodongModel.define('cfg_icon_cat', {
icon_cat_id: { type: INTEGER, primaryKey: true, autoIncrement: true },
slag: STRING,
name: STRING,
notice: STRING,
status: INTEGER,
is_single: INTEGER,
}, {
timestamps: false,
tableName: 'cfg_icon_cat',
});
return IconType;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const Message = app.huodongModel.define('cfg_message', {
id: { type: STRING, primaryKey: true },
title: STRING,
content: STRING,
url: STRING,
image: STRING,
send_time: {
type: DATE,
get() {
const date = this.getDataValue('send_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
msg_type: INTEGER,
msg_push_type: INTEGER,
app_id: STRING,
app_type_id: STRING,
show_type: INTEGER,
valid: INTEGER,
end_time: DATE,
}, {
timestamps: false,
tableName: 'cfg_message',
});
Message.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await Message.findOne({
attributes,
where,
});
};
Message.all = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await Message.findAll({
attributes,
where,
});
};
Message.list = async (data = {}) => {
const limit = data.limit ? data.limit : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where,
order,
attributes,
};
console.log(condition);
const { count, rows } = await Message.findAndCountAll(condition);
return { page, count, rows };
};
Message.add = async data => {
try {
// 返回promise对象实力 instance
const res = await Message.create(data);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
this.ctx.status = 500;
throw (error);
}
};
Message.edit = async data => {
const where = data.where;
const params = data.params;
Message.update(params, {
where,
}).catch(e => res.json({ status: 500, error: e }));
};
return Message;
};
'use strict';
module.exports = app => {
const { INTEGER } = app.Sequelize;
const Score = app.huodongModel.define('sys_user_score_info', {
id: { type: INTEGER, primaryKey: true, autoIncrement: true },
user_sid: INTEGER(11),
all_score: INTEGER(11),
score: INTEGER(11),
vip: INTEGER(11),
lucky_draw: INTEGER(11),
}, {
timestamps: false,
tableName: 'sys_user_score_info',
});
return Score;
};
'use strict';
module.exports = app => {
const { INTEGER, STRING, TEXT } = app.Sequelize;
const Setting = app.huodongModel.define('cfg_setting', {
setting_id: { type: INTEGER, primaryKey: true, autoIncrement: true },
code: STRING(32),
keyword: STRING(64),
value: TEXT,
is_json: INTEGER(2),
}, {
timestamps: false,
tableName: 'cfg_setting',
});
Setting.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await Setting.findOne({
attributes: attributes,
where : where,
});
}
return Setting;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL } = app.Sequelize;
const ShadowSalary = app.huodongModel.define('shadow_salary', {
id: { type: INTEGER, primaryKey: true, autoIncrement: true },
user_id: STRING,
date: STRING,
base_pay: DECIMAL,
merit_pay: DECIMAL,
meal_allowance: DECIMAL,
other_allowance: DECIMAL,
heat_allowance: DECIMAL,
attendance_deduction: DECIMAL,
shebao_deduction: DECIMAL,
gjj_deduction: DECIMAL,
personal_income: DECIMAL,
sum: DECIMAL,
status: INTEGER,
created_time: {
type: DATE,
get() {
const date = this.getDataValue('created_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'shadow_salary',
});
return ShadowSalary;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { INTEGER, DATE } = app.Sequelize;
const SignIn = app.huodongModel.define('sys_user_score_sign_in', {
id: { type: INTEGER, primaryKey: true, autoIncrement: true },
user_sid: INTEGER(11),
sign_in: INTEGER(11),
count: INTEGER(11),
start_time: {
type: DATE,
get() {
const date = this.getDataValue('start_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_time: {
type: DATE,
get() {
const date = this.getDataValue('updated_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'sys_user_score_sign_in',
});
return SignIn;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, ENUM, TEXT } = app.Sequelize;
const ZhirenInvestment = app.huodongModel.define('zhiren_investment', {
id: { type: INTEGER, primaryKey: true, autoIncrement: true },
title: STRING,
description: STRING,
file_url: STRING,
type_id: INTEGER,
language: INTEGER,
status: INTEGER,
is_deleted: INTEGER,
created_time: {
type: DATE,
get() {
const date = this.getDataValue('created_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_time: {
type: DATE,
get() {
const date = this.getDataValue('updated_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'zhiren_investment',
});
ZhirenInvestment.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await ZhirenInvestment.findOne({
attributes: attributes,
where: where,
});
}
ZhirenInvestment.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await ZhirenInvestment.findAll({
attributes: attributes,
where: where,
});
}
ZhirenInvestment.list = async (data = {}) => {
const limit = data.limit ? data.limit : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where: where,
order: order,
// attributes: attributes,
};
const { count, rows } = await ZhirenInvestment.findAndCountAll(condition);
return { page, count, rows };
}
ZhirenInvestment.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await ZhirenInvestment.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
ctx.status = 500;
throw (error);
}
}
ZhirenInvestment.edit = async (data) => {
const where = data.where;
const params = data.params;
ZhirenInvestment.update(params, {
where: where
}).catch(e => res.json({ status: 500, error: e }));
}
return ZhirenInvestment;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, ENUM, TEXT } = app.Sequelize;
const ZhirenInvestmentType = app.huodongModel.define('zhiren_investment_type', {
id: { type: INTEGER, primaryKey: true, autoIncrement: true },
name: STRING,
status: INTEGER,
is_deleted: INTEGER,
created_time: {
type: DATE,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_time: {
type: DATE,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'zhiren_investment_type',
});
ZhirenInvestmentType.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await ZhirenInvestmentType.findOne({
attributes: attributes,
where: where,
});
}
ZhirenInvestmentType.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await ZhirenInvestmentType.findAll({
attributes: attributes,
where: where,
order: order,
});
}
ZhirenInvestmentType.list = async (data = {}) => {
const limit = data.limit ? data.limit : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where: where,
order: order,
attributes: attributes,
};
console.log(condition);
const { count, rows } = await ZhirenInvestmentType.findAndCountAll(condition);
return { page, count, rows };
}
ZhirenInvestmentType.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await ZhirenInvestmentType.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
ctx.status = 500;
throw (error);
}
}
ZhirenInvestmentType.edit = async (data) => {
const where = data.where;
const params = data.params;
ZhirenInvestmentType.update(params, {
where: where
}).catch(e => res.json({ status: 500, error: e }));
}
return ZhirenInvestmentType;
};
......@@ -4,6 +4,9 @@
* @param {Egg.Application} app - egg application
*/
module.exports = app => {
const { router, controller } = app;
const { controller } = app;
const router = app.router.namespace(app.config.projectRootPath);
router.get('/', controller.home.index);
require('./router/gjj')(app);
};
'use strict';
module.exports = app => {
const router = app.router.namespace(app.config.projectRootPath + '/gjj');
router.get('/mine/loans', 'gjj.mine.getMyLoans');// 我的贷款
router.get('/mine/creditcards', 'gjj.mine.getMyCreditCards');// 我的信用卡
};
'use strict';
const Service = require('egg').Service;
class MineService extends Service {
// 我的贷款
async getMyLoans() {
const { ctx } = this;
// 调用php接口
const phpResult = await ctx.helper.send_request(this.config.PHP_URL + '/business/loanschedule/v3/loans/get_list', {}, { method: 'POST', headers: { Cookie: ctx.oldCookie }, dataType: 'json' });
let phpData;
if (phpResult.status === 200) {
phpData = phpResult.data.ret;
}
// todo
const ret = { results: phpData };
return ret;
}
// 我的信用卡
async getMyCreditCards() {
const { ctx } = this;
// 调用php接口
const phpResult = await ctx.helper.send_request(this.config.PHP_URL + '/business/loanschedule/v3/creditcards/get_list', {}, { method: 'POST', headers: { Cookie: ctx.oldCookie }, dataType: 'json' });
let phpData;
if (phpResult.status === 200) {
phpData = phpResult.data.ret;
}
// todo
const ret = { results: phpData };
return ret;
}
}
module.exports = MineService;
......@@ -15,8 +15,10 @@ module.exports = appInfo => {
// use for cookie sign key, should change to your own and keep security
config.keys = appInfo.name + '_1554705194320_9697';
config.projectRootPath = '/51business/api';
// add your middleware config here
config.middleware = [];
config.middleware = [ 'errorHandler', 'deviceInit' ];
// add your user config here
const userConfig = {
......
......@@ -74,6 +74,9 @@ module.exports = appInfo => {
timeout: '60s',
},
};
config.PHP_URL = 'https://kaifa.jianbing.com';
config.NODE_URL = 'https://dev-nginx.jianbing.com';
return config;
};
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