You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.7 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. <?php
  2. namespace App\Http\Controllers\Home;
  3. use Illuminate\Support\Facades\DB;
  4. class TestController extends BaseController
  5. {
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. }
  10. //首页
  11. public function index()
  12. {
  13. //Excel文件导出功能,如果出现文件名中文乱码,iconv('UTF-8', 'GBK', '学生成绩')
  14. /* $cellData = [
  15. ['学号','姓名','成绩'],
  16. ['10001','AAAAA','99'],
  17. ['10002','BBBBB','92'],
  18. ['10003','CCCCC','95'],
  19. ['10004','DDDDD','89'],
  20. ['10005','EEEEE','96'],
  21. ];
  22. \Excel::create('学生成绩',function($excel) use ($cellData){
  23. //第一个工作簿,score是工作簿的名称
  24. $excel->sheet('score', function($sheet) use ($cellData){
  25. $sheet->rows($cellData);
  26. });
  27. //第二个工作簿
  28. $excel->sheet('score', function($sheet) use ($cellData){
  29. $sheet->rows($cellData);
  30. });
  31. })->export('xls');
  32. //Excel文件导入功能
  33. $filePath = 'storage/'.iconv('UTF-8', 'GBK', '学生成绩').'.xls';
  34. \Excel::load($filePath, function($reader) {
  35. $reader = $reader->getSheet(0);
  36. $res = $reader->toArray();
  37. dd($res);
  38. }); */
  39. }
  40. // 队列测试
  41. public function queue()
  42. {
  43. // php artisan queue:work
  44. dispatch(new \App\Jobs\Example());
  45. }
  46. // 事件测试
  47. public function event()
  48. {
  49. $order = \App\Http\Model\Order::where(['id' => 1])->first();
  50. $order_id = 1;
  51. event(new \App\Events\OrderShipped($order_id));
  52. }
  53. }