| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- namespace App\Http\Controllers;
- use App\MeasuringMachine;
- use App\Package;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Gate;
- require_once 'api-speech/AipSpeech.php';
- class MeasureMonitorController extends Controller
- {
- const APP_ID='18433903';
- const API_KEY='3pfojF55BI9LFfXdaI8wRyV2';
- const SECRET_KEY='ZRSZWUPNgRNrdm4gBQ5Gf0c1oANN4mnd';
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function index(Request $request)
- {
- if(!Gate::allows('包裹信息-查询')){ return redirect(url('/')); }
- /*$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';
- $packages=DB::table(DB::raw("($sql) as t"))->get();*/
- $measuring_machine_id=[];
- /* for ($i=0;$i<count($measuringMachine);$i++){
- $measuring_machine_id[$i]=$measuringMachine[$i]->id;
- }
- dd($measuring_machine_id);*/
- $measuring_machine_id=$request->input('id');
- $measuringMachines=MeasuringMachine::select('id','name','code')->get();
- if ($measuringMachines){
- if (!$measuring_machine_id){
- $package=Package::with('owner','paperBox','measuringMachine')->where('measuring_machine_id',$measuringMachines[0]->id)->orderBy('id','DESC')->first();
- }else{
- $package=Package::with('owner','paperBox','measuringMachine')->where('measuring_machine_id',$measuring_machine_id)->orderBy('id','DESC')->first();
- if (!$package){
- $measuringMachine=MeasuringMachine::where('id',$measuring_machine_id)->first();
- $package=new Package();
- if ($measuringMachine)$package->measuringMachine=$measuringMachine;
- }
- }
- }
- return view('weight.measureMonitor.index',['package'=>isset($package)?$package:null,'measuringMachines'=>$measuringMachines]);
- }
- public function flush(Request $request){
- $measuring_machine_id=$request->input('id');
- if ($measuring_machine_id){
- $package=Package::with('owner','paperBox','measuringMachine')->where('measuring_machine_id',$measuring_machine_id)->orderBy('id','DESC')->first();
- if (!$package){
- $measuringMachine=MeasuringMachine::where('id',$measuring_machine_id)->first();
- $package=new Package();
- if ($measuringMachine)$package->measuringMachine=$measuringMachine;
- }
- return $package;
- }
- return false;
- }
- public function speech(){
- $client=new \AipSpeech(self::APP_ID,self::API_KEY,self::SECRET_KEY);
- $client->setConnectionTimeoutInMillis('180000');
- $client->setSocketTimeoutInMillis('180000');
- $result = $client->synthesis('你好百度', 'zh', 1, array(
- 'vol' => 5,
- ));
- // 识别正确返回语音二进制 错误则返回json 参照下面错误码
- if(!is_array($result)){
- file_put_contents('audio.mp3', $result);
- }
- }
- /**
- * Store a newly created resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function store(Request $request)
- {
- //
- }
- /**
- * Display the specified resource.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function show($id)
- {
- //
- }
- /**
- * Show the form for editing the specified resource.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function edit($id)
- {
- //
- }
- /**
- * Update the specified resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function update(Request $request, $id)
- {
- //
- }
- /**
- * Remove the specified resource from storage.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function destroy($id)
- {
- //
- }
- }
|