Authored by 周少峰

add method

... ... @@ -468,4 +468,25 @@ class CartData
return Yohobuy::get(API_URL, $param);
}
/**
* 添加电子票
* @param int $uid
* @param int $productSku
* @param int $buyNumber
* @param int $useYohoCoin
* @author sefon 2016-7-2 18:12:30
* @return array
*/
public static function addTickets ($uid, $productSku, $buyNumber, $useYohoCoin = 0)
{
$param = Yohobuy::param();
$param['method'] = 'app.shopping.ticket';
$param['uid'] = $uid;
$param['product_sku'] = $productSku;
$param['buy_number'] = $buyNumber;
$param['use_yoho_coin'] = $useYohoCoin;
$param['client_secret'] = Sign::getSign($param);
// return Yohobuy::get(API_URL, $param);
return Yohobuy::get('dev', $param);
}
}
... ...
... ... @@ -37,7 +37,9 @@ var $chosePanel = $('#chose-panel'),
$choseArea,
$cartBar,
$soonSoldOut = $('.soonSoldOut-tag'),
$yohoPage = $('.yoho-page');
$yohoPage = $('.yoho-page'),
//门票 限购数量
ticketsLimit = $('#limitNum').val();
// 购物车编辑标相关变量
var isEdit,
... ... @@ -173,7 +175,7 @@ function updateConformButtonClassAndText() {
$chosed = $allChoseItems.find('.chosed');
if (2 === $chosed.closest('.zero-stock').length) {
$('#chose-btn-sure').css('background-color', '#c0c0c0').html('已售罄');
} else if (limitProductCode) {
} else if (limitProductCode || ticketsLimit) {
$('#chose-btn-sure').css('background-color', '#eb0313').html('立即购买');
} else {
$('#chose-btn-sure').css('background-color', '#eb0313').html(isEdit ? '确认' : '加入购物车');
... ... @@ -183,7 +185,14 @@ function updateConformButtonClassAndText() {
//显示剩余件数
function displayGoodNum(curGoodNum) {
//数量大于0
//门票限购
if (ticketsLimit && curGoodNum > ticketsLimit) {
$allChoseItems.find('.num .left-num').html('限购' + ticketsLimit + '件');
$leftNum.val(curGoodNum);
return;
}
//数量大于
if (curGoodNum > 0) {
if ($soonSoldOut.length > 0) {
$allChoseItems.find('.num .left-num').html('即将售罄');
... ... @@ -247,6 +256,30 @@ function changeColorChosed(newColorIndex) {
return 0;
}
//添加门票
function addTickets(productSku, buyNumber) {
var data = {
productSku: productSku,
buyNumber: buyNumber
}
//添加电子票
$.ajax({
url: '/cart/index/cart',
dataType: 'json',
data: data,
type: 'post',
success: function (addRestult) {
//调整订单确认页
window.location.href = '/cart/index/orderEnsure?cartType=tickets';
},
error: function () {
tip.show('网络异常~');
}
});
}
init();
... ... @@ -296,7 +329,6 @@ $yohoPage.on('touchstart', '.color-list .block', function() {
//老的选中尺码去掉勾选,新的选中尺码加上勾选
curGoodNum = changeSizeChosed(index + 1);
// 显示剩余数量
displayGoodNum(curGoodNum);
... ... @@ -402,9 +434,10 @@ $yohoPage.on('touchstart', '.btn-minus', function() {
$num.val(num - 1);
}).on('touchstart', '.btn-plus', function() {
var num = parseInt($num.val(), 10);
var num = parseInt($num.val(), 10),
maxTips = ticketsLimit ? '每人只可购买' + ticketsLimit + '张当日门票' : '您选择的数量超过了最大库存量~';
leftNum = $('#left-num').val();
leftNum = ticketsLimit || $('#left-num').val();
if (!checkColorSizeNum()) {
return;
... ... @@ -416,7 +449,7 @@ $yohoPage.on('touchstart', '.btn-minus', function() {
//TODO:库存数验证
if (num > leftNum - 1) {
tip.show('您选择的数量超过了最大库存量~');
tip.show(maxTips);
return;
}
$num.val(num + 1);
... ... @@ -461,6 +494,12 @@ $yohoPage.on('touchstart', '.btn-minus', function() {
confirming = true;
loading.showLoadingMask();
//立即购买门票
if (ticketsLimit) {
addTickets(productSku, buyNumber);
return;
}
//针对是否处于编辑模式设置不同的url和需要post的数据
if (isEdit) {
cartGoodData = {
... ...
... ... @@ -24,10 +24,6 @@
padding: 0 22px;
}
.tickets {
}
.chose-items {
height: 325px;
overflow: auto;
... ... @@ -189,4 +185,12 @@
border: none;
}
}
.tickets-info {
span.left-num {
color: #e10;
}
}
}
... ...
... ... @@ -183,5 +183,12 @@
<input type="hidden" name="loginUrl" id="loginUrl" value="{{.}}">
{{/loginUrl}}
{{#if tickets}}
<form name="buyNow" method="post" action="{{buyNowUrl}}">
<input type="hidden" name="productId">
<input type="hidden" name="buyNumber">
</form>
{{/if}}
</div>
{{> layout/footer}}
... ...
... ... @@ -7,6 +7,7 @@ use Index\UserModel;
use Plugin\Helpers;
use Plugin\UnionTrans;
use Home\OrderModel;
use LibModels\Wap\Home\CartData;
use Plugin\UdpLog;
/**
... ... @@ -573,4 +574,23 @@ class IndexController extends AbstractAction
$this->_view->display('jit-detail', $data);
}
/**
* 电子票添加
*
*/
public function addTickets()
{
if (!$this->isAjax()) {
exit;
}
$uid = $this->getUid();
if (!$uid) {
exit;
}
$productSku = $this->post('$productSku');
$buyNumber = $this->post('$buyNumber');
$this->echoJson(CartData::addTickets($uid, $productSku, $buyNumber));
}
}
... ...
... ... @@ -51,9 +51,10 @@ class DetailController extends AbstractAction
if (!$this->isApp()){
$this->setNavHeader('商品详情');
}
// 渲染模板 TODO
//门票
$data['tickets'] = true;
$data['buyNowurl'] = Helpers::url('/cart/index/buyNow');
$data['cartInfo']['colorName'] = $data['tickets'] ? '日期' : '颜色';
$data['cartInfo']['sizeName'] = $data['tickets'] ? '区域' : '尺码';
//单日票
... ... @@ -61,8 +62,10 @@ class DetailController extends AbstractAction
//套票
// $data['package'] = true;
//购票限制
$data['cartInfo']['limit'] = '10';
$data['cartInfo']['limit'] = '4';
// print_r($data); exit;
// 渲染模板 TODO
$this->_view->display('index', $data);
}
... ...