|
|
@@ -96,7 +96,7 @@ class PackageController extends Controller
|
|
|
* Store a newly created resource in storage.
|
|
|
*
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
- * @return \Illuminate\Http\Response
|
|
|
+ * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
|
*/
|
|
|
public function store(Request $request)
|
|
|
{
|
|
|
@@ -106,16 +106,24 @@ class PackageController extends Controller
|
|
|
$weight=$request->input('weight');
|
|
|
$batch_number=$request->input('batch_number');
|
|
|
$paper_box_id=$request->input('paper_box_id');
|
|
|
+ if($logistic_number&&$batch_number)return redirect('package/create')->with('successError','录入失败!波次号和快递单号只能填一项!');
|
|
|
$package=null;
|
|
|
- if($batch_number)$package=Package::where('batch_number',$batch_number)->first();
|
|
|
- if($logistic_number)$package=Package::where('logistic_number',$logistic_number)->first();
|
|
|
+ if($batch_number){
|
|
|
+ $package=Package::where('batch_number',$batch_number)->first();
|
|
|
+ }elseif($logistic_number){
|
|
|
+ $package=Package::where('logistic_number',$logistic_number)->first();
|
|
|
+ }
|
|
|
if (!$package && !$logistic_number)return redirect('package/create')->with('successError','录入失败!系统内没有对应波次的包裹!');
|
|
|
+ $successTip = '操作成功';
|
|
|
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{
|
|
|
+ if($batch_number){
|
|
|
+ return redirect('package/create')->with('successError','录入失败!该波次不是组合提总!');
|
|
|
+ }
|
|
|
$package->weight=$weight;
|
|
|
$package->paper_box_id=$paper_box_id;
|
|
|
$package->batch_number=$batch_number;
|
|
|
@@ -134,11 +142,12 @@ class PackageController extends Controller
|
|
|
'paper_box_id'=>$paper_box_id,
|
|
|
'batch_number'=>$batch_number
|
|
|
]);
|
|
|
+ $successTip = "新建称重记录成功!单号:$logistic_number";
|
|
|
}
|
|
|
$package->save();
|
|
|
$this->log(__METHOD__,'create_'.__FUNCTION__,json_encode($package),Auth::user()['name']);
|
|
|
event(new WeighedEvent($package));
|
|
|
- return redirect('package/create')->with('successTip','操作成功');
|
|
|
+ return redirect('package/create')->with('successTip', $successTip);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -310,7 +319,7 @@ class PackageController extends Controller
|
|
|
'logistic_number'=>['nullable','max:50'],
|
|
|
'weight'=>'required|min:0|max:999999|numeric',
|
|
|
'paper_box_id'=>'nullable|integer',
|
|
|
- 'batch_number'=>'required_without:logistic_number'
|
|
|
+ 'batch_number'=>['required_without:logistic_number']
|
|
|
],[
|
|
|
'required'=>':attribute 为必填项',
|
|
|
'max'=>':attribute 字符过多或输入值过大',
|
|
|
@@ -330,26 +339,28 @@ class PackageController extends Controller
|
|
|
|
|
|
public function syncBatch($batch_number,$weight,$max,$centre,$min,$date,$paperBox_id){
|
|
|
$accomplishToWMS=new \App\Http\Controllers\Api\thirdPart\flux\PackageController();
|
|
|
- $packagesBatch=Package::where('batch_number',$batch_number)->get();
|
|
|
- foreach ($packagesBatch as $packageBatch){
|
|
|
- $packageBatch->weight=$weight;
|
|
|
- if($max)$packageBatch->length=$max;
|
|
|
- if($centre)$packageBatch->width=$centre;
|
|
|
- if($min)$packageBatch->height=$min;
|
|
|
- $packageBatch->bulk=$max*$centre*$min;
|
|
|
- $packageBatch->weighed_at=$date;
|
|
|
- if ($paperBox_id)$packageBatch->paper_box_id=$paperBox_id;
|
|
|
- $packageBatch->status="未上传";
|
|
|
- $result=$accomplishToWMS->accomplishToWMS($packageBatch);
|
|
|
- if ($result['result']=='success'){
|
|
|
- if ($packageBatch->status=="记录异常")$packageBatch->status="已上传异常";
|
|
|
- else $packageBatch->status="已上传";
|
|
|
- }else{
|
|
|
- $packageBatch->status="上传异常";
|
|
|
- }
|
|
|
- $packageBatch->save();
|
|
|
- $this->log(__METHOD__,'SUCCESS_'.__FUNCTION__,json_encode($packageBatch));
|
|
|
+ $packageBatch=Package::where('batch_number',$batch_number)->first();
|
|
|
+ if(!$packageBatch)return;
|
|
|
+ $newValues = ['weight' => $weight];
|
|
|
+ if($max)$newValues['length']=$max;
|
|
|
+ if($centre)$newValues['width']=$centre;
|
|
|
+ if($min)$newValues['height']=$min;
|
|
|
+ if($date)$newValues['weighed_at']=$date;
|
|
|
+ if($paperBox_id)$newValues['paper_box_id']=$paperBox_id;
|
|
|
+ if($max&&$centre&&$min){
|
|
|
+ $newValues['bulk']=$max*$centre*$min;
|
|
|
+ }
|
|
|
+ $packageBatch->update($newValues);
|
|
|
+ $result=$accomplishToWMS->accomplishToWMS($packageBatch);
|
|
|
+ if ($result['result']=='success'){
|
|
|
+ $newValues['status']='已上传';
|
|
|
+ Controller::logS(__METHOD__,'SUCCESS_'.__FUNCTION__,'批量更改波次上传成功'.json_encode($packageBatch));
|
|
|
+ }else{
|
|
|
+ $newValues['status']='上传异常';
|
|
|
+ Controller::logS(__METHOD__,'error_'.__FUNCTION__,'批量更改波次上传异常:'.json_encode($packageBatch));
|
|
|
}
|
|
|
+ Package::where('batch_number',$batch_number)->update($newValues);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public function statisticExport($packages,$owners,$logistics){
|