Authored by weiqingting

tianjia

  1 +
  2 +module.exports=function(app) {
  3 +
  4 + app.get("/login","common.Login");
  5 +
  6 + app.get("/logout","common.Login",function (req) {
  7 + delete req.session.user;
  8 + });
  9 +
  10 + app.post("/login", "common_login", function (login, req, res){
  11 + if (login.code == 200) {
  12 + res.myRedirect('/');
  13 + } else {
  14 + res.myRedirect('/login');
  15 + }
  16 + });
  17 +
  18 + app.get("/","common.index");
  19 +
  20 + app.get("/error", "common.Error");
  21 +
  22 + app.get("/index/ajaxshop","common_changeShop");
  23 +}
  24 +
  25 +
  1 +module.exports=function(app) {
  2 + //查询通过审核店铺列表接口
  3 + app.post("/ShopsRest/selectCheckPassShopsByName","select_selectCheckPassShopsByName");
  4 + //查询店铺下关联品牌
  5 + app.post("/MerchantShopsRest/queryMerchantBrandByShopsId","select_queryMerchantBrandByShopsId");
  6 + //获取JIT店铺
  7 + app.post("/AgreementRest/getJitSupplierByBrandId","select_getJitSupplierByBrandId");
  8 + //尺码
  9 + app.post("/product/querySizeListBySortId4Html","select_querySizeListBySortId4Html");
  10 + //店铺列表
  11 + app.post("/ShopsRest/selectCheckPassShopsByName","select_selectCheckPassShopsByName");
  12 + //查询店铺下关联供应商
  13 + app.post("/MerchantShopsRest/queryMerchantSupplierByShopsId","select_queryMerchantSupplierByShopsId");
  14 +
  15 + //根据品牌获取供应商
  16 + app.post("/ShopsRest/queryShopsByBrandId", "select_queryShopsByBrandId");
  17 +
  18 + app.post("/product/queryMaxSortByName","select_queryMaxSortByName");
  19 + /*类目 已经集成到控件里面去了注意*/
  20 + app.post("/product/class/queryAllProductSortList","select_queryAllMaxSortList");
  21 + app.post("/product/class/queryProductSortList","select_queryProductSortList");
  22 +}
  1 +module.exports=function(app) {
  2 + app.get("/ajax/link/:name","common_downExcel");
  3 + app.get("/ajax/down","common_exportExcel");
  4 +
  5 + app.post("/ajax/upload","common_multipart");
  6 + app.post("/ajax/ueditor","common_baiduUeditor");
  7 + app.post("/ajax/proxy","common_proxy");
  8 +
  9 + app.get("/ajax/download","common_download")
  10 +}
  1 +var request = require('request');
  2 +var _ = require('lodash');
  3 +var fs = require('fs');
  4 +
  5 +var Iaccount = global.Register.system;
  6 +
  7 +var Utils = {
  8 + createrMenus: function (data) {
  9 + var menu = [];
  10 + for (var key in data) {
  11 +
  12 + var v = data[key];
  13 + var item = {
  14 + title: v.menu_name,
  15 + }
  16 + if (v.parent_id === "0") {
  17 + item.parent = 'menu-template';
  18 + var itemSubs = [];
  19 + _.forEach(v.sub, function (val) {
  20 + var sub = {
  21 + title: val.menu_name,
  22 + href: val.menu_url,
  23 + icon: 'list-alt'
  24 + }
  25 + itemSubs.push(sub);
  26 + });
  27 +
  28 + item.menu = itemSubs;
  29 + }
  30 + menu.push(item);
  31 + }
  32 + return menu;
  33 + }
  34 +}
  35 +
  36 +module.exports = {
  37 + namespace: "common",
  38 + apis: {
  39 + Ilogin: {
  40 + title:'登录接口',
  41 + url: Iaccount.login,
  42 + form: '["{{user}}","{{password}}",{{website}}]',
  43 + params: {
  44 + user: { type: String },
  45 + password: { type: String },
  46 + website: {type:Number,default: Iaccount.WEBSITE}
  47 + }
  48 + },
  49 + getResourceByPid: {
  50 + title:'菜单接口',
  51 + url: Iaccount.getResourceByPid,
  52 + form: '[{{pid}},{{role_id}},{{website}}]',
  53 + params: {
  54 + pid: { type: Number },
  55 + role_id: { type: Number },
  56 + website: { type: Number, default: Iaccount.WEBSITE }
  57 + }
  58 + },
  59 + allRight: {
  60 + title: '获取权限',
  61 + url: Iaccount.allRight,
  62 + form: '[false]'
  63 + },
  64 + getShopList: {
  65 + title:'获取当前用户所有店铺',
  66 + url: Iaccount.getShopList,
  67 + form:true,
  68 + headers: {
  69 + "x-user-id": {type:Number}
  70 + }
  71 + },
  72 + sessionAsync: {
  73 + title:'与老系统session同步',
  74 + url: Iaccount.url + '/login/sessions',
  75 + outobj: "response",
  76 + form: {'account':'{{user}}','password':'{{password}}','refer': '%2Faccount%2Fprofile%2Fdisplay'},
  77 + params: {
  78 + user: { type: String },
  79 + password: { type: String }
  80 + }
  81 + },
  82 + login: function (req, callback, common) {
  83 + var userInfo = {},result = { code: 400, message: "登录失败" },isSuccess=false;
  84 + var user = req.body.user;
  85 + var password = req.body.password;
  86 + var errcallback = function (err) {
  87 + return callback(null, result);
  88 + }
  89 + common.Ilogin(user, password).allRight().sessionAsync(user, password).done(function (IloginRes,allRes,sesRes) {
  90 + var userData = IloginRes.data, cookie = sesRes.caseless.dict["set-cookie"];
  91 +
  92 + userInfo = { auth: userData, uid: userData.pid, name: userData.truename, right: {},shopList:[]};
  93 + allRes.data.forEach(function (data) {
  94 + if (data.platform_id == Iaccount.WEBSITE) {
  95 + userInfo.right[data.path] = true;
  96 + }
  97 + });
  98 + common.getResourceByPid(userData.pid, userData.role_id)
  99 + .getShopList({ "@x-user-id": userInfo.uid }).done(function (getRRes, shopRes) {
  100 + userInfo.menu = Utils.createrMenus(getRRes.data);
  101 + if (shopRes.data) {
  102 + shopRes.data.forEach(function (data, index) {
  103 + if (!index) {
  104 + userInfo.auth.shopName = data.shopName;
  105 + userInfo.auth.shopId = data.shopsId;
  106 + }
  107 + userInfo.shopList.push({
  108 + name: data.shopName,
  109 + id: data.shopsId
  110 + });
  111 + });
  112 + req.session.user = userInfo;
  113 + if (cookie && cookie.length > 0) {
  114 + req.session.gray = cookie[0];
  115 + result = { code: 200, message: "登录成功" };
  116 + }
  117 + console.log(result);
  118 +
  119 + } else {
  120 + result = { code: 400, message: "该用户没有店铺" };
  121 + }
  122 + return callback(null, result);
  123 + },errcallback);
  124 + }, errcallback);
  125 + },
  126 + isUsedMenuAuth:{
  127 + title:'检查有没有权限',
  128 + url:Iaccount.isUsedMenuAuth,
  129 + form:'[{{pid}},{{role_id}},"{{path}}","","",' + Iaccount.WEBSITE + ']',
  130 + params:{
  131 + pid:{type:Number},
  132 + role_id:{type:Number},
  133 + path:{type:String}
  134 + }
  135 + },
  136 + gray: function (req, callback,common) {
  137 + var result = { code: 201, message: "没有权限" };
  138 + if (req.session && req.session.user) {
  139 + var user = req.session.user;
  140 + var path = req.route?req.route.path[0]:req.originalUrl.replace(/\?.+/, '');
  141 + req._yoheaders = {
  142 + 'x-user-id': user.auth.pid,
  143 + 'x-user-name': user.auth.account,
  144 + 'x-site-type': Iaccount.WEBSITE,
  145 + 'x-client-ip': req.ip,
  146 + 'x-shop-id': user.auth.shopId
  147 + };
  148 + if (path && user.right[path]) {
  149 + common.isUsedMenuAuth(user.auth.pid,user.auth.role_id,path).done(function(isURes){
  150 + result = { code: 200, message: "具有权限" };
  151 + return callback(null, result);
  152 + },function(error){
  153 + return callback(error, result);
  154 + });
  155 + } else {
  156 + result = { code: 200, message: "不受权限控制" };
  157 + return callback(null, result);
  158 + }
  159 + } else {
  160 + return callback(null, result);
  161 + }
  162 + },
  163 + IchangeShops:{
  164 + title:'调用老系统的切换店铺的接口',
  165 + url: Iaccount.changeShops + '?shops_id={{shops_id}}',
  166 + method:'GET',
  167 + outobj:'response',
  168 + headers: {
  169 + cookie: { type: String }
  170 + },
  171 + params: {
  172 + shops_id: { type: Number },
  173 + '@cookie': {type:String}
  174 + }
  175 + },
  176 + changeShop: function (req, callback,common) {
  177 + var shopId = Number(req.query.shops_id);
  178 + var cookie = req.session.gray;
  179 + var result = { code: 500, message: "something wrong!" };
  180 +
  181 + //设置当前的店铺信息
  182 + if (req.session.user && req.session.user.auth) {
  183 + _.forEach(req.session.user.shopList, function (v, k) {
  184 + if (v.id === shopId) {
  185 + req.session.user.auth.shopName = v.name;
  186 + req.session.user.auth.shopId = shopId;
  187 + };
  188 + });
  189 + }
  190 + common.IchangeShops(shopId,cookie).done(function(IchRes){
  191 + if(IchRes.statusCode == 200){
  192 + result = { code: 200, message: "success" };
  193 + return callback(null, result);
  194 + }else{
  195 + return callback(null, result);
  196 + }
  197 + });
  198 + }
  199 + }
  200 +}
  1 +module.exports={
  2 + namespace:"select",
  3 + apis:{
  4 + selectCheckPassShopsByName:{
  5 + title:"查询通过审核店铺列表接口",
  6 + url:"/ShopsRest/selectCheckPassShopsByName",
  7 + params:[
  8 + {name:"idName",type:"String"}
  9 + ]
  10 + },
  11 + queryMerchantBrandByShopsId:{
  12 + title:"查询店铺下关联品牌",
  13 + url:"/MerchantShopsRest/queryMerchantBrandByShopsId"
  14 + },
  15 + getJitSupplierByBrandId:{
  16 + title:"获取JIT店铺",
  17 + url:"/AgreementRest/getJitSupplierByBrandId",
  18 + params:[
  19 + {name:"brandId",type:"String"}
  20 + ]
  21 + },
  22 + querySizeListBySortId4Html:{
  23 + title:"尺码",
  24 + url: '/product/querySizeListBySortId4Html',
  25 + params:[
  26 + {name:"idName",type:"String"},
  27 + {name:"sortId",type:"Number"}
  28 + ]
  29 + },
  30 + queryAllMaxSortList:{
  31 + title:"顶级类目",
  32 + url:"/product/queryAllMaxSortList"
  33 + },
  34 + queryProductSortList:{
  35 + title:"子类目",
  36 + url: '/product/queryProductSortList',
  37 + params:[
  38 + {name:'param',type:'Number'}
  39 + ]
  40 + },
  41 + selectCheckPassShopsByName:{
  42 + title:"店铺列表",
  43 + url: "/ShopsRest/selectCheckPassShopsByName",
  44 + params:[
  45 + {name:'idName',type:'String'}
  46 + ]
  47 + },
  48 + queryMerchantSupplierByShopsId:{
  49 + title:'查询店铺下关联供应商',
  50 + url:'/MerchantShopsRest/queryMerchantSupplierByShopsId'
  51 + },
  52 + queryMerchantBrandByShopsId:{
  53 + title:'查询店铺下关联品牌',
  54 + url:'/MerchantShopsRest/queryMerchantBrandByShopsId'
  55 + },
  56 + queryMaxSortByName:{
  57 + title:"查询一级类目列表接口",
  58 + url:'/product/queryMaxSortByName',
  59 + params:[
  60 + {name:'idName',type:'String'}
  61 + ]
  62 + },
  63 + queryShopsByBrandId:{
  64 + title:'根据品牌查询店铺',
  65 + url: '/ShopsRest/queryShopsByBrandId',
  66 + params: [
  67 + {name: 'brandId',type: 'number'}
  68 + ]
  69 + }
  70 + }
  71 +}
  1 + var request = require('request');
  2 +var _ = require('lodash');
  3 +var fs = require('fs');
  4 +var http = require('http');
  5 +
  6 +var config=global.global.Register;
  7 +
  8 +var Utils={
  9 + objectToUrl:function(items){
  10 + var urls=[];
  11 + for(var name in items){
  12 + if(items.hasOwnProperty(name)&&items[name]){
  13 + // if(items[name]!=="undefined"){
  14 + urls.push(name+"="+items[name]);
  15 + // }
  16 + }
  17 + }
  18 + return urls.join('&');
  19 + },
  20 + createHttpHeader:function(req){
  21 + if (req.session && req.session.user) {
  22 + return {
  23 + 'x-user-id': req.session.user.auth.pid,
  24 + 'x-user-name': req.session.user.auth.account,
  25 + 'x-site-type': 1,
  26 + 'x-client-ip': req.ip,
  27 + 'x-shop-id':req.session.user.auth.shopId
  28 +
  29 + };
  30 + }
  31 + },
  32 + joinImg:function(url) {
  33 + var urlArr = url.split('/');
  34 + var domain = 'static.yhbimg.com/goodsimg';
  35 + var num = urlArr[urlArr.length - 1].substr(1, 1);
  36 + var url1 = domain + url;
  37 + if (num == 1) {
  38 + return 'http://img11.' + url1;
  39 + } else {
  40 + return 'http://img12.' + url1;
  41 + }
  42 + }
  43 + }
  44 +
  45 +module.exports={
  46 + namespace:"common",
  47 + apis:{
  48 + multipart:function(req, callback){
  49 + var result={code: "500",message: "接口异常"};
  50 + var httpHeader=Utils.createHttpHeader(req);
  51 + if(!httpHeader){
  52 + result = { code: "501", message: "用户失效,请重新登录" };
  53 + return callback(null, result);
  54 + }
  55 + var body=req.body;
  56 + if(body.__type == "batch-import"){
  57 + var url=Utils.objectToUrl(body);
  58 + body.file = fs.createReadStream(req.files[body.filename].path);
  59 + request.post({
  60 + url: config.domain + '/batch/import?' + url,
  61 + formData: body,
  62 + headers: httpHeader
  63 + }, function optionalCallback(error, httpResponse, rebody) {
  64 + if (!error && httpResponse.statusCode == 200) {
  65 + result = JSON.parse(rebody);
  66 + result.status = true;
  67 + }
  68 + return callback(null, result);
  69 + });
  70 + }else{
  71 + var files = req.files[req.body.filename];
  72 + //判断是单张传还是多张传
  73 + var flag = Object.prototype.toString.call(files) === '[object Array]';
  74 + //如果是单张,则数组化
  75 + if (!flag) {
  76 + files = [];
  77 + files.push(req.files[req.body.filename]);
  78 + }
  79 + req.body.files = [];
  80 + req.body.fileNames = [];
  81 + for (var index = 0; index < files.length; index++) {
  82 + req.body.files[index] = fs.createReadStream(files[index].path);
  83 + req.body.fileNames[index] = files[index].name;
  84 + }
  85 + if (req.body.bucket === 'goodsimg') {
  86 + request.post({
  87 + url: "http://upload.static.yohobuy.com",
  88 + formData: {
  89 + fileData: req.body.files,
  90 + project: req.body.bucket
  91 + }
  92 + }, function (error, httpResponse, rebody) {
  93 + if (!error && httpResponse.statusCode == 200) {
  94 + var ret = JSON.parse(rebody);
  95 + var imgs = ret.data.imagesList || [];
  96 + var datas = [];
  97 + for (var i = 0; i < imgs.length; i++) {
  98 + datas.push(Utils.joinImg(imgs[i]))
  99 + }
  100 + result={
  101 + code: 200,
  102 + data: datas[0],
  103 + datas:datas,
  104 + names: req.body.fileNames,
  105 + message: '上传成功',
  106 + status: true
  107 + };
  108 + }
  109 + return callback(null, result);
  110 + });
  111 + } else {
  112 + req.body.file = fs.createReadStream(req.files[req.body.filename].path);
  113 + request.post({
  114 + url: config.domain + '/fileupload/upload',
  115 + formData: req.body
  116 + }, function optionalCallback(error, httpResponse, rebody) {
  117 + if (!error && httpResponse.statusCode == 200) {
  118 + result = JSON.parse(rebody);
  119 + result.status = true;
  120 + }
  121 + return callback(null, result);
  122 + });
  123 + }
  124 + }
  125 + },
  126 + baiduUeditor:function(req, callback){
  127 + var result={code: "500",message: "接口异常"};
  128 + var httpHeader=Utils.createHttpHeader(req);
  129 + if(!httpHeader){
  130 + result={code: "501",message: "用户失效,请重新登录"};
  131 + return callback(null, result);
  132 + }
  133 + req.body.files = [fs.createReadStream(req.files.upfile.path)];
  134 + req.body.bucket="goodsimg";
  135 + request.post({
  136 + url: "http://upload.static.yohobuy.com",
  137 + formData: {
  138 + fileData: req.body.files,
  139 + project: req.body.bucket
  140 + }
  141 + }, function optionalCallback(error, httpResponse, body) {
  142 + if (!error && httpResponse.statusCode == 200) {
  143 + var ret = JSON.parse(body);
  144 + if (ret.code === 200) {
  145 + var imgUrl = ret.data.imagesList[0];
  146 + imgUrl=Utils.joinImg(imgUrl);
  147 + result={};
  148 + if(imgUrl){
  149 + result.originalName=Date.now();
  150 + result.name=Date.now();
  151 + result.url=imgUrl;
  152 + result.type=imgUrl.substring(imgUrl.lastIndexOf('.'));
  153 + result.state="SUCCESS";
  154 + }else{
  155 + result.state="FAIL";
  156 + }
  157 + }
  158 + }
  159 + return callback(null, result);
  160 + });
  161 + },
  162 + downExcel:function(req, callback){
  163 + var result = request.get(config.domain + "/common/" + req.params.name + ".xlsx");
  164 + return callback(null, result);
  165 + },
  166 + exportExcel:function(req, callback){
  167 + var result = request({
  168 + method: 'POST',
  169 + url: config.domain + '/batch/export',
  170 + headers: {
  171 + 'content-type': 'application/json'
  172 + },
  173 + body: req.query,
  174 + json: true
  175 + });
  176 + return callback(null, result);
  177 + },
  178 + proxy:function(req, callback){
  179 + var httpHeader = Utils.createHttpHeader(req);
  180 + if(!httpHeader){
  181 + return null;
  182 + }
  183 + httpHeader['Content-Type'] = 'application/json';
  184 +
  185 + var result=request({
  186 + headers:headers,
  187 + url:global.config.domain + req.query.url,
  188 + body:JSON.stringify(req.body)
  189 + });
  190 + return callback(null, result)
  191 + },
  192 + download:function(req, callback){
  193 + var result = request.get(config.domain + "/batch/download?path=" + req.query.path);
  194 + return callback(null, result);
  195 + }
  196 + }
  197 + }
  1 +<!DOCTYPE html>
  2 +<html lang="en">
  3 +<head>
  4 + <meta charset="utf-8">
  5 + <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
  6 + <meta name="description" content="">
  7 + <meta name="author" content="">
  8 + <link rel="stylesheet" href="/static/index.min.css">
  9 +</head>
  10 +<body>
  11 +<div class="login-cover">
  12 + <div class="login-cover-image"></div>
  13 + <div class="login-cover-bg"></div>
  14 +</div>
  15 +<div id="page-container">
  16 + <div class="login login-v2" data-pageload-addclass="animated flipInX">
  17 + <div class="login-header">
  18 + <div class="brand">
  19 + <span class="logo"></span> Yoho!Buy商家后台
  20 + </div>
  21 + </div>
  22 + <div class="login-content">
  23 + <form action="/login" method="POST" class="margin-bottom-0">
  24 + <input type="hidden" name="refer" value="%2F">
  25 + <div class="form-group m-b-20">
  26 + <input type="text" class="form-control input-lg" name="user" placeholder="用户名" autocomplete="off" />
  27 + </div>
  28 + <div class="form-group m-b-20">
  29 + <input type="password" class="form-control input-lg" name="password" placeholder="密码" autocomplete="off" />
  30 + </div>
  31 + <div class="login-buttons">
  32 + <button type="submit" class="btn btn-success btn-block btn-lg">&nbsp;&nbsp;</button>
  33 + </div>
  34 + </form>
  35 + </div>
  36 + </div>
  37 + </div>
  38 +</body>
  39 +</html>
  1 +<h1 class="page-header"><% pageName %></h1>
  1 + </div>
  2 + </div>
  3 +
  4 +</body>
  5 +</html>
  1 +<!doctype html>
  2 +<html class="no-js">
  3 +<head>
  4 + <meta charset="utf-8">
  5 + <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6 + <title>有货商家后台系统</title>
  7 + <meta name="description" content="">
  8 + <meta name="keywords" content="">
  9 + <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  10 + <meta name="renderer" content="webkit">
  11 + <meta http-equiv="Cache-Control" content="no-siteapp" />
  12 + <link rel="stylesheet" href="/static/index.min.css">
  13 +</head>
  14 +<body id="custom-wrapper">
  15 +<div id="page-container" class="page-sidebar-fixed page-header-fixed">
  16 +<%include 'topbar'%>
  17 +<%include 'sidebar'%>
  18 +<div id="content" class="content">
  19 +
  1 +<div id="sidebar" class="sidebar">
  2 + <div data-scrollbar="true" data-height="100%">
  3 + <ul class="nav">
  4 + <%each _locals.session.user.menu as value i%>
  5 + <li <%if value.parent%>class="has-sub "<%/if%>>
  6 + <a href="javascript:;">
  7 + <b class="caret pull-right"></b>
  8 + <span><%value.title%></span>
  9 + </a>
  10 + <%if value.menu%>
  11 + <ul class="sub-menu">
  12 + <%each value.menu%>
  13 + <li >
  14 + <a <%if $value.href%> href="<%$value.href%>"<%/if%>>
  15 + <b class="caret pull-right"></b>
  16 + <span><%$value.title%></span>
  17 + </a>
  18 + </li>
  19 + <%/each%>
  20 + </ul>
  21 + <%/if%>
  22 + </a>
  23 + </li>
  24 + <%/each%>
  25 +
  26 + <li>
  27 + <a href="javascript:;" class="sidebar-minify-btn" data-click="sidebar-minify">
  28 + <i class="fa fa-angle-double-left"></i>
  29 + </a>
  30 + </li>
  31 + </ul>
  32 + </div>
  33 +</div>
  34 +<div class="sidebar-bg"></div>
  1 +<div id="header" class="header navbar navbar-default navbar-fixed-top">
  2 + <div class="container-fluid">
  3 + <div class="navbar-header">
  4 + <a href="/" class="navbar-brand">
  5 + <div class="navbar-brand-img"></div>
  6 + </a>
  7 + <button type="button" class="navbar-toggle" data-click="sidebar-toggled">
  8 + <span class="icon-bar"></span>
  9 + <span class="icon-bar"></span>
  10 + <span class="icon-bar"></span>
  11 + </button>
  12 + </div>
  13 + <%if _locals.session.user.auth %>
  14 + <ul class="nav navbar-nav navbar-right">
  15 + <li class="dropdown">
  16 + <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
  17 + <%_locals.session.user.auth.shopName%><span class="hidden-xs">切换店铺</span> <b class="caret"></b>
  18 + </a>
  19 + <ul class="dropdown-menu animated fadeInLeft">
  20 + <li class="arrow"></li>
  21 + <%each _locals.session.user.shopList as item i%>
  22 + <li><a href="javascript:;" class="shops_id" data-shopid="<%item.id%>"><%item.name%></a></li>
  23 + <%/each%>
  24 + </ul>
  25 + </li>
  26 + <li class="login-out">
  27 + <div><%_locals.session.user.name%><span><a href="/logout" >[退出]</a></span></div>
  28 + </li>
  29 + </ul>
  30 + <%/if%>
  31 + </div>
  32 +</div>
  1 +<%include '__ui/header'%>
  2 +<%include '__ui/footer'%>