| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418 | 
							- /**
 
-  * Created by misszhou on 2016/5/17.
 
-  */
 
- var GameAdmin = function(id, openid){
 
-     //活动ID
 
-     this.activity_id = id;
 
-     this.openid = openid;
 
-     this.poststart = false;
 
-     this.urls = {};
 
-     this.defaults = {};
 
-     this.defaults.dtime = 1250;
 
-     this.defaults.SUCESS_CODE = 200;
 
-     this.defaults.FAILURE_CODE = 400;
 
-     this.defaults.SERVER_ERROR = 500;
 
-     this.defaults.NO_PERMISSION = 401;
 
-     this.defaults.PAGE_NUMS = 10;
 
-     this.defaults.PAGE_MAX_NUMS = 50;
 
-     this.init();
 
- };
 
- /**
 
-  * 弹框提示
 
-  * @param time
 
-  * @param html
 
-  * @param type
 
-  * @private
 
-  */
 
- GameAdmin.prototype._alert = function(html, type, time){
 
-     type = type || "1";
 
-     var html2='<div class="GameMsg">\
 
- 				<div>\
 
- 				'+html+'\
 
- 				</div>\
 
- 			</div>\
 
- 			<div class="GameMsgBg"></div>';
 
-     switch(type){
 
-         case "1"://时间自动关闭
 
-             if($(".GameMsg").length!=0){
 
-                 $(".GameMsg").show().find("div").html(html);
 
-             }else{
 
-                 $("body").append(html2);
 
-             }
 
-             closefn(time);
 
-             break;
 
-         default:
 
-     }
 
-     function closefn(time){
 
-         time=time?time:1250;
 
-         setTimeout(function(){
 
-             $(".GameMsg,.GameMsgBg").remove();
 
-         },time)
 
-     }
 
- };
 
- GameAdmin.prototype.init = function(){
 
-     // post请求数据是否开始
 
-     this.poststart = false;
 
-     // 添加埋点
 
-     this.urls.buriedpoint = '/api/buriedpoint';// 埋点
 
-     this.urls.draw = '/api/draw';// 抽奖
 
-     this.urls.rankinglist = '/api/rankinglist';// 获取排行榜
 
-     this.urls.createranking = '/api/createranking';// 添加排行榜
 
-     this.urls.awardslist = '/api/awardslist';// 我的奖品列表
 
-     this.urls.awardsdetail = '/api/awardsdetail';// 奖品详细信息
 
-     this.urls.getpartake = '/api/getpartake';// 获取活动参与人数
 
-     this.urls.getfirst = '/api/first';// 根据活动ID获取最好的成绩
 
-     this.urls.myresult = '/api/myresult';// 获取我的最佳成绩
 
-     this.urls.createpricecollect = '/api/createpricecollect';// 添加兑奖码收藏
 
-     this.urls.mydrawnumber = '/api/mydrawnumber';// 我的抽奖次数
 
- };
 
- GameAdmin.prototype.mydrawnumber = function(data, callback){
 
-     // 我的抽奖次数
 
-     var _this = this;
 
-     var _data = {
 
-         '_token' : $('meta[name="_token"]').attr('content'),
 
-         'activity_id' : this.activity_id,
 
-         'openid' : this.openid
 
-     };
 
-     if(_this.poststart != false){
 
-         // 已经开始了一个post请求,必须等到post完成之后再发送请求
 
-         return ;
 
-     }
 
-     _this.poststart = true;
 
-     $.post(this.urls.mydrawnumber, _data, function($data){
 
-         _this.poststart = false;
 
-         if($data.status == _this.defaults.SUCESS_CODE){
 
-             console.log($data);
 
-             if(typeof callback != 'undefined' && callback instanceof Function) {
 
-                 callback($data);
 
-             }
 
-         }else{
 
-             _this._alert($data.msg);
 
-             callback($data);
 
-         }
 
-     });
 
- };
 
- GameAdmin.prototype.awardsdetail = function(data, callback){
 
-     // 奖品详细信息
 
-     var _this = this;
 
-     var _data = {
 
-         '_token' : $('meta[name="_token"]').attr('content'),
 
-         'activity_id' : this.activity_id,
 
-         'awards_id' : data.awards_id
 
-     };
 
-     if(_this.poststart != false){
 
-         // 已经开始了一个post请求,必须等到post完成之后再发送请求
 
-         return ;
 
-     }
 
-     _this.poststart = true;
 
-     $.post(this.urls.awardsdetail, _data, function($data){
 
-         _this.poststart = false;
 
-         if($data.status == _this.defaults.SUCESS_CODE){
 
-             console.log($data);
 
-             if(typeof callback != 'undefined' && callback instanceof Function) {
 
-                 callback($data);
 
-             }
 
-         }else{
 
-             _this._alert($data.msg);
 
-             callback($data);
 
-         }
 
-     });
 
- };
 
- GameAdmin.prototype.createpricecollect = function(data, callback){
 
-     // 添加兑奖码收藏
 
-     var _this = this;
 
-     var _data = {
 
-         '_token' : $('meta[name="_token"]').attr('content'),
 
-         'openid' : this.openid,
 
-         'prize_id' : data.prize_id
 
-     };
 
-     if(_this.poststart != false){
 
-         // 已经开始了一个post请求,必须等到post完成之后再发送请求
 
-         return ;
 
-     }
 
-     _this.poststart = true;
 
-     $.post(this.urls.createpricecollect, _data, function($data){
 
-         _this.poststart = false;
 
-         if($data.status == _this.defaults.SUCESS_CODE){
 
-             console.log($data);
 
-             if(typeof callback != 'undefined' && callback instanceof Function) {
 
-                 callback($data);
 
-             }
 
-         }else{
 
-             _this._alert($data.msg);
 
-             callback($data);
 
-         }
 
-     });
 
- };
 
- GameAdmin.prototype.myresult = function(data, callback){
 
-     // 获取我的最佳成绩
 
-     var _this = this;
 
-     var _data = {
 
-         '_token' : $('meta[name="_token"]').attr('content'),
 
-         'openid' : this.openid,
 
-         'id' : this.activity_id,// 活动ID
 
-         'type' : 'time' // 【score|time】
 
-     };
 
-     if(_this.poststart != false){
 
-         // 已经开始了一个post请求,必须等到post完成之后再发送请求
 
-         return ;
 
-     }
 
-     _this.poststart = true;
 
-     $.post(this.urls.myresult, _data, function($data){
 
-         _this.poststart = false;
 
-         if($data.status == _this.defaults.SUCESS_CODE){
 
-             console.log($data);
 
-             if(typeof callback != 'undefined' && callback instanceof Function) {
 
-                 callback($data);
 
-             }
 
-         }else{
 
-             _this._alert($data.msg);
 
-             callback($data);
 
-         }
 
-     });
 
- };
 
- GameAdmin.prototype.getfirst = function(data, callback){
 
-     // 根据活动ID获取最好的成绩
 
-     var _this = this;
 
-     var _data = {
 
-         '_token' : $('meta[name="_token"]').attr('content'),
 
-         'id' : this.activity_id,
 
-         'type' : 'time' // 【score|time】
 
-     };
 
-     if(_this.poststart != false){
 
-         // 已经开始了一个post请求,必须等到post完成之后再发送请求
 
-         return ;
 
-     }
 
-     _this.poststart = true;
 
-     $.post(this.urls.getfirst, _data, function($data){
 
-         _this.poststart = false;
 
-         if($data.status == _this.defaults.SUCESS_CODE){
 
-             console.log($data);
 
-             if(typeof callback != 'undefined' && callback instanceof Function) {
 
-                 callback($data);
 
-             }
 
-         }else{
 
-             _this._alert($data.msg);
 
-             callback($data);
 
-         }
 
-     });
 
- };
 
- GameAdmin.prototype.getpartake = function(data, callback){
 
-     // 获取活动参与人数
 
-     var _this = this;
 
-     var _data = {
 
-         '_token' : $('meta[name="_token"]').attr('content'),
 
-         'activity_id' : this.activity_id
 
-     };
 
-     if(_this.poststart != false){
 
-         // 已经开始了一个post请求,必须等到post完成之后再发送请求
 
-         return ;
 
-     }
 
-     _this.poststart = true;
 
-     $.post(this.urls.getpartake, _data, function($data){
 
-         _this.poststart = false;
 
-         if($data.status == _this.defaults.SUCESS_CODE){
 
-             console.log($data);
 
-             if(typeof callback != 'undefined' && callback instanceof Function) {
 
-                 callback($data);
 
-             }
 
-         }else{
 
-             _this._alert($data.msg);
 
-             callback($data);
 
-         }
 
-     });
 
- };
 
- GameAdmin.prototype.rankinglist = function(data, callback){
 
-     // 获取排行榜
 
-     var _this = this;
 
-     var _data = {
 
-         '_token' : $('meta[name="_token"]').attr('content'),
 
-         'id' : this.activity_id,
 
-         'type' : 'time' // 【score|time】
 
-     };
 
-     if(_this.poststart != false){
 
-         // 已经开始了一个post请求,必须等到post完成之后再发送请求
 
-         return ;
 
-     }
 
-     _this.poststart = true;
 
-     $.post(this.urls.rankinglist, _data, function($data){
 
-         _this.poststart = false;
 
-         if($data.status == _this.defaults.SUCESS_CODE){
 
-             console.log($data);
 
-             if(typeof callback != 'undefined' && callback instanceof Function) {
 
-                 callback($data);
 
-             }
 
-         }else{
 
-             _this._alert($data.msg);
 
-             callback($data);
 
-         }
 
-     });
 
- };
 
- GameAdmin.prototype.createranking = function(data, callback){
 
-     var _this = this;
 
-     var _data = {
 
-         '_token' : $('meta[name="_token"]').attr('content'),
 
-         'openid' : this.openid,
 
-         'activity_id' : this.activity_id,
 
-         'record_time' : data.record_time,
 
-         'record_score' : data.record_score
 
-     };
 
-     if(_this.poststart != false){
 
-         // 已经开始了一个post请求,必须等到post完成之后再发送请求
 
-         return ;
 
-     }
 
-     _this.poststart = true;
 
-     // 创建排行榜
 
-     $.post(this.urls.createranking, _data, function($data){
 
-         _this.poststart = false;
 
-         if($data.status == _this.defaults.SUCESS_CODE){
 
-             console.log($data);
 
-             if(typeof callback != 'undefined' && callback instanceof Function) {
 
-                 callback($data);
 
-             }
 
-         }else{
 
-             _this._alert($data.msg);
 
-             callback($data);
 
-         }
 
-     });
 
- };
 
- GameAdmin.prototype.myPrize = function(data, callback){
 
-     // 我的奖品
 
-     var _this = this;
 
-     var _data = {
 
-         '_token' : $('meta[name="_token"]').attr('content'),
 
-         'openid' : this.openid,
 
-         'activity_id' : this.activity_id
 
-     };
 
-     if(_this.poststart != false){
 
-         // 已经开始了一个post请求,必须等到post完成之后再发送请求
 
-         return ;
 
-     }
 
-     _this.poststart = true;
 
-     $.post(this.urls.awardslist, _data, function($data){
 
-         _this.poststart = false;
 
-         if($data.status == _this.defaults.SUCESS_CODE){
 
-             var award = [];
 
-             $.each($data.data, function(key,item){
 
-                 award.push({
 
-                     Prizeid : item.awards_id,
 
-                     PrizeName : item.award_desc,
 
-                     PrizeText : item.award_name,
 
-                     PrizeTime : item.award_time,
 
-                     PrizeStatus : item.status_str,
 
-                     PrizeCode : item.coupon_code
 
-                 });
 
-             });
 
-             var metmsg={
 
-                 data:award,
 
-                 status:$data.status,
 
-                 msg:$data.msg
 
-             };
 
-     //				Prizeid:2,//奖品id
 
-     //				PrizeName:"一等奖",//奖品名称
 
-     //				PrizeText:"价值50元礼品",//奖品名称
 
-     //				PrizeTime:"2015.05.02至2015.06.02",//有效时间
 
-     //				PrizeStatus:"未兑奖",//领取状态
 
-             if(typeof callback != 'undefined' && callback instanceof Function) {
 
-                 callback(metmsg);
 
-             }
 
-         }else{
 
-             _this._alert($data.msg);
 
-             callback($data);
 
-         }
 
-     });
 
- };
 
- GameAdmin.prototype.draw = function(data, callback){
 
-     this.postPartake();
 
-     //用户抽奖
 
-     var _this = this;
 
-     var _data = {
 
-         '_token' : $('meta[name="_token"]').attr('content'),
 
-         'openid' : this.openid,
 
-         'score' : data.score,
 
-         'activity_id' : this.activity_id
 
-     };
 
-     if(_this.poststart != false){
 
-         // 已经开始了一个post请求,必须等到post完成之后再发送请求
 
-         return ;
 
-     }
 
-     _this.poststart = true;
 
-     $.post(this.urls.draw, _data, function($data){
 
-         _this.poststart = false;
 
-         var data = {};
 
-         if($data.status == _this.defaults.SUCESS_CODE){
 
-             var option = $data.data;
 
-             data = {
 
-                 Resuletype:(option.status==2?1:0),//0=未中奖  1=中奖  2=次数用完了
 
-                 Resuleid:(option.status==2?option.awardInfo.id:0),//奖品id
 
-                 ResuleFrequency:option.today_sy_count,//今日剩余次数
 
-                 ResuleLimitDrawTimes:option.more_is_limit_draw_times,//总体是否限制
 
-                 ResuleTotalTimes:option.total_sy_count,//总体剩余次数
 
-                 Resulenumber:option.partakeNum,//参与人数
 
-                 ResuleName:(option.status==2?option.awardInfo.award_desc:''),//奖品等级
 
-                 ResuleText:(option.status==2?option.awardInfo.award_name:''),//奖品名称
 
-                 ResuleUrl:"http://img-staging.liweijia.com/liweijia/wap/weixinActivity/images/gift.png",//奖品图片
 
-             };
 
-             var metmsg={
 
-                 data:data,
 
-                 status:$data.status,
 
-                 msg:$data.msg
 
-             };
 
-             if(typeof callback != 'undefined' && callback instanceof Function) {
 
-                 callback(metmsg);
 
-             }
 
-         }else{            
 
-             _this._alert($data.msg);
 
-             callback($data);
 
-         }
 
-     });
 
- };
 
- GameAdmin.prototype.postView = function(){
 
-     // 记录浏览-埋点
 
-     this.postMaiDian('view', function(d){});
 
- };
 
- GameAdmin.prototype.postPartake = function(){
 
-     // 记录参与人数-埋点
 
-     this.postMaiDian('partake', function(d){});
 
- };
 
- GameAdmin.prototype.postAward = function(){
 
-     // 记录获奖-埋点
 
-     this.postMaiDian('award', function(d){});
 
- };
 
- GameAdmin.prototype.postConvert = function(){
 
-     // 记录兑奖-埋点
 
-     this.postMaiDian('convert', function(d){});
 
- };
 
- GameAdmin.prototype.postShare = function(){
 
-     // 记录分享-埋点
 
-     this.postMaiDian('share', function(d){});
 
- };
 
- GameAdmin.prototype.postMaiDian = function(topic, callback){
 
-     // 记录--埋点
 
-     var _this = this;
 
-     var data = {
 
-         '_token' : $('meta[name="_token"]').attr('content'),
 
-         'topic' : topic,
 
-         'openid' : this.openid,
 
-         'id' : this.activity_id
 
-     };
 
-     $.post(this.urls.buriedpoint, data, function($data){
 
-         if($data.status == _this.defaults.SUCESS_CODE){
 
-             if(typeof callback != 'undefined' && callback instanceof Function) {
 
-                 callback($data);
 
-             }
 
-         }else{
 
-             callback($data);
 
-         }
 
-     }, 'json');
 
- };
 
 
  |