Commit 493d83c6 authored by 李尚科's avatar 李尚科

fix

parent 7acedd53
Pipeline #13750 passed with stage
in 6 seconds
......@@ -57,7 +57,7 @@ class OrderController extends Controller {
ctx.logger.info({ notice_params: ret_obj });
const ret = await ctx.service.credit.common.WexinNotify(ret_obj);
if (ret) {
ctx.success("<xml><return_code>SUCCESS</return_code><return_msg>OK</return_msg></xml>");
ctx.success("<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>");
return;
}
ctx.success("<xml><return_code>FAIL</return_code><return_msg>UNKONW</return_msg></xml>");
......
......@@ -141,27 +141,21 @@ class CommonService extends Service {
if (!transaction_id && !trade_no) {
return false;
}
const pay_info = await ctx.prometheusModel.CreditPay.one({ where: { trade_no } });
if (!pay_info || !pay_info.order_id) {
ctx.failed('pay info error');
}
const order_info = await ctx.service.credit.order.getOrderInfo(pay_info.order_id);
// const order_info = await ctx.service.credit.order.getOrderInfo(pay_info.order_id);
const nonce_str = ctx.helper.createNoncestr();
const url = 'https://api.mch.weixin.qq.com/pay/orderquery';
let data_obj = {
appid: this.config.MCH_APPID,
mch_id: this.config.MCH_ID,
transaction_id,
out_trade_no: trade_no,
nonce_str,
}
if (transaction_id) data_obj.transaction_id = transaction_id;
if (trade_no) data_obj.out_trade_no = trade_no;
const sign = this.getWexinSign(data_obj);
data_obj.sign = sign;
const xml_data = ctx.helper.jsonToxml(data_obj);
const result_wexin = await ctx.curl(url, { timeout: 3000, method: 'POST', data: xml_data, headers: { 'content-type': 'text/html', }, streaming: false, dataType: 'text', });
ctx.logger.info(JSON.stringify({ query_wexinpay_param: data_obj, query_wexinpay_result: result_wexin.data }));
if (result_wexin.status !== 200) {
ctx.failed('wexin orderquery error1');
}
......@@ -170,23 +164,18 @@ class CommonService extends Service {
for (let key in ret) {
ret_data[key] = ret[key][0];
}
ctx.logger.info(JSON.stringify({ query_wexinpay_param: params, query_wexinpay_result: ret_data }));
// ctx.logger.info(JSON.stringify({ query_wexinpay_param: params, query_wexinpay_result: ret_data }));
let error_msg = 'wexin orderquery error2';
if (ret_data.return_code !== 'SUCCESS' && ret_data.result_code !== 'SUCCESS') {
error_msg = ret_data.return_msg ? ret_data.return_msg : error_msg;
ctx.failed(error_msg);
}
if (ret_data.trade_state === 'SUCCESS') {
return false;
}
const price = order_info.price * 100 - order_info.preferential_price * 100;
if (price != ret_data.cash_fee) {
if (ret_data.trade_state !== 'SUCCESS') {
return false;
}
await ctx.prometheusModel.CreditPay.edit({ where: { id: pay_info.id }, params: { pay_result: JSON.stringify(ret_data), status: 1 } });
return true;
return { total_fee: ret_data.cash_fee, ret_data };
}
......
......@@ -240,13 +240,16 @@ class OrderService extends Service {
if (order && order.pay_status === 1) {
return true;
}
const credit_pay = await ctx.prometheusModel.CreditPay.one({ where: { order_id }, order: [['id', 'desc']] });
const credit_pay = await ctx.prometheusModel.CreditPay.findOne({ where: { order_id }, order: [['id', 'desc']] });
if (!credit_pay || !credit_pay.id) {
ctx.failed('error credit pay');
}
const { transaction_id, trade_no } = credit_pay;
const wexin_check_pay_ret = await ctx.service.credit.common.WexinCheckPay({ transaction_id, trade_no });
if (wexin_check_pay_ret) {
const price = ((order.price - order.preferential_price) * 100).toFixed();
if (price === wexin_check_pay_ret.total_fee) {
await ctx.prometheusModel.CreditPay.edit({ where: { id: credit_pay.id }, params: { pay_result: JSON.stringify(wexin_check_pay_ret), status: 1 } });
const state_time = moment().format('YYYY-MM-DD HH:mm:ss');
await ctx.prometheusModel.CreditOrder.update({ state: '已支付', state_time, pay_status: 1 }, { where: { id: order.id, pay_status: 0 } })
return true;
......
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