|
- $(function () {
- // console.log(location.host)
- var $hammer = $("#hammer"),
- explain = $("#explain"),//积分说明框
- playCreditLimit = '',//是否展示 积分说明框
- consumeTotal = '',//消耗积分
- falglimitType = '',
- numFalg = false,//有次数=false
- wcancel = $('#w-cancel'),//弹出消耗积分取消按钮
- $tips = $(".info"),
- $eggList = $(".egg li"),//金蛋父级
- $egg = $(".goldegg"),//金蛋
- $change = $("#change"),//剩余次数
- length = $egg.length,
- data = { count: 0 },//次数
- arr = [],
- openArr,//记录被砸开的蛋的下标数组
- rem = 75,
- dataList = [],
- couponId = null,
- timer,//轮流提示定时器
- errorMessge = '',
- eggIndex = 0,
- playAble = true,
- radomData = [];
- let baseUrl = 'https://ctest.malls.iformall.com/C';
- if (window.location.origin == 'https://gametest.malls.iformall.com') {
- baseUrl = 'https://ctest.malls.iformall.com/C'
- } else if (window.location.origin == 'https://game.malls.iformall.com') {
- baseUrl = 'https://c.malls.iformall.com/C'
- } else if (window.location.origin == 'https://game.youlane.cn') {
- baseUrl = 'https://ciformall.youlane.cn/C'
- }
- /*轮流提示*/
- $(function () {
- // if (!!$.cookie("eggIndex")) {//如果存在cookie,也就是有金蛋被砸开
- // openArr = $.cookie("eggIndex").split(",");//将cookie变为数组
- // for (var i = 0; i < openArr.length; i++) {
- // arr.push(parseFloat(openArr[i]));//将上次cookie存入数组以免上次cookie被覆盖
- // $egg.eq(parseFloat(openArr[i])).prop("src", "../common/image/step3.png");
- // $egg.eq(parseFloat(openArr[i])).removeClass("init");
- // $egg.eq(parseFloat(openArr[i])).data("mark", false);//更改金蛋状态为已砸开
- // }
- // }
- $.ajax({
- url: baseUrl + "/api/game/getOneGame",//json文件位置
- type: "GET",//请求方式为get
- dataType: "json", //返回数据格式为json
- headers: {
- 'content-type': 'application/json',
- // "token":"b49fa2c4-a074-4147-afbe-6913c66705d6",
- "token": getQueryString('token')
- },
- data: {
- id: getQueryString('id'),
-
- },
- success: function (res) {//请求成功完成后要执行的方法
- // alert(JSON.stringify(res))
- // console.log(res)
- dataList = res.data.couponIdsList;
-
- playCreditLimit = res.data.playCreditLimit
- falglimitType = res.data.limitType
- if (playCreditLimit >= '0') {
- explain.show()
- }
-
- id = res.data.id
- let totalWeight = 0;
- dataList.forEach((item, index) => {
- totalWeight += Number(item.gameWeight)
- for (var i = 0; i < item.gameWeight; i++) {
- radomData.push(item)
- }
- })
- let notWinweight = 100 - totalWeight;
- // console.log(notWinweight)
- let b = {
- id: null
- }
- for (var i = 0; i < notWinweight; i++) {
- radomData.push(b)
- }
- getCount()
- }
- })
- //初始跳动
- length = 9
- $egg.eq(length).addClass("jump");
- $tips.eq(length).show();
- setInterval(function () {
- //金蛋跳动
- length++;
- length %= 9;
- $egg.eq(length - 1 < 0 && 8 || length - 1).removeClass("jump");
- $tips.eq(length - 1 < 0 && 8 || length - 1).hide();
- reback();
- $egg.eq(length).addClass("jump");
- $tips.eq(length).show();
- }, 1000);
- });
- /**
- * 获取剩余中奖次数
- */
- function getCount() {
-
- console.log("我执行了");
- $.ajax({
- url: baseUrl + "/api/game/getCount",//json文件位置
- type: "GET",//请求方式为get
- dataType: "json", //返回数据格式为json
- headers: {
- 'content-type': 'application/json',
- // "token":"b49fa2c4-a074-4147-afbe-6913c66705d6",
- "token": getQueryString('token')
- },
-
- data: {
- gameId: getQueryString('id'),
-
- },
- success: function (res) {//请求成功完成后要执行的方法
- if (res.code == 200) {
- if (res.data.playAble) {
- playAble = true;
- data.count = res.data.playLimit - res.data.playCount;
- $('#change').html(data.count);
- consumeTotal = res.data.playCredit;
-
- console.log(data.count);
- if (data.count <= '0') {
- $(integration).html(`${consumeTotal}积分/每次`);
- } else {
- $(integration).html(`当前游戏免费次数耗尽后${consumeTotal}积分/次`);
- }
-
- if (falglimitType == '0') {
- if (data.count == -1) {
- $('#change-box').hide();
- } else {
- $('#change-box').html('您总共还有' + data.count + '免费刮奖机会')
- }
-
- } else if (falglimitType == '1') {
- if (data.count == -1) {
- $('#change-box').hide()
- } else {
- $('#change-box').html('您今天还有' + data.count + '免费刮奖机会')
- }
-
- }
-
- if (res.data.playLimit < 0 && playCreditLimit >= '0') {
- return// 不设置能免费次数且设置每次消耗积分
- }
-
- if (res.data.playLimit < 0) {
- data.count = 1000000;
- $('#change-box').hide();
- } else {
- $('#change-box').show();
- }
- } else {
- playAble = false;
- if (res.data.playLimit <= 0) {
- errorMessge = '您的中奖次数已经达到上限!无法继续参加游戏!'
- data.count = 1000000;
- $('#change-box').hide();
- return;
- } else {
-
- if (res.data.AwardLimit == res.data.AwardCount && res.data.AwardLimit != 0) {
- errorMessge = '您的中奖次数已经达到上限!无法继续参加游戏!'
- data.count = res.data.playLimit - res.data.playCount;
- $('#change').html(data.count);
- $('#change-box').html('您的中奖次数已经达到上限!无法继续参加游戏!')
- $('#change-box').show();
- return;
- } else if (res.data.playLimit == res.data.playCount) {
- errorMessge = '您的剩余次数为0!无法继续参加游戏!'
- data.count = 0;
- $('#change').html(0);
- $('#change-box').html('您的剩余次数为0!无法继续参加游戏!')
- $('#change-box').show();
- return;
- }
- }
- }
- } else {
- errorMessge = res.message;
- playAble = false;
- $('#change').html(0);
- $('#change-box').hide();
- }
- }
- })
- }
- /**
- * 记录游戏次数
- */
- function reduceCount(paramData) {
- $.ajax({
- url: baseUrl + "/api/game/addActionLog",//json文件位置
- type: "POST",//请求方式为get
- dataType: "json", //返回数据格式为json
- async: true,
- headers: {
- 'content-type': 'application/json;charset=UTF-8',
- // "token":"025e5017-a268-4c21-98b3-d47b77b3ca54"
- "token": getQueryString('token')
- },
- data: JSON.stringify(paramData),
- success: function (res) {//请求成功完成后要执行的方法
- // alert('成功了!')
- getCount()
- }
- })
- }
- //跳过砸开的金蛋
- function reback() {
- if (!$egg.eq(length).hasClass("init")) {//若已砸开
- length++;
- length %= 9;
- reback();
- }
- }
- wcancel.click(function () {
- $("#warnning-box").hide()
- $("#warnning-box-bg").hide()
- numFalg = false;
- })
- $("#w-button").click(function () {
- $("#warnning-box").hide()
- $("#warnning-box-bg").hide()
- numFalg = true;
- })
- /*砸蛋事件*/
- for (var i = 0; i < length; i++) {
- $eggList.eq(i).data("i", i);
- // $egg.eq(i).data("mark", true);
- $egg.eq(i).data("mark", true);//判断金蛋是否砸开,true表示可砸
- $eggList.eq(i).click(function () {
- //设定剩余抽奖次数,判断用户是否还能点击
- // let paramContData = {
- // gameId: getQueryString('id'),
- // orderId: '0',
- // time: (new Date()).valueOf()
- // }
- if (playAble) {
- if (data.count > 0) {
- // $egg.eq($(this).data("i")).data("mark") ? eggChange($(this).data("i")) : alert("这枚金蛋已经被您砸开了");//判断金蛋是否已砸开
- if ($egg.eq($(this).data("i")).data("mark")) {
- eggChange($(this).data("i"))
- //随机生成一个优惠券
- // let b = Math.floor(Math.random() * radomData.length)
- // couponId = radomData[b].couponId
- let params = {
- // couponId: couponId,
- // couponChannelId: radomData[b].id
- gameId: getQueryString('id')
- }
-
-
- if (true) {
- ///查询中奖结果
- $.ajax({
- url: baseUrl + "/api/game/freeGameGo",//json文件位置
- type: "POST",//请求方式为get
- dataType: "json", //返回数据格式为json
- async: true,
- headers: {
- 'content-type': 'application/json;charset=UTF-8',
- // "token":"025e5017-a268-4c21-98b3-d47b77b3ca54"
- "token": getQueryString('token')
- },
- data: JSON.stringify(params),
- success: function (res) {//请求成功完成后要执行的方法
- if (res.code == 200) {
- if (res.data) {
- var toemdata = res.data
- if (res.data.prizeType == 1) {
- $('#card .win').html('积分增加+' + toemdata.credit);
- $('#card .win').css({
- 'font-size': ' 20px',
- 'text-align': 'center',
- 'color': '#FF6600',
- 'line-height': '50px',
- "background": 'url(../common/image/prize/prize2.png) no-repeat',
- 'background-size': '6rem'
- })
- $('.winning .red-body p').html('')
- $(".btn").html('再玩一把')
- } else {
- $('#card .win').html('')
- $('#card .win').css({
- "background": 'url(' + toemdata.coverImg + ') no-repeat',
- "background-size": "cover"
- });
- $('.winning .red-body p').html(toemdata.title + "(点击“我的”查看奖券)");
- $(".btn").html('再玩一把')
- }
-
- } else {
- $('#card .win').html('')
- $('#card .win').css({
- "background": 'url(../common/image/redPack/weizhongjiang.png) no-repeat',
- "background-size": "cover"
- });
- $('.winning .red-body p').html('未中奖!(点击“我的”查看奖券)');
- $(".btn").html('再玩一把')
- }
- getCount()
- } else if (res.code == 1013) {
- // reduceCount(paramContData);
- $('#card .win').html('')
- $('#card .win').css({
- "background": 'url(../common/image/redPack/weizhongjiang.png) no-repeat',
- "background-size": "cover"
- });
- $('.winning .red-body p').html(`${res.message}`);
- $(".btn").html('再玩一把')
- } else {
- $('#card .win').html('')
- $('#card .win').css({
- "background": 'url(../common/image/redPack/weizhongjiang.png) no-repeat',
- "background-size": "cover"
- });
- $('.winning .red-body p').html(`未中奖!(点击“我的”查看奖券)`);
- $(".btn").html('再玩一把')
- }
- }
- })
- } else {
- reduceCount(paramContData);
- $('#card .win').css({
- "background": 'url(../common/image/redPack/weizhongjiang.png) no-repeat',
- "background-size": "cover"
- });
- $('.winning .red-body p').html('未中奖!(点击“我的”查看奖券)');
- $(".btn").html('再玩一把')
- }
-
-
- } else {
- // alert("这枚金蛋已经被您砸开了")
- $('#warnning-box-bg').show();
- $('#warnning-box').show();
- $('#w-title').html("这枚金蛋已经被您砸开了");
- }
- } else {
- if (playCreditLimit >= '0') {
- //可以使用积分玩
-
- if (!numFalg) {//消耗积分提示框只会弹出一次
- $('#warnning-box-bg').show();
- $('#warnning-box').show();
- if (data.count == -1) {
- $('#w-title').html("将消耗" + consumeTotal + '积分');
- } else {
- $('#w-title').html("免费次数已耗尽,将消耗" + consumeTotal + '积分');
- }
-
- } else {
- eggChange($(this).data("i"))
- numFalg = true;
- let b = Math.floor(Math.random() * radomData.length)
- console.log(radomData[b])
- // couponId = radomData[b].couponId
- let params = {
- // couponId:couponId,
- // couponChannelId:radomData[b].id
- gameId: getQueryString('id')
- }
- //查询中奖结果
- $.ajax({
- url: baseUrl + "/api/game/freeCridetGameGo",//json文件位置
- type: "POST",//请求方式为get
- dataType: "json", //返回数据格式为json
- async: true,
- headers: {
- 'content-type': 'application/json;charset=UTF-8',
- // "token":"025e5017-a268-4c21-98b3-d47b77b3ca54"
- "token": getQueryString('token')
- },
- data: JSON.stringify(params),
- success: function (res) {//请求成功完成后要执行的方法
- if (res.code == 200) {
- getCount()
- // $canvasMask.hide();
- if (res.data) {
- var toemdata = res.data
- if (res.data.prizeType == 1) {
- $('#card .win').html('积分增加+' + toemdata.credit);
- $('.winning .red-body p').html('')
- $('#card .win').css({
- 'font-size': ' 20px',
- 'text-align': 'center',
- 'color': '#FF6600',
- 'line-height': '50px',
- "background": 'url(../common/image/prize/prize2.png) no-repeat',
- 'background-size': '6rem'
- })
- } else {
- $('#card .win').html('')
- // $canvas.css("background-image", 'url(' + toemdata.coverImg + ')');
- $('#card .win').css({
- "background": 'url(' + toemdata.coverImg + ') no-repeat',
- "background-size": "cover"
- });
- $('.winning .red-body p').html(toemdata.title + "(点击“我的”查看奖券)");
- }
- $(".btn").html('再玩一把')
-
- } else {
- $('#card .win').html('')
- // $canvas.css("background-image", 'url(../common/image/redPack/weizhongjiang.png)');
- $('#card .win').css({
- "background": 'url(../common/image/redPack/weizhongjiang.png) no-repeat',
- "background-size": "cover"
- });
- $('.winning .red-body p').html('未中奖!(点击“我的”查看奖券)');
- $(".btn").html('再玩一把')
- }
- } else if (res.code == 13101) {
- // $canvasMask.hide();
- // $canvas.css("background-image", 'url(../common/image/redPack/weizhongjiang.png)');
- $('#card .win').css({
- "background": 'url(../common/image/prize/prize2.png) no-repeat',
- "background-size": "cover"
- });
- $('.winning .red-body p').css({
- "line-height": "1.5rem",
- "font-size": "0.64rem"
- })
- $('.winning .red-body p').html('积分不足!');
- $(".btn").hide()
- }
- }
- })
-
- }
- } else {
- $('#warnning-box-bg').show();
- $('#warnning-box').show();
- $('#w-title').html("当前可用次数已耗尽");
- return
- }
- }
- } else {
-
- $('#warnning-box-bg').show();
- $('#warnning-box').show();
- $('#w-title').html(errorMessge);
- }
- });
- }
-
- /*砸蛋事件的处理*/
- function eggChange(i) {
- eggIndex = i;
- //砸蛋次数的变化
- // data.count--;
- // $change.html(data.count);
- $hammer.removeClass("shak");//清除锤子晃动动画
- //锤子砸蛋的位置
- (i === 0 || i === 3 || i === 6) && ($hammer.css("left", 165 / rem + "rem"));
- (i === 1 || i === 4 || i === 7) && ($hammer.css("left", 415 / rem + "rem"));
- (i === 2 || i === 5 || i === 8) && ($hammer.css("left", 665 / rem + "rem"));
- (i === 0 || i === 1 || i === 2) && ($hammer.css("top", 60 / rem + "rem"));
- (i === 3 | i === 4 || i === 5) && ($hammer.css("top", 280 / rem + "rem"));
- (i === 6 | i === 7 || i === 8) && ($hammer.css("top", 500 / rem + "rem"));
- //锤子返回
- setTimeout(function () {
- $hammer.css("left", 665 / rem + "rem");
- $hammer.css("top", 60 / rem + "rem");
- }, 1500);
-
- //金蛋破裂及锤子动画
- setTimeout(function () {
- $hammer.addClass("hit");
- $egg.eq(i).prop("src", "image/step1.png");
- setTimeout(function () {
- $egg.eq(i).prop("src", "image/step2.png");
- }, 300);
- setTimeout(function () {
- $egg.eq(i).prop("src", "image/step3.png");
- $egg.eq(i).removeClass("init");
- //clickData(false);//ajax回调
- win();
- $hammer.removeClass("hit");//清除锤子砸蛋动画
- $hammer.addClass("shak");
-
- //记录被砸开的蛋
- arr.push(i);//存入每个砸开蛋的下标
- // $.cookie("eggIndex", arr, {expires: 1});//存入cookie
- }, 600);
- }, 600);
- $egg.eq(i).data("mark", false);//更改金蛋状态为已砸开
- }
- $('.replay').click(function () {
- // alert(111)
- $egg.eq(eggIndex).addClass("init");
- $egg.eq(eggIndex).prop("src", "image/egg.png");
- $egg.eq(eggIndex).data("mark", true);
- })
- //点击跳回小程序奖券列表
- $('#myWin').click(function () {
- // alert(555)
- wx.miniProgram.redirectTo({
- url: '/pages/couponorder/index/index' + "?token=" + getQueryString('token') + "&gameId=" + getQueryString('gameId') + "&id=" + getQueryString('id') + '&from=h5'
- })
- })
- //返回首页
- $("#gotoindex").click(function () {
- wx.miniProgram.redirectTo({
- url: '/pages/index/index'
- })
- });
- });
-
-
-
-
|