Skip to content

Instantly share code, notes, and snippets.

@mimosa
Created March 16, 2014 15:42
Show Gist options
  • Save mimosa/9585128 to your computer and use it in GitHub Desktop.
Save mimosa/9585128 to your computer and use it in GitHub Desktop.
红美店铺,优惠卷领取代码。
  • 领取链接填写规则:
<a href="javascript:onGetCoupon(8);">1100</a>
<a href="javascript:onGetCoupon(7);">510</a>
<a href="javascript:onGetCoupon(6);">300</a>
<a href="javascript:onGetCoupon(5);">99</a>
  • 代码+到页面最后。
<script type='text/javascript'>
  var user_id = '';
  // 获取用户信息
  function getSimpleUserInfo(callback) {
    $.getJSON('https://passport.mmall.com/user/getSimpleInfo.html?callback=?', function(sData) {
      callback(sData);
    });
  }
  // 获取用户ID
  getSimpleUserInfo(function(sData){
    if(sData && sData.login_name){
      user_id = sData.user_id;
    }
  });
  // 获取优惠券
  function onGetCoupon(batch_id){
    if(user_id == ''){
      alert('亲,请您先登录。');
    }else{
      $.ajax({
        type: 'POST',
        url: 'http://www.mmall.com/activity/activity/coupon?batch_id=' + batch_id + '&user_id=' + user_id,
        cache: false,
        dataType: 'json',
        success:function(res){
          if(res.code == -1){
            alert('亲,您不能再领了。');
          }else if(res.code == 0){
            alert(res.message);
          }
        }
      });
    }
  }
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment