<?php

namespace web\api;

class craw {
    public static function json_getmaxid() {
        global $db;
        $post = new \ciy\post();
        $table = $post->get('table');
        $csql = new \ciy\sql($table);
        $csql->order('id desc');
        $csql->column('id');
        $ret['maxid'] = toint($db->get1($csql));
        return succjson($ret);
    }
    public static function json_filldata() {
        global $db;
        $post = new \ciy\post();
        $lists = $post->get('list');
        $table = $post->get('table');
        if (is_string($lists))
            $lists = json_decode($lists, true);
        $ret['dataid'] = 0;
        foreach ($lists as $list) {
            $csql = new \ciy\sql($table);
            $csql->where('id', $list['id']);
            $row = $db->getone($csql);
            if (is_array($row)) {
                if ($db->update($csql, $list) === false) {
                    savelogfile('err_db', '更新filldata失败:' . $db->error, true);
                    break;
                }
            } else {
                if ($db->insert($csql, $list) === false) {
                    savelogfile('err_db', '新增filldata失败:' . $db->error, true);
                    break;
                }
            }
            $ret['dataid'] = $list['id'];
            if ($table == 'c_*') {
            }
        }
        return succjson($ret);
    }
}
