Exemple #1
0
function erp_Write_fee($chips)
{
    $write = false;
    $unfields = array('ProjGUID', 'SyncTime', 'Rate', 'Flag');
    $sql = " select * from " . tablename('s_fee') . " where TradeGUID=:guid order by Sequence";
    $list = pdo_fetchall($sql, array(':guid' => $chips['qrcode']));
    foreach ($list as $fee) {
        if ($fee['SyncTime'] == 0) {
            foreach ($unfields as $field) {
                unset($fee[$field]);
            }
            if (empty($fee['lastDate'])) {
                unset($fee['lastDate']);
            }
            $fee['signguid'] = $chips['projguid'];
            $write = MsSql()->insertObject('s_Fee', $fee);
            if ($write) {
                pdo_update('s_fee', array('SyncTime' => TIMESTAMP), array('FeeGUID' => $fee['FeeGUID']));
            } else {
                logging('写入s_fee出错', $fee['FeeGUID']);
            }
        }
    }
    return $write;
}
function export_chips($projGUID, $progressFunc)
{
    $res = array('total' => 0, 'update' => 0, 'failed' => 0);
    $sql = "select * from " . tablename('chips') . " where projguid=:projguid and SyncTime=0 ";
    $list = pdo_fetchall($sql, array(':projguid' => $projGUID));
    $count = count($list);
    $progress = 0;
    $index = 0;
    $showProgress = function () use(&$progress, $count, &$index, $progressFunc) {
        $index++;
        $value = intval($index * 5 / $count);
        if ($value > $progress) {
            $progress = $value;
            if (!empty($progressFunc)) {
                $progressFunc($value);
            }
        }
    };
    $project = biz_getProject($projGUID);
    $payform = biz_unserializer($project, 'payform');
    $sql = "select * from " . tablename('s_discountdefine') . " where DiscntGUID=:DiscntGUID and ProjGUID=:ProjGUID ";
    foreach ($payform['dis_id'] as $id) {
        $payform['disc_Details'][] = pdo_fetch($sql, array(':DiscntGUID' => $id, ':ProjGUID' => $projGUID));
    }
    foreach ($list as $chips) {
        $showProgress();
        if (!empty($chips['ProtocolNO'])) {
            $res['total']++;
            $result = writeChipsToErp($chips, $payform);
            if ($result) {
                pdo_update('chips', array('SyncTime' => TIMESTAMP), array('qrcode' => $chips['qrcode']));
                $res['update']++;
            } else {
                $error = MsSql()->getErrors();
                MsSql()->clearError();
                //记录出错信息
                logging($chips['qrcode'], $error);
                $res['failed']++;
            }
        }
    }
    return $res;
}