Commit 33f7fcf1 by 王昆

gsb

parent 00ed1a86
#!/bin/bash #!/bin/bash
FROM registry.cn-beijing.aliyuncs.com/hantang/node105:v2 FROM registry.cn-beijing.aliyuncs.com/hantang/node105:v2
MAINTAINER jy "jiangyong@gongsibao.com" MAINTAINER jy "jiangyong@gongsibao.com"
ADD xggsve-order/apps/xggsve-order/ ADD xggsve-invoice/apps/xggsve-invoice/
WORKDIR /apps/xggsve-order/ WORKDIR /apps/xggsve-invoice/
RUN cnpm install -S RUN cnpm install -S
CMD ["node","/apps/xggsve-order/main.js"] CMD ["node","/apps/xggsve-invoice/main.js"]
......
...@@ -65,17 +65,60 @@ class APIBase extends DocBase { ...@@ -65,17 +65,60 @@ class APIBase extends DocBase {
return x >= 0; return x >= 0;
} }
async checkAcck(gname, methodname, pobj, query, req) { async checkAcck(gname, methodname, pobj, query, req) {
return system.getResultSuccess(); var appInfo = null;
var result = system.getResultSuccess();
var ispass = await this.isCheckWhiteList(gname, methodname);
var appkey = req.headers["accesskey"];
var app_id = req.headers["app_id"];
if (ispass) {
return result;
}//在白名单里面
if (app_id) {
appInfo = await this.cacheManager["ApiAppIdCheckCache"].cache(app_id, null, 3000);
if (!appInfo) {
result.status = system.appidFail;
result.msg = "请求头app_id值失效,请重新获取";
}
// var signResult = await this.verifySign(pobj.action_body, appInfo.appSecret);
// if (signResult.status != 0) {
// result.status = system.signFail;
// result.msg = signResult.msg;
// }
}//验签
else if (appkey) {
appInfo = await this.cacheManager["ApiAccessKeyCheckCache"].cache(appkey, { status: true }, 3000);
if (!appInfo || !appInfo.app) {
result.status = system.tokenFail;
result.msg = "请求头accesskey失效,请重新获取";
}
}//验证accesskey
else {
result.status = -1;
result.msg = "请求头没有相关访问参数,请验证后在进行请求";
}
return result;
} }
async doexec(gname, methodname, pobj, query, req) { async doexec(gname, methodname, pobj, query, req) {
var requestid = this.getUUID(); var requestid = this.getUUID();
try { try {
//验证accesskey或验签
// var isPassResult = await this.checkAcck(gname, methodname, pobj, query, req);
// if (isPassResult.status != 0) {
// isPassResult.requestid = "";
// return isPassResult;
// }
if (pobj && pobj.action_body) {
pobj.action_body.merchant_id = pobj.action_body.merchant_id || req.headers["app_id"];
}
if (query) {
query.merchant_id = req.headers["app_id"];
}
var rtn = await this[methodname](pobj, query, req); var rtn = await this[methodname](pobj, query, req);
rtn.requestid = requestid; rtn.requestid = requestid;
this.oplogSve.createDb({ this.oplogSve.createDb({
appid: req.headers["app_id"] || "", appid: req.headers["app_id"] || "",
appkey: "", appkey: req.headers["accesskey"] || "",
requestId: requestid, requestId: requestid,
op: req.classname + "/" + methodname, op: req.classname + "/" + methodname,
content: JSON.stringify(pobj), content: JSON.stringify(pobj),
...@@ -88,8 +131,8 @@ class APIBase extends DocBase { ...@@ -88,8 +131,8 @@ class APIBase extends DocBase {
} catch (e) { } catch (e) {
console.log(e.stack, "api调用出现异常,请联系管理员..........") console.log(e.stack, "api调用出现异常,请联系管理员..........")
this.logCtl.error({ this.logCtl.error({
appid: "" + pobj.action_process, appid: req.headers["app_id"] || "",
appkey: "", appkey: req.headers["accesskey"] || "",
requestId: requestid, requestId: requestid,
op: pobj.classname + "/" + methodname, op: pobj.classname + "/" + methodname,
content: e.stack, content: e.stack,
......
...@@ -96,7 +96,7 @@ class UserCtl extends CtlBase { ...@@ -96,7 +96,7 @@ class UserCtl extends CtlBase {
await adminUser.save(); await adminUser.save();
var xggadminsid = uuidv4(); var xggadminsid = uuidv4();
xggadminsid = "3cb49932-fa02-44f0-90db-9f06fe02e5c7"; // xggadminsid = "3cb49932-fa02-44f0-90db-9f06fe02e5c7";
await this.redisClient.setWithEx(xggadminsid, JSON.stringify(adminUser), 60 * 60 * 2); await this.redisClient.setWithEx(xggadminsid, JSON.stringify(adminUser), 60 * 60 * 2);
// 处理登录逻辑 // 处理登录逻辑
......
...@@ -12,11 +12,7 @@ class ApiAppIdCheckCache extends CacheBase { ...@@ -12,11 +12,7 @@ class ApiAppIdCheckCache extends CacheBase {
return settings.cacheprefix + "_verify_appid:"; return settings.cacheprefix + "_verify_appid:";
} }
async buildCacheVal(cachekey, inputkey, val, ex, ...items) { async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
var item = await this.merchantDao.getItemByAppId(inputkey); return;
if (!item) {
return null;
}
return JSON.stringify(item);
} }
} }
module.exports = ApiAppIdCheckCache; module.exports = ApiAppIdCheckCache;
...@@ -3,14 +3,11 @@ class Dao { ...@@ -3,14 +3,11 @@ class Dao {
constructor(modelName) { constructor(modelName) {
this.modelName = modelName; this.modelName = modelName;
this.redisClient = system.getObject("util.redisClient"); this.redisClient = system.getObject("util.redisClient");
this.orderBusinessStatus = system.getObject("util.orderBusinessStatus");
var db = system.getObject("db.common.connection").getCon(); var db = system.getObject("db.common.connection").getCon();
this.db = db; this.db = db;
console.log("........set dao model.........."); console.log("........set dao model..........");
this.model = db.models[this.modelName]; this.model = db.models[this.modelName];
} }
async preCreate(u) { async preCreate(u) {
if (!u.id) { if (!u.id) {
u.id = await this.redisClient.genrateId(this.modelName); u.id = await this.redisClient.genrateId(this.modelName);
...@@ -33,7 +30,6 @@ class Dao { ...@@ -33,7 +30,6 @@ class Dao {
}); });
} }
} }
//批量插入 //批量插入
async bulkCreate(objs) { async bulkCreate(objs) {
if (!objs || objs.length == 0) { if (!objs || objs.length == 0) {
...@@ -81,7 +77,6 @@ class Dao { ...@@ -81,7 +77,6 @@ class Dao {
where: qobj where: qobj
}); });
if (en != null) { if (en != null) {
1
return en.destroy(); return en.destroy();
} }
return null; return null;
...@@ -294,7 +289,6 @@ class Dao { ...@@ -294,7 +289,6 @@ class Dao {
async findById(oid) { async findById(oid) {
return this.model.findById(oid); return this.model.findById(oid);
} }
async setListCodeName(list, field) { async setListCodeName(list, field) {
if (!list) { if (!list) {
return; return;
...@@ -325,7 +319,6 @@ class Dao { ...@@ -325,7 +319,6 @@ class Dao {
return map[item[field] || ""] || ""; return map[item[field] || ""] || "";
} }
async getById(id, attrs) { async getById(id, attrs) {
if (!id) { if (!id) {
return null; return null;
...@@ -350,6 +343,7 @@ class Dao { ...@@ -350,6 +343,7 @@ class Dao {
ids: ids ids: ids
}) || []; }) || [];
} }
async getMapByIds(ids, attrs) { async getMapByIds(ids, attrs) {
var result = {}; var result = {};
var list = await this.getListByIds(ids, attrs); var list = await this.getListByIds(ids, attrs);
...@@ -362,6 +356,5 @@ class Dao { ...@@ -362,6 +356,5 @@ class Dao {
} }
return result; return result;
} }
} }
module.exports = Dao; module.exports = Dao;
\ No newline at end of file
const system = require("../../../system");
const Dao = require("../../dao.base"); const Dao = require("../../dao.base");
class IborderDao extends Dao { const system = require("../../../system");
class ApplyDao extends Dao {
constructor() { constructor() {
super(Dao.getModelName(IborderDao)); super(Dao.getModelName(ApplyDao));
this.statusMap = { this.statusMap = {
"1000": "未付款", "0090": "未付款",
"1010": "订单关闭", "1000": "待审核",
"1010": "审核不通过",
"1020": "待分配", "1020": "待分配",
"1030": "待处理", "1030": "待处理",
"1040": "交付商关闭", "1040": "交付商关闭",
"1050": "执照办理中", "1050": "已开具",
"1060": "已出执照", "1060": "待审核",
"1070": "刻章办理中", "1070": "审核通过",
"1080": "已刻章", "1080": "已邮寄",
"1090": "银行开户中", "1090": "完成",
"1100": "银行卡已开户", "1100": "发票撤回",
"1110": "税务报道中", "1200": "红冲",
"1120": "已税务报道", "1300": "审核失败(平台第二次审核)"
"1130": "待审核",
"1140": "审核失败",
"1150": "审核通过",
"1160": "已邮寄",
"1170": "已完成",
}; };
this.ostatusMap = {
"1000": "未付款", this.customerMap = {
"1010": "订单关闭", "0090": "未付款",
"1000": "待审核",
"1030": "待处理", "1030": "待处理",
"1050": "执照办理中", "1050": "已开具",
"1060": "已出执照", "1090": "完成"
"1070": "刻章办理中",
"1080": "已刻章",
"1090": "银行开户中",
"1100": "银行卡已开户",
"1110": "税务报道中",
"1120": "已税务报道",
"1170": "已完成",
}; };
this.deliverTypeMap = { this.deliverMap = {
"10": "交付商交付", "1030": "待处理",
"20": "平台交付", "1040": "交付商关闭",
"30": "平台保存无需交付", "1050": "已开具",
"1060": "待审核",
"1080": "已邮寄",
"1300": "审核失败(平台第二次审核)"
} }
} }
async statOrderByTime(begin, end) {
var sql = [];
sql.push("SELECT");
sql.push("COUNT(1) AS orderCount, SUM(price) AS orderPrice");
sql.push("FROM `ib_order`");
sql.push("WHERE 1 = 1");
var params = { async findMapByIds(ids, attrs) {
begin: begin, var result = {};
end: end if (!ids || ids.length == 0) {
}; return result;
if (begin) {
sql.push("AND created_at >= :begin");
}
if (end) {
sql.push("AND created_at <= :end");
} }
var list = await this.customQuery(sql.join(" "), params);
attrs = attrs || "*";
var sql = "SELECT " + attrs + " FROM invoice_apply where id IN (:ids) ";
var list = await this.customQuery(sql, { ids: ids });
if (!list || list.length == 0) { if (!list || list.length == 0) {
return { return result;
orderCount: 0,
orderPrice: 0,
}
} }
var item = list[0];
return { for (var item of list) {
orderCount: item.orderCount || 0, result[item.id] = item;
orderPrice: item.orderPrice || 0,
} }
return result;
} }
//按天来计算(平台)
async statDayByTime(begin, end) { async statDayByTime(begin, end) {
var result = {}; var result = {};
var sql = []; var sql = [];
sql.push("SELECT"); sql.push("SELECT");
sql.push("DATE_FORMAT(created_at, '%Y-%m-%d') AS `day`, SUM(price) AS orderPrice, COUNT(1) AS orderCount"); sql.push("DATE_FORMAT(created_at, '%Y-%m-%d') AS `day`, SUM(service_change) AS serviceChange, COUNT(1) AS invoiceCount");
sql.push("FROM `ib_order`"); sql.push("FROM `invoice_apply`");
sql.push("WHERE 1 = 1"); sql.push("WHERE 1 = 1");
var params = { var params = {
...@@ -108,12 +90,13 @@ class IborderDao extends Dao { ...@@ -108,12 +90,13 @@ class IborderDao extends Dao {
return result; return result;
} }
//安月来计算(平台)
async statMonthByTime(begin, end) { async statMonthByTime(begin, end) {
var result = {}; var result = {};
var sql = []; var sql = [];
sql.push("SELECT"); sql.push("SELECT");
sql.push("DATE_FORMAT(created_at, '%Y-%m') AS `month`, SUM(price) AS orderPrice, COUNT(1) AS orderCount"); sql.push("DATE_FORMAT(created_at, '%Y-%m') AS `month`, SUM(service_change) AS serviceChange, COUNT(1) AS invoiceCount");
sql.push("FROM `ib_order`"); sql.push("FROM `invoice_apply`");
sql.push("WHERE 1 = 1"); sql.push("WHERE 1 = 1");
var params = { var params = {
...@@ -146,15 +129,47 @@ class IborderDao extends Dao { ...@@ -146,15 +129,47 @@ class IborderDao extends Dao {
result.end = item.month; result.end = item.month;
} }
} }
return result; return result;
} }
async statInvoiceByTime(begin, end) {
var sql = [];
sql.push("SELECT");
sql.push("COUNT(1) AS invoiceCount, SUM(service_change) AS serviceChange");
sql.push("FROM `invoice_apply`");
sql.push("WHERE 1 = 1");
var params = {
begin: begin,
end: end
};
if (begin) {
sql.push("AND created_at >= :begin");
}
if (end) {
sql.push("AND created_at <= :end");
}
var list = await this.customQuery(sql.join(" "), params);
if (!list || list.length == 0) {
return {
invoiceCount: 0,
serviceChange: 0,
}
}
var item = list[0];
return {
invoiceCount: item.invoiceCount || 0,
serviceChange: item.serviceChange || 0,
}
}
async statByStatus(begin, end) { async statByStatus(begin, end) {
var sql = []; var sql = [];
sql.push("SELECT"); sql.push("SELECT");
sql.push("`status`, COUNT(1) AS orderCount "); sql.push("`status`, COUNT(1) AS invoiceCount ");
sql.push("FROM `ib_order`"); sql.push("FROM `invoice_apply`");
sql.push("WHERE 1 = 1"); sql.push("WHERE 1 = 1");
var params = { var params = {
begin: begin, begin: begin,
...@@ -177,10 +192,10 @@ class IborderDao extends Dao { ...@@ -177,10 +192,10 @@ class IborderDao extends Dao {
} }
for(var item of list) { for(var item of list) {
result[item.status] = item.orderCount || 0; result[item.status] = item.invoiceCount || 0;
} }
return result; return result;
} }
} }
module.exports = IborderDao; module.exports = ApplyDao;
\ No newline at end of file
const Dao = require("../../dao.base");
const system = require("../../../system");
class DelivererDao extends Dao {
constructor() {
super(Dao.getModelName(DelivererDao));
this.statusMap = {
"0090":"未付款",
"1000":"待审核",
"1010":"审核不通过",
"1020":"待分配",
"1030":"待处理",
"1040":"交付商关闭",
"1050":"已开具",
"1060":"待审核",
"1070":"审核通过",
"1080":"已邮寄",
"1090":"完成",
"1100":"发票撤回",
"1200":"红冲",
"1300":"审核失败(平台第二次审核)"
};
this.customerMap = {
"0090":"未付款",
"1000":"待审核",
"1030":"待处理",
"1050":"已开具",
"1090":"完成"
};
this.deliverMap = {
"1030":"待处理",
"1040":"交付商关闭",
"1050":"已开具",
"1060":"待审核",
"1080":"已邮寄",
"1300":"审核失败(平台第二次审核)"
}
}
//交付商业务概览
async countStat(params) {
var sql = [];
sql.push("select distinct deliverer_id from `xgg-invoice`.invoice_deliverer where 1=1");
this.setCondition(params, sql);
var list = await this.customQuery(sql.join(" "), params);
return {
total:list.length || 0,
list:list
};
}
setCondition(params, sql) {
if (params.begin) {
sql.push("AND created_at >= :begin");
}
if (params.end) {
sql.push("AND created_at <= :end");
}
}
//获取名字 id等信息
async queryStat(params, startRow, pageSize) {
var sql = [];
sql.push("SELECT");
sql.push("b.id, b.deliverer_id, b.deliverer_name,sum(b.deliverer_amount) as totalAmount");
sql.push("FROM invoice_deliverer b inner join invoice_apply a on a.deliverer_id=b.id ");
sql.push("WHERE 1 = 1 and b.deliverer_id in ("+params.list+")");
if (params.begin) {
sql.push("AND b.created_at >= :begin");
}
if (params.end) {
sql.push("AND b.created_at <= :end");
}
sql.push("GROUP BY b.deliverer_id");
sql.push("LIMIT :startRow, :pageSize");
params.startRow = startRow;
params.pageSize = pageSize;
var list = await this.customQuery(sql.join(" "), params);
return list;
}
async statDeliverByStatus(params) {
var sql = [];
sql.push("SELECT");
sql.push("a.deliverer_id,a.status,COUNT(1) AS invoiceCount");
sql.push("FROM `invoice_apply` a inner join `invoice_deliverer` b on a.deliverer_id=b.id");
sql.push("WHERE 1 = 1");
if(params.delivererIds) {
sql.push("AND a.deliverer_id IN (:delivererIds)")
}
if (params.begin) {
sql.push("AND b.created_at >= :begin");
}
if (params.end) {
sql.push("AND b.created_at <= :end");
}
sql.push("GROUP BY a.`status`");
var result = {};
var list = await this.customQuery(sql.join(" "), params);
if (!list || list.length == 0) {
return result;
}
for (var item of list) {
result[item.deliverer_id + "_" + item.status] = item.invoiceCount || 0;
}
return result;
}
//按天来计算(交付商)
async delStatDayByTime(begin, end,delivererId) {
var result = {};
var sql = [];
sql.push("SELECT");
sql.push("DATE_FORMAT(created_at, '%Y-%m-%d') AS `day`, SUM(deliverer_amount) AS delivererAmount, COUNT(1) AS invoiceCount");
sql.push("FROM `invoice_deliverer`");
sql.push("WHERE 1 = 1");
var params = {
begin: begin,
end: end,
delivererId:delivererId
};
if (begin) {
sql.push("AND created_at >= :begin");
}
if (end) {
sql.push("AND created_at <= :end");
}
if (delivererId) {
sql.push("AND deliverer_id = :delivererId");
}
sql.push("GROUP BY `day` ORDER BY `day` ASC");
var list = await this.customQuery(sql.join(" "), params);
if (!list || list.length == 0) {
return result;
}
for (var item of list) {
result[item.day] = item;
}
return result;
}
//安月来计算(交付商)
async delStatMonthByTime(begin, end,delivererId) {
var result = {};
var sql = [];
sql.push("SELECT");
sql.push("DATE_FORMAT(created_at, '%Y-%m') AS `month`, SUM(deliverer_amount) AS delivererAmount, COUNT(1) AS invoiceCount");
sql.push("FROM `invoice_deliverer`");
sql.push("WHERE 1 = 1");
var params = {
begin: begin,
end: end
};
if (begin) {
sql.push("AND created_at >= :begin");
}
if (end) {
sql.push("AND created_at <= :end");
}
if (delivererId) {
sql.push("AND deliverer_id = :delivererId");
}
sql.push("GROUP BY `month` ORDER BY `month` ASC");
var list = await this.customQuery(sql.join(" "), params);
if (!list || list.length == 0) {
return result;
}
for (var idx = 0; idx < list.length; idx++) {
var item = list[idx];
result[item.month] = item;
if (idx == 0) {
result.begin = item.month;
}
if (idx == list.length - 1) {
result.end = item.month;
}
}
return result;
}
async delStatInvoiceByTime(begin, end,delivererId) {
var sql = [];
sql.push("SELECT");
sql.push("COUNT(1) AS invoiceCount, SUM(deliverer_amount) AS delivererAmount");
sql.push("FROM `invoice_deliverer`");
sql.push("WHERE 1 = 1");
var params = {
begin: begin,
end: end,
delivererId:delivererId
};
if (begin) {
sql.push("AND created_at >= :begin");
}
if (end) {
sql.push("AND created_at <= :end");
}
if (delivererId) {
sql.push("AND deliverer_id = :delivererId");
}
var list = await this.customQuery(sql.join(" "), params);
if (!list || list.length == 0) {
return {
invoiceCount: 0,
delivererAmount: 0,
}
}
var item = list[0];
return {
invoiceCount: item.invoiceCount || 0,
delivererAmount: item.delivererAmount || 0,
}
}
/**
* 发票办理
* @param {*} begin
* @param {*} end
*/
async delStatByStatus(begin, end) {
var sql = [];
sql.push("SELECT");
sql.push("`status`, COUNT(1) AS invoiceCount ");
sql.push("FROM `invoice_deliverer`");
sql.push("WHERE 1 = 1");
var params = {
begin: begin,
end: end
};
if (begin) {
sql.push("AND created_at >= :begin");
}
if (end) {
sql.push("AND created_at <= :end");
}
sql.push("GROUP BY `status`");
var result = {};
var list = await this.customQuery(sql.join(" "), params);
if(!list || list.length == 0) {
return result;
}
for(var item of list) {
result[item.status] = item.invoiceCount || 0;
}
return result;
}
}
module.exports = DelivererDao;
const system = require("../../../system");
const Dao = require("../../dao.base");
const moment = require("moment");
class InvoiceDao extends Dao {
constructor() {
super(Dao.getModelName(InvoiceDao));
this.statusMap = {
"0090": "未付款",
"1000": "待审核",
"1010": "审核不通过",
"1020": "待分配",
"1030": "待处理",
"1040": "交付商关闭",
"1050": "已开具",
"1060": "待审核",
"1070": "审核通过",
"1080": "已邮寄",
"1090": "完成",
"1100": "发票撤回",
"1200": "红冲",
"1300": "审核失败(平台第二次审核)"
};
this.customerMap = {
"0090": "未付款",
"1000": "待审核",
"1030": "待处理",
"1050": "已开具",
"1090": "完成"
};
this.deliverMap = {
"1030": "待处理",
"1040": "交付商关闭",
"1050": "已开具",
"1060": "待审核",
"1080": "已邮寄",
"1300": "审核失败(平台第二次审核)"
}
this.redStatusMap = {
"1": "未红冲",
"2": "红冲中",
"3": "红冲失败",
"4": "红冲成功",
};
this.red_statusMap = this.redStatusMap;
}
async countByParams(params) {
var sql = [];
sql.push("SELECT");
sql.push("COUNT(1) as total");
sql.push("FROM `invoice` t1");
sql.push("INNER JOIN `invoice_apply` t2 ON t1.`id` = t2.`id`");
sql.push("WHERE 1 = 1 and t2.status in('1070','1080','1090')");
this.setCondition(params, sql);
var counts = await this.customQuery(sql.join(" "), params);
if(!counts || counts.length == 0) {
return 0;
}
return counts[0].total || 0;
}
async pageByParams(params, startRow, pageSize) {
var sql = [];
sql.push("SELECT");
sql.push("t1.*");
sql.push("FROM `invoice` t1");
sql.push("INNER JOIN `invoice_apply` t2 ON t1.`id` = t2.`id`");
sql.push("WHERE 1 = 1 ");
this.setCondition(params, sql);
sql.push("ORDER BY id DESC");
sql.push("LIMIT :startRow, :pageSize");
params.startRow = startRow || 0;
params.pageSize = pageSize || 10;
return await this.customQuery(sql.join(" "), params);
}
setCondition(params, sql) {
var complateTax = params.complateTax;
if (complateTax != "-1") {
params.complateTax = Number(complateTax);
sql.push("AND t1.`complate_tax` = :complateTax");
}
// invoiceTimeBegin 2019-01-01 2019-01-01 00:00:00
// invoiceTimeEnd 2019-11-01 2019-11-01 23:59:59
if(params.invoiceTimeBegin) {
sql.push("AND t1.`invoice_time` >= :invoiceTimeBegin");
}
if(params.invoiceTimeEnd) {
sql.push("AND t1.`invoice_time` <= :invoiceTimeEnd");
}
if(params.invoiceTime){
sql.push("AND t1.`invoice_time` >= :invoiceTime");
}
if(params.applyNo) {
sql.push("AND t2.`apply_no` = :applyNo");
}
if(params.redStatus) {
sql.push("AND t1.`red_status` = :redStatus");
}
if (params.type) {
sql.push("AND t2.`type` = :type");
}
if(params.statuses && params.statuses.length > 0){
sql.push("AND t2.`status` in (:statuses)");
}
}
}
module.exports = InvoiceDao;
\ No newline at end of file
...@@ -8,7 +8,7 @@ const md5 = require("MD5"); ...@@ -8,7 +8,7 @@ const md5 = require("MD5");
//同时增加账户数量,增加系统平台账户 //同时增加账户数量,增加系统平台账户
var dbf=system.getObject("db.common.connection"); var dbf=system.getObject("db.common.connection");
var db=dbf.getCon(); var db=dbf.getCon();
db.sync({force:true}).then(async ()=>{ db.sync({force:false}).then(async ()=>{
console.log("sync complete..."); console.log("sync complete...");
//创建role //创建role
......
...@@ -21,7 +21,6 @@ module.exports = { ...@@ -21,7 +21,6 @@ module.exports = {
}, },
"pdict": { "pdict": {
"logLevel": { "debug": 0, "info": 1, "warn": 2, "error": 3, "fatal": 4 }, "logLevel": { "debug": 0, "info": 1, "warn": 2, "error": 3, "fatal": 4 },
"sex": {"male": "男", "female": "女"},
} }
} }
} }
\ No newline at end of file
...@@ -3,54 +3,27 @@ const settings=require("../../../../config/settings"); ...@@ -3,54 +3,27 @@ const settings=require("../../../../config/settings");
const uiconfig=system.getUiConfig2(settings.appKey); const uiconfig=system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => { module.exports = (db, DataTypes) => {
return db.define("user", { return db.define("user", {
userName: { ucid: {
type:DataTypes.STRING, type:DataTypes.INTEGER,
allowNull: false, allowNull: false,
}, },
password: { ucname: {
type:DataTypes.STRING, type:DataTypes.STRING,
allowNull: false, allowNull: false,
}, },
nickName: { lastLoginTime: {
type:DataTypes.STRING, type:DataTypes.DATE,
allowNull: true,
},
sex: {
type:DataTypes.ENUM,
allowNull: true,
values: Object.keys(uiconfig.config.pdict.sex),
},
mobile:DataTypes.STRING,
mail: {
type:DataTypes.STRING,
allowNull: true, allowNull: true,
}, },
headUrl: DataTypes.STRING,
isAdmin:{
type:DataTypes.BOOLEAN,
defaultValue: false
},
isSuper:{
type:DataTypes.BOOLEAN,
defaultValue: false
},
openId:DataTypes.STRING,
app_id:DataTypes.INTEGER,
account_id:DataTypes.INTEGER,
isEnabled:{
type:DataTypes.BOOLEAN,
defaultValue: true
},
},{ },{
paranoid: true,//假的删除 paranoid: true,//假的删除
underscored: true, underscored: true,
version: true, version: true,
freezeTableName: true, freezeTableName: true,
//freezeTableName: true, // freezeTableName: true,
// define the table's name // define the table's name
tableName: 'p_user', tableName: 'xgg_admin_user',
validate: { validate: {
}, },
indexes:[ indexes:[
// Create a unique index on email // Create a unique index on email
......
const system = require("../../../system");
const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey);
const moment = require('moment')
/**
* 发表申请表
*/
module.exports = (db, DataTypes) => {
return db.define("apply", {
//抬头信息 购买方
merchantId: {type: DataTypes.STRING,field: 'merchant_id', allowNull: true, comment:'个体工商户id(购买方id)' },
merchantName: {type: DataTypes.STRING,field: 'merchant_name', allowNull: false, comment:'抬头名称' },
merchantCreditCode: {type: DataTypes.STRING,field: 'merchant_credit_code', allowNull: false, comment:'纳税人识别号' },
merchantAddr: {type: DataTypes.STRING,field: 'merchant_addr', allowNull: false, comment:'地址' },
merchantMobile: {type: DataTypes.STRING,field: 'merchant_mobile', allowNull: false, comment:'电话' },
merchantBank: {type: DataTypes.STRING,field: 'merchant_bank', allowNull: false, comment:'开户行' },
merchantAccount: {type: DataTypes.STRING,field: 'merchant_account', allowNull: false, comment:'账号' },
//销售方信息
businessmenId:{type: DataTypes.STRING,field: 'businessmen_id', allowNull: false, comment:'销售方id' },
businessmenCreditCode:{type: DataTypes.STRING,field: 'businessmen_credit_code', allowNull: false, comment:'个体户社会统一信息用代码' },
businessmenName:{type: DataTypes.STRING,field: 'businessmen_name', allowNull: false, comment:'销售方名称' },
businessmenAddr:{type: DataTypes.STRING,field: 'businessmen_addr', allowNull: false, comment:'销售方地址' },
businessmenMobile:{type: DataTypes.STRING,field: 'businessmen_mobile', allowNull: false, comment:'销售方电话' },
businessmenBank:{type: DataTypes.STRING,field: 'businessmen_bank', allowNull: false, comment:'销售方开户行' },
businessmenAccount:{type: DataTypes.STRING,field: 'businessmen_account', allowNull: false, comment:'销售方账户' },
isBank:{type: DataTypes.INTEGER, field: 'is_bank', allowNull: false, defaultValue: 0, comment:'开户状态:1.已开户 0.未开户'},
taxAuthorities:{type: DataTypes.STRING,field: 'tax_authoritioes', allowNull: true, comment:'税务报道机构' },
//发票信息
// invoiceNo:{type: DataTypes.STRING,field: 'invoice_no', allowNull: true, comment:'发票编号' },
type:{type: DataTypes.INTEGER,field: 'type', allowNull: false, defaultValue:10, comment:'发票类型:10 普通发票 20 增值税专用发票 30 电子发票' },
invoiceAmount:{type: DataTypes.BIGINT,field: 'invoice_amount', allowNull: false, comment:'发票总额' },
statements:{type: DataTypes.STRING,field: 'statements', allowNull: false, comment:'结算单' },
contract:{type: DataTypes.STRING,field: 'contract', allowNull: false, comment:'合同' },
invoiceTime:{type: DataTypes.DATE,field: 'invoice_time', allowNull: true, comment:'开票时间' },
settleImg:{type: DataTypes.STRING,field: 'settle_img', allowNull: true, comment:'开票凭证' },
applyNo:{type: DataTypes.STRING,field: 'apply_no', allowNull: true, comment:'开票申请记录' },
invoiceContent:{type: DataTypes.STRING,field: 'invoice_content', allowNull: true, comment:'开票内容' },
personalIncomeTax:{type: DataTypes.BIGINT,field: 'personal_invoice_tax', allowNull: true, comment:'个税',
set:function(val, key) {
if(val=="0.00"){val=0;}
if(String(val).indexOf(".")!=-1){
val=val*100;
}
let v = val?val:0;
this.setDataValue(key, v);} },
additionalTax:{type: DataTypes.BIGINT,field: 'additional_tax', allowNull: true, comment:'附加税',
set:function(val, key) {
if(val=="0.00"){val=0;}
if(String(val).indexOf(".")!=-1){
val=val*100;
}
let v = val?val:0;
this.setDataValue(key, v);} },
valueAddedTax:{type: DataTypes.BIGINT,field: 'value_added_tax', allowNull: true, comment:'增值税',
set:function(val, key) {
if(val=="0.00"){val=0;}
if(String(val).indexOf(".")!=-1){
val=val*100;
}
let v = val?val:0;
this.setDataValue(key, v);} },
serviceCharge:{type: DataTypes.BIGINT,field: 'service_change', allowNull: true, comment:'服务费',
set:function(val, key) {
if(val=="0.00"){val=0;}
if(String(val).indexOf(".")!=-1){
val=val*100;
}
let v = val?val:0;
this.setDataValue(key, v);} },
applyMobile:{type: DataTypes.STRING,field: 'apply_mobile', allowNull: true, comment:'申请方电话' },
isInvalid:{ type: DataTypes.STRING, field: 'is_invalid', allowNull: false,
get:function() {
var isInvalid = this.getDataValue('isInvalid');
let v;
if(isInvalid==1){
v="未红冲";
}else if(isInvalid==2){
v="红冲中";
}else if(isInvalid==3){
v="红冲失败";
}else if(isInvalid==4){
v="红冲成功"
}
return v;
},
defaultValue: 1,
comment:'红冲状态 1:未红冲 2:红冲中 3 红冲失败 4 红冲成功'
},
parentId:{type: DataTypes.STRING,field: 'parent_id', allowNull: true, comment:'父id 红冲的关系id' },
//发票状态
status:{ type: DataTypes.STRING, field: 'status', allowNull: false, defaultValue:'1000', comment:'订单状态 1000 未付款 1010 审核不通过 1020 代分配 1030 待处理 1040 交付商关闭 1050 已开具 1060 代审核 1070 审核通过 1080 已邮寄 1090 完成 1100 发票撤回'},
customerStatus:{ type: DataTypes.STRING, field: 'customer_status', allowNull: false, defaultValue:'1000', comment:'客户端状态 1000 未付款 1030 待处理 1050 已开具 1090 完成 1100 发票撤回'},
//付款信息
payWay:{ type: DataTypes.STRING, field: 'pay_way', allowNull: true, comment:'付款方式 10 系统账户扣款 20 线上支付'},
payAccount:{ type: DataTypes.STRING, field: 'pay_account', allowNull: true, comment:'付款账户'},
isPay:{type: DataTypes.INTEGER, field: 'is_pay', allowNull: false, defaultValue:0, comment:'支付状态:1.已支付 0.未支付'},
//邮寄地址
mailAddr:{type: DataTypes.STRING,field: 'mail_addr', allowNull: true, comment:'邮寄地址' },
mailMobile:{type: DataTypes.STRING,field: 'mail_mobile', allowNull: true, comment:'邮寄电话' },
mailTo:{type: DataTypes.STRING,field: 'mail_to', allowNull: true, comment:'邮寄人' },
//平台第一次审核信息
remark:{type: DataTypes.STRING,field: 'remark', allowNull: true, comment:'平台审核备注' },
delivererId:{type: DataTypes.STRING,field: 'deliverer_id', allowNull: true, comment:'正在办理的交付商id' },
createdAt: { type: DataTypes.DATE, field: 'created_at', allowNull: false, defaultValue: DataTypes.NOW,comment:'发票创建时间',
get() {
let res = moment(this.getDataValue('createdAt')).add(8).format('YYYY-MM-DD HH:mm:ss');
return res;
}
},
updatedAt: { type: DataTypes.DATE, field: 'updated_at', allowNull: false, defaultValue: DataTypes.NOW ,comment:'更新时间',
get(key) {
let res = moment(this.getDataValue(key)).add(8).format('YYYY-MM-DD HH:mm:ss');
return res;
}
},
deletedAt: { type: DataTypes.DATE, field: 'deleted_at', allowNull: true, comment:'删除时间'}
},{
timestamps: true,
underscore: false,
freezeTableName: true,
paranoid: true,
// schema: '',
tableName: 'invoice_apply',
comment: '发票申请表',
charset: 'utf8',
collate: 'utf8_general_ci',
version: true
});
}
\ No newline at end of file
const system = require("../../../system");
const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey);
//平台审批表 所有平台审批信息都添加到此表中 此表的状态应该和申请表的状态保持一致
module.exports = (db, DataTypes) => {
return db.define("deliverer", {
//发票id
invoiceId: {type: DataTypes.STRING,field: 'invoice_id', allowNull: true, comment:'发票id' },
applyNo:{type: DataTypes.STRING,field: 'apply_no', allowNull: false, comment:'发票编号' },
merchantId: {type: DataTypes.STRING,field: 'merchant_id', allowNull: true, comment:'个体工商户id(购买方id)' },
//平台选取交付商提交信息
delivererId:{type: DataTypes.STRING,field: 'deliverer_id', allowNull: true, comment:'交付商id' },
delivererName:{type: DataTypes.STRING,field: 'deliverer_name', allowNull: true, comment:'交付商名称' },
delivererAmount:{type: DataTypes.BIGINT,field: 'deliverer_amount', allowNull: true, comment:'交付商分成' },
breakReason:{type: DataTypes.STRING,field: 'break_reason', allowNull: true, comment:'拒绝原因' },
//平台第二次审核提交信息
auditContent:{type: DataTypes.STRING,field: 'audit_content', allowNull: true, comment:'审核备注' },
delivererContent:{type: DataTypes.STRING,field: 'deliverer_content', allowNull: true, comment:'交付内容' },
mailAddr:{type: DataTypes.STRING,field: 'mail_addr', allowNull: true, comment:'邮寄地址' },
mailMobile:{type: DataTypes.STRING,field: 'mail_mobile', allowNull: true, comment:'邮寄电话' },
mailTo:{type: DataTypes.STRING,field: 'mail_to', allowNull: true, comment:'邮寄人' },
mailEmail:{type: DataTypes.STRING,field: 'mail_email', allowNull: true, comment:'邮寄邮箱' },
//交付商交付信息(如果交付商邮寄那么则这个字段本应该在invoice表中,但是为了方便查询放在此表中)
delivererMailNo:{type: DataTypes.STRING,field: 'deliverer_mail_no', allowNull: true, comment:'交付商邮寄单号' },
platformMailNo:{type: DataTypes.STRING,field: 'platform_mail_no', allowNull: true, comment:'平台邮寄单号' },
createdAt: { type: DataTypes.DATE, field: 'created_at', allowNull: false, defaultValue: DataTypes.NOW,comment:'发票创建时间'},
updatedAt: { type: DataTypes.DATE, field: 'updated_at', allowNull: false, defaultValue: DataTypes.NOW ,comment:'更新时间'},
deletedAt: { type: DataTypes.DATE, field: 'deleted_at', allowNull: true, comment:'删除时间'}
},{
timestamps: true,
underscore: false,
freezeTableName: true,
paranoid: true,
// schema: '',
tableName: 'invoice_deliverer',
comment: '交付商分配表',
charset: 'utf8',
collate: 'utf8_general_ci',
version: true
});
}
\ No newline at end of file
const system = require("../../../system");
const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey);
const moment = require('moment')
//发票表 交付商提交的所有字段都保存到这个表中
module.exports = (db, DataTypes) => {
return db.define("invoice", {
applyNo:{type: DataTypes.STRING,field: 'apply_no', allowNull: false, comment:'发票申请号' },
merchantId: {type: DataTypes.STRING,field: 'merchant_id', allowNull: true, comment:'个体工商户id(购买方id)' },
status:{ type: DataTypes.INTEGER, field: 'status', allowNull: true, comment:'审核状态 1030 待处理 1040 交付商关闭 1050 已开具 1060 代审核 1070 审核通过 1080 已邮寄'},
//已开具
invoiceNo:{type: DataTypes.STRING,field: 'invoice_no', allowNull: true, comment:'发票编号' },
invoiceTime: { type: DataTypes.DATE, field: 'invoice_time', allowNull: true, defaultValue: DataTypes.NOW,comment:'开票时间',
get() {
let res = moment(this.getDataValue('updatedAt')).add(8).format('YYYY-MM-DD HH:mm:ss');
return res;
}
},
invoiceImg:{type: DataTypes.STRING,field: 'invoice_img', allowNull: true, comment:'发票照片' },
//拒绝原因
//reason:{type: DataTypes.STRING,field: 'reason', allowNull: true, comment:'拒绝原因' },
//完税
taxNo:{type: DataTypes.STRING,field: 'tax_no', allowNull: true, comment:'完税批号'},
complateTax: {type:DataTypes.INTEGER,field: 'complate_tax', allowNull: true, defaultValue:0,comment:'是否完税 0 未完成 1 已完成',
get:function() {
var isInvalid = this.getDataValue('complateTax');
var v = isInvalid=='1'?"已完成":"未完成";
return v;
},},
taxTime: { type: DataTypes.DATE, field: 'tax_time', allowNull: true, defaultValue: DataTypes.NOW,comment:'完税时间',
get() {
let res = moment(this.getDataValue('taxTime')).add(8).format('YYYY-MM-DD HH:mm:ss');
return res;
}},
taxVoucher:{type: DataTypes.STRING,field: 'tax_voucher', allowNull: true, comment:'完税照片' },
//邮寄相关
mailNo:{type: DataTypes.STRING,field: 'mail_no', allowNull: true, comment:'快递单号' },
redStatus:{ type: DataTypes.STRING, field: 'red_status', allowNull: false, defaultValue: '1',
comment:'红冲状态 1:未红冲 2:红冲中 3 红冲失败 4 红冲成功'
},
createdAt: { type: DataTypes.DATE, field: 'created_at', allowNull: false, defaultValue: DataTypes.NOW,comment:'发票创建时间',
get() {
let res = moment(this.getDataValue('createdAt')).add(8).format('YYYY-MM-DD HH:mm:ss');
return res;
}},
updatedAt: { type: DataTypes.DATE, field: 'updated_at', allowNull: false, defaultValue: DataTypes.NOW ,comment:'更新时间',
get() {
let res = moment(this.getDataValue('updatedAt')).add(8).format('YYYY-MM-DD HH:mm:ss');
return res;
}},
deletedAt: { type: DataTypes.DATE, field: 'deleted_at', allowNull: true, comment:'删除时间'},
},{
timestamps: true,
underscore: false,
freezeTableName: true,
paranoid: true,
// schema: '',
tableName: 'invoice',
comment: '发票表',
charset: 'utf8',
collate: 'utf8_general_ci',
version: true
});
}
\ No newline at end of file
const system=require("../../../system"); const system=require("../../../system");
const ServiceBase=require("../../sve.base"); const ServiceBase=require("../../sve.base");
const fs=require("fs"); const fs=require("fs");
var excel = require('exceljs');
const uuidv4 = require('uuid/v4'); const uuidv4 = require('uuid/v4');
var path= require('path'); var path= require('path');
class TaskService extends ServiceBase{ class TaskService extends ServiceBase{
......
const ServiceBase = require("../../sve.base");
const system = require("../../../system");
const moment = require('moment')
/**
* 交付商 提交的信息
*/
class InvoiceService extends ServiceBase {
constructor() {
super("invoice", ServiceBase.getDaoName(InvoiceService));
let is = system.getObject("util.invoiceStatus");
this.invoiceStatus = is.status;
this.applyDao = system.getObject("db.invoice.applyDao");
this.delivererDao = system.getObject("db.invoice.delivererDao");
}
/**
* 完税证明
* @param {*} params
*/
async apiTxPayment(params) {
if (!params.id) {
return system.getResult(null, `参数错误 发票ID不合法`);
}
try {
let res = await this.txPayment(params);
return res;
} catch (error) {
return system.getResult(null, `参数错误 错误信息 ${error}`);
}
}
/**
* 查看完税证明
* @param {*} params
*/
async apiQueryTxPayment(params) {
if (!params.id) {
return system.getResult(null, `参数错误 发票ID不合法`);
}
try {
return await this.queryTxPayment(params);
} catch (error) {
return system.getResult(null, `参数错误 错误信息 ${error}`);
}
}
/**
* 发票列表(平台)
* @param {*} params
*/
async apiQueryInvoices(params) {
try {
if(params.applyNo){params.applyNo=this.trim(params.applyNo)}
if(params.type){params.type=this.trim(params.type);}
if(params.invoiceTime){params.invoiceTime=this.trim(params.invoiceTime);}
return await this.queryInvoices(params);
} catch (error) {
return system.getResult(null, `系统错误 错误信息 ${error}`);
}
}
//==============================================================
/**
* 完税证明
* @param {*} params
* {
* id:xxx //完税证明
* }
*/
async txPayment(params) {
try {
let _invoice = await this.dao.findOne({
id: this.trim(params.id)
});
if (!_invoice) {
return system.getResult(null, `发票不存在`);
}
let res = await this.dao.update({
id: this.trim(params.id),
taxNo: this.trim(params.taxNo),
complateTax: 1,
taxTime: this.trim(params.taxTime),
taxVoucher: this.trim(params.taxVoucher)
});
return system.getResult(res);
} catch (error) {
return system.getResult(null, `参数错误 错误信息 ${error}`);
}
}
/**
* 查看完税证明
* @param {*} params
* {
* id:xxx //完税证明
* }
*/
async queryTxPayment(params) {
try {
let _invoice = await this.dao.model.findOne({
where: {
id: this.trim(params.id),
complateTax: 1
},
attributes: ['id', 'taxNo', 'complateTax', 'taxTime', 'taxVoucher']
});
if (!_invoice) {
return system.getResult(null, `完税证明不存在`);
}
return system.getResult(_invoice);
} catch (error) {
return system.getResult(null, `参数错误 错误信息 ${error}`);
}
}
/**
* 发票列表查询(平台)
* @param {*} params
* @param applyNo 发票的申请编号
* @param invoiceTime 发票的申请时间
* @param type 发票的类型
* @param status 业务进度
*/
async queryInvoices(params) {
try {
var pageIndex = Number(params.pageIndex || 1);
var pageSize = Number(params.pageSize || 10);
var total = await this.dao.countByParams(params);
if (total == 0) {
return system.getResultSuccess({
count: 0,
rows: []
});
}
var startRow = (pageIndex - 1) * pageSize;
var list = await this.dao.pageByParams(params, startRow, pageSize);
await this.setApply(list);
for (var item of list) {
// item.redStatusName = this.dao.getRowCodeName(item, "red_status");
if (item.red_status == 1) {
item.red_status = '未红冲';
} else if (item.red_status == 2) {
item.red_status = '红冲中';
} else if (item.red_status == 3) {
item.red_status = '红冲失败'
} else if (item.red_status == 4) {
item.red_status = '红冲成功';
} else {
item.red_status = '';
}
this.dao.getRowCodeName(item.apply,"status");
item.complate_tax = item.complate_tax == 1 ? '已完税' : '未完税';
item.month = moment(item.invoice_time).month() + 1;
this.handleDate(item,['invoice_time'],null,-8);
if (item.apply['type'] == '10') {
item.apply['type'] = "普通发票";
} else if (item.apply['type'] == '20') {
item.apply['type'] = "增值税专用发票";
} else {
item.apply['type'] = "电子发票";
}
}
var page = {
count: total,
rows: list
};
return system.getResultSuccess(page);
} catch (error) {
console.log(error);
return system.getResult(`系统错误 错误信息 ${error}`);
}
}
async setApply(list) {
if (!list || list.length == 0) {
return;
}
var ids = [];
for (var item of list) {
ids.push(item.id);
}
var applyMap = await this.applyDao.findMapByIds(ids) || {};
for (var item of list) {
item.apply = applyMap[item.id] || {};
}
}
}
module.exports = InvoiceService;
\ No newline at end of file
...@@ -10,7 +10,6 @@ class ServiceBase { ...@@ -10,7 +10,6 @@ class ServiceBase {
this.daoName = daoName; this.daoName = daoName;
this.dao = system.getObject("db." + gname + "." + daoName); this.dao = system.getObject("db." + gname + "." + daoName);
this.restS = system.getObject("util.restClient"); this.restS = system.getObject("util.restClient");
this.orderBusinessStatus = system.getObject("util.orderBusinessStatus");
} }
/** /**
* 验证签名 * 验证签名
......
...@@ -147,55 +147,33 @@ class System { ...@@ -147,55 +147,33 @@ class System {
static getUid(len, radix) { static getUid(len, radix) {
var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''); var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
var uuid = [], var uuid = [],
i; i;
radix = radix || chars.length; radix = radix || chars.length;
if (len) { if (len) {
for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix]; for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
} else { } else {
var r; var r;
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'; uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
uuid[14] = '4'; uuid[14] = '4';
for (i = 0; i < 36; i++) { for (i = 0; i < 36; i++) {
if (!uuid[i]) { if (!uuid[i]) {
r = 0 | Math.random() * 16; r = 0 | Math.random() * 16;
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r]; uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
}
} }
}
} }
return uuid.join(''); return uuid.join('');
} }
static microsetting() {
var path = "/api/op/action/springboard";
if (settings.env == "dev") {
var domain = "http://192.168.18.237";
return {
common: domain + ":3102" + path,
merchant: domain + ":3101" + path,
order: domain + ":3103" + path,
invoice: "" + path,
payment: "" + path,
}
} else {
var odomain = "http://39.107.51.68"
return {
common: odomain + ":8333" + path,
merchant: odomain + ":8335" + path,
order: odomain + ":8336" + path,
invoice: odomain + ":8338" + path,
payment: odomain + ":8337" + path,
} }
}
} }
Date.prototype.Format = function (fmt) { //author: meizz Date.prototype.Format = function (fmt) { //author: meizz
var o = { var o = {
"M+": this.getMonth() + 1, //月份 "M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日 "d+": this.getDate(), //日
"h+": this.getHours(), //小时 "h+": this.getHours(), //小时
"m+": this.getMinutes(), //分 "m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒 "s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度 "q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒 "S": this.getMilliseconds() //毫秒
}; };
if (/(y+)/.test(fmt)) if (/(y+)/.test(fmt))
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
......
const system = require("../../system");
const uuidv4 = require('uuid/v4');
const md5 = require("MD5");
var settings = require("../../../config/settings");
class OpPlatformUtils {
constructor() {
this.logCtl = system.getObject("web.common.oplogCtl");
this.cacheManager = system.getObject("db.common.cacheManager");
this.restClient = system.getObject("util.restClient");
this.createUserUrl = settings.paasUrl() + "api/auth/accessAuth/register";
this.fetchDefaultVCodeUrl = settings.paasUrl() + "api/auth/accessAuth/fetchDefaultVCode";
this.loginUrl = settings.paasUrl() + "api/auth/accessAuth/login";
this.authByCodeUrl = settings.paasUrl() + "api/auth/accessAuth/authByCode";
}
getUUID() {
var uuid = uuidv4();
var u = uuid.replace(/\-/g, "");
return u;
}
async getReqApiAccessKey() {
return await this.cacheManager["ApiAccessKeyCache"].cache(settings.appKey, null, 3600);
}
/**
* 创建用户信息
* @param {*} userName 用户名
* @param {*} mobile 手机号
* @param {*} password 密码,不传为使用默认密码
*
* 返回值:
* {
"status": 0,---值为2000为已经存在此用户,注册失败
"msg": "success",
"data": {
"auth_url": "http://sj.app.com:3002/auth?opencode=1e4949d1c39444a8b32f023143625b1d",---回调url,通过回调地址获取平台用户信息
"opencode": "1e4949d1c39444a8b32f023143625b1d",---平台用户code随机生成会变,平台是30s有效期,通过其可以向获取用户信息
"open_user_id": 12---平台用户id
},
"requestid": "5362bf6f941e4f92961a61068f05cd7f"
}
*/
async createUserInfo(userName, mobile, password) {
var reqApiAccessKey = await this.getReqApiAccessKey();
if (!reqApiAccessKey || !reqApiAccessKey.accessKey) {
return system.getResult(null, "获取请求token失败");
}
var param = {
userName: userName,
mobile: mobile,
password: password || settings.defaultPassWord,
}
//按照访问token
var restResult = await this.restClient.execPostWithAK(
param,
this.createUserUrl, reqApiAccessKey.accessKey);
if (restResult.status != 0 || !restResult.data) {
return system.getResult(restResult.status, restResult.msg);
}
return system.getResultSuccess(restResult.data);
}
async fetchVCode(mobile) {
var reqApiAccessKey = await this.getReqApiAccessKey();
if (!reqApiAccessKey || !reqApiAccessKey.accessKey) {
return system.getResult(null, "获取请求token失败");
}
var param = { mobile: mobile }
//按照访问token
var restResult = await this.restClient.execPostWithAK(
param,
this.fetchDefaultVCodeUrl, reqApiAccessKey.accessKey);
if (restResult.status != 0 || !restResult.data) {
return system.getResult(null, restResult.msg);
}
return system.getResultSuccess();
}
/**
* 用户登录
* @param {*} userName 用户名
* @param {*} password 密码,不传为使用默认密码
*
* 返回值:
* {
"status": 0,---值为2010为用户名或密码错误
"msg": "success",
"data": {
"auth_url": "http://sj.app.com:3002/auth?opencode=1e4949d1c39444a8b32f023143625b1d",---回调url,通过回调地址获取平台用户信息
"opencode": "1e4949d1c39444a8b32f023143625b1d"---平台用户code随机生成会变,平台是30s有效期,通过其可以向获取用户信息
},
"requestid": "5362bf6f941e4f92961a61068f05cd7f"
}
*/
async login(userName, password) {
var reqApiAccessKey = await this.getReqApiAccessKey();
if (!reqApiAccessKey || !reqApiAccessKey.accessKey) {
return system.getResult(null, "获取请求token失败");
}
var param = {
userName: userName,
password: password || settings.defaultPassWord,
}
//按照访问token
var restResult = await this.restClient.execPostWithAK(
param,
this.loginUrl, reqApiAccessKey.accessKey);
if (restResult.status != 0 || !restResult.data) {
return system.getResult(restResult.status, restResult.msg);
}
return system.getResultSuccess(restResult.data);
}
/**
* 通过opencode获取用户登录信息
* @param {*} opencode 用户登录或注册opencode
*
* 返回值:
* {
"status": 0,---值为2010为用户名或密码错误
"msg": "success",
"data": {},---平台用户信息
"requestid": "5362bf6f941e4f92961a61068f05cd7f"
}
*/
async authByCode(opencode) {
var reqApiAccessKey = await this.getReqApiAccessKey();
if (!reqApiAccessKey || !reqApiAccessKey.accessKey) {
return system.getResult(null, "获取请求token失败");
}
var param = {
opencode: opencode
}
//按照访问token
var restResult = await this.restClient.execPostWithAK(
param,
this.authByCodeUrl, reqApiAccessKey.accessKey);
if (restResult.status != 0 || !restResult.data) {
return system.getResult(restResult.status, restResult.msg);
}
return system.getResultSuccess(restResult.data);
}
}
module.exports = OpPlatformUtils;
const system = require("../../system");
const uuidv4 = require('uuid/v4');
const md5 = require("MD5");
class PushUtils {
constructor() {
this.logCtl = system.getObject("web.common.oplogCtl");
this.cacheManager = system.getObject("db.common.cacheManager");
this.merchantpushlogSve = system.getObject("service.merchant.merchantpushlogSve");
this.execClient = system.getObject("util.execClient");
this.merchantpushSve = system.getObject("service.merchant.merchantpushSve");
}
getUUID() {
var uuid = uuidv4();
var u = uuid.replace(/\-/g, "");
return u;
}
async getCachePushItemUrl(merchant_id) {
return await this.cacheManager["MerchantPushUrlCache"].cache(merchant_id, null, 3600);
}
/**
* 推送到第三方数据
* @param {*} reqUrl 请求推送的url
* @param {*} params 推送的参数
*/
async push(merchantId, field, params) {
try {
var pushConfig = await this.getCachePushItemUrl(merchantId) || {};
var reqUrl = pushConfig[field];
if(!reqUrl) {
this.logCtl.error({
optitle: "推送到第三方数据异常error",
op: "merchantId = " + merchantId + "; reqUrl is empty, field = " + field,
content: "reqUrl is empty",
clientIp: "pushUtils中没有ip"
});
return;
}
// 签名
params.sign = await this.createSign(params, merchantId);
params.requestid = this.getUUID();
var rtn = await this.execClient.execPost(params, reqUrl);
var returnValue = 0;
if (rtn.stdout) {
var result = JSON.parse(rtn.stdout);
if (result.code == "success") {
returnValue = 1;
}
}
//记录推送结果
this.merchantpushlogSve.create({
merchant_id: merchantId,//商户id
api: reqUrl,//接口地址
params: JSON.stringify(params),//推送数据信息
rs: rtn.stdout,//推送返回结果
success: returnValue//是否推送成功
});
} catch (e) {
console.log(e.stack);
this.logCtl.error({
optitle: "推送到第三方数据异常error",
op: reqUrl + ";params=" + JSON.stringify(params) + ";reqid=" + params.requestid,
content: e.stack,
clientIp: "pushUtils中没有ip"
});
}
}
/**
* 多次推送到第三方数据
* @param {*} reqUrl 请求推送的url
* @param {*} params 推送的参数
*/
async pushMany(reqUrl, params) {
try {
params.requestid = this.getUUID();
var rtn = this.execClient.execPost(params, reqUrl);
//TODO:可以做多次推送,规则待定
// var result = JSON.parse(rtn.stdout);
// if (result && result.code == 200) {
// var resultdata = result.data;
// return { code: 1, msg: "success" };
// } else {
// return { code: -1, msg: "err" };
// }
} catch (e) {
this.logCtl.error({
optitle: "多次推送到第三方数据异常error",
op: url + ";params=" + JSON.stringify(params) + ";reqid=" + params.requestid,
content: e.stack,
clientIp: pobj.clientIp
});
}
}
async createSign(params, appId) {
var appInfo = await this.cacheManager["ApiAppIdCheckCache"].cache(appId, null, 3000);
var signArr = [];
var keys = Object.keys(params).sort();
for (let k = 0; k < keys.length; k++) {
const tKey = keys[k];
if (tKey != "sign" && params[tKey]) {
signArr.push(tKey + "=" + params[tKey]);
}
}
var resultSignStr = signArr.join("&") + "&key=" + appInfo.appSecret;
return md5(resultSignStr).toUpperCase();
}
}
module.exports = PushUtils;
var excel = require('exceljs');
const system=require("../system");
const uuidv4 = require('uuid/v4');
const fs=require("fs");
class ExcelClient {
constructor() {
this.columns = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
this.ossClient=system.getObject("util.ossClient");
this.filedownloadDao = system.getObject("db.filedownloadDao");
}
async download(params) {
var self = this;
var title = params.title || "";
var code = params.code || uuidv4();
var fileName = params.fileName || code + ".xlsx";
var filePath = params.filePath || "/tmp/" + fileName;
var rows = params.rows || [];
var user = params.user || {};
var wb = new excel.Workbook();
wb.properties.date1904 = true;
var sheet = wb.addWorksheet("sheet1");
var headers = rows[0];
console.log(headers, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2 headers");
if(title) {
sheet.addRow([title]);
sheet.getCell("A1").font = {
    name: '微软雅黑',
    family: 4,
    size: 12,
    bold: true
};
sheet.getCell('A1').alignment = { vertical: 'middle', horizontal: 'center' };
var colkey = 0;
if(headers.length > 0) {
colkey = headers.length - 1;
}
var endColumn = this.columns[colkey] || "A";
sheet.mergeCells("A1:" + endColumn + "1");
}
for(var r of rows) {
sheet.addRow(r);
}
wb.xlsx.writeFile(filePath).then(async function(d) {
var rtn = await self.ossClient.upfile(fileName, filePath);
fs.unlink(filePath,function(err){});
var obj = {
user_id : user.id || 0,
userName : user.userName || "",
code : code,
fileName : fileName,
filePath : rtn.url || "",
isDownload : false,
}
var obj = await self.filedownloadDao.create(obj);
});
}
}
module.exports = ExcelClient;
const system = require("../system"); const system = require("../system");
class OrderBusinessStatus { class InvoiceStatus {
constructor() { constructor() {
this.busiStatus = { this.finish="1090";
this.unpay="1000";
this.auditPass="1070";
this.recall="1100";
this.unAssignment="1020";//待分被
this.pending="1030";//待处理
this.cancleInvoice="1200";//红冲
this.status = {
"0090": {
"status": "0090",
"name": "未付款",
"next": "1000",
"cstatus": "0090",//客户
"dstatus": "",//交付商
},
"1000": { "1000": {
"status": "1000", "status": "1000",
"name": "未付款", "name": "待审核",
"next": "1020", "next": "1020",
"ostatus": "1000", "cstatus": "0090",//客户
"dstatus": "", "dstatus": "",//交付商
}, },
"1010": { "1010": {
"status": "1010", "status": "1010",
"name": "订单关闭", "name": "审核不通过",
"next": "", "next": "",
"ostatus": "1010", "cstatus": "1010",
"dstatus": "", "dstatus": "",
}, },
"1020": { "1020": {
"status": "1020", "status": "1020",
"name": "待分配", "name": "待分配",
"next": "1030", "next": "1030",
"ostatus": "1030", "cstatus": "1030",
"dstatus": "1030", "dstatus": "",
}, },
"1030": { "1030": {
"status": "1030", "status": "1030",
"name": "待处理", "name": "待处理",
"next": "1050", "next": "1050",
"ostatus": "1030", "cstatus": "1030",
"dstatus": "1030", "dstatus": "1030",
}, },
"1040": { "1040": {
"status": "1040", "status": "1040",
"name": "交付商关闭", "name": "交付商关闭",
"next": "1020", "next": "1020",
"ostatus": "1030", "cstatus": "1030",
"dstatus": "1030", "dstatus": "1040",
}, },
"1050": { "1050": {
"status": "1050", "status": "1050",
"name": "执照办理中", "name": "已开具",
"next": "1060", "next": "1060",
"ostatus": "1050", "cstatus": "1050",
"dstatus": "1050", "dstatus": "1050",
}, },
"1060": { "1060": {
"status": "1060", "status": "1060",
"name": "已出执照", "name": "待审核",
"next": "1070", "next": "1070",
"ostatus": "1060", "cstatus": "1050",
"dstatus": "1060", "dstatus": "1070",
}, },
"1070": { "1070": {
"status": "1070", "status": "1070",
"name": "刻章办理中", "name": "审核通过",
"next": "1080", "next": "1080",
"ostatus": "1070", "cstatus": "1050",
"dstatus": "1070", "dstatus": "1070",
}, },
"1080": { "1080": {
"status": "1080", "status": "1080",
"name": "已刻章", "name": "已邮寄",
"next": "1090", "next": "1090",
"ostatus": "1080", "cstatus": "1050",
"dstatus": "1080", "dstatus": "1080",
}, },
"1090": { "1090": {
"status": "1090", "status": "1090",
"name": "银行开户中", "name": "完成",
"next": "1100", "next": "1100",
"ostatus": "1090", "cstatus": "1090",
"dstatus": "1090", "dstatus": "1080",
}, },
"1100": { "1100": {
"status": "1100", "status": "1090",
"name": "银行卡已开户", "name": "发票撤回",
"next": "1110", "next": "1100",
"ostatus": "1100", "cstatus": "1090",
"dstatus": "1100", "dstatus": "1080",
},
"1110": {
"status": "1110",
"name": "税务报道中",
"next": "1120",
"ostatus": "1110",
"dstatus": "1110",
},
"1120": {
"status": "1120",
"name": "已税务报道",
"next": "1130",
"ostatus": "1120",
"dstatus": "1120",
},
"1130": {
"status": "1130",
"name": "待审核",
"next": "1140",
"ostatus": "1120",
"dstatus": "1130",
},
"1140": {
"status": "1140",
"name": "审核失败",
"next": "1150",
"ostatus": "1120",
"dstatus": "1140",
},
"1150": {
"status": "1150",
"name": "审核通过",
"next": "1160",
"ostatus": "1120",
"dstatus": "1150",
},
"1160": {
"status": "1160",
"name": "已邮寄",
"next": "1170",
"ostatus": "1120",
"dstatus": "1160",
}, },
"1170": { "1200": {
"status": "1170", "status": "1200",
"name": "已完成", "name": "红冲",
"ostatus": "1170", "next": "",
"cstatus": "1200",
"dstatus": "", "dstatus": "",
},
"1300": {
"status": "1300",
"name": "审核失败(平台第二次审核)",
"next": "1060",
"cstatus": "1050",
"dstatus": "1060",
} }
}; };
} }
async findOrderBusinessStatus(status) { async findInvoiceBusinessStatus(status) {
return this.busiStatus[status]; return this.invoiceStatus[status];
} }
async findOrderNextBusinessStatus(status) { async findInvoiceNextBusinessStatus(status) {
var curStatus = await this.findOrderBusinessStatus(status); var curStatus = await this.findInvoiceBusinessStatus(status);
if(!curStatus || !curStatus.next) { if(!curStatus || !curStatus.next) {
return; return;
} }
return await this.findOrderBusinessStatus(curStatus.next); return await this.findInvoiceBusinessStatus(curStatus.next);
} }
} }
module.exports = OrderBusinessStatus; module.exports = InvoiceStatus;
\ No newline at end of file \ No newline at end of file
...@@ -220,6 +220,7 @@ class RedisClient { ...@@ -220,6 +220,7 @@ class RedisClient {
async genrateId(tableName) { async genrateId(tableName) {
// "时间戳 - tableName的hashCode + (1000 - 9999) + 随机8位数" // "时间戳 - tableName的hashCode + (1000 - 9999) + 随机8位数"
var time = parseInt(new Date().getTime() / 1000); var time = parseInt(new Date().getTime() / 1000);
var tabcode = this.hashCode(tableName); var tabcode = this.hashCode(tableName);
......
...@@ -6,10 +6,10 @@ var settings={ ...@@ -6,10 +6,10 @@ var settings={
db:10, db:10,
}, },
database:{ database:{
dbname : "xgg-order", dbname : "xgg-invoice",
user: "write", user: "write",
password: "write", password: "write",
config: { config: {
// host: '43.247.184.35', // host: '43.247.184.35',
// port: 8899, // port: 8899,
host: '192.168.18.237', host: '192.168.18.237',
......
...@@ -4,11 +4,11 @@ var ENVINPUT = { ...@@ -4,11 +4,11 @@ var ENVINPUT = {
DB_PORT: process.env.DB_PORT, DB_PORT: process.env.DB_PORT,
DB_USER: process.env.DB_USER, DB_USER: process.env.DB_USER,
DB_PWD: process.env.DB_PWD, DB_PWD: process.env.DB_PWD,
DB_NAME: process.env.XGGSVEORDER_DB_NAME, DB_NAME: process.env.XGGSVEINVOICE_DB_NAME,
REDIS_HOST: process.env.REDIS_HOST, REDIS_HOST: process.env.REDIS_HOST,
REDIS_PORT: process.env.REDIS_PORT, REDIS_PORT: process.env.REDIS_PORT,
REDIS_PWD: process.env.REDIS_PWD, REDIS_PWD: process.env.REDIS_PWD,
REDIS_DB: process.env.XGGSVEORDER_REDIS_DB, REDIS_DB: process.env.XGGSVEINVOICE_REDIS_DB,
APP_ENV: process.env.APP_ENV ? process.env.APP_ENV : "dev" APP_ENV: process.env.APP_ENV ? process.env.APP_ENV : "dev"
}; };
var settings = { var settings = {
......
## 1. 发票接口
  1 [发票](doc/invoice/invoice_index.md)
<a name="menu">目录</a>
1. [交易数据(交付商)](#delTransData)
1. [业务办理数据(交付商)](#delBusinessData)
1. [交易数据](#transdata)
1. [业务办理数据](#businessData)
1. [业务概览](#businessOverview)
## **<a name="delTransData"> 本月交易数据(交付商)</a>**
[返回到目录](#menu)
##### URL
[/web/index/managerCtl/delTransData]
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
``` javascript
{
"action_process": "sijibao",
"action_type": "delStatTransData",
"action_body": {
"type":"1", // 筛选状态 1本月 2上月 3总计
"delivererId":"11330348689004287" //交付商ID
}
}
```
#### 返回结果
```javascript
{
"status": 0,
"msg": "success",
"data": {
"invoiceCount": 19, // 业务订单量
"delivererAmount": 43600, //服务费
"days": [ // echart日期
"2019-01",
"2019-02",
"2019-03",
],
"dayCounts": [ // echart交易量
1,
0,
0,
],
"priceCounts": [ // echart交易额
3000,
0,
0,
]
},
"requestid": "536712febd5b440f8abe7e5df7480aba"
}
```
## **<a name="delBusinessData"> 业务办理数据(交付商)</a>**
[返回到目录](#menu)
##### URL
[/web/index/managerCtl/delBusinessData]
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
``` javascript
{
"action_process": "sijibao",
"action_type": "delStatBusinessData",
"action_body": {
"type":1, // 筛选状态 1本月 2上月 3总计
"delivererId":"13120681528000587" //交付商ID
}
}
```
#### 返回结果
```javascript
{
"status": 0,
"msg": "success",
"data": {
"completeCount": 0, // 已开具
"handlingCount": 5 // 交付商办理中
},
"requestid": "776c869048b440d4bf16f9e2f7b42fb8"
}
```
## **<a name="transdata"> 本月交易数据(平台)</a>**
[返回到目录](#menu)
##### URL
[/web/index/managerCtl/transData]
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
``` javascript
{
"action_process": "sijibao",
"action_type": "delStatBusinessData",
"action_body": {
"type":1, // 筛选状态 1本月 2上月 3总计
}
}
```
#### 返回结果
```javascript
{
"status": 0,
"msg": "success",
"data": {
"invoiceCount": 19, // 业务订单量
"serviceChange": 43600, // 订单交易额
"days": [ // echart日期
"2019-01",
"2019-02",
"2019-03",
],
"dayCounts": [ // echart交易量
1,
0,
0,
],
"priceCounts": [ // echart交易额
3000,
0,
0,
]
},
"requestid": "536712febd5b440f8abe7e5df7480aba"
}
```
## **<a name="businessData"> 业务办理数据</a>**
[返回到目录](#menu)
##### URL
[/web/index/managerCtl/businessData]
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
``` javascript
{
"action_process": "sijibao",
"action_type": "delStatBusinessData",
"action_body": {
"type":1, // 筛选状态 1本月 2上月 3总计
}
}
```
#### 返回结果
```javascript
{
"status": 0,
"msg": "success",
"data": {
"completeCount": 0, // 已开具
"toApplyCount": 10, // 待申请审核
"toAuditCount": 1, // 待交付审核
"handlingCount": 5 // 交付商办理中
},
"requestid": "776c869048b440d4bf16f9e2f7b42fb8"
}
```
## **<a name="businessOverview"> 业务概览</a>**
[返回到目录](#menu)
##### URL
[/web/index/managerCtl/deliverData]
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
``` javascript
{
"action_process": "sijibao",
"action_type": "delStatBusinessData",
"action_body": {
currentPage: 1,
pageSize: 10,
type: 1, // 筛选状态 1本月 2上月 3总计
}
}
```
#### 返回结果
```javascript
{
"status": 0,
"msg": "success",
"data": {
"count": 3,
"rows": [
{
"deliverName": "某某交付商222", // 交付商
"servicePrice": "4492976", // 服务费
"completeCount": 0, // 完成订单量
"handlingCount": 17 // 办理中订单量
},
{
"id": "11330348689004287", //交易记录id
"deliverer_id": "11330348689004287", //交付商id
"deliverer_name": "111", //交付商名称
"totalAmount": 519.99, //服务费
"completeCount": 0, //完成的订单
"handlingCount": 0 //办理中订单
},
]
},
"requestid": "6ef971357a2745e4b2996a97149c0055"
}
```
\ No newline at end of file
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