ProgressImgController.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Support\Facades\Cache;
  5. use App\Tools\RedisClusters;
  6. use Illuminate\Support\Facades\Log;
  7. class ProgressImgController extends Controller
  8. {
  9. /**
  10. * Display a listing of the resource.
  11. *
  12. * @return \Illuminate\Http\Response
  13. */
  14. public function index()
  15. {
  16. //
  17. }
  18. /**
  19. * Store a newly created resource in storage.
  20. *
  21. * @param \Illuminate\Http\Request $request
  22. * @return \Illuminate\Http\Response
  23. */
  24. public function store(Request $request)
  25. {
  26. //
  27. }
  28. /**
  29. * Display the specified resource.
  30. *
  31. * @param string $id
  32. * @return \Illuminate\Http\Response
  33. */
  34. public function show($id)
  35. {
  36. //
  37. return response()->stream(function () use ($id) {
  38. $key = str_replace('-','/',$id);
  39. $svg = RedisClusters::get('svg/'.$key, function () use ($key) {
  40. $viewHeight = 60;
  41. $svg = "<svg xmlns='http://www.w3.org/2000/svg' fill='currentColor' viewBox='0 0 300 60'>";
  42. $data = RedisClusters::get($key);
  43. if(is_array($data)){
  44. $point = [];
  45. foreach ($data as $key => $value) {
  46. $point[] = ($key*10) . ',' . $viewHeight-($value/20)-3;
  47. }
  48. $svg .= '<polyline points="'. implode(' ',$point) . '"';
  49. $svg .= ' style="fill:none;stroke:green;stroke-width:3" /></svg>';
  50. }else{
  51. $svg .= '<polyline points="0,0 1,0" /></svg>';
  52. }
  53. return $svg;
  54. } , config('mint.cache.expire') );
  55. echo $svg;
  56. }, 200, ['Content-Type' => 'image/svg+xml']);
  57. /*
  58. ————————————————
  59. 原文作者:Summer
  60. 转自链接:https://learnku.com/laravel/wikis/25600
  61. 版权声明:著作权归作者所有。商业转载请联系作者获得授权,非商业转载请保留以上作者信息和原文链接。
  62. */
  63. }
  64. /**
  65. * Update the specified resource in storage.
  66. *
  67. * @param \Illuminate\Http\Request $request
  68. * @param int $id
  69. * @return \Illuminate\Http\Response
  70. */
  71. public function update(Request $request, $id)
  72. {
  73. //
  74. }
  75. /**
  76. * Remove the specified resource from storage.
  77. *
  78. * @param int $id
  79. * @return \Illuminate\Http\Response
  80. */
  81. public function destroy($id)
  82. {
  83. //
  84. }
  85. }