|
@@ -304,15 +304,9 @@ class ImportService extends Service
|
|
$array_clean[] = $value[1];
|
|
$array_clean[] = $value[1];
|
|
|
|
|
|
if(! empty($value[15])){
|
|
if(! empty($value[15])){
|
|
- $dateTimeObject = Date::excelToDateTimeObject($value[15]);
|
|
|
|
- // 现在你可以格式化这个日期了
|
|
|
|
- $formattedDate = $dateTimeObject->format('Y-m-d H:i:s');
|
|
|
|
-
|
|
|
|
- if(! strtotime($formattedDate)){
|
|
|
|
- return [false, '录入日期请填写正确的日期'];
|
|
|
|
- }else{
|
|
|
|
- $value[15] = strtotime($formattedDate);
|
|
|
|
- }
|
|
|
|
|
|
+ list($status, $msg) = $this->convertExcelCellToDate($value[15]);
|
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
|
+ $value[15] = $msg;
|
|
} else{
|
|
} else{
|
|
$value[15] = $now;
|
|
$value[15] = $now;
|
|
}
|
|
}
|
|
@@ -509,6 +503,31 @@ class ImportService extends Service
|
|
return [true, ''];
|
|
return [true, ''];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ function convertExcelCellToDate($cellValue) {
|
|
|
|
+ // 尝试将单元格值转换为浮点数(Excel 日期序列号)
|
|
|
|
+ $excelTimestamp = filter_var($cellValue, FILTER_VALIDATE_FLOAT);
|
|
|
|
+
|
|
|
|
+ if ($excelTimestamp !== false && $excelTimestamp > 0) {
|
|
|
|
+ // 如果成功转换并且值大于0,则认为是Excel日期序列号
|
|
|
|
+ try {
|
|
|
|
+ $dateTimeObject = Date::excelToDateTimeObject($cellValue);
|
|
|
|
+ // 现在你可以格式化这个日期了
|
|
|
|
+ $formattedDate = $dateTimeObject->format('Y-m-d H:i:s');
|
|
|
|
+ if(! strtotime($formattedDate)) return [false, '录入日期请填写正确的日期'];
|
|
|
|
+
|
|
|
|
+ return [true, strtotime($formattedDate)];
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
+ // 处理转换失败的情况
|
|
|
|
+ return [false, '单元格日期格式转换时间戳失败'];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 如果不是有效的浮点数,则尝试按照多种日期格式解析
|
|
|
|
+ if(! strtotime($cellValue)) return [false, '单元格文本格式转换时间戳失败'];
|
|
|
|
+
|
|
|
|
+ return [true, strtotime($cellValue)];
|
|
|
|
+ }
|
|
|
|
+
|
|
public function productImport($array, $user){
|
|
public function productImport($array, $user){
|
|
//当前门店
|
|
//当前门店
|
|
$depart_id = $this->getDepart($user);
|
|
$depart_id = $this->getDepart($user);
|