Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
liexin_supplier
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
41680f18
authored
Mar 16, 2022
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
空格校验
parent
890df309
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
45 deletions
app/Console/Commands/SetSupplierFollowUp.php
app/Http/Services/DataService.php
app/Console/Commands/SetSupplierFollowUp.php
View file @
41680f18
...
...
@@ -31,6 +31,6 @@ class SetSupplierFollowUp extends Command
public
function
handle
()
{
$service
=
new
DataService
();
$service
->
importSupplierLevel
();
$service
->
trimSupplierName
();
}
}
app/Http/Services/DataService.php
View file @
41680f18
...
...
@@ -296,53 +296,53 @@ class DataService
public
function
importSupplierLevel
()
{
$filePath
=
'public/data'
.
DIRECTORY_SEPARATOR
.
'supplier_level.xlsx'
;
Excel
::
selectSheetsByIndex
(
0
)
->
load
(
$filePath
,
function
(
$reader
)
{
$supplierChannelModel
=
new
SupplierChannelModel
();
$reader
->
sheet
(
'2021年评估'
,
function
(
$sheet
)
use
(
$reader
,
$supplierChannelModel
)
{
$number
=
0
;
foreach
(
$reader
->
all
()
->
toArray
()
as
$key
=>
$item
)
{
if
(
$key
==
0
)
{
Excel
::
selectSheetsByIndex
(
0
)
->
load
(
$filePath
,
function
(
$reader
)
{
$supplierChannelModel
=
new
SupplierChannelModel
();
$reader
->
sheet
(
'2021年评估'
,
function
(
$sheet
)
use
(
$reader
,
$supplierChannelModel
)
{
$number
=
0
;
foreach
(
$reader
->
all
()
->
toArray
()
as
$key
=>
$item
)
{
if
(
$key
==
0
)
{
continue
;
}
//判断如果有日志了就跳过
$logModel
=
new
LogModel
();
$supplierName
=
trim
(
$item
[
1
]);
$level
=
trim
(
$item
[
2
]);
//先去判断是否存在
$supplierLevelMap
=
$supplierChannelModel
->
where
(
'supplier_name'
,
$supplierName
)
->
select
([
'level'
,
'supplier_id'
])
->
first
();
if
(
empty
(
$supplierLevelMap
))
{
$number
++
;
echo
'供应商不存在 : '
.
$supplierName
.
PHP_EOL
;
//然后修改excel
$sheet
->
cell
(
'D'
.
(
$key
+
1
),
function
(
$cell
)
{
$cell
->
setValue
(
'供应商不存在'
);
});
}
else
{
$supplierLevelMap
=
$supplierLevelMap
->
toArray
();
$supplierId
=
$supplierLevelMap
[
'supplier_id'
];
$existLog
=
$logModel
->
where
(
'supplier_id'
,
$supplierId
)
->
where
(
'action'
,
'脚本处理等级'
)
->
exists
();
if
(
$existLog
)
{
continue
;
}
//判断如果有日志了就跳过
$logModel
=
new
LogModel
();
$supplierName
=
trim
(
$item
[
1
]);
$level
=
trim
(
$item
[
2
]);
//先去判断是否存在
$supplierLevelMap
=
$supplierChannelModel
->
where
(
'supplier_name'
,
$supplierName
)
->
select
([
'level'
,
'supplier_id'
])
->
first
();
if
(
empty
(
$supplierLevelMap
))
{
$number
++
;
echo
'供应商不存在 : '
.
$supplierName
.
PHP_EOL
;
//然后修改excel
$sheet
->
cell
(
'D'
.
(
$key
+
1
),
function
(
$cell
)
{
$cell
->
setValue
(
'供应商不存在'
);
});
}
else
{
$supplierLevelMap
=
$supplierLevelMap
->
toArray
();
$supplierId
=
$supplierLevelMap
[
'supplier_id'
];
$existLog
=
$logModel
->
where
(
'supplier_id'
,
$supplierId
)
->
where
(
'action'
,
'脚本处理等级'
)
->
exists
();
if
(
$existLog
)
{
continue
;
}
$supplierChannelModel
->
where
(
'supplier_name'
,
$supplierName
)
->
update
([
'level'
=>
$level
,
]);
$sheet
->
cell
(
'D'
.
(
$key
+
1
),
function
(
$cell
)
{
$cell
->
setValue
(
'修改成功'
);
});
$originLevel
=
$supplierLevelMap
[
'level'
];
$originLevel
=
$originLevel
?:
'无'
;
$content
=
"admin将供应商等级
$originLevel
修改为
$level
"
;
echo
$content
.
PHP_EOL
;
$logService
=
new
LogService
();
$logService
->
AddAdminLog
(
$supplierId
,
LogModel
::
UPDATE_OPERATE
,
'脚本处理等级'
,
$content
);
}
$supplierChannelModel
->
where
(
'supplier_name'
,
$supplierName
)
->
update
([
'level'
=>
$level
,
]);
$sheet
->
cell
(
'D'
.
(
$key
+
1
),
function
(
$cell
)
{
$cell
->
setValue
(
'修改成功'
);
});
$originLevel
=
$supplierLevelMap
[
'level'
];
$originLevel
=
$originLevel
?:
'无'
;
$content
=
"admin将供应商等级
$originLevel
修改为
$level
"
;
echo
$content
.
PHP_EOL
;
$logService
=
new
LogService
();
$logService
->
AddAdminLog
(
$supplierId
,
LogModel
::
UPDATE_OPERATE
,
'脚本处理等级'
,
$content
);
}
var_dump
(
"一共有${number}个不存在的供应商"
);
});
}
var_dump
(
"一共有${number}个不存在的供应商"
);
});
});
}
...
...
@@ -385,6 +385,19 @@ class DataService
}
}
public
function
trimSupplierName
()
{
$suppliers
=
SupplierChannelModel
::
where
(
'is_type'
,
0
)
->
select
([
'supplier_id'
,
'supplier_name'
])
->
get
()
->
toArray
();
foreach
(
$suppliers
as
$supplier
)
{
if
(
mb_strlen
(
$supplier
[
'supplier_name'
])
!=
mb_strlen
(
trim
(
$supplier
[
'supplier_name'
])))
{
echo
'有空格的供应商 : '
.
$supplier
[
'supplier_name'
]
.
mb_strlen
(
$supplier
[
'supplier_name'
])
.
"_"
.
mb_strlen
(
trim
(
$supplier
[
'supplier_name'
]))
.
PHP_EOL
;
}
}
}
//从excel导入供应商
public
function
importSupplier
()
{
...
...
@@ -393,7 +406,7 @@ class DataService
Excel
::
selectSheetsByIndex
(
0
)
->
load
(
$filePath
,
function
(
$reader
)
{
$supplierChannelModel
=
new
SupplierChannelModel
();
$supplierService
=
new
SupplierService
();
$reader
->
sheet
(
'供应商清单'
,
function
(
$sheet
)
use
(
$reader
,
$supplierChannelModel
,
$supplierService
)
{
$reader
->
sheet
(
'供应商清单'
,
function
(
$sheet
)
use
(
$reader
,
$supplierChannelModel
,
$supplierService
)
{
$number
=
0
;
foreach
(
$reader
->
all
()
->
toArray
()
as
$key
=>
$item
)
{
$supplierName
=
trim
(
$item
[
1
]);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment