|
|
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
|
|
|
|
|
use App\UploadFile;
|
|
|
use App\WaybillAuditLog;
|
|
|
+use App\WaybillOnTop;
|
|
|
use App\WaybillPriceModel;
|
|
|
use App\Carrier;
|
|
|
use App\CarType;
|
|
|
@@ -105,17 +106,13 @@ class WaybillsController extends Controller
|
|
|
if(!Gate::allows('运输管理-查询')){ return redirect(url('/')); }
|
|
|
$data=$request->input();
|
|
|
if ($data != null ) {
|
|
|
- $waybills=Waybill::with(['owner','wmsCommodities','waybillAuditLogs' => function ($query) {
|
|
|
- return $query->with('user');
|
|
|
- }])->orderBy('id','DESC');
|
|
|
+ $waybills = $this->getWaybills();
|
|
|
$waybills=$this->conditionQuery($request,$waybills);
|
|
|
$carries = Carrier::get();
|
|
|
$owners = Owner::get();
|
|
|
return view('waybill.index', ['waybills' => $waybills, 'carriers' => $carries, 'owners' => $owners,'filterData'=>$data,'uriType'=>'']);
|
|
|
} else {
|
|
|
- $waybills = Waybill::with(['owner','waybillAuditLogs' => function ($query) {
|
|
|
- return $query->with('user');
|
|
|
- }])->orderBy('id', 'DESC')->paginate(50);
|
|
|
+ $waybills = $this->getWaybills()->paginate(50);
|
|
|
$carries = Carrier::get();
|
|
|
$owners = Owner::get();
|
|
|
return view('waybill.index', ['waybills' => $waybills, 'carriers' => $carries, 'owners' => $owners,'filterData'=>$data,'uriType'=>'']);
|
|
|
@@ -126,17 +123,15 @@ class WaybillsController extends Controller
|
|
|
if(!Gate::allows('运输管理-查询')){ return redirect(url('/')); }
|
|
|
$data=$request->input();
|
|
|
if ($data != null ) {
|
|
|
- $waybills=Waybill::with(['owner','wmsCommodities', 'waybillAuditLogs' => function ($query) {
|
|
|
- return $query->with('user');
|
|
|
- }])->orderBy('id','DESC')->where('type','直发车');
|
|
|
+
|
|
|
+ $waybills = $this->getWaybills()->where('type','直发车');
|
|
|
+
|
|
|
$waybills=$this->conditionQuery($request,$waybills);
|
|
|
$carries = Carrier::get();
|
|
|
$owners = Owner::get();
|
|
|
return view('waybill.index', ['waybills' => $waybills, 'carriers' => $carries, 'owners' => $owners,'filterData'=>$data,'uriType'=>'ZF']);
|
|
|
} else {
|
|
|
- $waybills = Waybill::with(['owner','wmsCommodities', 'waybillAuditLogs' => function ($query) {
|
|
|
- return $query->with('user');
|
|
|
- }])->where('type','直发车')->orderBy('id', 'DESC')->paginate(50);
|
|
|
+ $waybills = $this->getWaybills()->where('type','直发车')->paginate(50);
|
|
|
$carries = Carrier::get();
|
|
|
$owners = Owner::get();
|
|
|
return view('waybill.index', ['waybills' => $waybills, 'carriers' => $carries, 'owners' => $owners,'filterData'=>$data,'uriType'=>'ZF']);
|
|
|
@@ -148,17 +143,14 @@ class WaybillsController extends Controller
|
|
|
if(!Gate::allows('运输管理-查询')){ return redirect(url('/')); }
|
|
|
$data=$request->input();
|
|
|
if ($data != null ) {
|
|
|
- $waybills=Waybill::with(['owner','wmsCommodities', 'waybillAuditLogs' => function ($query) {
|
|
|
- return $query->with('user');
|
|
|
- }])->orderBy('id','DESC')->where('type','专线');
|
|
|
+ $waybills = $this->getWaybills()->where('type','专线');
|
|
|
+
|
|
|
$waybills=$this->conditionQuery($request,$waybills);
|
|
|
$carries = Carrier::get();
|
|
|
$owners = Owner::get();
|
|
|
return view('waybill.index', ['waybills' => $waybills, 'carriers' => $carries, 'owners' => $owners,'filterData'=>$data,'uriType'=>'ZX']);
|
|
|
} else {
|
|
|
- $waybills = Waybill::with(['owner','wmsCommodities', 'waybillAuditLogs' => function ($query) {
|
|
|
- return $query->with('user');
|
|
|
- }])->where('type','专线')->orderBy('id', 'DESC')->paginate(50);
|
|
|
+ $waybills = $this->getWaybills()->where('type','专线')->paginate(50);
|
|
|
$carries = Carrier::get();
|
|
|
$owners = Owner::get();
|
|
|
return view('waybill.index', ['waybills' => $waybills, 'carriers' => $carries, 'owners' => $owners,'filterData'=>$data,'uriType'=>'ZX']);
|
|
|
@@ -884,7 +876,7 @@ class WaybillsController extends Controller
|
|
|
if ($request->input('type')=='直发车'){
|
|
|
$validator=Validator::make($request->input(),[
|
|
|
'carrier_bill'=>"nullable|max:50|unique:waybills,carrier_bill,$id",
|
|
|
- 'fee'=>'required|min:0|numeric|max:999999',
|
|
|
+ // 'fee'=>'required|min:0|numeric|max:999999',
|
|
|
'other_fee'=>'nullable|min:0|numeric|max:999999',
|
|
|
'charge'=>'nullable|min:0|numeric|max:999999',
|
|
|
'mileage'=>'nullable|numeric',
|
|
|
@@ -898,7 +890,7 @@ class WaybillsController extends Controller
|
|
|
'unique'=>':attribute 已存在',
|
|
|
],[
|
|
|
'carrier_bill'=>'承运商单号',
|
|
|
- 'fee'=>'运费',
|
|
|
+ //'fee'=>'运费',
|
|
|
'other_fee'=>'其他费用',
|
|
|
'charge'=>'收费',
|
|
|
'mileage'=>'里程数',
|
|
|
@@ -975,4 +967,95 @@ class WaybillsController extends Controller
|
|
|
$city->save();
|
|
|
return $city;
|
|
|
}
|
|
|
+
|
|
|
+ // 运单删除 软删除
|
|
|
+ public function destroy(int $id){
|
|
|
+ if(!GAte::allows('运输管理-删除')){return['success'=>0,'status'=>'没有权限'];}
|
|
|
+ if(is_null($id)){return ['success'=>'0','status'=>'传入id为空'];}
|
|
|
+ $result = Waybill::where('id',$id)->delete();
|
|
|
+ return ['success'=>$result,'status'=>$result];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 回收站
|
|
|
+ public function recycle(Request $request){
|
|
|
+ if(!Gate::allows('运输管理-删除')){return redirect('/');}
|
|
|
+ $user = Auth::user();
|
|
|
+ $paginate = $request->input('paginate')??50;
|
|
|
+ $waybills = Waybill::with(['owner','waybillAuditLogs' => function ($query) {
|
|
|
+ return $query->with('user');
|
|
|
+ }])->orderBy('deleted_at', 'DESC')->withTrashed()->whereNotNull('deleted_at')->paginate(50);
|
|
|
+ $total = $waybills->count();
|
|
|
+ $paginateParams = [];
|
|
|
+ $paginateParams['paginate'] = $paginate;
|
|
|
+ return view('waybill.recycle',compact('waybills','total','paginateParams'));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 软删除恢复
|
|
|
+ public function apiRestoreSelected(Request $request){
|
|
|
+ DB::enableQueryLog();
|
|
|
+ if(!Gate::allows('运输管理-删除')){return ['success'=>'false','fail_info'=>'没有权限'];}
|
|
|
+ $ids = $request->input('ids')??'';
|
|
|
+ if($ids == ''){return ['success'=>'false','fail_info'=>'没有可恢复对象'];}
|
|
|
+ $waybills = Waybill::withTrashed()->whereIn('id',$ids)->get();
|
|
|
+ $result = '';
|
|
|
+ $waybills->each(function (Waybill $waybill){
|
|
|
+ $waybill->restore();
|
|
|
+ });
|
|
|
+ $this->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
|
|
|
+ return ['success'=>'true','waybills'=>$waybills];
|
|
|
+ }
|
|
|
+ // 修改运费
|
|
|
+ public function changeFee(Request $request){
|
|
|
+ if(!Gate::allows('运输管理-运费')){return ['success'=>'false','fail_info'=>'没有权限'];}
|
|
|
+ $wayBillId = $request->input('id');
|
|
|
+ $waybillFee = $request->input('fee');
|
|
|
+ if(is_null($wayBillId) or is_null($waybillFee)){
|
|
|
+ return ['success'=>'false','fail_info'=>'参数异常'];
|
|
|
+ }
|
|
|
+ $result = Waybill::where('id',$wayBillId)->update(['fee'=>$waybillFee]);
|
|
|
+ $this->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
|
|
|
+ return ['success'=>$result,'status'=>$result];
|
|
|
+ }
|
|
|
+ // 置顶
|
|
|
+ public function waybillOnTop(Request $request){
|
|
|
+ $id = $request->input('id');
|
|
|
+ $detail = $request->input('detail');
|
|
|
+ if(!Gate::allows('运输管理-置顶')){return ['success'=>'false','fail_info'=>'没有权限'];}
|
|
|
+ if(is_null($id)){
|
|
|
+ return ['success'=>'false','fail_info'=>'传参错误'];
|
|
|
+ }
|
|
|
+ $wayontop = WaybillOnTop::withTrashed()->where('waybill_id',$id);
|
|
|
+ $result = '';
|
|
|
+ if(count($wayontop->get()) == 0){
|
|
|
+ $wayontop = WaybillOnTop::create(['waybill_id'=>$id,'remark'=>$detail]);
|
|
|
+ $result = $wayontop->save();
|
|
|
+ }else{
|
|
|
+ $wayontop = WaybillOnTop::withTrashed()->where('waybill_id',$id);
|
|
|
+ $result = WaybillOnTop::withTrashed()->where('waybill_id',$id)->restore();
|
|
|
+ }
|
|
|
+ return ['success'=>$result,'status'=>$result];
|
|
|
+ }
|
|
|
+ // 取消置顶
|
|
|
+ public function cancelOnTop(Request $request){
|
|
|
+ $id = $request->input('id');
|
|
|
+ if(!Gate::allows('运输管理-置顶')){return ['success'=>'false','fail_info'=>'没有权限'];}
|
|
|
+ if(is_null($id)){
|
|
|
+ return ['success'=>'false','fail_info'=>'传参错误'];
|
|
|
+ }
|
|
|
+ $result = WaybillOnTop::where('waybill_id',$id)->forceDelete();
|
|
|
+ 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')
|
|
|
+ ->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;
|
|
|
+ }
|
|
|
+
|
|
|
}
|