Authored by weiqingting

提交

... ... @@ -43,6 +43,7 @@ var apiCofig = {
//root:__dirname,
EnvConst:{
domain:"http://192.168.102.210:8088/platform",
//domain:"http://172.16.6.225:8080/platform",
yohoSearch: 'http://192.168.102.216:8080/yohosearch',
system:Iaccount
},
... ...
... ... @@ -80,6 +80,7 @@ module.exports={
{name: 'maxSortId', type: 'Number'},
{name: 'middleSortId', type: 'Number'},
{name: 'smallSortId', type: 'Number'},
{name: 'seasons', type: 'String'},
{name: 'productStandardRelationStr', type: 'String'}
]
},
... ...
... ... @@ -46,7 +46,11 @@
title:"店铺装修详情保存",
url:"/ShopsDecoratorRest/saveShopsDecorator",
params:[
{name: 'shopsId', type: 'Number'}
{name: 'shopsId', type: 'Number'},
{name: 'submitStatus', type: 'Number'},
{name: 'platform', type: 'String'},
{name: 'templateType', type: 'String'},
{name: 'resources', type: 'String'}
]
},
... ...
... ... @@ -102,10 +102,6 @@ function __requestApi(config, apiOpt, req, callback) {
for (var i in o) {
fns.push(o[i]);
}
//return apiOpt.call(0, req, function (err, result) {
// req._yoheaders = req._yoheaders;
// return callback(null, result);
//});
return apiOpt.apply(0, [req, function (err, result) {
req._yoheaders = req._yoheaders;
return callback(null, result);
... ... @@ -113,43 +109,15 @@ function __requestApi(config, apiOpt, req, callback) {
}
var options = __requestOption(req, apiOpt, config, me.CONSTS);
Request(options, function (error, response, body) {
var _err_ = new Error();
if (error) {
console.info("Error [request"+options.url+"]:" + options.title);
console.error(error);
return callback(error, null);
}
try {
if (response && response.statusCode === 200) {
var obj = JSON.parse(body)
if (!(typeof obj == "object")) {
_err_.message = "Error[json parse@" + options.title + "--"+options.url+"]:" + body;
console.info(_err_.message);
console.error(_err_);
return callback(_err_, null);
}
} else {
_err_.message = "Error[response state @" + options.title + "--"+options.url+"]:" + response;
console.log(response);
console.info(_err_.message);
console.error(_err_);
return callback(_err_, null);
}
} catch (err) {
console.info("Error[response to json @" + options.title + "--"+options.url+"]");
console.info(response);
console.error(err);
return callback(err, null);
}
return callback(null, JSON.parse(body));
});
__sendRequest(options, function (result) {
return callback(null, result);
}, function (result) {
return callback(result, null);
}, {len:1}, 0, []);
};
function __requestOption(req, apiOpt, config, consts) {
var method = (apiOpt.method || "POST").toLocaleUpperCase();
var method = (apiOpt.method || "POST").toLocaleUpperCase(), errs = [];
var data = {};
if (apiOpt.params && (_.isArray(apiOpt.params) || _.isPlainObject(apiOpt.params))) {
if (_.isArray(apiOpt.params)) {
... ... @@ -169,6 +137,7 @@ function __requestOption(req, apiOpt, config, consts) {
});
} else
if (_.isPlainObject(apiOpt.params)) {
var fns = [];
for (var name in apiOpt.params) {
if (req.param("@" + name)) {
continue;
... ... @@ -180,10 +149,34 @@ function __requestOption(req, apiOpt, config, consts) {
if (req.param(name)) {
data[name] = param.type(req.param(name));
}
if (param.coerce && typeof param.coerce == "function") {
fns.push({ param: param,name:name});
}
}
fns.forEach(function (fn) {
var d = fn.param.coerce.call(data, req);
if (d) {
data[fn.name] = param.type(d);
}
});
//验证
for (var name in apiOpt.params) {
var param = apiOpt.params[name];
if (param.required && !data[name]) {
errs.push("params "+name + "is required!!!");
}
if (param.validator&&typeof param.validator=="function") {
var isSuc = param.validator.call(data, data[name]);
if (isSuc===false) {
errs.push("params " +name + " validator error!!!");
}
}
}
}
}
var options = { method: method };
options.errs = errs;
options.title = apiOpt.title || '';
options.outobj = apiOpt.outobj || '';
if (options.method == "GET") {
... ... @@ -340,12 +333,20 @@ queue.prototype = {
},
}
function __sendRequest(options, success, fail,wlen,i,args) {
function __sendRequest(options, success, fail, wlen, i, args) {
var _err_ = new Error(), obj;
if (options.errs instanceof Array&&options.errs.length) {
_err_.message = options.errs.join(',');
console.info("Error [options" + options.url + "]:" + options.title);
console.error(_err_);
wlen.len = 0;
fail && fail(_err_);
return;
}
Request(options, function (error, response, body) {
if (!wlen.len) {
return;
}
var _err_ = new Error(), obj;
if (error) {
console.info("Error [request"+options.url+"]:" + options.title);
console.error(error);
... ...