Authored by yyq

complaints

... ... @@ -17,7 +17,7 @@ const index = (req, res, next) => {
let uid = req.user.uid;
let page = req.query.page || 1;
complaints.getComplaintsList(uid, page).then(result => {
req.ctx(complaints).getComplaintsList(uid, page).then(result => {
res.render('complaints', result);
}).catch(next);
};
... ... @@ -36,7 +36,7 @@ const submit = (req, res, next) => {
return next();
}
complaints.addComplaints(uid, params).then(result => {
req.ctx(complaints).addComplaints(uid, params).then(result => {
res.json(result);
}).catch(next);
};
... ... @@ -55,7 +55,7 @@ const cancel = (req, res, next) => {
return next();
}
complaints.cancelComplaints(uid, id).then(result => {
req.ctx(complaints).cancelComplaints(uid, id).then(result => {
res.json(result);
}).catch(next);
};
... ...
/**
* @author: weiqingting<qingting.wei@yoho.cn>
*/
'use strict';
const api = global.yoho.API;
const getByNodeContent = (node, mode)=>{
mode = mode || 'release';
let options = {
method: 'web.html.content',
mode: mode,
node: node
};
return api.get('', options);
};
module.exports = {
getByNodeContent
};
... ... @@ -5,8 +5,6 @@
*/
'use strict';
const api = global.yoho.API;
const _ = require('lodash');
const Promise = require('bluebird');
... ... @@ -20,106 +18,116 @@ const complaintType = {
2: '物流相关'
};
/**
* 获取投诉列表
* @function getComplaintsList
* @param { Number } uid 用户uid
* @param { Number } page 页码
* @param { Number } limit 每页数目
* @return { Object } 投诉列表数据
*/
const getComplaintsList = (uid, page, limit) => {
page = page || 1;
limit = limit || 10;
const process = function*() {
let resData = {};
let result = yield api.get('', {
method: 'web.complaints.getList',
uid: uid,
page: page,
limit: limit
}, {code: 200});
if (!_.isEmpty(result.data)) {
let list = [];
_.forEach(_.get(result, 'data.complaintList', []), value => {
list.push({
id: value.id,
title: value.title,
target: value.customer,
type: complaintType[value.complaintsType],
order: value.orderCode,
time: value.createTime,
question: value.content,
reply: value.reply,
replyTime: value.replyTime,
revoke: value.status === -1
});
});
if (_.isEmpty(list)) {
resData.complaints = {empty: '您尚未投诉任何内容'};
} else {
resData.complaints = list;
}
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 获取投诉列表
* @function getComplaintsList
* @param { Number } uid 用户uid
* @param { Number } page 页码
* @param { Number } limit 每页数目
* @return { Object } 投诉列表数据
*/
getComplaintsList(uid, page, limit) {
page = page || 1;
limit = limit || 10;
const process = function*() {
let resData = {};
let result = yield this.get({
data: {
method: 'web.complaints.getList',
uid: uid,
page: page,
limit: limit
},
param: {
cache: 200
}
});
resData.pager = Object.assign({
count: _.get(result, 'data.total', 0),
curPage: page,
totalPages: _.get(result, 'data.page_total', 0)
}, setPager(_.get(result, 'data.page_total', 0), {
page: page
}));
if (!_.isEmpty(result.data)) {
let list = [];
_.forEach(_.get(result, 'data.complaintList', []), value => {
list.push({
id: value.id,
title: value.title,
target: value.customer,
type: complaintType[value.complaintsType],
order: value.orderCode,
time: value.createTime,
question: value.content,
reply: value.reply,
replyTime: value.replyTime,
revoke: value.status === -1
});
});
if (!_.get(resData, 'pager.pages[1]')) {
_.unset(resData, 'pager.pages');
if (_.isEmpty(list)) {
resData.complaints = {empty: '您尚未投诉任何内容'};
} else {
resData.complaints = list;
}
resData.pager = Object.assign({
count: _.get(result, 'data.total', 0),
curPage: page,
totalPages: _.get(result, 'data.page_total', 0)
}, setPager(_.get(result, 'data.page_total', 0), {
page: page
}));
if (!_.get(resData, 'pager.pages[1]')) {
_.unset(resData, 'pager.pages');
}
}
}
return resData;
};
return co(process)();
};
/**
* 添加投诉
* @function addComplaints
* @param { Number } uid 用户uid
* @param { Object } params 投诉内容信息
* @return { Object } 添加投诉结果
*/
const addComplaints = (uid, params) => {
return api.post('', {
method: 'web.complaints.add',
uid: uid,
title: _.trim(params.title),
customer: _.trim(params.customer),
complaintsType: _.trim(params.complaintsType),
orderCode: _.trim(params.orderCode),
content: _.trim(params.content)
});
};
/**
* 撤销投诉
* @function addComplaints
* @param { Number } uid 用户uid
* @param { Number } id 投诉id
* @return { Object } 撤销投诉结果
*/
const cancelComplaints = (uid, id) => {
return api.post('', {
method: 'web.complaints.cancel',
uid: uid,
id: id
});
};
module.exports = {
getComplaintsList,
addComplaints,
cancelComplaints
return resData;
};
return co(process)();
}
/**
* 添加投诉
* @function addComplaints
* @param { Number } uid 用户uid
* @param { Object } params 投诉内容信息
* @return { Object } 添加投诉结果
*/
addComplaints(uid, params) {
return this.post({
data: {
method: 'web.complaints.add',
uid: uid,
title: _.trim(params.title),
customer: _.trim(params.customer),
complaintsType: _.trim(params.complaintsType),
orderCode: _.trim(params.orderCode),
content: _.trim(params.content)
}
});
}
/**
* 撤销投诉
* @function addComplaints
* @param { Number } uid 用户uid
* @param { Number } id 投诉id
* @return { Object } 撤销投诉结果
*/
cancelComplaints(uid, id) {
return this.post({
data: {
method: 'web.complaints.cancel',
uid: uid,
id: id
}
});
}
};
... ...