Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

482 строки
23 KiB

  1. $(function () {
  2. var $cards = $(".box li"),//所有卡牌
  3. $maskCard = $("#mask-card"),//翻牌遮罩
  4. length = $cards.length,
  5. index = length,//轮流滚动的卡牌下标
  6. data = { count: 5 },//次数
  7. rem = 75,
  8. initArr = [[34 / rem, 0], [273 / rem, 0], [512 / rem, 0], [34 / rem, 268 / rem], [273 / rem, 268 / rem], [512 / rem, 268 / rem]],//卡牌位置数组
  9. clickTime = 0,
  10. bool = false,//首次点击时不能在卡牌归位期间
  11. dataList = [],
  12. couponId = null,
  13. errorMessge = '',
  14. playAble = true,
  15. timer,//轮流提示定时器
  16. playCreditLimit = '',//是否展示 积分说明框
  17. falglimitType = '',
  18. consumeTotal = '',//消耗积分
  19. explain = $("#explain"),//积分说明框
  20. numFalg = false,//有次数=false
  21. wcancel = $('#w-cancel'),//弹出消耗积分取消按钮
  22. radomData = [];
  23. let baseUrl = 'https://ctest.malls.iformall.com/C';
  24. if (window.location.origin == 'https://gametest.malls.iformall.com') {
  25. baseUrl = 'https://ctest.malls.iformall.com/C'
  26. } else if (window.location.origin == 'https://game.malls.iformall.com') {
  27. baseUrl = 'https://c.malls.iformall.com/C'
  28. } else if (window.location.origin == 'https://game.youlane.cn') {
  29. baseUrl = 'https://ciformall.youlane.cn/C'
  30. }
  31. init();
  32. // alert('token是'+getQueryString('token')+"-------------"+'gameId是'+getQueryString('gameId')+"-------------"+'id是'+getQueryString('id'))
  33. function init() {
  34. $.ajax({
  35. url: baseUrl + "/api/game/getOneGame",//json文件位置
  36. type: "GET",//请求方式为get
  37. dataType: "json", //返回数据格式为json
  38. headers: {
  39. 'content-type': 'application/json',
  40. // "token":"025e5017-a268-4c21-98b3-d47b77b3ca54",
  41. "token": getQueryString('token')
  42. },
  43. data: {
  44. id: getQueryString('id'),
  45. // id:"212380694809149440"
  46. },
  47. success: function (res) {//请求成功完成后要执行的方法
  48. // console.log(res)
  49. var strHtml = "";
  50. dataList = res.data.couponIdsList;
  51. playCreditLimit = res.data.playCreditLimit
  52. falglimitType = res.data.limitType
  53. if (playCreditLimit >= '0') {
  54. explain.show()
  55. }
  56. id = res.data.id
  57. let totalWeight = 0;
  58. dataList.forEach((item, index) => {
  59. strHtml += '<li class="swiper-slide">';
  60. strHtml += '<img src="' + item.coverImg + '">';
  61. strHtml += '</li>';
  62. totalWeight += Number(item.gameWeight)
  63. for (var i = 0; i < item.gameWeight; i++) {
  64. radomData.push(item)
  65. }
  66. })
  67. let notWinweight = 100 - totalWeight;
  68. let b = {
  69. id: null
  70. }
  71. for (var i = 0; i < notWinweight; i++) {
  72. radomData.push(b)
  73. }
  74. $('.swiper-wrapper').html(strHtml);
  75. //奖品展示
  76. var show = new Swiper(".swiper-container", {
  77. direction: "horizontal",//水平方向滑动。 vertical为垂直方向滑动
  78. loop: false,//是否循环
  79. slidesPerView: 'auto' //自动根据slides的宽度来设定数量
  80. });
  81. getCount()
  82. }
  83. })
  84. //卡牌归位动画
  85. for (var i = 0; i < length; i++) {
  86. (function (i) {
  87. var seat = setTimeout(function () {
  88. $cards.eq(i).css({
  89. left: initArr[i][0] + "rem",
  90. top: initArr[i][1] + "rem"
  91. });
  92. clearTimeout(seat);
  93. }, 300 * i);
  94. })(i);
  95. }
  96. //卡牌轮流选中动画
  97. setTimeout(function () {
  98. timer = setInterval(function () {
  99. bool = true;//卡牌归位,可以点击
  100. $cards.eq(index - 1).removeClass("active");
  101. index %= 6;
  102. $cards.eq(index).addClass("active");
  103. index++;
  104. }, 1000);
  105. }, 1000);
  106. }
  107. /**
  108. * 获取剩余中奖次数
  109. */
  110. function getCount() {
  111. $.ajax({
  112. url: baseUrl + "/api/game/getCount",//json文件位置
  113. type: "GET",//请求方式为get
  114. dataType: "json", //返回数据格式为json
  115. headers: {
  116. 'content-type': 'application/json',
  117. // "token":"b49fa2c4-a074-4147-afbe-6913c66705d6",
  118. "token": getQueryString('token')
  119. },
  120. data: {
  121. gameId: getQueryString('id'),
  122. // id:"213206254531641344"
  123. },
  124. success: function (res) {//请求成功完成后要执行的方法
  125. if (res.code == 200) {
  126. if (res.data.playAble) {
  127. playAble = true;
  128. data.count = res.data.playLimit - res.data.playCount;
  129. $('#change').html(data.count);
  130. consumeTotal = res.data.playCredit;
  131. if (data.count <= '0') {
  132. $(integration).html(`${consumeTotal}积分/每次`);
  133. } else {
  134. $(integration).html(`当前游戏免费次数耗尽后${consumeTotal}积分/次`);
  135. }
  136. if (falglimitType == '0') {
  137. if (data.count == -1) {
  138. $('#change-box').hide();
  139. } else {
  140. $('#change-box').html('您总共还有' + data.count + '免费刮奖机会')
  141. }
  142. } else if (falglimitType == '1') {
  143. if (data.count == -1) {
  144. $('#change-box').hide()
  145. } else {
  146. $('#change-box').html('您今天还有' + data.count + '免费刮奖机会')
  147. }
  148. }
  149. if (res.data.playLimit < '0' && playCreditLimit >= '0') {
  150. return// 不设置能免费次数且设置每次消耗积分
  151. }
  152. if (res.data.playLimit < '0') {
  153. data.count = 1000000;
  154. $('#change-box').hide();
  155. } else {
  156. $('#change-box').show();
  157. }
  158. } else {
  159. playAble = false;
  160. if (res.data.playLimit <= '0') {
  161. errorMessge = '您的中奖次数已经达到上限!无法继续参加游戏!'
  162. data.count = 1000000;
  163. $('#change-box').hide();
  164. return;
  165. } else {
  166. if (res.data.AwardLimit == res.data.AwardCount && res.data.AwardLimit != 0) {
  167. errorMessge = '您的中奖次数已经达到上限!无法继续参加游戏!'
  168. data.count = res.data.playLimit - res.data.playCount;
  169. $('#change').html(data.count);
  170. $('#change-box').html('您的中奖次数已经达到上限!无法继续参加游戏!');
  171. $('#change-box').show();
  172. return;
  173. } else if (res.data.playLimit == res.data.playCount) {
  174. errorMessge = '您的剩余次数为0!无法继续参加游戏!'
  175. data.count = 0;
  176. $('#change').html(0);
  177. $('#change-box').html('您的剩余次数为0!无法继续参加游戏!');
  178. $('#change-box').show();
  179. return;
  180. }
  181. }
  182. }
  183. } else {
  184. errorMessge = res.message;
  185. playAble = false;
  186. $('#change').html(0);
  187. $('#change-box').hide();
  188. }
  189. }
  190. })
  191. }
  192. /**
  193. * 记录游戏次数
  194. */
  195. function reduceCount(paramData) {
  196. $.ajax({
  197. url: baseUrl + "/api/game/addActionLog",//json文件位置
  198. type: "POST",//请求方式为get
  199. dataType: "json", //返回数据格式为json
  200. async: true,
  201. headers: {
  202. 'content-type': 'application/json;charset=UTF-8',
  203. // "token":"025e5017-a268-4c21-98b3-d47b77b3ca54"
  204. "token": getQueryString('token')
  205. },
  206. data: JSON.stringify(paramData),
  207. success: function (res) {//请求成功完成后要执行的方法
  208. // alert('成功了!')
  209. getCount()
  210. }
  211. })
  212. }
  213. $('.fenxiang').click(function () {
  214. wx.ready(function () {
  215. wx.onMenuShareAppMessage({
  216. title: "title", // 分享标题
  217. desc: "desc", // 分享描述
  218. link: '/pages/index/index', // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
  219. imgUrl: '', // 分享图标
  220. type: '', // 分享类型,music、video或link,不填默认为link
  221. dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
  222. success: function () {
  223. // 用户确认分享后执行的回调函数
  224. },
  225. cancel: function () {
  226. // 用户取消分享后执行的回调函数
  227. }
  228. });
  229. })
  230. })
  231. wcancel.click(function () {
  232. $("#warnning-box").hide()
  233. $("#warnning-box-bg").hide()
  234. numFalg = false;
  235. })
  236. $("#w-button").click(function () {
  237. $("#warnning-box").hide()
  238. $("#warnning-box-bg").hide()
  239. numFalg = true;
  240. })
  241. //点击卡牌翻转
  242. $(".box").on("click", "li", function () {
  243. let _this = this;
  244. if (new Date() - clickTime > 2000 && bool) {//两次点击的间隔不能小于2秒
  245. if (playAble) {
  246. if (data.count > 0) {
  247. let params = {
  248. gameId: getQueryString('id')
  249. }
  250. $maskCard.show();
  251. clearInterval(timer);//清除轮流选中动画
  252. $cards.removeClass("active");//清除轮流滚动类名
  253. $(_this).addClass("open-card");//添加翻牌动画
  254. //动画监听
  255. $(_this).on("animationend", function () {
  256. $(_this).removeClass("open-card");//移除翻牌动画
  257. $cards.css({//所有卡牌放到右下角
  258. left: 512 / rem + "rem",
  259. top: 268 / rem + "rem"
  260. });
  261. $maskCard.hide();
  262. win();
  263. $(_this).off("animationend");//解绑动画监听
  264. });
  265. if (true) {
  266. //查询中奖结果
  267. $.ajax({
  268. url: baseUrl + "/api/game/freeGameGo",//json文件位置
  269. type: "POST",//请求方式为get
  270. dataType: "json", //返回数据格式为json
  271. async: true,
  272. headers: {
  273. 'content-type': 'application/json;charset=UTF-8',
  274. // "token":"025e5017-a268-4c21-98b3-d47b77b3ca54"
  275. "token": getQueryString('token')
  276. },
  277. data: JSON.stringify(params),
  278. success: function (res) {//请求成功完成后要执行的方法
  279. if (res.code == 200) {
  280. //保存中奖信息
  281. getCount()
  282. if (res.data) {
  283. var toemdata = res.data
  284. if (res.data.prizeType == 1) {
  285. $('#card .win').html('积分增加+' + toemdata.credit);
  286. $('#card .win').css({
  287. 'font-size': ' 20px',
  288. 'text-align': 'center',
  289. 'color': '#FF6600',
  290. 'line-height': '50px',
  291. "background": 'url(../common/image/prize/prize2.png) no-repeat',
  292. 'background-size': '6rem'
  293. })
  294. $('.winning .red-body p').html('')
  295. $(".btn").html('再玩一把')
  296. } else {
  297. $('#card .win').html('')
  298. $('#card .win').css({
  299. "background": 'url(' + toemdata.coverImg + ') no-repeat',
  300. "background-size": "cover"
  301. });
  302. $('.winning .red-body p').html(toemdata.title + "(点击“我的”查看奖券)");
  303. $(".btn").html('再玩一把')
  304. }
  305. } else {
  306. $('#card .win').html('')
  307. $('#card .win').css({
  308. "background": 'url(../common/image/redPack/weizhongjiang.png) no-repeat',
  309. "background-size": "cover"
  310. });
  311. $('.winning .red-body p').html('未中奖!(点击“我的”查看奖券)');
  312. $(".btn").html('再玩一把')
  313. }
  314. } else {
  315. $('#card .win').html('')
  316. $('#card .win').css({
  317. "background": 'url(../common/image/redPack/weizhongjiang.png) no-repeat',
  318. "background-size": "cover"
  319. });
  320. $('.winning .red-body p').html('未中奖!(点击“我的”查看奖券)');
  321. $(".btn").html('再玩一把')
  322. }
  323. }
  324. })
  325. } else {
  326. reduceCount(paramContData);
  327. $('#card .win').css({
  328. "background": 'url(../common/image/redPack/weizhongjiang.png) no-repeat',
  329. "background-size": "cover"
  330. });
  331. $('.winning .red-body p').html('未中奖!(点击“我的”查看奖券)');
  332. $(".btn").html('再玩一把')
  333. }
  334. } else {
  335. if (playCreditLimit >= '0') {
  336. if (!numFalg) {//消耗积分提示框只会弹出一次
  337. $('#warnning-box-bg').show();
  338. $('#warnning-box').show();
  339. if (data.count == -1) {
  340. $('#w-title').html("将消耗" + consumeTotal + '积分');
  341. } else {
  342. $('#w-title').html("免费次数已耗尽,将消耗" + consumeTotal + '积分');
  343. }
  344. } else {
  345. $maskCard.show();
  346. clearInterval(timer);//清除轮流选中动画
  347. $cards.removeClass("active");//清除轮流滚动类名
  348. $(_this).addClass("open-card");//添加翻牌动画
  349. //动画监听
  350. $(_this).on("animationend", function () {
  351. $(_this).removeClass("open-card");//移除翻牌动画
  352. $cards.css({//所有卡牌放到右下角
  353. left: 512 / rem + "rem",
  354. top: 268 / rem + "rem"
  355. });
  356. $maskCard.hide();
  357. win();
  358. $(_this).off("animationend");//解绑动画监听
  359. });
  360. let params = {
  361. gameId: getQueryString('id')
  362. }
  363. $.ajax({
  364. url: baseUrl + "/api/game/freeCridetGameGo",//json文件位置
  365. type: "POST",//请求方式为get
  366. dataType: "json", //返回数据格式为json
  367. async: true,
  368. headers: {
  369. 'content-type': 'application/json;charset=UTF-8',
  370. // "token":"025e5017-a268-4c21-98b3-d47b77b3ca54"
  371. "token": getQueryString('token')
  372. },
  373. data: JSON.stringify(params),
  374. success: function (res) {//请求成功完成后要执行的方法
  375. if (res.code == 200) {
  376. if (res.data) {
  377. var toemdata = res.data
  378. if (res.data.prizeType == 1) {
  379. $('#card .win').html('积分增加+' + toemdata.credit);
  380. $('#card .win').css({
  381. 'font-size': ' 20px',
  382. 'text-align': 'center',
  383. 'color': '#FF6600',
  384. 'line-height': '50px',
  385. "background": 'url(../common/image/prize/prize2.png) no-repeat',
  386. 'background-size': '6rem'
  387. })
  388. $('.winning .red-body p').html('')
  389. $(".btn").html('再玩一把')
  390. } else {
  391. $('#card .win').html('')
  392. $('#card .win').css({
  393. "background": 'url(' + toemdata.coverImg + ') no-repeat',
  394. "background-size": "cover"
  395. });
  396. $('.winning .red-body p').html(toemdata.title + "(点击“我的”查看奖券)");
  397. $(".btn").html('再玩一把')
  398. }
  399. } else {
  400. $('#card .win').html('')
  401. $('#card .win').css({
  402. "background": 'url(../common/image/redPack/weizhongjiang.png) no-repeat',
  403. "background-size": "cover"
  404. });
  405. $('.winning .red-body p').html('未中奖!(点击“我的”查看奖券)');
  406. $(".btn").html('再玩一把')
  407. }
  408. } else if (res.code == 13101) {
  409. $('#card .win').html('')
  410. $('#card .win').css({
  411. "background": 'url(../common/image/prize/prize2.png) no-repeat',
  412. "background-size": "cover"
  413. });
  414. $('.winning .red-body p').css({
  415. "line-height": "1.5rem",
  416. "font-size": "0.64rem"
  417. })
  418. $('.winning .red-body p').html('积分不足!');
  419. $(".btn").hide()
  420. }
  421. }
  422. })
  423. }
  424. } else {
  425. $('#warnning-box-bg').show();
  426. $('#warnning-box').show();
  427. $('#w-title').html("当前可用次数已耗尽");
  428. return
  429. }
  430. }
  431. } else {
  432. $('#warnning-box-bg').show();
  433. $('#warnning-box').show();
  434. $('#w-title').html(errorMessge);
  435. }
  436. }
  437. });
  438. //点击跳回小程序奖券列表
  439. $('#myWin').click(function () {
  440. wx.miniProgram.redirectTo({
  441. url: '/pages/couponorder/index/index' + "?token=" + getQueryString('token') + "&gameId=" + getQueryString('gameId') + "&id=" + getQueryString('id') + '&from=h5'
  442. })
  443. })
  444. //中奖信息提示
  445. $(".btn").click(function () {
  446. clickTime = new Date();//时间更新
  447. index = length;//卡牌选中重新从第一张开始
  448. init();
  449. });
  450. //关闭中奖提示页面
  451. $("#close").click(function () {
  452. clickTime = new Date();//时间更新
  453. index = length;//卡牌选中重新从第一张开始
  454. init();
  455. });
  456. //返回首页
  457. $("#gotoindex").click(function () {
  458. wx.miniProgram.redirectTo({
  459. url: '/pages/index/index'
  460. })
  461. });
  462. });