gameadmin.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. /**
  2. * Created by misszhou on 2016/5/17.
  3. */
  4. var GameAdmin = function(id, openid){
  5. //活动ID
  6. this.activity_id = id;
  7. this.openid = openid;
  8. this.poststart = false;
  9. this.urls = {};
  10. this.defaults = {};
  11. this.defaults.dtime = 1250;
  12. this.defaults.SUCESS_CODE = 200;
  13. this.defaults.FAILURE_CODE = 400;
  14. this.defaults.SERVER_ERROR = 500;
  15. this.defaults.NO_PERMISSION = 401;
  16. this.defaults.PAGE_NUMS = 10;
  17. this.defaults.PAGE_MAX_NUMS = 50;
  18. this.init();
  19. };
  20. /**
  21. * 弹框提示
  22. * @param time
  23. * @param html
  24. * @param type
  25. * @private
  26. */
  27. GameAdmin.prototype._alert = function(html, type, time){
  28. type = type || "1";
  29. var html2='<div class="GameMsg">\
  30. <div>\
  31. '+html+'\
  32. </div>\
  33. </div>\
  34. <div class="GameMsgBg"></div>';
  35. switch(type){
  36. case "1"://时间自动关闭
  37. if($(".GameMsg").length!=0){
  38. $(".GameMsg").show().find("div").html(html);
  39. }else{
  40. $("body").append(html2);
  41. }
  42. closefn(time);
  43. break;
  44. default:
  45. }
  46. function closefn(time){
  47. time=time?time:1250;
  48. setTimeout(function(){
  49. $(".GameMsg,.GameMsgBg").remove();
  50. },time)
  51. }
  52. };
  53. GameAdmin.prototype.init = function(){
  54. // post请求数据是否开始
  55. this.poststart = false;
  56. // 添加埋点
  57. this.urls.buriedpoint = '/api/buriedpoint';// 埋点
  58. this.urls.draw = '/api/draw';// 抽奖
  59. this.urls.rankinglist = '/api/rankinglist';// 获取排行榜
  60. this.urls.createranking = '/api/createranking';// 添加排行榜
  61. this.urls.awardslist = '/api/awardslist';// 我的奖品列表
  62. this.urls.awardsdetail = '/api/awardsdetail';// 奖品详细信息
  63. this.urls.getpartake = '/api/getpartake';// 获取活动参与人数
  64. this.urls.getfirst = '/api/first';// 根据活动ID获取最好的成绩
  65. this.urls.myresult = '/api/myresult';// 获取我的最佳成绩
  66. this.urls.createpricecollect = '/api/createpricecollect';// 添加兑奖码收藏
  67. this.urls.mydrawnumber = '/api/mydrawnumber';// 我的抽奖次数
  68. };
  69. GameAdmin.prototype.mydrawnumber = function(data, callback){
  70. // 我的抽奖次数
  71. var _this = this;
  72. var _data = {
  73. '_token' : $('meta[name="_token"]').attr('content'),
  74. 'activity_id' : this.activity_id,
  75. 'openid' : this.openid
  76. };
  77. if(_this.poststart != false){
  78. // 已经开始了一个post请求,必须等到post完成之后再发送请求
  79. return ;
  80. }
  81. _this.poststart = true;
  82. $.post(this.urls.mydrawnumber, _data, function($data){
  83. _this.poststart = false;
  84. if($data.status == _this.defaults.SUCESS_CODE){
  85. console.log($data);
  86. if(typeof callback != 'undefined' && callback instanceof Function) {
  87. callback($data);
  88. }
  89. }else{
  90. _this._alert($data.msg);
  91. callback($data);
  92. }
  93. });
  94. };
  95. GameAdmin.prototype.awardsdetail = function(data, callback){
  96. // 奖品详细信息
  97. var _this = this;
  98. var _data = {
  99. '_token' : $('meta[name="_token"]').attr('content'),
  100. 'activity_id' : this.activity_id,
  101. 'awards_id' : data.awards_id
  102. };
  103. if(_this.poststart != false){
  104. // 已经开始了一个post请求,必须等到post完成之后再发送请求
  105. return ;
  106. }
  107. _this.poststart = true;
  108. $.post(this.urls.awardsdetail, _data, function($data){
  109. _this.poststart = false;
  110. if($data.status == _this.defaults.SUCESS_CODE){
  111. console.log($data);
  112. if(typeof callback != 'undefined' && callback instanceof Function) {
  113. callback($data);
  114. }
  115. }else{
  116. _this._alert($data.msg);
  117. callback($data);
  118. }
  119. });
  120. };
  121. GameAdmin.prototype.createpricecollect = function(data, callback){
  122. // 添加兑奖码收藏
  123. var _this = this;
  124. var _data = {
  125. '_token' : $('meta[name="_token"]').attr('content'),
  126. 'openid' : this.openid,
  127. 'prize_id' : data.prize_id
  128. };
  129. if(_this.poststart != false){
  130. // 已经开始了一个post请求,必须等到post完成之后再发送请求
  131. return ;
  132. }
  133. _this.poststart = true;
  134. $.post(this.urls.createpricecollect, _data, function($data){
  135. _this.poststart = false;
  136. if($data.status == _this.defaults.SUCESS_CODE){
  137. console.log($data);
  138. if(typeof callback != 'undefined' && callback instanceof Function) {
  139. callback($data);
  140. }
  141. }else{
  142. _this._alert($data.msg);
  143. callback($data);
  144. }
  145. });
  146. };
  147. GameAdmin.prototype.myresult = function(data, callback){
  148. // 获取我的最佳成绩
  149. var _this = this;
  150. var _data = {
  151. '_token' : $('meta[name="_token"]').attr('content'),
  152. 'openid' : this.openid,
  153. 'id' : this.activity_id,// 活动ID
  154. 'type' : 'time' // 【score|time】
  155. };
  156. if(_this.poststart != false){
  157. // 已经开始了一个post请求,必须等到post完成之后再发送请求
  158. return ;
  159. }
  160. _this.poststart = true;
  161. $.post(this.urls.myresult, _data, function($data){
  162. _this.poststart = false;
  163. if($data.status == _this.defaults.SUCESS_CODE){
  164. console.log($data);
  165. if(typeof callback != 'undefined' && callback instanceof Function) {
  166. callback($data);
  167. }
  168. }else{
  169. _this._alert($data.msg);
  170. callback($data);
  171. }
  172. });
  173. };
  174. GameAdmin.prototype.getfirst = function(data, callback){
  175. // 根据活动ID获取最好的成绩
  176. var _this = this;
  177. var _data = {
  178. '_token' : $('meta[name="_token"]').attr('content'),
  179. 'id' : this.activity_id,
  180. 'type' : 'time' // 【score|time】
  181. };
  182. if(_this.poststart != false){
  183. // 已经开始了一个post请求,必须等到post完成之后再发送请求
  184. return ;
  185. }
  186. _this.poststart = true;
  187. $.post(this.urls.getfirst, _data, function($data){
  188. _this.poststart = false;
  189. if($data.status == _this.defaults.SUCESS_CODE){
  190. console.log($data);
  191. if(typeof callback != 'undefined' && callback instanceof Function) {
  192. callback($data);
  193. }
  194. }else{
  195. _this._alert($data.msg);
  196. callback($data);
  197. }
  198. });
  199. };
  200. GameAdmin.prototype.getpartake = function(data, callback){
  201. // 获取活动参与人数
  202. var _this = this;
  203. var _data = {
  204. '_token' : $('meta[name="_token"]').attr('content'),
  205. 'activity_id' : this.activity_id
  206. };
  207. if(_this.poststart != false){
  208. // 已经开始了一个post请求,必须等到post完成之后再发送请求
  209. return ;
  210. }
  211. _this.poststart = true;
  212. $.post(this.urls.getpartake, _data, function($data){
  213. _this.poststart = false;
  214. if($data.status == _this.defaults.SUCESS_CODE){
  215. console.log($data);
  216. if(typeof callback != 'undefined' && callback instanceof Function) {
  217. callback($data);
  218. }
  219. }else{
  220. _this._alert($data.msg);
  221. callback($data);
  222. }
  223. });
  224. };
  225. GameAdmin.prototype.rankinglist = function(data, callback){
  226. // 获取排行榜
  227. var _this = this;
  228. var _data = {
  229. '_token' : $('meta[name="_token"]').attr('content'),
  230. 'id' : this.activity_id,
  231. 'type' : 'time' // 【score|time】
  232. };
  233. if(_this.poststart != false){
  234. // 已经开始了一个post请求,必须等到post完成之后再发送请求
  235. return ;
  236. }
  237. _this.poststart = true;
  238. $.post(this.urls.rankinglist, _data, function($data){
  239. _this.poststart = false;
  240. if($data.status == _this.defaults.SUCESS_CODE){
  241. console.log($data);
  242. if(typeof callback != 'undefined' && callback instanceof Function) {
  243. callback($data);
  244. }
  245. }else{
  246. _this._alert($data.msg);
  247. callback($data);
  248. }
  249. });
  250. };
  251. GameAdmin.prototype.createranking = function(data, callback){
  252. var _this = this;
  253. var _data = {
  254. '_token' : $('meta[name="_token"]').attr('content'),
  255. 'openid' : this.openid,
  256. 'activity_id' : this.activity_id,
  257. 'record_time' : data.record_time,
  258. 'record_score' : data.record_score
  259. };
  260. if(_this.poststart != false){
  261. // 已经开始了一个post请求,必须等到post完成之后再发送请求
  262. return ;
  263. }
  264. _this.poststart = true;
  265. // 创建排行榜
  266. $.post(this.urls.createranking, _data, function($data){
  267. _this.poststart = false;
  268. if($data.status == _this.defaults.SUCESS_CODE){
  269. console.log($data);
  270. if(typeof callback != 'undefined' && callback instanceof Function) {
  271. callback($data);
  272. }
  273. }else{
  274. _this._alert($data.msg);
  275. callback($data);
  276. }
  277. });
  278. };
  279. GameAdmin.prototype.myPrize = function(data, callback){
  280. // 我的奖品
  281. var _this = this;
  282. var _data = {
  283. '_token' : $('meta[name="_token"]').attr('content'),
  284. 'openid' : this.openid,
  285. 'activity_id' : this.activity_id
  286. };
  287. if(_this.poststart != false){
  288. // 已经开始了一个post请求,必须等到post完成之后再发送请求
  289. return ;
  290. }
  291. _this.poststart = true;
  292. $.post(this.urls.awardslist, _data, function($data){
  293. _this.poststart = false;
  294. if($data.status == _this.defaults.SUCESS_CODE){
  295. var award = [];
  296. $.each($data.data, function(key,item){
  297. award.push({
  298. Prizeid : item.awards_id,
  299. PrizeName : item.award_desc,
  300. PrizeText : item.award_name,
  301. PrizeTime : item.award_time,
  302. PrizeStatus : item.status_str,
  303. PrizeCode : item.coupon_code
  304. });
  305. });
  306. var metmsg={
  307. data:award,
  308. status:$data.status,
  309. msg:$data.msg
  310. };
  311. // Prizeid:2,//奖品id
  312. // PrizeName:"一等奖",//奖品名称
  313. // PrizeText:"价值50元礼品",//奖品名称
  314. // PrizeTime:"2015.05.02至2015.06.02",//有效时间
  315. // PrizeStatus:"未兑奖",//领取状态
  316. if(typeof callback != 'undefined' && callback instanceof Function) {
  317. callback(metmsg);
  318. }
  319. }else{
  320. _this._alert($data.msg);
  321. callback($data);
  322. }
  323. });
  324. };
  325. GameAdmin.prototype.draw = function(data, callback){
  326. this.postPartake();
  327. //用户抽奖
  328. var _this = this;
  329. var _data = {
  330. '_token' : $('meta[name="_token"]').attr('content'),
  331. 'openid' : this.openid,
  332. 'score' : data.score,
  333. 'activity_id' : this.activity_id
  334. };
  335. if(_this.poststart != false){
  336. // 已经开始了一个post请求,必须等到post完成之后再发送请求
  337. return ;
  338. }
  339. _this.poststart = true;
  340. $.post(this.urls.draw, _data, function($data){
  341. _this.poststart = false;
  342. var data = {};
  343. if($data.status == _this.defaults.SUCESS_CODE){
  344. var option = $data.data;
  345. data = {
  346. Resuletype:(option.status==2?1:0),//0=未中奖 1=中奖 2=次数用完了
  347. Resuleid:(option.status==2?option.awardInfo.id:0),//奖品id
  348. ResuleFrequency:option.today_sy_count,//今日剩余次数
  349. ResuleLimitDrawTimes:option.more_is_limit_draw_times,//总体是否限制
  350. ResuleTotalTimes:option.total_sy_count,//总体剩余次数
  351. Resulenumber:option.partakeNum,//参与人数
  352. ResuleName:(option.status==2?option.awardInfo.award_desc:''),//奖品等级
  353. ResuleText:(option.status==2?option.awardInfo.award_name:''),//奖品名称
  354. ResuleUrl:"http://img-staging.liweijia.com/liweijia/wap/weixinActivity/images/gift.png",//奖品图片
  355. };
  356. var metmsg={
  357. data:data,
  358. status:$data.status,
  359. msg:$data.msg
  360. };
  361. if(typeof callback != 'undefined' && callback instanceof Function) {
  362. callback(metmsg);
  363. }
  364. }else{
  365. _this._alert($data.msg);
  366. callback($data);
  367. }
  368. });
  369. };
  370. GameAdmin.prototype.postView = function(){
  371. // 记录浏览-埋点
  372. this.postMaiDian('view', function(d){});
  373. };
  374. GameAdmin.prototype.postPartake = function(){
  375. // 记录参与人数-埋点
  376. this.postMaiDian('partake', function(d){});
  377. };
  378. GameAdmin.prototype.postAward = function(){
  379. // 记录获奖-埋点
  380. this.postMaiDian('award', function(d){});
  381. };
  382. GameAdmin.prototype.postConvert = function(){
  383. // 记录兑奖-埋点
  384. this.postMaiDian('convert', function(d){});
  385. };
  386. GameAdmin.prototype.postShare = function(){
  387. // 记录分享-埋点
  388. this.postMaiDian('share', function(d){});
  389. };
  390. GameAdmin.prototype.postMaiDian = function(topic, callback){
  391. // 记录--埋点
  392. var _this = this;
  393. var data = {
  394. '_token' : $('meta[name="_token"]').attr('content'),
  395. 'topic' : topic,
  396. 'openid' : this.openid,
  397. 'id' : this.activity_id
  398. };
  399. $.post(this.urls.buriedpoint, data, function($data){
  400. if($data.status == _this.defaults.SUCESS_CODE){
  401. if(typeof callback != 'undefined' && callback instanceof Function) {
  402. callback($data);
  403. }
  404. }else{
  405. callback($data);
  406. }
  407. }, 'json');
  408. };