|
|
@@ -7,8 +7,6 @@ use App\RejectedBillItem;
|
|
|
use App\Store;
|
|
|
use App\WMSReflectReceive;
|
|
|
use App\WMSReflectReceiveSku;
|
|
|
-use Illuminate\Http\Request;
|
|
|
-use Illuminate\Support\Facades\Validator;
|
|
|
use Zttp\Zttp;
|
|
|
|
|
|
class StoreController extends Controller
|
|
|
@@ -21,23 +19,13 @@ class StoreController extends Controller
|
|
|
*/
|
|
|
public function accomplishToWMS(Store $store)
|
|
|
{
|
|
|
- $wmsReceiveds=WMSReflectReceive::where('ASNREFERENCE3',$store['asn_code'])
|
|
|
- ->where('is_uploaded',0)->get();
|
|
|
+ $wmsReceiveds=WMSReflectReceive::where('ASNNO',$store['asn_code'])->get();
|
|
|
if($wmsReceiveds->isEmpty()){
|
|
|
- (new Controller())->log(__METHOD__,'error_'.__FUNCTION__,'没有WMS入库单');
|
|
|
+ (new Controller())->log(__METHOD__,'error_'.__FUNCTION__,'没有本地WMS入库单');
|
|
|
return false;
|
|
|
}
|
|
|
- $items=$store->items()->get();
|
|
|
- $amountsItem=(function()use($items){
|
|
|
- $result=[];
|
|
|
- $items->each(function($item)use(&$result){
|
|
|
- $result[$item['id']]= $item['amount'];
|
|
|
- });
|
|
|
- return $result;
|
|
|
- })();
|
|
|
$success=true;
|
|
|
- $wmsReceiveds->each(function ($wmsReceived)use(&$store,&$amountsItem,$items,&$success){
|
|
|
- if(!$store && $store['is_loaded']!=0)return;
|
|
|
+ $wmsReceiveds->each(function ($wmsReceived)use(&$store,&$amountsItem,&$success){
|
|
|
|
|
|
$wmsSkus=$wmsReceived->skus()->get();
|
|
|
$orderNumberCode=$wmsReceived['ASNREFERENCE1']??$store['order_number'];
|
|
|
@@ -50,46 +38,24 @@ class StoreController extends Controller
|
|
|
})();
|
|
|
$skuStrList=[];
|
|
|
$customerCode=$store->owner()->first()['code'];
|
|
|
- $wmsSkus->each(function(WMSReflectReceiveSku $sku)use(&$items,&$skuList,&$amountsItem,&$amountsSku,&$skuStrList,$wmsReceived,$customerCode){
|
|
|
- $items->each(function(RejectedBillItem $item)use(&$sku,&$amountsItem,&$amountsSku,&$skuStrList,$wmsReceived,$customerCode){
|
|
|
- if($item['barcode_goods']!=$sku['ALTERNATE_SKU1'])return;
|
|
|
- if($amountsItem[$item['id']]==0||$amountsSku[$sku['id']]==0)return;
|
|
|
- $uploadingAmount=(function()use(&$item,&$sku,&$amountsItem,&$amountsSku){
|
|
|
- if($amountsItem[$item['id']]>$amountsSku[$sku['id']]){
|
|
|
- $amountsItem[$item['id']]-=$amountsSku[$sku['id']];
|
|
|
- $amount= $amountsSku[$sku['id']];
|
|
|
- $amountsSku[$sku['id']]=0;
|
|
|
- return $amount;
|
|
|
- }
|
|
|
- if($amountsItem[$item['id']]<$amountsSku[$sku['id']]){
|
|
|
- $amount=$amountsItem[$item['id']];
|
|
|
- $amountsSku[$sku['id']]-=$amount;
|
|
|
- $amountsItem[$item['id']]=0;
|
|
|
- return $amount;
|
|
|
- }
|
|
|
- $amount=$amountsItem[$item['id']];
|
|
|
- $amountsItem[$item['id']]=0;
|
|
|
- $amountsSku[$sku['id']]=0;
|
|
|
- return $amount;
|
|
|
- })();
|
|
|
- if($item['is_loaded']=='已入库'){return;}
|
|
|
- $STATUS=$item['id_quality_label']==1?'ZP':'CC';
|
|
|
- $STATUS_code=$item['id_quality_label']==1?'01':'02';
|
|
|
- $skuStr="
|
|
|
+ $wmsSkus->each(function(WMSReflectReceiveSku $sku)use(&$skuList,&$amountsItem,&$amountsSku,&$skuStrList,$wmsReceived,$customerCode) {
|
|
|
+// $STATUS=$item['id_quality_label']==1?'ZP':'CC';
|
|
|
+ $STATUS = 'ZP';
|
|
|
+// $STATUS_code=$item['id_quality_label']==1?'01':'02';
|
|
|
+ $STATUS_code = '01';
|
|
|
+ $skuStr = "
|
|
|
{
|
|
|
\"ORDERNUMBERCODE\": \"{$wmsReceived['ASNNO']}\",
|
|
|
\"ASNLINENO\": \"{$sku['ASNLINENO']}\",
|
|
|
\"SKUCODE\": \"{$sku['SKU']}\",
|
|
|
- \"QUANTITY\": \"{$uploadingAmount}\",
|
|
|
+ \"QUANTITY\": \"{$sku['EXPECTEDQTY_EACH']}\",
|
|
|
\"LOTATT04\": \"{$sku['LOTATT04']}\",
|
|
|
\"LOTATT05\": \"{$sku['LOTATT05']}\",
|
|
|
\"STATUS\": \"{$STATUS}\",
|
|
|
- \"PRODUCTION DATE\": \"{$item['made_at']}\",
|
|
|
- \"EXPIRATION DATE\": \"{$item['validity_at']}\",
|
|
|
\"USERDEFINE1\": \"{$customerCode}{$STATUS_code}\",
|
|
|
\"USERDEFINE2\": \"\",
|
|
|
\"USERDEFINE3\": \"\",
|
|
|
- \"UNIQUE_CODE_LIST\": [".
|
|
|
+ \"UNIQUE_CODE_LIST\": [" .
|
|
|
// {
|
|
|
// \"ORDERNUMBERCODE\": \"{$wmsReceived['ASNNO']}\",
|
|
|
// \"SKUCODE\": \"{$sku['SKU']}\",
|
|
|
@@ -99,22 +65,20 @@ class StoreController extends Controller
|
|
|
// \"LOTATT05\": \"{$sku['LOTATT05']}\",
|
|
|
// \"UNIQUE_CODE\": \"\"
|
|
|
// }
|
|
|
- "]
|
|
|
+ "]
|
|
|
}
|
|
|
";
|
|
|
- $skuStrList[]=$skuStr;
|
|
|
- });
|
|
|
+ $skuStrList[] = $skuStr;
|
|
|
});
|
|
|
- if(count($skuStrList)==0)return;
|
|
|
$skuStrList = implode(',',$skuStrList);
|
|
|
$json="
|
|
|
{
|
|
|
\"request\": [
|
|
|
{
|
|
|
\"ORDERNUMBERCODE\": \"{$wmsReceived['ASNNO']}\",
|
|
|
- \"CUSTOMERID\": \"{$customerCode}\",
|
|
|
+ \"CUSTOMERID\": \"{$wmsReceived['CUSTOMERID']}\",
|
|
|
\"ASNTYPE\": \"{$wmsReceived['ASNTYPE']}\",
|
|
|
- \"ASNREFERENCE1\": \"{$orderNumberCode}\",
|
|
|
+ \"ASNREFERENCE1\": \"{$wmsReceived['ASNREFERENCE1']}\",
|
|
|
\"ADDWHO\": \"WCS\",
|
|
|
\"USERDEFINE1\": \"\",
|
|
|
\"USERDEFINE2\": \"\",
|
|
|
@@ -130,30 +94,32 @@ class StoreController extends Controller
|
|
|
$response = Zttp::post($url, $sendingJson);
|
|
|
$noIssues=true;
|
|
|
$json = $response->json();
|
|
|
- (new Controller())->log(__METHOD__,__FUNCTION__,$response->body().'|'.json_encode($sendingJson));
|
|
|
+ (new Controller())->log(__METHOD__,__FUNCTION__,$response->body());
|
|
|
if(!$json||!isset($json['Response'])||!$json['Response']['return']['returnFlag']=='1'){
|
|
|
$noIssues=false;
|
|
|
}
|
|
|
if($json&&isset($json['Response'])){
|
|
|
if($json['Response']['return']['returnFlag']=='2'){
|
|
|
+ (new Controller())->log(__METHOD__,'error_'.__FUNCTION__,$response->body());
|
|
|
return true;
|
|
|
}
|
|
|
if(isset($json['Response']['return']['returnDesc'])&&strpos($json['Response']['return']['returnDesc'],'唯一约束')!==false){
|
|
|
- (new Controller())->log(__METHOD__,'error_'.__FUNCTION__,$response->body().'|'.json_encode($sendingJson));
|
|
|
+ (new Controller())->log(__METHOD__,'error_'.__FUNCTION__,$response->body());
|
|
|
return true;
|
|
|
}
|
|
|
if(isset($json['Response']['return']['errordescr'])&&strpos($json['Response']['return']['errordescr'],'已完成')!==false){
|
|
|
- (new Controller())->log(__METHOD__,'error_'.__FUNCTION__,$response->body().'|'.json_encode($sendingJson));
|
|
|
+ (new Controller())->log(__METHOD__,'error_'.__FUNCTION__,$response->body());
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
if($noIssues&&$json['Response']['return']['returnFlag']=='1'){
|
|
|
$wmsReceived['is_uploaded']=1;
|
|
|
$wmsReceived->save();
|
|
|
+ (new Controller())->log(__METHOD__, 'success_' . __FUNCTION__, $response->body() );
|
|
|
return true;
|
|
|
- }else{
|
|
|
- $success=false;
|
|
|
- (new Controller())->log(__METHOD__,'error_'.__FUNCTION__,$response->body().'|'.json_encode($sendingJson));
|
|
|
+ }else {
|
|
|
+ $success = false;
|
|
|
+ (new Controller())->log(__METHOD__, 'error_' . __FUNCTION__, $response->body());
|
|
|
}
|
|
|
});
|
|
|
|