|
|
@@ -8,12 +8,19 @@ use App\Logistic;
|
|
|
use App\Owner;
|
|
|
use App\Package;
|
|
|
use App\PaperBox;
|
|
|
+use Box\Spout\Common\Helper\Escaper\XLSX;
|
|
|
+use Box\Spout\Common\Type;
|
|
|
+use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
|
|
|
+use Box\Spout\Writer\Common\Creator\WriterFactory;
|
|
|
use Carbon\Carbon;
|
|
|
use Illuminate\Http\Request;
|
|
|
+use Illuminate\Support\Facades\Auth;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
|
+use Box\Spout\Common\Entity\Row;
|
|
|
+
|
|
|
|
|
|
class PackageController extends Controller
|
|
|
{
|
|
|
@@ -51,11 +58,10 @@ class PackageController extends Controller
|
|
|
if(!Gate::allows('称重管理-查询')){ return redirect(url('/')); }
|
|
|
if ($request->input()){
|
|
|
$packages=Package::orderBy('id','DESC');
|
|
|
-
|
|
|
$packages=$this->conditionQuery($request,$packages);
|
|
|
$packages=$packages->paginate($request->input('paginate')?$request->input('paginate'):50);
|
|
|
$owners=Owner::select('id','name')->get();
|
|
|
- return view('weight.package.index',['packages'=>$packages,'owners'=>$owners]);
|
|
|
+ return view('weight.package.index',['packages'=>$packages,'owners'=>$owners,'request'=>$request->input()]);
|
|
|
}
|
|
|
$packages=Package::orderBy('id','DESC')->paginate(50);
|
|
|
$owners=Owner::select('id','name')->get();
|
|
|
@@ -95,6 +101,7 @@ class PackageController extends Controller
|
|
|
if ($package){
|
|
|
$accomplishToWMS=new \App\Http\Controllers\Api\thirdPart\flux\PackageController();
|
|
|
if ($package->batch_rule&&strstr($package->batch_rule,'组合')){
|
|
|
+ $this->log(__METHOD__,'活动波次开始同步_'.__FUNCTION__,json_encode($package),Auth::user()['name']);
|
|
|
$this->syncBatch($package->batch_number,$weight,null,null,null,Carbon::now(),$paper_box_id);
|
|
|
}else{
|
|
|
$package->weight=$weight;
|
|
|
@@ -117,10 +124,12 @@ class PackageController extends Controller
|
|
|
]);
|
|
|
}
|
|
|
$package->save();
|
|
|
+ $this->log(__METHOD__,'create_'.__FUNCTION__,json_encode($package),Auth::user()['name']);
|
|
|
event(new WeighedEvent($package));
|
|
|
return redirect('package/create')->with('successTip','操作成功');
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public function statistics(Request $request){
|
|
|
$packages=Package::select(DB::raw('owner_id,logistic_id,COUNT(logistic_id) AS count'));
|
|
|
if($request->input('owner_id')){
|
|
|
@@ -132,18 +141,34 @@ class PackageController extends Controller
|
|
|
$packages=$packages->whereIn('logistic_id',$logistics_id);
|
|
|
}
|
|
|
if($request->input('date_start')){
|
|
|
- $packages=$packages->where('created_at','<=',$request->input('date_start'));
|
|
|
+ $packages=$packages->where('created_at','>=',$request->input('date_start'));
|
|
|
}
|
|
|
if($request->input('date_end')){
|
|
|
- $packages=$packages->where('created_at','>=',$request->input('date_end'));
|
|
|
+ $packages=$packages->where('created_at','<=',$request->input('date_end'));
|
|
|
}
|
|
|
-
|
|
|
$packages=$packages->groupBy(['owner_id','logistic_id'])->get();
|
|
|
$owners=Owner::get();
|
|
|
$logistics=Logistic::get();
|
|
|
+ if ($request->input('checkSign')){
|
|
|
+ if ($request->input('checkSign')=="-1"){
|
|
|
+/* $id=[];
|
|
|
+ foreach ($packages as $package){
|
|
|
+ array_push($id,$package->id);
|
|
|
+ }*/
|
|
|
+ $excel=$this->statisticExport($packages,$owners,$logistics);
|
|
|
+ return $excel;
|
|
|
+ }
|
|
|
+ $id=$id = explode( ',',$request->input('checkSign'));
|
|
|
+ $packages=Package::select(DB::raw('owner_id,logistic_id,COUNT(logistic_id) AS count'))
|
|
|
+ ->whereIn('owner_id',$id)->groupBy(['owner_id','logistic_id'])->get();
|
|
|
+ $excel=$this->statisticExport($packages,$owners,$logistics);
|
|
|
+ return $excel;
|
|
|
+
|
|
|
+ }
|
|
|
return view('weight.package.statistics',["packages"=>$packages,'owners'=>$owners,'logistics'=>$logistics]);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* Display the specified resource.
|
|
|
*
|
|
|
@@ -293,7 +318,78 @@ class PackageController extends Controller
|
|
|
$packageBatch->status="上传异常";
|
|
|
}
|
|
|
$packageBatch->save();
|
|
|
+ $this->log(__METHOD__,'SUCCESS_'.__FUNCTION__,json_encode($packageBatch));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function statisticExport($packages,$owners,$logistics){
|
|
|
+ if (!$packages||!$owners||!$logistics) return;
|
|
|
+ $row=[[]];
|
|
|
+ $row[0]['owner']='货主';
|
|
|
+ $row[0]['sum']='总计';
|
|
|
+ foreach ($logistics as $logistic){
|
|
|
+ $row[0][$logistic->id]=$logistic->name;
|
|
|
+ }
|
|
|
+ $ownerArr=[];
|
|
|
+ foreach ($owners as $owner){
|
|
|
+ foreach ($packages as $package){
|
|
|
+ if ($owner->id==$package->owner_id){
|
|
|
+ $ownerArr[$owner->name][$package->logistic_id]=$package->count;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $list=[];
|
|
|
+ for ($i=0;$i<count($ownerArr);$i++){
|
|
|
+ foreach ($owners as $owner){
|
|
|
+ if (isset($ownerArr[$owner->name])){
|
|
|
+ $w['owner']=$owner->name;
|
|
|
+ $sum=0;
|
|
|
+ foreach ($logistics as $logistic){
|
|
|
+ if (isset($ownerArr[$owner->name][$logistic->id])){
|
|
|
+ $w[$logistic->id]=$ownerArr[$owner->name][$logistic->id];
|
|
|
+ $sum=$sum+$ownerArr[$owner->name][$logistic->id];
|
|
|
+ }
|
|
|
+ if (!isset($ownerArr[$owner->name][$logistic->id])){
|
|
|
+ $w[$logistic->id]=0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $w['sum']=$sum;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $list[$i]=$w;
|
|
|
}
|
|
|
+ return Excel::download(new WaybillExport($row,$list),date('YmdHis', time()).'-称重统计记录单.xls');
|
|
|
+ /* $writer = WriterEntityFactory::createXLSXWriter();
|
|
|
+// $writer = WriterEntityFactory::createODSWriter();
|
|
|
+// $writer = WriterEntityFactory::createCSVWriter();
|
|
|
+
|
|
|
+ $writer->openToBrowser("test.xlsx"); // write data to a file or to a PHP stream
|
|
|
+//$writer->openToBrowser($fileName); // stream data directly to the browser
|
|
|
+
|
|
|
+ $cells = [
|
|
|
+ WriterEntityFactory::createCell('a'),
|
|
|
+ WriterEntityFactory::createCell('is'),
|
|
|
+ WriterEntityFactory::createCell('great!'),
|
|
|
+ ];
|
|
|
+
|
|
|
+ /** add a row at a time */
|
|
|
+ /* $singleRow = WriterEntityFactory::createRow($cells);
|
|
|
+ $writer->addRow($singleRow);
|
|
|
+
|
|
|
+ /** add multiple rows at a time */
|
|
|
+ /* $multipleRows = [
|
|
|
+ WriterEntityFactory::createRow($cells),
|
|
|
+ WriterEntityFactory::createRow($cells),
|
|
|
+ ];
|
|
|
+ $writer->addRows($multipleRows);
|
|
|
+
|
|
|
+ /** Shortcut: add a row from an array of values */
|
|
|
+ /* $values = ['Carl', 'is', 'great!'];
|
|
|
+ $rowFromValues = WriterEntityFactory::createRowFromArray($values);
|
|
|
+ $writer->addRow($rowFromValues);
|
|
|
+
|
|
|
+ $writer->close();*/
|
|
|
}
|
|
|
|
|
|
}
|