Commit a9c44923 by 王昆

gsb

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