Authored by weiqingting

tianjia

module.exports=function(app) {
app.get("/login","common.Login");
app.get("/logout","common.Login",function (req) {
delete req.session.user;
});
app.post("/login", "common_login", function (login, req, res){
if (login.code == 200) {
res.myRedirect('/');
} else {
res.myRedirect('/login');
}
});
app.get("/","common.index");
app.get("/error", "common.Error");
app.get("/index/ajaxshop","common_changeShop");
}
... ...
module.exports=function(app) {
//查询通过审核店铺列表接口
app.post("/ShopsRest/selectCheckPassShopsByName","select_selectCheckPassShopsByName");
//查询店铺下关联品牌
app.post("/MerchantShopsRest/queryMerchantBrandByShopsId","select_queryMerchantBrandByShopsId");
//获取JIT店铺
app.post("/AgreementRest/getJitSupplierByBrandId","select_getJitSupplierByBrandId");
//尺码
app.post("/product/querySizeListBySortId4Html","select_querySizeListBySortId4Html");
//店铺列表
app.post("/ShopsRest/selectCheckPassShopsByName","select_selectCheckPassShopsByName");
//查询店铺下关联供应商
app.post("/MerchantShopsRest/queryMerchantSupplierByShopsId","select_queryMerchantSupplierByShopsId");
//根据品牌获取供应商
app.post("/ShopsRest/queryShopsByBrandId", "select_queryShopsByBrandId");
app.post("/product/queryMaxSortByName","select_queryMaxSortByName");
/*类目 已经集成到控件里面去了注意*/
app.post("/product/class/queryAllProductSortList","select_queryAllMaxSortList");
app.post("/product/class/queryProductSortList","select_queryProductSortList");
}
\ No newline at end of file
... ...
module.exports=function(app) {
app.get("/ajax/link/:name","common_downExcel");
app.get("/ajax/down","common_exportExcel");
app.post("/ajax/upload","common_multipart");
app.post("/ajax/ueditor","common_baiduUeditor");
app.post("/ajax/proxy","common_proxy");
app.get("/ajax/download","common_download")
}
... ...
var request = require('request');
var _ = require('lodash');
var fs = require('fs');
var Iaccount = global.Register.system;
var Utils = {
createrMenus: function (data) {
var menu = [];
for (var key in data) {
var v = data[key];
var item = {
title: v.menu_name,
}
if (v.parent_id === "0") {
item.parent = 'menu-template';
var itemSubs = [];
_.forEach(v.sub, function (val) {
var sub = {
title: val.menu_name,
href: val.menu_url,
icon: 'list-alt'
}
itemSubs.push(sub);
});
item.menu = itemSubs;
}
menu.push(item);
}
return menu;
}
}
module.exports = {
namespace: "common",
apis: {
Ilogin: {
title:'登录接口',
url: Iaccount.login,
form: '["{{user}}","{{password}}",{{website}}]',
params: {
user: { type: String },
password: { type: String },
website: {type:Number,default: Iaccount.WEBSITE}
}
},
getResourceByPid: {
title:'菜单接口',
url: Iaccount.getResourceByPid,
form: '[{{pid}},{{role_id}},{{website}}]',
params: {
pid: { type: Number },
role_id: { type: Number },
website: { type: Number, default: Iaccount.WEBSITE }
}
},
allRight: {
title: '获取权限',
url: Iaccount.allRight,
form: '[false]'
},
getShopList: {
title:'获取当前用户所有店铺',
url: Iaccount.getShopList,
form:true,
headers: {
"x-user-id": {type:Number}
}
},
sessionAsync: {
title:'与老系统session同步',
url: Iaccount.url + '/login/sessions',
outobj: "response",
form: {'account':'{{user}}','password':'{{password}}','refer': '%2Faccount%2Fprofile%2Fdisplay'},
params: {
user: { type: String },
password: { type: String }
}
},
login: function (req, callback, common) {
var userInfo = {},result = { code: 400, message: "登录失败" },isSuccess=false;
var user = req.body.user;
var password = req.body.password;
var errcallback = function (err) {
return callback(null, result);
}
common.Ilogin(user, password).allRight().sessionAsync(user, password).done(function (IloginRes,allRes,sesRes) {
var userData = IloginRes.data, cookie = sesRes.caseless.dict["set-cookie"];
userInfo = { auth: userData, uid: userData.pid, name: userData.truename, right: {},shopList:[]};
allRes.data.forEach(function (data) {
if (data.platform_id == Iaccount.WEBSITE) {
userInfo.right[data.path] = true;
}
});
common.getResourceByPid(userData.pid, userData.role_id)
.getShopList({ "@x-user-id": userInfo.uid }).done(function (getRRes, shopRes) {
userInfo.menu = Utils.createrMenus(getRRes.data);
if (shopRes.data) {
shopRes.data.forEach(function (data, index) {
if (!index) {
userInfo.auth.shopName = data.shopName;
userInfo.auth.shopId = data.shopsId;
}
userInfo.shopList.push({
name: data.shopName,
id: data.shopsId
});
});
req.session.user = userInfo;
if (cookie && cookie.length > 0) {
req.session.gray = cookie[0];
result = { code: 200, message: "登录成功" };
}
console.log(result);
} else {
result = { code: 400, message: "该用户没有店铺" };
}
return callback(null, result);
},errcallback);
}, errcallback);
},
isUsedMenuAuth:{
title:'检查有没有权限',
url:Iaccount.isUsedMenuAuth,
form:'[{{pid}},{{role_id}},"{{path}}","","",' + Iaccount.WEBSITE + ']',
params:{
pid:{type:Number},
role_id:{type:Number},
path:{type:String}
}
},
gray: function (req, callback,common) {
var result = { code: 201, message: "没有权限" };
if (req.session && req.session.user) {
var user = req.session.user;
var path = req.route?req.route.path[0]:req.originalUrl.replace(/\?.+/, '');
req._yoheaders = {
'x-user-id': user.auth.pid,
'x-user-name': user.auth.account,
'x-site-type': Iaccount.WEBSITE,
'x-client-ip': req.ip,
'x-shop-id': user.auth.shopId
};
if (path && user.right[path]) {
common.isUsedMenuAuth(user.auth.pid,user.auth.role_id,path).done(function(isURes){
result = { code: 200, message: "具有权限" };
return callback(null, result);
},function(error){
return callback(error, result);
});
} else {
result = { code: 200, message: "不受权限控制" };
return callback(null, result);
}
} else {
return callback(null, result);
}
},
IchangeShops:{
title:'调用老系统的切换店铺的接口',
url: Iaccount.changeShops + '?shops_id={{shops_id}}',
method:'GET',
outobj:'response',
headers: {
cookie: { type: String }
},
params: {
shops_id: { type: Number },
'@cookie': {type:String}
}
},
changeShop: function (req, callback,common) {
var shopId = Number(req.query.shops_id);
var cookie = req.session.gray;
var result = { code: 500, message: "something wrong!" };
//设置当前的店铺信息
if (req.session.user && req.session.user.auth) {
_.forEach(req.session.user.shopList, function (v, k) {
if (v.id === shopId) {
req.session.user.auth.shopName = v.name;
req.session.user.auth.shopId = shopId;
};
});
}
common.IchangeShops(shopId,cookie).done(function(IchRes){
if(IchRes.statusCode == 200){
result = { code: 200, message: "success" };
return callback(null, result);
}else{
return callback(null, result);
}
});
}
}
}
\ No newline at end of file
... ...
module.exports={
namespace:"select",
apis:{
selectCheckPassShopsByName:{
title:"查询通过审核店铺列表接口",
url:"/ShopsRest/selectCheckPassShopsByName",
params:[
{name:"idName",type:"String"}
]
},
queryMerchantBrandByShopsId:{
title:"查询店铺下关联品牌",
url:"/MerchantShopsRest/queryMerchantBrandByShopsId"
},
getJitSupplierByBrandId:{
title:"获取JIT店铺",
url:"/AgreementRest/getJitSupplierByBrandId",
params:[
{name:"brandId",type:"String"}
]
},
querySizeListBySortId4Html:{
title:"尺码",
url: '/product/querySizeListBySortId4Html',
params:[
{name:"idName",type:"String"},
{name:"sortId",type:"Number"}
]
},
queryAllMaxSortList:{
title:"顶级类目",
url:"/product/queryAllMaxSortList"
},
queryProductSortList:{
title:"子类目",
url: '/product/queryProductSortList',
params:[
{name:'param',type:'Number'}
]
},
selectCheckPassShopsByName:{
title:"店铺列表",
url: "/ShopsRest/selectCheckPassShopsByName",
params:[
{name:'idName',type:'String'}
]
},
queryMerchantSupplierByShopsId:{
title:'查询店铺下关联供应商',
url:'/MerchantShopsRest/queryMerchantSupplierByShopsId'
},
queryMerchantBrandByShopsId:{
title:'查询店铺下关联品牌',
url:'/MerchantShopsRest/queryMerchantBrandByShopsId'
},
queryMaxSortByName:{
title:"查询一级类目列表接口",
url:'/product/queryMaxSortByName',
params:[
{name:'idName',type:'String'}
]
},
queryShopsByBrandId:{
title:'根据品牌查询店铺',
url: '/ShopsRest/queryShopsByBrandId',
params: [
{name: 'brandId',type: 'number'}
]
}
}
}
\ No newline at end of file
... ...
var request = require('request');
var _ = require('lodash');
var fs = require('fs');
var http = require('http');
var config=global.global.Register;
var Utils={
objectToUrl:function(items){
var urls=[];
for(var name in items){
if(items.hasOwnProperty(name)&&items[name]){
// if(items[name]!=="undefined"){
urls.push(name+"="+items[name]);
// }
}
}
return urls.join('&');
},
createHttpHeader:function(req){
if (req.session && req.session.user) {
return {
'x-user-id': req.session.user.auth.pid,
'x-user-name': req.session.user.auth.account,
'x-site-type': 1,
'x-client-ip': req.ip,
'x-shop-id':req.session.user.auth.shopId
};
}
},
joinImg:function(url) {
var urlArr = url.split('/');
var domain = 'static.yhbimg.com/goodsimg';
var num = urlArr[urlArr.length - 1].substr(1, 1);
var url1 = domain + url;
if (num == 1) {
return 'http://img11.' + url1;
} else {
return 'http://img12.' + url1;
}
}
}
module.exports={
namespace:"common",
apis:{
multipart:function(req, callback){
var result={code: "500",message: "接口异常"};
var httpHeader=Utils.createHttpHeader(req);
if(!httpHeader){
result = { code: "501", message: "用户失效,请重新登录" };
return callback(null, result);
}
var body=req.body;
if(body.__type == "batch-import"){
var url=Utils.objectToUrl(body);
body.file = fs.createReadStream(req.files[body.filename].path);
request.post({
url: config.domain + '/batch/import?' + url,
formData: body,
headers: httpHeader
}, function optionalCallback(error, httpResponse, rebody) {
if (!error && httpResponse.statusCode == 200) {
result = JSON.parse(rebody);
result.status = true;
}
return callback(null, result);
});
}else{
var files = req.files[req.body.filename];
//判断是单张传还是多张传
var flag = Object.prototype.toString.call(files) === '[object Array]';
//如果是单张,则数组化
if (!flag) {
files = [];
files.push(req.files[req.body.filename]);
}
req.body.files = [];
req.body.fileNames = [];
for (var index = 0; index < files.length; index++) {
req.body.files[index] = fs.createReadStream(files[index].path);
req.body.fileNames[index] = files[index].name;
}
if (req.body.bucket === 'goodsimg') {
request.post({
url: "http://upload.static.yohobuy.com",
formData: {
fileData: req.body.files,
project: req.body.bucket
}
}, function (error, httpResponse, rebody) {
if (!error && httpResponse.statusCode == 200) {
var ret = JSON.parse(rebody);
var imgs = ret.data.imagesList || [];
var datas = [];
for (var i = 0; i < imgs.length; i++) {
datas.push(Utils.joinImg(imgs[i]))
}
result={
code: 200,
data: datas[0],
datas:datas,
names: req.body.fileNames,
message: '上传成功',
status: true
};
}
return callback(null, result);
});
} else {
req.body.file = fs.createReadStream(req.files[req.body.filename].path);
request.post({
url: config.domain + '/fileupload/upload',
formData: req.body
}, function optionalCallback(error, httpResponse, rebody) {
if (!error && httpResponse.statusCode == 200) {
result = JSON.parse(rebody);
result.status = true;
}
return callback(null, result);
});
}
}
},
baiduUeditor:function(req, callback){
var result={code: "500",message: "接口异常"};
var httpHeader=Utils.createHttpHeader(req);
if(!httpHeader){
result={code: "501",message: "用户失效,请重新登录"};
return callback(null, result);
}
req.body.files = [fs.createReadStream(req.files.upfile.path)];
req.body.bucket="goodsimg";
request.post({
url: "http://upload.static.yohobuy.com",
formData: {
fileData: req.body.files,
project: req.body.bucket
}
}, function optionalCallback(error, httpResponse, body) {
if (!error && httpResponse.statusCode == 200) {
var ret = JSON.parse(body);
if (ret.code === 200) {
var imgUrl = ret.data.imagesList[0];
imgUrl=Utils.joinImg(imgUrl);
result={};
if(imgUrl){
result.originalName=Date.now();
result.name=Date.now();
result.url=imgUrl;
result.type=imgUrl.substring(imgUrl.lastIndexOf('.'));
result.state="SUCCESS";
}else{
result.state="FAIL";
}
}
}
return callback(null, result);
});
},
downExcel:function(req, callback){
var result = request.get(config.domain + "/common/" + req.params.name + ".xlsx");
return callback(null, result);
},
exportExcel:function(req, callback){
var result = request({
method: 'POST',
url: config.domain + '/batch/export',
headers: {
'content-type': 'application/json'
},
body: req.query,
json: true
});
return callback(null, result);
},
proxy:function(req, callback){
var httpHeader = Utils.createHttpHeader(req);
if(!httpHeader){
return null;
}
httpHeader['Content-Type'] = 'application/json';
var result=request({
headers:headers,
url:global.config.domain + req.query.url,
body:JSON.stringify(req.body)
});
return callback(null, result)
},
download:function(req, callback){
var result = request.get(config.domain + "/batch/download?path=" + req.query.path);
return callback(null, result);
}
}
}
\ No newline at end of file
... ...
ERROR:<%message%>
\ No newline at end of file
... ...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link rel="stylesheet" href="/static/index.min.css">
</head>
<body>
<div class="login-cover">
<div class="login-cover-image"></div>
<div class="login-cover-bg"></div>
</div>
<div id="page-container">
<div class="login login-v2" data-pageload-addclass="animated flipInX">
<div class="login-header">
<div class="brand">
<span class="logo"></span> Yoho!Buy商家后台
</div>
</div>
<div class="login-content">
<form action="/login" method="POST" class="margin-bottom-0">
<input type="hidden" name="refer" value="%2F">
<div class="form-group m-b-20">
<input type="text" class="form-control input-lg" name="user" placeholder="用户名" autocomplete="off" />
</div>
<div class="form-group m-b-20">
<input type="password" class="form-control input-lg" name="password" placeholder="密码" autocomplete="off" />
</div>
<div class="login-buttons">
<button type="submit" class="btn btn-success btn-block btn-lg">&nbsp;&nbsp;</button>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
\ No newline at end of file
... ...
<h1 class="page-header"><% pageName %></h1>
\ No newline at end of file
... ...
</div>
</div>
</body>
</html>
\ No newline at end of file
... ...
<!doctype html>
<html class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>有货商家后台系统</title>
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="stylesheet" href="/static/index.min.css">
</head>
<body id="custom-wrapper">
<div id="page-container" class="page-sidebar-fixed page-header-fixed">
<%include 'topbar'%>
<%include 'sidebar'%>
<div id="content" class="content">
... ...
<div id="sidebar" class="sidebar">
<div data-scrollbar="true" data-height="100%">
<ul class="nav">
<%each _locals.session.user.menu as value i%>
<li <%if value.parent%>class="has-sub "<%/if%>>
<a href="javascript:;">
<b class="caret pull-right"></b>
<span><%value.title%></span>
</a>
<%if value.menu%>
<ul class="sub-menu">
<%each value.menu%>
<li >
<a <%if $value.href%> href="<%$value.href%>"<%/if%>>
<b class="caret pull-right"></b>
<span><%$value.title%></span>
</a>
</li>
<%/each%>
</ul>
<%/if%>
</a>
</li>
<%/each%>
<li>
<a href="javascript:;" class="sidebar-minify-btn" data-click="sidebar-minify">
<i class="fa fa-angle-double-left"></i>
</a>
</li>
</ul>
</div>
</div>
<div class="sidebar-bg"></div>
... ...
<div id="header" class="header navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a href="/" class="navbar-brand">
<div class="navbar-brand-img"></div>
</a>
<button type="button" class="navbar-toggle" data-click="sidebar-toggled">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<%if _locals.session.user.auth %>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
<%_locals.session.user.auth.shopName%><span class="hidden-xs">切换店铺</span> <b class="caret"></b>
</a>
<ul class="dropdown-menu animated fadeInLeft">
<li class="arrow"></li>
<%each _locals.session.user.shopList as item i%>
<li><a href="javascript:;" class="shops_id" data-shopid="<%item.id%>"><%item.name%></a></li>
<%/each%>
</ul>
</li>
<li class="login-out">
<div><%_locals.session.user.name%><span><a href="/logout" >[退出]</a></span></div>
</li>
</ul>
<%/if%>
</div>
</div>
\ No newline at end of file
... ...
<%include '__ui/header'%>
<%include '__ui/footer'%>
... ...