Commit e133ce59 authored by 李尚科's avatar 李尚科

fix

parent 6d45b0f3
Pipeline #13685 passed with stage
in 26 seconds
......@@ -4,7 +4,14 @@
const Service = require('egg').Service;
const moment = require('moment');
const _ = require('lodash');
const TypeConfig = {
blacklist: 1,
callrisk: 2
}
const TypeConfigFlip = {
1: 'blacklist',
2: 'callrisk',
}
class OrderService extends Service {
//历史订单
......@@ -17,12 +24,7 @@ class OrderService extends Service {
const app_user_id = ctx.appUserId;
const app_id = ctx.appId;
const type_obj = {
'blacklist': 1,
'callrisk': 2,
}
const type = type_obj[order_type];
const type = TypeConfig[order_type];
// const where = { user_id };
const order_records = await ctx.prometheusModel.CreditOrder.all({ where: { user_id, type, valid: 1 } });
const worth_h = [];
......@@ -30,18 +32,18 @@ class OrderService extends Service {
for (let i in order_records) {
const order = await this.updateOrderState(order_records[i]);
const order = await this.updateOrderStateToOverdue(order_records[i]);
if (order.state === '已失效') continue;
const is_expire = await this.checkOrderExpire(order);
const apply = { phone: '15968762898', report_no: '51gjj201909050100001' };//TODO query apply
// const apply = { phone: '15968762898', report_no: '51gjj201909050100001' };//TODO query apply
const item = {
order_id: order.id,
order_no: order.order_no,
report_id: apply.report_id,
type: order_type,
created_time: order.created_at,
phone: apply.phone.replace(apply.phone.substring(3, 7), "****"),
phone: order.phone.replace(order.phone.substring(3, 7), "****"),
state: order.state,
state_text: order.state === '已支付' ? '' : order.state,
};
......@@ -56,7 +58,7 @@ class OrderService extends Service {
}
//更新订单状态
async updateOrderState(order) {
async updateOrderStateToOverdue(order) {
const { ctx } = this;
const { id, created_at, state, pay_status } = order;
......@@ -68,7 +70,7 @@ class OrderService extends Service {
const state_time = moment().format('YYYY-MM-DD HH:mm:ss');
if (expire_time < now_time && (state === '待支付' || state === '已取消') && pay_status === 0) {
const ret = await ctx.prometheusModel.CreditOrder.update({ state: '已失效', state_time: state_time }, { where: { id } });
if (ret || ret[0]) {
if (ret && ret[0]) {
order.state = '已失效';
order.state_time = state_time;
}
......@@ -77,27 +79,44 @@ class OrderService extends Service {
}
async updateOrderPrice(order_id) {
//将订单更新为已取消
async updateOrderStateToCancel(order) {
const { ctx } = this;
const user_id = ctx.userId;
const order = await ctx.service.credit.common.getOrderInfo(order_id);
if (!order || !order.id) {
ctx.failed('error order');
const { id, phone, name, id_card } = order;
let status = false;
if (!id || !phone || !name || !id_card) {
return status;
}
const type_obj = {
1: 'blacklistk',
2: 'callrisk',
const state_time = moment().format('YYYY-MM-DD HH:mm:ss');
const where = { user_id, name, id_card, id: { $ne: id } };
const ret = await ctx.prometheusModel.CreditOrder.update({ state: '已取消', state_time: state_time }, { where });
if (ret && ret[0]) {
status = true;
}
const type = type_obj[order.type];
const preferential = await this.getPreferential(type);
return status;
}
async updateOrderPrice(order) {
const { ctx } = this;
const user_id = ctx.userId;
// const order = await ctx.service.credit.common.getOrderInfo(order_id);
const { id, type, } = order;
if (!id || !type) {
ctx.failed('error order');
}
const slag = TypeConfigFlip[type];
const preferential = await this.getPreferential(slag);
let preferential_price = 0;
if (preferential && preferential.id) {
preferential_price = preferential.price;
}
const price = order.price - preferential_price;
await ctx.prometheusModel.CreditOrder.update({ price, preferential_price, preferential_id: preferential.id }, { where: { id: order.id } });
await ctx.prometheusModel.CreditOrder.update({ price, preferential_price, preferential_id: preferential.id }, { where: { id, pay_status: 0 } });
return true;
......@@ -179,10 +198,6 @@ class OrderService extends Service {
await ctx.prometheusModel.CreditOrder.update({ price, preferential_price, preferential_id: preferential.id }, { where: { id: order.id, pay_status: 0 } });
const type_obj = {
1: 'blacklist',
2: 'callrisk',
}
const type = order.type;
const countdown = moment(order.state_time).format('X') + 86400 - moment().format('X');
const ret = {
......@@ -192,7 +207,7 @@ class OrderService extends Service {
preferential_price,
preferential_title,
order_no: order.order_no,
type: type_obj[type],
type: TypeConfigFlip[type],
type_title: type === 1 ? '黑名单检测' : '个人通话风险检测',
notice: type === 1 ? '温馨提示:15天内无需重复付费查询' : '温馨提示:30天内无需重复付费查询',
countdown,
......@@ -297,7 +312,7 @@ class OrderService extends Service {
order_id,
trade_no: moment().valueOf() + ctx.helper.PrefixInteger(order_id, 11),
total_fee: price,
notify_url: 'https://dev-nginx.jianbing.com/51business/api/credit/order/pay_notice',
notify_url: `${this.config.OUT_P_NODE_URL}/51business/api/credit/order/pay_notice`,
product_id: order.order_no,
scene_info: JSON.stringify({ h5_info: { type: 'Wap', wap_url: this.config.PHP_URL, wap_name: '我的信用' }, }),
};
......@@ -309,12 +324,13 @@ class OrderService extends Service {
trade_no: data.trade_no,
description: data.body,
prepay_id: ret.prepay_id || 0,
amount: data.total_fee,
amount: data.total_fee / 100,
unifiedorder_result: JSON.stringify(ret),
client_ip: ctx.helper.getClientIP(),
};
await this.addCreditPay(pay_data);
await this.updateOrderStateToCancel(order);
await this.updateOrderPrice(order);
return { url: ret.mweb_url, order_id: order_id, trade_no: data.trade_no };
} else if (type === 'alipay') {
......@@ -410,7 +426,7 @@ class OrderService extends Service {
let historyFilter = {
where: {
user_id: ctx.userId,
type: type === 1 ? 2 : 1,
type: TypeConfig[type],
valid: 1,
state: '已支付',
state_time: { $gte: moment().subtract(3, 'days').format('YYYY-MM-DD HH:mm:ss') }
......@@ -422,7 +438,7 @@ class OrderService extends Service {
let preFilter = {
where: {
alias: 'limit',
type: type,
type: TypeConfig[type],
valid: 1,
},
order: [['id', 'desc']]
......
......@@ -131,6 +131,8 @@ module.exports = appInfo => {
config.BLACKLIST_APPLY_APPSECRET = '233B8E10E31B4C899EE6FEB3AEC22F140B6528BF';
config.BLACKLIST_APPLY_URL = 'http://47.96.253.64:8049/mycredit/blackList';
config.OUT_P_NODE_URL = 'https://dev-nginx.jianbing.com';
//数盒魔方
config.SHUHEMOFANG_APP_KEY = 'BdNFbog6';
config.SHUHEMOFANG_APP_SECRET = 'a695e9b3c0f1e3f15fb0b958fd3a4b67';
......
......@@ -122,6 +122,8 @@ module.exports = appInfo => {
config.MCH_ID = process.env.MCH_ID;//商户id
config.MCH_KEY = process.env.MCH_KEY;//商户秘钥
config.OUT_P_NODE_URL = process.env.OUT_P_NODE_URL
//数盒魔方
config.SHUHEMOFANG_APP_KEY = process.env.SHUHEMOFANG_APP_KEY;
config.SHUHEMOFANG_APP_SECRET = process.env.SHUHEMOFANG_APP_SECRET;
......
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