diff --git a/app/portal/controller/TestController.php b/app/portal/controller/TestController.php
index ba390af..ead3c59 100644
--- a/app/portal/controller/TestController.php
+++ b/app/portal/controller/TestController.php
@@ -15,6 +15,122 @@ use think\Db;
 
 class TestController extends HomeBaseController
 {
+
+    public function prob()
+    {
+        $uid = 451;
+        $user = Db::name('user')->where('id',$uid)->find();
+        $indent = Db::name('indent')->where('salesman_uid',$uid)->order('create_time','desc')->select();
+        $arr = collection($indent)->toArray();
+        $data = [];
+        $state_arr = [
+            4 => '待付款',
+            2 => '待发货',
+            3 => '已完成',
+            5 => '已发货',
+            6 => '待取货'
+        ];
+        foreach ($arr as &$v) {
+            $money = Db::name('money_income')->where('uid',$uid)->where('indent_id',$v['id'])->value('money');
+            $fact_money = Db::name('money_income')->where('uid',$uid)->where('indent_id',$v['id'])->sum('money');
+//            $income = Db::name('money_income')->where('uid',$uid)->where('indent_id',$v['id'])->select();
+//            $v['income'] = collection($income)->toArray();
+
+//            $data[] = [
+//                'id' => $v['id'],
+//                'money' => $money,
+//                'number' => $v['book_num'],
+//                'name' => $v['name'],
+//                'phone' => $v['phone'],
+//                'school' => $v['school'].'-'.$v['grade'].$v['class'],
+//                'state' => $state_arr[$v['state']],
+//                'create_time' => date('Y-m-d H:i:s',$v['create_time']),
+//                'pay_time' => date('Y-m-d H:i:s',$v['pay_time']),
+//                'region' => $v['region'],
+//                'beiyong_address' => $v['beiyong_address'],
+//                'award' => $money,
+//                'fact_award' => $fact_money,
+//                'is_error' => $fact_money != $money ? '是' : '否'
+//            ];
+            $data[] = [
+                $v['id'],
+                $money,
+                $v['book_num'],
+                $v['name'],
+                $v['phone'],
+                $v['school'].'-'.$v['grade'].$v['class'],
+                $state_arr[$v['state']],
+                date('Y-m-d H:i:s',$v['create_time']),
+                date('Y-m-d H:i:s',$v['pay_time']),
+                $v['region'],
+                $v['beiyong_address'],
+                $money,
+                $fact_money,
+                $fact_money != $money ? '是' : '否'
+            ];
+        }
+        $this->excel($user,$data);
+        print_r($arr);exit;
+    }
+
+
+    /**
+     *
+     * 导出Excel
+     */
+    public function excel($user,$data2)
+    {
+        //引入PHPExcel库文件
+//        Vendor('phpexcel2.PHPExcel');
+        //创建对象
+        $excel = new \PHPExcel();
+        //Excel表格式,这里简略写了8列
+        $letter = array('A', 'B', 'C', 'D', 'E', 'F', 'F', 'G','H','I','J','k','L','M','N');
+        $excel->getActiveSheet()->setCellValue("A1", "业务员名称");
+        $excel->getActiveSheet()->setCellValue("B1", $user['user_nickname']);
+        //表头数组
+        $tableheader = array('订单号', '价钱', '数量', '姓名', '电话', '学校-班级', '订单状态', '创建时间', '支付时间', '配送时间', '地区', '备用地址',
+            '应得收益', '实际收益', '是否异常');
+        //填充表头信息
+        for ($i = 1; $i < count($tableheader) + 1; $i++) {
+            $excel->getActiveSheet()->setCellValue("$letter[$i]2", "$tableheader[$i]");
+        }
+        //表格数组
+        $data = array(
+            array('1', 'B', 'C', 'D', 'E', 'F', 'G'),
+            array('2', 'B', 'C', 'D', 'E', 'F', 'G'),
+            array('3', 'B', 'C', 'D', 'E', 'F', 'G'),
+            array('4', 'B', 'C', 'D', 'E', 'F', 'G'),
+            array('5', 'B', 'C', 'D', 'E', 'F', 'G'),
+            array('6', 'B', 'C', 'D', 'E', 'F', 'G'),
+            array('7', 'B', 'C', 'D', 'E', 'F', 'G'),
+        );
+//        $tz = Db::name('taizhang');
+//        $data2 = $tz->field('type',true)->select();
+        //print_r($data2);exit();
+        //填充表格信息
+        for ($i = 3; $i <= count($data2) + 1; $i++) {
+            $j = 0;
+            foreach ($data2[$i - 2] as $key => $value) {
+                $excel->getActiveSheet()->setCellValue("$letter[$j]$i", "$value");
+                $j++;
+            }
+        }
+        //创建Excel输入对象
+        $write = new \PHPExcel_Writer_Excel2007($excel);
+        header("Pragma: public");
+        header("Expires: 0");
+        header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
+        header("Content-Type:application/force-download");
+        header("Content-Type:application/vnd.ms-execl");
+        header("Content-Type:application/octet-stream");
+        header("Content-Type:application/download");;
+        header('Content-Disposition:attachment;filename="信息系统表.xlsx"');
+        header("Content-Transfer-Encoding:binary");
+        $write->save('php://output');
+    }
+
+
     /**
      * 恢复父级id
      * @throws \think\Exception
@@ -24,14 +140,93 @@ class TestController extends HomeBaseController
      * @throws \think\exception\PDOException
      */
     public function test(){
-        $uids = Db::name('indent_over')->group('uid')->column('uid');
-        $indent = Db::name('indent')->whereIn('salesman_uid',$uids)->select();
-        $insert = [];
-        foreach ($indent as $v) {
-            unset($v['id']);
-            $insert[] = $v;
+        ini_set('max_execution_time', 3600);//秒为单位,自己根据需要定义
+        ini_set('memory_limit','-1');
+//        $b = Db::name('indent_pro')->where('salesman_uid',309)->update(['is_out'=>0]);
+        $page = $this->request->param('page',1);
+        $uid = Db::name('indent_pro')->where('is_out',0)->group('salesman_uid')->order('salesman_uid','desc')->value('salesman_uid');
+        if(!$uid) {
+            echo 123;exit;
         }
-        Db::name('indent_pro')->insertAll($insert);
+//        print_r($uid);exit;
+        $list = Db::name('indent_pro')->where('salesman_uid',$uid)->paginate(50,true,['page'=>$page]);
+        $list = $list->items();
+        $state_arr = ['2'=>'待发货','3'=>'已完成','5'=>'已发货','6'=>'待收货'];
+        $i = [];
+        foreach ($list as $v) {
+            $order = Db::name('indent')->where('salesman_uid',$v['salesman_uid'])->where('order_number',$v['order_number'])
+                ->whereIn('state',['2','3','5','6'])->find();
+            if(!$order) continue;
+            $school_class = $v['school'].'-'.$v['grade'].$v['class'];
+            $salesman_name = Db::name('user')->where('id',$v['salesman_uid'])->value('user_nickname');
+            $award = Db::name('money_income')->where('indent_id',$order['id'])->where('uid',$order['salesman_uid'])->value('money');
+            if($award) {
+                $award_fac = Db::name('money_income')->where('indent_id',$order['id'])->where('uid',$order['salesman_uid'])->sum('money');
+                $i[] = [
+                    'state_text' => $state_arr[$order['state']],
+                    'order_number' => $order['order_number'],
+                    'money' => $order['money'],
+                    'create_time' => date('Y-m-d H:i:s',$order['create_time']),
+                    'book_num' => $order['book_num'],
+                    'leave_word' => $order['leave_word'],
+                    'name' => $order['name'],
+                    'phone' => $order['phone'],
+                    'school_class' => $school_class,
+                    'salesman_name' => $salesman_name,
+                    'pay_time' => date('Y-m-d H:i:s',$order['pay_time']),
+                    'start_time' => $order['start_time'],
+                    'end_time' => $order['end_time'],
+                    'region' => $order['region'],
+                    'beiyong_address' => $order['beiyong_address'],
+                    'award' => $award,
+                    'award_fac' => $award_fac,
+                    'is_pro' => $award_fac > $award ? '是' : '否'
+                ];
+            }
+        }
+        $b = true;
+        Db::startTrans();
+        if(count($i) == 0) {
+            Db::name('indent_pro')->where('salesman_uid',$uid)->update(['is_out'=>1]);
+            $page = 0;
+        } else {
+            $a = Db::name('indent_orders')->insertAll($i);
+            if(count($i) < 50) {
+                $b = Db::name('indent_pro')->where('salesman_uid',$uid)->update(['is_out'=>1]);
+                $page = 0;
+            }
+            if(!$a || !$b) Db::rollback();
+        }
+        Db::commit();
+        $page = $page + 1;
+        sleep(1);
+        $this->redirect(url('portal/test/test',['page'=>$page],true,true));
+//        $sql = Db::name('indent_pro')->getLastSql();
+//        print_r($sql);
+//        print_r($uid);exit;
+//        $page = $this->request->param('page',1,'intval');
+//        $num = 2000;
+////        $arr = [267,295,309];
+//        $uid = Db::name('indent_over')->where('status',0)
+////            ->whereNotIn('uid',$arr)
+//            ->group('uid')->value('uid');
+////        print_r($uid);exit;
+//        $list = Db::name('indent')->whereIn('salesman_uid',$uid)->paginate($num,true,['page'=>$page]);
+//        $indent = $list->items();
+//        $insert = [];
+//        foreach ($indent as $v) {
+//            unset($v['id']);
+//            $insert[] = $v;
+//        }
+//        $res = $res2 = true;
+//        Db::startTrans();
+//        if(count($indent) == 0) {
+//            $res2 = Db::name('indent_over')->where('uid',$uid)->update(['status'=>1]);
+//        } else {
+//            $res = Db::name('indent_pro')->insertAll($insert);
+//        }
+//        if(!$res || !$res2) Db::rollback();
+//        Db::commit();
 //        $all = Db::name('indent_over')->select();
 //        foreach ($all as $v) {
 //            $indent = Db::name('indent')->where('id',$v['indent_id'])->where('book_num',2)->count();