WaybillFinancialSnapshotsController.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Exports\Export;
  4. use App\WaybillFinancialSnapshot;
  5. use Carbon\Carbon;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\Auth;
  8. use Illuminate\Support\Facades\Gate;
  9. use Illuminate\Support\Facades\Http;
  10. use Maatwebsite\Excel\Facades\Excel;
  11. class WaybillFinancialSnapshotsController extends Controller
  12. {
  13. public function conditionQuery(Request $request,$waybillFinancialSnapshots){
  14. if ($request->input('created_at_start')){
  15. $created_at_start=$request->input('created_at_start')." 00:00:00";
  16. $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','>=',$created_at_start);
  17. }
  18. if ($request->input('created_at_end')){
  19. $created_at_end=$request->input('created_at_end')." 23:59:59";
  20. $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','<=',$created_at_end);
  21. }
  22. $waybillFinancialSnapshots=$waybillFinancialSnapshots->paginate(50);
  23. return $waybillFinancialSnapshots;
  24. }
  25. public function index(Request $request)
  26. {
  27. if(!Gate::allows('财务报表-查询')){ return redirect(url('/')); }
  28. $waybillFinancialSnapshots=WaybillFinancialSnapshot::query()->orderBy('id', 'DESC');
  29. $type='';
  30. if ($request->type=='ZF'){
  31. $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('json_content','like','%直发车%');
  32. $type='ZF';
  33. }
  34. if ($request->type=='ZX'){
  35. $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('json_content','like','%专线%');
  36. $type='ZX';
  37. }
  38. $waybillFinancialSnapshots=$this->conditionQuery($request,$waybillFinancialSnapshots);
  39. return view('waybill.waybillFinancialSnapshot.index',['waybillFinancialSnapshots'=>$waybillFinancialSnapshots,'filterData'=>$request->input(),'type'=>$type]);
  40. }
  41. public function export(Request $request){
  42. if(!Gate::allows('财务报表-查询')){ return '没有权限'; }
  43. if ($request->checkAllSign){
  44. $param = $request->input();
  45. unset($param['checkAllSign']);
  46. $sql = app('waybillFinancialService')->getSql($param);
  47. }else{
  48. $sql = app('waybillFinancialService')->getSql(['waybill_id'=>$request->data]);
  49. }
  50. return response(Http::post(config('go.export.url'),['type'=>'waybillFinancial','sql'=>$sql]),200, [
  51. "Content-type"=>"application/octet-stream",
  52. "Content-Disposition"=>"attachment; filename=财务报表-".date('ymdHis').'.xlsx',
  53. ]);
  54. }
  55. }