Example #1
0
    /**
     * 叮当内容统计add
     */
    public function dingdoneAddNums()
    {
        $id = intval($this->input['id']);
        $content_fromid = intval($this->input['content_fromid']);
        if (!$id) {
            $this->errorOutput(NOID);
        }
        $rec = intval($this->input['rec']);
        $appunid = addslashes($this->input['app_uniqueid']);
        $modunid = addslashes($this->input['mod_uniqueid']);
        //叮当原有数据兼容
        $old_sql = 'SELECT id, access_nums, is_sync,url, last_sync_time, create_time, title
				FROM ' . DB_PREFIX . "nums\r\n\t\t\tWHERE app_bundle='{$appunid}' AND module_bundle='{$modunid}' AND cid='{$id}' AND content_fromid = 0";
        $old_row = $this->db->query_first($old_sql);
        if ($old_row && is_array($old_row)) {
            $count = intval($old_row['access_nums']);
            //删除此数据
            $delete_old_sql = "delete from " . DB_PREFIX . "nums where cid =" . $id;
            $this->db->query($delete_old_sql);
        } else {
            $sql = 'SELECT id, access_nums, is_sync,url, last_sync_time, create_time, title
				FROM ' . DB_PREFIX . "nums\r\n\t\t\t\t\t\t\tWHERE app_bundle='{$appunid}' AND module_bundle='{$modunid}' AND content_fromid='{$content_fromid}'";
            $row = $this->db->query_first($sql);
            $count = intval($row['access_nums']);
            $delete_new_sql = "delete from " . DB_PREFIX . "nums where content_fromid =" . $content_fromid . "";
            $this->db->query($delete_new_sql);
        }
        if ($rec) {
            $title = $this->input['title'];
            if (!$title && !$row['title']) {
                include_once ROOT_PATH . 'lib/class/publishcontent.class.php';
                $this->publishcontent = new publishcontent();
                $content_type = $this->publishcontent->get_all_content_type();
                $this->pub_content_bundle = $pub_content_bundle = array();
                foreach ((array) $content_type as $k => $v) {
                    $this->pub_content_bundle[] = $pub_content_bundle[] = $v['bundle_id'];
                }
                if ($appunid && in_array($appunid, $pub_content_bundle)) {
                    //统计时如果没有传并且库里没有标题,去发布库查询标题,用户统计后台搜索
                    include_once ROOT_PATH . 'lib/class/publishcontent.class.php';
                    $this->publishtcontent = new publishcontent();
                    $content = $this->publishtcontent->get_content_by_cid($id);
                    $title = $content[$id]['title'];
                }
            }
            $title = $title ? addslashes($title) : addslashes($row['title']);
            $reffer = addslashes($this->input['reffer']);
            $type = intval($this->input['type']);
            $columnid = intval($this->input['column_id']);
            // 			if((TIMENOW - $row['last_sync_time']) >= SYNC_SPACE * 3600)
            // 			{
            $count = $count + 1;
            // 			}
            $ip = hg_getip();
            $time = date('Ym', TIMENOW);
            if (!$row['id']) {
                $row['create_time'] = TIMENOW;
            }
            $tableName = "record_" . $time;
            //			$sql = "SHOW TABLES LIKE '" . DB_PREFIX . $tableName. "'";
            //			$this->db->query($sql);
            //			if(!$this->db->affected_rows())
            ### 读取已经存在的表验证新表是否已经存在
            include_once CUR_CONF_PATH . 'lib/cache.class.php';
            $cache = new CacheFile();
            $oldTable = $cache->get_cache('access_table_name');
            if (!in_array($tableName, $oldTable)) {
                $sql = "CREATE TABLE " . DB_PREFIX . $tableName . " LIKE " . DB_PREFIX . "record";
                $this->db->query($sql);
                // 				###保存已建的表 关联时验证表是否存在
                $newTable = array($tableName);
                $allTable = array_merge($oldTable, $newTable);
                $allTable = array_unique($allTable);
                $cache->set_cache('access_table_name', $allTable);
                // 				###保存结束
            }
            $sql = 'INSERT INTO ' . DB_PREFIX . "record_" . $time . " (app_bundle, module_bundle, type, content_fromid ,cid, column_id, refer_url, ip, access_time, appid, appname,user_id, user_name, title) VALUES\r\n\t\t\t('{$appunid}', '{$modunid}', '{$type}', {$content_fromid} ,'{$id}', '{$columnid}', '{$reffer}', '{$ip}', " . TIMENOW . ", '{$this->user['appid']}', '{$this->user['appname']}', '{$this->user['user_id']}', '{$this->user['user_name']}', '{$title}')";
            $this->db->query($sql);
            if (!$row['url']) {
                $row['url'] = $reffer;
            }
            $sql = 'INSERT INTO ' . DB_PREFIX . "nums (app_bundle, module_bundle, content_fromid,cid, title, access_nums, last_sync_time, is_sync, url, create_time, update_time) VALUES\r\n\t\t\t('{$appunid}', '{$modunid}', '{$content_fromid}', '{$id}' ,'{$title}', " . $count . ", '{$row['last_sync_time']}', '{$row['is_sync']}', '{$row['url']}', '{$row['create_time']}', " . TIMENOW . ")";
            $this->db->query($sql);
            $this->dingdoneSync($content_fromid, $row['last_sync_time'], $row['create_time'], $count, $appunid, $modunid);
        }
        if (isset($this->settings['default_number']) && $this->settings['default_number']) {
            @srand($id);
            $min = $max = 0;
            list($min, $max) = @split(',', $this->settings['default_number']);
            $count += @rand($min, $max);
        }
        $this->addItem($count);
        $this->output();
    }