|
|
@@ -4,7 +4,9 @@ namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
use App\Components\AsyncResponse;
|
|
|
+use App\Region;
|
|
|
use App\Services\CarTypeService;
|
|
|
+use App\Services\common\ExportService;
|
|
|
use App\Services\LogisticService;
|
|
|
use App\Services\OwnerService;
|
|
|
use App\Services\UnitService;
|
|
|
@@ -15,7 +17,6 @@ use App\UploadFile;
|
|
|
use App\WaybillAuditLog;
|
|
|
use App\WaybillOnTop;
|
|
|
use App\WaybillPriceModel;
|
|
|
-use App\City;
|
|
|
use App\Unit;
|
|
|
use App\Waybill;
|
|
|
use App\WaybillPayoff;
|
|
|
@@ -137,7 +138,7 @@ class WaybillController extends Controller
|
|
|
if ($waybillPriceModel_id){
|
|
|
$carrier_weight=$request->input('carrier_weight');
|
|
|
$waybillPriceModel=$waybillPriceModelService->find($waybillPriceModel_id);
|
|
|
- $logistic=$logisticService->find($waybill->order->logistic_id ?? $waybill->logistic_id);
|
|
|
+ $logistic=$logisticService->find($waybill->logistic_id);
|
|
|
if ($carrier_weight<$waybillPriceModel->initial_weight){
|
|
|
$fee=(($waybillPriceModel->unit_price)*($waybillPriceModel->initial_weight))+$logistic->delivery_fee;
|
|
|
}else{
|
|
|
@@ -205,11 +206,11 @@ class WaybillController extends Controller
|
|
|
if ($waybillPriceModelRangeTwo)return $waybillPriceModelRangeTwo->id;
|
|
|
|
|
|
//城市为空
|
|
|
- $city=City::query()->where('id',$destination_city_id)->select('province_id')->first();
|
|
|
+ $city=Region::query()->where('id',$destination_city_id)->select('parent_id')->first();
|
|
|
$waybillPriceModelProvinceOne=WaybillPriceModel::query()->whereRaw('logistic_id = ? AND province_id = ? AND unit_id = ? AND range_max >= ? AND range_min < ? AND city_id IS NULL',
|
|
|
- [$logistic_id,$city->province_id,$carrier_weight_unit_id[0],$carrier_weight[0],$carrier_weight[0]])->first();
|
|
|
+ [$logistic_id,$city->parent_id ?? 0,$carrier_weight_unit_id[0],$carrier_weight[0],$carrier_weight[0]])->first();
|
|
|
$waybillPriceModelProvinceTwo=WaybillPriceModel::query()->whereRaw('logistic_id = ? AND province_id = ? AND unit_id = ? AND range_max >= ? AND range_min < ? AND city_id IS NULL',
|
|
|
- [$logistic_id,$city->province_id,$carrier_weight_unit_id[1],$carrier_weight[1],$carrier_weight[1]])->first();
|
|
|
+ [$logistic_id,$city->parent_id ?? 0,$carrier_weight_unit_id[1],$carrier_weight[1],$carrier_weight[1]])->first();
|
|
|
if ($waybillPriceModelProvinceOne&&$waybillPriceModelProvinceTwo){
|
|
|
if ($waybillPriceModelProvinceOne->unit_price*$carrier_weight[0]>=$waybillPriceModelProvinceTwo->unit_price*$carrier_weight[1]){
|
|
|
return $waybillPriceModelProvinceOne->id;
|
|
|
@@ -222,9 +223,9 @@ class WaybillController extends Controller
|
|
|
|
|
|
//城市价格区间都为空
|
|
|
$waybillPriceModelProvinceRangeOne=WaybillPriceModel::query()->whereRaw('logistic_id = ? AND province_id = ? AND unit_id = ? AND range_max IS NULL AND city_id IS NULL',
|
|
|
- [$logistic_id,$city->province_id,$carrier_weight_unit_id[0]])->first();
|
|
|
+ [$logistic_id,$city->parent_id ?? 0,$carrier_weight_unit_id[0]])->first();
|
|
|
$waybillPriceModelProvinceRangeTwo=WaybillPriceModel::query()->whereRaw('logistic_id = ? AND province_id = ? AND unit_id = ? AND range_max IS NULL AND city_id IS NULL',
|
|
|
- [$logistic_id,$city->province_id,$carrier_weight_unit_id[1]])->first();
|
|
|
+ [$logistic_id,$city->parent_id ?? 0,$carrier_weight_unit_id[1]])->first();
|
|
|
if ($waybillPriceModelProvinceRangeOne&&$waybillPriceModelProvinceRangeTwo){
|
|
|
if ($waybillPriceModelProvinceRangeOne->unit_price*$carrier_weight[0]>=$waybillPriceModelProvinceRangeTwo->unit_price*$carrier_weight[1]){
|
|
|
return $waybillPriceModelProvinceRangeOne->id;
|
|
|
@@ -248,14 +249,14 @@ class WaybillController extends Controller
|
|
|
if ($waybillPriceModelRange){ return $waybillPriceModelRange->id;}
|
|
|
|
|
|
//城市为空
|
|
|
- $city=City::where('id',$destination_city_id)->select('province_id')->first();
|
|
|
+ $city=Region::query()->where('id',$destination_city_id)->select('parent_id')->first();
|
|
|
$waybillPriceModelProvince=WaybillPriceModel::query()->whereRaw('logistic_id = ? AND province_id = ? AND unit_id = ? AND range_max >= ? AND range_min < ? AND city_id IS NULL',
|
|
|
- [$logistic_id,$city->province_id,$carrier_weight_unit_id[$i],$carrier_weight[$i],$carrier_weight[$i]])->first();
|
|
|
+ [$logistic_id,$city->parent_id ?? 0,$carrier_weight_unit_id[$i],$carrier_weight[$i],$carrier_weight[$i]])->first();
|
|
|
if ($waybillPriceModelProvince){return $waybillPriceModelProvince->id;}
|
|
|
|
|
|
//城市价格区间都为空
|
|
|
$waybillPriceModelProvinceRange=WaybillPriceModel::query()->whereRaw('logistic_id = ? AND province_id = ? AND unit_id = ? AND range_max IS NULL AND city_id IS NULL',
|
|
|
- [$logistic_id,$city->province_id,$carrier_weight_unit_id[$i]])->first();
|
|
|
+ [$logistic_id,$city->parent_id ?? 0,$carrier_weight_unit_id[$i]])->first();
|
|
|
if ($waybillPriceModelProvinceRange){return $waybillPriceModelProvinceRange->id;}
|
|
|
}
|
|
|
}
|
|
|
@@ -425,6 +426,7 @@ class WaybillController extends Controller
|
|
|
]);
|
|
|
}
|
|
|
}
|
|
|
+ app("waybillService")->createInstantBill($waybill);
|
|
|
app('LogService')->log(__METHOD__,__FUNCTION__,$waybillPayoffJson,Auth::id());
|
|
|
return ['success'=>$result,'status'=>$waybill->status,'waybillAuditLog'=>$waybillAuditLog];
|
|
|
}
|
|
|
@@ -434,7 +436,7 @@ class WaybillController extends Controller
|
|
|
//生成报表数据
|
|
|
private function createReportData($waybill,$waybillPayoff){
|
|
|
/** @var Waybill $waybill */
|
|
|
- $waybill->loadMissing(["order.owner",'order.logistic']);
|
|
|
+ $waybill->loadMissing(["order.owner"]);
|
|
|
return [
|
|
|
"type"=>$waybill->type,
|
|
|
"waybill_number"=>$waybill->waybill_number,
|
|
|
@@ -448,7 +450,7 @@ class WaybillController extends Controller
|
|
|
"charge"=>$waybill->charge,
|
|
|
"collect_fee"=>$waybill->collect_fee,
|
|
|
"ordering_remark"=>$waybill->ordering_remark,
|
|
|
- "carrier_name"=>$waybill->order->logistic->name ?? ($waybill->logistic->name ?? null),
|
|
|
+ "carrier_name"=>$waybill->logistic->name ?? null,
|
|
|
"carrier_bill"=>$waybill->carrier_bill,
|
|
|
"origination_city_name"=>$waybill->originationCity ? $waybill->originationCity->name : null,
|
|
|
"destination_city_name"=>$waybill->order->city ?? ($waybill->destinationCity->name ?? null),
|
|
|
@@ -611,22 +613,53 @@ class WaybillController extends Controller
|
|
|
return ['success'=>true];
|
|
|
}
|
|
|
|
|
|
- public function export(Request $request){
|
|
|
- if(!Gate::allows('运输管理-查询')){ return '没有权限'; }
|
|
|
- if ($request->checkAllSign){
|
|
|
- $param = $request->input();
|
|
|
- unset($param['checkAllSign']);
|
|
|
- $sql = app('waybillService')->getSql($param);
|
|
|
-
|
|
|
- }else $sql = app('waybillService')->getSql(['id'=>$request->data]);
|
|
|
- $post = Http::post(config('go.export.url'),['type'=>'waybill','sql'=>$sql]);
|
|
|
- if ($post->status() == 500){
|
|
|
- throw new Exception($post->header("Msg"));
|
|
|
- }
|
|
|
- return response($post,200, [
|
|
|
- "Content-type"=>"application/octet-stream",
|
|
|
- "Content-Disposition"=>"attachment; filename=运单列表-".date('ymdHis').'.xlsx',
|
|
|
- ]);
|
|
|
+ public function export(){
|
|
|
+ $this->gate('运输管理-查询');
|
|
|
+ if (request("checkAllSign")){
|
|
|
+ request()->offsetUnset("checkAllSign");
|
|
|
+ $waybills = app('waybillService')->get(request()->input());
|
|
|
+ }else $waybills = app('waybillService')->get(["id"=>request("id")]);
|
|
|
+ /** @var Collection $waybills */
|
|
|
+ $row = [
|
|
|
+ "运单类型", "货主", "上游单号", "wms订单号", "运单号", "运输收费",
|
|
|
+ "其他收费", "其他收费备注", "始发地", "目的地", "承运商", "承运商单号",
|
|
|
+ "仓库计抛", "承运商计抛", "仓库计重", "承运商计重", "车型", "车辆信息",
|
|
|
+ "计件", "里程数", "运费(元)", "提货费(元)", "其他费用(元)", "发货时间",
|
|
|
+ "调度备注", "创建时间"
|
|
|
+ ];
|
|
|
+ $list = [];
|
|
|
+ $waybills->each(function ($waybill)use(&$list){
|
|
|
+ $list[] = [
|
|
|
+ $waybill->type,
|
|
|
+ $waybill->order->owner->name ?? ($waybill->owner->name ?? ""),
|
|
|
+ $waybill->source_bill,
|
|
|
+ $waybill->wms_bill_number,
|
|
|
+ $waybill->waybill_number,
|
|
|
+ $waybill->waybill_number,
|
|
|
+ $waybill->charge,
|
|
|
+ $waybill->other_charge,
|
|
|
+ $waybill->other_charge_remark,
|
|
|
+ $waybill->origination,
|
|
|
+ $waybill->order->address ?? $waybill->destination,
|
|
|
+ $waybill->logistic->name ?? "",
|
|
|
+ $waybill->carrier_bill,
|
|
|
+ $waybill->warehouse_weight,
|
|
|
+ $waybill->carrier_weight,
|
|
|
+ $waybill->warehouse_weight_other,
|
|
|
+ $waybill->carrier_weight_other,
|
|
|
+ $waybill->car_type_name,
|
|
|
+ $waybill->car_owner_info,
|
|
|
+ $waybill->amount,
|
|
|
+ $waybill->mileage,
|
|
|
+ $waybill->fee,
|
|
|
+ $waybill->pick_up_fee,
|
|
|
+ $waybill->other_fee,
|
|
|
+ $waybill->deliver_at,
|
|
|
+ $waybill->dispatch_remark,
|
|
|
+ $waybill->created_at,
|
|
|
+ ];
|
|
|
+ });
|
|
|
+ return app(ExportService::class)->json($row,$list,"运输记录单");
|
|
|
}
|
|
|
|
|
|
public function deliveringExport(Request $request){
|
|
|
@@ -778,26 +811,12 @@ 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'],
|
|
|
- ];
|
|
|
- $messages=[
|
|
|
- 'destination_city.required'=>'市/县不能为空',
|
|
|
- 'destination_city.string'=>'市/县必须是字符串',
|
|
|
- 'destination_city.unique'=>'市/县已存在',
|
|
|
- ];
|
|
|
- $validator = Validator::make($request->all(),$rule,$messages);
|
|
|
- if ($validator->fails()) {
|
|
|
- return $validator->errors();
|
|
|
- }
|
|
|
- $city=new City([
|
|
|
- 'name'=>$request->input('destination_city'),
|
|
|
- 'type'=>3,
|
|
|
- ]);
|
|
|
- $city->save();
|
|
|
- return $city;
|
|
|
+ public function addCounty(){
|
|
|
+ $name = app("RegionService")->formatName(request("name"),2);
|
|
|
+ if (!$name)$this->error("非法参数");
|
|
|
+
|
|
|
+ $region = Region::query()->firstOrCreate(["name"=>$name,"type"=>2,"parent_id"=>request("province")]);
|
|
|
+ $this->success($region);
|
|
|
}
|
|
|
|
|
|
// 运单删除 软删除
|
|
|
@@ -813,7 +832,7 @@ class WaybillController extends Controller
|
|
|
if(!Gate::allows('运输管理-删除')){return redirect('/');}
|
|
|
$paginate = $request->input('paginate')??50;
|
|
|
/** @var Collection $waybills */
|
|
|
- $waybills = Waybill::query()->with(['owner','order.owner','order.logistic','logistic','amountUnit','warehouseWeightUnit','carrierWeightUnit',
|
|
|
+ $waybills = Waybill::query()->with(['owner','order.owner','logistic','amountUnit','warehouseWeightUnit','carrierWeightUnit',
|
|
|
'warehouseWeightUnitOther','carrierWeightUnitOther','carType','waybillAuditLogs' => function ($query) {
|
|
|
/** @var Builder $query */
|
|
|
$query->with('user');
|