MeasureMonitorController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\MeasuringMachine;
  4. use App\Package;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\DB;
  7. use Illuminate\Support\Facades\Gate;
  8. require_once 'api-speech/AipSpeech.php';
  9. class MeasureMonitorController extends Controller
  10. {
  11. const APP_ID='18433903';
  12. const API_KEY='3pfojF55BI9LFfXdaI8wRyV2';
  13. const SECRET_KEY='ZRSZWUPNgRNrdm4gBQ5Gf0c1oANN4mnd';
  14. /**
  15. * Display a listing of the resource.
  16. *
  17. * @return \Illuminate\Http\Response
  18. */
  19. public function index(Request $request)
  20. {
  21. if(!Gate::allows('包裹信息-查询')){ return redirect(url('/')); }
  22. /*$sql='SELECT a.* FROM packages a WHERE id = (SELECT MAX(id) FROM packages WHERE measuring_machine_id = a.measuring_machine_id) ORDER BY a.id';
  23. $packages=DB::table(DB::raw("($sql) as t"))->get();*/
  24. $measuring_machine_id=[];
  25. /* for ($i=0;$i<count($measuringMachine);$i++){
  26. $measuring_machine_id[$i]=$measuringMachine[$i]->id;
  27. }
  28. dd($measuring_machine_id);*/
  29. $measuring_machine_id=$request->input('id');
  30. $measuringMachines=MeasuringMachine::select('id','name','code')->get();
  31. if ($measuringMachines){
  32. if (!$measuring_machine_id){
  33. $package=Package::with('owner','paperBox','measuringMachine')->where('measuring_machine_id',$measuringMachines[0]->id)->orderBy('id','DESC')->first();
  34. }else{
  35. $package=Package::with('owner','paperBox','measuringMachine')->where('measuring_machine_id',$measuring_machine_id)->orderBy('id','DESC')->first();
  36. if (!$package){
  37. $measuringMachine=MeasuringMachine::where('id',$measuring_machine_id)->first();
  38. $package=new Package();
  39. if ($measuringMachine)$package->measuringMachine=$measuringMachine;
  40. }
  41. }
  42. }
  43. return view('weight.measureMonitor.index',['package'=>isset($package)?$package:null,'measuringMachines'=>$measuringMachines]);
  44. }
  45. public function flush(Request $request){
  46. $measuring_machine_id=$request->input('id');
  47. if ($measuring_machine_id){
  48. $package=Package::with('owner','paperBox','measuringMachine')->where('measuring_machine_id',$measuring_machine_id)->orderBy('id','DESC')->first();
  49. if (!$package){
  50. $measuringMachine=MeasuringMachine::where('id',$measuring_machine_id)->first();
  51. $package=new Package();
  52. if ($measuringMachine)$package->measuringMachine=$measuringMachine;
  53. }
  54. return $package;
  55. }
  56. return false;
  57. }
  58. public function speech(){
  59. $client=new \AipSpeech(self::APP_ID,self::API_KEY,self::SECRET_KEY);
  60. $client->setConnectionTimeoutInMillis('180000');
  61. $client->setSocketTimeoutInMillis('180000');
  62. $result = $client->synthesis('你好百度', 'zh', 1, array(
  63. 'vol' => 5,
  64. ));
  65. // 识别正确返回语音二进制 错误则返回json 参照下面错误码
  66. if(!is_array($result)){
  67. file_put_contents('audio.mp3', $result);
  68. }
  69. }
  70. /**
  71. * Store a newly created resource in storage.
  72. *
  73. * @param \Illuminate\Http\Request $request
  74. * @return \Illuminate\Http\Response
  75. */
  76. public function store(Request $request)
  77. {
  78. //
  79. }
  80. /**
  81. * Display the specified resource.
  82. *
  83. * @param int $id
  84. * @return \Illuminate\Http\Response
  85. */
  86. public function show($id)
  87. {
  88. //
  89. }
  90. /**
  91. * Show the form for editing the specified resource.
  92. *
  93. * @param int $id
  94. * @return \Illuminate\Http\Response
  95. */
  96. public function edit($id)
  97. {
  98. //
  99. }
  100. /**
  101. * Update the specified resource in storage.
  102. *
  103. * @param \Illuminate\Http\Request $request
  104. * @param int $id
  105. * @return \Illuminate\Http\Response
  106. */
  107. public function update(Request $request, $id)
  108. {
  109. //
  110. }
  111. /**
  112. * Remove the specified resource from storage.
  113. *
  114. * @param int $id
  115. * @return \Illuminate\Http\Response
  116. */
  117. public function destroy($id)
  118. {
  119. //
  120. }
  121. }