Cart.php 49.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240
<?php

namespace Index;

use LibModels\Wap\Home\CartData;
use LibModels\Wap\Home\OrderData;
use Plugin\Helpers;
use Plugin\Images;
use Plugin\UdpLog;
use Configs\TicketsConfig;
use Plugin\Encryption;


/**
 *
 * @name CartModel
 * @package models/Index
 * @copyright yoho.inc
 * @version 1.0 (2015-11-09 14:05:09)
 * @author Gtskk (tttt6399998@126.com)
 */
class CartModel
{

    /**
     * 加入购物车
     *
     * @param int $productSku 商品SKU
     * @param int $buyNumber 购买数量
     * @param int $goodsType 商品类型,0表示普通商品,1表示加价购商品
     * @param int $isEdit 是否是编辑商品SKU,0表示不是编辑
     * @param null|int $promotionId 促销id,默认null(加价购有关)
     * @param null|int $uid 用户UID,可以不传
     * @param string $shoppingKey 未登录用户唯一识别码,可以不传
     * @return array 加入购物车接口返回的数据
     */
    public static function addToCart($productSku, $buyNumber, $goodsType, $isEdit, $promotionId, $uid, $shoppingKey)
    {
        $result = array('code' => 400, 'message' => '出错啦~~');

        $addCart = CartData::addToCart($productSku, $buyNumber, $goodsType, $isEdit, $promotionId, $uid, $shoppingKey);
        if ($addCart && isset($addCart['code'])) {
            $result = $addCart;
        }else{
            UdpLog::info('【购物车】校验参数传递auth','productSku:'.$productSku.'buyNumber:'.$buyNumber.'goodsType:'.$goodsType.'isEdit:'.$isEdit.'promotionId:'.$promotionId.'uid:'.$uid.'shoppingKey:'.$shoppingKey);
        }

        return $result;
    }

    /**
     * 获取购物车信息
     *
     * @param integer $uid 用户ID
     * @param string $shoppingKey 未登录用户唯一识别码
     * @param string $cartType 购物车类型,默认是是所有购物车,ordinary为普通购物车,advance为预售购物车
     * @param bool $onlyGift 只获取赠品的商品数据
     * @param bool $onlyAdvanceBuy 只获取加价购的商品数据
     * @return array|mixed 处理之后的购物车数据
     */
    public static function getCartData($uid, $shoppingKey, $cartType = 'all', $onlyGift = false, $onlyAdvanceBuy = false)
    {
        $result = array('cartNav' => false, 'commonGoodsCount' => '0', 'presellGoodsCount' => '0');

        // 用户是否登录
        if (empty($uid)) {
            $signurl = Helpers::url('/signin.html', array('refer' => Helpers::url('/cart/index/index')));
            $result['signurl'] = strtr($signurl, array('http://' => '//'));
            $result['showLoginInfo'] = true;
        }

        // 调用接口获取购物车的数据
        $cartData = CartData::cartData($uid, $shoppingKey);

        // 处理普通购物车和预售购物车的数据
        do {
            if (empty($cartData['data'])) {
                $result['isEmptyCart'] = true;
                break;
            }

            $cart = $cartData['data'];

            if ($onlyGift || $onlyAdvanceBuy) { // 加价购或者赠品数据
                $result = self::procCartData($cart['ordinary_cart_data'], $onlyGift, $onlyAdvanceBuy);
                break;
            }

            $ordinaryCount = strval($cart['ordinary_cart_data']['shopping_cart_data']['goods_count']);
            $advanceCount = strval($cart['advance_cart_data']['shopping_cart_data']['goods_count']);
            $ordinarySoldOut = empty($cart['ordinary_cart_data']['sold_out_goods_list']);
            $advanceSoldOut = empty($cart['advance_cart_data']['sold_out_goods_list']);
            // 普通购物车和预售购物车都为空
            if ($ordinaryCount === '0' && $advanceCount === '0' && $ordinarySoldOut && $advanceSoldOut) {
                $result['isEmptyCart'] = true;
                break;
            }

            // 普通购物车空,则显示预售购物车
            if ($ordinaryCount === '0' && $ordinarySoldOut) {
                $result['cartNav'] = false;
                $result['cartType'] = 'advance';
            } // 预售购物车空,则显示普通购物车
            elseif ($advanceCount === '0' && $advanceSoldOut) {
                $result['cartNav'] = false;
                $result['cartType'] = 'ordinary';
            } // 以上两个购物车中都有数据, 默认显示普通购物车
            else {
                $result['cartNav'] = true;
                $result['cartType'] = $cartType !== 'all' ? $cartType : 'ordinary';
            }

            /* 普通购物车 */
            $result['commonGoodsCount'] = $ordinaryCount;
            $result['commonCart'] = self::procCartData($cart['ordinary_cart_data'], $onlyGift, $onlyAdvanceBuy, false);
            /* 预售购物车 */
            $result['presellGoodsCount'] = $advanceCount;
            $result['preSellCart'] = self::procCartData($cart['advance_cart_data'], $onlyGift, $onlyAdvanceBuy);
        }
        while (false);

        return $result;
    }

    /**
     * 获取购物车商品数目
     *
     * @param integer $uid 用户ID
     * @param string $shoppingKey 未登录用户唯一识别码
     * @return array|mixed 购物车商品数目
     */
    public static function getCartCount($uid, $shoppingKey)
    {
        return CartData::cartCount($uid, $shoppingKey);
    }

    /**
     * 购物车商品选择与取消接口返回的数据处理
     *
     * @param int $uid 用户ID
     * @param string $skuList 商品sku列表
     * @param string $shoppingKey 未登录用户唯一识别码
     * @return array 处理之后的数据的数据
     */
    public static function selectGoods($uid, $skuList, $shoppingKey)
    {
        $result = array('code' => 400, 'message' => '出错啦~');

        do {
            if (empty($skuList)) {
                UdpLog::info('【购物车】校验参数传递auth','skuList:'.$skuList);
                break;
            }

            $arr = json_decode($skuList, true);
            foreach ($arr as &$values) {
                $values['promotion_id'] = $values['hasPromotion'];
            }
            $skuList = json_encode($arr);

            $select = CartData::selectGoods($uid, $skuList, $shoppingKey);
            if ($select && isset($select['code'])) {
                $result['code'] = $select['code'];
                $result['message'] = $select['message'];
            }else{
                UdpLog::info('【购物车】校验参数传递auth','uid:'.$uid.'skuList:'.$skuList.'shoppingKey:'.$shoppingKey);
            }
        }
        while (0);

        return $result;
    }

    /**
     * 移出购物车
     *
     * @param int $uid 用户ID
     * @param string $sku 商品sku
     * @param string $count 要删除的数目
     * @param string $shoppingKey 未登录用户唯一识别码
     * @return array 接口返回的数据
     */
    public static function removeFromCart($uid, $sku, $count, $shoppingKey, $promotionId = 0)
    {
        $result = array('code' => 400, 'message' => '出错啦~');

        // 处理sku
        $sku_list = json_encode(array(array('product_sku' => $sku, 'buy_number' => intval($count), 'promotion_id' => $promotionId)));
        $remove = CartData::removeFromCart($uid, $sku_list, $shoppingKey);
        if ($remove && isset($remove['code'])) {
            $result['code'] = $remove['code'];
            $result['message'] = $remove['message'];
        }else{
            UdpLog::info('【购物车】校验参数传递auth','uid:'.$uid.'sku_list:'.$sku_list.'shoppingKey:'.$shoppingKey.'hasPromotion:'.$hasPromotion);
        }

        return $result;
    }

    /**
     * 移入收藏夹
     *
     * @param int $uid 用户ID
     * @param string $sku 商品sku列表
     * @return array 接口返回的数据
     */
    public static function addToFav($uid, $sku, $hasPromotion = false)
    {
        $result = array('code' => 400, 'message' => '出错啦~');

        if (empty($uid)) {
            $result['code'] = 300;
            $result['message'] = '请先登录';
            $result['data'] = Helpers::url('/signin.html');

            return $result;
        }

        // 处理sku
        $sku_list = json_encode(array($sku => 1));

        $add = CartData::addToFav($uid, $sku_list, $hasPromotion);
        if ($add && isset($add['code'])) {
            $result['code'] = $add['code'];
            $result['message'] = $add['message'];
        }else{
            UdpLog::info('【购物车】校验参数传递auth','uid:'.$uid.'sku_list:'.$sku_list.'hasPromotion:'.$hasPromotion);
        }

        return $result;
    }

    /**
     * 处理购物车商品数据
     *
     * @param int $uid 用户ID
     * @param int $skn 商品skn
     * @param int $num 购买数目
     * @return array 接口返回的数据
     */
    public static function cartProductData($uid, $skn, $num)
    {
        $result = array('code' => 400, 'message' => '出错啦~');

        $product = CartData::cartProductData($uid, $skn);
        if (isset($product['code']) && $product['code'] === 200) {
            $result = self::procGoodsDetail($product['data'], $num);
        }else{
            UdpLog::info('【购物车】校验参数传递auth','uid:'.$uid.'skn:'.$skn);
        }

        return $result;
    }

    /**
     * 处理加价购商品数据
     *
     * @param int $skn 商品skn
     * @param int $promotionId 加价购商品促销ID
     * @return array
     */
    public static function giftProductData($skn, $promotionId)
    {
        $result = array();

        $product = CartData::giftProductData($skn, $promotionId);
        if (isset($product['code']) && $product['code'] === 200) {
            $result = self::procGoodsDetail($product['data']);
        }else{
            UdpLog::info('【购物车】校验参数传递auth','skn:'.$skn.'promotionId:'.$promotionId);
        }

        return $result;
    }

    /**
     * 修改购物车商品数量
     *
     * @param int $uid 用户ID
     * @param string $sku 商品SKU
     * @param int $increaseNum 增加的数目
     * @param int $decreaseNum 减少的数目
     * @param string $shoppingKey 未登录用户唯一识别码
     * @return array 接口返回的数据
     */
    public static function modifyProductNum($uid, $sku, $increaseNum, $decreaseNum, $shoppingKey)
    {
        $result = array('code' => 400, 'message' => '出错啦~');

        do {
            if (empty($sku)) {
                UdpLog::info('【购物车】校验参数传递auth','sku:'.$sku);
                braek;
            }

            $modify = CartData::modifyProductNum($uid, $sku, $increaseNum, $decreaseNum, $shoppingKey);
            if ($modify && isset($modify['code'])) {
                $result['code'] = $modify['code'];
                $result['message'] = $modify['message'];
            }else{
                UdpLog::info('【购物车】校验参数传递auth','uid:'.$uid.'sku:'.$sku,'increaseNum:'.$increaseNum.'decreaseNum:'.$decreaseNum.'shoppingKey:'.$shoppingKey);
            }
        }
        while (0);

        return $result;
    }

    /**
     * 修改购物车商品数据
     *
     * @param int $uid 用户ID
     * @param string $param 要更改的数据
     * @param string $shoppingKey 未登录用户唯一识别码
     * @return array 接口返回的数据
     */
    public static function modifyCartProduct($uid, $param, $shoppingKey)
    {
        $result = array('code' => 400, 'message' => '出错啦~');

        do {
            if (empty($param['old_product_sku']) || empty($param['new_product_sku'])) {
                break;
            }

            // 处理要更改的数据
            $swapData = json_encode(array($param));

            $modify = CartData::modifyCartProduct($uid, $swapData, $shoppingKey);
            if ($modify && isset($modify['code'])) {
                $result['code'] = $modify['code'];
                $result['message'] = $modify['message'];
            }else{
                UdpLog::info('【购物车】校验参数传递auth','uid:'.$uid.'swapData:'.$swapData.'shoppingKey:'.$shoppingKey);
            }
        }
        while (0);

        return $result;
    }

    /**
     * 调用购物车结算接口返回的数据处理
     *
     * @param int $uid 用户ID
     * @param string $cartType 购物车类型,ordinary表示普通购物车
     * @param array $orderInfo cookie中记录的一些订单有关数据
     * @param string $limitProductCode 限购商品码,用户限购商品购买
     * @param string $sku 商品sku,用于限购商品购买
     * @param stirng $skn 商品skn,用于限购商品购买
     * @param int $buyNumber 购买商品数目,用户限购商品支付
     * @param bool $isAjax 是否是异步请求
     * @return array 接口返回的数据
     */
    public static function cartPay($uid, $cartType, $orderInfo, $limitProductCode, $sku, $skn, $buyNumber, $isAjax = false)
    {
        $result = array();

        $skuList = '';
        $isLimitGoods = !empty($sku) && !empty($skn) && !empty($buyNumber);
        if ($isLimitGoods) { // 存在sku,skn和buyNumber时为限购商品
            $skuList = json_encode(array(
                array(
                    'type' => 'limitcode',
                    'limitproductcode' => $limitProductCode,
                    'skn' => $skn,
                    'sku' => $sku,
                    'buy_number' => $buyNumber
                )
            ));
            $result['isLimit'] = true;
        }

        $pay = CartData::cartPay($uid, $cartType, 0, $skuList);

        do {
            if (!$pay || $pay['code'] != 200 || empty($pay['data']['goods_list'])) {
                if ($isLimitGoods) {
                    $result['error'] = true;
                    $result['message'] = $pay['message'];
                }
                else {
                    $result['cartUrl'] = Helpers::url('/cart/index/index');
                }

                break;
            }

            if ($isAjax) { // 如果是异步请求,求直接返回,不进行下面的处理,从而优化性能
                break;
            }

            $payReturn = $pay['data'];
            $address = array();
            $orderCompute = array();

            // cookie保存的数据
            if (!empty($orderInfo)) {
                $orderInfo['paymentType'] = isset($orderInfo['paymentType']) ? $orderInfo['paymentType'] : '';
                $orderCompute = self::orderCompute($uid, $cartType, $orderInfo['deliveryId'], $orderInfo['paymentType'], $orderInfo['couponCode'], $orderInfo['yohoCoin'], $skuList);
                // 有货币
                $result['yohoCoinCompute'] = $orderCompute['yohoCoinCompute'];
            } else {
                // 有货币
                $result['yohoCoinCompute'] = self::yohoCoinCompute($pay['data']);
            }

            // 根据地址id查询地址信息
            if (isset($orderInfo['address'])) {
                $address = $orderInfo['address'];
            }

            // 收货人有关信息
            $isSunfengSupport = false; // 是否支持顺丰快递
            if (isset($payReturn['delivery_address']) && !empty($payReturn['delivery_address'])) {
                $result['addressId'] = isset($address['address_id']) ? $address['address_id'] : $payReturn['delivery_address']['address_id'];
                $result['addressId'] = Encryption::encrypt($result['addressId']);
                $result['name'] = isset($address['consignee']) ? $address['consignee'] : $payReturn['delivery_address']['consignee'];
                $result['phoneNum'] = isset($address['mobile']) ? $address['mobile'] : $payReturn['delivery_address']['mobile'];
//                $result['area'] = isset($address['area']) ? $address['area'] : $payReturn['delivery_address']['area'];
                $result['addressInfo'] = isset($address['address_info']) ? $address['address_info'] : $payReturn['delivery_address']['area'] . ' ' . $payReturn['delivery_address']['address'];

                // 是否支持顺丰快递
                $isSupport = isset($address['is_support']) ? $address['is_support'] : $payReturn['delivery_address']['is_support'];
                $isSunfengSupport = $isSupport === 'Y';
            }

            // 配送方式
            if (isset($payReturn['delivery_way'])) {
                $defaultKey = 0;
                $oneDeliv = array();
                $isDeliveryId = true;
                $deliveries = $payReturn['delivery_way'];
                if (isset($orderCompute['delivery_way']) && !empty($orderCompute['delivery_way'])) {
                    $deliveries = $orderCompute['delivery_way'];
                }

                foreach ($deliveries as $key => $val) {
                    if ($val['delivery_way_name'] === '顺丰速运' && !$isSunfengSupport) {
                        continue;
                    }

                    $oneDeliv = array();
                    $oneDeliv['id'] = $val['delivery_way_id'];
                    $oneDeliv['name'] = $val['delivery_way_name'];
                    $oneDeliv['cost'] = $val['delivery_way_cost'];
                    ($val['default'] === 'Y') && $defaultKey = $key;

                    if (isset($orderInfo['deliveryId']) && $orderInfo['deliveryId'] === $oneDeliv['id']) {
                        $oneDeliv['isSelected'] = true;
                        $isDeliveryId = false;
                    }

                    $result['dispatchMode'][$key] = $oneDeliv;
                }

                if ($isDeliveryId) {
                    $result['dispatchMode'][$defaultKey]['isSelected'] = true;
                }
            }

            // 配送时间
            if (isset($payReturn['delivery_time'])) {
                $idArr = array();
                $defaultKey = 0;
                $oneDelivTime = array();
                foreach ($payReturn['delivery_time'] as $key => $one) {
                    $oneDelivTime = array();
                    $oneDelivTime['id'] = $one['delivery_time_id'];
                    $oneDelivTime['name'] = $one['delivery_time_string'];
                    ($one['default'] === 'Y') && $defaultKey = $key;

                    $idArr[$key] = $oneDelivTime['id'];

                    $result['dispatchTime'][] = $oneDelivTime;
                }

                if (isset($orderInfo['deliveryTimeId'])) {
                    $flag = array_search($orderInfo['deliveryTimeId'], $idArr);
                    $flag !== false && $result['dispatchTime'][$flag]['isSelected'] = true;
                }
                else {
                    $result['dispatchTime'][$defaultKey]['isSelected'] = true;
                }
            }

            // 订单商品
            if (isset($payReturn['goods_list'])) {
                $oneGoods = array();
                $goodsPrice = 0;

                foreach ($payReturn['goods_list'] as $single) {

                    $oneGoods = array();
                    $oneGoods['id'] = $single['product_sku'];
                    $oneGoods['thumb'] = Images::getImageUrl($single['goods_images'], 120, 160);
                    $oneGoods['name'] = $single['product_name'];
                    $oneGoods['color'] = $single['color_name'];
                    $oneGoods['size'] = $single['size_name'];
                    $oneGoods['count'] = $single['buy_number'];
                    $oneGoods['price'] = Helpers::transPrice($single['last_price']);

                    if (isset($single['is_limit_skn']) && $single['is_limit_skn'] === 'Y') {
                        $oneGoods['isLimitSkn'] = true;
                    }

                    $oneGoods['yohoCoinNum'] = $single['yoho_coin_num'];
                    
                    //gift=>是否赠品,advanceBuy=>是否加价购;
                    if ($single['goods_type'] == 'gift' && !isset($single['isAdvanceBuy'])) {
                        $oneGoods['gift'] = true;
                        $oneGoods['price'] = Helpers::transPrice($single['sale_price']);
                    }
                    elseif ($single['goods_type'] == 'price_gift') {
                        $oneGoods['advanceBuy'] = true;
                        $oneGoods['price'] = Helpers::transPrice($single['sale_price']);
                    }

                    // 累加商品金额
                    $goodsPrice += $oneGoods['count'] * $oneGoods['price'];

                    $result['goods'][] = $oneGoods;
                }

                // 商品金额
                $result['goodsPrice'] = Helpers::transPrice($goodsPrice);
                
            }

            // 支付方式
            if (isset($payReturn['payment_way'])) {
                $onePay = array();
                $isPaymentType = true;
                foreach ($payReturn['payment_way'] as $val) {
                    if ($val['is_support'] !== 'Y') {
                        continue;
                    }

                    $onePay = array();
                    $onePay['id'] = $val['payment_id'];
                    $onePay['paymentType'] = $val['payment_type'];
                    $onePay['name'] = $val['payment_type_name'];
                    $onePay['isSupport'] = $val['is_support'] === 'Y';
//                    $onePay['default'] = ($val['default'] === 'Y');
                    if (isset($orderInfo['paymentType']) && $onePay['paymentType'] === $orderInfo['paymentType']) {
                        $onePay['recommend'] = true;
                        $isPaymentType = false;
                    }

                    $result['paymentWay'][] = $onePay;
                }

                //默认第一个
                if ($isPaymentType) {
                    $result['paymentWay'][0]['recommend'] = true;
                }
            }

            // 订单数据
            if (isset($payReturn['shopping_cart_data']) && !empty($payReturn['shopping_cart_data'])) {
                //判断是否为JIT商品
                if ($payReturn['shopping_cart_data']['is_multi_package'] == 'Y') {
                    $result['isJit'] = true;
                    $jitInfo = array();
                    if (!empty($orderInfo)) {
                        $jitInfo = array('deliveryId' => $orderInfo['deliveryId'], 'paymentType' => $orderInfo['paymentType'], 'couponCode' => $orderInfo['couponCode'], 'yohoCoin' => $orderInfo['yohoCoin']);
                    }
                    //传递相关参数
                    $param = array_merge(array('cartType' => $cartType, 'skuList' => $skuList), $jitInfo);
                    $result['jitDetailUrl'] = Helpers::url('/cart/index/jitDetail', $param);
                }
                $result['cartPayData'] = isset($orderCompute['promotion_formula_list']) ? $orderCompute['promotion_formula_list'] : $payReturn['shopping_cart_data']['promotion_formula_list'];
                $price = isset($orderCompute['last_order_amount']) ? $orderCompute['last_order_amount'] : $payReturn['shopping_cart_data']['last_order_amount'];
                $result['price'] = Helpers::transPrice($price, true);
                // 订单商品数
                $result['num'] = $payReturn['shopping_cart_data']['selected_goods_count'];
                // 商品金额
                $result['goodsPrice'] = $payReturn['shopping_cart_data']['str_order_amount'];

                //有货币
                if((int)$payReturn['shopping_cart_data']['gain_yoho_coin'] > 0) {
                    
                    $result['yohoCoinNum'] = $payReturn['shopping_cart_data']['gain_yoho_coin'];
                    $result['returnYohoCoin'] = true;
                }
            }

            // 发票有关数据
            if (isset($payReturn['invoices']) && !empty($payReturn['invoices'])) {
                foreach ($payReturn['invoices']['invoiceContentList'] as $inv) {
                    $result['invoice'][] = array(
                        'id' => $inv['invoices_type_id'],
                        'name' => $inv['invoices_type_name'],
                    );
                }

                // 发票信息需要记录
                if (isset($orderInfo['invoice'])) {
                    $result['needInvoice'] = $orderInfo['invoice'];
                    $result['invoiceText'] = $orderInfo['invoiceText'];
                }
            }

            // 留言
            isset($orderInfo['msg']) && $result['msg'] = $orderInfo['msg'];

            // 优惠券数据
            $coupons = array(
                'couponName' => '',
                'isCoupon' => false,
                'count' => self::getValidCouponCount($uid)
            );
            if (isset($orderCompute['coupon_amount']) && (!empty($orderCompute['coupon_amount']) || ($orderCompute['coupon_amount'] === 0 && $orderCompute['shipping_cost'] === 0))) {
                $coupons['couponName'] = $orderInfo['couponName'];
            }
            //选中已使用的优惠劵,则剩余多少张优惠劵,不提示
            if (empty($coupons['couponName']) || $coupons['count'] === 0) {
                $coupons['isCoupon'] = true;
            }

            $result['coupon'] = $coupons;
        }
        while (false);
        
        return $result;
    }

    /**
    *有货币使用前端方案显示及是否可单击判断
    */
    public static function yohoCoinCompute($orderCompute) {
        $yohoCoinData = ['totalYohoCoinNum' => 0, 'yohoCoin' => 0, 'useYohoCoin' => 0, 'yohoCoinClick' => 0, 'yohoCoinMsg' => '', 'yoho_coin_pay_rule' => []];

        if (empty($orderCompute) || empty($orderCompute['yoho_coin_pay_rule'])) {
            return $yohoCoinData;
        }

        $yohoCoinData = [
            'totalYohoCoinNum' => isset($orderCompute['total_yoho_coin_num']) ? intval($orderCompute['total_yoho_coin_num']) : 0,
            'yohoCoin' => isset($orderCompute['yoho_coin']) ? Helpers::transPrice($orderCompute['yoho_coin']) : 0,
            'useYohoCoin' => isset($orderCompute['use_yoho_coin']) ? Helpers::transPrice($orderCompute['use_yoho_coin']) : 0,
            'yohoCoinClick' => 0,
            'yohoCoinMsg' => '',
            'yoho_coin_pay_rule' => $orderCompute['yoho_coin_pay_rule']
        ];

        if ($yohoCoinData['totalYohoCoinNum'] < 100) {
            $yohoCoinData['yohoCoinMsg'] = "共{$yohoCoinData['totalYohoCoinNum']}有货币,满{$orderCompute['yoho_coin_pay_rule']['num_limit']}可用";
        } else if ($yohoCoinData['useYohoCoin'] > 0 || $yohoCoinData['yohoCoin'] > 0) {
            $yohoCoinData['yohoCoinMsg'] = '可抵¥' . ($yohoCoinData['useYohoCoin'] > 0 ? $yohoCoinData['useYohoCoin'] : $yohoCoinData['yohoCoin']);
            $yohoCoinData['yohoCoinClick'] = 1;
        } else {
            $yohoCoinData['yohoCoinMsg'] = "不满足有货币使用条件";
        }

        return $yohoCoinData;
    }
    /**
     * 购物车结算--获取可用的优惠券数目
     *
     * @param int $uid 用户ID
     * @return int 可用优惠券的数目
     */
    private static function getValidCouponCount($uid)
    {
        $count = 0;

        $validCount = CartData::getValidCouponCount($uid);
        if (isset($validCount['data']['count'])) {
            $count = intval($validCount['data']['count']);
        }

        return $count;
    }

    /**
     * 购物车结算--支付方式和配送方式选择以及是否使用有货币接口返回的数据处理
     *
     * @param int $uid 用户ID
     * @param string $cartType 购物车类型,ordinary表示普通购物车
     * @param int $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运
     * @param int $paymentType 支付方式,1表示在线支付,2表示货到付款
     * @param string $couponCode 优惠券码
     * @param mixed $yohoCoin 使用的有货币数量
     * @param string $skuList 购买限购商品时需要传递的参数
     * @return array 接口返回的数据
     */
    public static function orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin, $skuList)
    {
        $result = array();

        $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']);
            $result = $compute['data'];
            $result['yohoCoinCompute'] = self::yohoCoinCompute($compute['data']);
        }

        return $result;
    }

    /**
     * 购物车结算--输入优惠券代码返回的结果处理
     *
     * @param int $uid 用户ID
     * @param string $couponCode 优惠券代码
     * @return array 接口返回的数据
     */
    public static function searchCoupon($uid, $couponCode)
    {
        $result = array('code' => 400, 'message' => '出错啦~');

        do {
            if (empty($couponCode)) {
                $result['code'] = 401;
                $result['message'] = '优惠券代码为空';
                break;
            }

            $coupon = CartData::searchCoupon($uid, $couponCode);
            if ($coupon && isset($coupon['code'])) {
                $result = $coupon;
            }
        }
        while (0);

        return $result;
    }

    /**
     * 处理优惠券列表数据
     *
     * @param int $uid 用户ID
     * @return array|mixed 处理之后的优惠券数据
     */
    public static function getCouponList($uid)
    {
        $result = array();

        // 调用接口获取优惠券数据
        $coupons = CartData::getCouponList($uid);

        do {
            // 接口返回错误
            if (!isset($coupons['data']['unusable_coupons']) || !isset($coupons['data']['usable_coupons'])) {
                break;
            }

            // 不可用的优惠券
            $result['notAvailableCoupons'] = self::procCouponsData($coupons['data']['unusable_coupons']);
            // 可用优惠券
            $result['coupons'] = self::procCouponsData($coupons['data']['usable_coupons']);
        }
        while (false);

        return $result;
    }

    /**
     * 处理优惠券数据
     *
     * @param array $coupons 优惠券数据
     * @return array
     */
    private static function procCouponsData($coupons)
    {
        $result = array();

        $one = array();
        foreach ($coupons as $val) {
            $one = array();
            $one['couponCode'] = $val['coupon_code'];
            $one['couponDetailInfomation'] = $val['coupon_name'];
            $one['couponValue'] = $val['coupon_value'];
            $one['couponValidity'] = $val['coupon_validity'];

            $result[] = $one;
        }

        return $result;
    }

    /**
     * 购物车结算--提交结算信息
     *
     * @param int $uid 用户ID
     * @param int $addressId 地址ID
     * @param int $cartType 购物车类型ID
     * @param int $deliveryTime 寄送时间ID
     * @param int $deliveryWay 寄送方式ID
     * @param array $invoices 发票参数数组
     * @param int $paymentId 支付方式ID
     * @param int $paymentType 支付类型ID
     * @param string $remark 留言
     * @param string $couponCode 优惠券码
     * @param mixed $yohoCoin 使用的有货币数量或为空
     * @param string $skuList 购买限购商品时需要传递的参数
     * @param string $qhyUnio 友盟有关信息
     * @param string|null $userAgent 联盟过来用户下单时需要的User-Agent信息
     * @param int $times
     * @return array 接口返回的数据
     */
    public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoices, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin, $skuList, $qhyUnio = '', $userAgent = null, $times = 1)
    {
        $result = array('code' => 400, 'message' => '出错啦');

        if (empty($addressId)) {
            UdpLog::info('【结算信息】配送地址参数校验','addressId为空');
            $result['code'] = 401;
            $result['message'] = '配送地址不能为空';
        } elseif (empty($deliveryTime)) {
            UdpLog::info('【结算信息】配送时间参数校验','deliveryTime为空');
            $result['code'] = 402;
            $result['message'] = '请选择配送时间';
        } elseif (empty($deliveryWay)) {
            UdpLog::info('【结算信息】配送方式参数校验','deliveryWay为空');
            $result['code'] = 403;
            $result['message'] = '请选择配送方式';
        } else {
            $orderSubRes = CartData::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoices, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin, $skuList, $qhyUnio, $userAgent, $times);
            UdpLog::info('【结算信息】接口返回','orderSubRes'.json_encode($orderSubRes));

            if (isset($orderSubRes['data'])
                && isset($orderSubRes['data']['is_hint'])
                && $orderSubRes['data']['is_hint'] === 'Y') {

                $result['code'] = 409;

                if (isset($orderSubRes['data']['hintInfo'])) {
                    if (mb_strlen($orderSubRes['data']['hintInfo']['productName']) > 50) {
                        $orderSubRes['data']['hintInfo']['productName'] = mb_substr($orderSubRes['data']['hintInfo']['productName'], 0, 47) . '...';
                    }

                    $result['message'] =  array(
                        $orderSubRes['data']['hintInfo']['productName'] . $orderSubRes['data']['hintInfo']['suffix'],
                        $orderSubRes['data']['hintInfo']['lastLine']
                    );
                }

                $result['buttons'] = array(
                    array(
                        'href' => Helpers::url('/cart/index/index'),
                        'text' => '重新选择商品',
                        'class' => ''
                    ),
                    array(
                        'href' => '',
                        'text' => '继续结算',
                        'class' => 'order-tip-btnred'
                    ));
            } else if ($orderSubRes && isset($orderSubRes['code'])) {
                $result = $orderSubRes;
            }
        }

        return $result;
    }

    /**
     * 处理购物车商品、加价购商品、赠品详情数据
     *
     * @param array $productData 要处理的商品数据
     * @param int $num 购买数目
     * @return array $data 处理之后的数据
     */
    private static function procGoodsDetail($productData, $num = null)
    {
        $data = array();

        $data['name'] = $productData['product_name'];
        if (isset($productData['special_price'])) { // 加价购或者赠品的销售价字段
            $data['price'] = $productData['format_market_price'];
            $data['salePrice'] = $productData['format_sales_price'];
        }
        else { // 购物车商品的销售价字段
            $data['price'] = $productData['market_price'] > $productData['sales_price'] ? $productData['format_market_price'] : false;
            $data['salePrice'] = '¥' . Helpers::transPrice($productData['sales_price']);
        }


        if (isset($productData['storage_sum'])) {
            $data['storage'] = $productData['storage_sum'];
        }
        $data['num'] = 1;
        if ($num !== null) {
            $data['num'] = $num;
        }

        // 商品选择
        if (isset($productData['goods_list'])) {
            $goodsList = $productData['goods_list'];

            $sizeName = '';
            $colors = array();
            $colorList = array();
            $oneColor = array();
            $sizes = array();
            $oneSize = array();
            $sizeList = array();
            $allSizeList = array(); // 所有尺码列表
            $thumbImageList = array();
            $colorNum = 0;
            $totalStorageNum = 0; // 总库存数
            $colorStorageGroup = array(); // 颜色分组的库存总数集合, 多个之间用/分隔
            foreach ($goodsList as $val) {
                $colorNum = 0;
                $sizeName = '';

                // 商品的尺码列表
                $colorStorageGroup[$val['product_skc']] = array();
                if (isset($val['size_list'])) {
                    // 尺码
                    foreach ($val['size_list'] as $one) {
                        $sizeName = $one['size_name'];
                        $oneSize = array();

                        $oneSize['id'] = $one['size_id'];
                        $oneSize['skuId'] = $one['product_sku'];
                        $oneSize['goodsId'] = $val['goods_id'];
                        $oneSize['colorId'] = $val['color_id'];
                        $oneSize['name'] = $sizeName;
                        $oneSize['sizeNum'] = intval($one['storage_number']);
                        $sizeList[$val['product_skc']][] = $oneSize;

                        // 所有尺码列表,赋值用于前端展示默认尺码的时候 判断出没有库存则显示灰色
                        $allSizeList[$sizeName] = empty($allSizeList[$sizeName]['storage']) ? array('storage' => $one['storage_number'], 'id' => $one['size_id']) : $allSizeList[$sizeName];

                        $colorNum += intval($one['storage_number']);

                        $colorStorageGroup[$val['product_skc']][$one['size_name']] = intval($one['storage_number']);
                    }

                    // 颜色分组
                    $oneColor = array();
                    $oneColor['id'] = $val['color_id'];
                    $oneColor['skcId'] = $val['product_skc'];
                    $oneColor['name'] = $val['color_name'];
                    $oneColor['goodsName'] = $productData['product_name'];
                    $oneColor['colorNum'] = $colorNum;
                    $colorList[] = $oneColor;
                }

                // 缩略图
                $thumbImageList[] = array(
                    'img' => Helpers::getImageUrl($val['color_image'], 60, 60)
                );

                // 商品库存总数
                $totalStorageNum += $colorNum;
            }

            // 遍历所有尺码,构建颜色显示数据
            $i = 1;
            foreach ($allSizeList as $sizeName => $value) {
                // 默认尺码
                $sizes[0]['size'][] = array(
                    'name' => $sizeName, // 尺码名称
                    'sizeNum' => empty($value['storage']) ? false : true, // 是否有库存 (false:表示没有库存,true:表示有库存)
                    'id' => $value['id'],
                );

                // 各个颜色的尺码, 每行显示一个尺码对应的颜色
                foreach ($colorList as $colorArr) {
                    $colorArr['colorNum'] = isset($colorStorageGroup[$colorArr['skcId']][$sizeName]) ? intval($colorStorageGroup[$colorArr['skcId']][$sizeName]) : 0;
                    $colors[$i]['color'][] = $colorArr;
                }
                $colors[$i]['id'] = $value['id'];

                ++$i;
            }

            // 遍历所有颜色, 构建尺码显示数据
            $i = 1;
            foreach ($colorList as $value) {
                // 各个尺码的颜色,每行显示一个颜色的对应尺码
                $sizes[$i]['size'] = $sizeList[$value['skcId']];
                $sizes[$i]['colorId'] = $value['skcId'];
                // 默认颜色
                $colors[0]['color'][] = $value;

                ++$i;
            }
            ksort($colors, SORT_NUMERIC);

            $data['thumbs'] = $thumbImageList;
            $data['colors'] = $colors;
            $data['sizes'] = $sizes;
            $data['totalNum'] = $totalStorageNum;
        }

        return $data;
    }

    /**
     * 处理不同类型的购物车数据
     *
     * @param array $data 不同类型购物车数据
     * @param bool $onlyGift 只获取赠品的商品数据
     * @param bool $onlyAdvanceBuy 只获取加价购的商品数据
     * @param bool $isAdvanceCart 是否是预售购物车,默认是,(和上市期有关)
     * @return array $result 处理之后的不同类型购物车数据
     */
    private static function procCartData($data, $onlyGift = false, $onlyAdvanceBuy = false, $isAdvanceCart = true)
    {
        $result = array();

        do {
            // 数据为空时返回空的标志
            if (empty($data['goods_list']) && empty($data['sold_out_goods_list']) && empty($data['off_shelves_goods_list'])) {
                break;
            }

            if ($onlyGift) {
                // 赠品
                $count = 0;
                $result['freebie'] = Helpers::formatAdvanceGoods($data['gift_list'], $count, true);
                break;
            }
            if ($onlyAdvanceBuy) {
                // 加价购
                $result['advanceBuy'] = Helpers::formatAdvanceGoods($data['price_gift']);
                break;
            }

            // 购买的可用商品列表
            $validGoods = Helpers::formatCartGoods($data['goods_list'], $isAdvanceCart);
            if (!empty($validGoods)) {
                $result['goods'] = $validGoods;
            }

            // 失效商品列表
            $notValidGoods = Helpers::formatCartGoods($data['sold_out_goods_list'], $isAdvanceCart, false);
            if (!empty($notValidGoods)) {
                $result['notValidGoods'] = $notValidGoods;
            }

            // 下架的商品列表
            $offShelveGoods = Helpers::formatCartGoods($data['off_shelves_goods_list'], $isAdvanceCart, false);
            if (!empty($offShelveGoods)) {
                $result['offShelveGoods'] = $offShelveGoods;
            }

            // 赠品和加价购商品
            if (count($data['gift_list']) || count($data['price_gift'])) {
                $result['freebieOrAdvanceBuy'] = true;
                // 赠品
                $result['giftCount'] = 0;
                $result['freebie'] = Helpers::formatAdvanceGoods($data['gift_list'], $result['giftCount']);
                // 加价购
                $result['advanceBuyCount'] = 0;
                $result['advanceBuy'] = Helpers::formatAdvanceGoods($data['price_gift'], $result['advanceBuyCount']);
            }

            // 已参加的活动
            if (!empty($data['promotion_info'])) {
                $result['promotionInfo'] = array();
                $info = array();
                foreach ($data['promotion_info'] as $val) {
                    $info = array();
                    $info['id'] = $val['promotion_id'];
                    $info['name'] = $val['promotion_title'];

                    $result['promotionInfo'][] = $info;
                }
            }

            // 结算数据
            $result['formulaPrice'] = $data['shopping_cart_data']['promotion_formula'];
            /* $result['price'] = Helpers::transPrice($data['shopping_cart_data']['order_amount']);
              $result['activityPrice'] = Helpers::transPrice($data['shopping_cart_data']['discount_amount']); */
            $result['count'] = $data['shopping_cart_data']['selected_goods_count'];
            $result['isAllSelected'] = ($data['shopping_cart_data']['goods_count'] === $data['shopping_cart_data']['selected_goods_count']) && ($data['shopping_cart_data']['selected_goods_count'] > 0);
            $result['sumPrice'] = Helpers::transPrice($data['shopping_cart_data']['last_order_amount']);
        }
        while (0);
        
        return $result;
    }

    /**
     * 支付成功页
     */
    public static function paySuccessData($orderCode, $uid)
    {
        $result = array();
        $orderInfo = OrderData::viewOrderData($orderCode, $uid, '');

        if (isset($orderInfo['code']) && $orderInfo['code'] == 200 && !empty($orderInfo['data'])) {
            if ($orderInfo['data']['payment_amount'] > 0) {
                $result['price'] = $orderInfo['data']['payment_amount'];
            }
        }
        $param = array('order_code' => $orderCode);
        $result['guang'] = Helpers::url('', '', 'guang');
        $result['orderDetail'] = Helpers::url('/home/orderDetail', $param);

        return $result;
    }

    /**
     * jit拆单数据(结算页和订单详情页)
     * @param type $uid 用户uid
     * @param type $cartType 购物车类型
     * @param type $skuList cookie中记录的一些订单有关数据
     * @param type $orderCode 订单号
     * @param type $sessionKey 用户会话
     * @param type $deliveryId 配送方式,1表示普通快递,2表示顺丰速运
     * @param type $paymentType 支付方式,1表示在线支付,2表示货到付款
     * @param type $couponCode 优惠券码
     * @param type $yohoCoin 使用的有货币数量 
     * @return type        
     */
    public static function getPackageInfo($uid, $cartType, $skuList, $orderCode, $sessionKey, $deliveryId, $paymentType, $couponCode, $yohoCoin)
    {
        $result = array('jitDetailPage' => true, 'packages' => array());
        if ($cartType) {
            //购物车中结算页拆单
            if (isset($deliveryId) && !empty($deliveryId)) {
                //购物车选择改变字段,重新运算订单数据
                $newcar = CartData::orderCompute($uid, $cartType, $deliveryId, $paymentType, $paymentType, $couponCode, $yohoCoin, $skuList);
                if (isset($newcar['data']['package_list'])) {
                    $packageList = $newcar['data']['package_list'];
                    //返回地址跳转
                    $result['returnUrl'] = Helpers::url('/cart/index/orderEnsure', array('cartType' => $cartType));
                }
            }
            else {
                $carpay = CartData::cartPay($uid, $cartType, 0, $skuList);
                if (isset($carpay['data']['shopping_cart_data']['package_list'])) {
                    $packageList = $carpay['data']['shopping_cart_data']['package_list'];
                    //返回地址跳转
                    $result['returnUrl'] = Helpers::url('/cart/index/orderEnsure', array('cartType' => $cartType));
                }
            }
        }
        else {
            //订单详情页中拆单
            $carpay = OrderData::viewOrderData($orderCode, $uid, $sessionKey);
            if (isset($carpay['data']['package_list'])) {
                $packageList = $carpay['data']['package_list'];
            }
        }
        do {
            if (!isset($packageList) || empty($packageList)) {
                break;
            }
            // 拆单数据
            foreach ($packageList as $pk => $pv) {
                $result['packages'][$pk]['packageType'] = $pk + 1;
                $result['packages'][$pk]['dispatchType'] = ($pv['supplier_id'] == 0) ? '总仓发货' : '异地调拨'; //仓库
                $goodList = $pv['goods_list'];
                foreach ($goodList as $glk => $glv) {
                    $result['packages'][$pk]['goods'][$glk]['thumb'] = Images::getImageUrl($glv['goods_images'], 235, 314);
                    $tag = isset($glv['goods_type']) ? $glv['goods_type'] : '';
                    switch ($tag) {
                        case 'price_gift' :
                            //加价购
                            $result['packages'][$pk]['goods'][$glk]['isAdd'] = true;
                            break;
                        case 'gift' :
                            //赠品
                            $result['packages'][$pk]['goods'][$glk]['isGift'] = true;
                            break;
                        default:
                            break;
                    }
                }
                if ($pv['shopping_cost'] != 0) {
                    $result['packages'][$pk]['expressCost'] = $pv['shopping_cost']; //运费
                }
                if ($pv['shopping_cut_cost'] != 0) {
                    $result['packages'][$pk]['discount'] = $pv['shopping_cut_cost']; //已优惠
                }
            }
        }
        while (false);
        return $result;
    }

    /**
     * 获取门票数据
     * @param int $uid
     * @param int $productSku
     * @param int $buyNumber
     * @param int $useYohoCoin
     * @return arr
     */
    public static function getTickets($uid, $productSku, $buyNumber, $useYohoCoin = 0)
    {
        $result = array();

        $data = CartData::checkTickets($uid, $productSku, $buyNumber, $useYohoCoin);
        if (!isset($data['code']) || $data['code'] !== 200) {
            return $result;
        }

        //商品数据
        //门票skn
        $ticketsSkn = array('single' => TicketsConfig::SINGLE_TICKETS_SKN,'package' => TicketsConfig::PACKAGE_TICKETS_SKN);
        $goodsPrice = 0;
        foreach ($data['data']['goods_list'] as $key => $single) {
            $oneGoods = array();
            $oneGoods['tickets'] = true;
            $oneGoods['id'] = $single['product_sku'];
            $oneGoods['thumb'] = Images::getImageUrl($single['goods_images'], 120, 160);
            $oneGoods['name'] = $single['product_name'];
            $oneGoods['color'] = $single['color_name'];
            $oneGoods['size'] = $single['product_skn'] == $ticketsSkn['single'] ? '' : $single['size_name'];
            $oneGoods['count'] = $single['buy_number'];
            $oneGoods['price'] = Helpers::transPrice($single['last_price']);
            // 累加商品金额
            $goodsPrice += $oneGoods['count'] * $oneGoods['price'];
            $result['goods'][] = $oneGoods;
        }

        $result['cartPayData'] = $data['data']['shopping_cart_data']['promotion_formula_list'];
        $price = $data['data']['shopping_cart_data']['last_order_amount'];
        $result['price'] = Helpers::transPrice($price, true);
        // 有货币
        $result['yohoCoinCompute'] = self::yohoCoinCompute($data['data']['shopping_cart_data']);
        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'];
            $result['yohoCoinCompute'] = self::yohoCoinCompute($compute['data']['shopping_cart_data']);
        }
        return $result;
    }


}