No Description

index.js 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. var token = '';
  2. var lunboList = ''
  3. var content = ''
  4. var level = ''
  5. var nextUrl = ''
  6. var html = null;//页面
  7. var time = null;
  8. var ua = "";
  9. $().ready(function () {
  10. getToken()
  11. // callBackMethodName()
  12. // userInfo()//测试
  13. if(!token){
  14. $("#other").hide()
  15. $("#newUser").show()
  16. getList()
  17. }
  18. // 判断是否是微信
  19. ua = navigator.userAgent.toLowerCase();//获取判断用的对象
  20. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  21. //在微信中打开
  22. writeLogH5({action:'enter-upload',channel:'H5',url:window.location.href});//埋点
  23. $("#bottom").html(`
  24. <div id="button" onclick="nextPage('upload')">
  25. 下载猎豆,赚取佣金
  26. </div>
  27. `)
  28. } else {
  29. if(!token) {
  30. writeLogH5({action:'enter-double',channel:'H5',url:window.location.href});//进入翻倍埋点
  31. }
  32. $("#bottom").html(`
  33. <div id="buttonOne" onclick="nextPage('share','1')">
  34. <img src="./img/weixin.png" class="smaIcon">
  35. 分享给好友
  36. </div>
  37. <div id="buttonOne" onclick="nextPage('share','2')">
  38. <img src="./img/pengyouquan.png" class="smaIcon">
  39. 分享到朋友圈
  40. </div>
  41. `)
  42. }
  43. })
  44. function getToken() {
  45. var param = '{"js_callback" : "callBackMethodName"}';
  46. try {
  47. if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
  48. window.webkit.messageHandlers.app_h5_login.postMessage(param);
  49. }
  50. if (navigator.userAgent.match(/android/i)) {
  51. obj4H5.app_h5_login(param);
  52. }
  53. } catch (e) {
  54. //TODO handle the exception
  55. }
  56. }
  57. function callBackMethodName(data) {//app token 回调
  58. var data = JSON.parse(data); //上线时添加
  59. token=data.token; //上线时添加
  60. // token='4d0abd9cfaed33c77bcaf11bbb61378c257552'
  61. if(token){
  62. getLevel();// 判断用户等级(上线时在token中调)
  63. }else {
  64. $("#other").hide()
  65. $("#newUser").show()
  66. getList()
  67. }
  68. }
  69. function getLevel() {
  70. $.ajax({
  71. type: 'post',
  72. url: '/api/v2/pullTheNewUser/oldOrNewUser',
  73. headers: {
  74. 'token': token
  75. },
  76. data: {
  77. 'token': token
  78. },
  79. success: function (res) {
  80. if (res && res.errno == 0) {
  81. if (res.rst.level >= 3) {
  82. $("#newUser").hide()
  83. $("#other").show()
  84. userInfo()
  85. count_down('2019-1-1 00:00:00')
  86. writeLogH5({action:'enter-specail',channel:'H5',url:window.location.href});//进入瓜分埋点
  87. } else {
  88. $("#other").hide()
  89. $("#newUser").show()
  90. getList()
  91. writeLogH5({action:'enter-double',channel:'H5',url:window.location.href});//进入翻倍埋点
  92. }
  93. }
  94. },
  95. fail: function () {
  96. console.log("fail")
  97. }
  98. })
  99. }
  100. function getList() {
  101. $.ajax({
  102. type: 'post',
  103. url: '/api/v2/pullTheNewUser/newUserInfo',
  104. success: function (res) {
  105. if (res && res.errno == 0) {
  106. lunboList = res.rst.orderInfo
  107. content=''
  108. for (var i in lunboList) {
  109. if(lunboList[i].nickname.length>4){
  110. lunboList[i].nickname=lunboList[i].nickname.substring(0, 2)+"..."
  111. }
  112. if(lunboList[i].orderRebate!=0){
  113. content += `
  114. <div class="swiper-slide">
  115. 恭喜
  116. <img class="avatar" src="`+ lunboList[i].headimgurl + `" alt="">
  117. <span class="name">`+ lunboList[i].nickname + `</span>
  118. 获得
  119. <span class="orderRebate">`+ lunboList[i].orderRebate + `</span>元购物佣金+
  120. <span class="rewardMoney">`+ lunboList[i].rewardMoeny + `</span>元奖励佣金
  121. </div>
  122. `
  123. }else {
  124. content += `
  125. <div class="swiper-slide">
  126. 恭喜
  127. <img class="avatar" src="`+ lunboList[i].headimgurl + `" alt="">
  128. <span class="name">`+ lunboList[i].nickname + `</span>
  129. 邀请新用户下单获得`+lunboList[i].rewardMoeny+`元奖励佣金
  130. </div>
  131. `
  132. }
  133. }
  134. $("#wrapper").html(content)
  135. swiper()
  136. }
  137. },
  138. fail: function () {
  139. }
  140. })
  141. }
  142. function userInfo() {
  143. $.ajax({
  144. type: 'post',
  145. url: '/api/v2/pullTheNewUser/userLogin',
  146. dataType: 'json',
  147. headers: {
  148. 'token': token,
  149. },
  150. data: {
  151. 'token': token
  152. },
  153. success: function (res) {
  154. if (res && res.errno == 0) {
  155. content = `
  156. <div class="img">
  157. <img class="avatar" src="`+ res.rst.headimgurl + `" alt="">
  158. </div>
  159. <div class="right">
  160. <span class="descri">`+ res.rst.desc + `</span>
  161. </div>
  162. `
  163. odometer.innerHTML = Number(res.rst.oneUserMoney);
  164. $("#info").html(content)
  165. }
  166. },
  167. fail: function () {
  168. }
  169. })
  170. }
  171. function nextPage(str,data) {
  172. // 埋点
  173. if(str=='share'){
  174. // 佣金翻倍显示
  175. if(!$("#newUser").is(":hidden")) {
  176. writeLogH5({action:'christmas-double-share',channel:'H5',url:window.location.href});// 佣金翻倍
  177. }else {
  178. writeLogH5({action:'christmas-specail-share',channel:'H5',url:window.location.href});//运营商
  179. }
  180. }else if(str=='upload') {
  181. writeLogH5({action:'christmas-upload',channel:'H5',url:window.location.href});//埋点
  182. }
  183. ua = navigator.userAgent.toLowerCase();//获取判断用的对象
  184. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  185. //在微信中打开
  186. window.location.href = "http://a.app.qq.com/o/simple.jsp?pkgname=com.kuxuan.coupon_liedou"
  187. } else {
  188. // 没有token
  189. if(!token){
  190. getToken()
  191. }else {
  192. $.ajax({
  193. type: 'post',
  194. url: '/api/v2/pullTheNewUser/shareToFriend',
  195. dataType: 'json',
  196. headers: {
  197. 'token': token,
  198. },
  199. data: {
  200. 'token': token
  201. },
  202. success: function (res) {
  203. nextUrl = res.rst.url
  204. if (res && res.errno == 0) {
  205. // 判断时候在微信
  206. shareWechatUrl(data)
  207. }
  208. },
  209. fail: function () {
  210. }
  211. })
  212. }
  213. }
  214. }
  215. // 倒计时
  216. function count_down(o) {
  217. // $("#test").html(o);
  218. time = setTimeout(function () { count_down(o) }, 1000);
  219. var datatime = /^[\d]{4}-[\d]{1,2}-[\d]{1,2}( [\d]{1,2}:[\d]{1,2}(:[\d]{1,2})?)?$/ig, str = '', conn, s;
  220. if (!o.match(datatime)) {
  221. // alert('参数格式为2020-01-01[ 01:01[:01]].\r其中[]内的内容可省略');
  222. return false;
  223. }
  224. var sec = (new Date(o.replace(/-/ig, '/')).getTime() - new Date().getTime()) / 1000;
  225. // $("#test1").text(sec)
  226. if (sec == 0 || sec < 0) {
  227. html = `<img class="img" src="https://kx-youhuiquan.oss-cn-beijing.aliyuncs.com/shuangshiyi/chaojihongbao/yure_hongbao.png" />`
  228. $('.daojishi').html(html);
  229. $(".button").addClass('buttonActive');
  230. $(".button").click(function () {
  231. copyPassword();
  232. })
  233. clearTimeout(time);
  234. } else {
  235. s = { '天': sec / 24 / 3600, '时': Math.floor(sec / 3600 % 24), '分': Math.floor(sec / 60 % 60) };
  236. for (i in s) {
  237. if (s[i] < 10) { s[i] = '0' + s[i] };
  238. if (i != '天') {
  239. str += '<span>' + s[i] + '</span>' + i;
  240. } else {
  241. str += '<span>' + parseInt(s[i]) + '</span>' + i;
  242. }
  243. }
  244. $("#count").html(str)
  245. }
  246. }
  247. //分享到微信url
  248. function shareWechatUrl(data) {
  249. var param = {
  250. "shareImageUrl": "https://kx-youhuiquan.oss-cn-beijing.aliyuncs.com/lieodu_gw/ldyx.png",
  251. "shareTitle": "领完券再返钱,佣金翻倍0元购",
  252. "shareDescirpt": "帮你发现隐藏优惠券,下单还能返双倍佣金",
  253. "shareUrl": nextUrl,//详情链接
  254. "shareType": data //1:微信好友 2:朋友圈
  255. }
  256. param = JSON.stringify(param)
  257. if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
  258. window.webkit.messageHandlers.app_h5_wx_share_url.postMessage(param);
  259. }
  260. if (navigator.userAgent.match(/android/i)) {
  261. obj4H5.app_h5_wx_share_url(param);
  262. }
  263. }
  264. // 滚动
  265. function swiper() {
  266. var mySwiper = new Swiper(".dirList", {
  267. autoplay: true,
  268. loop: true,
  269. slidesPerView: 2,
  270. slidesPerGroup: 2,
  271. speed: 5000,
  272. initialSlide:0,
  273. direction: 'vertical'
  274. })
  275. }
  276. // 弹框显示
  277. function showMsg(msg) {
  278. var msgBox = document.getElementsByClassName('alert-info')[0];
  279. msgBox.children[0].innerText = msg;
  280. msgBox.style.display="block";
  281. setTimeout(function() {
  282. msgBox.style.display="none";
  283. }, 1500);
  284. }
  285. // h5埋点
  286. function writeLogH5 (data) {
  287. $.ajax({
  288. type:'post',
  289. url:'/api/v2/channel/writeLogH5',
  290. dataType:'json',
  291. data:data,
  292. success:function (res) {
  293. }
  294. })
  295. }