Authored by 郝肖肖

店铺 领取优惠券接口

... ... @@ -34,7 +34,8 @@ var $subNav = $('.home-sub-nav'),
appVersion = $('input[name="app_version"]').val(),
brand = $('input[name="brand"]').val(),
coverChannel = $('input[name="coverChannel"]').val(),
favId = $('input[name="favId"]').val();
favId = $('input[name="favId"]').val(),
isCouponClick = true;;
var winH = $(window).height(),
noResult = '<p class="no-result">未找到相关搜索结果</p>';
... ... @@ -954,3 +955,45 @@ $('#collect').on('touchstart', function(e) {
collectShop();
}
});
$(".coupon-content .receive-btn").on('touchstart', function(e) {
var that = this,
code = $(this).closest('.coupon-small').data('id') || '';
if (isCouponClick === false) {
return false;
}
isCouponClick = false;
$.ajax({
method: 'POST',
url: '/product/index/userCoupon',
// url: location.protocol + '//m.yohobuy.com/product/index/userCoupon',
data: {
couponID: code
},
xhrFields: {
withCredentials: true
},
success: function(data) {
isCouponClick = true;
if (data.code === 200) {
tip.show('领取成功');
$(that).addClass('padding-20').html('已领取');
$(that).unbind('touchstart');//移除绑定事件
return true;
} else if (data.code === 4401) {
document.location.href = data.url;
} else {
tip.show(data.message);
}
},
error: function() {
tip.show('网络断开连接了~');
isCouponClick = true;
}
});
});
\ No newline at end of file
... ...
... ... @@ -514,8 +514,7 @@ class ListModel
'name' => $value['coupon_name'],
'pic' => $value['coupon_pic'],
'money' => $value['money'],
'status' => $key === 1,
// 'status' => $value['status'] === 1,
'status' => $value['status'] === 1,
);
}
}
... ...
... ... @@ -5,6 +5,7 @@ use LibModels\Wap\Product\SaleData;
use LibModels\Wap\Product\ShopData;
use Plugin\Helpers;
use Product\ListModel;
use LibModels\Wap\Coupon\CouponData;
/**
* 商品列表相关的控制器
... ... @@ -696,4 +697,41 @@ class IndexController extends AbstractAction
return ListModel::getBrandShops($brandId);
}
/**
* 用户领券
* @param int app_version
* @param int couponID
* @return json
*/
public function userCouponAction() {
$appVersion = $this->post('app_version', 0);
$couponID = $this->post('couponID', 0);
if (empty($appVersion)){
$uid = $this->getUid();
} else {
$uid = $this->getCookie('appUid');
}
$data = array();
do {
if (empty($uid)) {
$data['code'] = 4401;//401错误已经被接口占用
$refer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
$toUrl = Helpers::url('/signin.html')."?refer=".$refer;
if (!empty($appVersion)){
$toUrl .= '&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"'.$refer.'"}}';
}
$data['url'] = $toUrl;
break;
}
$data = CouponData::receiveCoupon($uid, $couponID);
} while(false);
$this->echoJson($data);
}
}
... ...