Authored by 周少峰

use yohocoin

... ... @@ -474,19 +474,23 @@ class CartData
* @param int $productSku
* @param int $buyNumber
* @param int $useYohoCoin
* @param int $yohoCoinMode 1:使用yoho币;0:不使用yoho币
* @author sefon 2016-7-2 18:12:30
* @return array
*/
public static function checkickets ($uid, $productSku, $buyNumber, $useYohoCoin = 0)
public static function checkTickets ($uid, $productSku, $buyNumber, $useYohoCoin = 0, $yohoCoinMode = true)
{
$param = Yohobuy::param();
$param['method'] = 'app.shopping.ticket';
$param['uid'] = $uid;
$param['product_sku'] = $productSku;
$param['buy_number'] = $buyNumber;
if (!$yohoCoinMode) {
$param['yoho_coin_mode'] = 0;
}
$param['use_yoho_coin'] = $useYohoCoin;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(API_URL, $param);
return Yohobuy::get(API_URL, $param);
}
/**
... ...
... ... @@ -275,7 +275,14 @@ function addTickets(productSku, buyNumber) {
type: 'post',
success: function (addRestult) {
if (addRestult.code != 200) {
tip.show(addRestult.masseage);
if (addRestult.code == 401) {
var refer = window.location.href;
window.location.href = '//m.yohobuy.com/signin.html?refer=' + refer;
}
tip.show(addRestult.message);
setTimeout(function() {
location.reload();
}, 1000);
} else {
$productSku.val(productSku);
$buyNumber.val(buyNumber);
... ...
... ... @@ -137,20 +137,30 @@ function updateDeliverId(id) {
function orderCompute() {
var yohoCoin = orderInfo('yohoCoin'),
deliverId = orderInfo('deliveryId');
loading.showLoadingMask();
$.ajax({
method: 'POST',
url: '/cart/index/orderCompute',
data: {
deliverId = orderInfo('deliveryId'),
data = {
cartType: orderInfo('cartType') || 'ordinary',
deliveryId: orderInfo('deliveryId'),
paymentTypeId: orderInfo('paymentTypeId'),
couponCode: orderInfo('couponCode'),
yohoCoin: yohoCoin,
skuList: isLimitGood() ? orderInfo('skuList') : undefined
};
//门票
if (isTickets) {
data = {
type: 'tickets',
productSku: productSku,
buyNumber: buyNumber,
yohoCoin: yohoCoin
}
};
loading.showLoadingMask();
$.ajax({
method: 'POST',
url: '/cart/index/orderCompute',
data: data
}).then(function(res) {
if ($.type(res) !== 'object') {
window.location.reload();
... ... @@ -278,7 +288,7 @@ $('.dispatch-time').on('touchend', 'li', function() {
$('.coin').on('touchend', function() {
var $this = $(this);
if ($this.find('.checkbox').hasClass('icon-cb-radio')) {
orderInfo('yohoCoin', $this.data('yoho-coin'));
$this.find('.can-use').hide();
... ... @@ -387,7 +397,7 @@ function ticketsConfirm () {
productSku: productSku,
buyNumber: buyNumber,
mobile: $ticketsMobile.val(),
useYohoCoin: ''
useYohoCoin: orderInfo('yohoCoin')
};
$.ajax({
... ...
... ... @@ -1119,7 +1119,7 @@ class CartModel
{
$result = array();
$data = CartData::checkickets($uid, $productSku, $buyNumber, $useYohoCoin);
$data = CartData::checkTickets($uid, $productSku, $buyNumber, $useYohoCoin);
if (!isset($data['code']) || $data['code'] !== 200) {
return $result;
}
... ... @@ -1147,12 +1147,24 @@ class CartModel
$result['price'] = Helpers::transPrice($price, true);
// 有货币
$result['yohoCoin'] = Helpers::transPrice($data['data']['yoho_coin']);
/*
* 默认使用有货币
* $result['useYohoCoin'] = isset($orderCompute['use_yoho_coin']) ? $orderCompute['use_yoho_coin'] : $payReturn['use_yoho_coin'];
*/
$result['useYohoCoin'] = isset($orderCompute['use_yoho_coin']) ? $orderCompute['use_yoho_coin'] : false;
// print_r($data);
$result['useYohoCoin'] = isset($data['data']['shopping_cart_data']['use_yoho_coin']) ? $data['data']['shopping_cart_data']['use_yoho_coin'] : false;
return $result;
}
public static function ticketsOrderCompute($uid, $productSku, $buyNumber, $yohoCoin)
{
$result = array();
$compute = CartData::checkTickets($uid, $productSku, $buyNumber, $yohoCoin);
if ($compute && isset($compute['code']) && $compute['code'] === 200) {
// 有货币添加.00后缀
$compute['data']['shopping_cart_data']['use_yoho_coin'] = Helpers::transPrice($compute['data']['shopping_cart_data']['use_yoho_coin']);
$result = $compute['data']['shopping_cart_data'];
}
// print_r($compute);
return $result;
}
}
... ...
... ... @@ -360,9 +360,19 @@ class IndexController extends AbstractAction
$paymentType = $this->post('paymentTypeId', 1);
$couponCode = $this->post('couponCode', null);
$yohoCoin = $this->post('yohoCoin', null);
$productSku = $this->post('productSku', null);
$buyNumber = $this->post('buyNumber', null);
$uid = $this->getUid(true);
$skuList = $this->post('skuList', '');
$result = CartModel::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin, $skuList);
$type = $this->post('type', null);
//type : tickets 门票
if ($type !== 'tickets' ) {
$result = CartModel::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin, $skuList);
}
//非门票
else {
$result = CartModel::ticketsOrderCompute($uid, $productSku, $buyNumber, $yohoCoin);
}
}
$this->echoJson($result);
... ... @@ -580,17 +590,24 @@ class IndexController extends AbstractAction
*/
public function checkTicketsAction()
{
// $uid = $this->getUid();
// if (!$this->isAjax() || !$uid) {
// exit;
// }
// $productSku = $this->post('$productSku');
// $buyNumber = $this->post('$buyNumber');
// $data = CartData::checkTickets($uid, $productSku, $buyNumber);
$data = array(
'code' => 200,
'data' => array()
);
if (!$this->isAjax()) {
exit;
}
$data = array();
$uid = $this->getUid();
do {
//判断用户登陆
if (!$uid) {
$data = array(
'code' => 401,
);
break;
}
$productSku = $this->post('productSku');
$buyNumber = $this->post('buyNumber');
$useYohoCoin = $this->post('useYohoCoin', 0);
$data = CartData::checkTickets($uid, $productSku, $buyNumber, $useYohoCoin);
} while(false);
$this->echoJson($data);
}
... ... @@ -606,7 +623,6 @@ class IndexController extends AbstractAction
$this->error();
}
$tickets = CartModel::getTickets($uid, $productSku, $buyNumber);
// print_r($tickets); exit;
$this->setTitle('确认订单');
$this->setNavHeader('确认订单', '', false); // 不显示右上角home按钮
... ...