Commit 8b062132 by 孙亚楠

d

parent 52009e37
...@@ -44,9 +44,24 @@ class ActionAPI extends APIBase { ...@@ -44,9 +44,24 @@ class ActionAPI extends APIBase {
case "getEorderById":// 查看订单 case "getEorderById":// 查看订单
opResult = await this.eorderSve.getEorderById(action_body); opResult = await this.eorderSve.getEorderById(action_body);
break; break;
case "pageEorder":// 查看订单 case "pageEorder":// 查看订单列表(分页)
opResult = await this.eorderSve.pageEorder(action_body); opResult = await this.eorderSve.pageEorder(action_body);
break; break;
case "listEorderProduct":// 查看订单列表
opResult = await this.eorderproductSve.listEorderProduct(action_body);
break;
case "saveEorderAuthLog":// 保存身份认证日志
opResult = await this.eorderauthlogSve.saveEorderAuthLog(action_body);
break;
case "pageEorderAuthLog":// 保存身份认证日志
opResult = await this.eorderauthlogSve.pageEorderAuthLog(action_body);
break;
case "saveEorderSignLog":// 保存签约日志
opResult = await this.eordersignlogSve.saveEorderSignLog(action_body);
break;
case "pageEorderSignLog":// 保存签约日志
opResult = await this.eordersignlogSve.pageEorderSignLog(action_body);
break;
default: default:
opResult = system.getResult(null, "action_type参数错误"); opResult = system.getResult(null, "action_type参数错误");
break; break;
......
...@@ -5,5 +5,88 @@ class EorderDao extends Dao{ ...@@ -5,5 +5,88 @@ class EorderDao extends Dao{
super(Dao.getModelName(EorderDao)); super(Dao.getModelName(EorderDao));
} }
/**
* fn:记录总数
* @param params
* @returns {Promise<void>}
*/
async countEorder(params){
let sql = [];
sql.push('SELECT COUNT(1) AS eorderCount FROM e_order WHERE 1 = 1 ');
this.setEorderParams(sql,params);
let list = await this.customQuery(sql.join(" "), params);
if(!list || list.length==0){
return {count:0};
}
return list[0];
}
setEorderParams(sql,params){
if(params.id){
sql.push('and id=:id');
}
if(params.merchant_id){
sql.push('and merchant_id=:merchant_id');
}
if(params.sign_id){
sql.push('and sign_id=:sign_id');
}
if(params.product_id){
sql.push('and product_id=:product_id');
}
if(params.product_type){
sql.push('and product_type=:product_type');
}
if(params.audit_status){
params.pay_status="20";
sql.push(`and audit_status=:audit_status and pay_status=:pay_status`);
}
if(params.live_status){
params.pay_status="20";
params.audit_status="20";
sql.push('and live_status=:live_status and pay_status=:pay_status and audit_status=:audit_status');
}
if(params.pay_status){
sql.push('and pay_status=:pay_status');
}
if(params.audit_user_id){
sql.push('and audit_user_id=:audit_user_id');
}
if (params.createdBegin) {
sql.push("AND t1.created_at >= :createdBegin");
}
if (params.createdEnd) {
sql.push("AND t1.created_at <= :createdEnd");
}
if (params.payBegin) {
sql.push("AND t1.pay_date >= :payBegin");
}
if (params.payEnd) {
sql.push("AND t1.pay_date <= :payEnd");
}
if (params.auditBegin) {
sql.push("AND t1.audit_date >= :auditBegin");
}
if (params.auditEnd) {
sql.push("AND t1.audit_date <= :auditEnd");
}
}
/**
* fn:订单分页查询
* @param params
* @returns {Promise<void>}
*/
async pageEorder(params){
let sql = [];
sql.push('SELECT * FROM e_order WHERE 1 = 1 ');
this.setEorderParams(sql,params);
sql.push("ORDER BY t1.created_at DESC");
sql.push("LIMIT :startRow, :pageSize");
let list = await this.customQuery(sql.join(" "), params);
return list ||[];
}
} }
module.exports=EorderDao; module.exports=EorderDao;
...@@ -2,8 +2,59 @@ const system=require("../../../system"); ...@@ -2,8 +2,59 @@ const system=require("../../../system");
const Dao=require("../../dao.base"); const Dao=require("../../dao.base");
class EorderproductDao extends Dao{ class EorderproductDao extends Dao{
constructor(){ constructor(){
super(Dao.getModelName(EorderproductDao.js)); super(Dao.getModelName(EorderproductDao));
} }
/**
* fn:根据订单ID查询产品信息
* @param params
* @returns {Promise<void>}
*/
async findAllByOrderId(params){
let sql = [];
sql.push('SELECT * FROM e_order_product WHERE 1 = 1 ');
this.setEorderParams(sql,params);
sql.push(`order by created_at desc`);
let list = await this.customQuery(sql.join(" "), params);
return list || [];
}
setEorderParams(sql,params){
if(params.order_id){
sql.push('and order_id = :order_id');
}
if(params.order_ids || params.order_ids.length!=0){
sql.push('and order_id in (:order_ids)');
}
}
/**
* fn:物理删除订单-产品关系表
* @param params
* @returns {Promise<*>}
*/
async delete(params){
if(!params.order_id){
return ;
}
let sql = [];
sql.push('DELETE FROM e_order_product WHERE 1 = 1 ');
this.setEorderParams(sql,params);
return await this.customQuery(sql.join(" "), params);
}
/**
* fn:根据订单ID查询产品信息(创建时间降序排列)
* @param params
* @returns {Promise<*|*[]>}
*/
async findAllByOrderIdCreatedAsc(params){
let sql = [];
sql.push(`SELECT t1.order_id FROM e_order_product t1 INNER JOIN e_order t2 ON t1.order_id = t2.id where 1=1 and t2.live_status ='20'`);
sql.push(`t1.id =:id`);
sql.push(`ORDER BY t2.created_at ASC`);
let list = await this.customQuery(sql.join(" "), params);
return list;
}
} }
module.exports=EorderproductDao; module.exports=EorderproductDao;
...@@ -18,10 +18,12 @@ module.exports = function (db, DataTypes) { ...@@ -18,10 +18,12 @@ module.exports = function (db, DataTypes) {
live_start: {type: DataTypes.DATE, field: 'live_start', allowNull: true, defaultValue:null, comment:'生效时间' }, live_start: {type: DataTypes.DATE, field: 'live_start', allowNull: true, defaultValue:null, comment:'生效时间' },
live_end: {type: DataTypes.DATE, field: 'live_end', allowNull: true, defaultValue:null, comment:'结束时间' }, live_end: {type: DataTypes.DATE, field: 'live_end', allowNull: true, defaultValue:null, comment:'结束时间' },
audit_status: {type: DataTypes.STRING, field: 'audit_status', allowNull: true, defaultValue:'10', comment:'审核状态10 待审核 20 审核成功 30 审核失败' }, audit_status: {type: DataTypes.STRING, field: 'audit_status', allowNull: true, defaultValue:'10', comment:'审核状态10 待审核 20 审核成功 30 审核失败' },
audit_date: {type: DataTypes.STRING, field: 'audit_date', allowNull: true, defaultValue:null, comment:'审核时间' },
audit_remark: {type: DataTypes.STRING, field: 'audit_remark', allowNull: true, defaultValue:'', comment:'审核备注' }, audit_remark: {type: DataTypes.STRING, field: 'audit_remark', allowNull: true, defaultValue:'', comment:'审核备注' },
audit_user_id: {type: DataTypes.STRING, field: 'audit_user_id', allowNull: true, defaultValue:'', comment:'审核人' }, audit_user_id: {type: DataTypes.STRING, field: 'audit_user_id', allowNull: true, defaultValue:'', comment:'审核人' },
live_status: {type: DataTypes.STRING, field: 'live_status', allowNull: true, defaultValue:'10', comment:'生效状态10 待生效 20 已生效 30 已终止' }, live_status: {type: DataTypes.STRING, field: 'live_status', allowNull: true, defaultValue:'10', comment:'生效状态10 待生效 20 已生效 30 已终止' },
pay_status: {type: DataTypes.STRING, field: 'pay_status', allowNull: true, defaultValue:'10', comment:'支付状态10 待支付 20 已支付 30 支付失败' }, pay_status: {type: DataTypes.STRING, field: 'pay_status', allowNull: true, defaultValue:'10', comment:'支付状态10 待支付 20 已支付 30 支付失败' },
pay_date: {type: DataTypes.DATE, field: 'pay_date', allowNull: true, defaultValue:null, comment:'支付时间' },
engine_account_id: {type: DataTypes.STRING, field: 'engine_account_id', allowNull: true, defaultValue:'', comment:'计费引擎账户id' }, engine_account_id: {type: DataTypes.STRING, field: 'engine_account_id', allowNull: true, defaultValue:'', comment:'计费引擎账户id' },
created_at: { type: DataTypes.DATE, field: 'created_at', allowNull: false}, created_at: { type: DataTypes.DATE, field: 'created_at', allowNull: false},
updated_at: { type: DataTypes.DATE, field: 'updated_at', allowNull: false}, updated_at: { type: DataTypes.DATE, field: 'updated_at', allowNull: false},
......
...@@ -4,7 +4,9 @@ const ServiceBase = require("../../sve.base") ...@@ -4,7 +4,9 @@ const ServiceBase = require("../../sve.base")
class EorderSve extends ServiceBase { class EorderSve extends ServiceBase {
constructor() { constructor() {
super("eorder", ServiceBase.getDaoName(EorderSve)); super("eorder", ServiceBase.getDaoName(EorderSve));
this.eorderprodcutDao = system.getObject("db.eorder.eorderprodcutDao"); this.eorderproductDao = system.getObject("db.eorder.eorderproductDao");
this.GROUP_PRODUCT_TYPE = "2";
this.AUDIT_STATUS=['10','20','30']
} }
/** /**
...@@ -13,7 +15,113 @@ class EorderSve extends ServiceBase { ...@@ -13,7 +15,113 @@ class EorderSve extends ServiceBase {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async saveEorder(params){ async saveEorder(params){
if(!params.merchant_id){
return system.getResult(null, `参数错误 商户ID不能为空`);
}
if(!params.sign_id){
return system.getResult(null, `参数错误 签署ID不能为空`);
}
if((!params.product_ids || params.product_ids.length==0) && !params.product_id ){
return system.getResult(null, `参数错误 产品ID列表不能为空`);
}
if(!params.product_id ){
return system.getResult(null, `参数错误 父产品ID列表不能为空`);
}
if(!params.product_type){
return system.getResult(null, `参数错误 未知的产品类型`);
}
if(params.product_type==this.GROUP_PRODUCT_TYPE && !params.product_unit_price){
return system.getResult(null, `参数错误 商品单价不能为空`);
}
if(!params.contract_url){
return system.getResult(null, `参数错误 业务合同不能为空`);
}
if(!params.live_start){
return system.getResult(null, `参数错误 生效时间不能为空`);
}
if(!params.live_end){
return system.getResult(null, `参数错误 结束时间不能为空`);
}
params.product_specifications = Number(params.product_specifications || 0);
params.audit_status="10";
params.live_status="10";
params.pay_status="10";
console.log(`eorderSve->saveEorder->params` + JSON.stringify(params));
try{
if(params.id){//更新新操作
let _orderBean = await this.dao.model.findOne(this.trim(params.id));
if(!_orderBean){
return system.getResult(null, `订单【${params.id}】不存在`);
}
let _orderBeanProperties={id:_orderBean.id};
_orderBeanProperties.merchant_id = params.merchant_id ? params.merchant_id : _orderBean.merchant_id;
_orderBeanProperties.sign_id = params.sign_id ? params.sign_id : _orderBean.sign_id;
_orderBeanProperties.sign_name = params.sign_name ? params.sign_name : _orderBean.sign_name;
_orderBeanProperties.product_id = params.product_id ? params.product_id : _orderBean.product_id;
_orderBeanProperties.product_type = params.product_type ? params.product_type : _orderBean.product_type;
_orderBeanProperties.product_unit_price = params.product_unit_price ? params.product_unit_price : _orderBean.product_unit_price;
_orderBeanProperties.product_desc = params.product_desc ? params.product_desc : _orderBean.product_desc;
if(params.hasOwnProperty('price')){
_orderBeanProperties.price = Number(params.price || 0);
}
if(params.hasOwnProperty('product_specifications')){
_orderBeanProperties.product_specifications = Number(params.product_specifications || 0);
}
_orderBeanProperties.contract_url = params.contract_url ? params.contract_url : _orderBean.contract_url;
_orderBeanProperties.live_start = params.live_start ? params.live_start : _orderBean.live_start;
_orderBeanProperties.live_end = params.live_end ? params.live_end : _orderBean.live_end;
_orderBeanProperties.audit_status = params.audit_status ? params.audit_status : _orderBean.audit_status;
_orderBeanProperties.audit_date = params.audit_date ? params.audit_date : _orderBean.audit_date;
_orderBeanProperties.audit_remark = params.audit_remark ? params.audit_remark : _orderBean.audit_remark;
_orderBeanProperties.audit_user_id = params.audit_user_id ? params.audit_user_id : _orderBean.audit_user_id;
_orderBeanProperties.live_status = params.live_status ? params.live_status : _orderBean.live_status;
_orderBeanProperties.pay_status = params.pay_status ? params.pay_status : _orderBean.pay_status;
_orderBeanProperties.pay_date = params.pay_date ? params.pay_date : _orderBean.pay_date;
_orderBeanProperties.engine_account_id = params.engine_account_id ? params.engine_account_id : _orderBean.engine_account_id;
console.log(`eorderSve->saveEorder->_orderBeanProperties`+JSON.stringify(_orderBeanProperties));
await this.db.transaction(async t=>{
await this.dao.update(_orderBeanProperties, t);
//首先删除 eorderproduct 表中所用指定order_id的所有记录
let deleteRows = await this.eorderproductDao.delete({order_id:_orderBean.id});
if(deleteRows==0){
throw new Error("更新订单失败");
return system.getResult(null,`系统错误 更新订单商品失败`);
}
if(params.product_ids || params.product_ids.length>0){
let ids = Array.from(new Set(params.product_ids));
let eorderProductProperties = [];
for(let item of ids){
eorderProductProperties.push({order_id:orderBean.id,product_id:item});
}
await this.eorderproductDao.model.bulkCreate(eorderProductProperties,t);
}else{
await this.eorderproductDao.create({order_id: _orderBean.id, product_id: this.trim(params.product_id)},t);
}
});
return system.getResult(orderBean);
}else{ //新增操作
let orderBean =null;
await this.db.transaction(async t => {
orderBean=await this.dao.create(params,t);
if(params.product_ids || params.product_ids.length>0){
let ids = Array.from(new Set(params.product_ids));
let eorderProductProperties = [];
for(let item of ids){
eorderProductProperties.push({order_id:orderBean.id,product_id:item});
}
await this.eorderproductDao.model.bulkCreate(eorderProductProperties,t);
}else{
await this.eorderproductDao.create({order_id: orderBean.id, product_id: this.trim(params.product_id)},t);
}
});
return system.getResult(orderBean);
}
}catch (e) {
console.log(e);
return system.getResult(null,`系统错误`);
}
} }
/** /**
...@@ -22,7 +130,27 @@ class EorderSve extends ServiceBase { ...@@ -22,7 +130,27 @@ class EorderSve extends ServiceBase {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async auditEorder(params){ async auditEorder(params){
if(!params.audit_status || !this.AUDIT_STATUS.includes(params.audit_status)){
return system.getResult(null,`参数错误 审核状态错误`);
}
if(params.audit_status=="30" && !params.audit_remark){
return system.getResult(null,`参数错误 审核备注不能为空`);
}
if(!params.id){
return system.getResult(null,`参数错误 订单ID不能为空`);
}
let orderBean = await this.dao.getById(this.trim(params.id));
if(!orderBean){
return system.getResult(null, `订单不存在`);
}
try{
await orderBean.dao.update({id:orderBean.id,audit_status:this.trim(params.audit_status),audit_remark:this.trim(params.audit_remark) || ""});
return system.getResultSuccess();
}catch (e) {
console.log(e);
return system.getResult(null, `系统错误`);
}
} }
/** /**
...@@ -31,7 +159,22 @@ class EorderSve extends ServiceBase { ...@@ -31,7 +159,22 @@ class EorderSve extends ServiceBase {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async getEorderById(params){ async getEorderById(params){
if(!params.id){
return system.getResult(null,`参数错误 订单ID不能为空`);
}
let orderBean = await this.dao.getById(this.trim(params.id));
if(!orderBean){
return system.getResult(null, `订单不存在`);
}
let productIds = await this.eorderproductDao.model.findAll({
where:{
order_id:orderBean.id
},
attributes:['product_id']
});
orderBean.productIds = productIds;
this.handleDate(orderBean, ['created_at','pay_date','audit_date'], null, null);
return system.getResult(orderBean);
} }
/** /**
...@@ -40,9 +183,42 @@ class EorderSve extends ServiceBase { ...@@ -40,9 +183,42 @@ class EorderSve extends ServiceBase {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async pageEorder(params){ async pageEorder(params){
params.currentPage = Number(params.currentPage || 1);
params.pageSize = Number(params.pageSize || 10);
params.startRow = (params.currentPage - 1) * params.pageSize;
try{
let countRes = await this.dao.countEorder(params);
if(countRes.eorderCount==0){
return system.getResult({count: 0, row: []});
}
let list =await this.dao.pageEorder(params);
for (let item of list) {
this.handleDate(item, ['created_at','pay_date','audit_date'], null, null);
}
let orderIds = [];
for(let ele of list){
orderIds.push(ele.id);
}
let eorderProductList = await this.eorderproductDao.findAllByOrderId(orderIds);
if(!eorderProductList || eorderProductList.length==0){
return system.getResult(null, `系统错误 订单子产品不存在`);
}
let orderProductMap = {};
for (let childPro of eorderProductList) {
if(!orderProductMap[childPro.order_id]){
orderProductMap[childPro.order_id] = [];
}
orderProductMap[childPro.order_id].push(childPro.product_id);
}
for(let element of list){
element.eorderproduct = orderProductMap[element.id] || [];
}
return system.getResult({count: countRes.eorderCount, rows: list});
}catch (e) {
console.log(e);
return system.getResult(null, `系统错误`);
}
} }
} }
module.exports = EorderSve; module.exports = EorderSve;
\ No newline at end of file
...@@ -4,9 +4,56 @@ const ServiceBase = require("../../sve.base") ...@@ -4,9 +4,56 @@ const ServiceBase = require("../../sve.base")
class EorderauthlogSve extends ServiceBase { class EorderauthlogSve extends ServiceBase {
constructor() { constructor() {
super("eorderauthlogSve", ServiceBase.getDaoName(EorderauthlogSve)); super("eorderauthlogSve", ServiceBase.getDaoName(EorderauthlogSve));
// this.accounttradeDao = system.getObject("db.account.accounttradeDao"); this.eorderDao = system.getObject("db.eorder.eorderDao");
} }
/**
* fn:保存身份验证日志
* @param params
* @returns {Promise<void>}
*/
async saveEorderAuthLog(params) {
if(!params.order_id){
return system.getResult(null, `参数错误 订单ID不能为空`);
}
if(!params.product_id){
return system.getResult(null, `参数错误 订单ID不能为空`);
}
if(!params.user_name){
return system.getResult(null, `参数错误 使用方不能为空`);
}
if(!params.actual_spend_name){
return system.getResult(null, `参数错误 实际使用方不能为空`);
}
params.spended_num = Number(params.spended_num || 0);
try{
let orderBean = await this.eorderDao.dao.model.findOne({
where:{
order_id:this.trim(params.order_id)
}
});
if(!orderBean){
return system.getResult(null, `订单【${params.order_id}】不存在`);
}
await this.dao.create(params);
}catch (e) {
console.log(e);
return system.getResult(null,`系统错误`);
}
}
/**
* fn:身份验证日志列表
* @param params
* @returns {Promise<void>}
*/
async pageEorderAuthLog(params){
}
} }
module.exports = EorderauthlogSve; module.exports = EorderauthlogSve;
\ No newline at end of file
...@@ -7,6 +7,24 @@ class EorderproductSve extends ServiceBase { ...@@ -7,6 +7,24 @@ class EorderproductSve extends ServiceBase {
// this.accounttradeDao = system.getObject("db.account.accounttradeDao"); // this.accounttradeDao = system.getObject("db.account.accounttradeDao");
} }
/**
* fn:根据产品ID查询(根据订单创建时间升序派)
* @param params
* @returns {Promise<void>}
*/
async listEorderProduct(params){
try{
if(!params.id){
return system.getResult(null, `参数错误 产品ID不能为空`);
}
let list = await this.dao.model.findAllByOrderIdCreatedAsc({id:this.trim(params.id)});
return system.getResult(list || []);
}catch (e) {
console.log(e);
return system.getResult(null,`系统错误`);
}
}
} }
module.exports = EorderproductSve; module.exports = EorderproductSve;
\ No newline at end of file
...@@ -7,6 +7,24 @@ class EordersignlogSve extends ServiceBase { ...@@ -7,6 +7,24 @@ class EordersignlogSve extends ServiceBase {
// this.accounttradeDao = system.getObject("db.account.accounttradeDao"); // this.accounttradeDao = system.getObject("db.account.accounttradeDao");
} }
/**
* fn:保存签约证日志
* @param params
* @returns {Promise<void>}
*/
async saveEorderSignLog(params) {
}
/**
* fn:签约日志列表
* @param params
* @returns {Promise<void>}
*/
async pageEorderSignLog(params){
}
} }
module.exports = EordersignlogSve; module.exports = EordersignlogSve;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment