|
|
@@ -7,7 +7,6 @@ use App\CarType;
|
|
|
use App\Components\AsyncResponse;
|
|
|
use App\Region;
|
|
|
use App\Services\CarTypeService;
|
|
|
-use App\Services\common\ExportService;
|
|
|
use App\Services\LogisticService;
|
|
|
use App\Services\OwnerService;
|
|
|
use App\Services\UnitService;
|
|
|
@@ -24,7 +23,6 @@ use App\WaybillPayoff;
|
|
|
use App\WaybillFinancialExcepted;
|
|
|
use App\WaybillFinancialSnapshot;
|
|
|
use Carbon\Carbon;
|
|
|
-use Exception;
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
@@ -32,7 +30,6 @@ use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
-use Illuminate\Support\Facades\Http;
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
use Intervention\Image\Facades\Image;
|
|
|
@@ -493,51 +490,47 @@ class WaybillController extends Controller
|
|
|
}
|
|
|
|
|
|
public function upload(Request $request){
|
|
|
- if(!Gate::allows('运输管理-运单-图片上传')){ return '没有权限'; }
|
|
|
- $file=$request->file('file');
|
|
|
- $waybill_number=$request->input('waybill_number');
|
|
|
- $waybill=Waybill::query()->where('waybill_number',$waybill_number)->first();
|
|
|
- if (!$waybill){
|
|
|
- return ['success'=>false,'error'=>"未找到该运单!"];
|
|
|
- }
|
|
|
- if ($waybill->upload_file_url){
|
|
|
- return ['success'=>false,'error'=>"该运单已存在照片!"];
|
|
|
- }
|
|
|
- if (!$file){
|
|
|
- return ['success'=>false,'error'=>"照片不得为空!"];
|
|
|
- }
|
|
|
- if (!$file->isValid()){
|
|
|
- return ['success'=>false,'error'=>"找不到照片!"];
|
|
|
- }
|
|
|
- $tmpFile = $file->getRealPath();
|
|
|
- if (! is_uploaded_file($tmpFile)) {
|
|
|
- return ['success'=>false,'error'=>"文件错误!"];
|
|
|
- }
|
|
|
- $fileExtension=$file->getClientOriginalExtension();
|
|
|
- // 5.存储, 生成一个随机文件名
|
|
|
- $fileName = date('ymd').'-'.Uuid::uuid1();//thumbnail common bulky
|
|
|
- $thumbnailName=storage_path('app/public/files/'.$fileName.'-thumbnail.'.$fileExtension);
|
|
|
- $commonName=storage_path('app/public/files/'.$fileName.'-common.'.$fileExtension);
|
|
|
- $bulkyName=storage_path('app/public/files/'.$fileName.'-bulky.'.$fileExtension);
|
|
|
- $result=move_uploaded_file ($tmpFile ,$bulkyName);
|
|
|
- if ($result){
|
|
|
- $img=Image::make($bulkyName);
|
|
|
- if ($img->height() > $img->width())
|
|
|
- $img->heighten(250)->save($commonName);
|
|
|
- else $img->widen(250)->save($commonName);
|
|
|
- $img->heighten(28)->save($thumbnailName);
|
|
|
- $uploadFile=new UploadFile([
|
|
|
- "table_name"=>"waybills",
|
|
|
- "table_id"=>$waybill->id,
|
|
|
- "url"=>'/files/'.$fileName,
|
|
|
- "type"=>$fileExtension,
|
|
|
- ]);
|
|
|
- if ($uploadFile->save())
|
|
|
- app('LogService')->log(__METHOD__,'图片上传',json_encode($request),Auth::user()['id']);
|
|
|
- $uploadFile->url=asset('/storage'.$uploadFile->url);
|
|
|
- return ['success'=>true,'data'=>$uploadFile];
|
|
|
+ $this->gate("运输管理-运单-图片上传");
|
|
|
+ $files=$request->file("files");
|
|
|
+ if (!$files)$this->error("未传递照片");
|
|
|
+ $id=$request->input('id');
|
|
|
+ $waybill=Waybill::query()->find($id);
|
|
|
+ if (!$waybill)$this->error("未找到该运单!");
|
|
|
+ $res = [];
|
|
|
+ foreach ($files as $file){
|
|
|
+ if (!$file->isValid()){
|
|
|
+ return ['success'=>false,'error'=>"找不到照片!"];
|
|
|
+ }
|
|
|
+ $tmpFile = $file->getRealPath();
|
|
|
+ if (! is_uploaded_file($tmpFile)) {
|
|
|
+ return ['success'=>false,'error'=>"文件错误!"];
|
|
|
+ }
|
|
|
+ $fileExtension=$file->getClientOriginalExtension();
|
|
|
+ // 5.存储, 生成一个随机文件名
|
|
|
+ $fileName = date('ymd').'-'.Uuid::uuid1();//thumbnail common bulky
|
|
|
+ $thumbnailName=storage_path('app/public/files/'.$fileName.'-thumbnail.'.$fileExtension);
|
|
|
+ $commonName=storage_path('app/public/files/'.$fileName.'-common.'.$fileExtension);
|
|
|
+ $bulkyName=storage_path('app/public/files/'.$fileName.'-bulky.'.$fileExtension);
|
|
|
+ $result=move_uploaded_file ($tmpFile ,$bulkyName);
|
|
|
+ if ($result){
|
|
|
+ $img=Image::make($bulkyName);
|
|
|
+ if ($img->height() > $img->width())
|
|
|
+ $img->heighten(250)->save($commonName);
|
|
|
+ else $img->widen(250)->save($commonName);
|
|
|
+ $img->heighten(28)->save($thumbnailName);
|
|
|
+ /** @var UploadFile|\stdClass $uploadFile */
|
|
|
+ $uploadFile=new UploadFile([
|
|
|
+ "table_name"=>"waybills",
|
|
|
+ "table_id"=>$waybill->id,
|
|
|
+ "url"=>'/files/'.$fileName,
|
|
|
+ "type"=>$fileExtension,
|
|
|
+ ]);
|
|
|
+ if ($uploadFile->save())
|
|
|
+ app('LogService')->log(__CLASS__,'运输图片上传',json_encode($request),Auth::user()['id']);
|
|
|
+ $res[] = $uploadFile;
|
|
|
+ }else $this->error("图片存储失败,检查服务器状态");
|
|
|
}
|
|
|
- return ['success'=>false,'error'=>"图片保存失败!"];
|
|
|
+ $this->success($res);
|
|
|
}
|
|
|
|
|
|
//批量上传图片
|
|
|
@@ -566,9 +559,9 @@ class WaybillController extends Controller
|
|
|
$number[] = $num;
|
|
|
$mapping[$num] = $index;
|
|
|
}
|
|
|
- $waybills = Waybill::query()->select("id","source_bill")->doesntHave("uploadFile")->whereIn('source_bill',$number)->get();
|
|
|
+ $waybills = Waybill::query()->select("id","source_bill")->whereIn('source_bill',$number)->get();
|
|
|
foreach (array_diff($number,array_column($waybills->toArray(),"source_bill")) as $diff){
|
|
|
- $errors[] = "“".$diff."”不存在运单或已存在照片";
|
|
|
+ $errors[] = "“".$diff."”不存在运单";
|
|
|
unset($images[$mapping[$diff]]);
|
|
|
}
|
|
|
$insert = [];
|
|
|
@@ -598,16 +591,17 @@ class WaybillController extends Controller
|
|
|
];
|
|
|
}
|
|
|
if ($insert)UploadFile::query()->insert($insert);
|
|
|
- $waybills->load("uploadFile");
|
|
|
+ $waybills->load("uploadFiles");
|
|
|
$this->success(["errors"=>$errors,"data"=>$waybills]);
|
|
|
}
|
|
|
|
|
|
//删除照片
|
|
|
public function deleteImg(Request $request){
|
|
|
- if(!Gate::allows('运输管理-运单-图片删除')){ return '没有权限'; }
|
|
|
- $ids=$request->input('ids');
|
|
|
- $uploadFiles=UploadFile::where('table_name','waybills')->whereIn('table_id',$ids)->get();
|
|
|
- foreach ($uploadFiles as $uploadFile){
|
|
|
+ $this->gate("运输管理-运单-图片删除");
|
|
|
+ $query=UploadFile::query()->where('table_name','waybills');
|
|
|
+ if ($request->input("url"))$query = $query->where('table_id',$request->input("id"))->where("url",$request->input("url"));
|
|
|
+ else $query = $query->whereIn('table_id',$request->input("id"));
|
|
|
+ foreach ($query->get() as $uploadFile){
|
|
|
$bulky=storage_path('app/public/'.$uploadFile->url.'-bulky.'.$uploadFile->type);
|
|
|
$common=storage_path('app/public/'.$uploadFile->url.'-common.'.$uploadFile->type);
|
|
|
$thumbnail=storage_path('app/public/'.$uploadFile->url.'-thumbnail.'.$uploadFile->type);
|
|
|
@@ -615,9 +609,9 @@ class WaybillController extends Controller
|
|
|
unlink($bulky);unlink($common);unlink($thumbnail);
|
|
|
}
|
|
|
}
|
|
|
- UploadFile::where('table_name','waybills')->whereIn('table_id',$ids)->delete();
|
|
|
+ $query->delete();
|
|
|
app('LogService')->log(__METHOD__,'图片删除',json_encode($request),Auth::user()['id']);
|
|
|
- return ['success'=>true];
|
|
|
+ $this->success();
|
|
|
}
|
|
|
|
|
|
public function export(){
|