Authored by 陈轩

fix im bug

... ... @@ -85,3 +85,37 @@ exports.fetchOrderList = (uid, createTimeBegin) => {
return ImAPI.get('/api/order/queryLastTenOrder', params);
};
/**
*
新建评价信息
### url
```
{host}/evalute/saveEvalute
```
### 请求参数说明
| 名称 | 类型 | 是否必须 | 描述 |
| -------------- | ------ | ---- | --------------- |
| conversationId | long | Y | 会话id |
| uid | int | Y | 用户ID |
|encryptedUid | String |Y |加密的用户标识 |
| promoter | int | Y | 评价发起者 1 用户 2 客服 |
| stars | int | Y | 评分星级 |
| reasonIds | string | N | 固定原因Id用冒号隔开 |
| reasonMsgs | string | N | 固定原因用分号隔开 |
| reasonMsg | string | N | 其他原因 |
*/
exports.saveEvalute = (uid, conversationId, promoter, stars) => {
let params = {
conversationId,
uid,
encryptedUid: encryptedUid(uid),
promoter,
stars
};
return ImAPI.post('/api/evalute/saveEvalute', params);
};
... ...
... ... @@ -111,3 +111,22 @@ exports.fetchOrders = (req, res) => {
});
};
exports.saveEvalute = (req, res) => {
const uid = req.user.uid;
const conversationId = req.body.conversationId;
const promoter = req.body.promoter;
const stars = req.body.stars;
imApi.saveEvalute(uid, conversationId, promoter, stars)
.then(result => {
return res.json(result);
}, () => {
return res.json({
code: 500,
message: '评价失败'
});
});
};
... ...
... ... @@ -23,6 +23,7 @@ router.get('/im/fetchHistory', chat.fetchHistory);
router.get('/getOrders', chat.getOrders);
router.get('/order-list', chat.fetchOrders);
router.post('/leavemsg/save.json', chat.saveMSG);
router.post('/im/saveEvalute', chat.saveEvalute);
router.get('/chatQaList', chatQa.qaList); // 问题搜索列表页
router.get('/qaSearch', chatQa.qaSearch); // 问题搜索页
... ...
... ... @@ -19,6 +19,15 @@ module.exports = () => {
req.user.uid = cookie.getUid(req);
}
// app 特殊读法
if (!req.user.uid && req.yoho.isApp) {
let userAgent = _.get(req.headers, 'user-agent', '');
if (userAgent.indexOf('YohoBuy') >= 0) {
req.user.uid = req.cookies._YOHOUID || 0;
}
}
next();
};
};
... ...
... ... @@ -199,6 +199,7 @@ var chat = {
this.$ratingView.on('click', '.submit', function() {
self.ratingView.post({
uid,
encryptedUid,
conversationId: cmEntity.conversationId,
});
... ...
... ... @@ -35,6 +35,10 @@ EventEmitter.prototype = {
EventEmitter.prototype.constructer = EventEmitter;
function buildAPPUid(data) {
}
// api interface
//--------------------------------------------------------
... ... @@ -72,6 +76,10 @@ let api = {
endTime && (data.endTime = endTime);
return $.get(url, data);
},
saveEvalute: function(data) {
return $.post('/service/im/saveEvalute', data);
}
};
... ...
const loading = require('../../plugin/loading'),
tip = require('plugin/tip'),
lazyLoad = require('yoho-jquery-lazyload');
require('../../common');
import {EventEmitter, bus, api} from './store';
import {EventEmitter, api} from './store';
const LeaveMSGView = function(elem) {
... ... @@ -47,7 +48,11 @@ LeaveMSGView.prototype = $.extend({}, EventEmitter.prototype, {
*/
submit() {
let self = this;
let content = this.$input.val();
let content = $.trim(this.$input.val());
if (!content) {
return;
}
api.leaveMsg(content)
.done(function() {
... ... @@ -83,12 +88,14 @@ RatingView.prototype = $.extend({}, EventEmitter.prototype, {
this.elem
.on('click.RatingView.rating', '.stars i', function(event) {
self.rating($(event.target));
let starVal = $(this).index();
self.rating(starVal);
})
.on('click.RatingView.close', '.close', $.proxy(this.toggle, this, false));
},
rating($rank) {
rating(starVal) {
const rankMap = {
0: '非常不满意',
1: '不满意',
... ... @@ -97,14 +104,13 @@ RatingView.prototype = $.extend({}, EventEmitter.prototype, {
4: '非常满意',
};
const curVal = this.rank = $rank.index();
this.rankText = rankMap[curVal];
this.$label.text(rankMap[curVal]);
this.rank = starVal;
this.rankText = rankMap[starVal] || rankMap[3];
this.$label.text(this.rankText);
this.$ranks.removeClass('rated');
this.$ranks.toggleClass(index => {
return index <= curVal ? 'rated' : null;
return index <= starVal ? 'rated' : null;
});
},
... ... @@ -118,24 +124,26 @@ RatingView.prototype = $.extend({}, EventEmitter.prototype, {
};
Object.assign(params, data);
$.ajax({
type: 'POST',
url: 'http://192.168.102.18:60101/api/evalute/saveEvalute',
data: params,
success: function(res) {
api.saveEvalute(params)
.done(res => {
if (res && res.code === 200) {
elem.hide();
elem.trigger('rating-success', [self.rankText]);
}
},
error: function() {
return;
}
tip.show('评价失败');
})
.fail(()=> {
tip.show('评价失败');
});
},
toggle(willShow) {
this.elem.toggle(willShow);
this.rating(3);
}
});
... ...