Exemplo n.º 1
0
    public function view_fetchAliOrderDetail()
    {
        $id = isset($_GET['id']) ? intval($_GET['id']) : FALSE;
        $type = isset($_GET['type']) ? trim($_GET['type']) : FALSE;
        $returndata = array('errCode' => 0, 'errMsg' => '');
        if (empty($id)) {
            //id不合法
            $returndata['errCode'] = 1;
            $returndata['errMsg'] = 'id不合法';
            echo json_encode($returndata);
            exit;
        }
        $alimsg_obj = new AliOderMessageModel();
        if ($type == 'order') {
            $messageinfo = $alimsg_obj->getMessageInfoByMessageId($id);
        } else {
            $messageinfo = $alimsg_obj->getMessageInfoByMessageId_site($id);
            if (empty($messageinfo['orderId']) || empty($messageinfo['orderUrl'])) {
                $returndata['errCode'] = 9;
                $returndata['errMsg'] = '未关联订单号 !';
                echo json_encode($returndata);
                exit;
            }
        }
        if (empty($messageinfo)) {
            $returndata['errCode'] = 2;
            $returndata['errMsg'] = '没找到messsage信息!';
            echo json_encode($returndata);
            exit;
        }
        $receiverid = $messageinfo['receiverid'];
        //     	$receiverid    = 'cn1500439756';
        if ($type == 'order') {
            $orderid = $messageinfo['orderid'];
        } else {
            $orderid = $messageinfo['orderId'];
        }
        //$orderid = '60293405706949';
        if (empty($orderid)) {
            //订单号不存在
            $returndata['errCode'] = 3;
            $returndata['errMsg'] = '改留言不存在订单号!';
            echo json_encode($returndata);
            exit;
        }
        $tokenfilepath = WEB_PATH . "lib/ali_keys/config_{$receiverid}.php";
        if (!file_exists($tokenfilepath)) {
            $returndata['errCode'] = 2;
            $returndata['errMsg'] = '没找到messsage信息!';
            echo json_encode($returndata);
            exit;
        }
        include_once '' . $tokenfilepath;
        include_once WEB_PATH . 'lib/AliMessage.class.php';
        $ali_obj = new AliMessage();
        $ali_obj->setConfig($appKey, $appSecret, $refresh_token);
        $ali_obj->doInit();
        $detail = $ali_obj->fetchOrderdetail($orderid);
        if ($detail == FALSE) {
            //获取消息失败
            $returndata['errCode'] = 4;
            $returndata['errMsg'] = '获取订单详情失败!';
            echo json_encode($returndata);
            exit;
        }
        //     	print_r($detail);exit;
        $time = $detail['gmtCreate'];
        $year = substr($time, 0, 4);
        //年
        $month = substr($time, 4, 2);
        //月
        $day = substr($time, 6, 2);
        //日
        $time = $month . '/' . $day . '/' . $year;
        $timeend = $month . '/' . (intval($day) + 1) . '/' . $year;
        $skustr = '';
        foreach ($detail['childOrderList'] as $sku) {
            $skucode = substr($sku['skuCode'], 0, strlen($sku['skuCode']) - 1);
            $tmpstr = $skucode;
            $hstr = strrchr($tmpstr, '*');
            //处理组合料号
            $tmpstr = $hstr === FALSE ? $tmpstr : ltrim($hstr, '*');
            $spu = explode('_', $tmpstr);
            $spu = $spu[0];
            $attr = json_decode($sku[productAttributes], TRUE);
            $skuimgurl = getSkuImg($spu, $tmpstr, 'G');
            $attrinfo = json_decode($sku['productAttributes'], TRUE);
            //     	    print_r($sku);exit;
            $attrstr = array();
            if (isset($sku['productAttributes']) && !empty($attrinfo['sku'])) {
                foreach ($attrinfo['sku'] as $attrval) {
                    $attrstr[] = $attrval['pName'] . ':' . $attrval['pValue'];
                }
            }
            //     	    print_r($attrstr);exit;
            $attrstr = implode('<br>', $attrstr);
            $skustr .= <<<EOF
\t\t\t\t<tr>
\t\t\t\t\t\t<td>
\t\t\t\t\t\t\t<img src="{$skuimgurl}" width="50" height="50">
\t\t\t\t\t\t</td>
\t\t\t\t\t\t<td align="left">
\t\t\t\t\t\t  <a href="http://www.aliexpress.com/item/something/{$sku['productId']}.html" target="_blank">{$sku['productName']}</a>
\t\t\t\t\t\t</td>
\t\t\t\t\t\t<td>
\t\t\t\t\t\t          {$attrstr}
\t\t\t\t\t\t</td>
\t\t\t\t\t\t<td>
\t\t\t\t\t\t        {$skucode}          
\t\t\t\t\t\t</td>
\t\t\t\t\t\t<td>
\t\t\t\t\t\t        {$sku['productCount']}
\t\t\t\t\t\t</td>
\t\t\t\t\t\t<td>
\t\t\t\t\t           {$sku[productPrice][currency][symbol]}{$sku[productPrice][amount]}
\t\t\t\t\t\t</td>
\t\t\t\t</tr>
EOF;
        }
        $skulist = <<<EOF
\t\t\t\t\t<tr class="title">
\t\t\t\t\t\t<td>
\t\t\t\t\t\t\t图片
\t\t\t\t\t\t</td>
\t\t\t\t\t\t<td>
\t\t\t\t\t\t\t标题
\t\t\t\t\t\t</td>
\t\t\t\t\t\t<td style="width:60px;">
\t\t\t\t\t\t\t属性
\t\t\t\t\t\t</td>
\t\t\t\t\t\t<td>
\t\t\t\t\t\t\tSKU
\t\t\t\t\t\t</td>
\t\t\t\t\t\t<td style="width:60px;">
\t\t\t\t\t\t\t数量
\t\t\t\t\t\t</td>
\t\t\t\t\t\t<td>
\t\t\t\t\t\t\t单价
\t\t\t\t\t\t</td>
\t\t\t\t\t</tr>
                    {$skustr}
EOF;
        //计算倒计时
        $timeStr = '';
        if ($detail['orderStatus'] == 'RISK_CONTROL') {
            //计算风控倒计时
            $paytimestamp = aliTranslateTime($detail['gmtPaySuccess']);
            //付款时间戳
            $riskendtime = $paytimestamp + 86400;
            $timeStr = date('m/d/Y H:i:s', $riskendtime);
            //风控结束时间字符串表示
            $timeStr = $riskendtime;
        } elseif ($detail['logisticsStatus'] == 'SELLER_SEND_GOODS' && $detail['orderStatus'] != 'FINISH') {
            $sendTimeStamp = aliTranslateTime($detail['logisticInfoList'][0]['gmtSend']);
            //发货时间戳
            $days = $alimsg_obj->culculateCountdown($receiverid, $detail['logisticInfoList'][0]['logisticsTypeCode'], $detail['receiptAddress']['country']);
            if ($days === FALSE) {
                $timeStr = AliOderMessageModel::$errMsg;
            } else {
                $endtime = $sendTimeStamp + $days * 86400;
                //$timeStr        = date('m/d/Y H:i:s', $endtime);
                $timeStr = $endtime;
            }
        }
        //物流信息
        $shipstr = '';
        if (isset($detail['logisticInfoList'][0])) {
            $shipstr .= '运输方式:' . $detail['logisticInfoList'][0]['logisticsTypeCode'] . '<br>';
            $carrier = $detail['logisticInfoList'][0]['logisticsTypeCode'];
            $tracksn = $detail['logisticInfoList'][0]['logisticsNo'];
            $trackstr = <<<EOF
            <a href="javascript:queryExpressInfo('aliexpress', '{$carrier}', '{$tracksn}', 'zh')">{$tracksn}</a>
EOF;
            $shipstr .= '跟踪号:' . $trackstr . '<br>';
        }
        $returndata['errCode'] = 5;
        $returndata['errMsg'] = '成功!';
        $returndata['data'] = array('buyer' => $detail['buyerInfo']['firstName'] . $detail['buyerInfo']['lastName'], 'seller' => $detail['sellerOperatorLoginId'], 'orderId' => $orderid, 'createtime' => formateAliTime($detail['gmtCreate']), 'paytime' => !empty($detail['gmtPaySuccess']) ? formateAliTime($detail['gmtPaySuccess']) : '未付款', 'initOderAmount' => $detail['initOderAmount']['currency']['symbol'] . $detail['initOderAmount']['amount'], 'OderAmount' => $detail['orderAmount']['currency']['symbol'] . $detail['orderAmount']['amount'], 'paytype' => '-----', 'fundStatus' => $this->status2str($detail['fundStatus']), 'loanStatus' => $this->status2str($detail['loanStatus']), 'issueStatus' => $this->status2str($detail['issueStatus']), 'issuscolor' => $detail['issueStatus'] == 'NO_ISSUE' ? 'green' : 'red', 'orderstatus' => $this->status2str($detail['orderStatus']), 'logisticsStatus' => $this->status2str($detail['logisticsStatus']), 'logisticsMoney' => $detail['logisticsAmount']['amount'], 'mobileNo' => $detail['receiptAddress']['mobileNo'], 'phoneNumber' => $detail['receiptAddress']['phoneArea'] . '-' . $detail['receiptAddress']['phoneNumber'], 'address' => $detail['receiptAddress']['detailAddress'] . ' ' . $detail['receiptAddress']['city'] . ' ' . $detail['receiptAddress']['province'] . ' ' . $detail['receiptAddress']['country'], 'skulist' => $skulist, 'refund' => isset($detail['refundInfo']) ? '退款状态' . $detail['refundInfo']['refundStatus'] . '<br>' . '退款类型' . $detail['refundInfo']['refundType'] : '', 'logisticInfo' => $shipstr, 'buyerSignerFullname' => isset($detail['buyerSignerFullname']) ? $detail['buyerSignerFullname'] : '', 'zip' => isset($detail['receiptAddress']['zip']) ? $detail['receiptAddress']['zip'] : '', 'email' => isset($detail['buyerInfo']['email']) ? $detail['buyerInfo']['email'] : '', 'timestr' => $timeStr, 'commission' => '$' . round($detail['orderAmount']['amount'] * 0.05, 2), 'profit' => '$' . round($detail['orderAmount']['amount'] * 0.95, 2));
        if (isset($detail['logisticInfoList'][0]['gmtSend'])) {
            $timeinfo = extractAliTimeInfo($detail['logisticInfoList'][0]['gmtSend']);
            $returndata['data']['shippedtime'] = $timeinfo['year'] . '-' . $timeinfo['month'] . '-' . $timeinfo['day'] . ' ' . $timeinfo['hour'] . ':' . $timeinfo['minit'] . ':' . $timeinfo['second'];
        } else {
            $returndata['data']['shippedtime'] = '';
        }
        $accountname = aliAccountf2Name($detail['sellerOperatorLoginId']);
        if ($accountname == FALSE) {
            //没找到对应关系
            $accountname == '';
        }
        $result_sys = getOpenSysApi('aliExpressOrderInfo', array('type' => 'orderinfo', 'recordnumber' => $orderid, 'selleraccount' => $accountname));
        //     	print_r($result_sys);exit;
        if (!empty($result_sys['data'])) {
            $returndata['data']['systemnum'] = $result_sys['data'][0]['ebay_id'];
            //系统编号
            $returndata['data']['syscarrer'] = $result_sys['data'][0]['ebay_carrier'];
            //运输方式
            $returndata['data']['systracknumber'] = $result_sys['data'][0]['ebay_tracknumber'];
            //跟踪号
            //     		$returndata['data']['shippedtime']    = empty($result_sys['data'][0]['ShippedTime']) ? '' : date('Y-m-d H:i:s', $result_sys['data'][0]['ShippedTime']);  //发货时间
            $returndata['data']['status'] = $result_sys['data'][0]['catename'];
            //发货状态
            $returndata['data']['ebay_note'] = $result_sys['data'][0]['note'];
            //订单留言
        } else {
            $returndata['data']['systemnum'] = '';
            //系统编号
            $returndata['data']['syscarrer'] = '';
            //运输方式
            $returndata['data']['systracknumber'] = '';
            //跟踪号
            //     	    $returndata['data']['shippedtime']    = '';                 //发货时间
            $returndata['data']['status'] = '';
            //发货状态
            $returndata['data']['ebay_note'] = '';
        }
        //     	print_r($returndata);exit;
        echo json_encode($returndata);
    }