|
@@ -3,9 +3,11 @@
|
|
|
namespace App\Http\Controllers;
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Imports\ExpressImport;
|
|
use App\Imports\ExpressImport;
|
|
|
|
|
+use App\Imports\OwnerPriceDirectLogisticDetailImport;
|
|
|
use App\Imports\OwnerPriceLogisticDetailImport;
|
|
use App\Imports\OwnerPriceLogisticDetailImport;
|
|
|
use App\Owner;
|
|
use App\Owner;
|
|
|
use App\OwnerOutStorageRule;
|
|
use App\OwnerOutStorageRule;
|
|
|
|
|
+use App\OwnerPriceDirectLogistic;
|
|
|
use App\OwnerPriceExpress;
|
|
use App\OwnerPriceExpress;
|
|
|
use App\OwnerPriceExpressProvince;
|
|
use App\OwnerPriceExpressProvince;
|
|
|
use App\OwnerPriceLogistic;
|
|
use App\OwnerPriceLogistic;
|
|
@@ -591,7 +593,7 @@ class PriceModelController extends Controller
|
|
|
|
|
|
|
|
public function expressExport($id)
|
|
public function expressExport($id)
|
|
|
{
|
|
{
|
|
|
- if(!Gate::allows('计费模型-物流-查询')){ return ["success"=>false,"data"=>"无权操作"]; }
|
|
|
|
|
|
|
+ if(!Gate::allows('计费模型-快递-查询')){ return ["success"=>false,"data"=>"无权操作"]; }
|
|
|
$model = app("OwnerPriceExpressService")->find($id,[
|
|
$model = app("OwnerPriceExpressService")->find($id,[
|
|
|
"owners","logistics","initialWeightUnit","additionalWeightUnit","details"=>function($query){
|
|
"owners","logistics","initialWeightUnit","additionalWeightUnit","details"=>function($query){
|
|
|
/** @var Builder $query */
|
|
/** @var Builder $query */
|
|
@@ -634,6 +636,55 @@ class PriceModelController extends Controller
|
|
|
return ["success"=>false,"data"=>"导入发生错误,数据无响应"];
|
|
return ["success"=>false,"data"=>"导入发生错误,数据无响应"];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public function logisticExport($id)
|
|
|
|
|
+ {
|
|
|
|
|
+ if(!Gate::allows('计费模型-物流-查询')){ return ["success"=>false,"data"=>"无权操作"]; }
|
|
|
|
|
+ $model = app("OwnerPriceLogisticService")->find($id,[
|
|
|
|
|
+ "owners","logistics","unit","otherUnit","details"=>function($query){
|
|
|
|
|
+ /** @var Builder $query */
|
|
|
|
|
+ $query->with(["province","unit","city"]);
|
|
|
|
|
+ }]);
|
|
|
|
|
+ $row = ["客户","价格名称",
|
|
|
|
|
+ "单位一区间/".($model->unit ? $model->unit->name : ''),
|
|
|
|
|
+ "单位二区间/".($model->otherUnit ? $model->otherUnit->name : ''),
|
|
|
|
|
+ "提货费","燃油附加费","信息服务费","创建时间","承运商"];
|
|
|
|
|
+ $range = "";
|
|
|
|
|
+ foreach (explode(",",$model->unit_range) as $str){
|
|
|
|
|
+ $range .= $str."\r\n";
|
|
|
|
|
+ }
|
|
|
|
|
+ $otherRange = "";
|
|
|
|
|
+ foreach (explode(",",$model->other_unit_range) as $str){
|
|
|
|
|
+ $otherRange .= $str."\r\n";
|
|
|
|
|
+ }
|
|
|
|
|
+ $list = [[
|
|
|
|
|
+ implode(",",array_column($model->owners->toArray(),"name")),
|
|
|
|
|
+ $model->name,
|
|
|
|
|
+ $range,
|
|
|
|
|
+ $otherRange,
|
|
|
|
|
+ $model->pick_up_price,
|
|
|
|
|
+ $model->fuel_price,
|
|
|
|
|
+ $model->service_price,
|
|
|
|
|
+ $model->created_at,
|
|
|
|
|
+ implode(",",array_column($model->logistics->toArray(),"name")),
|
|
|
|
|
+ ],[
|
|
|
|
|
+ "单位","区间","省份","市","单价","送货费","起始计费","起始计数","费率"
|
|
|
|
|
+ ]];
|
|
|
|
|
+ foreach ($model->details as $detail){
|
|
|
|
|
+ $list[] = [
|
|
|
|
|
+ $detail->unit ? $detail->unit->name : '',
|
|
|
|
|
+ $detail->range,
|
|
|
|
|
+ $detail->province ? $detail->province->name : '',
|
|
|
|
|
+ $detail->city ? $detail->city->name : '',
|
|
|
|
|
+ $detail->unit_price,
|
|
|
|
|
+ $detail->delivery_fee,
|
|
|
|
|
+ $detail->initial_fee,
|
|
|
|
|
+ $detail->initial_amount,
|
|
|
|
|
+ $detail->rate ? $detail->rate."%" : '',
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+ return app(ExportService::class)->json($row,$list,"物流计费模型");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public function logisticUpdateDetail(Request $request)
|
|
public function logisticUpdateDetail(Request $request)
|
|
|
{
|
|
{
|
|
|
if(!Gate::allows('计费模型-物流-编辑')){ return ["success"=>false,"data"=>"无权操作"]; }
|
|
if(!Gate::allows('计费模型-物流-编辑')){ return ["success"=>false,"data"=>"无权操作"]; }
|
|
@@ -718,17 +769,145 @@ class PriceModelController extends Controller
|
|
|
|
|
|
|
|
public function directLogisticIndex(){
|
|
public function directLogisticIndex(){
|
|
|
if(!Gate::allows('计费模型-直发-查询')){ return redirect('denied'); }
|
|
if(!Gate::allows('计费模型-直发-查询')){ return redirect('denied'); }
|
|
|
- return response()->view('maintenance.priceModel.directLogistic.index');
|
|
|
|
|
|
|
+ $models = app("OwnerPriceDirectLogisticService")->paginate();
|
|
|
|
|
+ return response()->view('maintenance.priceModel.directLogistic.index',compact("models"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function directLogisticCreate(){
|
|
public function directLogisticCreate(){
|
|
|
if(!Gate::allows('计费模型-直发-录入')){ return redirect('denied'); }
|
|
if(!Gate::allows('计费模型-直发-录入')){ return redirect('denied'); }
|
|
|
- return response()->view('maintenance.priceModel.directLogistic.create');
|
|
|
|
|
|
|
+ $owners = app("OwnerService")->getSelection();
|
|
|
|
|
+ return response()->view('maintenance.priceModel.directLogistic.create',compact("owners"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function directLogisticStore(Request $request)
|
|
public function directLogisticStore(Request $request)
|
|
|
{
|
|
{
|
|
|
if(!Gate::allows('计费模型-直发-录入')){ return redirect('denied'); }
|
|
if(!Gate::allows('计费模型-直发-录入')){ return redirect('denied'); }
|
|
|
|
|
+ $request->offsetSet("owner_id",explode(",",$request->input("owner_id")));
|
|
|
|
|
+ $this->directLogisticValidator($request->input())->validate();
|
|
|
|
|
+ /** @var OwnerPriceDirectLogistic $model */
|
|
|
|
|
+ $model = app("OwnerPriceDirectLogisticService")->create([
|
|
|
|
|
+ "name" => $request->input("name"),
|
|
|
|
|
+ "base_km" => $request->input("base_km"),
|
|
|
|
|
+ ]);
|
|
|
|
|
+ $model->owners()->sync($request->input("owner_id"));
|
|
|
|
|
+ return response()->redirectTo("maintenance/priceModel/directLogistic")->with("successTip","创建“".$request->input("name")."”成功");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function directLogisticDestroy($id)
|
|
|
|
|
+ {
|
|
|
|
|
+ if(!Gate::allows('计费模型-直发-删除')){ return ["success"=>false,"data"=>"无权操作"]; }
|
|
|
|
|
+ $row = app("OwnerPriceDirectLogisticService")->destroy($id);
|
|
|
|
|
+ if ($row == 1)return ["success"=>true];
|
|
|
|
|
+ return ["success"=>false,"data"=>"影响了“".$row."”行"];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function directLogisticEdit($id)
|
|
|
|
|
+ {
|
|
|
|
|
+ if(!Gate::allows('计费模型-直发-编辑')){ return redirect('denied'); }
|
|
|
|
|
+ $owners = app("OwnerService")->getSelection();
|
|
|
|
|
+ $model = app("OwnerPriceDirectLogisticService")->find($id)->append("owner_id");
|
|
|
|
|
+ return response()->view('maintenance.priceModel.directLogistic.create',compact("model","owners"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function directLogisticUpdate($id, Request $request)
|
|
|
|
|
+ {
|
|
|
|
|
+ if(!Gate::allows('计费模型-直发-编辑')){ return redirect('denied'); }
|
|
|
|
|
+ $request->offsetSet("owner_id",explode(",",$request->input("owner_id")));
|
|
|
|
|
+ $this->directLogisticValidator($request->input(),$id)->validate();
|
|
|
|
|
+ app("OwnerPriceDirectLogisticService")->update(["id"=>$id],[
|
|
|
|
|
+ "name" => $request->input("name"),
|
|
|
|
|
+ "base_km" => $request->input("base_km"),
|
|
|
|
|
+ ]);
|
|
|
|
|
+ $model = new OwnerPriceDirectLogistic();
|
|
|
|
|
+ $model->id = $id;
|
|
|
|
|
+ $model->owners()->sync($request->input("owner_id"));
|
|
|
|
|
+ return response()->redirectTo("maintenance/priceModel/directLogistic")->with("successTip","修改“".$request->input("name")."”成功");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function directLogisticGetDetail(Request $request)
|
|
|
|
|
+ {
|
|
|
|
|
+ if(!Gate::allows('计费模型-直发-查询')){ return ["success"=>false,"data"=>"无权操作"]; }
|
|
|
|
|
+ $model = new OwnerPriceDirectLogistic();
|
|
|
|
|
+ $model->id = $request->input("id");
|
|
|
|
|
+ $model->load(["details"=>function($query){
|
|
|
|
|
+ /** @var Builder $query */
|
|
|
|
|
+ $query->with("carType");
|
|
|
|
|
+ }]);
|
|
|
|
|
+ return ["success"=>true,"data"=>$model->details];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function directLogisticImport(Request $request)
|
|
|
|
|
+ {
|
|
|
|
|
+ if(!Gate::allows('计费模型-直发-录入')){ return ["success"=>false,"data"=>"无权操作"]; }
|
|
|
|
|
+ $fileSuffix=$request->file('file')->getClientOriginalExtension();
|
|
|
|
|
+ if ($fileSuffix != 'xlsx' && $fileSuffix != 'xls' && $fileSuffix != 'csv')
|
|
|
|
|
+ return ['success'=>false,'data'=>'不支持该文件类型'];
|
|
|
|
|
+ ini_set('max_execution_time',2500);
|
|
|
|
|
+ ini_set('memory_limit','1526M');
|
|
|
|
|
+ $fileSuffix = ucwords($fileSuffix);
|
|
|
|
|
+ $model = new OwnerPriceDirectLogistic();
|
|
|
|
|
+ $model->id = $request->input("id");
|
|
|
|
|
+ $model->load("details");
|
|
|
|
|
+ Excel::import(new OwnerPriceDirectLogisticDetailImport($model),$request->file('file')->path(),null,$fileSuffix);
|
|
|
|
|
+ if (Cache::has('directLogistic'))return Cache::pull('directLogistic');
|
|
|
|
|
+
|
|
|
|
|
+ return ["success"=>false,"data"=>"导入发生错误,数据无响应"];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function directLogisticUpdateDetail(Request $request)
|
|
|
|
|
+ {
|
|
|
|
|
+ if(!Gate::allows('计费模型-直发-编辑')){ return ["success"=>false,"data"=>"无权操作"]; }
|
|
|
|
|
+ $detail = $request->input("detail");
|
|
|
|
|
+ if ($detail["id"]){
|
|
|
|
|
+ app('OwnerPriceDirectLogisticService')->updateDetail(["id"=>$detail["id"]],[
|
|
|
|
|
+ "base_fee" => $detail["base_fee"],
|
|
|
|
|
+ "additional_fee" => $detail["additional_fee"],
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ $row = app('OwnerPriceDirectLogisticService')->isExistDetail([
|
|
|
|
|
+ "owner_price_direct_logistic_id"=>$request->input("id"),
|
|
|
|
|
+ "car_type_id"=>$detail["car_type_id"],
|
|
|
|
|
+ ]);
|
|
|
|
|
+ if ($row>0)return ["success"=>false,"data"=>"已存在该计费模型"];
|
|
|
|
|
+ /** @var OwnerPriceExpressProvince $detail */
|
|
|
|
|
+ $detail = app('OwnerPriceDirectLogisticService')->createDetail([
|
|
|
|
|
+ "owner_price_direct_logistic_id"=>$request->input("id"),
|
|
|
|
|
+ "car_type_id"=>$detail["car_type_id"],
|
|
|
|
|
+ "base_fee" => $detail["base_fee"],
|
|
|
|
|
+ "additional_fee" => $detail["additional_fee"],
|
|
|
|
|
+ ]);
|
|
|
|
|
+ $detail->load("carType");
|
|
|
|
|
+ }
|
|
|
|
|
+ return ["success"=>true,"data"=>$detail];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function directLogisticDestroyDetail(Request $request)
|
|
|
|
|
+ {
|
|
|
|
|
+ if(!Gate::allows('计费模型-直发-删除')){ return ["success"=>false,"data"=>"无权操作"]; }
|
|
|
|
|
+ $id = $request->input("id");
|
|
|
|
|
+ if (!$id)return ["success"=>false,"data"=>"非法参数"];
|
|
|
|
|
+ app("OwnerPriceDirectLogisticService")->destroyDetail($id);
|
|
|
|
|
+ return ["success"=>true];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function directLogisticValidator(array $params, $id= null)
|
|
|
|
|
+ {
|
|
|
|
|
+ return Validator::make($params,[
|
|
|
|
|
+ 'name'=>['required',$id?"unique:owner_price_direct_logistics,name,$id":'unique:owner_price_direct_logistics,name'],
|
|
|
|
|
+ 'base_km'=>['required','numeric','min:0'],
|
|
|
|
|
+ 'owner_id'=>[function ($attribute, $value, $fail)use($id) {
|
|
|
|
|
+ $owners = app("OwnerPriceDirectLogisticService")->getExistOwnerName($value,$id);
|
|
|
|
|
+ if ($owners)$fail("(".implode(',',$owners).') 已经绑定直发计费模型');
|
|
|
|
|
+ }],
|
|
|
|
|
+ ],[
|
|
|
|
|
+ 'required'=>':attribute 为必填项',
|
|
|
|
|
+ 'unique' => ':attribute 已存在',
|
|
|
|
|
+ 'numeric' => ':attribute 必须为数字',
|
|
|
|
|
+ 'min' => ':attribute 不得为负',
|
|
|
|
|
+ ],[
|
|
|
|
|
+ 'name' =>"名称",
|
|
|
|
|
+ 'base_km' =>"起步公里数",
|
|
|
|
|
+ ]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|