|
@@ -187,19 +187,23 @@ class Import implements WithMultipleSheets,ToArray {
|
|
|
//------ 根据规则 查找数据 =>做 替换和校验--------------//
|
|
|
//校验数据唯一
|
|
|
if (strpos($value['other_rule'], 'unique') !== false) {
|
|
|
- $uniqueIndex = strpos($value['other_rule'], 'unique:');
|
|
|
- $start = $uniqueIndex + strlen('unique:');
|
|
|
- $end = strpos($value['other_rule'], '|', $start);
|
|
|
- if ($end !== false) {
|
|
|
- $uniqueValue = substr($value['other_rule'], $start, $end - $start);
|
|
|
- } else {
|
|
|
- $uniqueValue = substr($value['other_rule'], $start);
|
|
|
- }
|
|
|
+ $uniqueValue = $this->getOtherRuleModelName($value,"unique");
|
|
|
$model = "\App\Model\\" . $uniqueValue;
|
|
|
+ $newStr = "";
|
|
|
+ if( ! empty($value['search_raw'])){
|
|
|
+ $str = $value['search_raw'];
|
|
|
+ foreach ($value['search_field'] as $value_field){
|
|
|
+ if(isset($this->data[$value_field])){
|
|
|
+ $v = $this->data[$value_field];
|
|
|
+ $newStr = str_replace("?", $v, $str);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if( ! empty($newStr)) $model::whereRaw($newStr);
|
|
|
+ }
|
|
|
$bool = $model::whereIn($value['key'], array_unique($tmp_data))
|
|
|
->where('del_time',0)
|
|
|
->exists();
|
|
|
- if($bool) return [false, $key . "在数据库中已存在"];
|
|
|
+ if($bool) return [false, $key . "在已存在"];
|
|
|
}
|
|
|
|
|
|
//替换数据
|
|
@@ -210,12 +214,25 @@ class Import implements WithMultipleSheets,ToArray {
|
|
|
->pluck($db['value'], $db['key'])
|
|
|
->toArray();
|
|
|
}
|
|
|
+
|
|
|
+ //常量字典
|
|
|
+ if(strpos($value['other_rule'], 'dk') !== false){
|
|
|
+ $uniqueValue = $this->getOtherRuleModelName($value,"dk");
|
|
|
+ $model = "\App\Model\\" . $uniqueValue;
|
|
|
+ $constantValue = constant($model . '::' . $value['dk_name']);
|
|
|
+ }
|
|
|
//------ 根据规则 查找数据 =>做 替换和校验--------------//
|
|
|
|
|
|
|
|
|
//校验&&组织
|
|
|
$tmp_clean = [];
|
|
|
foreach ($tmp_data as $v_key => $v_data){
|
|
|
+ //常量字典
|
|
|
+ if(strpos($value['other_rule'], 'dk') !== false){
|
|
|
+ if(! isset($constantValue[$v_data])) return [false, $key . '在系统中不存在!'];
|
|
|
+ $v_data = $constantValue[$v_data];
|
|
|
+ }
|
|
|
+
|
|
|
if (strpos($value['other_rule'], 'require') !== false) {
|
|
|
if(empty($v_data)) return [false, $key . '不能为空!'];
|
|
|
}
|
|
@@ -229,8 +246,10 @@ class Import implements WithMultipleSheets,ToArray {
|
|
|
if($formattedNumber != $v_data) return [false, $key . '请输入数字(请输入不超过两位小数)!'];
|
|
|
}
|
|
|
if(! empty($value['db_search'])) {
|
|
|
- if(empty($map[$v_data])) return [false, $key . '下所输入的内容在系统中不存在!'];
|
|
|
- $v_data = $map[$v_data];
|
|
|
+ if(! empty($v_data)){
|
|
|
+ if(empty($map[$v_data])) return [false, $key . '下所输入的内容在系统中不存在!'];
|
|
|
+ $v_data = $map[$v_data];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if(! empty($value['multiple'])) {
|
|
@@ -245,11 +264,24 @@ class Import implements WithMultipleSheets,ToArray {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- unset($tmp_clean);
|
|
|
+ unset($tmp_clean);dd($return_data);//TODO
|
|
|
|
|
|
return [true, $return_data];
|
|
|
}
|
|
|
|
|
|
+ function getOtherRuleModelName($value,$needle){
|
|
|
+ $needle = $needle . ":";
|
|
|
+ $uniqueIndex = strpos($value['other_rule'], $needle);
|
|
|
+ $start = $uniqueIndex + strlen($needle);
|
|
|
+ $end = strpos($value['other_rule'], '|', $start);
|
|
|
+ if ($end !== false) {
|
|
|
+ $uniqueValue = substr($value['other_rule'], $start, $end - $start);
|
|
|
+ } else {
|
|
|
+ $uniqueValue = substr($value['other_rule'], $start);
|
|
|
+ }
|
|
|
+ return $uniqueValue;
|
|
|
+ }
|
|
|
+
|
|
|
// 处理合并单元格数据
|
|
|
function clearMergeData($data){
|
|
|
//获取行列
|