Ejemplo n.º 1
0
/**
 * 刷单标记发货:当当
 */
function shipping_sync_16($order_info)
{
    require_once '../admin/dangdang/ddClient.php';
    $dd = new ddClient(2100001198);
    // 获取商品列表
    $sql_select = 'SELECT goods_sn,goods_number FROM ' . $GLOBALS['ecs']->table('order_goods') . " WHERE order_id={$order_info['b']}";
    $goods_list = $GLOBALS['db']->getAll($sql_select);
    unset($val);
    foreach ($goods_list as &$val) {
        $params['oit'] = $val['goods_sn'];
        $resp = $dd->execute('POST', $params, 'dangdang.item.itemid.get');
        $val['goods_sn'] = $resp['Result']['itemID'];
    }
    unset($val);
    $order_info['shipping_tel'] = 1234567;
    $order_info['shipping_name'] = mb_strcut($order_info['shipping_name'], 0, 6) . '快递';
    $order_info['shipping_name'] = mb_convert_encoding($order_info['shipping_name'], 'GBK', 'UTF-8');
    $order_info['tracking_sn'] = trim($order_info['tracking_sn']);
    global $smarty;
    $smarty->assign('time', date('Y-m-d H:i:s'));
    $smarty->assign('method', 'dangdang.order.goods.send');
    $smarty->assign('order_info', $order_info);
    $smarty->assign('goods_list', $goods_list);
    $send_goods = $smarty->fetch('dangdang_XML.htm');
    if (file_exists('ddXML.xml')) {
        unlink('ddXML.xml');
    }
    $bytes = file_put_contents('ddXML.xml', $send_goods);
    $params['sendGoods'] = '/var/www/html/crm2/admin/ddXML.xml';
    //$dd = new ddClient(2100001198);
    $resp = $dd->execute('POSTXML', $params, 'dangdang.order.goods.send');
    if (isset($resp['Result']['OrdersList']['OrderInfo']['orderOperCode'])) {
        $res['message'] = '当当网提示您:订单' . $resp['Result']['OrdersList']['OrderInfo']['orderID'] . ',' . $resp['Result']['OrdersList']['OrderInfo']['orderOperation'];
    } else {
        $res = true;
    }
}
Ejemplo n.º 2
0
/**
 * 同步标记发货
 */
function shipping_synchro($order_id)
{
    global $json;
    // 获取标记发货所需的相关订单参数
    if ($_SESSION['role_id'] == 10) {
        $sql = 'SELECT order_sn,team,' . 'tracking_sn,shipping_id,shipping_name,shipping_code,province,shipping_time FROM ' . $GLOBALS['ecs']->table('ordersyn_info') . " WHERE order_id={$order_id}";
    } else {
        $sql = 'SELECT IF(platform_order_sn,platform_order_sn,order_sn) order_sn,team,' . 'tracking_sn,shipping_id,shipping_name,shipping_code,province,shipping_time FROM ' . $GLOBALS['ecs']->table('order_info') . " WHERE order_id={$order_id}";
    }
    $order_info = $GLOBALS['db']->getRow($sql);
    $tracking_sn = $order_info['tracking_sn'];
    // 获取快递公司编码
    $sql = 'SELECT company_code, company_name FROM ' . $GLOBALS['ecs']->table('shipping') . " WHERE shipping_id='{$order_info['shipping_id']}'";
    $logistics = $GLOBALS['db']->getRow($sql);
    // 同步发货(淘宝)
    if ($order_info['shipping_time'] && in_array($order_info['team'], array(6, 21, 22, 26, 53))) {
        $platform_path = array(6 => 'taobao', 21 => 'taobao01', 22 => 'taobao02', 26 => 'taobao03', 53 => 'taobao04');
        require_once dirname(__FILE__) . "/taobao/order_synchro.php";
        require_once dirname(__FILE__) . "/{$platform_path[$order_info['team']]}/sk.php";
        $auth = (require_once dirname(__FILE__) . "/{$platform_path[$order_info['team']]}/config.php");
        // 配置淘宝签权参数
        $c = new TopClient();
        $c->appkey = $auth['appkey'];
        $c->secretKey = $auth['secretKey'];
        // 查询订单当前状态是否符合发货条件
        $req = new TradeFullinfoGetRequest();
        $req->setFields("status");
        $req->setTid($order_info['order_sn']);
        $shipping_able = $c->execute($req, $sk['access_token']);
        $shipping_able = $json->decode($json->encode($shipping_able), true);
        // 订单状态符合发货条件
        if ($shipping_able['trade']['status'] == 'WAIT_SELLER_SEND_GOODS') {
            // 构建标记发货的数据格式
            $req = new LogisticsOfflineSendRequest();
            if ($logistics['company_code'] == 'zjs') {
                $req->setOutSid($tracking_sn);
                $req->setTid($order_info['order_sn']);
                $req->setCompanyCode(strtoupper($logistics['company_code']));
            } elseif ('lbex' == $logistics['company_code']) {
                return true;
                $req->setOutSid($tracking_sn);
                $req->setTid($order_info['order_sn']);
                $req->setCompanyCode('龙邦速递');
            } else {
                $req->setOutSid($tracking_sn);
                $req->setTid($order_info['order_sn']);
                $req->setCompanyCode(strtoupper($logistics['company_code']));
            }
            // 发送发货请求
            $shipping_resp = $c->execute($req, $sk['access_token']);
        } elseif ($shipping_able['trade']['status'] == 'WAIT_BUYER_CONFIRM_GOODS') {
            $req = new LogisticsConsignResendRequest();
            $req->setOutSid($tracking_sn);
            $req->setTid(number_format($order_info['order_sn'], 0, '', ''));
            $req->setCompanyCode(strtoupper($logistics['company_code']));
            $shipping_resp = $c->execute($req, $sk['access_token']);
        } elseif ($shipping_able['code'] == 27) {
            $res['message'] = '淘宝授权到期,请联系天猫推广,进行授权后再发货!';
            file_put_contents('taobao.txt', 27);
        } else {
            $res['message'] = '订单状态已改变,不符合发货条件!【天猫商城提示您】';
            $res['shipping_name'] = $order_info['shipping_name'];
            $res['errMsg'] = 1;
        }
        if (!isset($shipping_resp['shipping']['is_success']) || !$shipping_resp['shipping']['is_success']) {
            $res['message'] = $shipping_resp['sub_msg'];
        }
    }
    // 同步发货(拍拍)
    if ($order_info['shipping_time'] && $order_info['team'] == 7) {
        if (in_array($order_info['shipping_id'], array(29, 12))) {
            return false;
        }
        require_once dirname(__FILE__) . '/paipai/PaiPaiOpenApiOauth.php';
        // 加载参数
        $cfg_paipai = (require_once dirname(__FILE__) . '/paipai/config.php');
        // 配置四项签权参数
        $uin = $cfg_paipai['account'];
        $appOAuthID = $cfg_paipai['appkey'];
        $appOAuthkey = $cfg_paipai['secretKey'];
        $accessToken = $cfg_paipai['sessionKey'];
        // 2013-09-17更新,下次更新2014-09-17
        // 实例化拍拍接口
        $sdk = new PaiPaiOpenApiOauth($appOAuthID, $appOAuthkey, $accessToken, $uin);
        // 关闭调试模式
        $sdk->setDebugOn(false);
        // 查询订单当前状态是否符合发货条件
        $sdk->setApiPath("/deal/getDealDetail.xhtml");
        $sdk->setMethod("get");
        //post
        $sdk->setCharset("utf-8");
        //gbk
        $sdk->setFormat('json');
        $params =& $sdk->getParams();
        //注意,这里使用的是引用,故可以直接使用
        $params['sellerUin'] = $uin;
        $params['dealCode'] = trim($order_info['order_sn']);
        $params['pureData'] = 1;
        $shipping_able = $json->decode($sdk->invoke(), true);
        // 货到付款不需要标记发货
        if ($shipping_able['dealState'] == 'STATE_COD_WAIT_SHIP') {
            return true;
        }
        $propertymask = explode('_', $shipping_able['propertymask']);
        $allow_shipping = array('DS_WAIT_SELLER_DELIVERY');
        $need_pay = array('ems', 'sto_express', 'sf', 'emssn');
        if (!in_array($shipping_able['dealState'], $allow_shipping)) {
            $res['message'] = '【QQ商城提示您】订单状态已改变,不符合发货条件!';
            $res['shipping_name'] = $order_info['shipping_name'];
            $res['errMsg'] = 1;
        }
        if (($shipping_able['dealState'] == 'STATE_COD_WAIT_SHIP' || end($propertymask) == 2048 && $shipping_able['dealState'] == 'DS_WAIT_BUYER_PAY') && !in_array($order_info['shipping_code'], $need_pay)) {
            $res['message'] = '该订单须使用货到付款的配送方式!!!';
            $res['shipping_name'] = $order_info['shipping_name'];
            $res['errMsg'] = 1;
        }
        // 实例化拍拍接口
        $sdk = new PaiPaiOpenApiOauth($appOAuthID, $appOAuthkey, $accessToken, $uin);
        // 关闭调试模式
        $sdk->setDebugOn(false);
        //需要调用的 接口函数
        $sdk->setApiPath("/deal/sellerConsignDealItem.xhtml");
        $sdk->setMethod("get");
        //post
        $sdk->setCharset("utf-8");
        //gbk
        $sdk->setFormat('json');
        // 处理发货相关数据
        if (in_array($order_info['province'], array(6, 3465))) {
            $params['arriveDays'] = 3;
        } elseif (in_array($order_info['shipping_code'], array('sto_express', 'ems2', 'sf'))) {
            $params['arriveDays'] = 7;
        } else {
            $params['arriveDays'] = 5;
        }
        // 配置标记发货所需的参数
        $params =& $sdk->getParams();
        //注意,这里使用的是引用,故可以直接使用
        $params['sellerUin'] = $uin;
        $params['dealCode'] = $order_info['order_sn'];
        $params['pureData'] = 1;
        $params['logisticsName'] = $logistics['company_name'];
        $params['logisticsCode'] = $tracking_sn;
        $response = json_decode($sdk->invoke(), true);
        if ($response['errorCode']) {
            $res['message'] = $response['errorMessage'];
        }
    }
    // 同步发货(京东)
    if ($order_info['shipping_time'] && in_array($order_info['team'], array(10, 54, 55))) {
        include_once dirname(__FILE__) . '/jingdong/JdClient.php';
        include_once dirname(__FILE__) . '/jingdong/JdException.php';
        include_once dirname(__FILE__) . '/jingdong/request/order/OrderSopOutstorageRequest.php';
        $platform_path = array(10 => 'jingdong', 54 => 'aksojd', 55 => 'jlfjd');
        require_once dirname(__FILE__) . "/{$platform_path[$order_info['team']]}/sk.php";
        $auth = (require_once dirname(__FILE__) . "/{$platform_path[$order_info['team']]}/config.php");
        //include dirname(__FILE__).'/jingdong/sk.php';
        //$auth = include dirname(__FILE__).'/jingdong/config.php';
        $req = new OrderSopOutstorageRequest();
        $req->setOrderId($order_info['order_sn']);
        $req->setWaybill($tracking_sn);
        $sql_select = 'SELECT jd_code FROM ' . $GLOBALS['ecs']->table('shipping') . " WHERE shipping_id={$order_info['shipping_id']}";
        $req->setLogisticsId($GLOBALS['db']->getOne($sql_select));
        $jd = new JdClient();
        $jd->appKey = $auth['appkey'];
        // 京东AppKey
        $jd->appSecret = $auth['secretKey'];
        // 京东AppSecret
        $jd->accessToken = $sk['access_token'];
        // 京东sessionkey(access_token)
        $jd->timestamp = date('Y-m-d H:i:s');
        $jd->v = '2.0';
        $resp = $jd->execute($req);
        $resp = json_decode(json_encode($resp), true);
        if ($resp['error_response']['code']) {
            $res['message'] = $resp['error_response']['zh_desc'] . '【京东商城提示您】';
            $res['tracking_sn'] = $order_info['tracking_sn'];
        }
    }
    // 同步发货(1号店)
    if ($order_info['shipping_time'] && $order_info['team'] == 14) {
        include_once dirname(__FILE__) . '/yhd/YhdClient.php';
        include_once dirname(__FILE__) . '/yhd/sk.php';
        include_once dirname(__FILE__) . '/yhd/request/order/OrderLogisticsPushRequest.php';
        include_once dirname(__FILE__) . '/yhd/request/logistics/LogisticsOrderShipmentsUpdateRequest.php';
        $auth = (include_once dirname(__FILE__) . '/yhd/config.php');
        $req = new LogisticsOrderShipmentsUpdateRequest();
        // 应用级参数
        $req->setOrderCode($order_info['order_sn']);
        $req->setExpressNbr($tracking_sn);
        $sql_select = 'SELECT 1mall_code FROM ' . $GLOBALS['ecs']->table('shipping') . " WHERE shipping_id={$order_info['shipping_id']}";
        $req->setDeliverySupplierId($GLOBALS['db']->getOne($sql_select));
        $yhdClient = new YhdClient();
        // 系统级参数
        $yhdClient->appkey = $auth['appkey'];
        $yhdClient->secretKey = $auth['secretKey'];
        $yhdClient->format = 'json';
        $result = $yhdClient->execute($req, $sk['accessToken']);
        $result = objectsIntoArray($result);
        if ($result['response']['errInfoList']) {
            $req = new OrderDetailGetRequest();
            $req->setOrderCode($order_info['order_sn']);
            $yhdClient = new YhdClient();
            // 系统级参数
            $yhdClient->appkey = $auth['appkey'];
            $yhdClient->secretKey = $auth['secretKey'];
            $yhdClient->format = 'json';
            $express = $yhdClient->execute($req, $sk['accessToken']);
            $express = json_decode($express, true);
            if (isset($express['response']['orderInfo']['orderDetail']['merchantExpressNbr']) && $express['response']['orderInfo']['orderDetail']['merchantExpressNbr'] == $tracking_sn) {
            } elseif (isset($express['response']['orderInfo']['orderDetail']['merchantExpressNbr']) && $express['response']['orderInfo']['orderDetail']['merchantExpressNbr'] != $tracking_sn) {
                $res['message'] = '该订单已经在一号店标记发货,所使用的运单号为【' . $express['response']['orderInfo']['orderDetail']['merchantExpressNbr'] . '】';
            } else {
                $res['message'] = $result['response']['errInfoList']['errDetailInfo'][0]['errorDes'];
                $res['tracking_sn'] = $order_info['tracking_sn'];
            }
        }
    }
    // 当当同步发货
    if ($order_info['shipping_time'] && $order_info['team'] == 16) {
        require_once 'dangdang/ddClient.php';
        $dd = new ddClient(2100001198);
        // 获取商品列表
        $sql_select = 'SELECT IF(platform_order_sn,platform_order_sn,order_sn) order_sn FROM ' . $GLOBALS['ecs']->table('order_info') . " WHERE order_id={$order_id}";
        $order_sn = $GLOBALS['db']->getOne($sql_select);
        $params['o'] = $order_sn;
        $goods_info = $dd->execute('POST', $params, 'dangdang.order.details.get');
        $goods_list = array();
        if (isset($goods_info['ItemsList']['ItemInfo']['itemID'])) {
            $goods_list[] = array('goods_sn' => $goods_info['ItemsList']['ItemInfo']['outerItemID'], 'goods_number' => $goods_info['ItemsList']['ItemInfo']['orderCount']);
        } else {
            foreach ($goods_info['ItemsList']['ItemInfo'] as $v) {
                $goods_list[] = array('goods_sn' => $goods_info['ItemsList']['ItemInfo']['outerItemID'], 'goods_number' => $goods_info['ItemsList']['ItemInfo']['orderCount']);
            }
        }
        unset($val);
        foreach ($goods_list as &$val) {
            $params['oit'] = $val['goods_sn'];
            $resp = $dd->execute('POST', $params, 'dangdang.item.itemid.get');
            $val['goods_sn'] = $resp['Result']['itemID'];
        }
        unset($val);
        $order_info['shipping_tel'] = 1234567;
        $order_info['shipping_name'] = mb_strcut($order_info['shipping_name'], 0, 6) . '快递';
        $order_info['shipping_name'] = mb_convert_encoding($order_info['shipping_name'], 'GBK', 'UTF-8');
        $order_info['tracking_sn'] = trim($order_info['tracking_sn']);
        global $smarty;
        $smarty->assign('time', date('Y-m-d H:i:s'));
        $smarty->assign('method', 'dangdang.order.goods.send');
        $smarty->assign('order_info', $order_info);
        $smarty->assign('goods_list', $goods_list);
        $send_goods = $smarty->fetch('dangdang_XML.htm');
        if (file_exists('ddXML.xml')) {
            unlink('ddXML.xml');
        }
        $bytes = file_put_contents('ddXML.xml', $send_goods);
        $params['sendGoods'] = '/var/www/html/crm2/admin/ddXML.xml';
        //$dd = new ddClient(2100001198);
        $resp = $dd->execute('POSTXML', $params, 'dangdang.order.goods.send');
        if (isset($resp['Result']['OrdersList']['OrderInfo']['orderOperCode'])) {
            $res['message'] = '当当网提示您:订单' . $resp['Result']['OrdersList']['OrderInfo']['orderID'] . ',' . $resp['Result']['OrdersList']['OrderInfo']['orderOperation'];
        } else {
            $res = true;
        }
        $resp = var_export($resp, true);
        file_put_contents('ddInfo.htm', $resp, FILE_APPEND);
    }
    // 国美同步发货
    if ($order_info['shipping_time'] && $order_info['team'] == 12) {
        $auth = (include_once 'gome/config.php');
        $url = 'http://api.coo8.com/ApiControl';
        $sys_param = array('venderId' => $auth['appkey'], 'timestamp' => date('Y-m-d H:i:s'), 'v' => '2.0', 'signMethod' => 'md5', 'format' => 'json');
        // 应用级参数
        $sys_param['method'] = 'coo8.orders.send';
        $sys_param['orderid'] = $order['order_sn'];
        $sys_param['logisticsNumber'] = $tracking_sn;
        // 配送公司编号
        $sql_select = 'SELECT gemo_code FROM ' . $GLOBALS['ecs']->table('shipping') . ' s, ' . $GLOBALS['ecs']->table('order_info') . " i WHERE i.shipping_id=s.shipping_id AND i.order_id={$order_id}";
        $sys_param['carriersName'] = $GLOBALS['db']->getOne($sql_select);
        $sys_param['sign'] = makeSign($sys_param, $auth['secretKey']);
        //$url = $url.'?'.http_build_query($sys_param);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($sys_param));
        $data = curl_exec($ch);
        if (curl_errno($ch)) {
            throw new Exception(curl_error($ch), 0);
        } else {
            $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            if (200 !== $httpStatusCode) {
                throw new Exception($data, $httpStatusCode);
            }
        }
        curl_close($ch);
        $res = true;
    }
    // 苏宁同步发货
    if ($order_info['shipping_time'] && $order_info['team'] == 17) {
        require_once 'suning/SuningSdk.php';
        $auth = (require_once 'suning/config.php');
        // 配送公司编号
        $sql_select = 'SELECT suning_code,company_name FROM ' . $GLOBALS['ecs']->table('shipping') . ' s, ' . $GLOBALS['ecs']->table('order_info') . " i WHERE i.shipping_id=s.shipping_id AND i.order_id={$order_id}";
        $logistics = $GLOBALS['db']->getRow($sql_select);
        $shipping_code = $logistics['suning_code'];
        $req = new SuningCustomOrderGet();
        echo $order_info['order_sn'], PHP_EOL;
        $req->setOrderCode($order_info['order_sn']);
        $reqParam = $req->makeReqObject();
        $suning = new SuningClient();
        $suning->setAppKey($auth['appkey']);
        $suning->setAppSecret($auth['secretKey']);
        $suning->setMethod('suning.custom.order.get');
        $suning->setAppRequestTime(date('Y-m-d H:i:s'));
        $resp = $suning->execute($req, $reqParam);
        $resp = json_decode($resp, true);
        $orderLineNumbers = array();
        foreach ($resp['sn_responseContent']['sn_body']['orderGet']['orderDetail'] as $suningOrderLineNumber) {
            $orderLineNumbers = $suningOrderLineNumber['orderLineNumber'];
        }
        $req = new SuningCustomOrderDeliveryAdd();
        $req->setOrderCode($order_info['order_sn']);
        $req->setExpressNo($tracking_sn);
        $req->setExpressCompanyCode($shipping_code);
        $req->setDeliveryTime(date('Y-m-d H:i:s'));
        $sql_select = 'SELECT goods_sn FROM ' . $GLOBALS['ecs']->table('order_goods') . " WHERE order_sn='{$order_info['order_sn']}'";
        $productCode = $GLOBALS['db']->getCol($sql_select);
        $req->setProductCode($productCode);
        $req->setOrderLineNumber($orderLineNumbers);
        $reqParam = $req->makeReqObject();
        if ('param_is_null' == $reqParam['error_code']) {
            $msg = array('req_msg' => true, 'timeout' => 2000, 'message' => $reqParam['error_msg']);
            die($json->encode($msg));
        }
        $suning = new SuningClient();
        $suning->setAppKey($auth['appkey']);
        $suning->setAppSecret($auth['secretKey']);
        $suning->setMethod('suning.custom.orderdelivery.add');
        $suning->setAppRequestTime(date('Y-m-d H:i:s'));
        $resp = $suning->execute($req, $reqParam);
        $resp = json_decode($resp, true);
        $res = true;
    }
    return $res;
}
Ejemplo n.º 3
0
<?php

date_default_timezone_set('Asia/Shanghai');
include 'ddClient.php';
$dd = new ddClient(2100001198);
//$dd->set_method('dangdang.orders.list.get');
$dd = new ddClient(2100001198);
$resp = $dd->execute('POST', null, 'dangdang.orders.list.get');
echo '<pre>';
//print_r($resp);
foreach ($resp['OrdersList']['OrderInfo'] as $val) {
    //$dd->set_method('dangdang.order.details.get');
    $params['o'] = $val['orderID'];
    $order_detail = $dd->execute('POST', $params, 'dangdang.order.details.get');
    print_r($order_detail);
    exit;
}
//$dd->execute('POST');