Authored by liuyue

Merge branch 'develop' of http://git.dev.yoho.cn/platform/yohobuy-shops-fe into develop

@@ -32,7 +32,7 @@ var urlObj = { @@ -32,7 +32,7 @@ var urlObj = {
32 32
33 // 逛 33 // 逛
34 'guangGetAuthorList':'/guang/article/getAuthorList', // 逛-获取作者 34 'guangGetAuthorList':'/guang/article/getAuthorList', // 逛-获取作者
35 - 'guangGetSortList':'/guang/article/getSortList', // 逛-获取作者 35 + 'guangGetSortList':'/ajax/guang/article/getSortList', // 逛-获取作者
36 'guangGetTagCategoryByStatus':'/guang/tagSort/getTagItems', 36 'guangGetTagCategoryByStatus':'/guang/tagSort/getTagItems',
37 'guangCommentGetFilterItems':'/guang/comment/getItems', // 逛-评论列表-获取筛选条件 37 'guangCommentGetFilterItems':'/guang/comment/getItems', // 逛-评论列表-获取筛选条件
38 'guangPlusSatrChannel':'/guang/plustarcategory/getCategoryNames', // 逛-plus star 频道 38 'guangPlusSatrChannel':'/guang/plustarcategory/getCategoryNames', // 逛-plus star 频道
@@ -171,7 +171,7 @@ edit.prototype = { @@ -171,7 +171,7 @@ edit.prototype = {
171 }, 171 },
172 'onComplete': function(response) { 172 'onComplete': function(response) {
173 if (response.status && response.code == 200) { 173 if (response.status && response.code == 200) {
174 - var _w = $(this).next().find('.fileinput-button-icon'); 174 + var _w = $(this).parent().find('.fileinput-button-icon');
175 var _img = $('img', _w).add('video', _w); 175 var _img = $('img', _w).add('video', _w);
176 if (_img.length > 0) { 176 if (_img.length > 0) {
177 _img.attr("src", response.data); 177 _img.attr("src", response.data);
@@ -267,6 +267,17 @@ var util = { @@ -267,6 +267,17 @@ var util = {
267 setTimeout(function(){ 267 setTimeout(function(){
268 $this.removeAttr("disabled"); 268 $this.removeAttr("disabled");
269 },3000); 269 },3000);
  270 + },
  271 + __joinImg:function(url) {
  272 + var urlArr = url.split('/');
  273 + var domain = 'static.yhbimg.com/brandLogo';
  274 + var num = urlArr[urlArr.length-1].substr(1,1);
  275 + var url = domain + url;
  276 + if(num == 1) {
  277 + return 'http://img11.' + url;
  278 + } else {
  279 + return 'http://img12.'+ url;
  280 + }
270 } 281 }
271 } 282 }
272 module.exports = util; 283 module.exports = util;
@@ -41,17 +41,18 @@ function getHeader(req,res){ @@ -41,17 +41,18 @@ function getHeader(req,res){
41 } 41 }
42 42
43 43
44 -exports.uploadFile = function(req, res) {  
45 - var headers = getHeader(req,res);  
46 - 44 +exports.uploadFile = function (req, res) {
  45 + var headers = getHeader(req, res);
47 if (req.is("multipart/form-data")) { 46 if (req.is("multipart/form-data")) {
48 - console.log(req.body);  
49 var url = []; 47 var url = [];
50 for (var key in req.body) { 48 for (var key in req.body) {
51 url.push(key + "=" + req.body[key]); 49 url.push(key + "=" + req.body[key]);
52 } 50 }
53 - req.body.file = fs.createReadStream(req.files[req.body.filename].path); 51 + console.log("req.body",req.body);
  52 + //req.body.file = fs.createReadStream(req.files[req.body.filename].path);
  53 +
54 if (req.body.__type == "batch-import") { 54 if (req.body.__type == "batch-import") {
  55 + req.body.file = fs.createReadStream(req.files[req.body.filename].path);
55 request.post({ 56 request.post({
56 url: domain + '/batch/import?' + url.join("&"), 57 url: domain + '/batch/import?' + url.join("&"),
57 formData: req.body, 58 formData: req.body,
@@ -63,31 +64,51 @@ exports.uploadFile = function(req, res) { @@ -63,31 +64,51 @@ exports.uploadFile = function(req, res) {
63 if (!error && httpResponse.statusCode == 200) { 64 if (!error && httpResponse.statusCode == 200) {
64 var json = JSON.parse(body); 65 var json = JSON.parse(body);
65 json.status = true; 66 json.status = true;
66 - // console.log(json);  
67 res.json(json); 67 res.json(json);
68 } else { 68 } else {
69 res.json(errBackMsg); 69 res.json(errBackMsg);
70 } 70 }
71 }); 71 });
72 } else { 72 } else {
  73 + var files = req.files[req.body.filename];
  74 + //判断是单张传还是多张传
  75 + var flag = Object.prototype.toString.call(files) === '[object Array]';
  76 + //如果是单张,则数组化
  77 + if (!flag) {
  78 + files = [];
  79 + files.push(req.files[req.body.filename]);
  80 + }
  81 + req.body.files = [];
  82 + req.body.fileNames = [];
  83 + for (var index = 0; index < files.length; index++) {
  84 + req.body.files[index] = fs.createReadStream(files[index].path);
  85 + req.body.fileNames[index] = files[index].name;
  86 + }
73 87
74 //如果是goodsimg(商品)的图片,灰度到老系统的上传地址 88 //如果是goodsimg(商品)的图片,灰度到老系统的上传地址
75 if (req.body.bucket === 'goodsimg') { 89 if (req.body.bucket === 'goodsimg') {
76 - req.body.filename = req.files[req.body.filename].path; 90 + //req.body.filename = req.files[req.body.filename].path;
77 request.post({ 91 request.post({
78 url: oldUploadUrl, 92 url: oldUploadUrl,
79 formData: { 93 formData: {
80 - fileData: req.body.file, 94 + fileData: req.body.files,
81 project: req.body.bucket 95 project: req.body.bucket
82 } 96 }
83 - }, function(error, resd, body) { 97 + }, function (error, resd, body) {
84 if (!error && resd.statusCode == 200) { 98 if (!error && resd.statusCode == 200) {
85 var ret = JSON.parse(body); 99 var ret = JSON.parse(body);
86 if (ret.code === 200) { 100 if (ret.code === 200) {
87 - var imgUrl = ret.data.imagesList[0]; 101 + //var imgUrl = ret.data.imagesList[0];
  102 + var imgs = ret.data.imagesList || [];
  103 + var datas = [];
  104 + for (var i = 0; i < imgs.length; i++) {
  105 + datas.push(joinimg(imgs[i]))
  106 + }
88 res.json({ 107 res.json({
89 code: 200, 108 code: 200,
90 - data: joinimg(imgUrl), 109 + data: datas[0],
  110 + datas:datas,
  111 + names: req.body.fileNames,
91 message: '上传成功', 112 message: '上传成功',
92 status: true 113 status: true
93 }); 114 });
@@ -97,12 +118,12 @@ exports.uploadFile = function(req, res) { @@ -97,12 +118,12 @@ exports.uploadFile = function(req, res) {
97 res.json(errBackMsg); 118 res.json(errBackMsg);
98 }); 119 });
99 } else { 120 } else {
100 - 121 + req.body.file = fs.createReadStream(req.files[req.body.filename].path);
  122 + // delete req.body.files;
101 request.post({ 123 request.post({
102 url: domain + '/fileupload/upload', 124 url: domain + '/fileupload/upload',
103 formData: req.body 125 formData: req.body
104 }, function optionalCallback(error, httpResponse, body) { 126 }, function optionalCallback(error, httpResponse, body) {
105 - console.log(body);  
106 if (!error && httpResponse.statusCode == 200) { 127 if (!error && httpResponse.statusCode == 200) {
107 var json = JSON.parse(body); 128 var json = JSON.parse(body);
108 json.status = true; 129 json.status = true;
@@ -119,7 +140,7 @@ exports.uploadFile = function(req, res) { @@ -119,7 +140,7 @@ exports.uploadFile = function(req, res) {
119 message: "请求类型错误" 140 message: "请求类型错误"
120 }); 141 });
121 } 142 }
122 -} 143 +};
123 144
124 /** 145 /**
125 * 组合全路径的图片地址 146 * 组合全路径的图片地址
@@ -128,22 +149,42 @@ function joinimg(url) { @@ -128,22 +149,42 @@ function joinimg(url) {
128 var urlArr = url.split('/'); 149 var urlArr = url.split('/');
129 var domain = 'static.yhbimg.com/goodsimg'; 150 var domain = 'static.yhbimg.com/goodsimg';
130 var num = urlArr[urlArr.length - 1].substr(1, 1); 151 var num = urlArr[urlArr.length - 1].substr(1, 1);
131 - var url = domain + url; 152 + var url1 = domain + url;
132 if (num == 1) { 153 if (num == 1) {
133 - return 'http://img11.' + url; 154 + return 'http://img11.' + url1;
134 } else { 155 } else {
135 - return 'http://img12.' + url; 156 + return 'http://img12.' + url1;
136 } 157 }
137 } 158 }
138 159
139 - 160 +// exports.getSaveState=function(req,res){
  161 +// console.log("6666666");
  162 +// request.post({
  163 +// url: domain + '/product/queryBatchImportResult',
  164 +// formData: req.body
  165 +// }, function optionalCallback(error, httpResponse, body) {
  166 +// console.log(body);
  167 +// if (error) {
  168 +// return console.error('upload failed:', error);
  169 +// }
  170 +// if (!error && httpResponse.statusCode == 200) {
  171 +// var json = JSON.parse(body);
  172 +// json.status = true;
  173 +// // console.log(json);
  174 +// res.json(json);
  175 +// } else {
  176 +// res.json(errBackMsg);
  177 +// }
  178 +// });
  179 +// }
140 180
141 exports.ueditor = function(req, res) { 181 exports.ueditor = function(req, res) {
142 - var headers = getHeader(req,res); 182 +
  183 + var headers = getHeader(req, res);
143 184
144 if (req.is("multipart/form-data")) { 185 if (req.is("multipart/form-data")) {
145 req.body.file = fs.createReadStream(req.files.upfile.path); 186 req.body.file = fs.createReadStream(req.files.upfile.path);
146 - req.body.bucket = "goodsimg"; 187 + req.body.bucket="goodsimg";
147 request.post({ 188 request.post({
148 url: domain + '/fileupload/upload', 189 url: domain + '/fileupload/upload',
149 formData: req.body 190 formData: req.body
@@ -153,18 +194,15 @@ exports.ueditor = function(req, res) { @@ -153,18 +194,15 @@ exports.ueditor = function(req, res) {
153 // {"originalName":"018da7232374448d10a565fdfe6211d078.jpg","name":"","url":"","type":".jpg","state":"SUCCESS"} 194 // {"originalName":"018da7232374448d10a565fdfe6211d078.jpg","name":"","url":"","type":".jpg","state":"SUCCESS"}
154 if (!error && httpResponse.statusCode == 200) { 195 if (!error && httpResponse.statusCode == 200) {
155 var json = JSON.parse(body); 196 var json = JSON.parse(body);
156 - var result = {};  
157 - result.originalName = json.data.substring(json.data.lastIndexOf('/') + 1);  
158 - result.name = result.originalName;  
159 - result.url = json.data;  
160 - result.type = json.data.substring(json.data.lastIndexOf('.'));  
161 - result.state = json.message == "上传成功" ? "SUCCESS" : "FAIL"; 197 + var result={};
  198 + result.originalName=json.data.substring(json.data.lastIndexOf('/')+1);
  199 + result.name=result.originalName;
  200 + result.url=json.data;
  201 + result.type=json.data.substring(json.data.lastIndexOf('.'));
  202 + result.state=json.message=="上传成功"?"SUCCESS":"FAIL";
162 res.send(JSON.stringify(result)); 203 res.send(JSON.stringify(result));
163 - } else {  
164 - res.send({  
165 - code: "500",  
166 - message: "接口异常"  
167 - }); 204 + }else{
  205 + res.send({code:"500",message:"接口异常"});
168 } 206 }
169 }); 207 });
170 208
@@ -177,7 +215,7 @@ exports.ueditor = function(req, res) { @@ -177,7 +215,7 @@ exports.ueditor = function(req, res) {
177 } 215 }
178 216
179 exports.linkFile = function(req, res) { 217 exports.linkFile = function(req, res) {
180 - request.get(domain + "/common/" + req.params.name + ".xlsx").pipe(res); 218 + request.get(domain+"/common/"+req.params.name+".xlsx").pipe(res);
181 } 219 }
182 220
183 exports.downFile = function(req, res) { 221 exports.downFile = function(req, res) {
@@ -192,3 +230,7 @@ exports.downFile = function(req, res) { @@ -192,3 +230,7 @@ exports.downFile = function(req, res) {
192 }; 230 };
193 request(options).pipe(res); 231 request(options).pipe(res);
194 } 232 }
  233 +exports.getJSONFile=function(req,res){
  234 + console.log(searchDomain);
  235 + request.get("http://192.168.10.64:8080/yohosearch/brand/list.json").pipe(res);
  236 +}