Commit a9c44923 by 王昆

gsb

parent 11606669
var system = require("../../../system") var system = require("../../../system")
const CtlBase = require("../../ctlms.base"); const CtlBase = require("../../ctlms.base");
class TradeCtl extends CtlBase { class TradeCtl extends CtlBase {
constructor() { constructor() {
super(); super();
...@@ -15,5 +16,14 @@ class TradeCtl extends CtlBase { ...@@ -15,5 +16,14 @@ class TradeCtl extends CtlBase {
} }
} }
async lockOrder(params, pobj2, req) {
try {
return await this.tradeSve.lockOrder(params);
} catch (error) {
return system.getResult(null, `系统错误 错误信息 ${error}`);
}
}
} }
module.exports = TradeCtl; module.exports = TradeCtl;
\ No newline at end of file
...@@ -9,53 +9,106 @@ class TradeService extends ServiceBase { ...@@ -9,53 +9,106 @@ class TradeService extends ServiceBase {
super(); super();
this.businessmenSve = system.getObject("service.business.businessmenSve"); this.businessmenSve = system.getObject("service.business.businessmenSve");
this.merchantSve = system.getObject("service.saas.merchantSve"); this.merchantSve = system.getObject("service.saas.merchantSve");
this.redisClient = system.getObject("util.redisClient");
}
async lockOrder(params) {
params.acc_type = this.trim(params.acc_type);
params.fileUrl = this.trim(params.fileUrl);
let itemList = params.itemList || [];
if (["00", "01", "02"].indexOf(params.acc_type) == -1) {
return system.getResultFail(-1, `请选择打款通道`, itemList);
}
if (itemList.length == 0) {
return system.getResultFail(-1, `锁定批次无数据`, itemList);
}
// 验证字段
let error = await this.checkItemList(itemList);
if (error) {
return system.getResultFail(-1, `批次内有错误数据,请检查后修改`, itemList);
}
// 获取商户签约信息
let info = await this.merchantSve.signInfo({id: params.saas_merchant_id}) || {};
info = info.data || {};
let main = info.main || {};
// 计算预计付款金额
let result = await this.countAmt(itemList, info);
let out_trade_no = await this.redisClient.genrateId("gsb_out_trade_no");
// 构建订单对象
let order = {
saas_id: params.saas_id,
saas_merchant_id: params.saas_merchant_id,
out_trade_no: out_trade_no,
service_rate: system.f2y(info.trans_service_rate),
amt: result.actual_amt,
actual_amt: result.actual_amt,
deduct_amt: result.deduct_amt,
service_tax: result.service_tax,
item_count: itemList.length,
acc_type: params.acc_type,
order_file: params.fileUrl,
// 付款凭证信息
pay_voucher: "",
pay_bank_account: main.bank_account,
pay_bank_name: main.bank_name,
pay_bank_no: main.bank_no,
itemList: itemList
};
let rs = await this.callms("trade", "saveOrder", order);
return rs;
} }
async parseItems(params) { async parseItems(params) {
// 读取excel // 读取excel
let dataList = await this.readItems(params.fileUrl, params.fileName); let itemList = await this.readItems(params.fileUrl, params.fileName);
// 验证字段 // 验证字段
let error = await this.checkDataList(dataList); let error = await this.checkItemList(itemList);
// 获取商户签约信息
let info = await this.merchantSve.signInfo({id: params.saas_merchant_id}) || {};
// 计算预计付款基恩 // 计算预计付款基恩
let result = await this.countAmt(dataList, params.saas_merchant_id); let result = await this.countAmt(itemList, (info.data || {}));
// 封装返回对象 // 封装返回对象
result.error = error; result.error = error;
result.dataList = dataList; result.itemList = itemList;
return system.getResultSuccess(result); return system.getResultSuccess(result);
} }
async countAmt(dataList, saas_merchant_id) {
let result = {actual_amt:0, deduct_amt:0, service_tax:0}; async countAmt(itemList, info) {
if(!dataList) { let result = {amt:0, actual_amt: 0, deduct_amt: 0, service_tax: 0};
if (!itemList) {
return result; return result;
} }
// 获取商户签约信息
let info = await this.merchantSve.signInfo({id: saas_merchant_id}) || {};
info = info.data || {};
// 服务费,这里已经处理了分转元,不用在处理 // 服务费,这里已经处理了分转元,不用在处理
let service_rate = info.trans_service_rate; let service_rate = info.trans_service_rate;
// 实发总数 // 计算金额
let totalAmt = 0; for (let data of itemList) {
for (let data of dataList) { let amt = Number(data.amt);
totalAmt = totalAmt + Number(data.amt || 0); data.service_tax = parseFloat((amt * service_rate) / 100).toFixed(2);
data.actual_amt = parseFloat(amt).toFixed(2);
data.deduct_amt = parseFloat(Number(data.actual_amt) + Number(data.service_tax)).toFixed(2);
// 总服务费
result.service_tax = Number(result.service_tax) + Number(data.service_tax);
// 总实发
result.actual_amt = Number(result.actual_amt) + Number(data.actual_amt);
// 总扣款
result.deduct_amt = Number(result.service_tax) + Number(data.deduct_amt);
// 总请求打款
result.amt = Number(result.amt) + amt;
} }
// 服务费
result.service_tax = parseFloat((totalAmt * service_rate) / 100).toFixed(2);
// 总实发
result.actual_amt = parseFloat(totalAmt).toFixed(2);
// 总扣款
result.deduct_amt = parseFloat(Number(result.actual_amt) + Number(result.service_tax)).toFixed(2);
return result; return result;
} }
async readItems(fileUrl, fileName) { async readItems(fileUrl, fileName) {
let dataList = []; let itemList = [];
let filePath = settings.localpath() + "saas_xgg_trade_order_" + this.trim(fileName) + ".xlsx"; let filePath = settings.localpath() + "saas_xgg_trade_order_" + this.trim(fileName) + ".xlsx";
try { try {
// await this.downloadFile(params.url, filePath); // await this.downloadFile(params.url, filePath);
...@@ -72,7 +125,7 @@ class TradeService extends ServiceBase { ...@@ -72,7 +125,7 @@ class TradeService extends ServiceBase {
return system.getResult(null, "打款文件无数据") return system.getResult(null, "打款文件无数据")
} }
let rows = sheet.data; let rows = sheet.data;
let dataList = []; let itemList = [];
for (let idx = 6; idx < rows.length; idx++) { for (let idx = 6; idx < rows.length; idx++) {
var data = { var data = {
errors: [] errors: []
...@@ -94,29 +147,29 @@ class TradeService extends ServiceBase { ...@@ -94,29 +147,29 @@ class TradeService extends ServiceBase {
data.open_bank = this.trim(cells[4]); data.open_bank = this.trim(cells[4]);
data.amt = this.trim(cells[5]); data.amt = this.trim(cells[5]);
data.remark = this.trim(cells[6]); data.remark = this.trim(cells[6]);
dataList.push(data); itemList.push(data);
} }
return dataList; return itemList;
} catch (error) { } catch (error) {
console.log(error); console.log(error);
return system.getResult(null, "excel解析出错") return system.getResult(null, "excel解析出错")
} }
} }
async checkDataList(dataList) { async checkItemList(itemList) {
let error = false; let error = false;
if (!dataList || dataList.length == 0) { if (!itemList || itemList.length == 0) {
return system.getResult(null, "打款文件无数据") return system.getResult(null, "打款文件无数据")
} }
// 统一社会信用代码获取 // 统一社会信用代码获取
let creditCodes = []; let creditCodes = [];
for (let data of dataList) { for (let data of itemList) {
creditCodes.push(data.credit_code); creditCodes.push(data.credit_code);
} }
let creditCodeMap = await this.businessmenSve.mapByCreditCodes({creditCodes: creditCodes, attrs: "credit_code"}); let creditCodeMap = await this.businessmenSve.mapByCreditCodes({creditCodes: creditCodes, attrs: "credit_code"});
for (let data of dataList) { for (let data of itemList) {
this.checkField(data, "acc_name", {name: "收款户名", is_require: true, maxLen: 64}); this.checkField(data, "acc_name", {name: "收款户名", is_require: true, maxLen: 64});
let bm = creditCodeMap[data.credit_code]; let bm = creditCodeMap[data.credit_code];
if (!bm) { if (!bm) {
...@@ -139,6 +192,7 @@ class TradeService extends ServiceBase { ...@@ -139,6 +192,7 @@ class TradeService extends ServiceBase {
if (!data || !field) { if (!data || !field) {
return; return;
} }
data.errors = data.errors || [];
let v = data[field]; let v = data[field];
if (rule.is_require && !v) { if (rule.is_require && !v) {
data.errors.push(`${rule.name}未填写`); data.errors.push(`${rule.name}未填写`);
......
...@@ -192,6 +192,10 @@ class System { ...@@ -192,6 +192,10 @@ class System {
// 用户服务 // 用户服务
uc: dev + ":3106" + path, uc: dev + ":3106" + path,
// uc: "http://127.0.0.1:3106" + path, // uc: "http://127.0.0.1:3106" + path,
// 交易
trade: local + ":3107" + path,
// uc: "http://127.0.0.1:3106" + path,
} }
} else { } else {
var odomain = "http://123.57.217.203" var odomain = "http://123.57.217.203"
...@@ -201,6 +205,7 @@ class System { ...@@ -201,6 +205,7 @@ class System {
order: "xggsveorder-service" + path, order: "xggsveorder-service" + path,
invoice: "xggsveinvoice-service" + path, invoice: "xggsveinvoice-service" + path,
uc: "xggsveuc-service" + path, uc: "xggsveuc-service" + path,
trade: "xggsvetrade-service" + path,
} }
} }
} }
......
...@@ -3,6 +3,7 @@ const redis = require("redis"); ...@@ -3,6 +3,7 @@ const redis = require("redis");
const settings = require("../../config/settings"); const settings = require("../../config/settings");
const bluebird = require("bluebird"); const bluebird = require("bluebird");
bluebird.promisifyAll(redis); bluebird.promisifyAll(redis);
// const logCtl=system.getObject("web.oplogCtl"); // const logCtl=system.getObject("web.oplogCtl");
class RedisClient { class RedisClient {
constructor() { constructor() {
...@@ -105,61 +106,76 @@ class RedisClient { ...@@ -105,61 +106,76 @@ class RedisClient {
} }
}); });
} }
async subscribe(channel, chatserver) { async subscribe(channel, chatserver) {
if (!this.chatserver) { if (!this.chatserver) {
this.chatserver = chatserver; this.chatserver = chatserver;
} }
return this.subclient.subscribeAsync(channel); return this.subclient.subscribeAsync(channel);
} }
async unsubscribe(channel) { async unsubscribe(channel) {
//this.chatserver=null; //this.chatserver=null;
return this.subclient.unsubscribeAsync(channel); return this.subclient.unsubscribeAsync(channel);
} }
async subscribeTask(channel, taskmanager) { async subscribeTask(channel, taskmanager) {
if (!this.taskmanager) { if (!this.taskmanager) {
this.taskmanager = taskmanager; this.taskmanager = taskmanager;
} }
return this.subclient.subscribeAsync(channel); return this.subclient.subscribeAsync(channel);
} }
async publish(channel, msg) { async publish(channel, msg) {
console.log(channel + ":" + msg); console.log(channel + ":" + msg);
return this.client.publishAsync(channel, msg); return this.client.publishAsync(channel, msg);
} }
async rpush(key, val) { async rpush(key, val) {
return this.client.rpushAsync(key, val); return this.client.rpushAsync(key, val);
} }
async llen(key) { async llen(key) {
return this.client.llenAsync(key); return this.client.llenAsync(key);
} }
async rpushWithEx(key, val, t) { async rpushWithEx(key, val, t) {
var p = this.rpush(key, val); var p = this.rpush(key, val);
this.client.expire(key, t); this.client.expire(key, t);
return p; return p;
} }
async rpop(key) { async rpop(key) {
return this.client.rpopAsync(key); return this.client.rpopAsync(key);
} }
async lpop(key) { async lpop(key) {
return this.client.lpopAsync(key); return this.client.lpopAsync(key);
} }
async lrem(key, val) { async lrem(key, val) {
return this.client.lremAsync(key, 1, val); return this.client.lremAsync(key, 1, val);
} }
async ltrim(key, s, e) { async ltrim(key, s, e) {
return this.client.ltrimAsync(key, s, e); return this.client.ltrimAsync(key, s, e);
} }
async clearlist(key) { async clearlist(key) {
await this.client.ltrim(key, -1, -1); await this.client.ltrim(key, -1, -1);
await this.client.ltrim(key, 1, -1); await this.client.ltrim(key, 1, -1);
return 0; return 0;
} }
async flushall() { async flushall() {
console.log("sss"); console.log("sss");
return this.client.flushallAsync(); return this.client.flushallAsync();
} }
async keys(p) { async keys(p) {
return this.client.keysAsync(p); return this.client.keysAsync(p);
} }
async set(key, val) { async set(key, val) {
if (typeof val == "undefined" || typeof key == "undefined") { if (typeof val == "undefined" || typeof key == "undefined") {
console.log("......................cache val undefined"); console.log("......................cache val undefined");
...@@ -168,29 +184,36 @@ class RedisClient { ...@@ -168,29 +184,36 @@ class RedisClient {
} }
return this.client.setAsync(key, val); return this.client.setAsync(key, val);
} }
async setWithEx(key, val, t) { async setWithEx(key, val, t) {
var p = this.client.setAsync(key, val); var p = this.client.setAsync(key, val);
this.client.expire(key, t); this.client.expire(key, t);
return p; return p;
} }
async get(key) { async get(key) {
return this.client.getAsync(key); return this.client.getAsync(key);
} }
async delete(key) { async delete(key) {
return this.client.delAsync(key); return this.client.delAsync(key);
} }
async hmset(key, jsonObj) { async hmset(key, jsonObj) {
return this.client.hmsetAsync(key, jsonObj); return this.client.hmsetAsync(key, jsonObj);
} }
async hmsetWithEx(key, jsonObj, t) { async hmsetWithEx(key, jsonObj, t) {
var p = this.client.hmsetAsync(key, jsonObj); var p = this.client.hmsetAsync(key, jsonObj);
this.client.expire(key, t); this.client.expire(key, t);
return p; return p;
} }
async hgetall(key) { async hgetall(key) {
return this.client.hgetallAsync(key); return this.client.hgetallAsync(key);
} }
async hincrby(key, f, n) { async hincrby(key, f, n) {
return this.client.hincrbyAsync(key, f, n); return this.client.hincrbyAsync(key, f, n);
} }
...@@ -199,37 +222,43 @@ class RedisClient { ...@@ -199,37 +222,43 @@ class RedisClient {
await this.client.saddAsync(key, ...vals); await this.client.saddAsync(key, ...vals);
return this.scard(key); return this.scard(key);
} }
async scard(key) { async scard(key) {
return this.client.scardAsync(key); return this.client.scardAsync(key);
} }
async srem(key, val) { async srem(key, val) {
return this.client.sremAsync(key, val); return this.client.sremAsync(key, val);
} }
async sismember(key, val) { async sismember(key, val) {
return this.client.sismemberAsync(key, val); return this.client.sismemberAsync(key, val);
} }
async smembers(key) { async smembers(key) {
return this.client.smembersAsync(key); return this.client.smembersAsync(key);
} }
async exists(key) { async exists(key) {
return this.client.existsAsync(key); return this.client.existsAsync(key);
} }
async incr(key) { async incr(key) {
return this.client.incrAsync(key); return this.client.incrAsync(key);
} }
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);
var id = await this.client.incrAsync(tableName) % 9999; var id = await this.client.incrAsync(tableName) % 9999;
if(id < 10) { if (id < 10) {
id = "000" + id; id = "000" + id;
} else if(id < 100) { } else if (id < 100) {
id = "00" + id; id = "00" + id;
} else if(id < 1000) { } else if (id < 1000) {
id = "0" + id; id = "0" + id;
} }
return "1" + Math.abs(time + tabcode) + id + this.getRandomNumber(2); return "1" + Math.abs(time + tabcode) + id + this.getRandomNumber(2);
...@@ -252,12 +281,13 @@ async genrateId(tableName) { ...@@ -252,12 +281,13 @@ async genrateId(tableName) {
var maxPos = chars.length; var maxPos = chars.length;
var pwd = ''; var pwd = '';
for (var i = 0; i < len; i++) { for (var i = 0; i < len; i++) {
pwd += chars.charAt(Math.floor(Math.random() * maxPos)); pwd += chars.charAt(Math.floor(Math.random() * maxPos));
} }
return pwd; return pwd;
} }
} }
module.exports = RedisClient; module.exports = RedisClient;
// var client=new RedisClient(); // var client=new RedisClient();
// (async ()=>{ // (async ()=>{
......
<a name="menu">目录</a> <a name="menu">目录</a>
1. [批量打款列表](#page) 1. [批量打款列表](#page)
1. [上传数据](#parseItems) 1. [上传数据](#parseItems)
1. [锁定批次](#add) 1. [锁定批次](#lockOrder)
1. [付款申请](#payVoucher) 1. [付款申请](#payVoucher)
## **<a name="page"> 订单列表</a>** ## **<a name="page"> 订单列表</a>**
...@@ -77,8 +77,9 @@ ...@@ -77,8 +77,9 @@
}, },
"requestid": "00521a0a0f094c8d982bf4375fbe91b1" "requestid": "00521a0a0f094c8d982bf4375fbe91b1"
} }
``` ```
1. [上传数据](#parseItems)
## **<a name="parseItems"> 上传数据</a>** ## **<a name="parseItems"> 上传数据</a>**
[返回到目录](#menu) [返回到目录](#menu)
...@@ -91,7 +92,8 @@ ...@@ -91,7 +92,8 @@
``` javascript ``` javascript
{ {
"id": "1726882554002859" // 订单id // 上传文件地址
"fileUrl": "https://gsb-zc.oss-cn-beijing.aliyuncs.com//zc_273315857206750512020113575551testbank2.xlsx"
} }
``` ```
...@@ -103,51 +105,35 @@ ...@@ -103,51 +105,35 @@
"status": 0, "status": 0,
"msg": "success", "msg": "success",
"data": { "data": {
// 基本剑术 "actual_amt": "131083.32", // 实发总额
"baseInfo": { "deduct_amt": "133704.99", // 扣除总额
"id": "1726882554002859", // 订单编号 "service_tax": "2621.67", // 服务费
"created_at": "2020-03-23 03:44:44", // 创建时间 "error": false, // 上传文件是否有错误 false没有,true有错误
"price": 1500 // 价格 "itemList": [
}, {
// 注册申请信息 "errors": [ // 错误信息数组,多条,都在页面展示吧
"regInfo": { "错误信息1",
"legal_name": "11111", // 法人 "错误信息2",
"legal_idno": "11111", // 身份证号码 ],
"legal_mobile": "11111", // 联系电话 "acc_name": "11",
"company_names": "11111", // 个体户名称 "credit_code": "92321311MA205KN92J",
"idcard_front": "11111", // 身份证图正面 "acc_no": "3",
"idcard_back": "11111" // 身份证图反面 "open_bank": "4",
}, "amt": "5",
// 商户交付信息 "remark": "6"
"merchantDeliverInfo": { },
"merchant_deliver_man": "", // 联系人 ]
"merchant_deliver_mobile": "", // 联系电话 }
"merchant_deliver_addr": "" // 邮寄地址
},
// 支付信息
"payInfo": {
"amount": 0, // 付款金额
"created_at": "2020-03-23", // 支付时间
"trade_no": "1123123", // 资金流水号
"pay_voucher_img": "123213" // 付款凭证
},
// 订单交付信息
"deliverInfo": {
"deliver_express_no": "", // 快递单号
"deliver_express_img": "" // 交接单
},
},
"requestid": "b46e1ff5176143ffa4135a357f93d757"
} }
``` ```
## **<a name="checkPay"> 支付验证</a>** ## **<a name="lockOrder"> 锁定批次</a>**
[返回到目录](#menu) [返回到目录](#menu)
##### URL ##### URL
[/web/saas/orderCtl/checkPay] [/web/trade/tradeCtl/lockOrder]
#### 参数格式 `JSON` #### 参数格式 `JSON`
#### HTTP请求方式 `POST` #### HTTP请求方式 `POST`
......
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