Authored by hongyong.zhao

Merge branch 'feature/first-buy-share' into 'release/6.9.8'

活动模板新增分享组件及分享领券相关功能



See merge request !3
... ... @@ -117,6 +117,56 @@ exports.couponSend = (req, res, next) => {
}).catch(next);
};
/**
* 分享领券活动模板领券接口
* @param req
* @param res
* @param next
* @returns {*}
*/
exports.webShareCouponSend = (req, res, next) => {
let uid = req.user.uid,
app = req.query.app || {},
activityId = req.query.activityId,
templateId = req.query.templateId;
let resultData = {
code: 403,
message: '参数错误',
data: ''
};
if (req.yoho.isApp || app.client_type === 'miniapp') {
if (app.app_version && app.client_type && app.session_key && app.uid) {
// 小程序调接口获取 session 的方式不同,H5 嵌小程序,client_type 标记为 h5
let isMiniApp = app.client_type === 'miniapp';
uid = {
toString: () => {
return _.parseInt(app.uid);
},
sessionKey: app.session_key,
appVersion: isMiniApp ? _.get(global, 'yoho.config.appVersion') : app.app_version,
appSessionType: app.client_type
};
}
}
if (uid === '' || uid === 0 || !parseInt(activityId, 10) || !parseInt(templateId, 10)) {
return res.jsonp(resultData);
}
req.ctx(model).couponSendWebShare(activityId, templateId, uid).then(result => {
res.set({
'Cache-Control': 'no-cache',
Pragma: 'no-cache',
Expires: (new Date(1900, 0, 1, 0, 0, 0, 0)).toUTCString()
});
res.jsonp(result);
}).catch(next);
};
exports.redenvelope = (req, res, next) => {
let token = req.query.token || '',
uid = req.user.uid,
... ...
... ... @@ -446,6 +446,15 @@ class featureModel extends global.yoho.BaseModel {
}
}
if (componentType === 'share') { // 分享模板
f.component[0].webShare = data.webShare;
if (f.component[0].share_template_id) {
f.component[0].webShare.url =
data.webShare.url.substring(0, data.webShare.url.lastIndexOf('/')) + '/' +
f.component[0].share_template_id + '.html';
}
}
let set = new Set();
_.forEach(f.component, component => {
... ...
... ... @@ -284,6 +284,7 @@ router.get('/feature/:code.html', feature.index);
router.get('/featuresidebar/:code.html', feature.sidebar);
router.get('/featurebottombar/:code.html', feature.bottombar);
router.get('/feature/couponSend', feature.couponSend); // 获取优惠券
router.get('/feature/webShareCouponSend', feature.webShareCouponSend); // 活动模板分享领取优惠券, 不用分券类型,不用传券ID
router.get('/tide/category', auth, tide.category); // 潮品推介
router.get('/tide/shop', auth, tide.shop); // 潮牌推介
router.get('/feature/redenvelope', feature.redenvelope); // 获取红包
... ...
... ... @@ -248,6 +248,10 @@
{{! 秒杀}}
{{> feature/seckill}}
{{/isEqualOr}}
{{#isEqualOr type 'share'}}<!--分享模板-->
{{> feature/web-share}}
{{/isEqualOr}}
{{/component}}
</div>
{{/isEqualOr}}
... ...
<!--活动模板分享领券组件-->
<div class="web-share">
{{#webShare}}
<a href="javascript:void(0)" class="web-share-button" data-stid="{{../share_template_id}}" data-scoupon="{{../share_condition}}"
data-spic="{{pic}}" data-sdesc="{{content}}" data-stitle="{{title}}" data-surl="{{url}}" data-slanding="{{../landing_attr}}"></a>
{{/webShare}}
</div>
<div class="web-share-tips-wrapper">
<div class="web-share-tips-container">
<div class="web-share-tips">
<p class="title">提示</p>
<p class="desc"></p>
<div class="web-share-buttons-container">
<a href="javascript:void(0)" class="button-ok">确 定</a>
<a href='https://union.yoho.cn/union/app-downloads.html' class="button-download">打开有货APP</a>
</div>
</div>
</div>
</div>
<div class="web-share-img-wrapper"></div>
... ...
... ... @@ -13,9 +13,9 @@ const isTest = process.env.NODE_ENV === 'test3' || process.env.NODE_ENV === 'tes
const domains = {
api: 'http://api.yoho.cn/',
service: 'http://service.yoho.cn/',
// api: 'http://api.yoho.cn/',
//
// service: 'http://service.yoho.cn/',
// yoLuck: 'https://action.yoho.cn',
... ... @@ -28,8 +28,8 @@ const domains = {
// platformApi: 'http://172.16.6.210:8088/',
// api: 'http://api-test3.dev.yohocorp.com/',
// service: 'http://api-test3.dev.yohocorp.com/',
api: 'http://api-test3.dev.yohocorp.com/',
service: 'http://api-test3.dev.yohocorp.com/',
liveApi: 'http://testapi.live.yohops.com:9999/',
singleApi: 'http://api-test3.dev.yohocorp.com/',
ufo: 'http://java-yohoufo-fore.test3.ingress.dev.yohocorp.com/ufo-gateway/',
... ...
... ... @@ -12,7 +12,7 @@
a.async = 1;
a.src = j;
m.parentNode.insertBefore(a, m);
}(window, document, 'script', (document.location.protocol === 'https:' ? 'https:' : 'http:') + '//cdn.yoho.cn/yas-jssdk/2.4.20/yas.js', '_yas'));
}(window, document, 'script', (document.location.protocol === 'https:' ? 'https:' : 'http:') + '//cdn.yoho.cn/yas-jssdk/2.4.21/yas.js', '_yas'));
var _hmt = _hmt || [];
... ...
/* global wx */
const $ = require('yoho-jquery');
const lazyLoad = require('js/plugin/lazyload');
const Swiper = require('yoho-swiper');
... ... @@ -7,13 +8,327 @@ const cookie = require('yoho-cookie');
const shopTmpl = require('hbs/activity/feature/shop-group.hbs');
const seckillTabTpl = require('hbs/activity/feature/seckill-tab.hbs');
const seckillProductTpl = require('hbs/activity/feature/seckill-product.hbs');
const yo_sdk = require('yoho-activity-sdk');
require('scss/feature.scss');
let isAndroid = /(Android)/i.test(navigator.userAgent);
let isWechat = /micromessenger/i.test(navigator.userAgent);
let isApp = /yohobuy/i.test(navigator.userAgent);
let isWechatMiniProgram = /miniprogram/i.test(navigator.userAgent);
let app_info = {
uid: '0',
session_key: '',
app_version: '',
client_type: ''
};
let appInterface = null;
// 分享领券相关START------------------------------------------------------------
// 用于判断app版本
let versionCompare = {
toVersion: function(str = '') {
let ver = str.split('.').map(function(i) {
return Number(i);
});
if (!ver[0]) {
ver[0] = 0;
}
if (!ver[1]) {
ver[1] = 0;
}
if (!ver[2]) {
ver[2] = 0;
}
return ver;
},
toNumber: function(ver) {
let major = ver[0] * 10000;
let minor = ver[1] * 100;
let patch = ver[2] * 1;
return major + minor + patch;
},
compare: function(left, right) {
if (left > right) {
return 1;
} else if (left < right) {
return -1;
} else {
return 0;
}
},
version: function(left, right) {
let leftVersion = this.toNumber(this.toVersion(left));
let rightVersion = this.toNumber(this.toVersion(right));
let result = this.compare(leftVersion, rightVersion);
return result;
}
};
function closeWebShareTips() { // 关闭提示框
$('.web-share-tips-wrapper').removeClass('show');
$('.web-share-tips-wrapper .desc').text('');
}
function showWebShareTips(text) { // 显示提示框
$('.web-share-tips-wrapper').addClass('show');
$('.web-share-tips-wrapper .desc').text(text);
}
function showShare() {
$('.web-share-img-wrapper').addClass('show');
}
function hideShare() {
$('.web-share-img-wrapper').removeClass('show');
}
function getParams() { // 获取登录相关信息
let app_uid = cookie.get('app_uid') || qs.uid || app_info.uid;
let app_session_key = cookie.get('app_session_key') || qs.session_key || app_info.session_key;
let app_version = cookie.get('app_version') || qs.app_version || '';
let app_client_type = cookie.get('app_client_type') || qs.app_client_type || '';
if (isApp) {
if (/android/i.test(navigator.userAgent)) {
app_client_type = 'android';
}
}
app_info = {
uid: app_uid,
session_key: app_session_key,
app_version: app_version,
client_type: app_client_type
};
}
function getCoupon() { // 分享成功后领券
if (parseInt(app_info.uid, 10)) {
let activityInfo = JSON.parse($('.activity-plan').val());
let data = {
activityId: activityInfo[0].activityId,
templateId: activityInfo[0].templateId,
app: app_info
};
$.ajax({
url: '//m.yohobuy.com/activity/feature/webShareCouponSend',
type: 'get',
dataType: 'jsonp',
data: data,
success: function(result) {
if (result.code === 200) {
showWebShareTips(result.message);
} else if (result.code === 401) {
showWebShareTips('您已领取过该优惠券');
} else if (result.code === 402) {
showWebShareTips('登录信息异常');
} else {
showWebShareTips(result.message);
}
hideShare();
}
});
} else {
showWebShareTips('您还没登录哦');
}
}
function checkShare(shareData) {
if (isApp) {
let newShare = false;
let app_vercode = cookie.get('app_vercode');
let app_version = cookie.get('app_version') || qs.app_version || '';
if (versionCompare.version(app_version, '6.9.5') >= 0 || app_vercode) {
newShare = true;
}
window.successShare = function() {
getCoupon();
};
appInterface.triggerEvent(
function() {},
function() {},
{
method: 'go.showshareaction',
arguments: shareData
}
);
if (!newShare) {
setTimeout(getCoupon, 5000);
}
} else {
showShare();
if (isWechatMiniProgram) {
setTimeout(getCoupon, 6000);
}
}
}
function goLogin(shareData) { // 跳转登录判断
if (isApp) {
let uidParams = {
method: 'get.uid'
};
let sessionIdParams = {
method: 'get.sessionId'
};
appInterface.triggerEvent(function(uid) {
if (!parseInt(uid, 10)) {
yo_sdk.goLogin();
} else {
app_info.uid = uid;
appInterface.triggerEvent(function(sid) {
app_info.session_key = sid;
checkShare(shareData);
}, function() {}, sessionIdParams);
}
}, function() {}, uidParams);
} else {
yo_sdk.goLogin();
}
}
function initWxShare(data) {
let shareData = {
title: data.title,
imgUrl: data.imgUrl,
desc: data.desc,
link: data.link,
success: function() {
setTimeout(getCoupon, 500);
}
};
if (wx) {
setTimeout(function() {
window.wx.ready(function() {
wx.onMenuShareAppMessage(shareData);
wx.onMenuShareTimeline(shareData);
wx.onMenuShareQQ(shareData);
wx.onMenuShareWeibo(shareData);
});
}, 500);
if (isWechatMiniProgram) {
wx.miniProgram.postMessage({
data: {
title: data.title,
imgUrl: data.imgUrl,
link: data.link
}
});
}
}
// yo_sdk.wxShare(shareData);
}
function initWebShareButtons(env = '') { // 初始化分享按钮事件
let webShareData = {
title: $('#shareTitle').val(),
desc: $('#shareImg').val(),
imgUrl: $('#shareDesc').val(),
link: $('#shareLink').val()
};
if ($('.web-share-button')[0]) {
let webShareButton = $('.web-share-button');
webShareData = {
title: webShareButton.data('stitle'),
desc: webShareButton.data('sdesc'),
imgUrl: webShareButton.data('spic'),
link: webShareButton.data('surl').replace('https:', 'http:')
};
}
initWxShare(webShareData);
$('.web-share-button').each(function() {
let webShareButton = $(this);
$(this).on('click', function() {
if (!env) {
showWebShareTips('请在微信中打开');
return;
}
getParams();
webShareData = {
title: webShareButton.data('stitle'),
desc: webShareButton.data('sdesc'),
imgUrl: webShareButton.data('spic'),
link: webShareButton.data('surl').replace('https:', 'http:')
};
$('#shareTitle').val(webShareData.title);
$('#shareImg').val(webShareData.desc);
$('#shareDesc').val(webShareData.imgUrl);
$('#shareLink').val(webShareData.link);
if (isApp) {
Object.assign(webShareData, {
hideType: ['4', '5', '6', '7', '8', '9'],
isCareCallBack: '1',
wxShareMode: parseInt(webShareButton.data('slanding'), 10) ? 'miniprogram' : 'h5',
miniProgramUrl: 'pages/webview/webview?url=' + webShareData.link // 安卓分享小程序会用到
});
}
if (parseInt(app_info.uid, 10)) {
checkShare(webShareData);
} else {
goLogin(webShareData);
}
});
});
$('.web-share-img-wrapper').on('click', hideShare);
}
// 分享领券模板功能初始化
function initWebShare() {
getParams();
$('.web-share-buttons-container .button-ok').on('click', closeWebShareTips);
if (isApp) {
document.addEventListener('deviceready', function() {
appInterface = window.yohoInterface;
if (appInterface) {
initWebShareButtons('app');
}
});
$('.web-share-buttons-container .button-download').hide();
} else if (isWechatMiniProgram) {
$('.web-share-buttons-container .button-download').hide();
initWebShareButtons('miniprogram');
} else if (isWechat) {
initWebShareButtons('wechat');
} else {
initWebShareButtons();
}
}
// 分享领券相关END------------------------------------------------------------
function swiperInit() {
$('.swiper-container').each(function() {
... ... @@ -1120,6 +1435,9 @@ $(function() {
miniProgramHandleInit();
}
// 分享领券
initWebShare();
// 商品曝光事件上报
if (yoho.isApp) {
require('./feature/goods-show-yas-rpter');
... ...
... ... @@ -9,15 +9,16 @@ import {transToMiniappPath} from 'js/common/miniapp-path-rules';
* go.collagehome = 福利团
* go.activitytemplate = 拼团列表
* go.productDetail (带有参数activity_type:groupPurchase) = 拼团商品详情页
* go.ufo = UFO小程序
* @type {[*]}
*/
const jumpAction = ['go.productDetail', 'go.list', 'go.h5', 'go.shop', 'go.poollist',
'go.activitytemplate', 'go.collagehome', 'go.bargainlist', 'go.limitpurchase',
'go.groupProductDetail', 'go.yoluckHome', 'go.yoluckDetail'];
'go.groupProductDetail', 'go.yoluckHome', 'go.yoluckDetail', 'go.ufo'];
class LinkHandle {
constructor() {
$(document).delegate('a:not(.yoho-coin, .yoho-conpon)', 'click', event => {
$(document).delegate('a:not(.yoho-coin, .yoho-conpon, .web-share-button, .button-ok)', 'click', event => {
let $currentTarget = $(event.currentTarget);
let href = $currentTarget.attr('href');
... ...
... ... @@ -9,6 +9,7 @@
@import "scss/feature/redenvelope";
@import "scss/feature/liked-activity";
@import "scss/feature/seckill";
@import "scss/feature/web-share";
/* stylelint-disable */
... ...
.web-share {
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
z-index: 9;
.web-share-button {
display: block;
width: 100%;
height: 100%;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
}
.web-share-tips-wrapper {
display: none;
position: fixed;
width: 100%;
height: 100%;
left: 0;
top: 0;
background-color: rgba(0, 0, 0, 0.7);
z-index: 29;
.web-share-tips-container {
position: absolute;
width: 100%;
height: 400px;
top: 50%;
margin-top: -200px;
.web-share-tips {
position: relative;
margin: 38px auto;
width: 460.8px;
background-color: #fff;
border-radius: 10px;
color: #444;
}
.web-share-tips .title {
font-size: 29px;
line-height: 40.96px;
color: #d0021b;
text-align: center;
padding: 34.1px 51.2px 0 51.2px;
}
.web-share-tips .desc {
min-height: 39.25px;
font-size: 24px;
line-height: 39px;
padding: 14px 51.2px 34.1px 51.2px;
text-align: center;
}
.web-share-tips .web-share-buttons-container {
width: 100%;
height: 75px;
display: flex;
flex-direction: row;
flex: 1;
border-top: 1px solid #e0e0e0;
}
.web-share-tips .web-share-buttons-container a {
width: 100%;
height: 100%;
text-align: center;
line-height: 75px;
font-size: 29px;
text-decoration: none;
color: #444;
}
.web-share-tips .web-share-buttons-container .button-download {
border-left: 1px solid #e0e0e0;
color: #d0021b;
}
}
&.show {
display: block;
}
}
.web-share-img-wrapper {
display: none;
position: fixed;
width: 100%;
height: 100%;
left: 0;
top: 0;
background-color: rgba(0, 0, 0, 0.7);
z-index: 30;
background-image: url("img/activity/feature/share.png");
background-size: contain;
background-position: 0 50%;
background-repeat: no-repeat;
&.show {
display: block;
}
}
... ...