TP3怎么把2个表查到的数据,合并到一个表里面

浏览:386 发布日期:2019/07/02 分类:求助交流 关键字: tp3 php
public function editors()
    {
        if(I('start'))
        {
            $start = I('start');
        }
        else
        {
            $start = date("Y-m-01",time());
        }

        if(I('end'))
        {
            $end = I('end');
        }
        else
        {
            $end = date("Y-m-d",time());
        }       
        $this->assign("start",$start);
        $this->assign("end",$end);
        $end =  date("Y-m-d",strtotime("+1 day",strtotime($end)));
        
        if(I('page'))
        {
//          $username   = $_SESSION['admin_user'];
            $user  = M('mtuser','mt_');//用户表
            $article  = M('article','mt_');//文章表
            $editorlog = M('editor_log',null);//文章记录表

            $field='id,username,status,role_id,rname,level,group,edit_num';

            $count = $user->field($field)->count();
            $users = $user->field($field)->select();

            $usernames = array();

            foreach($users as $k => $v)
            {
                array_push($usernames,$v['username']);                
            }
            $where['hidden'] = 0;
            $where['instance'] = array('in',$usernames);

//            $where['addtime'] = array('between',array(strtotime($start),strtotime($end)));

            $infos = $article
                ->field('sum( audit_status = 0 ) as history,sum( audit_status = 6 ) as need,sum( audit_status = 0 and sin_time BETWEEN '.strtotime($start).' and '.strtotime($end).' ) as edited,instance')
                ->where($where)
                ->group('instance')
                ->order('history desc')
                ->page(I('page'),I('limit'))->select();

            $log_info = $editorlog
                ->field('sum( type = -1 ) as rebut_all,sum( type = 1 ) as publish_num,sum( type = 0 )as edit_all,instance')
                ->where($where)
                ->group('instance')
                ->page(I('page'),I('limit'))->select();

//            $info_all = array_merge($infos,$log_info);

            //获得间隔天数
            $dayinfo = array();
            $editor_dayinfo = array();
            $ext_infos['day_info'] = array();
            $ext_infos['day_info'] = $this->prDates($start,$end);
            
            for($i = 0 ;$i < count($infos['day_info']);$i++)
            {
                $dayinfo[$infos['day_info'][$i]] = 0;
            }

            $index = 0;
            foreach($infos as $k => $v)
            {
                foreach($users as $j => $l)
                {
                    if($l['username'] == $v['instance'])
                    {
                        //构造highcharts 数据
                        $where['instance'] = $v['instance'];
                        $where['sin_time'] = array('between',array(strtotime($start),strtotime($end)));
                        $editor_info =$article->field('sum(audit_status = 0) as edited,FROM_UNIXTIME(sin_time,"%Y-%m-%d") as day')
                        ->where($where)->group('day')->select();

                        $editor_dayinfo[$index]['name'] = $v['instance'];
                        $editor_dayinfo[$index]['data'] =  array();
                        foreach($editor_info as $m => $n)
                        {
                            $dayinfo[$n['day']] = $n['edited'];
                        }
                        foreach( $dayinfo as $q => $w)
                        {
                           array_push($editor_dayinfo[ $index]['data'],(int)$dayinfo[$q]);
                        }
                        $index++;
                        $infos[$k]['id'] = $l['id'];
                        $infos[$k]['username'] = $l['username'];
                        $infos[$k]['status'] = $l['status'];
                        $infos[$k]['role_id'] = $l['role_id'];
                        $infos[$k]['rname'] = $l['rname'];
                        $infos[$k]['level'] = $l['level'];
                        $infos[$k]['group'] = $l['group'];
                        $log_info[$k]['history'] = $k['history'];
                        $infos[$k]['edit_min'] = 125;
                        $log_info[$k]['edit_num'] = $k['edit_num'];
                        $log_info[$k]['publish_num'] = $k['publish_num'];
                        $log_info[$k]['rebut_all'] = $k['rebut_all'];
                        $log_info[$k]['biaozong'] = $k['biaozong'];
                        $log_info[$k]['need'] = $k['need'];



                    }
                }
            }

            $ext_infos['edit_info'] = $editor_dayinfo;
            $data['code'] = '0';
            $data['count'] = $count;
            $data['data'] = $infos;
            echo json_encode($data);
            exit();
        }
        $this->display();
    }
最佳答案
评论( 相关
后面还有条评论,点击查看>>