Authored by Rock Zhang

添加限购商品支付的接口(新增app.Shopping.payment,app.Shopping.compute,app.Shopping.submit增加

product_skn_list参数)

Code Review By Rock Zhang
... ... @@ -248,16 +248,23 @@ class CartData
*
* @param int $uid 用户ID
* @param string $cartType 购物车类型,ordinary表示普通购物车
* @param int $isUseYohoCoin 是否使用有货币,默认0不使用, 1使用
* @param int $isUseYohoCoin 是否使用有货币,0不使用, 1使用
* @param string $skuList 购买限购商品时需要传递的参数
* @return array 接口返回的数据
*/
public static function cartPay($uid, $cartType, $isUseYohoCoin = 0)
public static function cartPay($uid, $cartType, $isUseYohoCoin, $skuList)
{
$param = Yohobuy::param();
$param['method'] = 'app.Shopping.payment';
$param['cart_type'] = $cartType;
$param['yoho_coin_mode'] = $isUseYohoCoin;
$param['uid'] = $uid;
// 购买限购商品时需要传递product_sku_list参数
if (!empty($skuList)) {
$param['product_sku_list'] = $skuList;
}
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
... ... @@ -272,9 +279,10 @@ class CartData
* @param int $paymentType 支付方式,1表示在线支付,2表示货到付款
* @param string $couponCode 优惠券码
* @param mixed $yohoCoin 使用的YOHO币数量
* @param string $skuList 购买限购商品时需要传递的参数
* @return array 接口返回的数据
*/
public static function orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin)
public static function orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin, $skuList)
{
$param = Yohobuy::param();
$param['method'] = 'app.Shopping.compute';
... ... @@ -288,6 +296,11 @@ class CartData
$param['use_yoho_coin'] = $yohoCoin;
}
// 购买限购商品时需要传递product_sku_list参数
if (!empty($skuList)) {
$param['product_sku_list'] = $skuList;
}
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
... ... @@ -346,9 +359,10 @@ class CartData
* @param string $remark 留言
* @param string $couponCode 优惠券码
* @param mixed $yohoCoin 使用的YOHO币数量或为空
* @param string $skuList 购买限购商品时需要传递的参数
* @return array 接口返回的数据
*/
public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin)
public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin, $skuList)
{
$param = Yohobuy::param();
$param['debug'] = 'Y';
... ... @@ -375,6 +389,12 @@ class CartData
if (!empty($yohoCoin)) {
$param['use_yoho_coin'] = $yohoCoin;
}
// 购买限购商品时需要传递product_sku_list参数
if (!empty($skuList)) {
$param['product_sku_list'] = $skuList;
}
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
... ...
... ... @@ -314,13 +314,30 @@ class CartModel
* @param int $uid 用户ID
* @param string $cartType 购物车类型,ordinary表示普通购物车
* @param array $orderInfo cookie中记录的一些订单有关数据
* @param string $limitCode 限购商品的限购码,用户限购商品购买
* @param string $sku 商品sku,用于限购商品购买
* @param stirng $skn 商品skn,用于限购商品购买
* @param int $buyNumber 购买商品数目,用户限购商品支付
* @return array 接口返回的数据
*/
public static function cartPay($uid, $cartType, $orderInfo)
public static function cartPay($uid, $cartType, $orderInfo, $limitCode, $sku, $skn, $buyNumber)
{
$result = array();
$pay = CartData::cartPay($uid, $cartType);
$skuList = '';
if (!empty($sku) && !empty($skn) && !empty($buyNumber)) { // 存在sku,skn和buyNumber时
$skuList = json_encode(array(
array(
'type' => 'limitcode',
'limitproductcode' => $limitCode,
'skn' => $skn,
'sku' => $sku,
'buy_number' => $buyNumber
)
));
}
$pay = CartData::cartPay($uid, $cartType, 0, $skuList);
// 商品为空返回
if (!$pay || empty($pay['data']['goods_list'])) {
... ... @@ -335,7 +352,7 @@ class CartModel
// cookie保存的数据
if (!empty($orderInfo)) {
$orderCompute = self::orderCompute($uid, $cartType, $orderInfo['deliveryId'], $orderInfo['paymentTypeId'], $orderInfo['couponCode'], $orderInfo['yohoCoin']);
$orderCompute = self::orderCompute($uid, $cartType, $orderInfo['deliveryId'], $orderInfo['paymentTypeId'], $orderInfo['couponCode'], $orderInfo['yohoCoin'], $skuList);
}
// 根据地址id查询地址信息
... ... @@ -503,13 +520,14 @@ class CartModel
* @param int $paymentType 支付方式,1表示在线支付,2表示货到付款
* @param string $couponCode 优惠券码
* @param mixed $yohoCoin 使用的YOHO币数量
* @param string $skuList 购买限购商品时需要传递的参数
* @return array 接口返回的数据
*/
public static function orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin)
public static function orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin, $skuList)
{
$result = array();
$compute = CartData::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin);
$compute = CartData::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin, $skuList);
if ($compute && isset($compute['code']) && $compute['code'] === 200) {
// 有货币添加.00后缀
$compute['data']['use_yoho_coin'] = Helpers::transPrice($compute['data']['use_yoho_coin']);
... ... @@ -596,9 +614,10 @@ class CartModel
* @param string $remark 留言
* @param string $couponCode 优惠券码
* @param mixed $yohoCoin 使用的YOHO币数量或为空
* @param string $skuList 购买限购商品时需要传递的参数
* @return array 接口返回的数据
*/
public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin)
public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin, $skuList)
{
$result = array('code' => 400, 'message' => '出错啦');
... ... @@ -612,7 +631,7 @@ class CartModel
$result['code'] = 403;
$result['message'] = '请选择配送方式';
} else {
$orderSubRes = CartData::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin);
$orderSubRes = CartData::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin, $skuList);
if ($orderSubRes && isset($orderSubRes['code'])) {
$result = $orderSubRes;
}
... ...
... ... @@ -285,7 +285,7 @@ class IndexController extends AbstractAction
$this->setTitle('确认订单');
$this->setNavHeader('确认订单', Helpers::url('/cart/index/index'), false); // 不显示右上角home按钮
// 购物车商品为空跳转到购物车页面
$cartType = $this->get('cartType', '');
$cookieData = $this->getCookie('order-info', null);
$orderInfo = array();
... ... @@ -294,8 +294,15 @@ class IndexController extends AbstractAction
$cartType = $orderInfo['cartType'];
}
// 如果传递了code, sku,skn,buy_number就代表是限购商品
$limitCode = $this->get('code', '');
$sku = $this->get('sku', '');
$skn = $this->get('skn', '');
$buyNumber = $this->get('buy_number', '');
// 购物车商品为空跳转到购物车页面
$uid = $this->getUid(true);
$order = CartModel::cartPay($uid, $cartType, $orderInfo);
$order = CartModel::cartPay($uid, $cartType, $orderInfo, $limitCode, $sku, $skn, $buyNumber);
if (isset($order['cartUrl'])) {
$this->go($order['cartUrl']);
}
... ... @@ -323,7 +330,8 @@ class IndexController extends AbstractAction
$couponCode = $this->post('couponCode', null);
$yohoCoin = $this->post('yohoCoin', null);
$uid = $this->getUid(true);
$result = CartModel::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin);
$skuList = $this->post('skuList', '');
$result = CartModel::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin, $skuList);
}
$this->echoJson($result);
... ... @@ -423,7 +431,8 @@ class IndexController extends AbstractAction
$remark = $this->post('msg', null);
$couponCode = $this->post('couponCode', null);
$yohoCoin = $this->post('yohoCoin', 1);
$result = CartModel::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin);
$skuList = $this->post('skuList', '');
$result = CartModel::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin, $skuList);
// 记录下单异常的数据
if (empty($result)) {
... ...