| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace App\Http\Controllers;
- use App\Exports\Export;
- use App\Package;
- use Exception;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\Gate;
- use Illuminate\Support\Facades\Http;
- use Maatwebsite\Excel\Facades\Excel;
- class WeighExceptedController extends Controller
- {
- /**
- * Display a listing of the resource.
- * @param Request $request
- * @return \Illuminate\Http\Response
- */
- public function indexCreate(Request $request)
- {
- if(!Gate::allows('称重管理-查看异常')){ return redirect(url('/')); }
- $paginate=$request->input('paginate');
- $weightExcepteds=Package::query()->select('id','status','logistic_number','logistic_id','measuring_machine_id','weighed_at','weight','length','width','height','bulk','paper_box_id')->
- where('status','上传异常')->orWhere('status','测量异常')->orderBy('created_at','DESC');
- if ($paginate){
- $weightExcepteds=$weightExcepteds->paginate($paginate);
- }else{
- $weightExcepteds=$weightExcepteds->paginate(50);
- };
- return view('weight.weightExcepted.index',['weightExcepteds'=>$weightExcepteds,'view'=>'indexCreate']);
- }
- public function indexIssued(Request $request)
- {
- if(!Gate::allows('称重管理-查看异常')){ return redirect(url('/')); }
- $paginate=$request->input('paginate');
- $weightExcepteds=Package::query()->select('id','owner_id','logistic_number','created_at','delivery_number','batch_number','batch_rule','recipient','recipient_mobile','logistic_id')->
- where('status','下发异常')->orWhere('status','记录异常')->orWhere('status','已上传异常')->orderBy('created_at','DESC');
- if ($paginate){
- $weightExcepteds=$weightExcepteds->paginate($paginate);
- }else{
- $weightExcepteds=$weightExcepteds->paginate(50);
- };
- return view('weight.weightExcepted.index',['weightExcepteds'=>$weightExcepteds,'view'=>'indexIssued']);
- }
- public function export($type ,Request $request){
- if(!Gate::allows('称重管理-查看异常')){ return redirect(url('/')); }
- if ($type == 'indexIssued'){
- if ($request->checkAllSign){
- $params = $request->input();
- unset($params['checkAllSign']);
- $sql = app('weighExceptedService')->getIssuedExceptionSql($params);
- }else $sql=app('weighExceptedService')->getIssuedExceptionSql(['id'=>$request->data]);
- $post = Http::post(config('go.export.url'),['type'=>'packageIssuedException','sql'=>$sql]);
- if ($post->status() == 500){
- throw new Exception($post->header("Msg"));
- }
- return response($post,200, [
- "Content-type"=>"application/octet-stream",
- "Content-Disposition"=>"attachment; filename=下发异常记录-".date('ymdHis').'.xlsx',
- ]);
- }else{
- if ($request->checkAllSign){
- $params = $request->input();
- unset($params['checkAllSign']);
- $sql = app('weighExceptedService')->getCreateExceptionSql($params);
- }else $sql=app('weighExceptedService')->getCreateExceptionSql(['id'=>$request->data]);
- $post = Http::post(config('go.export.url'),['type'=>'packageCreateException','sql'=>$sql]);
- if ($post->status() == 500){
- throw new Exception($post->header("Msg"));
- }
- return response($post,200, [
- "Content-type"=>"application/octet-stream",
- "Content-Disposition"=>"attachment; filename=录入异常记录-".date('ymdHis').'.xlsx',
- ]);
- }
- }
- }
|