|
|
@@ -5,7 +5,6 @@ namespace App\Http\Controllers;
|
|
|
|
|
|
use App\Components\AsyncResponse;
|
|
|
use App\Services\CarTypeService;
|
|
|
-use App\Services\CityService;
|
|
|
use App\Services\LogisticService;
|
|
|
use App\Services\OwnerService;
|
|
|
use App\Services\UnitService;
|
|
|
@@ -17,7 +16,6 @@ use App\WaybillAuditLog;
|
|
|
use App\WaybillOnTop;
|
|
|
use App\WaybillPriceModel;
|
|
|
use App\City;
|
|
|
-use App\Owner;
|
|
|
use App\Unit;
|
|
|
use App\Waybill;
|
|
|
use App\WaybillPayoff;
|
|
|
@@ -28,11 +26,11 @@ use Exception;
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
use Illuminate\Http\Request;
|
|
|
-use Illuminate\Http\UploadedFile;
|
|
|
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;
|
|
|
use Ramsey\Uuid\Uuid;
|
|
|
@@ -78,26 +76,32 @@ class WaybillController extends Controller
|
|
|
public function store(Request $request)
|
|
|
{
|
|
|
if(!Gate::allows('运输管理-录入')){ return redirect(url('/')); }
|
|
|
- $id=false;
|
|
|
- $this->validatorWaybill($request,$id)->validate();
|
|
|
+ $this->validatorWaybill($request,false)->validate();
|
|
|
/** @var WaybillService */
|
|
|
$waybill=app('waybillService')->store($request);
|
|
|
app('LogService')->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
|
|
|
return redirect('waybill/index')->with('successTip','新运单“'.$waybill->waybill_number.'”录入成功');
|
|
|
}
|
|
|
|
|
|
- public function edit($id,LogisticService $logisticService,CarTypeService $carTypeService,
|
|
|
- CityService $cityService,UnitService $unitService)
|
|
|
+ public function edit($id,LogisticService $logisticService,CarTypeService $carTypeService,UnitService $unitService)
|
|
|
{
|
|
|
if(!Gate::allows('运输管理-编辑')){ return redirect(url('/')); }
|
|
|
- /** @var WaybillService */
|
|
|
$waybill = app('waybillService')->find($id);
|
|
|
+ if ($waybill->order_id){
|
|
|
+ /** @var Waybill $waybill */
|
|
|
+ $waybill->load("order.owner");
|
|
|
+ $waybill->destination_city_id = app("RegionService")->getCity($waybill->order->city ?? '',$waybill->order->province ?? '');
|
|
|
+ }else{
|
|
|
+ /** @var Waybill $waybill */
|
|
|
+ $waybill->load("owner");
|
|
|
+ }
|
|
|
+ /** @var \stdClass $waybill */
|
|
|
if (!$waybill)return view("exception.default",["code"=>"500","message"=>"数据已被删除或丢失"]);
|
|
|
if ($waybill->deliver_at){
|
|
|
$waybill->deliver_at_date=Carbon::parse($waybill->deliver_at)->format('Y-m-d');
|
|
|
$waybill->deliver_at_time=Carbon::parse($waybill->deliver_at)->format('H:i:s');
|
|
|
}
|
|
|
- $cities=$cityService->getSelection();
|
|
|
+ $cities=app("RegionService")->getSelection(2);
|
|
|
$units=$unitService->getSelection();
|
|
|
$carTypes=$carTypeService->getSelection();
|
|
|
return view('waybill/edit',['waybill'=>$waybill,'logistics'=>$logisticService->getSelection(["id","name"],"物流"),'cities'=>$cities,'units'=>$units,'carTypes'=>$carTypes]);
|
|
|
@@ -133,7 +137,7 @@ class WaybillController extends Controller
|
|
|
if ($waybillPriceModel_id){
|
|
|
$carrier_weight=$request->input('carrier_weight');
|
|
|
$waybillPriceModel=$waybillPriceModelService->find($waybillPriceModel_id);
|
|
|
- $logistic=$logisticService->find($waybill->logistic_id);
|
|
|
+ $logistic=$logisticService->find($waybill->order->logistic_id ?? $waybill->logistic_id);
|
|
|
if ($carrier_weight<$waybillPriceModel->initial_weight){
|
|
|
$fee=(($waybillPriceModel->unit_price)*($waybillPriceModel->initial_weight))+$logistic->delivery_fee;
|
|
|
}else{
|
|
|
@@ -367,14 +371,14 @@ class WaybillController extends Controller
|
|
|
public function waybillEdit($id){
|
|
|
if(!Gate::allows('运输管理-编辑')){ return redirect(url('/')); }
|
|
|
$waybill=app('waybillService')->find($id);
|
|
|
- $owners=Owner::get();
|
|
|
+ $owners=app("OwnerService")->getIntersectPermitting();
|
|
|
return view('waybill.waybillEdit',['waybill'=>$waybill,'owners'=>$owners]);
|
|
|
}
|
|
|
public function waybillRetreatAudit(Request $request){
|
|
|
if(!Gate::allows('运输管理-调度')){ return redirect(url('/')); }
|
|
|
$id=$request->input('id');
|
|
|
$waybill=app('waybillService')->find($id);
|
|
|
- WaybillAuditLog::whereRaw('waybill_id = ? and audit_stage = ?',[$id,"运单阶段"])->delete();
|
|
|
+ WaybillAuditLog::query()->whereRaw('waybill_id = ? and audit_stage = ?',[$id,"运单阶段"])->delete();
|
|
|
$waybill->status='待重审';
|
|
|
$result=$waybill->save();
|
|
|
app('LogService')->log(__METHOD__,__FUNCTION__,json_encode($waybill),Auth::user()['id']);
|
|
|
@@ -429,23 +433,25 @@ class WaybillController extends Controller
|
|
|
|
|
|
//生成报表数据
|
|
|
private function createReportData($waybill,$waybillPayoff){
|
|
|
+ /** @var Waybill $waybill */
|
|
|
+ $waybill->loadMissing(["order.owner",'order.logistic']);
|
|
|
return [
|
|
|
"type"=>$waybill->type,
|
|
|
"waybill_number"=>$waybill->waybill_number,
|
|
|
- "owner_name"=>$waybill->owner ? $waybill->owner->name : null,
|
|
|
+ "owner_name"=>$waybill->order->owner->name ?? ($waybill->owner->name ?? null),
|
|
|
"wms_bill_number"=>$waybill->wms_bill_number,
|
|
|
"source_bill"=>$waybill->source_bill,
|
|
|
"origination"=>$waybill->origination,
|
|
|
- "destination"=>$waybill->destination,
|
|
|
- "recipient"=>$waybill->recipient,
|
|
|
- "recipient_mobile"=>$waybill->recipient_mobile,
|
|
|
+ "destination"=>$waybill->order->address ?? $waybill->destination,
|
|
|
+ "recipient"=>$waybill->order->consignee_name ?? $waybill->recipient,
|
|
|
+ "recipient_mobile"=>$waybill->order->consignee_phone ?? $waybill->recipient_mobile,
|
|
|
"charge"=>$waybill->charge,
|
|
|
"collect_fee"=>$waybill->collect_fee,
|
|
|
"ordering_remark"=>$waybill->ordering_remark,
|
|
|
- "carrier_name"=>$waybill->logistic ? $waybill->logistic->name : null,
|
|
|
+ "carrier_name"=>$waybill->order->logistic->name ?? ($waybill->logistic->name ?? null),
|
|
|
"carrier_bill"=>$waybill->carrier_bill,
|
|
|
"origination_city_name"=>$waybill->originationCity ? $waybill->originationCity->name : null,
|
|
|
- "destination_city_name"=>$waybill->destinationCity ? $waybill->destinationCity->name : null,
|
|
|
+ "destination_city_name"=>$waybill->order->city ?? ($waybill->destinationCity->name ?? null),
|
|
|
"warehouse_weight"=>$waybill->warehouse_weight.($waybill->warehouseWeightUnit ? $waybill->warehouseWeightUnit->name : ''),
|
|
|
"carrier_weight"=>$waybill->carrier_weight.($waybill->carrierWeightUnit ? $waybill->carrierWeightUnit->name : ''),
|
|
|
"warehouse_weight_other"=>$waybill->warehouse_weight_other.($waybill->warehouseWeightUnitOther ? $waybill->warehouseWeightUnitOther->name : ''),
|
|
|
@@ -529,19 +535,24 @@ class WaybillController extends Controller
|
|
|
public function batchUploadImages()
|
|
|
{
|
|
|
$this->gate("运输管理-图片上传");
|
|
|
+ ini_set('max_execution_time',1000);
|
|
|
+ ini_set('memory_limit','100M');
|
|
|
$images = request("images");
|
|
|
$errors = [];
|
|
|
$number = [];
|
|
|
$mapping = [];
|
|
|
$type = ["jpg","png","gif","jfif","pjpeg","jpeg","webp"];
|
|
|
foreach ($images as $index => $image){
|
|
|
- $suffix = $image->getClientOriginalExtension();
|
|
|
- $name = $image->getClientOriginalName();
|
|
|
+ $arr = explode(".",$image["name"]);
|
|
|
+ $suffix = $arr[count($arr)-1];
|
|
|
+ unset($arr[count($arr)-1]);
|
|
|
+ $name = implode(".",$arr);
|
|
|
if (array_search(strtolower($suffix),$type) === false){
|
|
|
$errors[] = "“".$name."”格式错误";
|
|
|
unset($images[$index]);
|
|
|
continue;
|
|
|
}
|
|
|
+ $images[$index]["suffix"] = $suffix;
|
|
|
$num = trim(rtrim($name,".".$suffix));
|
|
|
$number[] = $num;
|
|
|
$mapping[$num] = $index;
|
|
|
@@ -555,11 +566,16 @@ class WaybillController extends Controller
|
|
|
foreach ($waybills as $waybill){
|
|
|
$image = $images[$mapping[$waybill->source_bill]];
|
|
|
$fileName = date('ymd').'-'.Uuid::uuid1();
|
|
|
- $suffix = $image->getClientOriginalExtension();
|
|
|
+ $suffix = $image["suffix"];
|
|
|
+
|
|
|
$thumbnailName=storage_path('app/public/files/'.$fileName.'-thumbnail.'.$suffix);
|
|
|
$commonName=storage_path('app/public/files/'.$fileName.'-common.'.$suffix);
|
|
|
$bulkyName=storage_path('app/public/files/'.$fileName.'-bulky.'.$suffix);
|
|
|
- move_uploaded_file ($image->getRealPath() ,$bulkyName);
|
|
|
+
|
|
|
+ preg_match('/^(data:\s*image\/(\w+);base64,)/',$image["src"],$res);
|
|
|
+ $base64_img=base64_decode(str_replace($res[1],'', $image["src"]));
|
|
|
+ Storage::put('public/files/'.$fileName.'-bulky.'.$suffix,$base64_img);
|
|
|
+
|
|
|
$img=Image::make($bulkyName);
|
|
|
if ($img->height() > $img->width())
|
|
|
$img->heighten(250)->save($commonName);
|
|
|
@@ -674,16 +690,17 @@ class WaybillController extends Controller
|
|
|
protected function validatorWaybill(Request $request,$id){
|
|
|
if ($id){$wms_bill_number=$id;};
|
|
|
$validator=Validator::make($request->input(),[
|
|
|
- 'owner_id'=>'required',
|
|
|
+ 'owner_id'=>'required_without:order_id',
|
|
|
'wms_bill_number'=>['nullable','max:50',isset($wms_bill_number)?"unique:waybills,wms_bill_number,$wms_bill_number":'unique:waybills,wms_bill_number'],
|
|
|
'origination'=>'required|max:255',
|
|
|
- 'destination'=>'required|max:255',
|
|
|
- 'recipient'=>'required|max:50',
|
|
|
- 'recipient_mobile'=>['required','regex:/^(\d{7,11})|(1[3|4|5|7|8][0-9]\d{4,8})$/'],
|
|
|
+ 'destination'=>'required_without:order_id|max:255',
|
|
|
+ 'recipient'=>'required_without:order_id|max:50',
|
|
|
+ 'recipient_mobile'=>['required_without:order_id','regex:/^(\d{7,11})|(1[3|4|5|7|8][0-9]\d{4,8})$/'],
|
|
|
'charge'=>'nullable|min:0|max:999999|numeric',
|
|
|
'collect_fee'=>'nullable|min:0|numeric',
|
|
|
],[
|
|
|
'required'=>':attribute 为必填项',
|
|
|
+ 'required_without'=>':attribute 为必填项',
|
|
|
'alpha_num'=>':attribute 应为字母或数字',
|
|
|
'max'=>':attribute 字符过多或输入值过大',
|
|
|
'regex'=>':attribute 输入有误',
|
|
|
@@ -705,7 +722,7 @@ class WaybillController extends Controller
|
|
|
}
|
|
|
protected function validatorWaybillDispatch(Request $request,$id){
|
|
|
$rule=[
|
|
|
- 'logistic_id'=>'required|integer',
|
|
|
+ 'logistic_id'=>'required_without:order_id|integer',
|
|
|
'carrier_bill'=>"sometimes|nullable|max:50|unique:waybills,carrier_bill,$id",
|
|
|
'fee'=>'sometimes|nullable|min:0|numeric|max:999999',
|
|
|
'other_fee'=>'sometimes|nullable|min:0|numeric|max:999999',
|
|
|
@@ -714,7 +731,7 @@ class WaybillController extends Controller
|
|
|
'amount'=>'nullable|numeric|min:0',
|
|
|
'amount_unit_id'=>'required',
|
|
|
'origination_city_id'=>'sometimes|required|integer',
|
|
|
- 'destination_city_id'=>'sometimes|required|integer',
|
|
|
+ 'destination_city_id'=>'sometimes|required_without:order_id|integer',
|
|
|
'warehouse_weight_other'=>'sometimes|nullable|min:0|numeric|max:999999',
|
|
|
'warehouse_weight_unit_id_other'=>'sometimes|required_with:warehouse_weight_other|nullable|integer',
|
|
|
'pick_up_fee'=>'sometimes|nullable|min:0|numeric|max:999999',
|
|
|
@@ -727,10 +744,11 @@ class WaybillController extends Controller
|
|
|
];
|
|
|
if ($request->type == '专线'){
|
|
|
$rule['origination_city_id']='required|integer';
|
|
|
- $rule['destination_city_id']='required|integer';
|
|
|
+ $rule['destination_city_id']='required_without:order_id|integer';
|
|
|
}
|
|
|
$validator=Validator::make($request->input(),$rule,[
|
|
|
'required'=>':attribute 为必填项',
|
|
|
+ 'required_without'=>':attribute 为必填项',
|
|
|
'alpha_num'=>':attribute 应为字母或数字',
|
|
|
'max'=>':attribute 字符过多或输入值过大',
|
|
|
'min'=>':attribute 不得为负',
|
|
|
@@ -795,7 +813,7 @@ class WaybillController extends Controller
|
|
|
if(!Gate::allows('运输管理-删除')){return redirect('/');}
|
|
|
$paginate = $request->input('paginate')??50;
|
|
|
/** @var Collection $waybills */
|
|
|
- $waybills = Waybill::query()->with(['owner','logistic','amountUnit','warehouseWeightUnit','carrierWeightUnit',
|
|
|
+ $waybills = Waybill::query()->with(['owner','order.owner','order.logistic','logistic','amountUnit','warehouseWeightUnit','carrierWeightUnit',
|
|
|
'warehouseWeightUnitOther','carrierWeightUnitOther','carType','waybillAuditLogs' => function ($query) {
|
|
|
/** @var Builder $query */
|
|
|
$query->with('user');
|
|
|
@@ -894,4 +912,15 @@ class WaybillController extends Controller
|
|
|
return ['success'=>true,'warehouseWeight'=>$warehouseWeight];
|
|
|
}
|
|
|
|
|
|
+ //寻找订单
|
|
|
+ public function seekOrder()
|
|
|
+ {
|
|
|
+ $this->gate("运输管理");
|
|
|
+ $code = request("code");
|
|
|
+ if (!$code)$this->error("暂无绑定订单");
|
|
|
+ $order = app("OrderService")->first(["code"=>$code]);
|
|
|
+ if (!$order)$this->error("暂无绑定订单");
|
|
|
+ $this->success($order);
|
|
|
+ }
|
|
|
+
|
|
|
}
|