|
|
@@ -8,6 +8,8 @@ use App\Services\CarTypeService;
|
|
|
use App\Services\CityService;
|
|
|
use App\Services\OwnerService;
|
|
|
use App\Services\UnitService;
|
|
|
+use App\Services\WaybillPayoffService;
|
|
|
+use App\Services\WaybillPriceModelService;
|
|
|
use App\Services\WaybillService;
|
|
|
use App\UploadFile;
|
|
|
use App\WaybillAuditLog;
|
|
|
@@ -93,10 +95,10 @@ class WaybillController extends Controller
|
|
|
return view('waybill/edit',['waybill'=>$waybill,'carriers'=>$carrierService->getSelection(),'cities'=>$cities,'units'=>$units,'carTypes'=>$carTypes]);
|
|
|
}
|
|
|
|
|
|
- public function update(Request $request, $id , CityService $cityService)
|
|
|
+ public function update(Request $request, $id,WaybillPriceModelService $waybillPriceModelService,
|
|
|
+ CarrierService $carrierService,WaybillPayoffService $waybillPayoffService)
|
|
|
{
|
|
|
if(!Gate::allows('运输管理-调度')){ return redirect(url('/')); }
|
|
|
- $waybill=app('waybillService')->find($id);
|
|
|
if (!$request->warehouse_weight && $request->warehouse_weight_unit_id){
|
|
|
$request->offsetUnset('warehouse_weight_unit_id');
|
|
|
}
|
|
|
@@ -110,86 +112,45 @@ class WaybillController extends Controller
|
|
|
$request->offsetUnset('carrier_weight_unit_id_other');
|
|
|
}
|
|
|
$this->validatorWaybillDispatch($request,$id)->validate();
|
|
|
- //替换换行符
|
|
|
- if ($request->dispatch_remark){
|
|
|
- $request->dispatch_remark = str_replace(PHP_EOL,' ',$request->dispatch_remark);
|
|
|
- }
|
|
|
- if (!$request->destination)$request->destination = $waybill->destination;
|
|
|
- if ($request->destination_city_id && $waybill->destination_city_id != $request->destination_city_id){
|
|
|
- $city=$cityService->find($request->destination_city_id);
|
|
|
- if ($city && (mb_strpos($request->destination,$city->name)===false || mb_strpos($request->destination,$city->province_name)===false)){
|
|
|
- if (mb_strpos($request->destination,$city->name)===false && mb_strpos($request->destination,$city->province_name)===false){
|
|
|
- $request->destination=$city->province_name.$city->name.$request->destination;
|
|
|
- goto sign;
|
|
|
- }
|
|
|
- if (mb_strpos($request->destination,$city->province_name)===false){
|
|
|
- $request->destination=$city->province_name.$request->destination;
|
|
|
+ $waybillPayoffParam = [];
|
|
|
+ $waybillPayoffParam['total_receivable']=0;
|
|
|
+ $waybill = app('waybillService')->update($request,$id);
|
|
|
+ if ($waybill->type=="直发车"){
|
|
|
+ if ($waybill->charge)$waybillPayoffParam['total_receivable'] = ($waybill->charge);
|
|
|
+ elseif ($waybill->collect_fee)$waybillPayoffParam['total_receivable'] = ($waybill->collect_fee);
|
|
|
+ $waybillPayoffParam['total_expense'] = ($waybill->fee)+($waybill->other_fee)-($waybill->collect_fee);
|
|
|
+ }else {
|
|
|
+ $waybillPriceModel_id=$request->input('waybillPriceModel');
|
|
|
+ if ($waybillPriceModel_id){
|
|
|
+ $carrier_weight=$request->input('carrier_weight');
|
|
|
+ $waybillPriceModel=$waybillPriceModelService->find($waybillPriceModel_id);
|
|
|
+ $carrier=$carrierService->find($waybill->carrier_id);
|
|
|
+ if ($carrier_weight<$waybillPriceModel->initial_weight){
|
|
|
+ $fee=(($waybillPriceModel->unit_price)*($waybillPriceModel->initial_weight))+$carrier->delivery_fee;
|
|
|
+ }else{
|
|
|
+ $fee=(($waybillPriceModel->unit_price)*$carrier_weight)+$carrier->delivery_fee;
|
|
|
}
|
|
|
- if (mb_strpos($request->destination,$city->name)===false){
|
|
|
- $province_name=$city->province_name;
|
|
|
- $start_index=mb_strpos($request->destination,$city->province_name.'省');
|
|
|
- if ($start_index===false)$start_index=mb_strpos($request->destination,$city->province_name);
|
|
|
- else $province_name=$province_name.'省';
|
|
|
- $strBefore=mb_substr($request->destination,$start_index,mb_strlen($province_name));
|
|
|
- $strAfter=mb_substr($request->destination,$start_index+mb_strlen($province_name));
|
|
|
- $request->destination=$strBefore.$city->name.$strAfter;
|
|
|
+ if ($waybillPriceModel->base_fee&&$fee<$waybillPriceModel->base_fee){
|
|
|
+ $fee=$waybillPriceModel->base_fee;
|
|
|
}
|
|
|
+ $waybill->fee=$fee;
|
|
|
+ $waybill->waybill_price_model_id=$waybillPriceModel_id;
|
|
|
}
|
|
|
- }
|
|
|
- sign:
|
|
|
- $total_receivable=0;
|
|
|
- $waybill->fill($request->input());
|
|
|
- if ($waybill->save()){
|
|
|
- if ($waybill->type=="直发车"){
|
|
|
- if ($waybill->charge)$total_receivable=($waybill->charge);
|
|
|
- elseif ($waybill->collect_fee)$total_receivable=($waybill->collect_fee);
|
|
|
- $total_expense=($waybill->fee)+($waybill->other_fee)-($waybill->collect_fee);
|
|
|
- }else {
|
|
|
- $waybillPriceModel_id=$request->input('waybillPriceModel');
|
|
|
- if ($waybillPriceModel_id){
|
|
|
- $carrier_weight=$request->input('carrier_weight');
|
|
|
- $waybillPriceModel=WaybillPriceModel::find($waybillPriceModel_id);
|
|
|
- $carrier=Carrier::find($waybill->carrier_id);
|
|
|
- if ($carrier_weight<$waybillPriceModel->initial_weight){
|
|
|
- $fee=(($waybillPriceModel->unit_price)*($waybillPriceModel->initial_weight))+$carrier->delivery_fee;
|
|
|
- }else{
|
|
|
- $fee=(($waybillPriceModel->unit_price)*$carrier_weight)+$carrier->delivery_fee;
|
|
|
- }
|
|
|
- if ($waybillPriceModel->base_fee&&$fee<$waybillPriceModel->base_fee){
|
|
|
- $fee=$waybillPriceModel->base_fee;
|
|
|
- }
|
|
|
- $waybill->fee=$fee;
|
|
|
- $waybill->waybill_price_model_id=$waybillPriceModel_id;
|
|
|
- }
|
|
|
- $waybill->save();
|
|
|
- if ($waybill->charge)$total_receivable=($waybill->charge);
|
|
|
- elseif($waybill->collect_fee) {
|
|
|
- $total_receivable=($waybill->collect_fee);
|
|
|
- }
|
|
|
- $total_expense=($waybill->pick_up_fee)+($waybill->other_fee)+($waybill->fee);
|
|
|
+ $waybill->save();
|
|
|
+ if ($waybill->charge)$waybillPayoffParam['total_receivable'] = ($waybill->charge);
|
|
|
+ elseif($waybill->collect_fee) {
|
|
|
+ $waybillPayoffParam['total_receivable'] = $waybill->collect_fee;
|
|
|
}
|
|
|
- if ($total_receivable>0){
|
|
|
- $waybillPayoff=WaybillPayoff::where('waybill_id','=',$id)->first();
|
|
|
- if ($waybillPayoff){
|
|
|
- $waybillPayoff->waybill_id=$id;
|
|
|
- $waybillPayoff->total_expense=$total_expense;
|
|
|
- $waybillPayoff->total_receivable=$total_receivable;
|
|
|
- $waybillPayoff->gross_margin=$total_receivable-$total_expense;
|
|
|
- $waybillPayoff->gross_profit_rate=(($total_receivable-$total_expense)/$total_receivable);
|
|
|
- $waybillPayoff->save();
|
|
|
- }else{
|
|
|
- WaybillPayoff::create([
|
|
|
- 'waybill_id'=>$id,
|
|
|
- 'total_expense'=>$total_expense,
|
|
|
- 'total_receivable'=>$total_receivable,
|
|
|
- 'gross_margin'=>$total_receivable-$total_expense,
|
|
|
- 'gross_profit_rate'=>(($total_receivable-$total_expense)/$total_receivable),
|
|
|
- ]);
|
|
|
- };
|
|
|
- }
|
|
|
- $this->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
|
|
|
- return redirect('waybill/index')->with('successTip','运单“'.$waybill->waybill_number.'”调度成功');
|
|
|
+ $waybillPayoffParam['total_expense'] = ($waybill->pick_up_fee)+($waybill->other_fee)+($waybill->fee);
|
|
|
+ }
|
|
|
+ if ($waybillPayoffParam['total_receivable'] > 0){
|
|
|
+ $waybillPayoffParam['waybill_id'] = $id;
|
|
|
+ $waybillPayoffParam['gross_margin'] = $waybillPayoffParam['total_receivable'] - $waybillPayoffParam['total_expense'];
|
|
|
+ $waybillPayoffParam['gross_profit_rate'] = $waybillPayoffParam['gross_margin']/$waybillPayoffParam['total_receivable'];
|
|
|
+ $waybillPayoffService->updateOrCreate($waybillPayoffParam);
|
|
|
}
|
|
|
+ $this->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
|
|
|
+ return redirect('waybill/index')->with('successTip','运单“'.$waybill->waybill_number.'”调度成功');
|
|
|
}
|
|
|
|
|
|
public function checkWaybillPriceModel($carrier_id,$destination_city_id,$carrier_weight,$carrier_weight_unit_id){
|
|
|
@@ -259,7 +220,7 @@ class WaybillController extends Controller
|
|
|
}
|
|
|
}
|
|
|
if ($waybillPriceModelProvinceRangeOne)return $waybillPriceModelProvinceRangeOne->id;
|
|
|
- if ($waybillPriceModelProvinceRangeOne)return $waybillPriceModelProvinceRangeOne->id;
|
|
|
+ if ($waybillPriceModelProvinceRangeTwo)return $waybillPriceModelProvinceRangeTwo->id;
|
|
|
};
|
|
|
for ($i=0;$i<count($carrier_weight);$i++){
|
|
|
if ($carrier_weight[$i]&&$carrier_weight_unit_id[$i]){
|
|
|
@@ -797,6 +758,7 @@ class WaybillController extends Controller
|
|
|
return $validator;
|
|
|
}
|
|
|
public function addCounty(Request $request){
|
|
|
+ if ($request->destination_city =='undefined')$request->offsetUnset('destination_city');
|
|
|
$rule =[
|
|
|
'destination_city' => ['required', 'string','unique:cities,name'],
|
|
|
];
|