Authored by huangyi

客服红包

const redbagModel = require('../models/red-envelope');
const headerModel = require('../../../doraemon/models/header'); // 头部model
const valid = require('../../../utils/validator');
const logger = global.yoho.logger;
const redbagPage = async(req, res, next) => {
try {
let isApp = req.yoho.isApp;
let obj = {uid: req.user.uid || false, shareCode: req.query.shareCode || 'c80f714bf980bdc8'}; // TODO 删除测试数据
let obj = {uid: req.user.uid || false, shareCode: req.query.shareCode || ''};
console.log(obj);
let isWechat = await req.ctx(redbagModel).isWechatService(obj);
console.log(isWechat);
if (isWechat) {
let userInfo = await req.ctx(redbagModel).renderByCs(obj);
if (userInfo.data && userInfo.data.rewardType === 1) {
userInfo.data.rewardType = true;
} else if (userInfo.data && userInfo.data.rewardType === 2) {
userInfo.data.rewardType = false;
let isGetRedBag = false;
if (userInfo.code === 200) {
isGetRedBag = true;
if (userInfo.data && userInfo.data.rewardType === 1) {
userInfo.data.rewardType = true;
} else if (userInfo.data && userInfo.data.rewardType === 2) {
userInfo.data.rewardType = false;
}
}
console.log(userInfo);
return res.render('red-envelope/redbag-cs', {
pageHeader: headerModel.setNav({
navTitle: '红包-客服'
}),
isApp,
isGetRedBag,
width750: true,
localCss: true,
module: 'activity',
... ... @@ -86,34 +87,28 @@ const receiveRedBag = async(req, res, next) => {
return next(error);
}
};
const submitWxCode = async(req, res) => {
const submitWxCode = async(req, res, next) => {
try {
let obj = {uid: req.user.uid || null,
shareCode: req.body.shareCode || '',
userUid: req.body.userUid || '',
userCode: req.body.userCode || ''};
obj = valid(obj, {
uid: {type: 'uid', empty: false},
shareCode: {type: 'String', empty: false},
userUid: {type: 'number', empty: false},
userCode: {type: 'String', empty: false}
});
let userInfo = await req.ctx(redbagModel).renderByCs(obj);
obj.userInfo = userInfo.data;
let result = await req.ctx(redbagModel).submitWxCode(obj);
return res.json({code: 200, data: result, result: true});
} catch (e) {
logger.error(e);
return res.json(e);
return res.json(result);
} catch (error) {
return next(error);
}
};
module.exports = {
redbagPage,
receiveRedBag,
... ...
const logger = global.yoho.logger;
class redEnvelopeModel extends global.yoho.BaseModel {
constructor(ctx) {
... ... @@ -26,48 +25,31 @@ class redEnvelopeModel extends global.yoho.BaseModel {
}
async renderByCs(obj) {
try {
let result = this.get({
data: {
method: 'app.passport.getUserInfoByShareCode',
uid: obj.uid,
shareCode: obj.shareCode
}
});
if (result.code) {
return Promise.resolve({code: 200, result: true, data: result.data});
} else {
logger.error(result);
return Promise.reject({code: 301, result: false, msg: '数据错误'});
let result = await this.get({
data: {
method: 'app.passport.getUserInfoByShareCode',
uid: obj.uid,
shareCode: obj.shareCode
}
} catch (e) {
logger.error(e);
return Promise.reject({code: 301, result: false, msg: '数据错误'});
});
if (result.code === 200) {
return Promise.resolve({code: 200, data: result.data, result: true});
} else {
return Promise.resolve(result);
}
}
async submitWxCode(obj) {
try {
let result = this.get({
data: {
method: 'app.passport.submitUserWechatCode',
uid: obj.userInfo,
wechat_uid: obj.uid,
userCode: obj.userCode
}
});
if (result.code) {
return Promise.resolve({code: 200, result: true, data: result.data});
} else {
logger.error(result);
return Promise.reject({code: 301, result: false, msg: '数据错误'});
return await this.get({
data: {
method: 'app.passport.submitUserWechatCode',
uid: obj.userUid,
wechat_uid: obj.uid,
userCode: obj.userCode
}
} catch (e) {
logger.error(e);
return Promise.reject({code: 301, result: false, msg: '数据错误'});
}
});
}
async renderByUser({uid, shareCode}) {
... ... @@ -116,7 +98,6 @@ class redEnvelopeModel extends global.yoho.BaseModel {
}
});
}
}
module.exports = redEnvelopeModel;
... ...
<div class="content-service">
<div class="coupon-desc">
<div>{{userInfo.userName}},已成功获取</div>
{{#if userInfo.rewardType }}
<div class="desc-li">{{userInfo.couponName}}</div>
{{else}}
<div class="desc-li">{{userInfo.rewardName}}</div>
{{/if}}
<div class="desc-li">{{userInfo.recievedTime}}</div>
</div>
<div class="user-info">
<div class="copy-account">
<div class="account">普通 500031262</div>
<button>点击复制</button>
{{#if isGetRedBag}}
<div class="user-coupon-info">
<input type="hidden" id="uid" value="{{userInfo.uid}}"/>
<div class="coupon-desc">
<div>{{userInfo.userName}},已成功获取</div>
{{#if userInfo.rewardType }}
<div class="desc-li">{{userInfo.couponName}}</div>
{{else}}
<div class="desc-li">{{userInfo.rewardName}}</div>
{{/if}}
<div class="desc-li">{{userInfo.recievedTime}}</div>
</div>
<div class="user-info">
<div class="copy-account">
<div class="account">{{userInfo.vipLevel}} {{userInfo.uid}}</div>
<button class="copy">点击复制</button>
</div>
{{#if userInfo.related}}
<div class="wx-account">
<input placeholder="请输入用户微信号" class="account-input" bindinput="bindAccount" value="{{account}}"/>
<button class="submitWxAccount">提交微信</button>
</div>
{{/if}}
<div class="wx-account-info">
{{#if userInfo.submitWechat}}
<div>已提交微信号:{{userInfo.userWechatCode}}</div>
{{else}}
<div>未提交微信</div>
{{/if}}
</div>
</div>
<div class="user-label">
<div class="title">用户标签</div>
<div>
<span class="label">{{userInfo.tag_address}}</span>
<span class="label">{{userInfo.tag_createTime}}</span>
</div>
</div>
<div class="relation-list">
<div class="title">已关联潮流顾问</div>
{{#each userInfo.relatedWechatList}}
<div class="list-item">
<span class="item-jqm">{{machineCode}}</span>
<span class="item-wx-acount">{{wechatCode}}</span>
</div>
{{/each}}
</div>
{{#if userInfo.submitWechat}}
<div class="wx-account-info">已提交微信号:wsling2</div>
{{else}}
<div>未提交微信</div>
{{/if}}
</div>
<div class="user-label">
<div class="title">用户标签</div>
<div class="label">天津</div>
<div class="label">201803注册</div>
</div>
<div class="relation-list">
<div class="title">已关联潮流顾问</div>
<div class="list-item">
<span class="item-jqm">111123</span>
<span class="item-wx-acount">123123</span>
</div>
{{else}}
<div class="no-box">
<div class="no-received">
<image src="http://img12.static.yhbimg.com/sns/2018/09/20/10/02f45a44a7dc9012468441eae604f1c910.png" class="no-icon"/>
<div class="no-txt">礼包尚未被领取</div>
<div class="no-txt">可以微信提醒用户尽快领取!</div>
</div>
</div>
{{/if}}
</div>
... ...
... ... @@ -18,7 +18,7 @@ let channels = {
lifestyle: 4
};
exports.index = (req, res, next) => {
exports.index = async(req, res, next) => {
let responseData = {
isLogin: req.user.uid ? true : false,
module: 'home',
... ... @@ -46,12 +46,26 @@ exports.index = (req, res, next) => {
(req.cookies._Channel && channels[req.cookies._Channel]) || 1
};
req.ctx(newHomeModel).index(params).then(result => {
// 为你优选开关
let recommendHide = _.get(req.app.locals.wap, 'ucenter.removePrefer', false);
try {
let isWxcs = false, shareUrl = '';
if (req.user.uid !== null) {
isWxcs = await req.ctx(newHomeModel).checkCs(req.user.uid);
}
if (isWxcs) {
let shareCode = await req.ctx(newHomeModel).getShareCode(req.user.uid);
shareUrl = '/activity/red-envelope/index?shareCode=' + shareCode.data;
}
let result = await req.ctx(newHomeModel).index(params);
let recommendHide = await _.get(req.app.locals.wap, 'ucenter.removePrefer', false);
responseData.isWxcs = isWxcs;
responseData.shareUrl = shareUrl;
res.render('new-home', Object.assign(responseData, result, {
recommendHide: recommendHide
}));
}).catch(next);
} catch (e) {
return next(e);
}
};
... ...
... ... @@ -131,7 +131,32 @@ class newHome extends global.yoho.BaseModel {
}
});
}
async checkCs(uid) {
let isWechatService = false; // 是否是微信客服
if (uid !== null || uid !== undefined) {
// 校验是客服还是用户 y则是客服
let ret = await this.get({
data: {
method: 'app.passport.checkIsWechatCs',
uid,
}
});
if (ret && ret.code && ret.code === 200) {
isWechatService = ret.data.isWechatService === 'Y' ? true : false;
}
}
return Promise.resolve(isWechatService);
}
getShareCode(uid) {
return this.get({
data: {
method: 'app.passport.getWechatShareCode',
uid
}
});
}
index(params) {
return Promise.all([
this._userData(params),
... ...
... ... @@ -154,6 +154,16 @@
<div class="arr iconfont">&#xe604;</div>
</div>
</a>
{{#if @root.isWxcs}}
<a class="list-item" id="wxcs" data-url="{{@root.shareUrl}}">
<div class="pic iconfont">&#xe730;</div>
<div class="body">
<div class="main eps">潮流顾问专属分享</div>
<div class="value"></div>
<div class="arr iconfont">&#xe604;</div>
</div>
</a>
{{/if}}
</div>
{{/ infoNum}}
<div class="ad-pic res-c clearfix">
... ... @@ -179,4 +189,4 @@
<div class="yoho-footer wechat-footer">
<div class="float-top"></div>
</div>
{{/if}}
\ No newline at end of file
{{/if}}
... ...
... ... @@ -68,6 +68,7 @@
"feed": "^1.1.0",
"geetest": "^4.1.2",
"handlebars": "^4.0.11",
"js": "^0.1.0",
"lodash": "^4.17.5",
"memory-cache": "^0.2.0",
"moment": "^2.22.1",
... ...
require('scss/activity/redbag-cs.page.scss');
import $ from 'yoho-jquery';
import tip from 'js/plugin/tip';
import Clipboard from 'clipboard';
// 提交微信客服账号
$('.submitWxAccount').click(function() {
let userCode = $('.account-input')[0].value;
if (!userCode) {
tip.show('请输入用户微信号');
return;
}
$.ajax({
method: 'POST',
url: '/activity/red-envelope/submitWxCode',
data: {
userUid: parseInt($('#uid')[0].value),
userCode
},
success: function(data) {
if (data.code === 200) {
tip.show('提交成功');
} else {
tip.show(data.message);
}
}
});
});
$('.copy').click(function() {
let clipboard = new Clipboard('.copy', {
text: function() {
return document.getElementsByClassName('account')[0].innerText;
}
});
clipboard.on('success', function(e) {
e.clearSelection();
tip.show('复制成功');
});
clipboard.on('error', function() {
tip.show('复制失败');
});
});
... ...
... ... @@ -6,6 +6,8 @@ import 'js/common/set-trend-world';
import Swiper from 'yoho-swiper2';
import yoho from 'js/yoho-app';
import AutoScroll from './new-home/auto-scroll';
import Clipboard from 'clipboard';
import tip from 'js/plugin/tip';
class NewHome extends Page {
constructor() {
... ... @@ -17,7 +19,8 @@ class NewHome extends Page {
$resYas: $('.res-c').find('a'),
$trendCode: $('.trend-code'),
$floatTop: $('.float-top'),
$recommendC: $('#new-recommend-c')
$recommendC: $('#new-recommend-c'),
$wxcs: $('#wxcs')
};
this.init();
... ... @@ -30,9 +33,30 @@ class NewHome extends Page {
this.showTrend();
this.autoScroll();
this.backToTop();
this.copyShareUrl();
window.reMarginFooter('.footer-tab');
}
copyShareUrl() {
this.selector.$wxcs.click(function() {
let clipboard = new Clipboard('#wxcs', {
text: ()=> {
return location.origin + $(this).attr('data-url');
}
});
clipboard.on('success', function(e) {
e.clearSelection();
tip.show('复制分享地址成功');
});
clipboard.on('error', function() {
tip.show('复制失败');
});
});
}
backToTop() {
if (this.selector.$recommendC.length > 0) {
$(document).scroll(() => {
... ...
... ... @@ -28,7 +28,6 @@ body {
.content-service {
margin: 30px;
background: #fff;
height: 100%;
}
... ... @@ -172,3 +171,32 @@ body {
padding-left: 24px;
display: inline-block;
}
.no-box {
padding: 348px 0 0;
}
.no-received {
width: 670px;
height: 372px;
margin: 0 auto;
}
.no-txt {
color: #b0b0b0;
font-size: 36px;
font-family: PingFang-SC-Bold, sans-serif;
text-align: center;
}
.no-icon {
width: 240px;
height: 240px;
display: block;
margin: 0 auto 40px;
}
.user-coupon-info {
background: #fff;
height: 87vh;
}
... ...