|
@@ -3,6 +3,9 @@
|
|
|
namespace App\Http\Controllers;
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+use App\Services\CarrierService;
|
|
|
|
|
+use App\Services\OwnerService;
|
|
|
|
|
+use App\Services\WaybillService;
|
|
|
use App\UploadFile;
|
|
use App\UploadFile;
|
|
|
use App\WaybillAuditLog;
|
|
use App\WaybillAuditLog;
|
|
|
use App\WaybillOnTop;
|
|
use App\WaybillOnTop;
|
|
@@ -29,108 +32,37 @@ use Ramsey\Uuid\Uuid;
|
|
|
|
|
|
|
|
class WaybillsController extends Controller
|
|
class WaybillsController extends Controller
|
|
|
{
|
|
{
|
|
|
- //超15天精确查询抽离 column前提:数据库字段名必须与request内字段名一致
|
|
|
|
|
- public function preciseQuery(string $column,Request $request,$waybills){
|
|
|
|
|
- $today=Carbon::now()->subDays(15);
|
|
|
|
|
- $waybillsTem=clone $waybills;
|
|
|
|
|
- $waybillsTem=$waybillsTem->where($column,'like','%'.$request->input($column).'%')->where('waybills.created_at','>',$today->format('Y-m-d'));
|
|
|
|
|
- if($waybillsTem->count()==0
|
|
|
|
|
- ||$waybillsTem->get()[0][$column]==$request->input($column)){
|
|
|
|
|
- $waybills=$waybills->where($column,$request->input($column));
|
|
|
|
|
- }else{
|
|
|
|
|
- $waybills=$waybillsTem;
|
|
|
|
|
- }
|
|
|
|
|
- return $waybills;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public function conditionQuery(Request $request,$waybills){
|
|
|
|
|
- if ($request->input('exportType')&&$request->input('exportType')==1){
|
|
|
|
|
- $checkData=explode(',',$request->input('checkData'));
|
|
|
|
|
- $waybills=$waybills->whereIn("id",$checkData)->get();
|
|
|
|
|
- $excel=$this->deliveringExport($waybills);
|
|
|
|
|
- return $excel;
|
|
|
|
|
- }
|
|
|
|
|
- if ($request->input('waybill_number')){
|
|
|
|
|
- $waybills=$this->preciseQuery("waybill_number",$request,$waybills);
|
|
|
|
|
- }
|
|
|
|
|
- if ($request->input('carrier_bill')){
|
|
|
|
|
- $waybills=$this->preciseQuery("carrier_bill",$request,$waybills);
|
|
|
|
|
- }
|
|
|
|
|
- if ($request->input('carrier_id')){
|
|
|
|
|
- $waybills=$waybills->where('carrier_id','=',$request->input('carrier_id'));
|
|
|
|
|
- }
|
|
|
|
|
- if ($request->input('owners')){
|
|
|
|
|
- $owners=array_values(json_decode($request->input('owners'),true));
|
|
|
|
|
- if (count($owners)>0)$waybills=$waybills->whereIn('owner_id',$owners);
|
|
|
|
|
- }
|
|
|
|
|
- if ($request->input('owner_id')){
|
|
|
|
|
- $waybills=$waybills->where('owner_id','=',$request->input('owner_id'));
|
|
|
|
|
- }
|
|
|
|
|
- if ($request->input('wms_bill_number')){
|
|
|
|
|
- $waybills=$this->preciseQuery("wms_bill_number",$request,$waybills);
|
|
|
|
|
- }
|
|
|
|
|
- if ($request->input('origination')){
|
|
|
|
|
- $waybills=$this->preciseQuery("origination",$request,$waybills);
|
|
|
|
|
- }
|
|
|
|
|
- if ($request->input('destination')){
|
|
|
|
|
- $waybills=$this->preciseQuery("destination",$request,$waybills);
|
|
|
|
|
- }
|
|
|
|
|
- if ($request->input('created_at_start')){
|
|
|
|
|
- $created_at_start=$request->input('created_at_start')." 00:00:00";
|
|
|
|
|
- $waybills=$waybills->where('created_at','>=',$created_at_start);
|
|
|
|
|
- }
|
|
|
|
|
- if ($request->input('created_at_end')){
|
|
|
|
|
- $created_at_end=$request->input('created_at_end')." 23:59:59";
|
|
|
|
|
- $waybills=$waybills->where('created_at','<=',$created_at_end);
|
|
|
|
|
- }
|
|
|
|
|
- if ($request->input('status')){
|
|
|
|
|
- $waybills=$waybills->where('status',$request->input('status'));
|
|
|
|
|
- }
|
|
|
|
|
- if ($request->input('exportType')&&$request->input('exportType')==2){
|
|
|
|
|
- $waybills=$waybills->get();
|
|
|
|
|
- $excel=$this->deliveringExport($waybills);
|
|
|
|
|
- return $excel;
|
|
|
|
|
- }
|
|
|
|
|
- if ($request->uriType=='ZF')$waybills=$waybills->where('type','直发车');
|
|
|
|
|
- if ($request->uriType=='ZX')$waybills=$waybills->where('type','专线');
|
|
|
|
|
- return $waybills;
|
|
|
|
|
|
|
+ public function __construct()
|
|
|
|
|
+ {
|
|
|
|
|
+ app()->singleton('waybillService',WaybillService::class);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function index(Request $request)
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @param Request $request
|
|
|
|
|
+ * @param OwnerService $ownerService
|
|
|
|
|
+ * @param CarrierService $carrierService
|
|
|
|
|
+ * @return void
|
|
|
|
|
+ */
|
|
|
|
|
+ public function index(Request $request,OwnerService $ownerService,CarrierService $carrierService)
|
|
|
{
|
|
{
|
|
|
if(!Gate::allows('运输管理-查询')){ return redirect(url('/')); }
|
|
if(!Gate::allows('运输管理-查询')){ return redirect(url('/')); }
|
|
|
- $data=$request->input();
|
|
|
|
|
- $carries = Carrier::get();
|
|
|
|
|
- $owners = Owner::filterAuthorities()->get();
|
|
|
|
|
- $ownerIds = $owners->map(function ($owner){
|
|
|
|
|
- return $owner['id'];
|
|
|
|
|
- })->all();
|
|
|
|
|
- $waybills = $this->getWaybills();
|
|
|
|
|
- $waybills=$waybills->whereIn('owner_id',$ownerIds);
|
|
|
|
|
- if ($data != null ) {
|
|
|
|
|
- $waybills=$this->conditionQuery($request,$waybills);
|
|
|
|
|
- if (!$waybills&&$request->input('waybill_number')){
|
|
|
|
|
- $waybills=Waybill::with(['owner', 'waybillAuditLogs' => function ($query) {
|
|
|
|
|
- return $query->with('user');
|
|
|
|
|
- }])->orderBy('id','DESC')->where('type','专线')
|
|
|
|
|
- ->where('waybill_number',$request->input('waybill_number'));
|
|
|
|
|
- }
|
|
|
|
|
- $waybills=$waybills->paginate($request->input('paginate')?$request->input('paginate'):50);
|
|
|
|
|
- } else {
|
|
|
|
|
- $waybills = $waybills->paginate(50);
|
|
|
|
|
- }
|
|
|
|
|
- return view('waybill.index', ['waybills' => $waybills, 'carriers' => $carries, 'owners' => $owners,'filterData'=>$data,'uriType'=>$request->uriType??'']);
|
|
|
|
|
|
|
+ $waybills=app('waybillService')->paginate($request);
|
|
|
|
|
+ return view('waybill.index', [
|
|
|
|
|
+ 'waybills' => $waybills,
|
|
|
|
|
+ 'carriers' => $carrierService->selectGet(),
|
|
|
|
|
+ 'owners' => $ownerService->selectGet(),
|
|
|
|
|
+ 'request'=>$request->input(),
|
|
|
|
|
+ 'uriType'=>$request->uriType??'']);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- public function create(Request $request)
|
|
|
|
|
|
|
+ public function create(Request $request,OwnerService $ownerService)
|
|
|
{
|
|
{
|
|
|
if(!Gate::allows('运输管理-录入')){ return redirect(url('/')); }
|
|
if(!Gate::allows('运输管理-录入')){ return redirect(url('/')); }
|
|
|
- $owners=Owner::get();
|
|
|
|
|
$type="";
|
|
$type="";
|
|
|
if ($request->type==='ZF')$type='直发车';
|
|
if ($request->type==='ZF')$type='直发车';
|
|
|
if ($request->type==='ZX')$type='专线';
|
|
if ($request->type==='ZX')$type='专线';
|
|
|
- return view('waybill.create',['owners'=>$owners,'type'=>$type]);
|
|
|
|
|
|
|
+ return view('waybill.create',['owners'=>$ownerService->selectGet(),'type'=>$type]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function store(Request $request)
|
|
public function store(Request $request)
|
|
@@ -189,16 +121,16 @@ class WaybillsController extends Controller
|
|
|
if(!Gate::allows('运输管理-调度')){ return redirect(url('/')); }
|
|
if(!Gate::allows('运输管理-调度')){ return redirect(url('/')); }
|
|
|
$waybill=Waybill::find($id);
|
|
$waybill=Waybill::find($id);
|
|
|
if (!$request->warehouse_weight && $request->warehouse_weight_unit_id){
|
|
if (!$request->warehouse_weight && $request->warehouse_weight_unit_id){
|
|
|
- unset($request->warehouse_weight_unit_id);
|
|
|
|
|
|
|
+ $request->offsetUnset('warehouse_weight_unit_id');
|
|
|
}
|
|
}
|
|
|
if (!$request->warehouse_weight_other && $request->warehouse_weight_unit_id_other){
|
|
if (!$request->warehouse_weight_other && $request->warehouse_weight_unit_id_other){
|
|
|
- unset($request->warehouse_weight_unit_id_other);
|
|
|
|
|
|
|
+ $request->offsetUnset('warehouse_weight_unit_id_other');
|
|
|
}
|
|
}
|
|
|
if (!$request->carrier_weight && $request->carrier_weight_unit_id){
|
|
if (!$request->carrier_weight && $request->carrier_weight_unit_id){
|
|
|
- unset($request->carrier_weight_unit_id);
|
|
|
|
|
|
|
+ $request->offsetUnset('carrier_weight_unit_id');
|
|
|
}
|
|
}
|
|
|
if (!$request->carrier_weight_other && $request->carrier_weight_unit_id_other){
|
|
if (!$request->carrier_weight_other && $request->carrier_weight_unit_id_other){
|
|
|
- unset($request->carrier_weight_unit_id_other);
|
|
|
|
|
|
|
+ $request->offsetUnset('carrier_weight_unit_id_other');
|
|
|
}
|
|
}
|
|
|
$this->validatorWaybillDispatch($request,$id)->validate();
|
|
$this->validatorWaybillDispatch($request,$id)->validate();
|
|
|
//替换换行符
|
|
//替换换行符
|
|
@@ -619,21 +551,16 @@ class WaybillsController extends Controller
|
|
|
return ['success'=>true];
|
|
return ['success'=>true];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function waybillExport(Request $request){
|
|
|
|
|
|
|
+ public function export(Request $request){
|
|
|
if(!Gate::allows('运输管理-查询')){ return '没有权限'; }
|
|
if(!Gate::allows('运输管理-查询')){ return '没有权限'; }
|
|
|
ini_set('max_execution_time',2500);
|
|
ini_set('max_execution_time',2500);
|
|
|
ini_set('memory_limit','1526M');
|
|
ini_set('memory_limit','1526M');
|
|
|
- $exportType=$request->exportType;
|
|
|
|
|
- $waybills=Waybill::with(['owner', 'waybillAuditLogs' => function ($query) {
|
|
|
|
|
- $query->with('user');
|
|
|
|
|
- }]);
|
|
|
|
|
- if ($exportType=='all'){
|
|
|
|
|
- $waybills=$this->conditionQuery($request,$waybills);
|
|
|
|
|
- $waybills=$waybills->get();
|
|
|
|
|
- }else {
|
|
|
|
|
- $id = explode( ',',$request->data);
|
|
|
|
|
- $waybills=$waybills->whereIn('id',$id)->get();
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ if ($request->checkAllSign){
|
|
|
|
|
+ $request->offsetUnset('checkAllSign');
|
|
|
|
|
+ $waybills = app('waybillService')->get($request);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ $waybills = app('waybillService')->some($request);
|
|
|
|
|
+ }
|
|
|
$row=[[
|
|
$row=[[
|
|
|
'type'=>'运单类型',
|
|
'type'=>'运单类型',
|
|
|
'owner'=>'货主',
|
|
'owner'=>'货主',
|
|
@@ -758,16 +685,12 @@ class WaybillsController extends Controller
|
|
|
//发运
|
|
//发运
|
|
|
public function delivering(Request $request){
|
|
public function delivering(Request $request){
|
|
|
if (!Auth::user())return view('exception.login');
|
|
if (!Auth::user())return view('exception.login');
|
|
|
- if (Auth::user()->isSuperAdmin())$waybills=Waybill::orderBy('id','DESC');
|
|
|
|
|
- else{
|
|
|
|
|
|
|
+ $waybills= app('waybillService')->paginate($request);
|
|
|
|
|
+ if (!Auth::user()->isSuperAdmin()){
|
|
|
$carriersUsers=DB::table('carrier_user')->where('user_id',Auth::id())->get();
|
|
$carriersUsers=DB::table('carrier_user')->where('user_id',Auth::id())->get();
|
|
|
$carrierIds=array_column($carriersUsers->toArray(),'carrier_id');
|
|
$carrierIds=array_column($carriersUsers->toArray(),'carrier_id');
|
|
|
- $waybills=Waybill::orderBy('id','DESC')->whereIn("carrier_id",$carrierIds);
|
|
|
|
|
- }
|
|
|
|
|
- if ($request->input('exportType')){
|
|
|
|
|
- return $this->conditionQuery($request,$waybills);
|
|
|
|
|
|
|
+ $waybills=$waybills->whereIn("carrier_id",$carrierIds);
|
|
|
}
|
|
}
|
|
|
- $waybills=$this->conditionQuery($request,$waybills);
|
|
|
|
|
return view('waybill.delivering',compact('waybills'));
|
|
return view('waybill.delivering',compact('waybills'));
|
|
|
}
|
|
}
|
|
|
//承运商提交
|
|
//承运商提交
|
|
@@ -995,17 +918,4 @@ class WaybillsController extends Controller
|
|
|
return ['success'=>$result,'status'=>$result];
|
|
return ['success'=>$result,'status'=>$result];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 获取所有运单信息
|
|
|
|
|
- public function getWaybills(){
|
|
|
|
|
- $waybills = Waybill::with(['owner','wmsCommodities','waybillAuditLogs' => function ($query) {
|
|
|
|
|
- return $query->with('user');
|
|
|
|
|
- }])
|
|
|
|
|
- ->selectRaw('waybills.* ,waybill_on_tops.id top_id ,waybill_on_tops.remark,waybill_on_tops.updated_at top_update,waybill_on_tops.created_at top_created_at')
|
|
|
|
|
- ->leftJoin('waybill_on_tops','waybill_on_tops.waybill_id','=','waybills.id')
|
|
|
|
|
- ->whereNull('waybill_on_tops.deleted_at')
|
|
|
|
|
- ->orderBy('waybill_on_tops.updated_at','desc')
|
|
|
|
|
- ->orderBy('waybills.id','desc');
|
|
|
|
|
- return $waybills;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|