Commit 46fd01aa by 孙亚楠

d

parent bfab015a
......@@ -28,6 +28,9 @@ class EorderDao extends Dao{
if(params.merchant_id){
sql.push('and merchant_id=:merchant_id');
}
if(params.merchant_name){
sql.push('and merchant_name=:merchant_name');
}
if(params.sign_id){
sql.push('and sign_id=:sign_id');
}
......
......@@ -47,12 +47,43 @@ class EorderauthlogDao extends Dao{
async pageEorderAuthLog(params){
let sql = [];
sql.push('SELECT * FROM e_order_auth_log WHERE 1 = 1 ');
this.setEorderParams(sql,params);
this.setEorderAuthLogParams(sql,params);
sql.push("ORDER BY spended_at DESC");
sql.push("LIMIT :startRow, :pageSize");
let list = await this.customQuery(sql.join(" "), params);
return list ||[];
}
/**
* fn:创建对象
* ps:为了防止 签约日志和身份日志 id 出现重复
* @param u
* @returns {Promise<*>}
*/
async preCreate(u) {
if (!u.id && !u.autoIncrement) {
u.id = await this.redisClient.genrateId(`EorderLog`);
}
return u;
}
async create(u, t) {
var u2 = await this.preCreate(u);
if (t) {
return this.model.create(u2, {
transaction: t
}).then(u => {
return u;
});
} else {
return this.model.create(u2, {
transaction: t
}).then(u => {
return u;
});
}
}
}
module.exports=EorderauthlogDao;
......@@ -52,7 +52,7 @@ class EorderproductDao extends Dao{
async findAllByOrderIdCreatedAsc(params){
let sql = [];
sql.push(`SELECT t1.order_id,t1.product_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.product_id =:product_id`);
sql.push(`and t1.product_id =:product_id and t2.merchant_id=:merchant_id`);
sql.push(`ORDER BY t2.created_at ASC`);
let list = await this.customQuery(sql.join(" "), params);
return list;
......
......@@ -3,6 +3,7 @@ const Dao=require("../../dao.base");
class EordersignlogDao extends Dao{
constructor(){
super(Dao.getModelName(EordersignlogDao));
}
/**
......@@ -44,12 +45,42 @@ class EordersignlogDao extends Dao{
async pageEorderSignLog(params){
let sql = [];
sql.push('SELECT * FROM e_order_sign_log WHERE 1 = 1 ');
this.setEorderParams(sql,params);
this.setEorderSignLogParams(sql,params);
sql.push("ORDER BY spended_at DESC");
sql.push("LIMIT :startRow, :pageSize");
let list = await this.customQuery(sql.join(" "), params);
return list ||[];
}
/**
* fn:创建对象
* ps:为了防止 签约日志和身份日志 id 出现重复
* @param u
* @returns {Promise<*>}
*/
async preCreate(u) {
if (!u.id && !u.autoIncrement) {
u.id = await this.redisClient.genrateId(`EorderLog`);
}
return u;
}
async create(u, t) {
var u2 = await this.preCreate(u);
if (t) {
return this.model.create(u2, {
transaction: t
}).then(u => {
return u;
});
} else {
return this.model.create(u2, {
transaction: t
}).then(u => {
return u;
});
}
}
}
module.exports=EordersignlogDao;
......@@ -5,6 +5,8 @@ class EorderService extends ServiceBase {
constructor() {
super("eorder", ServiceBase.getDaoName(EorderService));
this.eorderproductDao = system.getObject("db.eorder.eorderproductDao");
this.eordersignlogDao = system.getObject("db.eorder.eordersignlogDao");
this.eorderauthlogDao = system.getObject("db.eorder.eorderauthlogDao");
this.GROUP_PRODUCT_TYPE = "2";
this.SIGNLE_PRODUCT_TYPE = "1";
this.AUDIT_STATUS=['10','20','30'];
......@@ -52,7 +54,8 @@ class EorderService extends ServiceBase {
params.product_specifications = Number(params.product_specifications || 0);
params.audit_status="10";
params.live_status="10";
params.pay_status="10";
params.pay_status="20";
params.pay_date=new Date();
console.log(`eorderSve->saveEorder->params` + JSON.stringify(params));
try{
if(params.id){//更新新操作
......@@ -118,7 +121,7 @@ class EorderService extends ServiceBase {
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){
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){
......@@ -157,8 +160,11 @@ class EorderService extends ServiceBase {
if(!orderBean){
return system.getResult(null, `订单【${params.id}】不存在`);
}
if(params.merchant_id && this.trim(params.merchant_id)!=orderBean.merchant_id){
return system.getResult(null, `参数错误 订单【${params.id}】不存在`);
// if(params.merchant_id && this.trim(params.merchant_id)!=orderBean.merchant_id){
// return system.getResult(null, `参数错误 订单【${params.id}】不存在`);
// }
if(orderBean.pay_status!='20'){
return system.getResult(null, `订单【${params.id}】未支付`);
}
try{
......@@ -182,13 +188,13 @@ class EorderService extends ServiceBase {
return system.getResult(null, `参数错误 订单ID 不能为空`);
}
try{
let orderBean = await this.dao.model.findOne(this.trim(params.id));
let orderBean = await this.dao.model.findOne({id:this.trim(params.id)});
if(!orderBean){
return system.getResult(null, `订单【${params.id}】不存在`);
}
if(params.merchant_id && this.trim(params.merchant_id)!=orderBean.merchant_id){
return system.getResult(null, `参数错误 订单【${params.id}】不存在`);
}
// if(params.merchant_id && this.trim(params.merchant_id)!=orderBean.merchant_id){
// return system.getResult(null, `参数错误 订单【${params.id}】不存在`);
// }
//如果支付状态
if (params.pay_status && orderBean.pay_status == '10' && this.PAY_STATUS.includes(this.trim(params.pay_status))) {
orderBean.pay_status = this.trim(params.pay_status);
......@@ -208,7 +214,7 @@ class EorderService extends ServiceBase {
await orderBean.save();
return system.getResult(orderBean);
}
return system.getResult(null, `更新状态异常`);
return system.getResult(null, `更新失败`);
}catch (e) {
console.log(e);
return system.getResult(null, `系统错误`);
......@@ -231,16 +237,46 @@ class EorderService extends ServiceBase {
if(params.merchant_id && this.trim(params.merchant_id)!=orderBean.merchant_id){
return system.getResult(null, `参数错误 订单【${params.id}】不存在`);
}
try{
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','live_start','live_end'], null, null);
orderBean.product_type_name = orderBean.product_type == '1' ? '单产品' : '组合产品';
orderBean.product_specifications_unit = orderBean.product_type == '1' ? '份' : '元';
this.formatStatus(orderBean);
//格式化认证日志
let listEorderAuthLog =await this.eorderauthlogDao.model.findAll({
where:{
order_id:orderBean.id
},
order:[['spended_at','DESC']]
});
for (let itemOfauth of listEorderAuthLog) {
this.handleDate(itemOfauth.dataValues, ['spended_at', 'created_at'],null,null,);
}
orderBean.eorderauthlog = listEorderAuthLog;
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);
//格式化签约日志
let listEorderSignLog = await this.eordersignlogDao.model.findAll({
where:{
order_id:orderBean.id
},
order:[['spended_at','DESC']]
});
for (let itemOfsign of listEorderSignLog) {
this.handleDate(itemOfsign.dataValues, ['spended_at', 'created_at'],null,null,);
}
orderBean.eordersignlog = listEorderSignLog;
return system.getResult(orderBean);
}catch (e) {
console.log(e);
return system.getResult(null, `系统错误`);
}
}
/**
......@@ -259,7 +295,10 @@ class EorderService extends ServiceBase {
}
let list =await this.dao.pageEorder(params);
for (let item of list) {
this.handleDate(item, ['created_at','pay_date','audit_date'], null, null);
this.handleDate(item, ['created_at','pay_date','audit_date','live_start','live_end'], null, null);
item.product_type_name = item.product_type == '1' ? '单产品' : '组合产品';
item.product_specifications_unit = item.product_type == '1' ? `${item.product_unit_price}元/份` : '分开计价';
this.formatStatus(item);
}
let orderIds = [];
for(let ele of list){
......@@ -285,6 +324,53 @@ class EorderService extends ServiceBase {
return system.getResult(null, `系统错误`);
}
}
/**
* fn:格式化订单状态
* @param params
*/
formatStatus(params){
if(!params){return;}
if(params.pay_status){
if(params.pay_status=='10'){
params.pay_status_name='待付款';
}else if(params.pay_status=='20'){
params.pay_status_name='已付款';
}else if(params.pay_status=='30'){
params.pay_status_name='付款失败';
}else{
params.pay_status_name='';
}
}
if(params.audit_status){
if(params.audit_status=='10'){
params.audit_status_name='待审核';
}else if(params.audit_status=='20'){
params.audit_status_name='审核成功';
}else if(params.audit_status=='30'){
params.audit_status_name='审核失败';
}else{
params.audit_status_name='';
}
}
if(params.live_status){
if(params.live_status=='10'){
params.live_status_name='待生效';
}else if(params.live_status=='20'){
params.live_status_name='已生效';
}else if(params.live_status=='30'){
params.live_status_name='已终止';
}else{
params.live_status_name='';
}
}
}
}
module.exports = EorderService;
\ No newline at end of file
......@@ -32,9 +32,9 @@ class EorderauthlogService extends ServiceBase {
params.spended_num = Number(params.spended_num || 0);
params.spended_at = params.spended_at?params.spended_at:new Date();
try{
let orderBean = await this.eorderDao.dao.model.findOne({
let orderBean = await this.eorderDao.model.findOne({
where:{
order_id:this.trim(params.order_id)
id:this.trim(params.order_id)
}
});
if(!orderBean){
......@@ -42,6 +42,7 @@ class EorderauthlogService extends ServiceBase {
}
params.merchant_id = orderBean.merchant_id;
await this.dao.create(params);
return system.getResultSuccess();
}catch (e) {
console.log(e);
return system.getResult(null,`系统错误`);
......@@ -61,14 +62,15 @@ class EorderauthlogService extends ServiceBase {
try{
let countRes = await this.dao.countEorderAuthLog(params);
if(countRes.eorderauthlogCount==0){
return system.getResult({count: 0, row: []});
return system.getResult({count: 0, rows: []});
}
let list =await this.dao.pageEorderAuthLog(params);
if(!list || list.length==0){
return system.getResult({count: 0, row: []});
return system.getResult({count: 0, rows: []});
}
for (let item of list) {
this.handleDate(item,['spended_at','created_at'],null,null)
item.pass_name = item.pass == 0 ? '未通过':'已通过';
}
return system.getResult({count: countRes.eorderauthlogCount, rows: list});
}catch (e) {
......
......@@ -4,7 +4,7 @@ const ServiceBase = require("../../sve.base")
class EorderproductService extends ServiceBase {
constructor() {
super("eorder", ServiceBase.getDaoName(EorderproductService));
// this.accounttradeDao = system.getObject("db.account.accounttradeDao");
this.eorderDao = system.getObject("db.eorder.eorderDao");
}
/**
......@@ -17,7 +17,7 @@ class EorderproductService extends ServiceBase {
if(!params.product_id){
return system.getResult(null, `参数错误 产品ID不能为空`);
}
let list = await this.dao.model.findAllByOrderIdCreatedAsc({product_id:this.trim(params.product_id)});
let list = await this.dao.findAllByOrderIdCreatedAsc({product_id:this.trim(params.product_id),merchant_id:this.trim(params.merchant_id)});
return system.getResult(list || []);
}catch (e) {
console.log(e);
......@@ -31,16 +31,37 @@ class EorderproductService extends ServiceBase {
* @returns {Promise<void>}
*/
async listEorderProductByMerchantId(params){
// if(!params.merchant_id){
// return system.getResult(null, `参数错误 商户ID 不能为空`);
// }
if(!params.merchant_id){
return system.getResult(null, `参数错误 商户ID 不能为空`);
}
let p_list = await this.eorderDao.model.findAll({
where:{
merchant_id: this.trim(params.merchant_id)
},
attributes:['id']
});
let ids =[];
if(!p_list || p_list.length==0){
return system.getResult([]);
}else{
for (let item of p_list) {
ids.push(item.id);
}
}
let list = await this.dao.model.findAll({
where:{
merchant_id: this.trim(params.merchant)
order_id:{
[this.db.Op.in]:ids
}
},
attributes:['product_id']
});
return system.getResult(list);
let productIds=[];
for (let ele of list) {
productIds.push(ele.product_id);
}
return system.getResult(Array.from(new Set(productIds)));
}
}
......
......@@ -35,15 +35,17 @@ class EordersignlogService extends ServiceBase {
return system.getResult(null, `参数错误 平台名称不能为空`);
}
try{
let orderBean = await this.eorderDao.dao.model.findOne({
let orderBean = await this.eorderDao.model.findOne({
where:{
order_id:this.trim(params.order_id)
id:this.trim(params.order_id)
}
});
if(!orderBean){
return system.getResult(null, `订单【${params.order_id}】不存在`);
}
params.merchant_id = orderBean.merchant_id;
await this.dao.create(params);
return system.getResultSuccess();
}catch (e) {
console.log(e);
return system.getResult(null,`系统错误`);
......@@ -63,11 +65,11 @@ class EordersignlogService extends ServiceBase {
try{
let countRes = await this.dao.countEorderSignLog(params);
if(countRes.eordersignlogCount==0){
return system.getResult({count: 0, row: []});
return system.getResult({count: 0, rows: []});
}
let list =await this.dao.pageEorderSignLog(params);
if(!list || list.length==0){
return system.getResult({count: 0, row: []});
return system.getResult({count: 0, rows: []});
}
for (let item of list) {
this.handleDate(item,['spended_at','created_at'],null,null)
......
{
"lockfileVersion": 1
}
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