Authored by Rock Zhang

修改购物车结算页面的一些接口

Code Review By Rock Zhang
... ... @@ -201,19 +201,23 @@ class CartData
*
* @param int $uid 用户ID
* @param string $cartType 购物车类型,ordinary表示普通购物车
* @param string $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运
* @param string $paymentType 支付方式,1表示在线支付,2表示货到付款
* @param string $yohoCoin 使用的YOHO币数量,默认为null表示不适用
* @param int $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运
* @param int $paymentType 支付方式,1表示在线支付,2表示货到付款
* @param string $couponCode 优惠券码
* @param mixed $yohoCoin 使用的YOHO币数量
* @return array 接口返回的数据
*/
public static function paymentTypeAndDelivery($uid, $cartType, $deliveryWay, $paymentType, $yohoCoin = null)
public static function orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin)
{
$param = Yohobuy::param();
$param['method'] = 'app.Shopping.compute';
$param['cart_type'] = $cartType;
$param['delivery_way'] = $deliveryWay;
$param['payment_type'] = $paymentType;
if ($yohoCoin !== null) {
if (!empty($couponCode)) {
$param['coupon_code'] = $couponCode;
}
if (!empty($yohoCoin)) {
$param['use_yoho_coin'] = $yohoCoin;
}
... ... @@ -230,7 +234,7 @@ class CartData
* @param string $couponCode 优惠券代码
* @return array 接口返回的数据
*/
public static function getCoupon($uid, $couponCode)
public static function searchCoupon($uid, $couponCode)
{
$param = Yohobuy::param();
$param['method'] = 'app.Shopping.useCoupon';
... ... @@ -242,10 +246,38 @@ class CartData
}
/**
* 购物车结算--获取优惠券列表
*
* @param int $uid 用户ID
* @return array 接口返回的数据
*/
public static function getCouponList($uid)
{
$param = Yohobuy::param();
$param['method'] = 'app.coupons.lists';
$param['type'] = 'notuse';
$param['page'] = 1;
$param['limit'] = 1000;
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 购物车结算--提交结算信息
*
* @param int $uid 用户ID
* @param string $couponCode 优惠券代码
* @param int $addressId 地址ID
* @param int $cartType 购物车类型ID
* @param int $deliveryTime 寄送时间ID
* @param int $deliveryWay 寄送方式ID
* @param string $invoiceTitle 发票说明
* @param int $invoiceId 发票类型ID
* @param int $paymentId 支付方式ID
* @param int $paymentType 支付类型ID
* @param string $remark 留言
* @param mixed $yohoCoin 使用的YOHO币数量或为空
* @return array 接口返回的数据
*/
public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $yohoCoin)
... ... @@ -256,12 +288,19 @@ class CartData
$param['cart_type'] = $cartType;
$param['delivery_time'] = $deliveryTime;
$param['delivery_way'] = $deliveryWay;
$param['invoices_title'] = $invoiceTitle;
$param['invoices_type_id'] = $invoiceId;
if (!empty($invoiceTitle)) {
$param['invoices_title'] = $invoiceTitle;
}
if (!empty($invoiceId)) {
$param['invoices_type_id'] = $invoiceId;
}
$param['payment_id'] = $paymentId;
$param['payment_type'] = $paymentType;
$param['remark'] = $remark;
$param['use_yoho_coin'] = $yohoCoin;
if (!empty($yohoCoin)) {
$param['use_yoho_coin'] = $yohoCoin;
}
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
... ...
... ... @@ -143,16 +143,17 @@ class ShoppingCartController extends AbstractAction
/**
* 购物车结算请求
*/
public function payAction()
public function orderEnsureAction()
{
$this->setTitle('购物车');
$this->setNavHeader('购物车');
$cartType = $this->post('cartType', 'ordinary');
$cookieData = $this->getCookie('orderInfo', null);
$uid = $this->getUid(true);
$data = array(
'orderEnsurePage' => true,
'orderEnsure' => CartModel::cartPay($uid, $cartType)
'orderEnsure' => CartModel::cartPay($uid, $cartType, $cookieData)
);
... ... @@ -160,38 +161,16 @@ class ShoppingCartController extends AbstractAction
}
/**
* 购物车选择支付方式和配送方式接口
*/
public function payAndDeliveryAction()
{
$result = array();
if ($this->isAjax()) {
$cartType = $this->post('cartType', 'ordinary');
$deliveryWay = $this->post('deliveryWay', 1);
$paymentType = $this->post('paymentType', 1);
$uid = $this->getUid(true);
$result = CartModel::paymentTypeAndDelivery($uid, $cartType, $deliveryWay, $paymentType);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
}
/**
* 购物车输入优惠券码使用优惠券
*/
public function couponAction()
public function couponSearchAction()
{
$result = array();
if ($this->isAjax()) {
$couponCode = $this->post('couponCode', '');
$couponCode = $this->get('couponCode', '');
$uid = $this->getUid(true);
$result = CartModel::getCoupon($uid, $couponCode);
$result = CartModel::searchCoupon($uid, $couponCode);
}
if (empty($result)) {
... ... @@ -202,18 +181,16 @@ class ShoppingCartController extends AbstractAction
}
/**
* 购物车使用YOHO币
* 购物车结算--获取优惠券列表
*/
public function yohoCoinAction()
public function couponListAction()
{
$result = array();
if ($this->isAjax()) {
$cartType = $this->post('cartType', 'ordinary');
$deliveryWay = $this->post('deliveryWay', 1);
$paymentType = $this->post('paymentType', 1);
$yohoCoin = $this->post('yohoCoin', 1);
$result = CartModel::paymentTypeAndDelivery($this->_uid, $cartType, $deliveryWay, $paymentType, $yohoCoin);
$uid = $this->getUid(true);
$page = $this->get('page', 1);
$result = CartModel::getCouponList($uid);
}
if (empty($result)) {
... ... @@ -223,133 +200,17 @@ class ShoppingCartController extends AbstractAction
}
}
public function giftAdvanceAction()
{
$data = array(
'advance' => array(
array(
'title' => '【izzue】加¥19购袜子',
'goods' => array(
'id' => 1,
'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/09/17/03/014cacfa5c458b9732c68adf1af15d7a45.jpg?imageMogr2/thumbnail/120x120/extent/120x120/background/d2hpdGU=/position/center/quality/90',
'name' => 'Life.After.Life纯棉短袜',
'salePrice' => 19,
'price' => 99,
'count' => 1
)
),
array(
'title' => '【银鳞堂】加¥9购手绳',
'goods' => array(
'id' => 1,
'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/10/03/10/01bc1878f9154e77ac4f7a6003c954f1b8.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',
'name' => '银鳞堂民族风牛皮手绳',
'salePrice' => 9,
'price' => 19,
'count' => 1
)
)
)
);
$data = array(
'gift' => array(
'id' => 1,
'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/09/17/03/014cacfa5c458b9732c68adf1af15d7a45.jpg?imageMogr2/thumbnail/120x120/extent/120x120/background/d2hpdGU=/position/center/quality/90',
'name' => 'Life.After.Life纯棉短袜',
'color' => '黄色',
'size' => 'L',
'price' => 0,
'count' => 1
)
);
$this->_view->display('gift-advance', array('giftAdvancePage' => true, 'pageHeader' => array(
'navBack' => true, 'navTitle' => '加价购'), 'shoppingCart' => $data));
}
/*
* 确认订单
*/
public function orderEnsureAction()
{
$data = array(
'orderEnsurePage' => true,
'orderEnsure' => array(
'name' => '申建军',
'phoneNum' => '12345678',
'address' => '江苏省南京市建邺区',
'dispatchMode' => array(
array(
'id' => 1,
'name' => '普通快递¥10'
),
array(
'id' => 2,
'name' => '顺丰速运¥15(仅支持顺丰克配送的地区)'
)
),
'dispatchTime' => array(
array(
'id' => 1,
'name' => '工作日、双休日、节假日均可送货'
),
array(
'id' => 2,
'name' => '只工作日送货'
),
array(
'id' => 3,
'name' => '只双休日、节假日送货'
)
),
'goods' => array(
array(
'id' => 1,
'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/11/04/05/01ce2aff32fc3c90584f516167cd526d91.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',
'name' => 'Adidas Originals ZX FLUXM22508',
'color' => '黄',
'size' => '43',
'price' => '699.00',
'count' => '2'
),
array(
'id' => 1,
'thumb' => 'http://img10.static.yhbimg.com/goodsimg/2015/11/04/05/0188f1aca49ac478a565ec029b5d2d4a6c.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',
'name' => 'B.Duck浴室玩伴mini浮水鸭',
'gift' => true,
'color' => '黄',
'size' => '43',
'price' => '0.00',
'count' => '1'
)
),
'coupon' => array(
'count' => 1,
'notUsed' => true
),
'yohoCoin' => '0',
'invoice' => true,
'sumPrice' => 900,
'salePrice' => 90,
'freight' => 0,
'price' => 810
)
);
$this->_view->display('order-ensure', $data);
}
/**
* 下单流程 选择地址
*/
public function selectAddressAction() {
public function selectAddressAction()
{
// 设置网站标题
$this->setTitle('选择地址');
$this->setNavHeader('选择地址', Helpers::url('/shoppingCart/orderEnsure'));
$uid = $this->_uid;
$uid = $this->getUid(true);
$address = UserModel::getAddressData($uid);
$this->_view->display('select-address', array(
... ... @@ -364,19 +225,50 @@ class ShoppingCartController extends AbstractAction
* 下单流程 选择优惠券
*/
public function selectCouponAction() {
public function selectCouponAction()
{
// 设置网站标题
$this->setTitle('选择优惠券');
$this->setNavHeader('选择优惠券', Helpers::url('/shoppingCart/orderEnsure'));
$uid = $this->_uid;
$address = UserModel::getAddressData($uid);
$this->_view->display('select-coupon', array(
'selectCouponPage' => true,
'pageFooter' => true,
'address' => $address
'pageFooter' => true
));
}
/**
* 确认结算订单
*/
public function orderSubAction()
{
$result = array();
if ($this->isAjax()) {
$uid = $this->getUid(true);
$addressId = $this->post('addressId', null);
$cartType = $this->post('cartType', 'ordinary'); // 默认普通购物车
$deliveryTime = $this->post('deliveryTime', 1); // 默认只工作日配送
$deliveryWay = $this->post('deliveryWay', 1); // 默认普通快递
$invoiceTitle = $this->post('invoiceTitle', null);
$invoiceId = $this->post('invoiceId', null);
$paymentId = $this->post('paymentId', 15);
$paymentType = $this->post('paymentType', 1); // 默认在线支付
$remark = $this->post('remark', null); // 默认在线支付
$yohoCoin = $this->post('yohoCoin', 1);
$result = CartModel::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $yohoCoin);
}
if (empty($result)) {
echo ' ';
} else {
// 提交成功清除Cookie
$this->setCookie('orderInfo', null);
$this->echoJson($result);
}
}
}
... ...
... ... @@ -289,9 +289,10 @@ class CartModel
*
* @param int $uid 用户ID
* @param string $cartType 购物车类型,ordinary表示普通购物车
* @param null|string $cookieData cookie中记录的一些订单有关数据
* @return array 接口返回的数据
*/
public static function cartPay($uid, $cartType)
public static function cartPay($uid, $cartType, $cookieData)
{
$result = array();
... ... @@ -299,13 +300,28 @@ class CartModel
if ($pay && isset($pay['code']) && $pay['code'] === 200) {
$payReturn = $pay['data'];
$result = array();
$orderInfo = array();
$address = array();
$orderCompute = array();
// cookie保存的数据
if (!empty($cookieData)) {
$orderInfo = json_decode($cookieData, true);
$orderCompute = self::orderCompute($uid, $cartType, $orderInfo['deliveryId'], $orderInfo['paymentTypeId'], $orderInfo['couponCode'], $orderInfo['yohoCoin']);
}
// 根据地址id查询地址信息
if (isset($orderInfo['addressId'])) {
$address = UserModel::getAddressDataById($uid, $orderInfo['addressId']);
}
// 收货人有关信息
if (isset($payReturn['delivery_address']) && !empty($payReturn['delivery_address'])) {
$result['name'] = $payReturn['delivery_address']['consignee'];
$result['phoneNum'] = $payReturn['delivery_address']['mobile'] ?: $payReturn['delivery_address']['phone'];
$result['address'] = $payReturn['delivery_address']['address'];
$result['addressId'] = isset($address['address_id']) ? $address['address_id'] : $payReturn['delivery_address']['address_id'];
$result['name'] = isset($address['consignee']) ? $address['consignee'] : $payReturn['delivery_address']['consignee'];
$result['phoneNum'] = isset($address['mobile']) ? $address['mobile'] : $payReturn['delivery_address']['mobile'];
$result['address'] = isset($address['address']) ? $address['address'] : $payReturn['delivery_address']['address'];
$result['isSupport'] = ($payReturn['delivery_address']['is_support'] === 'Y');
}
// 配送方式
... ... @@ -316,6 +332,7 @@ class CartModel
$oneDeliv['id'] = $val['delivery_way_id'];
$oneDeliv['name'] = $val['delivery_way_name'];
$oneDeliv['default'] = ($val['default'] === 'Y');
isset($orderInfo['deliveryId']) && $orderInfo['deliveryId'] === $oneDeliv['id'] && $oneDeliv['isSelected'] = true;
$result['dispatchMode'][] = $oneDeliv;
}
... ... @@ -329,6 +346,7 @@ class CartModel
$oneDelivTime['id'] = $one['delivery_time_id'];
$oneDelivTime['name'] = $one['delivery_time_string'];
$oneDelivTime['default'] = ($one['default'] === 'Y');
isset($orderInfo['deliveryTimeId']) && $orderInfo['deliveryTimeId'] === $oneDelivTime['id'] && $oneDeliv['isSelected'] = true;
$result['dispatchTime'][] = $oneDelivTime;
}
... ... @@ -366,14 +384,18 @@ class CartModel
}
// 有货币
$result['yohoCoin'] = $payReturn['yoho_coin'];
$result['yohoCoin'] = isset($orderCompute['use_yoho_coin']) ? isset($orderCompute['use_yoho_coin']) : $payReturn['yoho_coin'];
// 订单数据
if (isset($payReturn['shopping_cart_data']) && !empty($payReturn['shopping_cart_data'])) {
$result['sumPrice'] = Helpers::transPrice($payReturn['shopping_cart_data']['order_amount']);
$result['salePrice'] = Helpers::transPrice($payReturn['shopping_cart_data']['discount_amount']);
$result['price'] = Helpers::transPrice($payReturn['shopping_cart_data']['last_order_amount']);
$result['freight'] = Helpers::transPrice($payReturn['shopping_cart_data']['shipping_cost']);
$sumPrice = isset($orderCompute['order_amount']) ? $orderCompute['order_amount'] : $payReturn['shopping_cart_data']['order_amount'];
$salePrice = isset($orderCompute['discount_amount']) ? $orderCompute['discount_amount'] : $payReturn['shopping_cart_data']['discount_amount'];
$price = isset($orderCompute['last_order_amount']) ? $orderCompute['last_order_amount'] : $payReturn['shopping_cart_data']['last_order_amount'];
$freight = isset($orderCompute['promotion_formula_list']['promotion_amount']) ? $orderCompute['promotion_formula_list']['promotion_amount'] : $payReturn['shopping_cart_data']['promotion_formula_list']['promotion_amount'];
$result['sumPrice'] = Helpers::transPrice($sumPrice);
$result['salePrice'] = Helpers::transPrice($salePrice);
$result['price'] = Helpers::transPrice($price);
$result['freight'] = strtr($freight, '¥', '') . '.00';
}
// 发票有关数据
... ... @@ -390,7 +412,8 @@ class CartModel
// 优惠券数据
$coupons = array('notUsed' => true);
$coupons += UserModel::getCouponData($uid, 0, 1, true);
!empty($orderCompute['coupon_amount']) && $coupons['notUsed'] = $orderInfo['couponName'];
$coupons += self::getCouponList($uid, 0, 1, true);
$result['coupon'] = $coupons;
}
... ... @@ -402,17 +425,19 @@ class CartModel
*
* @param int $uid 用户ID
* @param string $cartType 购物车类型,ordinary表示普通购物车
* @param string $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运
* @param string $paymentType 支付方式,1表示在线支付,2表示货到付款
* @param int $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运
* @param int $paymentType 支付方式,1表示在线支付,2表示货到付款
* @param string $couponCode 优惠券码
* @param mixed $yohoCoin 使用的YOHO币数量
* @return array 接口返回的数据
*/
public static function paymentTypeAndDelivery($uid, $cartType, $deliveryWay, $paymentType)
public static function orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin)
{
$result = array();
$pay = CartData::paymentTypeAndDelivery($uid, $cartType, $deliveryWay, $paymentType);
if ($pay && isset($pay['code']) && $pay['code'] === 200) {
$result = $pay['data'];
$compute = CartData::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin);
if ($compute && isset($compute['code']) && $compute['code'] === 200) {
$result = $compute['data'];
}
return $result;
... ... @@ -425,14 +450,78 @@ class CartModel
* @param string $couponCode 优惠券代码
* @return array 接口返回的数据
*/
public static function getCoupon($uid, $couponCode)
public static function searchCoupon($uid, $couponCode)
{
$result = array('code' => 400, 'message' => '出错啦~');
$coupon = CartData::getCoupon($uid, $couponCode);
if ($coupon && isset($coupon['code']) && $coupon['code'] === 200) {
$result['code'] = $coupon['code'];
$result['message'] = $coupon['message'];
$coupon = CartData::searchCoupon($uid, $couponCode);
if ($coupon && isset($coupon['code'])) {
$result = $coupon;
}
return $result;
}
/**
* 处理优惠券列表数据
*
* @param int $uid 用户ID
* @param boolean $onlyTotal 只返回总数
* @return array|mixed 处理之后的优惠券数据
*/
public static function getCouponList($uid, $onlyTotal = false)
{
$result = array();
// 调用接口获取优惠券数据
$coupons = CartData::getCouponList($uid);
// 处理优惠券数据
if (isset($coupons['data'])) {
if ($onlyTotal) {
$result['count'] = $coupons['data']['total'];
} else {
$couponArr = array();
isset($coupons['data']['couponList']) && $couponArr = $coupons['data']['couponList'];
foreach ($couponArr as &$val) {
$notAvailableRes = self::searchCoupon($uid, $val['couponCode']);
// 处理可用的优惠券
if (isset($notAvailableRes['code']) && $notAvailableRes['code'] !== 200) {
$val['notAvailable'] = true;
}
}
!empty($couponArr) && $result['coupons'] = $couponArr;
}
}
return $result;
}
/**
* 购物车结算--提交结算信息
*
* @param int $uid 用户ID
* @param int $addressId 地址ID
* @param int $cartType 购物车类型ID
* @param int $deliveryTime 寄送时间ID
* @param int $deliveryWay 寄送方式ID
* @param string $invoiceTitle 发票说明
* @param int $invoiceId 发票类型ID
* @param int $paymentId 支付方式ID
* @param int $paymentType 支付类型ID
* @param string $remark 留言
* @param mixed $yohoCoin 使用的YOHO币数量或为空
* @return array 接口返回的数据
*/
public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $yohoCoin)
{
$result = array();
$orderSubRes = CartData::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $yohoCoin);
if ($orderSubRes && isset($orderSubRes['code']) && $orderSubRes['code'] === 200) {
$result = $orderSubRes;
}
return $result;
... ...
... ... @@ -374,10 +374,9 @@ class UserModel
* @param int $uid 用户ID
* @param int $status 优惠券状态,0表示未使用,1表示已使用
* @param int $page 第几页
* @param boolean $onlyTotal 只返回总数
* @return array|mixed 处理之后的优惠券数据
*/
public static function getCouponData($uid, $status, $page, $onlyTotal = false)
public static function getCouponData($uid, $status, $page)
{
$result = array();
... ... @@ -386,7 +385,6 @@ class UserModel
// 没有获取到优惠券时
if (!$coupons) {
$result['topURL'] = '/product/new';
$result['noRecord'] = true;
return $result;
... ... @@ -395,15 +393,8 @@ class UserModel
// 处理优惠券数据
if (isset($coupons['data'])) {
if ($onlyTotal) {
$result['count'] = $coupons['data']['total'];
return $result;
}
// 不能再查到结果了
if ($page == 1 && $coupons['data']['total'] === 0) {
$result['walkwayUrl'] = '/product/new';
$result['noRecord'] = true;
} else {
$couponArr = array();
... ...