WaybillFinancialSnapshotsController.php 2.7 KB

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