...
|
...
|
@@ -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;
|
...
|
...
|
|