|
|
@@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
|
|
|
use Carbon\Carbon;
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
use App\Traits\ModelTimeFormat;
|
|
|
+use Illuminate\Support\Arr;
|
|
|
|
|
|
class Package extends Model
|
|
|
{
|
|
|
@@ -24,14 +25,16 @@ class Package extends Model
|
|
|
'WMSReflectPackage_name'
|
|
|
];
|
|
|
static protected $oracleOrderHeaderFields = [
|
|
|
- 'doc_order_header.userdefine1',
|
|
|
- 'doc_order_header.userdefine2',
|
|
|
- 'doc_order_header.soreference5',
|
|
|
- 'doc_order_header.waveno',
|
|
|
- 'doc_order_header.orderno',
|
|
|
- 'doc_order_header.customerid',
|
|
|
- 'doc_order_header.consigneename',
|
|
|
- 'doc_order_header.carrierid'
|
|
|
+ 'doc_order_header.userdefine1',
|
|
|
+ 'doc_order_header.soreference5',
|
|
|
+ 'doc_order_header.waveno',
|
|
|
+ 'doc_order_header.orderno',
|
|
|
+ 'doc_order_header.customerid',
|
|
|
+ 'doc_order_header.consigneename',
|
|
|
+ 'doc_order_header.carrierid',
|
|
|
+ 'doc_order_header.c_tel1',
|
|
|
+ 'doc_order_header.c_tel2',
|
|
|
+ 'doc_wave_header.descr',
|
|
|
];
|
|
|
protected $tempFields=[
|
|
|
'temOracleInfo','temOwner','temLogistic',
|
|
|
@@ -55,18 +58,22 @@ class Package extends Model
|
|
|
public function WMSReflectPackage(){
|
|
|
return $this->hasOne('App\WMSReflectPackage','SOReference5','logistic_number');
|
|
|
}
|
|
|
- public function save(array $options=[]){
|
|
|
- foreach ($this->tempFields as $field){
|
|
|
- unset($this->$field);
|
|
|
- }
|
|
|
- parent::save($options);
|
|
|
- }
|
|
|
|
|
|
- public function update(array $attributes=[],array $options=[]){
|
|
|
- foreach ($this->tempFields as $field){
|
|
|
- unset($this->$field);
|
|
|
- }
|
|
|
- parent::update($attributes,$options);
|
|
|
+ public function setLengthAttribute($value){
|
|
|
+ if(empty((int)($value)))return;
|
|
|
+ $this->attributes['length'] = $value;
|
|
|
+ }
|
|
|
+ public function setWidthAttribute($value){
|
|
|
+ if(empty((int)($value)))return;
|
|
|
+ $this->attributes['width'] = $value;
|
|
|
+ }
|
|
|
+ public function setHeightAttribute($value){
|
|
|
+ if(empty((int)($value)))return;
|
|
|
+ $this->attributes['height'] = $value;
|
|
|
+ }
|
|
|
+ public function setBulkAttribute($value){
|
|
|
+ if(empty((int)($value)))return;
|
|
|
+ $this->attributes['bulk'] = $value;
|
|
|
}
|
|
|
|
|
|
public function isActivityBatch(){
|
|
|
@@ -103,58 +110,67 @@ class Package extends Model
|
|
|
}
|
|
|
|
|
|
public function fetchLogisticFromOracle(){
|
|
|
- if(!$this['oracleInfo'])return null;
|
|
|
- if($this['temLogistic'])return $this['temLogistic'];
|
|
|
- Controller::logs(__METHOD__, __FUNCTION__, "tempPackage:{$this['oracleInfo']['carrierid']}||SOR:{$this['oracleInfo']['SOReference5']}||sor:{$this['oracleInfo']['soreference5']}||orderno:{$this['orderno']}" , null);
|
|
|
- if(!$this['oracleInfo']['carrierid'])return null;
|
|
|
- $logistic= Logistic::where('code',$this['oracleInfo']['carrierid'])->first();
|
|
|
+ if(empty($this->oracleInfo))return null;
|
|
|
+ if(Arr::exists($this->tempFields,'temLogistic'))return $this->tempFields['temLogistic'];
|
|
|
+ Controller::logs(__METHOD__, __FUNCTION__, "tempPackage:{$this->oracleInfo['carrierid']}||SOR:{$this->oracleInfo['SOReference5']}||sor:{$this->oracleInfo['soreference5']}||orderno:{$this['orderno']}" , null);
|
|
|
+ if(!$this->oracleInfo['carrierid'])return null;
|
|
|
+ $logistic= Logistic::where('code',$this->oracleInfo['carrierid'])->first();
|
|
|
if(!$logistic){
|
|
|
- Logistic::create(['code'=>$this['oracleInfo']['carrierid'],'name'=>$this['oracleInfo']['carrierid']]);
|
|
|
- Controller::logs(__METHOD__, __FUNCTION__, "富勒下发找不到快递公司,添加{$this['oracleInfo']['carrierid']}" , null);
|
|
|
+ $logistic=Logistic::create(['code'=>$this->oracleInfo['carrierid'],'name'=>$this->oracleInfo['carrierid']]);
|
|
|
+ Controller::logs(__METHOD__, __FUNCTION__, "富勒下发找不到快递公司,添加{$this->oracleInfo['carrierid']}" , null);
|
|
|
}
|
|
|
Controller::logs(__METHOD__, __FUNCTION__, "tempPackage2:{$logistic->id}" , null);
|
|
|
if(!$logistic)return null;
|
|
|
- $this['temLogistic']=$logistic;
|
|
|
+ $this->tempFields['temLogistic']=$logistic;
|
|
|
$this['logistic_id'] = $logistic['id'];
|
|
|
return $logistic;
|
|
|
}
|
|
|
public function fetchOwnerFromOracle(){
|
|
|
- if(!$this['oracleInfo'])return null;
|
|
|
- if($this['temOwner'])return $this['temOwner'];
|
|
|
- $owner= Owner::where('code',$this['oracleInfo']['customerid'])->first();
|
|
|
+ if(empty($this->oracleInfo))return null;
|
|
|
+ if(Arr::exists($this->tempFields,'temOwner'))return $this->tempFields['temOwner'];
|
|
|
+ $owner= Owner::where('code',$this->oracleInfo['customerid'])->first();
|
|
|
if(!$owner){
|
|
|
- Owner::create(['code'=>$this['oracleInfo']['customerid'],'name'=>$this['oracleInfo']['customerid']]);
|
|
|
- Controller::logs(__METHOD__, __FUNCTION__, "富勒下发找不到货主,添加{$this['oracleInfo']['customerid']}" , null);
|
|
|
+ $owner=Owner::create(['code'=>$this->oracleInfo['customerid'],'name'=>$this->oracleInfo['customerid']]);
|
|
|
+ Controller::logs(__METHOD__, __FUNCTION__, "富勒下发找不到货主,添加{$this->oracleInfo['customerid']}" , null);
|
|
|
}
|
|
|
if(!$owner)return null;
|
|
|
- $this['temOwner']=$owner;
|
|
|
+ $this->tempFields['temOwner']=$owner;
|
|
|
$this['owner_id'] = $owner['id'];
|
|
|
return $owner;
|
|
|
}
|
|
|
public function fetchAllFromOracle(){
|
|
|
- if(!$this['oracleInfo'])return null;
|
|
|
+ if(empty($this->oracleInfo))return null;
|
|
|
$this->fetchOwnerFromOracle();
|
|
|
$this->fetchLogisticFromOracle();
|
|
|
- $this['recipient'] = $this['oracleInfo']['consigneename'];
|
|
|
- if($this['oracleInfo']['SOReference5'])
|
|
|
- $this['logistic_number'] = $this['oracleInfo']['SOReference5'];
|
|
|
- $this['batch_rule'] = $this['oracleInfo']['userdefine2']??null;
|
|
|
- $this['batch_number'] = $this['oracleInfo']['waveno']??null;
|
|
|
+ $this['recipient'] = $this->oracleInfo['consigneename'];
|
|
|
+ $this['order_code'] = $this->oracleInfo['orderno'];
|
|
|
+ $this['batch_rule'] = $this->oracleInfo['descr'];
|
|
|
+ $this['recipient_mobile'] = $this->oracleInfo['c_tel2']??$this->oracleInfo['c_tel1'];
|
|
|
+ if($this->oracleInfo['soreference5'])
|
|
|
+ $this['logistic_number'] = $this->oracleInfo['soreference5'];
|
|
|
+ $this['batch_number'] = $this->oracleInfo['waveno']??null;
|
|
|
}
|
|
|
|
|
|
public function getOracleInfoAttribute()
|
|
|
{
|
|
|
- if(isset($this->temOracleInfo)&&$this->temOracleInfo)return $this->temOracleInfo;
|
|
|
- if(!$this['logistic_number']&&!$this['order_code'])return '';
|
|
|
+ if(isset($this->tempFields['temOracleInfo']))return $this->tempFields['temOracleInfo'];
|
|
|
+ if(empty($this['logistic_number'])&&empty($this['order_code']))return '';
|
|
|
if($this['order_code']){
|
|
|
$resultOracleObjs=OracleDOCOrderHeader::select(self::$oracleOrderHeaderFields)->where('orderno',$this['order_code']);
|
|
|
+ $resultOracleObjs->leftJoin('doc_wave_header','doc_wave_header.waveno','doc_order_header.waveno');
|
|
|
}else{
|
|
|
$resultOracleObjs=OracleActAllocationDetails::select(self::$oracleOrderHeaderFields);
|
|
|
$resultOracleObjs->where('picktotraceid',$this['logistic_number']);
|
|
|
$resultOracleObjs->leftJoin('DOC_Order_Header','act_allocation_details.orderno','doc_order_header.orderno');
|
|
|
+ $resultOracleObjs->leftJoin('doc_wave_header','doc_wave_header.waveno','doc_order_header.waveno');
|
|
|
+ }
|
|
|
+ $this->tempFields['temOracleInfo']=$resultOracleObjs->first();
|
|
|
+ if(empty($this->tempFields['temOracleInfo'])) {
|
|
|
+ $resultOracleObjs=OracleDOCOrderHeader::select(self::$oracleOrderHeaderFields)->where('soreference5',$this['logistic_number']);
|
|
|
+ $resultOracleObjs->leftJoin('doc_wave_header','doc_wave_header.waveno','doc_order_header.waveno');
|
|
|
}
|
|
|
- $this->temOracleInfo=$resultOracleObjs->first();
|
|
|
- return $this->temOracleInfo;
|
|
|
+ $this->tempFields['temOracleInfo']=$resultOracleObjs->first();
|
|
|
+ return $this->tempFields['temOracleInfo'];
|
|
|
}
|
|
|
public function getOwnerNameAttribute()
|
|
|
{
|
|
|
@@ -178,11 +194,14 @@ class Package extends Model
|
|
|
|
|
|
|
|
|
//寻找相近纸箱ID
|
|
|
- public function fetchPaperBox($max, $centre, $min, $owner_id=null){
|
|
|
+ public function fetchPaperBox($max=null, $centre=null, $min=null, $owner_id=null){
|
|
|
if($this['paper_box_id'])return $this['paper_box_id'];
|
|
|
$sumDiffer=0;
|
|
|
$maxDiffer=0;
|
|
|
$paperBox_id=null;
|
|
|
+ if(!$max)$max=$this['length'];
|
|
|
+ if(!$centre)$centre=$this['width'];
|
|
|
+ if(!$min)$min=$this['height'];
|
|
|
if(!$owner_id) $owner_id = $this['owner_id'];
|
|
|
if(!$owner_id) {
|
|
|
$owner = $this->fetchOwnerFromOracle();
|