123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- var token = '';
- var lunboList = ''
- var content = ''
- var level = ''
- var nextUrl = ''
- var html = null;//页面
- var time = null;
- var ua = "";
- $().ready(function () {
- getToken()
- // callBackMethodName()
- // userInfo()//测试
- if(!token){
- $("#other").hide()
- $("#newUser").show()
- getList()
- }
- // 判断是否是微信
- ua = navigator.userAgent.toLowerCase();//获取判断用的对象
- if (ua.match(/MicroMessenger/i) == "micromessenger") {
- //在微信中打开
- writeLogH5({action:'enter-upload',channel:'H5',url:window.location.href});//埋点
- $("#bottom").html(`
- <div id="button" onclick="nextPage('upload')">
- 下载猎豆,赚取佣金
- </div>
- `)
- } else {
- if(!token) {
- writeLogH5({action:'enter-double',channel:'H5',url:window.location.href});//进入翻倍埋点
- }
- $("#bottom").html(`
- <div id="buttonOne" onclick="nextPage('share','1')">
- <img src="./img/weixin.png" class="smaIcon">
- 分享给好友
- </div>
- <div id="buttonOne" onclick="nextPage('share','2')">
- <img src="./img/pengyouquan.png" class="smaIcon">
- 分享到朋友圈
- </div>
- `)
- }
- })
- function getToken() {
- var param = '{"js_callback" : "callBackMethodName"}';
- try {
- if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
- window.webkit.messageHandlers.app_h5_login.postMessage(param);
- }
- if (navigator.userAgent.match(/android/i)) {
- obj4H5.app_h5_login(param);
- }
- } catch (e) {
- //TODO handle the exception
- }
- }
- function callBackMethodName(data) {//app token 回调
- var data = JSON.parse(data); //上线时添加
- token=data.token; //上线时添加
- // token='4d0abd9cfaed33c77bcaf11bbb61378c257552'
- if(token){
- getLevel();// 判断用户等级(上线时在token中调)
- }else {
- $("#other").hide()
- $("#newUser").show()
- getList()
- }
- }
- function getLevel() {
- $.ajax({
- type: 'post',
- url: '/api/v2/pullTheNewUser/oldOrNewUser',
- headers: {
- 'token': token
- },
- data: {
- 'token': token
- },
- success: function (res) {
- if (res && res.errno == 0) {
- if (res.rst.level >= 3) {
- $("#newUser").hide()
- $("#other").show()
- userInfo()
- count_down('2019-1-1 00:00:00')
- writeLogH5({action:'enter-specail',channel:'H5',url:window.location.href});//进入瓜分埋点
- } else {
- $("#other").hide()
- $("#newUser").show()
- getList()
- writeLogH5({action:'enter-double',channel:'H5',url:window.location.href});//进入翻倍埋点
- }
- }
- },
- fail: function () {
- console.log("fail")
- }
- })
- }
- function getList() {
- $.ajax({
- type: 'post',
- url: '/api/v2/pullTheNewUser/newUserInfo',
- success: function (res) {
- if (res && res.errno == 0) {
- lunboList = res.rst.orderInfo
- content=''
- for (var i in lunboList) {
- if(lunboList[i].nickname.length>4){
- lunboList[i].nickname=lunboList[i].nickname.substring(0, 2)+"..."
- }
- if(lunboList[i].orderRebate!=0){
- content += `
- <div class="swiper-slide">
- 恭喜
- <img class="avatar" src="`+ lunboList[i].headimgurl + `" alt="">
- <span class="name">`+ lunboList[i].nickname + `</span>
- 获得
- <span class="orderRebate">`+ lunboList[i].orderRebate + `</span>元购物佣金+
- <span class="rewardMoney">`+ lunboList[i].rewardMoeny + `</span>元奖励佣金
- </div>
- `
- }else {
- content += `
- <div class="swiper-slide">
- 恭喜
- <img class="avatar" src="`+ lunboList[i].headimgurl + `" alt="">
- <span class="name">`+ lunboList[i].nickname + `</span>
- 邀请新用户下单获得`+lunboList[i].rewardMoeny+`元奖励佣金
- </div>
- `
- }
- }
- $("#wrapper").html(content)
- swiper()
- }
- },
- fail: function () {
- }
- })
- }
- function userInfo() {
- $.ajax({
- type: 'post',
- url: '/api/v2/pullTheNewUser/userLogin',
- dataType: 'json',
- headers: {
- 'token': token,
- },
- data: {
- 'token': token
- },
- success: function (res) {
- if (res && res.errno == 0) {
- content = `
- <div class="img">
- <img class="avatar" src="`+ res.rst.headimgurl + `" alt="">
- </div>
- <div class="right">
- <span class="descri">`+ res.rst.desc + `</span>
- </div>
- `
- odometer.innerHTML = Number(res.rst.oneUserMoney);
- $("#info").html(content)
- }
- },
- fail: function () {
- }
- })
- }
- function nextPage(str,data) {
- // 埋点
- if(str=='share'){
- // 佣金翻倍显示
- if(!$("#newUser").is(":hidden")) {
- writeLogH5({action:'christmas-double-share',channel:'H5',url:window.location.href});// 佣金翻倍
- }else {
- writeLogH5({action:'christmas-specail-share',channel:'H5',url:window.location.href});//运营商
- }
- }else if(str=='upload') {
- writeLogH5({action:'christmas-upload',channel:'H5',url:window.location.href});//埋点
- }
- ua = navigator.userAgent.toLowerCase();//获取判断用的对象
- if (ua.match(/MicroMessenger/i) == "micromessenger") {
- //在微信中打开
- window.location.href = "http://a.app.qq.com/o/simple.jsp?pkgname=com.kuxuan.coupon_liedou"
- } else {
- // 没有token
- if(!token){
- getToken()
- }else {
- $.ajax({
- type: 'post',
- url: '/api/v2/pullTheNewUser/shareToFriend',
- dataType: 'json',
- headers: {
- 'token': token,
- },
- data: {
- 'token': token
- },
- success: function (res) {
- nextUrl = res.rst.url
- if (res && res.errno == 0) {
- // 判断时候在微信
- shareWechatUrl(data)
- }
- },
- fail: function () {
- }
- })
- }
- }
- }
- // 倒计时
- function count_down(o) {
- // $("#test").html(o);
- time = setTimeout(function () { count_down(o) }, 1000);
- var datatime = /^[\d]{4}-[\d]{1,2}-[\d]{1,2}( [\d]{1,2}:[\d]{1,2}(:[\d]{1,2})?)?$/ig, str = '', conn, s;
- if (!o.match(datatime)) {
- // alert('参数格式为2020-01-01[ 01:01[:01]].\r其中[]内的内容可省略');
- return false;
- }
- var sec = (new Date(o.replace(/-/ig, '/')).getTime() - new Date().getTime()) / 1000;
- // $("#test1").text(sec)
- if (sec == 0 || sec < 0) {
- html = `<img class="img" src="https://kx-youhuiquan.oss-cn-beijing.aliyuncs.com/shuangshiyi/chaojihongbao/yure_hongbao.png" />`
- $('.daojishi').html(html);
- $(".button").addClass('buttonActive');
- $(".button").click(function () {
- copyPassword();
- })
- clearTimeout(time);
- } else {
- s = { '天': sec / 24 / 3600, '时': Math.floor(sec / 3600 % 24), '分': Math.floor(sec / 60 % 60) };
- for (i in s) {
- if (s[i] < 10) { s[i] = '0' + s[i] };
- if (i != '天') {
- str += '<span>' + s[i] + '</span>' + i;
- } else {
- str += '<span>' + parseInt(s[i]) + '</span>' + i;
- }
- }
- $("#count").html(str)
- }
- }
- //分享到微信url
- function shareWechatUrl(data) {
- var param = {
- "shareImageUrl": "https://kx-youhuiquan.oss-cn-beijing.aliyuncs.com/lieodu_gw/ldyx.png",
- "shareTitle": "领完券再返钱,佣金翻倍0元购",
- "shareDescirpt": "帮你发现隐藏优惠券,下单还能返双倍佣金",
- "shareUrl": nextUrl,//详情链接
- "shareType": data //1:微信好友 2:朋友圈
- }
- param = JSON.stringify(param)
- if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
- window.webkit.messageHandlers.app_h5_wx_share_url.postMessage(param);
- }
- if (navigator.userAgent.match(/android/i)) {
- obj4H5.app_h5_wx_share_url(param);
- }
- }
- // 滚动
- function swiper() {
- var mySwiper = new Swiper(".dirList", {
- autoplay: true,
- loop: true,
- slidesPerView: 2,
- slidesPerGroup: 2,
- speed: 5000,
- initialSlide:0,
- direction: 'vertical'
- })
- }
- // 弹框显示
- function showMsg(msg) {
- var msgBox = document.getElementsByClassName('alert-info')[0];
- msgBox.children[0].innerText = msg;
- msgBox.style.display="block";
- setTimeout(function() {
- msgBox.style.display="none";
- }, 1500);
- }
- // h5埋点
- function writeLogH5 (data) {
- $.ajax({
- type:'post',
- url:'/api/v2/channel/writeLogH5',
- dataType:'json',
- data:data,
- success:function (res) {
- }
- })
- }
|