<?php

/**
 * 同步历史订单
 */
include_once dirname(dirname(__FILE__)).'/base/dealBase.php';

class syncOrdersStatus extends dealBase {

    public function setPara() {
        $this->processnum = $GLOBALS['DAEMON_NUMLIMIT'][DAEMON_SYNC_ORDERS_STATUS];
        $this->deal_sleep = 60;
//         $this->is_while = false;
    }

    public function deal() {
        $obj = new mOrder();
        $order_list = $obj->getNotFinishedOrders();
        if (empty($order_list)) return true;

        $shopid2orders = array();
        foreach ($order_list as $order) {
            $shopid2orders[$order['shop_id']][] = $order['order_sn'];
        }

        $pobj = new mPdd();

        foreach ($shopid2orders as $shopid => $tids) {
            $tids_status = $pobj->getPddOrderStatus($tids, '', $shopid);
            if (!$tids_status) continue;

            foreach ($tids_status as $info) {
                if (!$info) continue;

                $obj->updateOrderBySn($info['orderSn'], array('order_status'=>$info['order_status'], 'refund_status'=>$info['refund_status']));
            }
        }

    }

}

new syncOrdersStatus();