Commit 13a71025 by Sxy

Merge branch 'gsb-ic-deliver' of gitlab.gongsibao.com:jiangyong/zhichan into gsb-ic-deliver

parents 29f57380 771eb725
var system = require("../../../system");
let dS = system.getObject("service.bizchance.deliverybillSve");
dS.updateCostBySkuCode().then(r => {
console.log(r)
})
\ No newline at end of file
......@@ -9,10 +9,10 @@ class Dao {
this.model = db.models[this.modelName];
console.log(this.modelName);
}
preCreate(u) {
preCreate (u) {
return u;
}
async create(u, t) {
async create (u, t) {
var u2 = this.preCreate(u);
if (t) {
console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
......@@ -26,11 +26,11 @@ class Dao {
});
}
}
static getModelName(ClassObj) {
static getModelName (ClassObj) {
return ClassObj["name"].substring(0, ClassObj["name"].lastIndexOf("Dao")).toLowerCase()
}
async refQuery(qobj) {
var w =qobj.refwhere? qobj.refwhere:{};
async refQuery (qobj) {
var w = qobj.refwhere ? qobj.refwhere : {};
if (qobj.levelinfo) {
w[qobj.levelinfo.levelfield] = qobj.levelinfo.level;
}
......@@ -38,8 +38,8 @@ class Dao {
w[qobj.parentinfo.parentfield] = qobj.parentinfo.parentcode;
}
//如果需要控制数据权限
if(qobj.datapriv){
w["id"]={ [this.db.Op.in]: qobj.datapriv};
if (qobj.datapriv) {
w["id"] = { [this.db.Op.in]: qobj.datapriv };
}
if (qobj.likestr) {
w[qobj.fields[0]] = { [this.db.Op.like]: "%" + qobj.likestr + "%" };
......@@ -48,11 +48,11 @@ class Dao {
return this.model.findAll({ where: w, attributes: qobj.fields });
}
}
async bulkDelete(ids) {
async bulkDelete (ids) {
var en = await this.model.destroy({ where: { id: { [this.db.Op.in]: ids } } });
return en;
}
async bulkDeleteByWhere(whereParam, t) {
async bulkDeleteByWhere (whereParam, t) {
var en = null;
if (t != null && t != 'undefined') {
whereParam.transaction = t;
......@@ -61,34 +61,34 @@ class Dao {
return await this.model.destroy(whereParam);
}
}
async delete(qobj, t) {
async delete (qobj, t) {
var en = null
if (t != null && t != 'undefined') {
en=await this.model.findOne({ where: {id:qobj.id},transaction:t});
en = await this.model.findOne({ where: { id: qobj.id }, transaction: t });
if (en != null) {
await en.destroy({ transaction: t });
return en
}
} else {
en=await this.model.findOne({ where: {id:qobj.id}});
en = await this.model.findOne({ where: { id: qobj.id } });
if (en != null) {
return en.destroy();
}
return en
}
}
extraModelFilter(pobj) {
extraModelFilter (pobj) {
//return {"key":"include","value":{model:this.db.models.app}};
return null;
}
extraWhere(obj, where) {
extraWhere (obj, where) {
return where;
}
orderBy() {
orderBy () {
//return {"key":"include","value":{model:this.db.models.app}};
return [["created_at", "DESC"]];
}
buildQuery(qobj) {
buildQuery (qobj) {
var linkAttrs = [];
const pageNo = qobj.pageInfo.pageNo;
const pageSize = qobj.pageInfo.pageSize;
......@@ -146,7 +146,7 @@ class Dao {
console.log(qc);
return qc;
}
buildaggs(qobj) {
buildaggs (qobj) {
var aggsinfos = [];
if (qobj.aggsinfo) {
qobj.aggsinfo.sum.forEach(aggitem => {
......@@ -160,7 +160,7 @@ class Dao {
}
return aggsinfos;
}
async findAggs(qobj, qcwhere) {
async findAggs (qobj, qcwhere) {
var aggArray = this.buildaggs(qobj);
if (aggArray.length != 0) {
qcwhere["attributes"] = {};
......@@ -173,19 +173,23 @@ class Dao {
}
}
async findAndCountAll(qobj, t) {
convertAggResult (aggresult) {
return aggresult
}
async findAndCountAll (qobj, t) {
var qc = this.buildQuery(qobj);
var apps = await this.model.findAndCountAll(qc);
var aggresult = await this.findAggs(qobj, qc);
let convertAggResult = this.convertAggResult(aggresult);
var rtn = {};
rtn.results = apps;
rtn.aggresult = aggresult;
rtn.aggresult = convertAggResult;
return rtn;
}
preUpdate(obj) {
preUpdate (obj) {
return obj;
}
async update(obj, tm) {
async update (obj, tm) {
var obj2 = this.preUpdate(obj);
if (tm != null && tm != 'undefined') {
return this.model.update(obj2, { where: { id: obj2.id }, transaction: tm });
......@@ -193,7 +197,7 @@ class Dao {
return this.model.update(obj2, { where: { id: obj2.id } });
}
}
async bulkCreate(ids, t) {
async bulkCreate (ids, t) {
if (t != null && t != 'undefined') {
return await this.model.bulkCreate(ids, { transaction: t });
} else {
......@@ -201,21 +205,21 @@ class Dao {
}
}
async updateByWhere(setObj, whereObj, t) {
let inWhereObj={}
async updateByWhere (setObj, whereObj, t) {
let inWhereObj = {}
if (t && t != 'undefined') {
if (whereObj && whereObj != 'undefined') {
inWhereObj["where"]=whereObj;
inWhereObj["where"] = whereObj;
inWhereObj["transaction"] = t;
} else {
inWhereObj["transaction"] = t;
}
}else{
inWhereObj["where"]=whereObj;
} else {
inWhereObj["where"] = whereObj;
}
return this.model.update(setObj, inWhereObj);
}
async customExecAddOrPutSql(sql, paras = null) {
async customExecAddOrPutSql (sql, paras = null) {
return this.db.query(sql, paras);
}
/**
......@@ -224,19 +228,19 @@ class Dao {
* p.group.aliasField=' as xxx'
* @param {*} p
*/
async statGroupBy(p,paras,t){
let groupFields=p.group.byFields.join(",")
let aggField=p.group.aggField?p.group.aggField:''
let tblName=p.group.tblName?p.group.tblName:''
let where=p.group.where?p.group.where:''
let having=p.group.having?p.group.having:''
let aliasField=p.group.aliasField?p.group.aliasField:''
let actionType=p.group.actionType?p.group.actionType:'count'
let sql=`select ${groupFields},${actionType}(${aggField}) ${aliasField} from ${tblName} ${where} group by ${groupFields} ${having} WITH ROLLUP`
return this.customQuery(sql,paras,t)
async statGroupBy (p, paras, t) {
let groupFields = p.group.byFields.join(",")
let aggField = p.group.aggField ? p.group.aggField : ''
let tblName = p.group.tblName ? p.group.tblName : ''
let where = p.group.where ? p.group.where : ''
let having = p.group.having ? p.group.having : ''
let aliasField = p.group.aliasField ? p.group.aliasField : ''
let actionType = p.group.actionType ? p.group.actionType : 'count'
let sql = `select ${groupFields},${actionType}(${aggField}) ${aliasField} from ${tblName} ${where} group by ${groupFields} ${having} WITH ROLLUP`
return this.customQuery(sql, paras, t)
}
async customQuery(sql, paras, t) {
async customQuery (sql, paras, t) {
var tmpParas = null;//||paras=='undefined'?{type: this.db.QueryTypes.SELECT }:{ replacements: paras, type: this.db.QueryTypes.SELECT };
if (t && t != 'undefined') {
if (paras == null || paras == 'undefined') {
......@@ -251,15 +255,15 @@ class Dao {
}
return this.db.query(sql, tmpParas);
}
async findCount(whereObj = null) {
async findCount (whereObj = null) {
return this.model.count(whereObj, { logging: false }).then(c => {
return c;
});
}
async findSum(fieldName, whereObj = null) {
async findSum (fieldName, whereObj = null) {
return this.model.sum(fieldName, whereObj);
}
async getPageList(pageIndex, pageSize, whereObj = null, orderObj = null, attributesObj = null, includeObj = null) {
async getPageList (pageIndex, pageSize, whereObj = null, orderObj = null, attributesObj = null, includeObj = null) {
var tmpWhere = {};
tmpWhere.limit = pageSize;
tmpWhere.offset = (pageIndex - 1) * pageSize;
......@@ -275,15 +279,15 @@ class Dao {
if (includeObj != null && includeObj.length > 0) {
tmpWhere.include = includeObj;
tmpWhere.distinct = true;
}else{
} else {
tmpWhere.raw = true;
}
return await this.model.findAndCountAll(tmpWhere);
}
async findOne(obj) {
async findOne (obj) {
return this.model.findOne({ "where": obj });
}
async findById(oid) {
async findById (oid) {
return this.model.findById(oid);
}
}
......
......@@ -4,11 +4,20 @@ class DeliverybillDao extends Dao {
constructor() {
super(Dao.getModelName(DeliverybillDao));
}
extraModelFilter(pobj) {
convertAggResult (aggresult) {
if (aggresult) {
Object.keys(aggresult).forEach((k) => {
if (k.indexOf("sum") >= 0) {
aggresult[k] = aggresult[k] / 100
}
})
}
return aggresult
}
extraModelFilter (pobj) {
return { "key": "include", "value": { model: this.db.models.settlebill, raw: true, attributes: ['memo'] } };
}
extraWhere(qobj, qw, qc) {//根据业务员id获取交付单信息的组装条件
extraWhere (qobj, qw, qc) {//根据业务员id获取交付单信息的组装条件
//qc.raw = true;
//检查查询的用户所属公司是否是平台运营公司-1,如果是则不添加公司查询条件, 不添加路径条件,返回所有数据
if (qw["delivery_status"] == "handling") {//解决首页多状态查询
......@@ -53,13 +62,13 @@ class DeliverybillDao extends Dao {
}
/*根据交付单编号获取订单详情*/
async findInfoByDeliverCode(qobj) {
async findInfoByDeliverCode (qobj) {
var qcwhere = { "delivery_code": qobj.deliverNumber };
return await this.findOne(qcwhere);
}
/*根据交付单编号更新状态信息*/
async updateStatusByDeliverCode(qobj, t) {
async updateStatusByDeliverCode (qobj, t) {
var setobj = { "delivery_status": qobj.deliverStatus };
if (qobj.statusReason && qobj.statusReason != 'undefined') {
setobj.close_reason = qobj.statusReason;
......@@ -85,28 +94,28 @@ class DeliverybillDao extends Dao {
}
/*更新业务员/交付员信息*/
async updateSalesmanInfoByDeliverCode(qobj, t) {
async updateSalesmanInfoByDeliverCode (qobj, t) {
var setobj = {};
if(qobj.type == "salesman") {
if (qobj.type == "salesman") {
if (qobj.salesmanId && qobj.salesmanId != 'undefined') {
setobj.delivery_man_id = qobj.salesmanId;
setobj.salesman_id = qobj.salesmanId;
};
if (qobj.salesmanName && qobj.salesmanName != 'undefined') {
setobj.delivery_man_name = qobj.salesmanName;
setobj.salesman_name = qobj.salesmanName;
};
if (qobj.salesmanOpcode && qobj.salesmanOpcode != 'undefined') {
setobj.delivery_man_opcode = qobj.salesmanOpcode;
setobj.salesman_opcode = qobj.salesmanOpcode;
};
}
if(qobj.type == "deliverman") {
if (qobj.type == "deliverman") {
if (qobj.deliverymanId && qobj.deliverymanId != 'undefined') {
setobj.salesman_id = qobj.deliverymanId;
setobj.delivery_man_id = qobj.deliverymanId;
};
if (qobj.deliverymanName && qobj.deliverymanName != 'undefined') {
setobj.salesman_name = qobj.deliverymanName;
setobj.delivery_man_name = qobj.deliverymanName;
};
if (qobj.deliverymanOpcode && qobj.deliverymanOpcode != 'undefined') {
setobj.salesman_opcode = qobj.deliverymanOpcode;
setobj.delivery_man_opcode = qobj.deliverymanOpcode;
};
}
// if (qobj.salesmanPhone && qobj.salesmanPhone != 'undefined') {
......@@ -123,7 +132,7 @@ class DeliverybillDao extends Dao {
}
/*根据交付单更新交付材料信息*/
async updateInfoByDeliverCode(qobj, t) {//公司注册、云上园区注册时填写交付材料
async updateInfoByDeliverCode (qobj, t) {//公司注册、云上园区注册时填写交付材料
var whereobj = { "delivery_code": qobj.deliverNumber };
var setobj = { "delivery_info": qobj.baseInfo };
if (qobj.deliverStatus && qobj.deliverStatus != 'undefined') {
......@@ -139,7 +148,7 @@ class DeliverybillDao extends Dao {
}
/*插入交付单信息*/
async insertInfo(qobj, t) {//到时候看交付单信息后再确定
async insertInfo (qobj, t) {//到时候看交付单信息后再确定
var obj = {
"delivery_code": qobj.deliverNumber,
"delivery_status": qobj.deliverStatus,
......@@ -151,6 +160,9 @@ class DeliverybillDao extends Dao {
if (qobj.schemeNumber && qobj.schemeNumber != 'undefined') {
obj.scheme_number = qobj.schemeNumber;
}
if (qobj.companyName && qobj.companyName != 'undefined') {
obj.company_name = qobj.companyName;
}
if (qobj.businessName && qobj.businessName != 'undefined') {
obj.product_name = qobj.businessName;
}
......@@ -182,7 +194,7 @@ class DeliverybillDao extends Dao {
if (qobj.clerkName && qobj.clerkName != 'undefined') {
obj.delivery_man_name = qobj.clerkName;
}
if (qobj.salesmanName && qobj.salesmanName != 'undefined'){
if (qobj.salesmanName && qobj.salesmanName != 'undefined') {
obj.salesman_name = qobj.salesmanName;
}
if (qobj.salesmanPhone && qobj.salesmanPhone != 'undefined') {
......
......@@ -42,6 +42,10 @@ module.exports = (db, DataTypes) => {
allowNull: true,
type: DataTypes.STRING
},
company_name: {// 方案编号
allowNull: true,
type: DataTypes.STRING
},
product_code: { // 产品编码
allowNull: true,
type: DataTypes.STRING
......
......@@ -10,7 +10,23 @@ class DeliverybillService extends ServiceBase {
this.cacheDao = system.getObject("db.bizchance.cacheinfoDao");
}
async statBizDeliverySettleAmountBySp(settleStatus) {
async updateCostBySkuCode () {
let bills = await this.dao.model.findAll()
bills.forEach(async b => {
//远程调用去查询成本按照skucode
let costqueryobj = await system.postJsonTypeReq("http://paas-service/api/common/product/findCostBySkuCode", {
"skucode": b.sku_code
}, "POST", { xappkey: "647a68c9-da01-40d3-9763-1ffa0f64cf3f" })
let rtn = costqueryobj.data
let cn = rtn.data.cost
console.log(cn, "....................................................................", b.sku_code)
b.cost_price = cn
await b.save()
})
return "ok"
}
async statBizDeliverySettleAmountBySp (settleStatus) {
let params = {}
let where = settleStatus != "" ? `where settle_status='${settleStatus}'` : ''
......@@ -26,7 +42,7 @@ class DeliverybillService extends ServiceBase {
let s = await this.dao.statGroupBy(params, null)
return s
}
async statBizDeliveryCountBySp(deliverStatus, betweenTime) {
async statBizDeliveryCountBySp (deliverStatus, betweenTime) {
let params = {}
let where = deliverStatus != "" ? `where delivery_status='${deliverStatus}'` : ''
if (deliverStatus == "handling") {
......@@ -47,7 +63,7 @@ class DeliverybillService extends ServiceBase {
let s = await this.dao.statGroupBy(params, null)
return s
}
async statBizDelivery(companyId, opath, username, userid, betweenTime) {
async statBizDelivery (companyId, opath, username, userid, betweenTime) {
// 时间 筛选
let andWhere = [];
if (betweenTime.length > 0) {
......@@ -115,17 +131,17 @@ class DeliverybillService extends ServiceBase {
closedCount: closedCount,
allHandled: allHandled,
toSettle: toSettle,
toSettleAmount: toSettleAmount ? toSettleAmount : 0,
toSettleAmount: toSettleAmount ? toSettleAmount / 100 : 0,
settling: settling,
settlingAmount: settlingAmount ? settlingAmount : 0,
settlingAmount: settlingAmount ? settlingAmount / 100 : 0,
settled: settled,
settledAmount: settledAmount ? settledAmount : 0
settledAmount: settledAmount ? settledAmount / 100 : 0
}
}
//为租户自己给交付打标记,表示中台已经给予结算,自己记账用
//租户自己临时记录结算情况
async settleApplyForTacent(ids, uid, uname, spname, spid) {
async settleApplyForTacent (ids, uid, uname, spname, spid) {
var self = this
return this.db.transaction(async function (t) {
//先按照ids查询出交付单的合计服务成本
......@@ -161,7 +177,7 @@ class DeliverybillService extends ServiceBase {
});
}
async settleApply(ids, uid, uname, spname, spid) {
async settleApply (ids, uid, uname, spname, spid) {
var self = this
return this.db.transaction(async function (t) {
//先按照ids查询出交付单的合计服务成本
......@@ -190,30 +206,30 @@ class DeliverybillService extends ServiceBase {
return newentity
});
}
async findAndCountAll(obj) {
async findAndCountAll (obj) {
var self = this;
const apps = await self.dao.findAndCountAll(obj);
return apps;
}
async findInfoByDeliverCode(qobj) {//*根据交付单编号获取交付单详情*/
async findInfoByDeliverCode (qobj) {//*根据交付单编号获取交付单详情*/
return await this.dao.findInfoByDeliverCode(qobj);
}
async updateStatusByDeliverCode(qobj) {//* 根据交付单编号更新交付单状态 */
async updateStatusByDeliverCode (qobj) {//* 根据交付单编号更新交付单状态 */
var self = this;
return self.db.transaction(async function (t) {
return await self.dao.updateStatusByDeliverCode(qobj, t);
});
}
/*更新业务员/交付员信息*/
async updateSalesmanInfoByDeliverCode(qobj){
async updateSalesmanInfoByDeliverCode (qobj) {
var self = this;
return self.db.transaction(async function (t) {
return await self.dao.updateSalesmanInfoByDeliverCode(qobj, t);
});
}
async updateInfoByDeliverCode(qobj) {//*更新交付单信息 */
async updateInfoByDeliverCode (qobj) {//*更新交付单信息 */
console.log("--------------------------------------------------------------------------------------------------------------------------------------");
var self = this;
return self.db.transaction(async function (t) {
......@@ -221,14 +237,14 @@ class DeliverybillService extends ServiceBase {
});
}
async insertInfo(qobj) {//*插入交付单信息*/从队列取数据的时候用
async insertInfo (qobj) {//*插入交付单信息*/从队列取数据的时候用
var self = this;
return self.db.transaction(async function (t) {
return await self.dao.insertInfo(qobj, t);
});
}
async insertInfoall(pobj) {//*插入交付单信息,大事务*/从队列取数据的时候用
async insertInfoall (pobj) {//*插入交付单信息,大事务*/从队列取数据的时候用
var self = this;
return await self.db.transaction(async function (t) {
var res = await self.dao.insertInfo(pobj);//插入交付单列表
......
......@@ -5,7 +5,7 @@ const request = require('request');
const cryptoJS = require('crypto-js');
class System {
static declare(ns) {
static declare (ns) {
var ar = ns.split('.');
var root = System;
for (var i = 0, len = ar.length; i < len; ++i) {
......@@ -18,7 +18,7 @@ class System {
}
}
}
static async delReq(url, qdata) {
static async delReq (url, qdata) {
let rtn = {}
let promise = new Promise(function (resv, rej) {
request.del({
......@@ -41,7 +41,7 @@ class System {
})
return promise;
}
static async getReq(url, qdata) {
static async getReq (url, qdata) {
let rtn = {}
let promise = new Promise(function (resv, rej) {
request.get({
......@@ -64,7 +64,7 @@ class System {
})
return promise;
}
static async postJsonTypeReq(url, data, md = "POST") {
static async postJsonTypeReq (url, data, md = "POST", otherHeaders) {
let rtn = {}
let promise = new Promise(function (resv, rej) {
request({
......@@ -73,6 +73,7 @@ class System {
json: true,
headers: {
"content-type": "application/json",
...otherHeaders
},
body: data
}, function (error, response, body) {
......@@ -92,7 +93,7 @@ class System {
})
return promise;
}
static async post3wFormTypeReq(url, data) {
static async post3wFormTypeReq (url, data) {
let rtn = {}
let promise = new Promise(function (resv, rej) {
request.post({
......@@ -111,7 +112,7 @@ class System {
})
return promise;
}
static async postMpFormTypeReq(url, formdata) {
static async postMpFormTypeReq (url, formdata) {
let promise = new Promise(function (resv, rej) {
request.post({
url: url,
......@@ -133,7 +134,7 @@ class System {
* @param {*} okmsg 操作成功的描述
* @param {*} req 请求头信息
*/
static getResult(data, opmsg = "操作成功", req) {
static getResult (data, opmsg = "操作成功", req) {
return {
status: !data ? -1 : 0,
msg: opmsg,
......@@ -146,7 +147,7 @@ class System {
* @param {*} data 操作成功返回的数据
* @param {*} okmsg 操作成功的描述
*/
static getResultSuccess(data, okmsg = "success") {
static getResultSuccess (data, okmsg = "success") {
return {
status: 0,
msg: okmsg,
......@@ -159,7 +160,7 @@ class System {
* @param {*} errmsg 操作失败的描述,默认为fail
* @param {*} data 操作失败返回的数据
*/
static getResultFail(status = -1, errmsg = "fail", data = null) {
static getResultFail (status = -1, errmsg = "fail", data = null) {
return {
status: status,
msg: errmsg,
......@@ -171,14 +172,14 @@ class System {
* @param {*} errmsg 操作失败的描述,默认为fail
* @param {*} data 操作失败返回的数据
*/
static getResultError(errmsg = "fail", data = null) {
static getResultError (errmsg = "fail", data = null) {
return {
status: -200,
msg: errmsg,
data: data,
};
}
static register(key, ClassObj, groupName, filename) {
static register (key, ClassObj, groupName, filename) {
if (System.objTable[key] != null) {
throw new Error("相同key的对象已经存在");
} else {
......@@ -193,7 +194,7 @@ class System {
return System.objTable[key];
}
static getObject(objpath) {
static getObject (objpath) {
var pathArray = objpath.split(".");
var packageName = pathArray[0];
var groupName = pathArray[1];
......@@ -234,7 +235,7 @@ class System {
}
}
static getSysConfig() {
static getSysConfig () {
var configPath = settings.basepath + "/app/base/db/metadata/index.js";
// if(settings.env=="dev"){
// console.log("delete "+configPath+"cache config");
......@@ -244,7 +245,7 @@ class System {
var configValue = require(configPath);
return configValue.config;
}
static get_client_ip(req) {
static get_client_ip (req) {
var ip = req.headers['x-forwarded-for'] ||
req.ip ||
req.connection.remoteAddress ||
......@@ -267,7 +268,7 @@ class System {
* @param {*} resultInfo 返回结果
* @param {*} errorInfo 错误信息
*/
static execLogs(opTitle, params, identifyCode, resultInfo, errorInfo) {
static execLogs (opTitle, params, identifyCode, resultInfo, errorInfo) {
var reqUrl = settings.logUrl();
let isLogData = true
if (params.method && (params.method.indexOf("find") >= 0 || params.method.indexOf("get") >= 0)) {
......@@ -304,7 +305,7 @@ class System {
* 加密信息
* @param {*} opStr
*/
static encryptStr(opStr) {
static encryptStr (opStr) {
if (!opStr) {
return "opStr is empty";
}
......@@ -317,7 +318,7 @@ class System {
* 解密信息
* @param {*} opStr
*/
static decryptStr(opStr) {
static decryptStr (opStr) {
if (!opStr) {
return "opStr is empty";
}
......@@ -388,4 +389,14 @@ module.exports = System;
// }catch(e){
// console.log(e);
// }
// })()
\ No newline at end of file
// })()
// let otherHeaders = {
// xappkey: "647a68c9- da01 - 40d3-9763 - 1ffa0f64cf3f",
// }
// let header = {
// "content-type": "application/json",
// ...otherHeaders
// }
// console.log(JSON.stringify(header))
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