Commit 4f5f1b64 authored by gengshaojing's avatar gengshaojing

fix: 合并hotfix

parents 354158d0 c9861793
This diff is collapsed.
......@@ -16,6 +16,8 @@
<% for (let i in htmlWebpackPlugin.options.cdn && htmlWebpackPlugin.options.cdn.js) { %>
<script src="<%= htmlWebpackPlugin.options.cdn.js[i] %>"></script>
<% } %>
<script src="//webapi.amap.com/maps?v=1.3&key=bb057625545d8cf77df1379e7aaae0b5"></script>
<script src="//webapi.amap.com/ui/1.0/main.js"></script>
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
......
const fs = require("fs");
const API_INTERNAL_URI = require("../config.js").API_INTERNAL_URI;
const reqOther = require("../utils/request").httpReqOther;
const FormData = require("form-data");
const http = require("http");
const GROUPMEAL_URI = require("../config.js").GROUPMEAL_URI;
exports.uploadPic = async (ctx, next) => {
const url = `${API_INTERNAL_URI}/ksy/ks3apiunencrypt/ks3api_upload`;
const {
body: { type },
files,
} = ctx.request;
console.log("type", type);
const filePath = files.file.path;
const file = fs.createReadStream(filePath);
const form = new FormData();
form.append("file", file);
form.append("type", type);
const opts = {
method: "post",
url: url,
body: form,
headers: form.getHeaders(),
};
ctx.body = await reqOther(opts);
};
exports.oldOrderExport = async (ctx) => {
const { marketing_id, type } = ctx.query;
// `${ENV}order/oldbackground/order_export?marketing_id=${eventId}&type=${type}`;
const url = `${GROUPMEAL_URI}/order/oldbackground/order_export?marketing_id=${marketing_id}&type=${type}`;
console.log("url", url);
const options = new URL(url);
let { buffer, res } = await requestPromise(options);
const fileName = res.headers["content-disposition"].split("=")[1];
ctx.set("Content-Type", "application/octet-stream");
ctx.set("Content-Disposition", `attachment; filename=${fileName}`);
ctx.body = buffer;
};
exports.orderExport = async (ctx) => {
const { marketing_id, type } = ctx.query;
const url = `${GROUPMEAL_URI}/order/background/order_export?marketing_id=${marketing_id}&type=${type}`;
console.log("url", url);
const options = new URL(url);
let { buffer, res } = await requestPromise(options);
const fileName = res.headers["content-disposition"].split("=")[1];
ctx.set("Content-Type", "application/octet-stream");
ctx.set("Content-Disposition", `attachment; filename=${fileName}`);
ctx.body = buffer;
};
function requestPromise(options) {
return new Promise(function (resolve, reject) {
const req = http.request(options, function (res) {
let { statusCode } = res;
//返回不是200
if (statusCode !== 200) {
return reject(new Error("error"));
}
let arr = [];
let len = 0;
res.on("data", (chunk) => {
len += chunk.length;
arr.push(Buffer.from(chunk));
});
res.on("end", () => {
//正确 success
return resolve({
buffer: Buffer.concat(arr, len),
res,
});
});
});
//请求出错
req.on("error", (err) => {
return reject(err);
});
req.end();
});
}
......@@ -10,6 +10,7 @@ const activity = require("./controllers/activity");
const withdrawal = require("./controllers/withdrawal");
const groupmeal = require("./controllers/groupmeal");
const qr_code = require("./controllers/qr-code");
const relay = require("./controllers/relay");
const router = Router();
const API_VERSION = "/api/v1";
......@@ -130,4 +131,9 @@ router.post(`${API_VERSION}/get_reblack_list`, withdrawal.getReblackList);
router.get(`${API_VERSION}/get_wallet_account_status`, withdrawal.getWalletAccountStatus);
router.post(`${API_VERSION}/reset_wallet_account_status`, withdrawal.resetAccountStatus);
// 图片上传
router.post(`${API_VERSION}/relay/ks3api_upload`, relay.uploadPic);
router.get(`${API_VERSION}/relay/order_export`, relay.orderExport);
router.get(`${API_VERSION}/relay/old_order_export`, relay.oldOrderExport);
module.exports = router;
const request = require("request");
exports.httpReq = (ctx, opts) => {
opts.timeout = opts.timeout || 10000;
return new Promise((resolve, reject) => {
var time_start = +new Date();
opts.timeout = opts.timeout || 10000;
return new Promise((resolve, reject) => {
var time_start = +new Date();
const defaultQs = {
appid: "merchant-op",
cv: "1.0.0",
version: "999999",
distribution: "op",
net: "wifi",
platform: "2"
};
const defaultQs = {
appid: "merchant-op",
cv: "1.0.0",
version: "999999",
distribution: "op",
net: "wifi",
platform: "2",
};
opts.qs = { ...defaultQs, ...ctx.request.query, ...opts.qs };
opts.qs = { ...defaultQs, ...ctx.request.query, ...opts.qs };
request(opts, (err, res, body) => {
console.info(
`[Api] httpReq (${opts.url}, user:[${
opts.qs.op_cur_user
}]) spent: ${+new Date() - time_start}ms`
);
request(opts, (err, res, body) => {
console.info(`[Api] httpReq (${opts.url}, user:[${opts.qs.op_cur_user}]) spent: ${+new Date() - time_start}ms`);
if (!err) {
resolve(body);
} else {
reject(err);
console.error(opts.url, err);
}
if (!err) {
resolve(body);
} else {
reject(err);
console.error(opts.url, err);
}
});
});
};
exports.httpReqOther = (opts) => {
opts.timeout = opts.timeout || 10000;
return new Promise((resolve, reject) => {
request(opts, (err, res, body) => {
if (!err) {
resolve(body);
} else {
reject(err);
console.error(opts.url, err);
}
});
});
});
};
This diff is collapsed.
This diff is collapsed.
......@@ -112,15 +112,21 @@ export async function orderRefundReject(params) {
// 导出订单
export function getOrderExportURL(eventId, type) {
var ENV;
if (process.env.NODE_ENV == "development") {
ENV = "http://bp-dev.ini.yidian-inc.com/";
} else if (process.env.NODE_ENV == "test") {
ENV = "http://bp-test.ini.yidian-inc.com/";
// var ENV;
// if(process.env.NODE_ENV == "development"){
// ENV = "http://bp-dev.ini.yidian-inc.com/"
// }else if(process.env.NODE_ENV == "test"){
// ENV = "http://bp-test.ini.yidian-inc.com/"
// }else{
// ENV = "http://bp.int.yidian-inc.com/"
// }
// return `${ENV}order/oldbackground/order_export?marketing_id=${eventId}&type=${type}`;
if (process.env.NODE_ENV === "development") {
return `http://127.0.0.1:8055/api/v1/relay/old_order_export?marketing_id=${eventId}&type=${type}`;
} else {
ENV = "http://bp.int.yidian-inc.com/";
return `/api/v1/relay/old_order_export?marketing_id=${eventId}&type=${type}`;
}
return `${ENV}order/oldbackground/order_export?marketing_id=${eventId}&type=${type}`;
}
// 新订单管理
......@@ -191,13 +197,10 @@ export async function newOrderRefundReject(params) {
// 导出订单
export function newGetOrderExportURL(eventId, type) {
var ENV;
if (process.env.NODE_ENV == "development") {
ENV = "http://bp-dev.ini.yidian-inc.com/";
} else if (process.env.NODE_ENV == "test") {
ENV = "http://bp-test.ini.yidian-inc.com/";
if (process.env.NODE_ENV === "development") {
return `http://127.0.0.1:8055/api/v1/relay/order_export?marketing_id=${eventId}&type=${type}`;
} else {
ENV = "http://bp.int.yidian-inc.com/";
return `/api/v1/relay/order_export?marketing_id=${eventId}&type=${type}`;
}
return `${ENV}order/background/order_export?marketing_id=${eventId}&type=${type}`;
// return `/api/v1/relay/order_export?marketing_id=${eventId}&type=${type}`;
}
......@@ -21,49 +21,52 @@ import router from "@/router";
// }
export function redirectToLogin() {
let hasCallback = window.location.href.match(/\?callback/);
if(hasCallback) return;
let isLogin = window.location.pathname.match(/op\/login/);
router.push(`/op/login${!isLogin ? '?callback=' + window.encodeURIComponent(window.location.pathname) : ''}`)
let hasCallback = window.location.href.match(/\?callback/);
if (hasCallback) return;
let isLogin = window.location.pathname.match(/op\/login/);
router.push(`/op/login${!isLogin ? "?callback=" + window.encodeURIComponent(window.location.pathname) : ""}`);
}
export function redirectPage() {
let url = window.location.search.split('?callback=')[1] || window.location.pathname;
router.push(window.decodeURIComponent(url))
let url = window.location.search.split("?callback=")[1] || window.location.pathname;
router.push(window.decodeURIComponent(url));
}
export function isYdUser(email) {
return email.match(/yidian-inc/) || false
return email.match(/yidian-inc/) || false;
}
export function setCookie(name, value) {
var hour = 8;
var exp = new Date();
exp.setTime(exp.getTime() + hour*60*60*1000);
document.cookie = name + "="+ value + ";expires=" + exp.toGMTString()+";path=/";
var hour = 8;
var exp = new Date();
exp.setTime(exp.getTime() + hour * 60 * 60 * 1000);
document.cookie = name + "=" + value + ";expires=" + exp.toGMTString() + ";path=/";
}
//获取cookie
export function getCookie(NameOfCookie) {
if (document.cookie.length > 0) {
let begin = document.cookie.indexOf(NameOfCookie + "=");
if (begin !== -1) {
begin += NameOfCookie.length + 1;
let end = document.cookie.indexOf(";", begin);
if (end === -1) end = document.cookie.length;
return document.cookie.substring(begin, end);
}
}
return null;
if (document.cookie.length > 0) {
let begin = document.cookie.indexOf(NameOfCookie + "=");
if (begin !== -1) {
begin += NameOfCookie.length + 1;
let end = document.cookie.indexOf(";", begin);
if (end === -1) end = document.cookie.length;
return document.cookie.substring(begin, end);
}
}
return null;
}
export function delCookie() {
var keys = document.cookie.match(/[^ =;]+(?==)/g)
if (keys) {
for (var i = keys.length; i--;) {
document.cookie = keys[i] + '=0;path=/;expires=' + new Date(0).toUTCString()
document.cookie = keys[i] + '=0;path=/;domain=' + document.domain + ';expires=' + new Date(0).toUTCString()
document.cookie = keys[i] + '=0;path=/;domain=yidian-inc.com;expires=' + new Date(0).toUTCString()
var keys = document.cookie.match(/[^ =;]+(?==)/g);
if (keys) {
for (var i = keys.length; i--; ) {
document.cookie = keys[i] + "=0;path=/;expires=" + new Date(0).toUTCString();
document.cookie = keys[i] + "=0;path=/;domain=" + document.domain + ";expires=" + new Date(0).toUTCString();
document.cookie = keys[i] + "=0;path=/;domain=yidian-inc.com;expires=" + new Date(0).toUTCString();
}
}
}
}
\ No newline at end of file
}
export const UploadPicUrl =
process.env.NODE_ENV === "development" ? `http://127.0.0.1:8055/api/v1/relay/ks3api_upload` : "/api/v1/relay/ks3api_upload";
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