Commit 93fd1bd6 by 王昆

gsb

parent 96cbbfb0
#!/bin/bash
FROM registry.cn-beijing.aliyuncs.com/hantang/node105:v2
MAINTAINER jy "jiangyong@gongsibao.com"
ADD xggsve-common/apps/xggsve-common/
WORKDIR /apps/xggsve-common/
ADD xggsve-merchant/apps/xggsve-merchant/
WORKDIR /apps/xggsve-merchant/
RUN cnpm install -S
CMD ["node","/apps/xggsve-common/main.js"]
CMD ["node","/apps/xggsve-merchant/main.js"]
......
const system = require("../../../system");
const Dao = require("../../dao.base");
class BusinessscopeDao extends Dao {
constructor() {
super(Dao.getModelName(BusinessscopeDao));
}
async findListByDomicileIds(domicileIds) {
if (!domicileIds || domicileIds.length == 0) {
return [];
}
var sql = [];
sql.push("SELECT");
sql.push("id, domicile_id, businessType,");
sql.push("businessscope, isEnabled, created_at ");
sql.push("FROM d_businessscope");
sql.push("WHERE domicile_id IN (:domicileIds)");
return await this.customQuery(sql.join(" "), {
domicileIds: domicileIds
}) || [];
}
async findMapByDomicileIds(domicileIds) {
var result = {};
if (!domicileIds || domicileIds.length == 0) {
return result;
}
var list = await this.findListByDomicileIds(domicileIds);
if (!list || list.length == 0) {
return result;
}
for (var item of list) {
var domicileList = result[item.domicile_id] || [];
domicileList.push(item);
result[item.domicile_id] = domicileList;
}
return result;
}
async delById(id, t) {
var sql = "DELETE FROM d_businessscope WHERE id = :id";
return await this.customUpdate(sql, {
id: id
}, t);
}
async delByDomicileId(domicileId, t) {
var sql = "DELETE FROM d_businessscope WHERE domicile_id = :domicileId";
return await this.customUpdate(sql, {
domicileId: domicileId
}, t);
}
}
module.exports = BusinessscopeDao;
// var u=new UserDao();
// var roledao=system.getObject("db.roleDao");
// (async ()=>{
// var users=await u.model.findAll({where:{app_id:1}});
// var role=await roledao.model.findOne({where:{code:"guest"}});
// console.log(role);
// for(var i=0;i<users.length;i++){
// await users[i].setRoles([role]);
// console.log(i);
// }
//
// })();
\ No newline at end of file
const fs = require("fs");
const settings = require("../../../../config/settings");
class CacheManager {
constructor() {
//await this.buildCacheMap();
this.buildCacheMap();
}
buildCacheMap() {
var self = this;
self.doc = {};
var cachePath = settings.basepath + "/app/base/db/cache/";
const files = fs.readdirSync(cachePath);
if (files) {
files.forEach(function (r) {
var classObj = require(cachePath + "/" + r);
if (classObj.name) {
self[classObj.name] = new classObj();
var refTmp = self[classObj.name];
if (refTmp.prefix) {
self.doc[refTmp.prefix] = refTmp.desc;
} else {
console.log("请在" + classObj.name + "缓存中定义prefix");
}
}
});
}
}
}
module.exports = CacheManager;
// var cm= new CacheManager();
// cm["InitGiftCache"].cacheGlobalVal("hello").then(function(){
// cm["InitGiftCache"].cacheGlobalVal().then(x=>{
// console.log(x);
// });
// });
\ No newline at end of file
const system = require("../../../system");
const Dao = require("../../dao.base");
class DomicileDao extends Dao {
constructor() {
super(Dao.getModelName(DomicileDao));
}
async getList(isEnabled, attrs) {
attrs = attrs || "*"
var sql = [];
sql.push("SELECT ");
sql.push(attrs);
sql.push("FROM d_domicile");
if (isEnabled == 1) {
sql.push("WHERE isEnabled = 1");
}
return await this.customQuery(sql.join(" ")) || [];
}
async delById(id, t) {
var sql = "DELETE FROM d_domicile WHERE id = :id";
return await this.customUpdate(sql, {
id: id
}, t);
}
async findListByIds(ids) {
if (!ids || ids.length == 0) {
return [];
}
var sql = [];
sql.push("SELECT");
sql.push("id, name, isEnabled, created_at ");
sql.push("FROM d_domicile");
sql.push("WHERE id IN (:ids)");
return await this.customQuery(sql.join(" "), {
ids: ids
}) || [];
}
async findMapByIds(ids) {
var result = {};
if (!ids || ids.length == 0) {
return result;
}
var list = await this.findListByIds(ids);
if (!list || list.length == 0) {
return result;
}
for (var item of list) {
result[item.id] = item;
}
return result;
}
}
module.exports = DomicileDao;
// var u=new UserDao();
// var roledao=system.getObject("db.roleDao");
// (async ()=>{
// var users=await u.model.findAll({where:{app_id:1}});
// var role=await roledao.model.findOne({where:{code:"guest"}});
// console.log(role);
// for(var i=0;i<users.length;i++){
// await users[i].setRoles([role]);
// console.log(i);
// }
//
// })();
\ No newline at end of file
const system=require("../../../system");
const Dao=require("../../dao.base");
class InvoicecontentDao extends Dao{
constructor(){
super(Dao.getModelName(InvoicecontentDao));
}
}
module.exports=InvoicecontentDao;
const system = require("../../../system");
const Dao = require("../../dao.base");
class DeliverDao extends Dao {
constructor() {
super(Dao.getModelName(DeliverDao));
}
async getList(isEnabled, attrs) {
attrs = attrs || "*"
var sql = [];
sql.push("SELECT ");
sql.push(attrs);
sql.push("FROM d_deliver");
if (isEnabled == 1) {
sql.push("WHERE isEnabled = 1");
}
return await this.customQuery(sql.join(" ")) || [];
}
async delById(id, t) {
var sql = "DELETE FROM d_deliver WHERE id = :id";
return await this.customUpdate(sql, {
id: id
}, t);
}
async findListByIds(ids) {
if (!ids || ids.length == 0) {
return [];
}
var sql = [];
sql.push("SELECT");
sql.push("id, name, businessmenDivide, invoiceDivide, isEnabled, created_at ");
sql.push("FROM d_deliver");
sql.push("WHERE id IN (:ids)");
return await this.customQuery(sql.join(" "), {
ids: ids
}) || [];
}
async findMapByIds(ids) {
var result = {};
if (!ids || ids.length == 0) {
return result;
}
var list = await this.findListByIds(ids);
if (!list || list.length == 0) {
return result;
}
for (var item of list) {
result[item.id] = item;
}
return result;
}
}
module.exports = DeliverDao;
// var u=new UserDao();
// var roledao=system.getObject("db.roleDao");
// (async ()=>{
// var users=await u.model.findAll({where:{app_id:1}});
// var role=await roledao.model.findOne({where:{code:"guest"}});
// console.log(role);
// for(var i=0;i<users.length;i++){
// await users[i].setRoles([role]);
// console.log(i);
// }
//
// })();
\ 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("invoicecontent", {
name: DataTypes.STRING,
isEnabled: {
type:DataTypes.BOOLEAN,
allowNull:false,
defaultValue:false
},
}, {
paranoid: true,//假的删除
underscored: true,
version: true,
freezeTableName: true,
timestamps: true,
//freezeTableName: true,
// define the table's name
tableName: 'd_invoicecontent',
validate: {
},
indexes: [
]
});
}
const system = require("../../../system");
const ServiceBase = require("../../sve.base")
const settings = require("../../../../config/settings")
class BusinessscopeService extends ServiceBase {
constructor() {
super("common", ServiceBase.getDaoName(BusinessscopeService));
this.domicileDao = system.getObject("db.common.domicileDao");
}
async apiPage(params) {
try {
return await this.page(params);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiSave(params) {
try {
return await this.save(params);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiInfo(params) {
try {
return await this.info(params);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiDomicileList(params) {
try {
return await this.ListByDomicileId(params.domicileId);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiDeleteByIds(params) {
var ids = params.ids || [];
try {
for(var id of ids) {
// 单条删除,方便以后有级联删除时使用事务
await this.delById(id);
}
return system.getResultSuccess(1);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
// where: {
// id: id
// },
// attrs: ["id", "domicile_id", "businessType", "businessscope", "isEnabled", "created_at",],
// raw: true
// -----------------------以此间隔,上面为API,下面为service---------------------------------
async ListByDomicileId(domicileId) {
var list = await this.dao.findListByDomicileIds([domicileId]) || [];
for(var item of list) {
this.handleDate(item, ["created_at"], null, -8);
}
await this.setDomicile(list);
return system.getResultSuccess(list);
}
async info(params) {
var id = params.id;
var sqlWhere = {
where: {
id: id
},
attributes: ["id", "domicile_id", "businessType", "businessscope", "isEnabled", "created_at",],
raw: true
};
var item = await this.dao.model.findOne(sqlWhere);
if(!item) {
return system.getResult(null, "经营范围不存在");
}
this.handleDate(item, ["created_at"], null, -8);
await this.setDomicile([item]);
return system.getResultSuccess(item);
}
async delById(id) {
if(!id) {
return;
}
await this.dao.delById(id);
return system.getResultSuccess(1);
}
async save(params) {
var domicileId = params.domicileId;
if (!domicileId) {
return system, getResult(null, domicileId);
}
var id = params.id;
var bsc;
if (id) {
bsc = await this.dao.findById(id);
} else {
bsc = {domicile_id: domicileId};
}
bsc.businessType = this.trim(params.businessType);
bsc.businessscope = this.trim(params.businessscope);
bsc.isEnabled = params.isEnabled == 1 ? true : false;
if(bsc.id) {
bsc = await bsc.save();
} else {
bsc = await this.dao.create(bsc);
}
return system.getResultSuccess(bsc);
}
async page(params) {
var currentPage = Number(params.currentPage || 1);
var pageSize = Number(params.pageSize || 10);
var where = {};
if (params.domicileId) {
where.domicile_id = params.domicileId;
}
var orderby = [
["id", 'desc']
];
var attributes = ["id", "domicile_id", "businessType", "businessscope", "isEnabled", "created_at"];
var page = await this.getPageList(currentPage, pageSize, where, orderby, attributes);
if (page && page.rows) {
for (var row of page.rows) {
this.handleDate(row, ["created_at"], null, -8);
}
await this.setDomicile(page.rows);
}
return system.getResultSuccess(page);
}
async setDomicile(rows) {
if(!rows || rows.length == 0) {
return;
}
var ids = [];
for(var item of rows) {
ids.push(item.domicile_id);
}
var map = await this.domicileDao.findMapByIds(ids);
for(var item of rows) {
item.domicile = map[item.domicile_id] || {};
this.handleDate(item.domicile, ["created_at"], null, -8);
}
}
}
module.exports = BusinessscopeService;
// var task=new UserService();
// task.getUserStatisticGroupByApp().then(function(result){
// console.log((result));
// }).catch(function(e){
// console.log(e);
// });
\ No newline at end of file
const system = require("../../../system");
const ServiceBase = require("../../sve.base");
var settings = require("../../../../config/settings");
const uuidv4 = require('uuid/v4');
var svgCaptcha = require('svg-captcha');
class CaptchaService {
constructor() {
this.redisClient = system.getObject("util.redisClient");
}
async apiGenerate(params) {
var key = uuidv4();
var options = {
size: 4,
noise: 1,
ignoreChars: '0o1i'
};
options.width = this.trim(params.width) || 120;
options.height = this.trim(params.height) || 32;
options.background = this.trim(params.background) || "#E8E8E8";
var captchaPrev = this.trim(params.captchaPrev);
var expire = Number(params.expire || 3 * 60)
try {
var cap = svgCaptcha.create(options);
console.log(cap);
await this.redisClient.setWithEx(key, cap.text, expire);
return system.getResultSuccess({
key: key,
text: cap.text,
captcha: cap.data,
});
} catch (error) {
return system.getResult(null, "接口异常:" + error.message);
}
}
async apiValidator(params) {
var key = this.trim(params.key);
var code = this.trim(params.code);
var cacheCode = await this.redisClient.get(key);
if(!cacheCode) {
return system.getResult(null, "验证码已过期,请点击重试");
}
if(code.toLowerCase() != cacheCode.toLowerCase()) {
await this.redisClient.delete(key);
return system.getResult(null, "验证码输入错误,清点击重试");
}
return system.getResultSuccess(1);
}
trim(o) {
if(!o) {
return "";
}
return o.toString().trim();
}
}
module.exports = CaptchaService;
\ No newline at end of file
const system = require("../../../system");
const ServiceBase = require("../../sve.base");
// var settings = require("../../../../config/settings");
class InvoicecontentService extends ServiceBase {
constructor() {
super("common", ServiceBase.getDaoName(InvoicecontentService));
// this.invoicecontentDao=system.getObject("db.common.invoicecontentDao");
}
async apiSave(params) {
try {
return await this.save(params);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiGetById(params) {
try {
if(!params.id){
return system.getResult(null, "参数错误");
}
return await this.getById(params.id);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiList(params) {
try {
console.log("--"+JSON.stringify(params));
return await this.invoiceList(params);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiDelete(params) {
var ids = params.ids;
if (!ids || ids.length == 0) {
return system.getResult(null, "传入参数错误:ids=" + JSON.stringify(ids));
}
try {
try {
await this.bulkDelete(ids);
} catch (error) {
console.log(error);
}
return system.getResultSuccess(1);
} catch (error) {
return system.getResult(null, "接口异常");
}
}
/**--------------------------------------------------------------------- */
async getById(id){
let res = await this.dao.findById(id);
return system.getResultSuccess(res);
}
async save(params) {
let id = params.id;
let invoicecontent;
if(id){
invoicecontent=await this.dao.findById(id);
}else{
invoicecontent={};
}
invoicecontent.name=this.trim(params.name);
invoicecontent.isEnabled=(params.isEnabled)==1?true:false;
if(id){
await invoicecontent.save();
}else{
invoicecontent = await this.dao.create(invoicecontent);
}
return system.getResultSuccess(invoicecontent);
}
async bulkDelete(ids) {
if (!ids || ids.length == 0) {
return system.getResult(null, "删除失败");
}
await this.dao.bulkDelete(ids);
}
async invoiceList(params) {
console.log(JSON.stringify(params));
var currentPage = Number(params.currentPage || 1);
var pageSize = Number(params.pageSize || 10);
var where = {};
if (params.domicileId) {
where.domicile_id = params.domicileId;
}
if (params.name) {
where.name = {
[this.db.Op.like]: "%" + decodeURIComponent(params.name) + "%"
};
}
var orderby = [
["id", 'desc']
];
var attributes = ["id", "name", "isEnabled", "created_at", "updated_at", "deleted_at"];
let res = await this.dao.getPageList(currentPage, pageSize, where, orderby, attributes);
return res;
}
}
module.exports = InvoicecontentService;
## 公共接口服务
  1 [图片验证码](doc/common/captcha.md)
  2 [注册地](doc/common/domicile.md)
  3 [经营范围](doc/common/businessscope.md)
  4 [交付商](doc/deliver/deliver.md)
  5 [发票内容](doc/common/invoicecontent.md)
<a name="menu">目录</a>
1. [列表](#list)
1. [查询](#info)
1. [添加/修改](#save)
1. [删除](#del)
1. [按注册地查](#domicileList)
## **<a name="list"> 列表</a>**
[返回到目录](#menu)
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
``` javascript
{
"action_process": "test",
"action_type": "businessscopePage",
"action_body": {
"currentPage": "1",
"pageSize": "3",
"domicileId": "" // 注册地id
}
}
```
#### 返回结果
```javascript
{
"status": 0,
"msg": "success",
"data": {
"count": 10,
"rows": [
{
"id": "12218127593000590", // 经营范围id
"domicile_id": "12706646858000580", // 注册地id
"businessType": "经营范围3", // 经营范围
"businessscope": "经营范围详情", // 经营范围详情
"isEnabled": 0, // 是否启用 0否 1是
"created_at": "2019-10-03 06:51:01", // 创建时间
"domicile": { // 注册地信息
"name": "杨庆菊1", // 注册地姓名
"isEnabled": 1, // 是否启用 0否 1是
"created_at": "2019-10-02 10:08:04"
}
},
]
},
"requestid": "f2bc255412d64cffb46d35b5c2f21ffe"
}
```
## **<a name="info"> 查询</a>**
[返回到目录](#menu)
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
``` javascript
{
"action_process": "test",
"action_type": "businessscopeInfo",
"action_body": {
"id": "12218127593000590" // 经营范围id
}
}
```
#### 返回结果
```javascript
{
"status": 0,
"msg": "success",
"data": {
"id": "12218127593000590", // 经营范围id
"domicile_id": "12706646858000580", // 注册地id
"businessType": "经营范围3", // 经营范围
"businessscope": "经营范围详情", // 经营范围详情
"isEnabled": 0, // 是否启用 0否 1是
"created_at": "2019-10-03 06:51:01", // 创建时间
"domicile": { // 注册地信息
"name": "杨庆菊1", // 注册地姓名
"isEnabled": 1, // 是否启用 0否 1是
"created_at": "2019-10-02 10:08:04"
}
},
"requestid": "436b027db2154f668c5f436040a28b9a"
}
```
## **<a name="save"> 添加/修改</a>**
[返回到目录](#menu)
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
``` javascript
{
"action_process": "test",
"action_type": "businessscopeSave",
"action_body": {
"id": "", // id
"domicileId": "12706710830001318", // 注册地id
"businesssType": "经营范围1", // 经营范围
"businessscope": "经营范围详情1", // 经营范围详情
"isEnabled": 0
}
}
```
#### 返回结果
```javascript
{
"status": 0,
"msg": "success",
"data": {},
"requestid": "02da57850743496181fcd4705c09749e"
}
}
```
## **<a name="del"> 删除</a>**
[返回到目录](#menu)
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
``` javascript
{
"action_process": "test",
"action_type": "businessscopeDelete",
"action_body": {
"ids": ["12218127708000700","12218127590000439","12218127733000865"]
}
}
```
#### 返回结果
```javascript
{
"status": 0,
"msg": "success",
"data": 1,
"requestid": "51161e8d79614cb58de8edaa61a85766"
}
}
```
## **<a name="domicileList"> 按注册地查</a>**
[返回到目录](#menu)
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
``` javascript
{
"action_process": "test",
"action_type": "businessscopeByDomicileId",
"action_body": {
"domicileId": "12706646858000580"
}
}
```
#### 返回结果
```javascript
{
"status": 0,
"msg": "success",
"data": [
{
"id": "12218127593000590", // 经营范围id
"domicile_id": "12706646858000580", // 注册地id
"businessType": "经营范围3", // 经营范围
"businessscope": "经营范围详情", // 经营范围详情
"isEnabled": 0, // 是否启用 0否 1是
"created_at": "2019-10-03 06:51:01", // 创建时间
"domicile": { // 注册地信息
"name": "杨庆菊1", // 注册地姓名
"isEnabled": 1, // 是否启用 0否 1是
"created_at": "2019-10-02 10:08:04"
}
},
],
"requestid": "f2bc255412d64cffb46d35b5c2f21ffe"
}
```
<a name="menu">目录</a>
1. [获取图片验证码](#getCaptha)
## **<a name="getCaptha"> 获取图片验证码</a>**
[返回到目录](#menu)
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
``` javascript
{
"action_process": "test",
"action_type": "getCaptha",
"action_body": {
"width": 120, // 验证码图片宽度 默认 120px
"height": 36, // 验证码图片高度 默认 36px
"background": "", // 验证码图片背景色,默认 #E8E8E8
"expire": 0 // 验证码过期时间(秒)
}
}
```
#### 返回结果
```javascript
{
"status": 0,
"msg": "success",
"data": {
"key": "3955eeef-606b-47af-ac7a-b3496b218f3e", // 图片验证码key
"captcha": "<svg>....</svg>" // 图片验证码
},
"requestid": "aca2b2767cef4a96b90a4d5d8e78becc"
}
```
<a name="menu">目录</a>
1. [全部注册地](#allList)
1. [名称列表](#namelist)
1. [列表](#list)
1. [查询](#info)
1. [添加/修改](#save)
1. [删除](#del)
## **<a name="allList"> 全部注册地</a>**
[返回到目录](#menu)
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
``` javascript
{
"action_process": "test",
"action_type": "invoicecontentSave",
"action_body": {
}
}
```
#### 返回结果
```javascript
{
"status": 0,
"msg": "success",
"data": [
{
"id": "12706710844001762", // id
"name": "杨庆菊12", // 注册地名称
"isEnabled": 1, // 是否启用 0否 1是
"created_at": "2019-10-03 03:54", // 创建时间
"businessscopeList": [ // 经营范围列表
{
"id": "12218127540000210", // 经营范围id
"domicile_id": "12706646858000580", // 注册地id
"businessType": "经营范围", // 经营范围
"businessscope": "经营范围详情", // 经营范围详情
"isEnabled": 0, // 是否启用 0否 1是
"created_at": "2019-10-03 06:50:08" // 创建时间
},
]
}
],
"requestid": "51161e8d79614cb58de8edaa61a85766"
}
```
## **<a name="namelist"> 名称列表</a>**
[返回到目录](#menu)
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
``` javascript
{
"action_process": "test",
"action_type": "domicileNameList",
"action_body": {
}
}
```
#### 返回结果
```javascript
{
"status": 0,
"msg": "success",
"data": [
{
"id": "12706646858000580", // 注册地id
"name": "杨庆菊1" // 注册地名称
},
{
"id": "12706647287000653",
"name": "杨庆菊2"
},
...
],
"requestid": "02da57850743496181fcd4705c09749e"
}
```
## **<a name="list"> 列表</a>**
[返回到目录](#menu)
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
``` javascript
{
"action_process": "test",
"action_type": "domicilePage",
"action_body": {
"currentPage": "1",
"pageSize": "3",
"id": "" // 注册地id
}
}
```
#### 返回结果
```javascript
{
"status": 0,
"msg": "success",
"data": {
"count": 1,
"rows": [
{
"id": "12706710844001762", // id
"name": "杨庆菊12", // 注册地名称
"isEnabled": 1, // 是否启用 0否 1是
"created_at": "2019-10-03 03:54", // 创建时间
"businessscopeList": [ // 经营范围列表
{
"id": "12218127540000210", // 经营范围id
"domicile_id": "12706646858000580", // 注册地id
"businessType": "经营范围", // 经营范围
"businessscope": "经营范围详情", // 经营范围详情
"isEnabled": 0, // 是否启用 0否 1是
"created_at": "2019-10-03 06:50:08" // 创建时间
},
]
}
]
},
"requestid": "51161e8d79614cb58de8edaa61a85766"
}
```
## **<a name="save"> 添加/修改</a>**
[返回到目录](#menu)
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
``` javascript
{
"action_process": "test",
"action_type": "domicileSave",
"action_body": {
"id": "", // id 空的时候添加,有具体id时修改
"name": "杨庆菊12", // 注册地名称
"isEnabled" : 1 // 是否启用 0否 1是
}
}
```
#### 返回结果
```javascript
{
"status": 0,
"msg": "success",
"data": {}
}
```
## **<a name="del"> 删除</a>**
[返回到目录](#menu)
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
``` javascript
{
"action_process": "test",
"action_type": "domicileDelete",
"action_body": {
"ids": ["12218127593000590","12218127593000592"...] // 注册地id数组
}
}
```
#### 返回结果
```javascript
{
"status": 0,
"msg": "success"
}
```
\ No newline at end of file
<a name="menu">目录</a>
1. [添加/修改](#save)
2. [批量查询](#bulquery)
3. [单个查询](#query)
4. [删除](#delete)
## **<a name="save"> 保存发票内容</a>**
[返回到目录](#menu)
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
``` javascript
{
"action_process": "test",
"action_type": "invoicecontentSave",
"action_body": {
"name": "总统孙",
"isEnabled": 1
}
}
```
#### 返回结果
```javascript
{
"status":0,
"msg":"success",
"data":{
"version":0,
"name":"总统孙",
"isEnabled":true,
"id":"11444111776000520",
"updated_at":"2019-10-10T08:51:00.939Z",
"created_at":"2019-10-10T08:51:00.939Z"
},
"requestid":"dce6dba445304dd8b043ecb913851a31"
}
```
## **<a name="invoicelist"> 发票列表</a>**
[返回到目录](#menu)
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
```
javascript
{
"action_process": "test",
"action_type": "invoiceList",
"action_body": {
currentPage:1, //非必填
pageSize:10,//非必填
name:xxx,//非必填(模糊查询)
id:xxx //非必填
}
}
```
#### 返回结果
```javascript
{
"count":2,
"rows":[
{
"id":"11444116222000933",
"name":"总统孙",
"isEnabled":1,
"created_at":"2019-10-10T10:05:06.000Z",
"updated_at":"2019-10-10T10:05:06.000Z",
"deleted_at":null
},
{
"id":"11444116214000855",
"name":"孙总统",
"isEnabled":1,
"created_at":"2019-10-10T10:04:58.000Z",
"updated_at":"2019-10-10T10:04:58.000Z",
"deleted_at":null
}
],
"requestid":"8557261ae1894ff2ba3a50b077f314e9"
}
```
## **<a name="invoicecontent"> 发票明细</a>**
[返回到目录](#menu)
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
```
javascript
{
"action_process": "test",
"action_type": "invoicecontent",
"action_body": {
id:xxx 
}
}
```
#### 返回结果
```javascript
{
"status":0,
"msg":"success",
"data":{
"id":"11444116222000933",
"name":"总统孙",
"isEnabled":true,
"created_at":"2019-10-10T10:05:06.000Z",
"updated_at":"2019-10-10T10:05:06.000Z",
"deleted_at":null,
"version":0
},
"requestid":"0a96be51bc2248469d8fb55d7b125dad"
}
```
## **<a name="invoicecontentDelete"> 删除发票</a>**
[返回到目录](#menu)
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
``` javascript
{
"action_process": "test",
"action_type": "invoicecontentDelete",
"action_body": {
"ids":["xx","xxs"]
}
}
```
#### 返回结果
```javascript
{"status":0,"msg":"success","data":1,"requestid":"b225c65307be4a53be99885f4b579241"}
```
node_modules
.idea
npm-debug.log
dump.rdb
.DS_Store
/.project
.package-lock.json
*.csv
.vscode/launch.json
......@@ -72,25 +72,31 @@ class APIBase extends DocBase {
var app_id = req.headers["app_id"];
if (ispass) {
return result;
}//在白名单里面
if (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 = "请求头没有相关访问参数,请验证后在进行请求";
}
//在白名单里面
// 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) {
......
......@@ -4,13 +4,14 @@ var settings = require("../../../../config/settings");
class ActionAPI extends APIBase {
constructor() {
super();
this.domicileSve = system.getObject("service.common.domicileSve");
this.businessscopeSve = system.getObject("service.common.businessscopeSve");
this.captchaSve = system.getObject("service.common.captchaSve");
this.merchantSve = system.getObject("service.merchant.merchantSve");
this.merchantsignedSve = system.getObject("service.merchant.merchantsignedSve");
this.merchantaccountSve = system.getObject("service.merchant.merchantaccountSve");
this.merchantrechargeSve = system.getObject("service.merchant.merchantrechargeSve");
this.merchanttitleSve = system.getObject("service.merchant.merchanttitleSve");
this.merchantaddressSve = system.getObject("service.merchant.merchantaddressSve");
this.deliverSve = system.getObject("service.deliver.deliverSve");
this.invoicecontentSve = system.getObject("service.common.invoicecontentSve");
}
/**
* 接口跳转
......@@ -38,83 +39,107 @@ class ActionAPI extends APIBase {
async handleRequest(action_process, action_type, action_body) {
var opResult = null;
switch (action_type) {
// 图片验证码
case "getCaptha":
opResult = await this.captchaSve.apiGenerate(action_body);
// 商户api
case "infoList":
opResult = await this.merchantSve.apiInfoList(action_body);
break;
case "nameList":
opResult = await this.merchantSve.apiNameList(action_body);
break;
case "validCaptha":
opResult = await this.captchaSve.apiValidator(action_body);
case "addMerchant":
opResult = await this.merchantSve.apiAddMerchant(action_body);
break;
// 注册地
case "domicileNameList":
opResult = await this.domicileSve.apiNameList(action_body);
case "getById":
opResult = await this.merchantSve.apiGetMerchant(action_body);
break;
case "domicileTree":
opResult = await this.domicileSve.apiTree(action_body);
case "getMapByIds":
opResult = await this.merchantSve.apiGetMerchantMap(action_body);
break;
case "domicilePage":
opResult = await this.domicileSve.apiPage(action_body);
case "updMerchant":
opResult = await this.merchantSve.apiUpdMerchant(action_body);
break;
case "domicileSave":
opResult = await this.domicileSve.apiSave(action_body);
case "auditMerchant":
opResult = await this.merchantSve.apiAuditMerchant(action_body);
break;
case "domicileInfo":
opResult = await this.domicileSve.apiInfo(action_body);
case "queryMerchant":
opResult = await this.merchantSve.apiQueryMerchant(action_body);
break;
case "domicileDelete":
opResult = await this.domicileSve.apiDeleteByIds(action_body);
case "secretById":
opResult = await this.merchantSve.apiSecretById(action_body);
break;
// 经营范围
case "businessscopeByDomicileId":
opResult = await this.businessscopeSve.apiDomicileList(action_body);
// 商户签约api
case "saveMerchantSign":
opResult = await this.merchantsignedSve.apiSaveSign(action_body);
break;
case "businessscopePage":
opResult = await this.businessscopeSve.apiPage(action_body);
case "merchantSignInfo":
opResult = await this.merchantsignedSve.apiSignInfo(action_body);
break;
case "merchantSignList":
opResult = await this.merchantsignedSve.apiSignPage(action_body);
break;
// 商户抬头api
case "merchantTitleList":
opResult = await this.merchanttitleSve.apiTitlePage(action_body);
break;
case "businessscopeSave":
opResult = await this.businessscopeSve.apiSave(action_body);
case "merchantTitleInfo":
opResult = await this.merchanttitleSve.apiTitleInfo(action_body);
break;
case "businessscopeInfo":
opResult = await this.businessscopeSve.apiInfo(action_body);
case "merchantTitleSave":
opResult = await this.merchanttitleSve.apiSaveTitle(action_body);
break;
case "merchantTitleDefault":
opResult = await this.merchanttitleSve.apiSetDefault(action_body);
break;
case "businessscopeDelete":
opResult = await this.businessscopeSve.apiDeleteByIds(action_body);
case "getMerchantTitleDefault":
opResult = await this.merchanttitleSve.apiGetDefault(action_body);
break;
// 交付商
case "deliverAll":
opResult = await this.deliverSve.apiAll(action_body);
// 商户地址api
case "merchantAddressList":
opResult = await this.merchantaddressSve.apiAddressPage(action_body);
break;
case "deliverPage":
opResult = await this.deliverSve.apiPage(action_body);
case "merchantAddressInfo":
opResult = await this.merchantaddressSve.apiAddressInfo(action_body);
break;
case "deliverSave":
opResult = await this.deliverSve.apiSave(action_body);
case "merchantAddressSave":
opResult = await this.merchantaddressSve.apiSaveAddress(action_body);
break;
case "deliverInfo":
opResult = await this.deliverSve.apiInfo(action_body);
case "merchantAddressDefault":
opResult = await this.merchantaddressSve.apiSetDefault(action_body);
break;
case "deliverDelete":
opResult = await this.deliverSve.apiDeleteByIds(action_body);
case "getMerchantAddressDefault":
opResult = await this.merchantaddressSve.apiGetDefault(action_body);
break;
// 发票内容
case "invoicecontentSave":
opResult = await this.invoicecontentSve.apiSave(action_body);
// 资金账户
case "merchantAccountPage":
opResult = await this.merchantaccountSve.apiPage(action_body);
break;
case "merchantAccountInfo":
opResult = await this.merchantaccountSve.apiInfo(action_body);
break;
case "invoicecontentDelete":
opResult = await this.invoicecontentSve.apiDelete(action_body);
case "merchantAccountInfoByMerchantId":
opResult = await this.merchantaccountSve.apiInfoByMerchantId(action_body);
break;
case "invoiceList":
opResult = await this.invoicecontentSve.apiList(action_body);
// 商户充值api
case "merchantRechargePage":
opResult = await this.merchantrechargeSve.apiPage(action_body);
break;
case "invoicecontent":
opResult = await this.invoicecontentSve.apiGetById(action_body);
case "merchantRechargeAdd":
opResult = await this.merchantrechargeSve.apiAdd(action_body);
break;
case "merchantRechargeInfo":
opResult = await this.merchantrechargeSve.apiInfo(action_body);
break;
case "merchantRechargeAudit":
opResult = await this.merchantrechargeSve.apiAudit(action_body);
break;
default:
opResult = system.getResult(null, "action_type参数错误");
break;
......
var system = require("../../../system")
const http = require("http")
const querystring = require('querystring');
var settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base");
const logCtl = system.getObject("web.common.oplogCtl");
const uuidv4 = require('uuid/v4');
var svgCaptcha = require('svg-captcha');
var cacheBaseComp = null;
class MerchantCtl extends CtlBase {
constructor() {
super("merchant", CtlBase.getServiceName(MerchantCtl));
this.redisClient = system.getObject("util.redisClient");
this.merchantsignedSve = system.getObject("service.merchant.merchantsignedSve");
this.merchantaccountSve = system.getObject("service.merchant.merchantaccountSve");
this.merchantrechargeSve = system.getObject("service.merchant.merchantrechargeSve");
}
async testId(pobj, pobj2, req) {
this.service.create({
name: "tesxtid"
});
}
async nameList(pobj, pobj2, req) {
try {
var nameList = await this.service.nameList();
return system.getResultSuccess(nameList);
} catch (e) {
console.log(e);
return system.getResultFail(500, "接口错误");
}
}
async allList(pobj, pobj2, req) {
return await this.queryList(pobj || {});
}
async queryList(condition) {
var condition = condition || {};
this.doTimeCondition(condition, ["createdBegin", "createdEnd"]);
try {
var page = await this.service.pageByCondition(condition);
return system.getResultSuccess(page);
} catch (e) {
console.log(e);
return system.getResultFail(500, "接口错误");
}
}
async saveMerchant(pobj, pobj2, req) {
var merchant;
var merchantName = this.trim(pobj.name);
if(!merchantName) {
return system.getResult(null, "商户名称不能为空");
}
var id = Number(pobj.id);
if (id) {
merchant = await this.service.findById(id)
if (merchant.name != merchantName) {
var nameMerchant = await this.service.findOne({
name: merchantName
});
if (nameMerchant) {
return system.getResult(null, "商户名称【" + merchantName + "】已存在");
}
}
} else {
var nameMerchant = await this.service.findOne({
name: merchantName
});
if (nameMerchant) {
return system.getResult(null, "商户名称【" + merchantName + "】已存在");
}
merchant = {};
merchant.status = 0;
merchant.appSecret = system.getUid(32);
}
merchant.name = merchantName;
merchant.taxType = Number(pobj.taxType || 0);
merchant.contactName = this.trim(pobj.contactName);
merchant.contactMobile = this.trim(pobj.contactMobile);
merchant.contactEmail = this.trim(pobj.contactEmail);
merchant.taxNo = this.trim(pobj.taxNo);
merchant.invoiceAddr = this.trim(pobj.invoiceAddr);
merchant.invoiceMobile = this.trim(pobj.invoiceMobile);
merchant.accountName = this.trim(pobj.accountName);
merchant.accountPublic = this.trim(pobj.accountPublic);
merchant.mailAddr = this.trim(pobj.mailAddr);
merchant.mailTo = this.trim(pobj.mailTo);
merchant.mailMobile = this.trim(pobj.mailMobile);
merchant.ownerName = this.trim(pobj.ownerName);
merchant.ownerMobile = this.trim(pobj.ownerMobile);
try {
if (merchant.id) {
// 判断名称是否重复
await merchant.save();
} else {
merchant = await this.service.create(merchant);
}
this.merchantaccountSve.saveNew(merchant.id);
return system.getResultSuccess(merchant);
} catch (error) {
return system.getResultFail(500, "接口异常:" + error.message);
}
}
async merchantAudit(pobj, pobj2, req) {
try {
var id = Number(pobj.id);
var ucname = this.trim(pobj.ucname);
if(!ucname) {
return system.getResult(null, "请输入系统登录帐号");
}
var merchant = await this.service.findById(id);
if(!merchant) {
return system.getResult(null, "商户不存在");
}
merchant.status = 1;
merchant.ucname = ucname;
// TODO 创建ucname账户
await merchant.save();
return system.getResultSuccess("");
} catch (error) {
return system.getResultFail(500, "接口异常:" + error.message);
}
}
}
module.exports = MerchantCtl;
\ No newline at end of file
var system = require("../../../system")
const http = require("http")
const querystring = require('querystring');
var settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base");
const logCtl = system.getObject("web.common.oplogCtl");
const uuidv4 = require('uuid/v4');
var svgCaptcha = require('svg-captcha');
var cacheBaseComp = null;
class MerchantaccountCtl extends CtlBase {
constructor() {
super("merchant", CtlBase.getServiceName(MerchantaccountCtl));
this.redisClient = system.getObject("util.redisClient");
this.merchantSve = system.getObject("service.merchant.merchantSve");
}
async accountList(pobj, pobj2, req) {
try {
var condition = {
currentPage: pobj.currentPage,
pageSize: pobj.pageSize,
merchantName: this.trim(pobj.merchantName),
merchantId: pobj.merchantId
}
var page = await this.service.pageByCondition(condition);
return system.getResultSuccess(page);
} catch (error) {
console.log(error);
return system.getResultFail(500, "接口异常:" + error.message);
}
}
}
module.exports = MerchantaccountCtl;
\ No newline at end of file
var system = require("../../../system")
const http = require("http")
const querystring = require('querystring');
var settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base");
const logCtl = system.getObject("web.common.oplogCtl");
const uuidv4 = require('uuid/v4');
var svgCaptcha = require('svg-captcha');
var cacheBaseComp = null;
class MerchantrechargeCtl extends CtlBase {
constructor() {
super("merchant", CtlBase.getServiceName(MerchantrechargeCtl));
this.redisClient = system.getObject("util.redisClient");
this.merchantSve = system.getObject("service.merchant.merchantSve");
}
async rechargeList(pobj, pobj2, req) {
try {
var condition = {
currentPage: pobj.currentPage,
pageSize: pobj.pageSize,
merchantName: this.trim(pobj.merchantName),
merchantId: pobj.merchantId
}
this.doTimeCondition(condition, ["createdBegin", "createdEnd"]);
if(pobj.status) {
condition.status = Number(pobj.status);
}
var page = await this.service.pageByCondition(condition);
return system.getResultSuccess(page);
} catch (error) {
console.log(error);
return system.getResultFail(500, "接口异常:" + error.message);
}
}
async rechargeAudit(pobj, pobj2, req) {
try {
var loginUser = req.loginUser;
var id = Number(pobj.id);
var auditStatus = Number(pobj.status);
var remark = this.trim(pobj.remark);
if(auditStatus != 1 && auditStatus != 2) {
return system.getResult(null, "审核状态错误");
}
if(auditStatus == 2 && !remark) {
return system.getResult(null, "请填写审核备注");
}
var page = await this.service.audit(id, auditStatus, remark);
return system.getResultSuccess(page);
} catch (error) {
console.log(error);
return system.getResultFail(500, "接口异常:" + error.message);
}
}
}
module.exports = MerchantrechargeCtl;
\ No newline at end of file
var system = require("../../../system")
const http = require("http")
const querystring = require('querystring');
var settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base");
const logCtl = system.getObject("web.common.oplogCtl");
const uuidv4 = require('uuid/v4');
var svgCaptcha = require('svg-captcha');
var cacheBaseComp = null;
class MerchantsignedCtl extends CtlBase {
constructor() {
super("merchant", CtlBase.getServiceName(MerchantsignedCtl));
this.redisClient = system.getObject("util.redisClient");
this.merchantSve = system.getObject("service.merchant.merchantSve");
}
async merchantSign(pobj, pobj2, req) {
try {
var merchantId = Number(pobj.merchant_id);
var merchant = await this.merchantSve.findById(merchantId);
if(!merchant) {
return system.getResult(null, "商户不存在");
}
if(merchant.status == 0) {
return system.getResult(null, "当前状态为【待审核】, 不允许签约");
}
var signObj = {
merchant_id : merchantId,
nameA : this.trim(pobj.nameA),
contractNo : this.trim(pobj.contractNo),
beginDate : this.trim(pobj.beginDate),
endDate : this.trim(pobj.endDate),
serviceRate : this.trim(pobj.serviceRate),
}
var msign = await this.service.findOne({merchant_id: merchantId});
if(!msign) {
msign = {};
}
msign.merchant_id = merchantId;
msign.nameA = this.trim(pobj.nameA);
msign.contractNo = this.trim(pobj.contractNo);
msign.beginDate = this.trim(pobj.beginDate);
msign.endDate = this.trim(pobj.endDate);
msign.serviceRate = Number(pobj.serviceRate);
if(msign.id) {
await msign.save();
} else {
msign = this.service.create(msign);
}
merchant.status = 2;
await merchant.save();
return system.getResultSuccess("");
} catch (error) {
return system.getResultFail(500, "接口异常:" + error.message);
}
}
async showSign(pobj, pobj2, req) {
try {
var merchantId = Number(pobj.merchant_id);
var merchant = await this.merchantSve.getById(merchantId);
var msign = await this.service.getByMerchantId(merchantId);
return system.getResultSuccess({
merchant: merchant,
merchantSign: msign
});
} catch (error) {
console.log(error);
return system.getResultFail(500, "接口异常:" + error.message);
}
}
async signList(pobj, pobj2, req) {
try {
var condition = {
currentPage: pobj.currentPage,
pageSize: pobj.pageSize,
merchantName: this.trim(pobj.merchantName),
merchantId: pobj.merchantId,
}
var page = await this.service.pageByCondition(condition);
return system.getResultSuccess(page);
} catch (error) {
console.log(error);
return system.getResultFail(500, "接口异常:" + error.message);
}
}
// try {
// } catch (error) {
// return system.getResultFail(500, "接口异常:" + error.message);
// }
}
module.exports = MerchantsignedCtl;
\ No newline at end of file
var system = require("../../../system")
const http = require("http")
const querystring = require('querystring');
var settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base");
const logCtl = system.getObject("web.common.oplogCtl");
const uuidv4 = require('uuid/v4');
var svgCaptcha = require('svg-captcha');
var cacheBaseComp = null;
class MerchanttradeCtl extends CtlBase {
constructor() {
super("merchant", CtlBase.getServiceName(MerchanttradeCtl));
this.redisClient = system.getObject("util.redisClient");
this.merchantSve = system.getObject("service.merchant.merchantSve");
}
async tradeList(pobj, pobj2, req) {
try {
var condition = {
currentPage: pobj.currentPage,
pageSize: pobj.pageSize,
merchantName: this.trim(pobj.merchantName),
merchantId: pobj.merchantId,
invoiceApplyNo: this.trim(pobj.invoiceApplyNo),
type: pobj.type,
createdBegin: this.trim(pobj.createdBegin),
createdEnd: this.trim(pobj.createdEnd),
}
this.doTimeCondition(condition, ["createdBegin", "createdEnd"]);
var page = await this.service.pageByCondition(condition);
return system.getResultSuccess(page);
} catch (error) {
console.log(error);
return system.getResultFail(500, "接口异常:" + error.message);
}
}
// try {
// } catch (error) {
// return system.getResultFail(500, "接口异常:" + error.message);
// }
}
module.exports = MerchanttradeCtl;
\ No newline at end of file
......@@ -4,6 +4,7 @@ const settings = require("../../../config/settings");
class ApiAppIdCheckCache extends CacheBase {
constructor() {
super();
this.merchantDao = system.getObject("db.merchant.merchantDao");
}
desc() {
return "应用中来访访问appid缓存";
......@@ -12,5 +13,11 @@ class ApiAppIdCheckCache extends CacheBase {
return settings.cacheprefix + "_verify_appid:";
}
async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
var item = await this.merchantDao.getItemByAppId(inputkey);
if (!item) {
return null;
}
return JSON.stringify(item);
}
}
module.exports = ApiAppIdCheckCache;
const CacheBase = require("../cache.base");
const system = require("../../system");
const settings = require("../../../config/settings");
class MerchantPushUrlCache extends CacheBase {
constructor() {
super();
this.merchantpushDao = system.getObject("db.merchant.merchantpushDao");
}
desc() {
return "应用中缓存访问token";
}
prefix() {
return settings.cacheprefix + "_merchantPushUrl:";
}
async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
var item = await this.merchantpushDao.getItemByMerchantId(inputkey);
if (!item) {
return null;
}
return JSON.stringify(item);
}
}
module.exports = MerchantPushUrlCache;
......@@ -321,6 +321,5 @@ class Dao {
ids: ids
}) || [];
}
}
module.exports = Dao;
\ No newline at end of file
const fs=require("fs");
const settings=require("../../../../config/settings");
class CacheManager{
constructor(){
//await this.buildCacheMap();
this.buildCacheMap();
}
buildCacheMap(){
var self=this;
self.doc={};
var cachePath=settings.basepath+"/app/base/db/cache/";
const files=fs.readdirSync(cachePath);
if(files){
files.forEach(function(r){
var classObj=require(cachePath+"/"+r);
self[classObj.name]=new classObj();
var refTmp=self[classObj.name];
if(refTmp.prefix){
self.doc[refTmp.prefix]=refTmp.desc;
}
else{
console.log("请在"+classObj.name+"缓存中定义prefix");
}
});
}
}
}
module.exports=CacheManager;
// var cm= new CacheManager();
// cm["InitGiftCache"].cacheGlobalVal("hello").then(function(){
// cm["InitGiftCache"].cacheGlobalVal().then(x=>{
// console.log(x);
// });
// });
const system = require("../../../system");
const Dao = require("../../dao.base");
class MerchantDao extends Dao {
constructor() {
super(Dao.getModelName(MerchantDao));
this.statusMap = {
"00": "待审核",
"10": "待签约",
"20": "签约完成",
}
this.taxTypeMap = {
"00": "一般纳税人",
"10": "小规模纳税人"
}
}
async nameList() {
var sql = "SELECT id, name FROM m_merchant";
return await this.customQuery(sql);
}
/**
* 获取商户信息
* @param {*} app_id appid
*/
async getItemByAppId(app_id) {
return this.model.findOne({
where: {
id: app_id
},
attributes: ["id",
"name", //商户名称
"taxType", //纳税人类型 0一般纳税人 1小规模纳税人
"contactName", //联系人姓名
"contactMobile", //联系人手机
"contactEmail", //联系人邮箱
"taxNo", //纳税人识别号
"invoiceAddr", //开票地址
"invoiceMobile", //开票电话
"accountName", //开户名称
"accountPublic", //对公账户
"mailAddr", //邮寄地址
"mailTo", //收件人
"mailMobile", //收件电话
"ownerId", //客户经理id
"ownerPath", //客户经理组织机构路径
"status", //订单状态 0待审核 1待签约 2签约完成
"ucname", //登录账号
"ucid", //登录账号用户id
"appSecret"
],
raw: true
});
}
async idsLikeName(name) {
var result = [];
if (!name || !name.trim()) {
return result;
}
var sql = "SELECT id FROM m_merchant WHERE name LIKE :name ";
var list = await this.customQuery(sql, {
name: "%" + name + "%"
});
if (list) {
for (var item of list) {
result.push(item.id);
}
}
return result;
}
async findMapByIds(ids, attrs) {
var result = {};
if (!ids || ids.length == 0) {
return result;
}
attrs = attrs || "*";
var sql = "SELECT " + attrs + " FROM m_merchant where id IN (:ids) ";
var list = await this.customQuery(sql, {
ids: ids
});
if (!list || list.length == 0) {
return result;
}
for (var item of list) {
result[item.id] = item;
}
return result;
}
}
module.exports = MerchantDao;
// var u=new UserDao();
// var roledao=system.getObject("db.roleDao");
// (async ()=>{
// var users=await u.model.findAll({where:{app_id:1}});
// var role=await roledao.model.findOne({where:{code:"guest"}});
// console.log(role);
// for(var i=0;i<users.length;i++){
// await users[i].setRoles([role]);
// console.log(i);
// }
//
// })();
\ No newline at end of file
const system = require("../../../system");
const Dao = require("../../dao.base");
class MerchantaccountDao extends Dao {
constructor() {
super(Dao.getModelName(MerchantaccountDao));
}
// 冻结金额
// async frozenAmt(id, amt, t) {
// var sql = [];
// // UPDATE m_merchant_account SET banlance = banlance - :amt, frozen_amt = frozen_amt + :amt WHERE id = 1 AND banlance - :amt >= 0
// sql.push("UPDATE");
// sql.push("m_merchant_account");
// sql.push("SET");
// sql.push("banlance = banlance - :amt, frozen_amt = frozen_amt + :amt");
// sql.push("WHERE id = :id");
// sql.push("AND banlance - :amt >= 0");
// return await this.customUpdate(sql.join(" "), {
// id: id,
// amt: amt,
// }, t);
// }
// 撤回冻结
// async unFrozenAmt(id, amt, t) {
// var sql = [];
// // UPDATE m_merchant_account SET banlance = banlance - :amt, frozen_amt = frozen_amt + :amt WHERE id = 1 AND banlance - :amt >= 0
// sql.push("UPDATE");
// sql.push("m_merchant_account");
// sql.push("SET");
// sql.push("banlance = banlance + :amt, frozen_amt = frozen_amt - :amt");
// sql.push("WHERE id = :id");
// sql.push("AND frozen_amt - :amt >= 0");
// return await this.customUpdate(sql.join(" "), {
// id: id,
// amt: amt,
// }, t);
// }
// 解冻扣款
// async cutpayment(id, amt, t) {
// var sql = [];
// sql.push("UPDATE");
// sql.push("m_merchant_account");
// sql.push("SET");
// sql.push("frozen_amt = frozen_amt - :amt");
// sql.push("WHERE id = :id");
// sql.push("AND frozen_amt - :amt >= 0");
// return await this.customUpdate(sql.join(" "), {
// id: id,
// amt: amt,
// }, t);
// }
async inrBanlance(merchantId, amt, t) {
var sql = [];
sql.push("UPDATE");
sql.push("m_merchant_account");
sql.push("SET");
sql.push("banlance = banlance + :amt");
sql.push("WHERE merchant_id = :merchantId AND banlance + :amt > 0");
return await this.customUpdate(sql.join(" "), {
merchantId: merchantId,
amt: amt,
}, t);
}
async getByMerchantId(merchantId, channelId, attrs) {
if (!merchantId) {
return null;
}
var params = {
merchantId: merchantId,
channelId: channelId || 1,
}
attrs = attrs || "*";
var sql = "SELECT " + attrs + " FROM " + this.model.tableName + " where merchant_id = :merchantId AND channel_id = :channelId LIMIT 1";
var list = await this.customQuery(sql, params);
return list && list.length > 0 ? list[0] : null;
}
}
module.exports = MerchantaccountDao;
// var u=new UserDao();
// var roledao=system.getObject("db.roleDao");
// (async ()=>{
// var users=await u.model.findAll({where:{app_id:1}});
// var role=await roledao.model.findOne({where:{code:"guest"}});
// console.log(role);
// for(var i=0;i<users.length;i++){
// await users[i].setRoles([role]);
// console.log(i);
// }
//
// })();
\ No newline at end of file
const system = require("../../../system");
const Dao = require("../../dao.base");
class MerchantaddressDao extends Dao {
constructor() {
super(Dao.getModelName(MerchantaddressDao));
}
async updDefaultByMerchantId(merchantId, isDefault, t) {
var sql = [];
sql.push("UPDATE");
sql.push("m_merchant_address");
sql.push("SET");
sql.push("isDefault = :isDefault ");
sql.push("WHERE merchant_id = :merchantId");
return await this.customUpdate(sql.join(" "), {
merchantId: merchantId,
isDefault: isDefault
}, t);
}
async updDefaultById(id, isDefault, t) {
var sql = [];
sql.push("UPDATE");
sql.push("m_merchant_address");
sql.push("SET");
sql.push("isDefault = :isDefault ");
sql.push("WHERE id = :id");
return await this.customUpdate(sql.join(" "), {
id: id,
isDefault: isDefault
}, t);
}
async defaultByMerchantId(merchantId, t) {
var sql = "SELECT * FROM m_merchant_address WHERE merchant_id = :merchantId AND isDefault = 1";
var list = await this.customQuery(sql, {
merchantId: merchantId
}, t) || [null];
return list[0];
}
async listByMerchantId(merchantId, t) {
var sql = "SELECT * FROM m_merchant_address WHERE merchant_id = :merchantId";
return await this.customQuery(sql, {
merchantId: merchantId
}, t) || [];
}
async getDefaultByMerchantId(merchantId, t) {
var sql = "SELECT * FROM m_merchant_address WHERE merchant_id = :merchantId AND isDefault = 1";
var list = await this.customQuery(sql, {
merchantId: merchantId
}, t) || [];
return list && list.length > 0 ? list[0] : null;
}
}
module.exports = MerchantaddressDao;
// var u=new UserDao();
// var roledao=system.getObject("db.roleDao");
// (async ()=>{
// var users=await u.model.findAll({where:{app_id:1}});
// var role=await roledao.model.findOne({where:{code:"guest"}});
// console.log(role);
// for(var i=0;i<users.length;i++){
// await users[i].setRoles([role]);
// console.log(i);
// }
//
// })();
\ No newline at end of file
const system = require("../../../system");
const Dao = require("../../dao.base");
class MerchantpushDao extends Dao {
constructor() {
super(Dao.getModelName(MerchantpushDao));
}
/**
* 获取推送地址
* @param {*} merchant_id 商户id
*/
async getItemByMerchantId(merchant_id) {
return this.model.findOne({
where: {
merchant_id: merchant_id
},
raw: true
});
}
async pushInfo(merchantId, field, params) {
var pushConfig = this.dao.findOne({
merchant_id: merchantId
}) || {};
var url = pushConfig[field];
if(!url) {
return;
}
var rs = await this.restClient.execPost(params, url);
var success = false;
if (rs.stdout) {
let rsData = JSON.parse(rs.stdout);
if (rsData.code == "0" || rsData.code == "0000") {
success = true;
}
}
await this.merchantpushlogDao.create({
merchant_id: merchantId,
api: url,
params: params,
rs: rs,
success: success
});
}
}
module.exports = MerchantpushDao;
// var u=new UserDao();
// var roledao=system.getObject("db.roleDao");
// (async ()=>{
// var users=await u.model.findAll({where:{app_id:1}});
// var role=await roledao.model.findOne({where:{code:"guest"}});
// console.log(role);
// for(var i=0;i<users.length;i++){
// await users[i].setRoles([role]);
// console.log(i);
// }
//
// })();
\ No newline at end of file
const system=require("../../../system");
const Dao=require("../../dao.base");
class MerchantpushlogDao extends Dao{
constructor(){
super(Dao.getModelName(MerchantpushlogDao));
}
}
module.exports=MerchantpushlogDao;
// var u=new UserDao();
// var roledao=system.getObject("db.roleDao");
// (async ()=>{
// var users=await u.model.findAll({where:{app_id:1}});
// var role=await roledao.model.findOne({where:{code:"guest"}});
// console.log(role);
// for(var i=0;i<users.length;i++){
// await users[i].setRoles([role]);
// console.log(i);
// }
//
// })();
const system=require("../../../system");
const Dao=require("../../dao.base");
class MerchantrechargeDao extends Dao{
constructor(){
super(Dao.getModelName(MerchantrechargeDao));
this.statusMap = {
"00": "待审核",
"10": "已入账",
"20": "审核失败",
}
}
}
module.exports=MerchantrechargeDao;
// var u=new UserDao();
// var roledao=system.getObject("db.roleDao");
// (async ()=>{
// var users=await u.model.findAll({where:{app_id:1}});
// var role=await roledao.model.findOne({where:{code:"guest"}});
// console.log(role);
// for(var i=0;i<users.length;i++){
// await users[i].setRoles([role]);
// console.log(i);
// }
//
// })();
const system=require("../../../system");
const Dao=require("../../dao.base");
class MerchantsignedDao extends Dao{
constructor(){
super(Dao.getModelName(MerchantsignedDao));
}
}
module.exports=MerchantsignedDao;
// var u=new UserDao();
// var roledao=system.getObject("db.roleDao");
// (async ()=>{
// var users=await u.model.findAll({where:{app_id:1}});
// var role=await roledao.model.findOne({where:{code:"guest"}});
// console.log(role);
// for(var i=0;i<users.length;i++){
// await users[i].setRoles([role]);
// console.log(i);
// }
//
// })();
const system = require("../../../system");
const Dao = require("../../dao.base");
class MerchanttitleDao extends Dao {
constructor() {
super(Dao.getModelName(MerchanttitleDao));
}
async updDefaultByMerchantId(merchantId, isDefault, t) {
var sql = [];
// UPDATE m_merchant_title SET banlance = banlance - :amt, frozen_amt = frozen_amt + :amt WHERE id = 1 AND banlance - :amt >= 0
sql.push("UPDATE");
sql.push("m_merchant_title");
sql.push("SET");
sql.push("isDefault = :isDefault ");
sql.push("WHERE merchant_id = :merchantId");
return await this.customUpdate(sql.join(" "), {
merchantId: merchantId,
isDefault: isDefault
}, t);
}
async updDefaultById(id, isDefault, t) {
var sql = [];
sql.push("UPDATE");
sql.push("m_merchant_title");
sql.push("SET");
sql.push("isDefault = :isDefault ");
sql.push("WHERE id = :id");
return await this.customUpdate(sql.join(" "), {
id: id,
isDefault: isDefault
}, t);
}
async defaultByMerchantId(merchantId, t) {
var sql = "SELECT * FROM m_merchant_title WHERE merchant_id = :merchantId AND isDefault = 1";
var list = await this.customQuery(sql, {
merchantId: merchantId
}, t) || [];
return list[0];
}
async listByMerchantId(merchantId, t) {
var sql = "SELECT * FROM m_merchant_title WHERE merchant_id = :merchantId";
return await this.customQuery(sql, {
merchantId: merchantId
}, t) || [];
}
async getDefaultByMerchantId(merchantId, t) {
var sql = "SELECT * FROM m_merchant_title WHERE merchant_id = :merchantId AND isDefault = 1";
var list = await this.customQuery(sql, {
merchantId: merchantId
}, t) || [];
return list && list.length > 0 ? list[0] : null;
}
}
module.exports = MerchanttitleDao;
// var u=new UserDao();
// var roledao=system.getObject("db.roleDao");
// (async ()=>{
// var users=await u.model.findAll({where:{app_id:1}});
// var role=await roledao.model.findOne({where:{code:"guest"}});
// console.log(role);
// for(var i=0;i<users.length;i++){
// await users[i].setRoles([role]);
// console.log(i);
// }
//
// })();
\ No newline at end of file
const system=require("../../../system");
const Dao=require("../../dao.base");
class MerchanttradeprocessDao extends Dao{
constructor(){
super(Dao.getModelName(MerchanttradeprocessDao));
}
}
module.exports=MerchanttradeprocessDao;
// var u=new UserDao();
// var roledao=system.getObject("db.roleDao");
// (async ()=>{
// var users=await u.model.findAll({where:{app_id:1}});
// var role=await roledao.model.findOne({where:{code:"guest"}});
// console.log(role);
// for(var i=0;i<users.length;i++){
// await users[i].setRoles([role]);
// console.log(i);
// }
//
// })();
......@@ -35,6 +35,35 @@ module.exports = (db, DataTypes) => {
},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
const system = require("../../../system");
const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => {
return db.define("merchant", {
name: DataTypes.STRING(100),
taxType: DataTypes.STRING(4),
contactName: DataTypes.STRING(30),
contactMobile: DataTypes.STRING(30),
contactEmail: DataTypes.STRING(30),
invoiceValid: {
type: DataTypes.BOOLEAN,
defaultValue: false
},
mustPay: {
type: DataTypes.BOOLEAN,
defaultValue: false
},
orderPrice: DataTypes.BIGINT,
ownerName: DataTypes.STRING,
ownerMobile: DataTypes.STRING,
ownerId: DataTypes.STRING(32),
ownerPath: DataTypes.STRING(100),
status:{
type:DataTypes.STRING(4)
},
ucname: DataTypes.STRING(30),
ucid: DataTypes.STRING(32),
appSecret: DataTypes.STRING(64),//商户密钥信息,用于进行签名请求接口
}, {
paranoid: true,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'm_merchant',
validate: {
},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
const system=require("../../../system");
const settings=require("../../../../config/settings");
const uiconfig=system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => {
return db.define("merchantaccount", {
merchant_id: DataTypes.STRING(32),
channel_id: DataTypes.STRING(32),
banlance: DataTypes.BIGINT,
},{
paranoid: true,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'm_merchant_account',
validate: {
},
indexes:[
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
......@@ -2,53 +2,55 @@ const system = require("../../../system");
const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => {
return db.define("businessscope", {
domicile_id: DataTypes.STRING,
businessType: DataTypes.STRING,
businessscope: DataTypes.STRING,
isEnabled: {
return db.define("merchantaddress", {
merchant_id: DataTypes.STRING(32),
mailAddr: DataTypes.STRING(200),
mailTo: DataTypes.STRING(200),
mailMobile: DataTypes.STRING(200),
isDefault: {
type: DataTypes.BOOLEAN,
allowNull: true,
defaultValue: false
},
}, {
paranoid: true, //假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'd_businessscope',
validate: {},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
\ No newline at end of file
paranoid: true,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'm_merchant_address',
validate: {
},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
const system = require("../../../system");
const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => {
return db.define("merchantpush", {
merchant_id: DataTypes.STRING,
merchangeUpdate: DataTypes.STRING(200),
orderUpdate: DataTypes.STRING(200),
yichuzhizhao: DataTypes.STRING(200),
yikezhang: DataTypes.STRING(200),
yikaihu: DataTypes.STRING(200),
yishuiwubaodao: DataTypes.STRING(200),
yiyouji: DataTypes.STRING(200),
fapiaoshenhe: DataTypes.STRING(200),
fapiaokaiju: DataTypes.STRING(200),
fapiaoyouji: DataTypes.STRING(200),
fapiaowanshui: DataTypes.STRING(200),
chongzhishenhe: DataTypes.STRING(200),
}, {
paranoid: true, //假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'm_merchant_push',
validate: {},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
\ No newline at end of file
......@@ -2,12 +2,16 @@ const system = require("../../../system");
const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => {
return db.define("domicile", {
name: DataTypes.STRING,
isEnabled: {
return db.define("merchantpushlog", {
merchant_id: DataTypes.STRING,
api: DataTypes.STRING(200),
params: DataTypes.STRING(5000),
rs: DataTypes.STRING(200),
success: {
type: DataTypes.BOOLEAN,
allowNull: true,
defaultValue: false
},
}, {
paranoid: true, //假的删除
underscored: true,
......@@ -15,7 +19,7 @@ module.exports = (db, DataTypes) => {
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'd_domicile',
tableName: 'm_merchant_push_log',
validate: {},
indexes: [
// Create a unique index on email
......
const system=require("../../../system");
const settings=require("../../../../config/settings");
const uiconfig=system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => {
return db.define("merchantrecharge", {
merchant_id: DataTypes.BIGINT,
voucher: DataTypes.STRING(300),
outTradeNo: DataTypes.STRING,
amt: DataTypes.BIGINT,
status: DataTypes.STRING(4),
remark: DataTypes.STRING(300),
auditUserName: DataTypes.STRING,
auditUserId: DataTypes.STRING,
auditTime: DataTypes.DATE,
},{
paranoid: true,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'm_merchant_recharge',
validate: {
},
indexes:[
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
const system=require("../../../system");
const settings=require("../../../../config/settings");
const uiconfig=system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => {
return db.define("merchantsigned", {
merchant_id: DataTypes.STRING(32),
nameA: DataTypes.STRING(100),
contractNo: DataTypes.STRING(64),
beginDate: DataTypes.DATE,
endDate: DataTypes.DATE,
serviceRate: DataTypes.INTEGER,
},{
paranoid: true,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'm_merchant_signed',
validate: {
},
indexes:[
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
......@@ -2,55 +2,58 @@ const system = require("../../../system");
const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => {
return db.define("deliver", {
name: DataTypes.STRING,
businessmenDivide: DataTypes.INTEGER,
invoiceDivide: DataTypes.INTEGER,
remark: DataTypes.STRING,
return db.define("merchanttitle", {
isEnabled: {
merchant_id: DataTypes.STRING(32),
taxNo: DataTypes.STRING(64),
invoiceAddr: DataTypes.STRING(200),
invoiceMobile: DataTypes.STRING(30),
accountName: DataTypes.STRING(50),
accountPublic: DataTypes.STRING(50),
isDefault: {
type: DataTypes.BOOLEAN,
allowNull: true,
defaultValue: false
},
}, {
paranoid: true, //假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'd_deliver',
validate: {},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
\ No newline at end of file
paranoid: true,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'm_merchant_title',
validate: {
},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
const system=require("../../../system");
const settings=require("../../../../config/settings");
const uiconfig=system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => {
return db.define("merchantuser", {
ucid: {
type:DataTypes.INTEGER,
allowNull: false,
},
ucname: {
type:DataTypes.STRING,
allowNull: false,
},
merchant_id: DataTypes.BIGINT,
lastLoginTime: {
type:DataTypes.DATE,
allowNull: true,
},
},{
paranoid: true,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'xgg_merchant_user',
validate: {
},
indexes:[
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
const system=require("../../../system");
const ServiceBase=require("../../sve.base")
const settings=require("../../../../config/settings")
class MerchantaccountService extends ServiceBase{
constructor(){
super("merchant", ServiceBase.getDaoName(MerchantaccountService));
this.merchantDao = system.getObject("db.merchant.merchantDao");
}
async apiPage(params) {
try {
return await this.page(params);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiInfo(params) {
try {
return await this.info(params);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiInfoByMerchantId(params) {
try {
return await this.infoByMerchantId(params);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
// -----------------------以此间隔,上面为API,下面为service---------------------------------
async info(params) {
var obj = await this.dao.getById(params.id);
if (obj) {
this.handleDate(obj, ["created_at", "updated_at"], null, -8);
await this.setMerchantName([obj], "id, name,");
}
return system.getResultSuccess(obj);
}
async infoByMerchantId(params) {
var obj = await this.dao.getByMerchantId(params.merchantId || params.merchant_id);
if (obj) {
this.handleDate(obj, ["created_at", "updated_at"], null, -8);
await this.setMerchantName([obj], "id, name");
}
return system.getResultSuccess(obj);
}
async page(params) {
var currentPage = Number(params.currentPage || 1);
var pageSize = Number(params.pageSize || 10);
var where = {};
var merchantIds ;
if (params.merchantName) {
merchantIds = await this.merchantDao.idsLikeName(params.merchantName);
if (!merchantIds || merchantIds.length == 0) {
return {count : 0, rows: []};
}
}
if(params.merchantId) {
var mid = Number(params.merchantId);
if(merchantIds) {
if(merchantIds.indexOf(mid) == -1) {
return {count : 0, rows: []};
} else {
merchantIds = [mid];
}
} else {
merchantIds = [mid];
}
}
if(merchantIds && merchantIds.length > 0) {
where.merchant_id = {
[this.db.Op.in]: merchantIds
};
}
var orderby = [
["id", 'desc']
];
var attributes = ["id", "merchant_id", "banlance", "created_at"];
var page = await this.getPageList(currentPage, pageSize, where, orderby, attributes);
if (page && page.rows) {
for (var row of page.rows) {
this.handleDate(row, ["created_at"], null, -8);
}
await this.setMerchantName(page.rows, "id, name")
}
return system.getResultSuccess(page);
}
async setMerchantName(rows, attrs) {
var map = await this.getMerchantMap(rows, attrs);
for (var row of rows) {
row.merchantName = (map[row.merchant_id] || {}).name || "";
}
}
async setMerchant(rows, attrs) {
var map = await this.getMerchantMap(rows, attrs);
for(var row of rows) {
row.merchant = map[row.merchant_id] || {};
}
}
async getMerchantMap(rows, attrs) {
if(!rows || rows.length == 0) {
return {};
}
var ids = [];
for(var row of rows) {
ids.push(row.merchant_id);
}
return await this.merchantDao.findMapByIds(ids, attrs);
}
}
module.exports=MerchantaccountService;
// var task=new UserService();
// task.getUserStatisticGroupByApp().then(function(result){
// console.log((result));
// }).catch(function(e){
// console.log(e);
// });
const system = require("../../../system");
const ServiceBase = require("../../sve.base")
const settings = require("../../../../config/settings")
class DomicileService extends ServiceBase {
class MerchantaddressService extends ServiceBase {
constructor() {
super("common", ServiceBase.getDaoName(DomicileService));
this.businessscopeDao = system.getObject("db.common.businessscopeDao");
super("merchant", ServiceBase.getDaoName(MerchantaddressService));
this.merchantDao = system.getObject("db.merchant.merchantDao");
}
async apiNameList(params) {
async apiAddressPage(params) {
try {
return await this.nameList();
return await this.addressPage(params);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiTree(params) {
async apiAddressInfo(params) {
try {
return await this.tree(params);
return await this.addressInfo(params);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiPage(params) {
async apiSaveAddress(params) {
try {
return await this.page(params);
return await this.saveAddress(params);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiSave(params) {
async apiSetDefault(params) {
try {
return await this.save(params);
return await this.setDefault(params.id);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiInfo(params) {
async apiGetDefault(params) {
try {
return await this.info(params);
return await this.getDefault(params);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiDeleteByIds(params) {
var ids = params.ids;
if (!ids || ids.length == 0) {
return system.getResult(null, "传入参数错误:ids=" + JSON.stringify(ids));
}
try {
for (var id of ids) {
try {
await this.delById(id);
} catch (error) {
console.log(error);
}
}
return system.getResultSuccess(1);
} catch (error) {
return system.getResult(null, "接口异常");
}
}
// -----------------------以此间隔,上面为API,下面为service---------------------------------
async info(params) {
async saveAddress(params) {
var id = params.id;
if (!id) {
return system.getResult(null, "注册地不存在");
}
var sqlWhere = {
where: {
id: id
},
attributes: ["id", "name", "isEnabled", "created_at"],
raw: true
};
var item = await this.dao.model.findOne(sqlWhere);
if (!item) {
return system.getResult(null, "注册地不存在");
}
this.handleDate(item, ["created_at"], null, -8);
await this.setBusinessscopeList([item]);
return system.getResultSuccess(item);
}
async save(params) {
var id = params.id;
var domicile;
var merchantId = params.merchantId;
var address;
if (id) {
domicile = await this.dao.findById(id);
address = await this.findById(id);
} else {
domicile = {};
address = {
merchant_id: merchantId
};
}
domicile.name = this.trim(params.name);
domicile.isEnabled = params.isEnabled == 1 ? true : 0;
address.mailAddr = this.trim(params.mailAddr);
address.mailTo = this.trim(params.mailTo);
address.mailMobile = this.trim(params.mailMobile);
if (id) {
domicile = await domicile.save();
address = await address.save();
} else {
domicile = await this.dao.create(domicile);
address = await this.create(address);
}
return system.getResultSuccess(domicile);
}
async nameList() {
var list = await this.dao.getList(1, "id, name");
return system.getResultSuccess(list);
}
async tree(isEnabled) {
var tree = await this.dao.getList(isEnabled, "id, name, created_at");
if (tree) {
for (var row of tree) {
this.handleDate(row, ["created_at"], null, -8);
}
await this.setBusinessscopeList(tree);
if (params.isDefault) {
await this.dao.updDefaultByMerchantId(address.merchant_id, false);
await this.dao.updDefaultById(address.id, true);
}
return system.getResultSuccess(tree);
return system.getResultSuccess("");
}
async delById(id) {
if (!id) {
return system.getResult(null, "删除失败");
async getDefault(params) {
var merchantId = params.merchantId || params.merchant_id;
var obj = await this.dao.getDefaultByMerchantId(merchantId);
return system.getResultSuccess(obj);
}
async setDefault(id) {
var address = await this.dao.findById(id);
if (!address) {
return system.getResult(null, "地址不存在");
}
var self = this;
await this.db.transaction(async function (t) {
await self.dao.delById(id, t);
await self.businessscopeDao.delByDomicileId(id, t);
});
return system.getResultSuccess(1);
await this.dao.updDefaultByMerchantId(address.merchant_id, false);
await this.dao.updDefaultById(address.id, true);
return system.getResultSuccess();
}
async page(params) {
async addressPage(params) {
var currentPage = Number(params.currentPage || 1);
var pageSize = Number(params.pageSize || 10);
var where = {};
if (params.id > 0) {
where.id = params.id;
if (params.merchantId > 0) {
where.merchant_id = params.merchantId;
}
var orderby = [
["isDefault", 'desc'],
["id", 'desc']
];
var attributes = ["id", "name", "isEnabled", "created_at"];
var attributes = ["id", "merchant_id", "mailAddr", "mailTo", "mailMobile", "isDefault", "created_at"];
var page = await this.getPageList(currentPage, pageSize, where, orderby, attributes);
if (page && page.rows) {
for (var row of page.rows) {
this.handleDate(row, ["created_at"], null, -8);
}
await this.setBusinessscopeList(page.rows);
await this.setMerchantName(page.rows);
}
return system.getResultSuccess(page);
}
async setBusinessscopeList(rows) {
async addressInfo(params) {
var addr = await this.dao.getById(params.id);
if(addr) {
this.handleDate(addr, ["created_at", "updated_at"], null, -8);
}
return addr;
}
async setMerchant(rows, attrs) {
var map = await this.getMerchantMap(rows, attrs);
for (var row of rows) {
row.merchant = map[row.merchant_id] || {};
}
}
async setMerchantName(rows) {
var map = await this.getMerchantMap(rows);
for (var row of rows) {
row.merchantName = (map[row.merchant_id] || {}).name || "";
}
}
async getMerchantMap(rows, attrs) {
if (!rows || rows.length == 0) {
return rows;
return {};
}
var ids = [];
for (var item of rows) {
ids.push(item.id);
}
var bsmap = await this.businessscopeDao.findMapByDomicileIds(ids)
for (var row of rows) {
row.businessscopeList = bsmap[row.id] || [];
for (var item of row.businessscopeList) {
this.handleDate(item, ["created_at"], null, -8);
}
ids.push(row.merchant_id);
}
return await this.merchantDao.findMapByIds(ids, attrs);
}
}
module.exports = DomicileService;
module.exports = MerchantaddressService;
// var task=new UserService();
// task.getUserStatisticGroupByApp().then(function(result){
// console.log((result));
......
const system=require("../../../system");
const ServiceBase=require("../../sve.base")
const settings=require("../../../../config/settings")
class MerchantService extends ServiceBase{
constructor(){
super("merchant", ServiceBase.getDaoName(MerchantService));
}
}
module.exports=MerchantService;
// var task=new UserService();
// task.getUserStatisticGroupByApp().then(function(result){
// console.log((result));
// }).catch(function(e){
// console.log(e);
// });
const system=require("../../../system");
const ServiceBase=require("../../sve.base")
const settings=require("../../../../config/settings")
class MerchantpushlogService extends ServiceBase{
constructor(){
super("merchant", ServiceBase.getDaoName(MerchantpushlogService));
}
}
module.exports=MerchantpushlogService;
// var task=new UserService();
// task.getUserStatisticGroupByApp().then(function(result){
// console.log((result));
// }).catch(function(e){
// console.log(e);
// });
const system = require("../../../system");
const ServiceBase = require("../../sve.base")
const settings = require("../../../../config/settings")
class MerchantrechargeService extends ServiceBase {
constructor() {
super("merchant", ServiceBase.getDaoName(MerchantrechargeService));
this.merchantDao = system.getObject("db.merchant.merchantDao");
this.merchantaccountDao = system.getObject("db.merchant.merchantaccountDao");
}
async apiAdd(params) {
try {
return await this.add(params);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiPage(params) {
try {
return await this.page(params);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiInfo(params) {
try {
return await this.info(params);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiAudit(params) {
try {
return await this.audit(params);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
// -----------------------以此间隔,上面为API,下面为service---------------------------------
async add(params) {
var recharge = {
merchant_id: params.merchantId || params.merchant_id,
outTradeNo: this.trim(params.outTradeNo),
voucher: this.trim(params.voucher),
amt: Number(params.amt),
status: "00",
remark: "",
};
if (!recharge.outTradeNo) {
return system.getResult(null, "充值流水号不能为空");
}
if (!recharge.voucher) {
return system.getResult(null, "充值凭证不能为空");
}
if (!/^\d+$/.test(recharge.amt) || Number(recharge.amt) <= 0) {
return system.getResult(null, "充值金额只能为正整数");
}
var exists = await this.findOne({
merchant_id: recharge.merchant_id,
outTradeNo: recharge.outTradeNo,
});
if(exists) {
return system.getResult(null, "充值流水号已存在");
}
recharge = await this.dao.create(recharge);
return system.getResultSuccess();
}
async info(params) {
var recharge = await this.dao.getById(params.id);
if (recharge) {
await this.dao.setRowCodeName(recharge, "status");
this.handleDate(recharge, ["created_at", "updated_at"], null, -8);
await this.setMerchantName([recharge], "id, name");
}
return system.getResultSuccess(recharge);
}
async audit(params) {
var id = params.id;
var auditStatus = this.trim(params.status);
var remark = this.trim(params.remark);
var opUser = params.opUser;
var recharge = await this.dao.findById(id);
if (!recharge) {
return system.getResult(null, "充值申请不存在");
}
if(auditStatus != "10" && auditStatus != "20") {
return system.getResult(null, "审核状态错误");
}
if (recharge.status != "00") {
return system.getResult(null, "该申请已经被审核,不允许再次审核");
}
var self = this;
await this.db.transaction(async function (t) {
var updateParams = {
status: auditStatus,
remark: remark || "",
auditTime: new Date(),
auditUserName: opUser.ucname,
auditUserId: opUser.ucid,
}
// 审核
await self.dao.model.update(updateParams, {
where: {
id: recharge.id
},
transaction: t
});
if (auditStatus == "10") {
await self.merchantaccountDao.inrBanlance(recharge.merchant_id, recharge.amt, t);
var account = await self.merchantaccountDao.model.findOne({
channel_id: 0,
merchant_id: recharge.merchant_id
}, t);
}
});
return system.getResultSuccess();
}
async page(params) {
var currentPage = Number(params.currentPage || 1);
var pageSize = Number(params.pageSize || 10);
var where = {};
if (params.merchantId) {
where.merchant_id = params.merchantId;
}
if (params.status) {
where.status = params.status;
}
// 创建时间
this.addWhereTime(where, 'created_at', params.createdBegin, params.createdEnd, true);
var orderby = [
["id", 'desc']
];
var page = await this.getPageList(currentPage, pageSize, where, orderby, null);
if (page && page.rows) {
for (var row of page.rows) {
await this.dao.setRowCodeName(row, "status");
this.handleDate(row, ["created_at", "updated_at", "auditTime"], null, -8);
}
await this.setMerchantName(page.rows, "id, name");
}
return system.getResultSuccess(page);
}
async setMerchantName(rows, attrs) {
var map = await this.getMerchantMap(rows, attrs);
for (var row of rows) {
row.merchantName = (map[row.merchant_id] || {}).name || "";
}
}
async setMerchant(rows, attrs) {
var map = await this.getMerchantMap(rows, attrs);
for (var row of rows) {
row.merchant = map[row.merchant_id] || {};
}
}
async getMerchantMap(rows, attrs) {
if (!rows || rows.length == 0) {
return {};
}
var ids = [];
for (var row of rows) {
ids.push(row.merchant_id);
}
return await this.merchantDao.findMapByIds(ids, attrs);
}
}
module.exports = MerchantrechargeService;
// var task=new UserService();
// task.getUserStatisticGroupByApp().then(function(result){
// console.log((result));
// }).catch(function(e){
// console.log(e);
// });
\ No newline at end of file
const system=require("../../../system");
const ServiceBase=require("../../sve.base")
const settings=require("../../../../config/settings")
class MerchantsignedService extends ServiceBase{
constructor(){
super("merchant", ServiceBase.getDaoName(MerchantsignedService));
this.merchantDao = system.getObject("db.merchant.merchantDao");
}
async apiSaveSign(params) {
try {
return await this.saveSign(params);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiSignInfo(params) {
try {
return await this.getByMerchantId(params.merchantId);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiSignPage(params) {
try {
return await this.signPage(params);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
// -----------------------以此间隔,上面为API,下面为service---------------------------------
async saveSign(params) {
var merchantId = params.merchantId;
var sign = await this.dao.findOne({merchant_id: merchantId});
var merchant = await this.merchantDao.findById(merchantId);
if(!sign) {
sign = {};
sign.merchant_id = merchantId;
}
sign.nameA = params.nameA;
sign.contractNo = params.contractNo;
sign.beginDate = params.beginDate;
sign.endDate = params.endDate;
sign.serviceRate = params.serviceRate;
if(sign.id) {
await sign.save();
} else {
sign = await this.create(sign);
}
merchant.status = "90";
await merchant.save();
return system.getResultSuccess();
}
async getByMerchantId(merchantId, attrs) {
var attrs = attrs || ["id", "merchant_id", "nameA", "contractNo", "beginDate", "endDate", "serviceRate", "created_at"];
var sign = await this.dao.model.findOne({
where: { merchant_id: merchantId }, attrs, raw: true
});
if(sign) {
this.handleDate(sign, ["beginDate", "endDate"], "YYYY-MM-DD");
this.handleDate(sign, ["created_at"], null, -8);
await this.setMerchantName([sign]);
}
return system.getResultSuccess(sign);
}
async signPage(params) {
var currentPage = Number(params.currentPage || 1);
var pageSize = Number(params.pageSize || 10);
var where = {};
if(params.merchantId > 0) {
where.merchant_id = params.merchantId;
}
var orderby = [
["id", 'desc']
];
var attributes = ["id", "merchant_id", "nameA", "contractNo", "beginDate", "endDate", "serviceRate", "created_at"];
var page = await this.getPageList(currentPage, pageSize, where, orderby, attributes);
if (page && page.rows) {
for (var row of page.rows) {
this.handleDate(row, ["beginDate", "endDate"], "YYYY-MM-DD");
this.handleDate(row, ["created_at"], null, -8);
}
await this.setMerchantName(page.rows);
}
return system.getResultSuccess(page);
}
async setMerchant(rows, attrs) {
var map = await this.getMerchantMap(rows, attrs);
for(var row of rows) {
row.merchant = map[row.merchant_id] || {};
}
}
async setMerchantName(rows) {
var map = await this.getMerchantMap(rows);
for(var row of rows) {
row.merchantName = (map[row.merchant_id] || {}).name || "";
}
}
async getMerchantMap(rows, attrs) {
if(!rows || rows.length == 0) {
return {};
}
var ids = [];
for(var row of rows) {
ids.push(row.merchant_id);
}
return await this.merchantDao.findMapByIds(ids, attrs);
}
}
module.exports=MerchantsignedService;
// var task=new UserService();
// task.getUserStatisticGroupByApp().then(function(result){
// console.log((result));
// }).catch(function(e){
// console.log(e);
// });
const system = require("../../../system");
const ServiceBase = require("../../sve.base")
const settings = require("../../../../config/settings")
class DeliverService extends ServiceBase {
class MerchanttitleService extends ServiceBase {
constructor() {
super("deliver", ServiceBase.getDaoName(DeliverService));
super("merchant", ServiceBase.getDaoName(MerchanttitleService));
this.merchantDao = system.getObject("db.merchant.merchantDao");
}
async apiAll(params) {
async apiTitlePage(params) {
try {
return await this.allList();
return await this.titlePage(params);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiPage(params) {
async apiTitleInfo(params) {
try {
return await this.page(params);
return await this.info(params);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiSave(params) {
async apiSaveTitle(params) {
try {
return await this.save(params);
return await this.saveTitle(params);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiInfo(params) {
async apiSetDefault(params) {
try {
return await this.info(params);
return await this.setDefault(params.id);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiDeleteByIds(params) {
var ids = params.ids;
if(!ids || ids.length == 0) {
return system.getResult(null, "传入参数错误:ids=" + JSON.stringify(ids));
}
async apiGetDefault(params) {
try {
for(var id of ids) {
try {
await this.delById(id);
} catch (error) {
console.log(error);
}
}
return system.getResultSuccess(1);
return await this.getDefault(params);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
// -----------------------以此间隔,上面为API,下面为service---------------------------------
async getDefault(params) {
var merchantId = params.merchantId || params.merchant_id;
var obj = await this.dao.getDefaultByMerchantId(merchantId);
return system.getResultSuccess(obj);
}
async info(params) {
var id = params.id;
var sqlWhere = {
where: {
id: id
},
attributes: ["id", "name", "businessmenDivide", "invoiceDivide", "isEnabled", "remark", "created_at"],
raw: true
};
var item = await this.dao.model.findOne(sqlWhere);
this.handleDate(item, ["created_at"], null, -8);
return system.getResultSuccess(item);
var title = await this.dao.getById(params.id);
if(title) {
this.handleDate(title, ["created_at"], null, -8);
await this.setMerchantName([title]);
}
return system.getResultSuccess(title);
}
async save(params) {
async saveTitle(params) {
var id = params.id;
var deliver;
var merchantId = params.merchantId;
var title;
if (id) {
deliver = await this.dao.findById(id);
title = await this.findById(id);
} else {
deliver = {};
title = {
merchant_id: merchantId
};
}
deliver.name = this.trim(params.name);
deliver.businessmenDivide = Number(params.businessmenDivide);
deliver.invoiceDivide = Number(params.invoiceDivide);
deliver.isEnabled = params.isEnabled == 1 ? true : 0;
deliver.remark = this.trim(params.remark);
title.taxNo = this.trim(params.taxNo);
title.invoiceAddr = this.trim(params.invoiceAddr);
title.invoiceMobile = this.trim(params.invoiceMobile);
title.accountName = this.trim(params.accountName);
title.accountPublic = this.trim(params.accountPublic);
if (id) {
deliver = await deliver.save();
title = await title.save();
} else {
deliver = await this.dao.create(deliver);
title = await this.create(title);
}
return system.getResultSuccess(deliver);
}
async allList() {
var list = await this.dao.getList(1, "id, name, businessmenDivide, invoiceDivide, remark");
return system.getResultSuccess(list);
if (params.isDefault) {
await this.dao.updDefaultByMerchantId(title.merchant_id, false);
await this.dao.updDefaultById(title.id, true);
}
return system.getResultSuccess(title);
}
async delById(id) {
if (!id) {
return system.getResult(null, "删除失败");
async setDefault(id) {
var title = await this.dao.findById(id);
if (!title) {
return system.getResult(null, "抬头不存在");
}
await this.dao.delById(id);
return system.getResultSuccess(1);
await this.dao.updDefaultByMerchantId(title.merchant_id, false);
await this.dao.updDefaultById(title.id, true);
return system.getResultSuccess();
}
async page(params) {
async titlePage(params) {
var currentPage = Number(params.currentPage || 1);
var pageSize = Number(params.pageSize || 10);
var where = {};
if (params.merchantId > 0) {
where.merchant_id = params.merchantId;
}
var orderby = [
["isDefault", 'desc'],
["id", 'desc']
];
var attributes = ["id", "name", "businessmenDivide", "invoiceDivide", "isEnabled", "remark", "created_at"];
var attributes = ["id", "merchant_id", "taxNo", "invoiceAddr", "invoiceMobile", "accountName", "accountPublic", "isDefault", "created_at"];
var page = await this.getPageList(currentPage, pageSize, where, orderby, attributes);
if (page && page.rows) {
for (var row of page.rows) {
this.handleDate(row, ["created_at"], null, -8);
}
await this.setMerchantName(page.rows);
}
return system.getResultSuccess(page);
}
async setMerchant(rows, attrs) {
var map = await this.getMerchantMap(rows, attrs);
for (var row of rows) {
row.merchant = map[row.merchant_id] || {};
}
}
async setMerchantName(rows) {
var map = await this.getMerchantMap(rows);
for (var row of rows) {
row.merchantName = (map[row.merchant_id] || {}).name || "";
}
}
async getMerchantMap(rows, attrs) {
if (!rows || rows.length == 0) {
return {};
}
var ids = [];
for (var row of rows) {
ids.push(row.merchant_id);
}
return await this.merchantDao.findMapByIds(ids, attrs);
}
}
module.exports = DeliverService;
module.exports = MerchanttitleService;
// var task=new UserService();
// task.getUserStatisticGroupByApp().then(function(result){
// console.log((result));
......
const system=require("../../../system");
const ServiceBase=require("../../sve.base")
const settings=require("../../../../config/settings")
class MerchantuserService extends ServiceBase{
constructor(){
super("merchant", ServiceBase.getDaoName(MerchantuserService));
}
}
module.exports=MerchantuserService;
// var task=new UserService();
// task.getUserStatisticGroupByApp().then(function(result){
// console.log((result));
// }).catch(function(e){
// console.log(e);
// });
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