Authored by huangyi

客服红包

1 const redbagModel = require('../models/red-envelope'); 1 const redbagModel = require('../models/red-envelope');
2 const headerModel = require('../../../doraemon/models/header'); // 头部model 2 const headerModel = require('../../../doraemon/models/header'); // 头部model
3 const valid = require('../../../utils/validator'); 3 const valid = require('../../../utils/validator');
4 -const logger = global.yoho.logger;  
5 4
6 const redbagPage = async(req, res, next) => { 5 const redbagPage = async(req, res, next) => {
7 try { 6 try {
8 let isApp = req.yoho.isApp; 7 let isApp = req.yoho.isApp;
9 - let obj = {uid: req.user.uid || false, shareCode: req.query.shareCode || 'c80f714bf980bdc8'}; // TODO 删除测试数据 8 + let obj = {uid: req.user.uid || false, shareCode: req.query.shareCode || ''};
10 9
11 - console.log(obj);  
12 let isWechat = await req.ctx(redbagModel).isWechatService(obj); 10 let isWechat = await req.ctx(redbagModel).isWechatService(obj);
13 11
14 - console.log(isWechat);  
15 if (isWechat) { 12 if (isWechat) {
16 let userInfo = await req.ctx(redbagModel).renderByCs(obj); 13 let userInfo = await req.ctx(redbagModel).renderByCs(obj);
17 -  
18 - if (userInfo.data && userInfo.data.rewardType === 1) {  
19 - userInfo.data.rewardType = true;  
20 - } else if (userInfo.data && userInfo.data.rewardType === 2) {  
21 - userInfo.data.rewardType = false; 14 + let isGetRedBag = false;
  15 +
  16 + if (userInfo.code === 200) {
  17 + isGetRedBag = true;
  18 + if (userInfo.data && userInfo.data.rewardType === 1) {
  19 + userInfo.data.rewardType = true;
  20 + } else if (userInfo.data && userInfo.data.rewardType === 2) {
  21 + userInfo.data.rewardType = false;
  22 + }
22 } 23 }
23 - console.log(userInfo);  
24 return res.render('red-envelope/redbag-cs', { 24 return res.render('red-envelope/redbag-cs', {
25 pageHeader: headerModel.setNav({ 25 pageHeader: headerModel.setNav({
26 navTitle: '红包-客服' 26 navTitle: '红包-客服'
27 }), 27 }),
28 isApp, 28 isApp,
  29 + isGetRedBag,
29 width750: true, 30 width750: true,
30 localCss: true, 31 localCss: true,
31 module: 'activity', 32 module: 'activity',
@@ -86,34 +87,28 @@ const receiveRedBag = async(req, res, next) => { @@ -86,34 +87,28 @@ const receiveRedBag = async(req, res, next) => {
86 return next(error); 87 return next(error);
87 } 88 }
88 }; 89 };
89 -const submitWxCode = async(req, res) => { 90 +
  91 +const submitWxCode = async(req, res, next) => {
90 try { 92 try {
91 let obj = {uid: req.user.uid || null, 93 let obj = {uid: req.user.uid || null,
92 - shareCode: req.body.shareCode || '', 94 + userUid: req.body.userUid || '',
93 userCode: req.body.userCode || ''}; 95 userCode: req.body.userCode || ''};
94 96
95 obj = valid(obj, { 97 obj = valid(obj, {
96 uid: {type: 'uid', empty: false}, 98 uid: {type: 'uid', empty: false},
97 - shareCode: {type: 'String', empty: false}, 99 + userUid: {type: 'number', empty: false},
98 userCode: {type: 'String', empty: false} 100 userCode: {type: 'String', empty: false}
99 }); 101 });
100 102
101 - let userInfo = await req.ctx(redbagModel).renderByCs(obj);  
102 -  
103 - obj.userInfo = userInfo.data;  
104 let result = await req.ctx(redbagModel).submitWxCode(obj); 103 let result = await req.ctx(redbagModel).submitWxCode(obj);
105 104
106 - return res.json({code: 200, data: result, result: true});  
107 - } catch (e) {  
108 - logger.error(e);  
109 - return res.json(e); 105 + return res.json(result);
  106 + } catch (error) {
  107 + return next(error);
110 } 108 }
111 }; 109 };
112 110
113 111
114 -  
115 -  
116 -  
117 module.exports = { 112 module.exports = {
118 redbagPage, 113 redbagPage,
119 receiveRedBag, 114 receiveRedBag,
1 -const logger = global.yoho.logger;  
2 1
3 class redEnvelopeModel extends global.yoho.BaseModel { 2 class redEnvelopeModel extends global.yoho.BaseModel {
4 constructor(ctx) { 3 constructor(ctx) {
@@ -26,48 +25,31 @@ class redEnvelopeModel extends global.yoho.BaseModel { @@ -26,48 +25,31 @@ class redEnvelopeModel extends global.yoho.BaseModel {
26 } 25 }
27 26
28 async renderByCs(obj) { 27 async renderByCs(obj) {
29 - try {  
30 - let result = this.get({  
31 - data: {  
32 - method: 'app.passport.getUserInfoByShareCode',  
33 - uid: obj.uid,  
34 - shareCode: obj.shareCode  
35 - }  
36 - });  
37 -  
38 - if (result.code) {  
39 - return Promise.resolve({code: 200, result: true, data: result.data});  
40 - } else {  
41 - logger.error(result);  
42 - return Promise.reject({code: 301, result: false, msg: '数据错误'}); 28 + let result = await this.get({
  29 + data: {
  30 + method: 'app.passport.getUserInfoByShareCode',
  31 + uid: obj.uid,
  32 + shareCode: obj.shareCode
43 } 33 }
44 - } catch (e) {  
45 - logger.error(e);  
46 - return Promise.reject({code: 301, result: false, msg: '数据错误'}); 34 + });
  35 +
  36 + if (result.code === 200) {
  37 + return Promise.resolve({code: 200, data: result.data, result: true});
  38 + } else {
  39 + return Promise.resolve(result);
47 } 40 }
  41 +
48 } 42 }
49 43
50 async submitWxCode(obj) { 44 async submitWxCode(obj) {
51 - try {  
52 - let result = this.get({  
53 - data: {  
54 - method: 'app.passport.submitUserWechatCode',  
55 - uid: obj.userInfo,  
56 - wechat_uid: obj.uid,  
57 - userCode: obj.userCode  
58 - }  
59 - });  
60 -  
61 - if (result.code) {  
62 - return Promise.resolve({code: 200, result: true, data: result.data});  
63 - } else {  
64 - logger.error(result);  
65 - return Promise.reject({code: 301, result: false, msg: '数据错误'}); 45 + return await this.get({
  46 + data: {
  47 + method: 'app.passport.submitUserWechatCode',
  48 + uid: obj.userUid,
  49 + wechat_uid: obj.uid,
  50 + userCode: obj.userCode
66 } 51 }
67 - } catch (e) {  
68 - logger.error(e);  
69 - return Promise.reject({code: 301, result: false, msg: '数据错误'});  
70 - } 52 + });
71 } 53 }
72 54
73 async renderByUser({uid, shareCode}) { 55 async renderByUser({uid, shareCode}) {
@@ -116,7 +98,6 @@ class redEnvelopeModel extends global.yoho.BaseModel { @@ -116,7 +98,6 @@ class redEnvelopeModel extends global.yoho.BaseModel {
116 } 98 }
117 }); 99 });
118 } 100 }
119 -  
120 } 101 }
121 102
122 module.exports = redEnvelopeModel; 103 module.exports = redEnvelopeModel;
1 <div class="content-service"> 1 <div class="content-service">
2 - <div class="coupon-desc">  
3 - <div>{{userInfo.userName}},已成功获取</div>  
4 - {{#if userInfo.rewardType }}  
5 - <div class="desc-li">{{userInfo.couponName}}</div>  
6 - {{else}}  
7 - <div class="desc-li">{{userInfo.rewardName}}</div>  
8 - {{/if}}  
9 - <div class="desc-li">{{userInfo.recievedTime}}</div>  
10 - </div>  
11 - <div class="user-info">  
12 - <div class="copy-account">  
13 - <div class="account">普通 500031262</div>  
14 - <button>点击复制</button> 2 +{{#if isGetRedBag}}
  3 + <div class="user-coupon-info">
  4 + <input type="hidden" id="uid" value="{{userInfo.uid}}"/>
  5 + <div class="coupon-desc">
  6 + <div>{{userInfo.userName}},已成功获取</div>
  7 + {{#if userInfo.rewardType }}
  8 + <div class="desc-li">{{userInfo.couponName}}</div>
  9 + {{else}}
  10 + <div class="desc-li">{{userInfo.rewardName}}</div>
  11 + {{/if}}
  12 + <div class="desc-li">{{userInfo.recievedTime}}</div>
  13 + </div>
  14 + <div class="user-info">
  15 + <div class="copy-account">
  16 + <div class="account">{{userInfo.vipLevel}} {{userInfo.uid}}</div>
  17 + <button class="copy">点击复制</button>
  18 + </div>
  19 + {{#if userInfo.related}}
  20 + <div class="wx-account">
  21 + <input placeholder="请输入用户微信号" class="account-input" bindinput="bindAccount" value="{{account}}"/>
  22 + <button class="submitWxAccount">提交微信</button>
  23 + </div>
  24 + {{/if}}
  25 + <div class="wx-account-info">
  26 + {{#if userInfo.submitWechat}}
  27 + <div>已提交微信号:{{userInfo.userWechatCode}}</div>
  28 + {{else}}
  29 + <div>未提交微信</div>
  30 + {{/if}}
  31 + </div>
  32 + </div>
  33 + <div class="user-label">
  34 + <div class="title">用户标签</div>
  35 + <div>
  36 + <span class="label">{{userInfo.tag_address}}</span>
  37 + <span class="label">{{userInfo.tag_createTime}}</span>
  38 + </div>
  39 + </div>
  40 + <div class="relation-list">
  41 + <div class="title">已关联潮流顾问</div>
  42 + {{#each userInfo.relatedWechatList}}
  43 + <div class="list-item">
  44 + <span class="item-jqm">{{machineCode}}</span>
  45 + <span class="item-wx-acount">{{wechatCode}}</span>
  46 + </div>
  47 + {{/each}}
15 </div> 48 </div>
16 - {{#if userInfo.submitWechat}}  
17 - <div class="wx-account-info">已提交微信号:wsling2</div>  
18 - {{else}}  
19 - <div>未提交微信</div>  
20 - {{/if}}  
21 </div> 49 </div>
22 - <div class="user-label">  
23 - <div class="title">用户标签</div>  
24 - <div class="label">天津</div>  
25 - <div class="label">201803注册</div>  
26 </div> 50 </div>
27 - <div class="relation-list">  
28 - <div class="title">已关联潮流顾问</div>  
29 - <div class="list-item">  
30 - <span class="item-jqm">111123</span>  
31 - <span class="item-wx-acount">123123</span>  
32 - </div> 51 +{{else}}
  52 + <div class="no-box">
  53 + <div class="no-received">
  54 + <image src="http://img12.static.yhbimg.com/sns/2018/09/20/10/02f45a44a7dc9012468441eae604f1c910.png" class="no-icon"/>
  55 + <div class="no-txt">礼包尚未被领取</div>
  56 + <div class="no-txt">可以微信提醒用户尽快领取!</div>
33 </div> 57 </div>
34 </div> 58 </div>
  59 +{{/if}}
35 </div> 60 </div>
@@ -18,7 +18,7 @@ let channels = { @@ -18,7 +18,7 @@ let channels = {
18 lifestyle: 4 18 lifestyle: 4
19 }; 19 };
20 20
21 -exports.index = (req, res, next) => { 21 +exports.index = async(req, res, next) => {
22 let responseData = { 22 let responseData = {
23 isLogin: req.user.uid ? true : false, 23 isLogin: req.user.uid ? true : false,
24 module: 'home', 24 module: 'home',
@@ -46,12 +46,26 @@ exports.index = (req, res, next) => { @@ -46,12 +46,26 @@ exports.index = (req, res, next) => {
46 (req.cookies._Channel && channels[req.cookies._Channel]) || 1 46 (req.cookies._Channel && channels[req.cookies._Channel]) || 1
47 }; 47 };
48 48
49 - req.ctx(newHomeModel).index(params).then(result => {  
50 - // 为你优选开关  
51 - let recommendHide = _.get(req.app.locals.wap, 'ucenter.removePrefer', false); 49 + try {
  50 + let isWxcs = false, shareUrl = '';
52 51
  52 + if (req.user.uid !== null) {
  53 + isWxcs = await req.ctx(newHomeModel).checkCs(req.user.uid);
  54 + }
  55 + if (isWxcs) {
  56 + let shareCode = await req.ctx(newHomeModel).getShareCode(req.user.uid);
  57 +
  58 + shareUrl = '/activity/red-envelope/index?shareCode=' + shareCode.data;
  59 + }
  60 + let result = await req.ctx(newHomeModel).index(params);
  61 + let recommendHide = await _.get(req.app.locals.wap, 'ucenter.removePrefer', false);
  62 +
  63 + responseData.isWxcs = isWxcs;
  64 + responseData.shareUrl = shareUrl;
53 res.render('new-home', Object.assign(responseData, result, { 65 res.render('new-home', Object.assign(responseData, result, {
54 recommendHide: recommendHide 66 recommendHide: recommendHide
55 })); 67 }));
56 - }).catch(next); 68 + } catch (e) {
  69 + return next(e);
  70 + }
57 }; 71 };
@@ -131,7 +131,32 @@ class newHome extends global.yoho.BaseModel { @@ -131,7 +131,32 @@ class newHome extends global.yoho.BaseModel {
131 } 131 }
132 }); 132 });
133 } 133 }
  134 + async checkCs(uid) {
  135 + let isWechatService = false; // 是否是微信客服
134 136
  137 + if (uid !== null || uid !== undefined) {
  138 + // 校验是客服还是用户 y则是客服
  139 + let ret = await this.get({
  140 + data: {
  141 + method: 'app.passport.checkIsWechatCs',
  142 + uid,
  143 + }
  144 + });
  145 +
  146 + if (ret && ret.code && ret.code === 200) {
  147 + isWechatService = ret.data.isWechatService === 'Y' ? true : false;
  148 + }
  149 + }
  150 + return Promise.resolve(isWechatService);
  151 + }
  152 + getShareCode(uid) {
  153 + return this.get({
  154 + data: {
  155 + method: 'app.passport.getWechatShareCode',
  156 + uid
  157 + }
  158 + });
  159 + }
135 index(params) { 160 index(params) {
136 return Promise.all([ 161 return Promise.all([
137 this._userData(params), 162 this._userData(params),
@@ -154,6 +154,16 @@ @@ -154,6 +154,16 @@
154 <div class="arr iconfont">&#xe604;</div> 154 <div class="arr iconfont">&#xe604;</div>
155 </div> 155 </div>
156 </a> 156 </a>
  157 + {{#if @root.isWxcs}}
  158 + <a class="list-item" id="wxcs" data-url="{{@root.shareUrl}}">
  159 + <div class="pic iconfont">&#xe730;</div>
  160 + <div class="body">
  161 + <div class="main eps">潮流顾问专属分享</div>
  162 + <div class="value"></div>
  163 + <div class="arr iconfont">&#xe604;</div>
  164 + </div>
  165 + </a>
  166 + {{/if}}
157 </div> 167 </div>
158 {{/ infoNum}} 168 {{/ infoNum}}
159 <div class="ad-pic res-c clearfix"> 169 <div class="ad-pic res-c clearfix">
@@ -179,4 +189,4 @@ @@ -179,4 +189,4 @@
179 <div class="yoho-footer wechat-footer"> 189 <div class="yoho-footer wechat-footer">
180 <div class="float-top"></div> 190 <div class="float-top"></div>
181 </div> 191 </div>
182 -{{/if}}  
  192 +{{/if}}
@@ -68,6 +68,7 @@ @@ -68,6 +68,7 @@
68 "feed": "^1.1.0", 68 "feed": "^1.1.0",
69 "geetest": "^4.1.2", 69 "geetest": "^4.1.2",
70 "handlebars": "^4.0.11", 70 "handlebars": "^4.0.11",
  71 + "js": "^0.1.0",
71 "lodash": "^4.17.5", 72 "lodash": "^4.17.5",
72 "memory-cache": "^0.2.0", 73 "memory-cache": "^0.2.0",
73 "moment": "^2.22.1", 74 "moment": "^2.22.1",
1 require('scss/activity/redbag-cs.page.scss'); 1 require('scss/activity/redbag-cs.page.scss');
  2 +import $ from 'yoho-jquery';
  3 +import tip from 'js/plugin/tip';
  4 +import Clipboard from 'clipboard';
2 5
  6 +// 提交微信客服账号
  7 +$('.submitWxAccount').click(function() {
  8 + let userCode = $('.account-input')[0].value;
3 9
  10 + if (!userCode) {
  11 + tip.show('请输入用户微信号');
  12 + return;
  13 + }
  14 +
  15 + $.ajax({
  16 + method: 'POST',
  17 + url: '/activity/red-envelope/submitWxCode',
  18 + data: {
  19 + userUid: parseInt($('#uid')[0].value),
  20 + userCode
  21 + },
  22 + success: function(data) {
  23 + if (data.code === 200) {
  24 + tip.show('提交成功');
  25 + } else {
  26 + tip.show(data.message);
  27 + }
  28 + }
  29 + });
  30 +});
  31 +
  32 +$('.copy').click(function() {
  33 + let clipboard = new Clipboard('.copy', {
  34 + text: function() {
  35 + return document.getElementsByClassName('account')[0].innerText;
  36 + }
  37 + });
  38 +
  39 + clipboard.on('success', function(e) {
  40 + e.clearSelection();
  41 + tip.show('复制成功');
  42 + });
  43 +
  44 + clipboard.on('error', function() {
  45 + tip.show('复制失败');
  46 + });
  47 +});
@@ -6,6 +6,8 @@ import 'js/common/set-trend-world'; @@ -6,6 +6,8 @@ import 'js/common/set-trend-world';
6 import Swiper from 'yoho-swiper2'; 6 import Swiper from 'yoho-swiper2';
7 import yoho from 'js/yoho-app'; 7 import yoho from 'js/yoho-app';
8 import AutoScroll from './new-home/auto-scroll'; 8 import AutoScroll from './new-home/auto-scroll';
  9 +import Clipboard from 'clipboard';
  10 +import tip from 'js/plugin/tip';
9 11
10 class NewHome extends Page { 12 class NewHome extends Page {
11 constructor() { 13 constructor() {
@@ -17,7 +19,8 @@ class NewHome extends Page { @@ -17,7 +19,8 @@ class NewHome extends Page {
17 $resYas: $('.res-c').find('a'), 19 $resYas: $('.res-c').find('a'),
18 $trendCode: $('.trend-code'), 20 $trendCode: $('.trend-code'),
19 $floatTop: $('.float-top'), 21 $floatTop: $('.float-top'),
20 - $recommendC: $('#new-recommend-c') 22 + $recommendC: $('#new-recommend-c'),
  23 + $wxcs: $('#wxcs')
21 }; 24 };
22 25
23 this.init(); 26 this.init();
@@ -30,9 +33,30 @@ class NewHome extends Page { @@ -30,9 +33,30 @@ class NewHome extends Page {
30 this.showTrend(); 33 this.showTrend();
31 this.autoScroll(); 34 this.autoScroll();
32 this.backToTop(); 35 this.backToTop();
  36 + this.copyShareUrl();
33 window.reMarginFooter('.footer-tab'); 37 window.reMarginFooter('.footer-tab');
34 } 38 }
35 39
  40 + copyShareUrl() {
  41 + this.selector.$wxcs.click(function() {
  42 + let clipboard = new Clipboard('#wxcs', {
  43 + text: ()=> {
  44 + return location.origin + $(this).attr('data-url');
  45 + }
  46 + });
  47 +
  48 + clipboard.on('success', function(e) {
  49 + e.clearSelection();
  50 + tip.show('复制分享地址成功');
  51 + });
  52 +
  53 + clipboard.on('error', function() {
  54 + tip.show('复制失败');
  55 + });
  56 +
  57 + });
  58 + }
  59 +
36 backToTop() { 60 backToTop() {
37 if (this.selector.$recommendC.length > 0) { 61 if (this.selector.$recommendC.length > 0) {
38 $(document).scroll(() => { 62 $(document).scroll(() => {
@@ -28,7 +28,6 @@ body { @@ -28,7 +28,6 @@ body {
28 28
29 .content-service { 29 .content-service {
30 margin: 30px; 30 margin: 30px;
31 - background: #fff;  
32 height: 100%; 31 height: 100%;
33 } 32 }
34 33
@@ -172,3 +171,32 @@ body { @@ -172,3 +171,32 @@ body {
172 padding-left: 24px; 171 padding-left: 24px;
173 display: inline-block; 172 display: inline-block;
174 } 173 }
  174 +
  175 +.no-box {
  176 + padding: 348px 0 0;
  177 +}
  178 +
  179 +.no-received {
  180 + width: 670px;
  181 + height: 372px;
  182 + margin: 0 auto;
  183 +}
  184 +
  185 +.no-txt {
  186 + color: #b0b0b0;
  187 + font-size: 36px;
  188 + font-family: PingFang-SC-Bold, sans-serif;
  189 + text-align: center;
  190 +}
  191 +
  192 +.no-icon {
  193 + width: 240px;
  194 + height: 240px;
  195 + display: block;
  196 + margin: 0 auto 40px;
  197 +}
  198 +
  199 +.user-coupon-info {
  200 + background: #fff;
  201 + height: 87vh;
  202 +}