|
|
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
|
|
|
|
|
use App\CarType;
|
|
|
use App\Components\AsyncResponse;
|
|
|
+use App\Http\Requests\GateRequest;
|
|
|
use App\Owner;
|
|
|
use App\Region;
|
|
|
use App\Services\CarTypeService;
|
|
|
@@ -15,7 +16,6 @@ use App\Services\UnitService;
|
|
|
use App\Services\WaybillPayoffService;
|
|
|
use App\Services\WaybillPriceModelService;
|
|
|
use App\Services\WaybillService;
|
|
|
-use App\Traits\ModelLogChanging;
|
|
|
use App\TerminalPrinter;
|
|
|
use App\UploadFile;
|
|
|
use App\WaybillAuditLog;
|
|
|
@@ -36,6 +36,8 @@ use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
+use Illuminate\Validation\ValidationException;
|
|
|
+use Illuminate\View\View;
|
|
|
use Intervention\Image\Facades\Image;
|
|
|
use Oursdreams\Export\Export;
|
|
|
use Ramsey\Uuid\Uuid;
|
|
|
@@ -50,18 +52,18 @@ class WaybillController extends Controller
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param Request $request
|
|
|
+ * @param GateRequest $request
|
|
|
* @param OwnerService $ownerService
|
|
|
* @param LogisticService $logisticService
|
|
|
- * @return \Illuminate\View\View
|
|
|
+ * @return View
|
|
|
*/
|
|
|
- public function index(Request $request,OwnerService $ownerService,LogisticService $logisticService)
|
|
|
+ public function index(GateRequest $request,OwnerService $ownerService,LogisticService $logisticService): View
|
|
|
{
|
|
|
$paginateParams = $request->input();
|
|
|
$waybills=app('waybillService')->paginate($request->input());
|
|
|
- $mac_addr = getMacAddr();
|
|
|
+ $macAddress = getMacAddr();
|
|
|
$print = TerminalPrinter::with(['terminal','logistics'])
|
|
|
- ->whereHas('terminal',function ($query)use($mac_addr){$query->where('ip',$mac_addr);})
|
|
|
+ ->whereHas('terminal',function ($query)use($macAddress){$query->where('ip',$macAddress);})
|
|
|
->whereHas('logistics',function ($query){$query->where('logistic_id',15);})
|
|
|
->first();
|
|
|
$print = $print->printer_name??'EK100B';
|
|
|
@@ -71,13 +73,13 @@ class WaybillController extends Controller
|
|
|
'owners' => $ownerService->getIntersectPermitting(),
|
|
|
"carTypes" => CarType::query()->get(),
|
|
|
'paginateParams'=>$paginateParams,
|
|
|
- 'uriType'=>$request->uriType??'','print_name'=> $print]);
|
|
|
+ 'uriType'=>$request->uriType??'',
|
|
|
+ 'print_name'=> $print]);
|
|
|
}
|
|
|
|
|
|
|
|
|
- public function create(Request $request,OwnerService $ownerService)
|
|
|
+ public function create(GateRequest $request,OwnerService $ownerService)
|
|
|
{
|
|
|
- if(!Gate::allows('运输管理-运单-录入')){ return redirect(url('denied')); }
|
|
|
$type=$request->type ?? "";
|
|
|
if ($type==='ZF')$type='直发车';
|
|
|
if ($type==='ZX')$type='专线';
|
|
|
@@ -85,6 +87,9 @@ class WaybillController extends Controller
|
|
|
return view('transport.waybill.create',['owners'=>$ownerService->getIntersectPermitting(),'type'=>$type]);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @throws ValidationException
|
|
|
+ */
|
|
|
public function store(Request $request)
|
|
|
{
|
|
|
if(!Gate::allows('运输管理-运单-录入')){ return redirect(url('denied')); }
|
|
|
@@ -96,17 +101,13 @@ class WaybillController extends Controller
|
|
|
|
|
|
public function edit($id,LogisticService $logisticService,CarTypeService $carTypeService,UnitService $unitService)
|
|
|
{
|
|
|
+ /** @var Waybill|\stdClass $waybill */
|
|
|
$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");
|
|
|
- }
|
|
|
+ }else $waybill->load("owner");
|
|
|
if ($waybill->merge_owner)$waybill->merge_owner = implode(",",array_column(Owner::query()->select("name")->whereIn("id",explode(",",$waybill->merge_owner))->get()->toArray(),"name"));
|
|
|
- /** @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');
|
|
|
@@ -300,7 +301,8 @@ class WaybillController extends Controller
|
|
|
* 计数二存在,一不存在:
|
|
|
* 城市价格区间不为空,城市价格区间都为空,城市为空,价格区间为空
|
|
|
* */
|
|
|
- public function isWaybillPriceModel(Request $request){
|
|
|
+ public function isWaybillPriceModel(Request $request): array
|
|
|
+ {
|
|
|
$logistic_id=$request->input('logistic_id');
|
|
|
$destination_city_id=$request->input('destination_city_id');
|
|
|
$carrier_weight=$request->input('carrier_weight');
|
|
|
@@ -401,17 +403,16 @@ class WaybillController extends Controller
|
|
|
$data=$request->input();
|
|
|
$waybill=app('waybillService')->find($id);
|
|
|
$waybill->fill($data);
|
|
|
- if ($waybill->save()){
|
|
|
- app('LogService')->log(__METHOD__,__FUNCTION__,json_encode($waybill),Auth::user()['id']);
|
|
|
- return redirect('transport/waybill/index')->with('successTip','运单“'.$waybill->waybill_number.'”修改成功');
|
|
|
- }
|
|
|
+ $waybill->save();
|
|
|
+ app('LogService')->log(__METHOD__,__FUNCTION__,json_encode($waybill),Auth::user()['id']);
|
|
|
+ return redirect('transport/waybill/index')->with('successTip','运单“'.$waybill->waybill_number.'”修改成功');
|
|
|
}
|
|
|
|
|
|
public function waybillAudit(Request $request){
|
|
|
if(!Gate::allows('运输管理-运单-运单审核')){ return redirect(url('/')); }
|
|
|
$id=$request->input('id');
|
|
|
$waybill=app('waybillService')->find($id);
|
|
|
- $isAudit=WaybillAuditLog::whereRaw('waybill_id = ? and audit_stage = ?',[$id,"运单阶段"])->first();
|
|
|
+ $isAudit=WaybillAuditLog::query()->whereRaw('waybill_id = ? and audit_stage = ?',[$id,"运单阶段"])->first();
|
|
|
if (empty($isAudit)){
|
|
|
$waybillAuditLog=new WaybillAuditLog([
|
|
|
'waybill_id'=>$id,
|
|
|
@@ -778,7 +779,7 @@ SQL;
|
|
|
|
|
|
private function deliveringQuery(Request $request): Builder
|
|
|
{
|
|
|
- $waybills= Waybill::query()->where("type","专线")->with(["order","logistic"])
|
|
|
+ $waybills= Waybill::query()->where("type","专线")->with(["order","logistic","amountUnit"])
|
|
|
->whereNotNull("logistic_id")->whereNotNull("deliver_at")->whereIn("status",["已审核","待终审"]);
|
|
|
if (!Auth::user()->isSuperAdmin()){
|
|
|
$carriersUsers=DB::table('logistic_user')->where('user_id',Auth::id())->get();
|
|
|
@@ -819,8 +820,9 @@ SQL;
|
|
|
$errors=Validator::make($request->input(),[
|
|
|
'id'=>'required|integer',
|
|
|
'carrier_bill'=>'required',
|
|
|
- 'inquire_tel'=>'nullable',
|
|
|
- 'amount'=>'nullable|integer',
|
|
|
+ 'inquire_tel'=>'required',
|
|
|
+ 'amount'=>'required|integer',
|
|
|
+ 'amount_unit_name'=>'required|string',
|
|
|
'carrier_weight'=>'required_without:carrier_weight_other|nullable|numeric',
|
|
|
'carrier_weight_other'=>'required_without:carrier_weight|nullable|numeric',
|
|
|
],[
|
|
|
@@ -831,14 +833,16 @@ SQL;
|
|
|
],[
|
|
|
'carrier_bill'=>'运单号',
|
|
|
'inquire_tel'=>'查件电话',
|
|
|
+ 'amount_unit_name'=>'数量单位',
|
|
|
'amount'=>'件数',
|
|
|
'carrier_weight'=>'体积',
|
|
|
'carrier_weight_other'=>'重量',
|
|
|
])->errors();
|
|
|
+ if ($request->input("amount_unit_name")!='件' && $request->input("amount_unit_name")!='托')$errors->add("amount_unit_name","非法参数");
|
|
|
+ if (count($errors)>0)return ["errors"=>$errors];
|
|
|
$unit = app("UnitService")->getUnit("kg");
|
|
|
- $unit1 = app("UnitService")->getUnit("件");
|
|
|
+ $unit1 = app("UnitService")->getUnit($request->input("amount_unit_name"));
|
|
|
$unit2 = app("UnitService")->getUnit("m³");
|
|
|
- if (count($errors)>0)return ["errors"=>$errors];
|
|
|
$waybill=Waybill::query()->find($request->input('id'));
|
|
|
if (!$waybill)return ["error"=>"未找到该运单!"];
|
|
|
$request->offsetSet("carrier_weight_unit_id",$unit2->id);
|
|
|
@@ -1128,8 +1132,7 @@ SQL;
|
|
|
for ($i=1;$i<$waybills->count();$i++){
|
|
|
//信息一致性校验
|
|
|
$identical = ($waybill->order && ($waybills[$i]->order->consignee_name!=$waybill->order->consignee_name
|
|
|
- || $waybills[$i]->order->consignee_phone!=$waybill->order->consignee_phone
|
|
|
- || $waybills[$i]->order->address!=$waybill->order->address)) ||
|
|
|
+ || $waybills[$i]->order->consignee_phone!=$waybill->order->consignee_phone)) ||
|
|
|
(!$waybill->order && ($waybills[$i]->recipient!=$waybill->recipient
|
|
|
|| $waybills[$i]->recipient_mobile!=$waybill->recipient_mobile
|
|
|
|| $waybills[$i]->destination!=$waybill->destination));
|
|
|
@@ -1291,8 +1294,7 @@ SQL;
|
|
|
foreach ($waybills as $item){
|
|
|
//信息一致性校验
|
|
|
$identical = ($waybill->order && ($item->order->consignee_name!=$waybill->order->consignee_name
|
|
|
- || $item->order->consignee_phone!=$waybill->order->consignee_phone
|
|
|
- || $item->order->address!=$waybill->order->address)) ||
|
|
|
+ || $item->order->consignee_phone!=$waybill->order->consignee_phone)) ||
|
|
|
(!$waybill->order && ($item->recipient!=$waybill->recipient
|
|
|
|| $item->recipient_mobile!=$waybill->recipient_mobile));
|
|
|
if ($identical)$this->error("订单信息不一致,无法统一发货");
|