| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412 |
- <?php
- 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;
- use App\Services\LogisticService;
- use App\Services\LogService;
- use App\Services\OwnerService;
- use App\Services\UnitService;
- use App\Services\WaybillPayoffService;
- use App\Services\WaybillPriceModelService;
- use App\Services\WaybillService;
- use App\TerminalPrinter;
- use App\UploadFile;
- use App\WaybillAuditLog;
- use App\WaybillOnTop;
- use App\WaybillPriceModel;
- use App\Unit;
- use App\Waybill;
- use App\WaybillPayoff;
- use App\WaybillFinancialExcepted;
- use App\WaybillFinancialSnapshot;
- use Carbon\Carbon;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Database\Eloquent\Collection;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Auth;
- 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;
- class WaybillController extends Controller
- {
- use AsyncResponse;
- public function __construct()
- {
- app()->singleton('waybillService',WaybillService::class);
- }
- /**
- * @param GateRequest $request
- * @param OwnerService $ownerService
- * @param LogisticService $logisticService
- * @return View
- */
- public function index(GateRequest $request,OwnerService $ownerService,LogisticService $logisticService): View
- {
- $paginateParams = $request->input();
- $waybills=app('waybillService')->paginate($request->input());
- $macAddress = getMacAddr();
- $print = TerminalPrinter::with(['terminal','logistics'])
- ->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';
- return view('transport.waybill.index', [
- 'waybills' => $waybills,
- 'logistics' => $logisticService->getSelection(["id","name"],"物流"),
- 'owners' => $ownerService->getIntersectPermitting(),
- "carTypes" => CarType::query()->get(),
- 'paginateParams'=>$paginateParams,
- 'uriType'=>$request->uriType??'',
- 'print_name'=> $print]);
- }
- public function create(GateRequest $request,OwnerService $ownerService)
- {
- $type=$request->type ?? "";
- if ($type==='ZF')$type='直发车';
- if ($type==='ZX')$type='专线';
- if ($type==='DBWL')$type='德邦物流';
- return view('transport.waybill.create',['owners'=>$ownerService->getIntersectPermitting(),'type'=>$type]);
- }
- /**
- * @throws ValidationException
- */
- public function store(Request $request)
- {
- if(!Gate::allows('运输管理-运单-录入')){ return redirect(url('denied')); }
- $this->validatorWaybill($request,false)->validate();
- /** @var WaybillService */
- $waybill=app('waybillService')->store($request);
- return redirect('transport/waybill/index')->with('successTip','新运单“'.$waybill->waybill_number.'”录入成功');
- }
- public function edit($id,LogisticService $logisticService,CarTypeService $carTypeService,UnitService $unitService)
- {
- /** @var Waybill|\stdClass $waybill */
- $waybill = app('waybillService')->find($id);
- if ($waybill->order_id){
- $waybill->load("order.owner");
- $waybill->destination_city_id = app("RegionService")->getCity($waybill->order->city ?? '',$waybill->order->province ?? '');
- }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"));
- 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=app("RegionService")->getSelection(2);
- $units=$unitService->getSelection();
- $carTypes=$carTypeService->getSelection();
- $deliveryType = app('DeliveryTypeService')->getSelection();
- return view('transport.waybill.edit',['waybill'=>$waybill,'logistics'=>$logisticService->getSelection(["id","name","tag"],"物流"),'cities'=>$cities,'units'=>$units,'carTypes'=>$carTypes,
- 'deliveryTypes'=>$deliveryType,'orderTypes' =>collect(config('api_logistic.DB.prod.orderType')),'transportTypes' => collect(config('api_logistic.DB.prod.transportType'))
- ,'payTypes' => collect(config('api_logistic.DB.prod.payType')),'backSignBills' => collect(config('api_logistic.DB.prod.backSignBill')),'packageServices' => collect(config('api_logistic.DB.prod.packageService'))
- ]);
- }
- public function update(Request $request, $id,WaybillPriceModelService $waybillPriceModelService,
- LogisticService $logisticService,WaybillPayoffService $waybillPayoffService)
- {
- if(!Gate::allows('运输管理-运单-调度') && $request->type != '德邦物流'){ return view("exception.authority"); }
- if (!$request->warehouse_weight && $request->warehouse_weight_unit_id)$request->offsetUnset('warehouse_weight_unit_id');
- if (!$request->warehouse_weight_other && $request->warehouse_weight_unit_id_other)$request->offsetUnset('warehouse_weight_unit_id_other');
- if (!$request->carrier_weight && $request->carrier_weight_unit_id)$request->offsetUnset('carrier_weight_unit_id');
- if (!$request->carrier_weight_other && $request->carrier_weight_unit_id_other)$request->offsetUnset('carrier_weight_unit_id_other');
- if ($request->type == '德邦物流' && empty($request->carrier_bill)) $request->offsetSet('carrier_bill', 'dbwl');
- $this->validatorWaybillDispatch($request,$id)->validate();
- if ($request->carrier_bill == 'dbwl')$request->offsetSet('carrier_bill', '');
- $waybillPayoffParam = [];
- $waybillPayoffParam['total_receivable']=0;
- /** @var WaybillService */
- $waybill = app('waybillService')->find($id);
- $oldBill = $waybill->carrier_bill;
- DB::beginTransaction();
- try {
- $waybill = app('waybillService')->update($waybill, $request->input());
- 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);
- $logistic=$logisticService->find($waybill->logistic_id);
- if ($carrier_weight<$waybillPriceModel->initial_weight){
- $fee=(($waybillPriceModel->unit_price)*($waybillPriceModel->initial_weight))+$logistic->delivery_fee;
- }else{
- $fee=(($waybillPriceModel->unit_price)*$carrier_weight)+$logistic->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)$waybillPayoffParam['total_receivable'] = ($waybill->charge);
- elseif($waybill->collect_fee) {
- $waybillPayoffParam['total_receivable'] = $waybill->collect_fee;
- }
- $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);
- }
- $stage = "发起调度";
- if ($waybill->type=='德邦物流' && !$oldBill){
- $bill = app('DbOpenService')->getDbOrderNo($waybill);
- if (!$bill){DB::rollBack();return "获取德邦单号失败,德邦服务异常";}
- if ($bill["result"]=="false"){
- DB::rollBack();return $bill["reason"];
- }
- $waybill->update(["carrier_bill"=>$bill['mailNo'],'waybill_number'=>$bill['mailNo'],'station_no' => $bill['stationNo'], 'arrived_org_simple_name' =>$bill['arrivedOrgSimpleName'], 'much_higher_delivery'=>$bill['muchHigherDelivery']]);
- $msg = "【申请德邦物流单号:".$bill['mailNo']."】";
- if (!app("WaybillService")->notifyFlux($waybill))$msg .= ",通知FLUX失败";
- $stage = '发起德邦调度';
- }
- WaybillAuditLog::query()->create([
- 'waybill_id' => $id,
- 'audit_stage' => $stage,
- 'user_id' => Auth::id(),
- ]);
- DB::commit();
- }catch (\Exception $e){
- DB::rollBack();
- return "调度失败".$e->getMessage();
- }
- return redirect('transport/waybill/index')->with('successTip','运单“'.$waybill->waybill_number.'”创建成功 '. ($msg??''));
- }
- public function checkWaybillPriceModel($logistic_id,$destination_city_id,$carrier_weight,$carrier_weight_unit_id){
- //确保承运商计数与计数单位为一个数组且长度2
- if(!$logistic_id)return false;
- if(!$destination_city_id)return false;
- if(!$carrier_weight)return false;
- if(!$carrier_weight_unit_id)return false;
- //多个计数标准,计算价格,取最贵
- if ($carrier_weight[0]&&$carrier_weight[1]&&$carrier_weight_unit_id[0]&&$carrier_weight_unit_id[1]){
- //城市价格区间不为空
- $waybillPriceModelOne=WaybillPriceModel::query()->where('logistic_id',$logistic_id)->where('city_id',$destination_city_id)
- ->where('range_min','<',$carrier_weight[0])->where('range_max','>=',$carrier_weight[0])
- ->where('unit_id',$carrier_weight_unit_id[0])->first();
- $waybillPriceModelTwo=WaybillPriceModel::query()->where('logistic_id',$logistic_id)->where('city_id',$destination_city_id)
- ->where('range_min','<',$carrier_weight[1])->where('range_max','>=',$carrier_weight[1])
- ->where('unit_id',$carrier_weight_unit_id[1])->first();
- if ($waybillPriceModelOne&&$waybillPriceModelTwo){
- if ($waybillPriceModelOne->unit_price*$carrier_weight[0]>=$waybillPriceModelTwo->unit_price*$carrier_weight[1]){
- return $waybillPriceModelOne->id;
- }else{
- return $waybillPriceModelTwo->id;
- }
- }
- if ($waybillPriceModelOne)return $waybillPriceModelOne->id;
- if ($waybillPriceModelTwo)return $waybillPriceModelTwo->id;
- //价格区间为空
- $waybillPriceModelRangeOne=WaybillPriceModel::query()->whereRaw('logistic_id = ? AND city_id = ? AND unit_id = ? AND range_max IS NULL',[$logistic_id,$destination_city_id,$carrier_weight_unit_id[0]])->first();
- $waybillPriceModelRangeTwo=WaybillPriceModel::query()->whereRaw('logistic_id = ? AND city_id = ? AND unit_id = ? AND range_max IS NULL',[$logistic_id,$destination_city_id,$carrier_weight_unit_id[1]])->first();
- if ($waybillPriceModelRangeOne&&$waybillPriceModelRangeTwo){
- if ($waybillPriceModelRangeOne->unit_price*$carrier_weight[0]>=$waybillPriceModelRangeTwo->unit_price*$carrier_weight[1]){
- return $waybillPriceModelRangeOne->id;
- }else{
- return $waybillPriceModelRangeTwo->id;
- }
- }
- if ($waybillPriceModelRangeOne)return $waybillPriceModelRangeOne->id;
- if ($waybillPriceModelRangeTwo)return $waybillPriceModelRangeTwo->id;
- //城市为空
- $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->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->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;
- }else{
- return $waybillPriceModelProvinceTwo->id;
- }
- }
- if ($waybillPriceModelProvinceOne)return $waybillPriceModelProvinceOne->id;
- if ($waybillPriceModelProvinceTwo)return $waybillPriceModelProvinceTwo->id;
- //城市价格区间都为空
- $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->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->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;
- }else{
- 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]){
- //城市价格区间不为空
- $waybillPriceModel=WaybillPriceModel::query()->where('logistic_id',$logistic_id)->where('city_id',$destination_city_id)
- ->where('range_min','<',$carrier_weight[$i])->where('range_max','>=',$carrier_weight[$i])
- ->where('unit_id',$carrier_weight_unit_id[$i])->first();
- if($waybillPriceModel)return $waybillPriceModel->id;
- //价格区间为空
- $waybillPriceModelRange=WaybillPriceModel::query()->whereRaw('logistic_id = ? AND city_id = ? AND unit_id = ? AND range_max IS NULL',[$logistic_id,$destination_city_id,$carrier_weight_unit_id[$i]])->first();
- if ($waybillPriceModelRange){ return $waybillPriceModelRange->id;}
- //城市为空
- $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->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->parent_id ?? 0,$carrier_weight_unit_id[$i]])->first();
- if ($waybillPriceModelProvinceRange){return $waybillPriceModelProvinceRange->id;}
- }
- }
- return false;
- }
- /*三层条件:无优先级,找到第一个直接返回
- * 无论是否为KG||T,计数单位一为KG,计数单位一为T,计数单位二为KG,计数单位二为T
- * 计数一与计数二同时存在取最贵价格:
- * 计数一存在,二不存在:
- * 计数二存在,一不存在:
- * 城市价格区间不为空,城市价格区间都为空,城市为空,价格区间为空
- * */
- 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');
- $carrier_weight_unit_id=$request->input('carrier_weight_unit_id');
- $validatorData=["logistic_id"=>$logistic_id,"destination_city_id"=>$destination_city_id,
- 'carrier_weight'=>$carrier_weight[0],"carrier_weight_unit_id"=>$carrier_weight_unit_id[0],
- "carrier_weight_other"=>$carrier_weight[1],"carrier_weight_unit_id_other"=>$carrier_weight_unit_id[1]];
- if ($logistic_id == 15){
- $flag = 1;
- $validatorData['cargo_name'] = $request->input('cargo_name');
- $validatorData['total_number'] = $request->input('total_number');
- $validatorData['total_weight'] = $request->input('total_weight');
- $validatorData['deliveryType_id'] = $request->input('deliveryType_id');
- $validatorData['order_type'] = $request->input('order_type');
- $validatorData['transport_type'] = $request->input('transport_type');
- $validatorData['pay_type'] = $request->input('pay_type');
- $validatorData['back_sign_bill'] = $request->input('back_sign_bill');
- $validatorData['package_service'] = $request->input('package_service');
- }else $flag = 0;
- $errors=Validator::make($validatorData,[
- 'logistic_id'=>'required|integer',
- 'destination_city_id'=>'required|integer',
- 'carrier_weight'=>'nullable|min:0|numeric|max:999999',
- 'carrier_weight_unit_id'=>'required_with:carrier_weight',
- 'carrier_weight_other'=>'nullable|min:0|numeric|max:999999',
- 'carrier_weight_unit_id_other'=>'required_with:carrier_weight_other',
- 'cargo_name' => $flag ? 'required' : '',
- 'total_number' => $flag ? 'required|min:0|numeric|max:999999' : '',
- 'total_weight' => $flag ? 'required|min:0|numeric|max:999999' : '',
- 'deliveryType_id' => $flag ? 'required' : '',
- 'order_type' => $flag ? 'required' : '',
- 'transport_type' => $flag ? 'required' : '',
- 'pay_type' => $flag ? 'required' : '',
- 'back_sign_bill' => $flag ? 'required' : '',
- 'package_service' => $flag ? 'required' : '',
- ],[
- 'required'=>':attribute 为必填项',
- 'max'=>':attribute 字符过多或输入值过大',
- 'min'=>':attribute 不得为负',
- 'numeric'=>':attribute 应为数字',
- 'unique'=>':attribute 已存在',
- 'required_with'=>':attribute 未填',
- 'integer'=>':attribute 必须为数字',
- ],[
- 'carrier_weight'=>'承运商计数(抛)',
- 'logistic_id'=>'承运商',
- 'destination_city_id'=>'目的市',
- 'carrier_weight_unit_id'=>'承运商计数单位',
- 'carrier_weight_other'=>'承运商计数二',
- 'carrier_weight_unit_id_other'=>'承运商计数单位二',
- 'cargo_name' => '货物名称',
- 'total_number' => '总包裹数',
- 'total_weight' => '总重量',
- 'deliveryType_id' => '送货方式',
- 'order_type' => '下单模式',
- 'transport_type' => '运输方式/产品类型',
- 'pay_type' => '支付方式',
- 'back_sign_bill' => '签收回单',
- ])->errors();
- if (count($errors)>0)return ['error'=>$errors];
- $result=$this->checkWaybillPriceModel($logistic_id,$destination_city_id,$carrier_weight,$carrier_weight_unit_id);
- if (!$result){
- //单位为kg,T时
- $unitKG=Unit::query()->where('name','kg')->first();
- $unitT=Unit::query()->where('name','T')->first();
- if ($carrier_weight_unit_id[0]==$unitKG->id){
- $carrier_weight_unit_id[0]=$unitT->id;
- $carrier_weight[0]=$carrier_weight[0]/1000;
- $result=$this->checkWaybillPriceModel($logistic_id,$destination_city_id,$carrier_weight,$carrier_weight_unit_id);
- if ($result)return ['success'=>$result];
- }
- if ($carrier_weight_unit_id[1]==$unitKG->id){
- $carrier_weight_unit_id[1]=$unitT->id;
- $carrier_weight[1]=$carrier_weight[1]/1000;
- $result=$this->checkWaybillPriceModel($logistic_id,$destination_city_id,$carrier_weight,$carrier_weight_unit_id);
- if ($result)return ['success'=>$result];
- }
- if ($carrier_weight_unit_id[0]==$unitT->id){
- $carrier_weight_unit_id[0]=$unitKG->id;
- $carrier_weight[0]=$carrier_weight[0]*1000;
- $result=$this->checkWaybillPriceModel($logistic_id,$destination_city_id,$carrier_weight,$carrier_weight_unit_id);
- if ($result)return ['success'=>$result];
- }
- if ($carrier_weight_unit_id[1]==$unitT->id){
- $carrier_weight_unit_id[1]=$unitKG->id;
- $carrier_weight[1]=$carrier_weight[1]*1000;
- $result=$this->checkWaybillPriceModel($logistic_id,$destination_city_id,$carrier_weight,$carrier_weight_unit_id);
- if ($result)return ['success'=>$result];
- }
- }
- return ['success'=>$result];
- }
- public function waybillUpdate(Request $request, $id){
- if(!Gate::allows('运输管理-编辑')){ return redirect(url('/')); }
- $this->validatorWaybill($request,$id)->validate();
- $data=$request->input();
- $waybill=app('waybillService')->find($id);
- $waybill->fill($data);
- $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::query()->whereRaw('waybill_id = ? and audit_stage = ?',[$id,"运单阶段"])->first();
- if (empty($isAudit)){
- $waybillAuditLog=new WaybillAuditLog([
- 'waybill_id'=>$id,
- 'audit_stage'=>'运单阶段',
- 'user_id'=>Auth::id(),
- ]);
- $waybillAuditLog->save();
- $waybillAuditLog['user']=Auth::user();
- $waybill->status='已审核';
- $result=$waybill->save();
- app('LogService')->log(__METHOD__,__FUNCTION__,json_encode($waybill),Auth::user()['id']);
- return ['success'=>$result,'status'=>$waybill->status,'waybillAuditLog'=>$waybillAuditLog];
- }
- return ['exception'=>'请勿重复审核!'];
- }
- public function waybillEdit($id){
- if(!Gate::allows('运输管理-编辑')){ return redirect(url('/')); }
- $waybill=app('waybillService')->find($id);
- $owners=app("OwnerService")->getIntersectPermitting();
- return view('transport.waybill.waybillEdit',['waybill'=>$waybill,'owners'=>$owners]);
- }
- public function waybillRetreatAudit(Request $request){
- if(!Gate::allows('运输管理-运单-调度')){ return redirect(url('/')); }
- $id=$request->input('id');
- /** @var Model|\stdClass $waybill */
- $waybill=app('waybillService')->find($id);
- $waybillLog = WaybillAuditLog::query()->whereRaw('waybill_id = ? and audit_stage = ?',[$id,"运单阶段"])->delete();
- $waybill->status='待重审';
- return ['success'=>$waybill->save(),'status'=>$waybill->status,"log"=>$waybillLog];
- }
- public function waybillEndAudit(Request $request){
- if(!Gate::allows('运输管理-运单-调度审核')){ return redirect(url('/')); }
- $id=$request->input('id');
- $waybill=Waybill::query()->with(["owner","logistic","originationCity","destinationCity","carType",'priceModel',"amountUnit",
- "warehouseWeightUnit","carrierWeightUnit","warehouseWeightUnitOther","carrierWeightUnitOther"])->find($id);
- if (!$waybill->charge&&!$waybill->collect_fee)return ['exception'=>'收费或到付费用未填!'];
- if ($waybill->charge==0&&$waybill->collect_fee==0)return ['exception'=>'收费与到付费用都为0!'];
- if ($waybill->type=='专线'){
- if (!$waybill->carrier_weight_other||$waybill->carrier_weight_other==0)return ['exception'=>'承运商计重未填或为0!'];
- if (!$waybill->carrier_weight_unit_id_other)return ['exception'=>'承运商计重单位未选!'];
- }
- $isAudit=WaybillAuditLog::query()->whereRaw('waybill_id = ? and audit_stage = ?',[$id,"调度阶段"])->first();
- if (empty($isAudit)){
- $waybillAuditLog=new WaybillAuditLog([
- 'waybill_id'=>$id,
- 'audit_stage'=>'调度阶段',
- 'user_id'=>Auth::id(),
- ]);
- $waybillAuditLog->save();
- $waybillAuditLog['user']=Auth::user();
- if ($waybill->waybill_price_model_id||$waybill->type=='直发车'){
- $waybill->status='已完结';
- $result=$waybill->save();
- $waybillPayoff=WaybillPayoff::query()->where('waybill_id','=',$id)->first();
- $waybillPayoffJson=json_encode($this->createReportData($waybill,$waybillPayoff),JSON_UNESCAPED_UNICODE);
- WaybillFinancialSnapshot::query()->create([
- 'waybill_id'=>$id,
- 'json_content'=>$waybillPayoffJson,
- ]);
- }else{
- $waybill->status='无模型';
- $result=$waybill->save();
- $waybillPayoff=WaybillPayoff::query()->where('waybill_id','=',$id)->first();
- if ($waybillPayoff){
- $waybillPayoffJson=json_encode($this->createReportData($waybill,$waybillPayoff),JSON_UNESCAPED_UNICODE);
- WaybillFinancialExcepted::query()->create([
- 'waybill_id'=>$id,
- 'json_content'=>$waybillPayoffJson,
- ]);
- }
- }
- app("waybillService")->createInstantBill($waybill);
- app('LogService')->log(__METHOD__,__FUNCTION__,$waybillPayoffJson,Auth::id());
- return ['success'=>$result,'status'=>$waybill->status,'waybillAuditLog'=>$waybillAuditLog];
- }
- return ['exception'=>'请勿重复审核!'];
- }
- //生成报表数据
- private function createReportData($waybill,$waybillPayoff){
- /** @var Waybill $waybill */
- $waybill->loadMissing(["order.owner"]);
- return [
- "type"=>$waybill->type,
- "waybill_number"=>$waybill->waybill_number,
- "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->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->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),
- "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 : ''),
- "carrier_weight_other"=>$waybill->carrier_weight_other.($waybill->carrierWeightUnitOther ? $waybill->carrierWeightUnitOther->name : ''),
- "car_type_name"=>$waybill->carType ? $waybill->carType->name : null,
- "fee"=>$waybill->fee,
- "pick_up_fee"=>$waybill->pick_up_fee,
- "other_fee"=>$waybill->other_fee,
- "dispatch_remark"=>$waybill->dispatch_remark,
- "price_model_range_min"=>$waybill->priceModel ? $waybill->priceModel->range_min : null,
- "price_model_range_max"=>$waybill->priceModel ? $waybill->priceModel->range_max : null,
- "price_model_unit_price"=>$waybill->priceModel ? $waybill->priceModel->unit_price : null,
- "price_model_base_fee"=>$waybill->priceModel ? $waybill->priceModel->base_fee : null,
- "price_model_initial_weight"=>$waybill->priceModel ? $waybill->priceModel->initial_weight : null,
- "car_owner_info"=>$waybill->car_owner_info,
- "status"=>$waybill->status,
- "mileage"=>$waybill->mileage,
- 'amount'=>$waybill->amount.($waybill->amountUnit ? $waybill->amountUnit->name : ''),
- "inquire_tel"=>$waybill->inquire_tel,
- "other_charge"=>$waybill->other_charge,
- "other_charge_remark"=>$waybill->other_charge_remark,
- "deliver_at"=>$waybill->deliver_at,
- "created_at"=>$waybill->created_at,
- "auditLog_user_name"=>Auth::user()['name'],
- "total_expense"=>$waybillPayoff->total_expense,
- "total_receivable"=>$waybillPayoff->total_receivable,
- "gross_margin"=>$waybillPayoff->gross_margin,
- "gross_profit_rate"=>$waybillPayoff->gross_profit_rate,
- ];
- }
- public function upload(Request $request){
- $this->gate("运输管理-运单-图片上传");
- $files=$request->file("files");
- if (!$files)$this->error("未传递照片");
- $id=$request->input('id');
- $waybill=Waybill::query()->find($id);
- if (!$waybill)$this->error("未找到该运单!");
- $res = [];
- foreach ($files as $file){
- if (!$file->isValid()){
- return ['success'=>false,'error'=>"找不到照片!"];
- }
- $tmpFile = $file->getRealPath();
- if (! is_uploaded_file($tmpFile)) {
- return ['success'=>false,'error'=>"文件错误!"];
- }
- $fileExtension=$file->getClientOriginalExtension();
- // 5.存储, 生成一个随机文件名
- $fileName = date('ymd').'-'.Uuid::uuid1();//thumbnail common bulky
- $thumbnailName=storage_path('app/public/files/'.$fileName.'-thumbnail.'.$fileExtension);
- $commonName=storage_path('app/public/files/'.$fileName.'-common.'.$fileExtension);
- $bulkyName=storage_path('app/public/files/'.$fileName.'-bulky.'.$fileExtension);
- $result=move_uploaded_file ($tmpFile ,$bulkyName);
- if ($result){
- $img=Image::make($bulkyName);
- if ($img->height() > $img->width())
- $img->heighten(250)->save($commonName);
- else $img->widen(250)->save($commonName);
- $img->heighten(28)->save($thumbnailName);
- /** @var UploadFile|\stdClass $uploadFile */
- $uploadFile=new UploadFile([
- "table_name"=>"waybills",
- "table_id"=>$waybill->id,
- "url"=>'/files/'.$fileName,
- "type"=>$fileExtension,
- ]);
- if ($uploadFile->save())
- app('LogService')->log(__CLASS__,'运输图片上传',json_encode($request),Auth::user()['id']);
- $res[] = $uploadFile;
- }else $this->error("图片存储失败,检查服务器状态");
- }
- $this->success($res);
- }
- //批量上传图片
- 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){
- $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;
- }
- $waybills = Waybill::query()->select("id","source_bill")->whereIn('source_bill',$number)->get();
- foreach (array_diff($number,array_column($waybills->toArray(),"source_bill")) as $diff){
- $errors[] = "“".$diff."”不存在运单";
- unset($images[$mapping[$diff]]);
- }
- $insert = [];
- foreach ($waybills as $waybill){
- $image = $images[$mapping[$waybill->source_bill]];
- $fileName = date('ymd').'-'.Uuid::uuid1();
- $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);
- 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);
- else $img->widen(250)->save($commonName);
- $img->heighten(28)->save($thumbnailName);
- $insert[] = [
- "table_name"=>"waybills",
- "table_id"=>$waybill->id,
- "url"=>'/files/'.$fileName,
- "type"=>strtolower($suffix),
- ];
- }
- if ($insert)UploadFile::query()->insert($insert);
- $waybills->load("uploadFiles");
- $this->success(["errors"=>$errors,"data"=>$waybills]);
- }
- //删除照片
- public function deleteImg(Request $request){
- $this->gate("运输管理-运单-图片删除");
- $query=UploadFile::query()->where('table_name','waybills');
- if ($request->input("url"))$query = $query->where('table_id',$request->input("id"))->where("url",$request->input("url"));
- else $query = $query->whereIn('table_id',$request->input("id"));
- foreach ($query->get() as $uploadFile){
- $bulky=storage_path('app/public/'.$uploadFile->url.'-bulky.'.$uploadFile->type);
- $common=storage_path('app/public/'.$uploadFile->url.'-common.'.$uploadFile->type);
- $thumbnail=storage_path('app/public/'.$uploadFile->url.'-thumbnail.'.$uploadFile->type);
- if (file_exists($bulky) && file_exists($common) && file_exists($thumbnail)){
- unlink($bulky);unlink($common);unlink($thumbnail);
- }
- }
- $query->delete();
- app('LogService')->log(__METHOD__,'图片删除',json_encode($request),Auth::user()['id']);
- $this->success();
- }
- public function export(){
- ini_set('max_execution_time',2500);
- ini_set('memory_limit','1526M');
- $append = \request("append")=='true';
- request()->offsetUnset("append");
- $this->gate('运输管理-运单-查询');
- /** @var Collection $waybills */
- if (request("checkAllSign")){
- request()->offsetUnset("checkAllSign");
- $waybills = app('waybillService')->get(request()->input());
- }else $waybills = app('waybillService')->get(["id"=>request("data")]);
- if ($waybills->count()==0)return "无数据";
- $row = [
- "运单类型", "货主", "上游单号", "wms订单号", "运单号", "运输收费",
- "其他收费", "其他收费备注", "始发地", "目的地","下单备注", "承运商", "承运商单号",
- "仓库计抛", "承运商计抛", "仓库计重", "承运商计重", "车型", "车辆信息",
- "计件", "里程数", "运费(元)", "提货费(元)", "其他费用(元)", "发货时间",
- "调度备注", "附加费","创建时间", "省", "市", "区", "FLUX地址", "FLUX重量", "FLUX数量"
- ];
- $list = [];
- $codes = [];
- $code = '';
- $map = [];
- $waybills->each(function ($waybill,$index)use(&$list,&$codes,&$code,&$map){
- foreach (explode(",",$waybill->wms_bill_number) as $bill){
- $code .= "'".$bill."',";
- $map[$bill] = $index;
- }
- if ($index%800==0){
- $codes[] = rtrim($code,",");
- $code = '';
- }
- $list[] = [
- $waybill->type,
- $waybill->owner->name ?? ($waybill->order->owner->name ?? ""),
- $waybill->source_bill,
- $waybill->wms_bill_number,
- $waybill->waybill_number,
- $waybill->charge,
- $waybill->other_charge,
- $waybill->other_charge_remark,
- $waybill->origination,
- $waybill->destination ?: ($waybill->order->address ?? ''),
- $waybill->ordering_remark,
- $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->subjoin_fee,
- $waybill->created_at->toDateTimeString(),
- "", "", "","",0,0
- ];
- });
- if ($code)$codes[] = rtrim($code,",");
- if ($codes && $append){
- foreach ($codes as $code){
- $sql = <<<SQL
- SELECT H.ORDERNO,SUM(S.GROSSWEIGHT) WEIGHT,SUM(S.QTY) AMOUNT,H.C_ADDRESS1,H.C_DISTRICT,H.C_PROVINCE,H.C_CITY FROM DOC_ORDER_PACKING_SUMMARY S
- LEFT JOIN DOC_ORDER_HEADER H ON S.ORDERNO = H.ORDERNO
- WHERE H.ORDERNO IN ({$code}) GROUP BY H.ORDERNO,H.C_ADDRESS1,H.C_DISTRICT,H.C_PROVINCE,H.C_CITY
- SQL;
- foreach (DB::connection("oracle")->select(DB::raw($sql)) as $summary){
- $list[$map[$summary->orderno]][27] = $summary->c_province;
- $list[$map[$summary->orderno]][28] = $summary->c_city;
- $list[$map[$summary->orderno]][29] = $summary->c_district;
- $list[$map[$summary->orderno]][30] = $summary->c_address1;
- $list[$map[$summary->orderno]][31] = (double)($list[$map[$summary->orderno]][31])+
- (is_numeric($summary->weight) ? $summary->weight : 0);
- $list[$map[$summary->orderno]][32] += $summary->amount;
- }
- }
- }
- return Export::make($row,$list,"运输记录单-".date("YmdH"));
- }
- public function deliveringExport(Request $request){
- if ($request->checkAllSign){
- $param = $request->input();
- unset($param['checkAllSign']);
- $sql = app('waybillService')->getDeliveringSql($param);
- }else{
- $sql = app('waybillService')->getDeliveringSql(['id'=>$request->data]);
- }
- $e = new Export();
- $e->setMysqlConnection(config('database.connections.mysql.host'),
- config('database.connections.mysql.port'),config('database.connections.mysql.database')
- ,config('database.connections.mysql.username'),config('database.connections.mysql.password'));
- $e->setFileName("发运报表");
- return $e->sql($sql,[
- "created_at"=>"日期","carrier_name"=>"承运商",
- "waybill_number"=>"宝时运单号","origination"=>"提货仓",
- "owner_name"=>"货主","warehouse_weight_other"=>"预估重量",
- "warehouse_weight"=>"预估体积","status"=>"状态",
- "carrier_bill"=>"专线运单号","inquire_tel"=>"查件电话",
- "amount"=>"件数","carrier_weight_other"=>"重量",
- "carrier_weight"=>"体积"
- ])->direct();
- }
- private function deliveringQuery(Request $request): Builder
- {
- $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();
- $carrierIds=array_column($carriersUsers->toArray(),'logistic_id');
- if ($carrierIds)$waybills->whereIn("logistic_id",$carrierIds);
- }
- $searchText = $request->get("searchText","");
- if ($searchText)$waybills->where(function ($query)use($searchText){
- $query->where("waybill_number",'like','%'.$searchText.'%')->orWhere("carrier_bill",'like','%'.$searchText.'%');
- });
- $lastId = $request->get("lastId","");
- if ($lastId)$waybills->where("id","<",$lastId);
- $deliverAt = $request->get("deliverAt");
- if ($deliverAt)$waybills->where("deliver_at",$deliverAt);
- $date = $request->get("date");
- if ($date)$waybills->where("deliver_at",'like',$date."%");
- return $waybills;
- }
- //发运
- public function delivering(Request $request){
- $groups = $this->deliveringQuery($request)->selectRaw("date_format(deliver_at, '%Y-%m-%d') date,sum(pick_up_fee) pick_up_fee_total")
- ->orderByDesc(DB::raw("date"))->groupByRaw("date")->get();
- $searchText = $request->get("searchText","");
- return view('transport.waybill.delivering',compact('groups',"searchText"));
- }
- /**
- * 懒加载发运数据
- */
- public function loadData(Request $request)
- {
- if (!Auth::user())$this->error("登录信息失效");
- $this->success($this->deliveringQuery($request)->orderByDesc("id")->get());
- }
- //承运商提交
- public function storeCarrierBill(Request $request){
- if(!Gate::allows("运输管理-承运商调度"))return ["error"=>"无权操作!"];
- $errors=Validator::make($request->input(),[
- 'id'=>'required|integer',
- 'carrier_bill'=>'required',
- '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',
- ],[
- 'required'=>':attribute 为必填项',
- 'integer'=>':attribute 应为整数',
- 'numeric'=>':attribute 应为数字',
- 'required_with'=>':attribute 重量与体积至少存在一项',
- ],[
- '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($request->input("amount_unit_name"));
- $unit2 = app("UnitService")->getUnit("m³");
- $waybill=Waybill::query()->find($request->input('id'));
- if (!$waybill)return ["error"=>"未找到该运单!"];
- $request->offsetSet("carrier_weight_unit_id",$unit2->id);
- $request->offsetSet("carrier_weight_unit_id_other",$unit->id);
- $request->offsetSet("amount_unit_id",$unit1->id);
- $request->offsetSet("status","待终审");
- $waybill->fill($request->input());
- WaybillAuditLog::query()->create([
- 'waybill_id'=>$waybill->id,
- 'audit_stage'=>'调度阶段',
- 'user_id'=>Auth::id(),
- ]);
- $waybill->update();
- return $waybill;
- }
- protected function validatorWaybill(Request $request,$id){
- if ($id){$wms_bill_number=$id;};
- return Validator::make($request->input(),[
- '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_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 输入有误',
- 'integer'=>':attribute 应为整数',
- 'min'=>':attribute 不得为负',
- 'numeric'=>':attribute 应为数字',
- 'unique'=>':attribute 已存在',
- ],[
- 'owner_id'=>'货主',
- 'wms_bill_number'=>'WMS单号',
- 'origination'=>'始发地',
- 'destination'=>'目的地',
- 'recipient'=>'收件人',
- 'recipient_mobile'=>'收件人电话',
- 'charge'=>'收费',
- 'collect_fee'=>'到付金额',
- ]);
- }
- protected function validatorWaybillDispatch(Request $request,$id){
- $rule=[
- 'logistic_id'=>'required_without:order_id|integer',
- 'carrier_bill'=>"sometimes|required|max:50|unique:waybills,carrier_bill,$id",
- 'fee'=>'sometimes|nullable|min:0|numeric|max:999999',
- 'inquire_tel'=>'required',
- 'carType_id'=>'sometimes|required|integer',
- 'other_fee'=>'sometimes|nullable|min:0|numeric|max:999999',
- 'charge'=>'sometimes|nullable|min:0|numeric|max:999999',
- 'mileage'=>'nullable|numeric|min:0',
- 'amount'=>'numeric|min:0',
- 'amount_unit_id'=>'required',
- 'origination_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',
- 'warehouse_weight'=>'sometimes|nullable|min:0|numeric|max:999999',
- 'warehouse_weight_unit_id'=>'sometimes|required_with:warehouse_weight|nullable|integer',
- 'carrier_weight'=>'sometimes|nullable|min:0|numeric|max:999999',
- 'carrier_weight_unit_id'=>'sometimes|required_with:carrier_weight',
- 'carrier_weight_other'=>'sometimes|nullable|min:0|numeric|max:999999',
- 'carrier_weight_unit_id_other'=>'sometimes|required_with:carrier_weight_other',
- 'deliver_at_date'=>'required',
- ];
- if ($request->type == '专线'){
- $rule['origination_city_id']='required|integer';
- $rule['destination_city_id']='required_without:order_id|integer';
- }
- return Validator::make($request->input(),$rule,[
- 'required'=>':attribute 为必填项',
- 'required_without'=>':attribute 为必填项',
- 'alpha_num'=>':attribute 应为字母或数字',
- 'max'=>':attribute 字符过多或输入值过大',
- 'min'=>':attribute 不得为负',
- 'numeric'=>':attribute 应为数字',
- 'unique'=>':attribute 已存在',
- 'required_with'=>':attribute 未填',
- 'integer'=>':attribute 必须为数字',
- ],[
- 'logistic_id'=>'承运商',
- 'inquire_tel'=>'查件电话',
- 'carrier_bill'=>'承运商单号',
- 'fee'=>'运费',
- 'other_fee'=>'其他费用',
- 'charge'=>'收费',
- 'mileage'=>'里程数',
- 'amount'=>'计数',
- 'amount_unit_id'=>'计数单位',
- 'warehouse_weight'=>'仓库计数(抛)',
- 'carrier_weight'=>'承运商计数(抛)',
- 'pick_up_fee'=>'提货费',
- 'destination_city_id'=>'目的市',
- 'carrier_weight_unit_id'=>'承运商计数单位',
- 'warehouse_weight_unit_id'=>'仓库计数单位',
- 'warehouse_weight_other'=>'仓库计数二',
- 'carrier_weight_other'=>'承运商计数二',
- 'warehouse_weight_unit_id_other'=>'仓库技数单位二',
- 'carrier_weight_unit_id_other'=>'承运商计数单位二',
- 'deliver_at_date'=>'发货日期',
- ]);
- }
- 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);
- }
- // 运单删除 软删除
- 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();
- WaybillAuditLog::query()->create([
- 'waybill_id'=>$id,
- 'audit_stage'=>'删除运单',
- 'user_id'=>Auth::id(),
- ]);
- return ['success'=>$result,'status'=>$result];
- }
- // 回收站
- public function recycle(Request $request){
- if(!Gate::allows('运输管理-运单-删除')){return redirect('/');}
- $paginate = $request->input('paginate')??50;
- /** @var Collection $waybills */
- $waybills = Waybill::query()->with(['owner','order.owner','logistic','amountUnit','warehouseWeightUnit','carrierWeightUnit',
- 'warehouseWeightUnitOther','carrierWeightUnitOther','carType','waybillAuditLogs' => function ($query) {
- /** @var Builder $query */
- $query->with('user');
- }])->orderBy('deleted_at', 'DESC')->withTrashed()->whereNotNull('deleted_at')->paginate(50);
- $total = $waybills->count();
- $paginateParams = [];
- $paginateParams['paginate'] = $paginate;
- return view('transport.waybill.recycle',compact('waybills','total','paginateParams'));
- }
- // 软删除恢复
- public function apiRestoreSelected(Request $request){
- 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();
- $waybills->each(function (Waybill $waybill){
- $waybill->restore();
- });
- app('LogService')->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
- foreach ($ids as $id) WaybillAuditLog::query()->create([
- 'waybill_id'=>$id,
- 'audit_stage'=>'恢复运单',
- 'user_id'=>Auth::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]);
- app('LogService')->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
- return ['success'=>$result,'status'=>$result];
- }
- // 修改运输收费
- public function changeCharge(Request $request){
- if(!Gate::allows('运输管理-运单-运单编辑')){return ['success'=>'false','fail_info'=>'没有权限'];}
- $wayBillId = $request->id;
- $waybillCharge = $request->input('charge');
- if(is_null($wayBillId) or is_null($waybillCharge)){
- return ['success'=>'false','fail_info'=>'参数异常'];
- }
- $result = Waybill::where('id',$wayBillId)->update(['charge'=>$waybillCharge]);
- app('LogService')->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);
- if(count($wayontop->get()) == 0){
- $wayontop = WaybillOnTop::create(['waybill_id'=>$id,'remark'=>$detail]);
- $result = $wayontop->save();
- }else{
- $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 refreshWaveHouseWeight(Request $request){
- $wms_bill_number=$request->input('wms_bill_number');
- if(is_null($wms_bill_number)) return ['success'=>false,'fail_info'=>'传参错误'];
- $waybills=DB::connection('oracle')->table('DOC_ORDER_DETAILS')->where('orderno',$wms_bill_number)->get();
- if($waybills->isEmpty()) return ['success'=>false,'fail_info'=>'传参错误'];
- $warehouseWeight=0;
- foreach ($waybills as $waybill){
- if ($waybill->grossweight) $warehouseWeight += $waybill->grossweight;
- if (!$waybill->grossweight&& $waybill->netweight) $warehouseWeight +=$waybill->netweight;
- }
- $warehouseWeight=round($warehouseWeight,2);
- $waybill=Waybill::where('wms_bill_number',$wms_bill_number)->first();
- if ($warehouseWeight!=0){
- if ($waybill['warehouse_weight_other']!=$warehouseWeight){
- $waybill['warehouse_weight_other']=$warehouseWeight;
- $waybill->update();
- app('LogService')->log(__METHOD__,'刷新仓库计重'.__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
- }
- }else{
- $warehouseWeight=$waybill['warehouse_weight_other'];
- }
- 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);
- }
- //按日输入专线费
- public function dailyBilling(Request $request): array
- {
- if(!Gate::allows('运输管理-运单-按日计算专线费')
- && !Gate::allows('运输管理-承运商调度')){return ['success'=>false,'message'=>'没有权限'];}
- $dailyBilling=$request->input('param');
- $waybills=app('waybillService')->dailyBilling($dailyBilling);
- if ($waybills===0)return ['success'=>false,'message'=>'请输入相应的发货日期和费用!'];
- if ($waybills===1)return ['success'=>false,'message'=>'当前选定发货日期没有任何记录'];
- if (!isset($waybills))return ['success'=>false,'message'=>'该日有记录未填写重量'];
- return ['success'=>true,'data'=>$waybills];
- }
- public function countPickUpFee(Request $request): array
- {
- if(!Gate::allows('运输管理-运单-查询')){ return ['success'=>false,'message'=>'没有权限']; }
- $param=$request->input('param');
- $waybills=app('waybillService')->get($param);
- $total_pick_up_fee=$waybills->sum('pick_up_fee');
- if ($total_pick_up_fee)$total_pick_up_fee=round($total_pick_up_fee);
- return ['success'=>true,'data'=>$total_pick_up_fee];
- }
- /**
- * 运单合并
- */
- public function waybillMerge(Request $request)
- {
- $this->gate("运输管理-编辑");
- $ids = $request->input("ids");
- if (!$ids || count($ids)<2)$this->error("至少选择两条记录");
- /** @var Collection $waybills */
- $waybills = Waybill::query()->with("order")->whereIn("id",$ids)->orderBy("order_id")->get();
- if ($waybills->count()<2)$this->error("运单不存在");
- $waybill = $waybills->first();
- $destroys = [];
- $owner = [$waybill->owner_id];
- if (array_search($waybill->status,["未审核","已审核","待终审"])===false)$this->error("运单禁止合并");
- $remark = [];
- if ($waybill->ordering_remark)$remark[] = $waybill->ordering_remark;
- 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)) ||
- (!$waybill->order && ($waybills[$i]->recipient!=$waybill->recipient
- || $waybills[$i]->recipient_mobile!=$waybill->recipient_mobile
- || $waybills[$i]->destination!=$waybill->destination));
- if (array_search($waybills[$i]->status,["未审核","已审核","待终审"])===false
- || $identical)$this->error("信息不一致,无法进行合并");
- $destroys[] = $waybills[$i]->id;
- $waybill->source_bill .= $waybills[$i]->source_bill ? ",".$waybills[$i]->source_bill : '';
- $waybill->wms_bill_number .= $waybills[$i]->wms_bill_number ? ",".$waybills[$i]->wms_bill_number : '';
- $waybill->charge += (double)$waybills[$i]->charge;
- $waybill->collect_fee += (double)$waybills[$i]->collect_fee;
- $waybill->other_fee += (double)$waybills[$i]->other_fee;
- $waybill->warehouse_weight_other += (double)$waybills[$i]->warehouse_weight_other;
- $waybill->warehouse_weight += (double)$waybills[$i]->warehouse_weight;
- if ($waybills[$i]->ordering_remark)$remark[] = $waybills[$i]->ordering_remark;
- $owner[] = $waybills[$i]->owner_id;
- }
- $waybill->ordering_remark = implode(",",array_unique($remark));
- if (strlen($waybill->source_bill)>191 || strlen($waybill->wms_bill_number)>191)$this->error("单号超长,无法合并");
- $owner = array_unique($owner);
- if (count($owner)>1)$waybill->merge_owner = implode(',',$owner);
- $waybill->update();
- Waybill::destroy($destroys);
- WaybillAuditLog::query()->create([
- 'waybill_id'=>$waybill->id,
- 'audit_stage'=>'合并运单',
- 'user_id'=>Auth::id(),
- ]);
- $this->success($waybill->waybill_number);
- }
- /**
- * 运单拆分
- */
- public function waybillSplit(Request $request)
- {
- $this->gate("运输管理-编辑");
- $ids = $request->input("ids");
- DB::beginTransaction();
- try {
- /** @var Collection $waybills */
- $waybills = Waybill::query()->whereHas("waybillAuditLogs",function ($query){
- $query->where("audit_stage","合并运单");
- })->whereIn("id",$ids)->get();
- if ($waybills->count()==0)$this->error("运单不存在或非合并运单");
- foreach ($waybills as $waybill)$this->split($waybill);
- DB::commit();
- }catch (\Exception $e){
- DB::rollBack();
- $this->error($e->getMessage());
- }
- $this->success(count($ids)==$waybills->count() ? '运单拆单完毕' : '部分运单不符合拆单条件');
- }
- private function split($waybill)
- {
- $codes = explode(",",$waybill->wms_bill_number);
- if (!$codes || count($codes)<2)return;
- $bills = explode(",",$waybill->source_bill);
- $remark = explode(",",$waybill->ordering_remark);
- /** @var Collection $waybills */
- $waybills = Waybill::onlyTrashed()->whereIn("wms_bill_number",$codes)->get();
- if (!$waybills->count())return;
- foreach ($waybills as $obj){
- unset($codes[array_search($obj->wms_bill_number,$codes)]);
- unset($bills[array_search($obj->source_bill,$bills)]);
- if (array_search($obj->ordering_remark,$remark)===false)unset($bills[array_search($obj->ordering_remark,$remark)]);
- $waybill->charge -= (double)$obj->charge;
- $waybill->collect_fee -= (double)$obj->collect_fee;
- $waybill->other_fee -= (double)$obj->other_fee;
- $waybill->warehouse_weight_other -= (double)$obj->warehouse_weight_other;
- $waybill->warehouse_weight -= (double)$obj->warehouse_weight;
- }
- Waybill::onlyTrashed()->whereIn("wms_bill_number",explode(",",$waybill->wms_bill_number))->restore();
- $waybill->merge_owner = null;
- $waybill->source_bill = implode(",",$bills);
- $waybill->wms_bill_number = implode(",",$codes);
- $waybill->ordering_remark = implode(",",$remark);
- $waybill->update();
- WaybillAuditLog::query()->create([
- 'waybill_id'=>$waybill->id,
- 'audit_stage'=>'拆单返回',
- 'user_id'=>Auth::id(),
- ]);
- }
- /**
- * 快递面单打印 :暂时支持 德邦
- */
- public function expressFaceList(Request $request)
- {
- $this->gate("运输管理-编辑");
- $ids = $request->input("ids");
- try {
- /** @var Collection $waybills */
- $waybills = Waybill::query()->where('type','德邦物流')
- ->whereIn("id",$ids)
- ->get();
- if ($waybills->count()==0)$this->error("运单不存在或运单类型不正确");
- foreach ($waybills as $waybill){
- $waybill->loadMissing([
- "order.shop","destinationCity","owner","order.warehouse.province","order.warehouse.city","order.warehouse.county","deliveryType"
- ]);
- }
- }catch (\Exception $e){
- $this->error($e->getMessage());
- }
- if (count($ids)==$waybills->count())$this->success($waybills );
- $this->error('非德邦快递不可打印');
- }
- public function changeExpressTag(Request $request)
- {
- $this->gate("运输管理-编辑");
- $id = $request->input("id");
- try {
- $row = Waybill::where('waybill_number',$id)->update(['express_face_list'=>1, 'updated_at'=>date('Y-m-d H:i:s')]);
- if ($row) $this->success('打印成功');
- }catch (\Exception $e){
- $this->error($e->getMessage());
- }
- $this->error('打印失败');
- }
- /**
- * 运输发货在PC-APP上临时入口
- */
- public function shipment()
- {
- $logistics = app("LogisticService")->getSelection(['id','name','tag'],"物流");
- return view("transport.waybill.android.shipment",compact("logistics"));
- }
- /**
- * 发货与合并
- */
- public function shipmentAndMerge()
- {
- $this->gate("运输管理-编辑");
- if (!\request("logistic"))$this->error("未选择承运商");
- $waybill = Waybill::query()->with("waybillAuditLogs:waybill_id,audit_stage")->where("waybill_number",\request("waybill"))
- ->whereNotIn("status",["已完结","无模型"])->first();
- if (!$waybill)$this->error("运单禁止操作");
- if ($waybill->deliver_at){
- if ($waybill->waybillAuditLogs->where("audit_stage","单独发货")->count())$this->split($waybill);
- else if(!$waybill->waybillAuditLogs->where("audit_stage","合单发货")->count())
- $this->error("运单已发货,请勿重复调配");
- }
- $codes = explode("\n",\request("order"));
- $waybills = Waybill::query()->whereIn("wms_bill_number",$codes)
- ->where("id","!=",$waybill->id)
- ->whereNull("deliver_at")
- ->whereNotIn("status",["已完结","无模型"])->get();
- if ($waybills->count()){
- if ($waybills->count()<count($codes)-1)$this->error("存在非法订单");
- $destroys = [];
- $owner = [$waybill->owner_id];
- foreach ($waybills as $item){
- //信息一致性校验
- $identical = ($waybill->order && ($item->order->consignee_name!=$waybill->order->consignee_name
- || $item->order->consignee_phone!=$waybill->order->consignee_phone)) ||
- (!$waybill->order && ($item->recipient!=$waybill->recipient
- || $item->recipient_mobile!=$waybill->recipient_mobile));
- if ($identical)$this->error("订单信息不一致,无法统一发货");
- $destroys[] = $item->id;
- $waybill->source_bill .= $item->source_bill ? ",".$item->source_bill : '';
- $waybill->wms_bill_number .= $item->wms_bill_number ? ",".$item->wms_bill_number : '';
- $waybill->charge += (double)$item->charge;
- $waybill->collect_fee += (double)$item->collect_fee;
- $waybill->other_fee += (double)$item->other_fee;
- $waybill->warehouse_weight_other += (double)$item->warehouse_weight_other;
- $waybill->warehouse_weight += (double)$item->warehouse_weight;
- $waybill->ordering_remark = $waybill->ordering_remark ? $waybill->ordering_remark.",".$item->ordering_remark : $item->ordering_remark;
- $owner[] = $item->owner_id;
- }
- if (strlen($waybill->source_bill)>191 || strlen($waybill->wms_bill_number)>191)$this->error("单号超长,无法合并");
- $owner = array_unique($owner);
- if (count($owner)>1)$waybill->merge_owner = implode(',',$owner);
- $waybill->deliver_at = date("Y-m-d H:i:s");
- $waybill->logistic_id = \request("logistic");
- if ($waybill->status=='未审核')$waybill->status = '已审核';
- $waybill->update();
- Waybill::destroy($destroys);
- WaybillAuditLog::query()->create([
- 'waybill_id'=>$waybill->id,
- 'audit_stage'=>'合单发货',
- 'user_id'=>Auth::id(),
- ]);
- }else{
- WaybillAuditLog::query()->create([
- 'waybill_id'=>$waybill->id,
- 'audit_stage'=>'单独发货',
- 'user_id'=>Auth::id(),
- ]);
- $update = ["deliver_at"=>date("Y-m-d H:i:s"),"logistic_id"=>\request("logistic")];
- if ($waybill->status=='未审核')$update["status"] = '已审核';
- $waybill->update($update);
- }
- $this->success();
- }
- /**
- * 运输发货在PC-APP上临时入口
- */
- public function waybillDispatch()
- {
- return view("transport.waybill.android.dispatch");
- }
- /**
- * 搜索运单获取信息
- */
- public function searchWaybill()
- {
- $this->success($this->dispatchCheck(\request("bill")));
- }
- private function dispatchCheck($bill)
- {
- if (!$bill)$this->error("参数异常");
- $waybill = Waybill::query()->select(["id","carrier_bill","inquire_tel","carrier_weight_other","carrier_weight","amount","deliver_at"])
- ->where("waybill_number",$bill)->whereNotIn("status",["已完结","无模型"])->first();
- if(!$waybill)$this->error("非法运单号");
- if ($waybill->carrier_bill)$this->error("运单已发货,请勿重复调配");
- if (!$waybill->deliver_at)$this->error("运单未发货,无法调配");
- return $waybill;
- }
- /**
- * 调配
- *
- */
- public function dispatchSubmit()
- {
- $this->gate("运输管理-编辑");
- if (!\request("waybill") || !\request("phone")
- || !\request("volume") || !\request("weight") || !\request("amount"))$this->error("非法参数");
- $waybill = $this->dispatchCheck(\request("waybill"));
- $unit = app("UnitService")->getUnit("kg");
- $unit1 = app("UnitService")->getUnit("件");
- $waybill->update([
- "carrier_bill" => \request("waybill"),
- "inquire_tel" => \request("phone"),
- "carrier_weight_other" => \request("volume"),
- "carrier_weight" => \request("weight"),
- "amount" => \request("amount"),
- "amount_unit_id" => $unit->id,
- "carrier_weight_unit_id" => $unit->id,
- "carrier_weight_unit_id_other" => $unit1->id,
- ]);
- WaybillAuditLog::query()->create([
- 'waybill_id'=>$waybill->id,
- 'audit_stage'=>'调度阶段',
- 'user_id'=>Auth::id(),
- ]);
- $this->success();
- }
- public function appendSubjoinFee()
- {
- $this->gate("运输管理-承运商调度");
- $id = \request("id");
- $subjoinFee = \request("subjoinFee");
- if (!$id || !$subjoinFee)$this->error("非法参数");
- if (Waybill::query()->where("id",$id)->update(["subjoin_fee"=>$subjoinFee]) == 0)$this->error("修改失败,运单信息发送变更");
- LogService::log("运输附加费","调度商添加","录入人:".Auth::id()." | 修改{$id}费用为:".$subjoinFee);
- $this->success();
- }
- }
|