|
|
@@ -912,9 +912,12 @@ class ProcessController extends Controller
|
|
|
$commodities = explode("\n",$request->data); //拆分行
|
|
|
$owner='';
|
|
|
$processContents=[];
|
|
|
- foreach ($commodities as $commodity){
|
|
|
- $commodity = array_filter(preg_split('/[\t]+/is',$commodity)); //拆分列
|
|
|
+ $errors = [];
|
|
|
+ foreach ($commodities as $i => $commodity){
|
|
|
+ $commodity = explode("\t",$commodity); //拆分列
|
|
|
+ $head="第".($i+1)."行";
|
|
|
if (count($commodity)<count($request->rows)){
|
|
|
+ $errors[$head] = ['数据不完整'];
|
|
|
unset($commodity);
|
|
|
continue;
|
|
|
}
|
|
|
@@ -922,32 +925,44 @@ class ProcessController extends Controller
|
|
|
$wmsCode='';
|
|
|
$barcode='';
|
|
|
$amount=0;
|
|
|
+ $errors[$head] = [];
|
|
|
foreach ($request->rows as $index => $row){
|
|
|
if ($row == '货主'){
|
|
|
- if (isset($commodity[$index]) && $commodity[$index] && !$owner){
|
|
|
- $owner=Owner::where('code',$commodity[$index])->orWhere('name',$commodity[$index])->first();
|
|
|
- if (!$owner){
|
|
|
- $owner = Owner::create([
|
|
|
- 'code' => $commodity[$index],
|
|
|
- 'name' => $commodity[$index]
|
|
|
- ]);
|
|
|
- }
|
|
|
+ if ($commodity[$index] && !$owner){
|
|
|
+ $owner = $commodity[$index];
|
|
|
}
|
|
|
+ if (!$commodity[$index])array_push($errors[$head],"货主为空");
|
|
|
}
|
|
|
if ($row == '单据'){
|
|
|
- $wmsCode = isset($commodity[$index]) ? $commodity[$index] : '';
|
|
|
+ $wmsCode = $commodity[$index] ?? '';
|
|
|
}
|
|
|
if ($row == 'SKU'){
|
|
|
- $commodityData['sku'] = isset($commodity[$index]) ? $commodity[$index] : '';
|
|
|
+ $commodityData['sku'] = $commodity[$index] ?? '';
|
|
|
}
|
|
|
if ($row == '品名'){
|
|
|
- $commodityData['name'] = isset($commodity[$index]) ? $commodity[$index] : '';
|
|
|
+ $commodityData['name'] = $commodity[$index] ?? '';
|
|
|
+ if (!$commodity[$index])array_push($errors[$head],"品名为空");
|
|
|
}
|
|
|
if ($row == '条码'){
|
|
|
- $barcode = isset($commodity[$index]) ? $commodity[$index] : '';
|
|
|
+ $barcode = $commodity[$index] ?? '';
|
|
|
}
|
|
|
if ($row == '数量'){
|
|
|
- $amount = isset($commodity[$index]) ? $commodity[$index] : '';
|
|
|
+ $amount = $commodity[$index] ?? '';
|
|
|
+ if (!$commodity[$index])array_push($errors[$head],"数量为空");
|
|
|
+ if (!is_numeric($commodity[$index]) || $commodity[$index] < 1)array_push($errors[$head],"数量为空或小于1");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (count($errors[$head]) > 0)continue;
|
|
|
+ else unset($errors[$head]);
|
|
|
+ if (!is_object($owner)){
|
|
|
+ $str = $owner;
|
|
|
+ $owner=Owner::where('code',$str)->orWhere('name',$str)->first();
|
|
|
+ if (!$owner){
|
|
|
+ $owner = Owner::create([
|
|
|
+ 'code' => $str,
|
|
|
+ 'name' => $str
|
|
|
+ ]);
|
|
|
+ $this->log(__METHOD__,"二次加工单录入导入商品数据时添加货主".__FUNCTION__,json_encode($owner),Auth::user()['id']);
|
|
|
}
|
|
|
}
|
|
|
$commodity = Commodity::query()->whereNull('owner_id')
|
|
|
@@ -957,6 +972,8 @@ class ProcessController extends Controller
|
|
|
'code' => $barcode,
|
|
|
'commodity_id' => $commodity->id
|
|
|
]);
|
|
|
+ $this->log(__METHOD__,"二次加工单录入导入商品数据时添加商品及条码".__FUNCTION__,
|
|
|
+ json_encode($commodity)." || ".json_encode($commodityBarCode),Auth::user()['id']);
|
|
|
$processContent=['bill_type'=>'入库单','commodity_id'=>$commodity->id,'wms_code'=>$wmsCode,'amount'=>$amount,
|
|
|
'commodity_name'=>$commodity->name,'commodity_barcodes'=>[$commodityBarCode],'commodity_sku'=>$commodity->sku,
|
|
|
'lineNo'=>1,'owner_id'=>$owner->id,'owner_name'=>$owner->name,'addBtnShow'=>false,'type'=>false];
|
|
|
@@ -964,7 +981,7 @@ class ProcessController extends Controller
|
|
|
$processContent['type']=true;
|
|
|
array_push($processContents,$processContent);
|
|
|
}
|
|
|
- return ['success'=>true,'data'=>$processContents];
|
|
|
+ return ['success'=>true,'data'=>$processContents,'errors'=>$errors];
|
|
|
}
|
|
|
|
|
|
|