Export data

来源:互联网 发布:女生变漂亮知乎 编辑:程序博客网 时间:2024/06/05 05:43

class ExportUserChannelCommand extends CConsoleCommand{


    public function run($args){


        echo "执行开始!!!\n";


        $date_now=time();

        $date_ago=$date_now-(60*60*24*30*4);

        $criteria=new CDbCriteria;

        $criteria->select='*';

        $criteria->addCondition("time >={$date_ago}");

        $criteria->order = 'time desc';

        $api_log=UserChannel::model()->findAll($criteria);


        if(empty($api_log)){

            echo "没有查到相关数据\n";

            return;

        }


        $line="";

        $fp = fopen('./UserChannelData.txt', 'w');

        foreach($api_log as $k=>$v) {

            $val=$v->attributes;

            $line="";


            foreach ($val as $va) {

                $line .= $va."^";

            }

            $line=trim($line,"^");

            $line .= "\n";

            fwrite($fp, $line);

        }

        fclose($fp);


        echo "执行结束!!!\n";


    }

}    

原创粉丝点击