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
f3019cfb
authored
May 06, 2021
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
test
parent
e0775771
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
178 additions
and
169 deletions
app/Http/Services/DataService.php
app/Http/routes.php
app/Http/Services/DataService.php
View file @
f3019cfb
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
namespace
App\Http\Services
;
namespace
App\Http\Services
;
//后台用户相关信息服务
//后台用户相关信息服务
use
App\Model\BrandModel
;
use
App\Model\IntracodeModel
;
use
App\Model\IntracodeModel
;
use
App\Model\SupplierChannelModel
;
use
App\Model\SupplierChannelModel
;
use
App\Model\SupplierContactModel
;
use
App\Model\SupplierContactModel
;
...
@@ -12,175 +13,181 @@ use Illuminate\Support\Facades\DB;
...
@@ -12,175 +13,181 @@ use Illuminate\Support\Facades\DB;
class
DataService
class
DataService
{
{
//修复数据
// //修复数据
public
function
repairData
(
$limit
=
0
)
// public function repairData($limit = 0)
{
// {
//先找出和无效采购员(离职或者不是采购员)相关的供应商
// //先找出和无效采购员(离职或者不是采购员)相关的供应商
//写死
// //写死
$invalidChannelUserName
=
[
// $invalidChannelUserName = [
"葛金菊"
,
// "葛金菊",
"姜喆"
,
// "姜喆",
"罗晓民"
,
// "罗晓民",
"周亚琳"
,
// "周亚琳",
"左佳晨"
,
// "左佳晨",
"陈泽彬"
,
// "陈泽彬",
"李跃"
,
// "李跃",
"赵佩旋"
,
// "赵佩旋",
"朱国军"
,
// "朱国军",
"许金荣"
,
// "许金荣",
"余佳兰"
,
// "余佳兰",
"李晶晶"
,
// "李晶晶",
"朱玉嘉"
// "朱玉嘉"
];
// ];
//找出对应的code_id
// //找出对应的code_id
$userModel
=
new
UserInfoModel
();
// $userModel = new UserInfoModel();
$invalidChannelUserIds
=
$userModel
->
whereIn
(
'name'
,
$invalidChannelUserName
)
->
pluck
(
'userId'
);
// $invalidChannelUserIds = $userModel->whereIn('name', $invalidChannelUserName)->pluck('userId');
//找出对应的codeId
// //找出对应的codeId
$adminUserService
=
new
AdminUserService
();
// $adminUserService = new AdminUserService();
$codeIds
=
$adminUserService
->
getCodeIdsByUserIds
(
$invalidChannelUserIds
);
// $codeIds = $adminUserService->getCodeIdsByUserIds($invalidChannelUserIds);
$codeIds
=
$codeIds
->
toArray
();
// $codeIds = $codeIds->toArray();
$likeSqlRaw
=
implode
(
'|'
,
$codeIds
);
// $likeSqlRaw = implode('|', $codeIds);
$model
=
new
SupplierChannelModel
();
// $model = new SupplierChannelModel();
//根据code_id去找供应商表里面找到包含该code_id的供应商
// //根据code_id去找供应商表里面找到包含该code_id的供应商
if
(
!
empty
(
$limit
))
{
// if (!empty($limit)) {
$suppliers
=
$model
->
whereRaw
(
"channel_uid REGEXP '
$likeSqlRaw
'"
)
->
where
(
'is_type'
,
// $suppliers = $model->whereRaw("channel_uid REGEXP '$likeSqlRaw'")->where('is_type',
0
)
->
limit
(
$limit
)
->
get
();
// 0)->limit($limit)->get();
}
else
{
// } else {
$suppliers
=
$model
->
whereRaw
(
"channel_uid REGEXP '
$likeSqlRaw
'"
)
->
where
(
'is_type'
,
0
)
->
get
();
// $suppliers = $model->whereRaw("channel_uid REGEXP '$likeSqlRaw'")->where('is_type', 0)->get();
}
// }
if
(
$suppliers
)
{
// if ($suppliers) {
$suppliers
=
$suppliers
->
toArray
();
// $suppliers = $suppliers->toArray();
}
else
{
// } else {
//
echo
"已经处理完"
;
// echo "已经处理完";
die
;
// die;
}
// }
$i
=
0
;
// $i = 0;
foreach
(
$suppliers
as
$supplier
)
{
// foreach ($suppliers as $supplier) {
$channelUidResult
=
[];
// $channelUidResult = [];
$channelUid
=
explode
(
','
,
$supplier
[
'channel_uid'
]);
// $channelUid = explode(',', $supplier['channel_uid']);
foreach
(
$channelUid
as
$key
=>
$uid
)
{
// foreach ($channelUid as $key => $uid) {
//如果不属于不合理采购员codeId,则保留
// //如果不属于不合理采购员codeId,则保留
if
(
!
in_array
(
$uid
,
$codeIds
))
{
// if (!in_array($uid, $codeIds)) {
$channelUidResult
[]
=
$uid
;
// $channelUidResult[] = $uid;
}
// }
}
// }
$channelUidResult
=
implode
(
','
,
$channelUidResult
);
// $channelUidResult = implode(',', $channelUidResult);
$content
=
"采购员从"
.
implode
(
','
,
$channelUid
)
.
'修改到'
.
$channelUidResult
;
// $content = "采购员从" . implode(',', $channelUid) . '修改到' . $channelUidResult;
//写日志
// //写日志
$remark
=
implode
(
','
,
$channelUid
)
.
"|"
.
$channelUidResult
;
// $remark = implode(',', $channelUid) . "|" . $channelUidResult;
$logService
=
new
LogService
();
// $logService = new LogService();
$logService
->
AddLog
(
$supplier
[
'supplier_id'
],
1
,
"系统修改采购员"
,
$content
,
$remark
);
// $logService->AddLog($supplier['supplier_id'], 1, "系统修改采购员", $content, $remark);
$model
->
where
(
'supplier_id'
,
$supplier
[
'supplier_id'
])
->
update
([
// $model->where('supplier_id', $supplier['supplier_id'])->update([
'channel_uid'
=>
$channelUidResult
,
// 'channel_uid' => $channelUidResult,
]);
// ]);
$i
++
;
// $i++;
if
(
!
empty
(
$limit
))
{
// if (!empty($limit)) {
print_r
(
$supplier
[
'supplier_id'
]
.
"<br>"
);
// print_r($supplier['supplier_id'] . "<br>");
}
// }
}
// }
echo
"修改了${i}条记录"
;
// echo "修改了${i}条记录";
die
;
// die;
}
// }
//
//补全联系人
// //补全联系人
public
function
completeContact
(
$limit
=
0
)
// public function completeContact($limit = 0)
{
// {
$i
=
0
;
// $i = 0;
//先找出联系人和采购员数量对不上的记录;
// //先找出联系人和采购员数量对不上的记录;
$model
=
new
SupplierChannelModel
();
// $model = new SupplierChannelModel();
if
(
!
empty
(
$limit
))
{
// if (!empty($limit)) {
$suppliers
=
$model
->
where
(
'is_type'
,
0
)
->
limit
(
$limit
)
->
get
()
->
toArray
();
// $suppliers = $model->where('is_type', 0)->limit($limit)->get()->toArray();
}
else
{
// } else {
$suppliers
=
$model
->
where
(
'is_type'
,
0
)
->
get
()
->
toArray
();
// $suppliers = $model->where('is_type', 0)->get()->toArray();
}
// }
$contactModel
=
new
SupplierContactModel
();
// $contactModel = new SupplierContactModel();
foreach
(
$suppliers
as
$supplier
)
{
// foreach ($suppliers as $supplier) {
//找出联系人数量
// //找出联系人数量
if
(
empty
(
$supplier
[
'channel_uid'
]))
{
// if (empty($supplier['channel_uid'])) {
continue
;
// continue;
}
// }
$contactCount
=
$contactModel
->
where
(
'supplier_id'
,
$supplier
[
'supplier_id'
])
->
where
(
'can_check_uids'
,
'!='
,
// $contactCount = $contactModel->where('supplier_id', $supplier['supplier_id'])->where('can_check_uids', '!=',
''
)
->
count
();
// '')->count();
$channelUidCount
=
count
(
explode
(
','
,
$supplier
[
'channel_uid'
]));
// $channelUidCount = count(explode(',', $supplier['channel_uid']));
if
(
$contactCount
>=
$channelUidCount
)
{
// if ($contactCount >= $channelUidCount) {
continue
;
// continue;
}
// }
//直接根据采购员id
// //直接根据采购员id
// $needAppendCount = $channelUidCount - $count;
//// $needAppendCount = $channelUidCount - $count;
// $countArray = array_fill(0, $needAppendCount, 1);
//// $countArray = array_fill(0, $needAppendCount, 1);
$countArray
=
array_fill
(
0
,
$channelUidCount
,
1
);
// $countArray = array_fill(0, $channelUidCount, 1);
//补的时候,记得把采购员id写进去
// //补的时候,记得把采购员id写进去
$channelUids
=
explode
(
','
,
$supplier
[
'channel_uid'
]);
// $channelUids = explode(',', $supplier['channel_uid']);
foreach
(
$countArray
as
$key
=>
$value
)
{
// foreach ($countArray as $key => $value) {
$channelUserId
=
$channelUids
[
$key
];
// $channelUserId = $channelUids[$key];
$data
=
[
// $data = [
'supplier_id'
=>
$supplier
[
'supplier_id'
],
// 'supplier_id' => $supplier['supplier_id'],
'can_check_uids'
=>
$channelUserId
,
// 'can_check_uids' => $channelUserId,
'add_time'
=>
time
(),
// 'add_time' => time(),
'admin_id'
=>
1000
,
// 'admin_id' => 1000,
];
// ];
$contactModel
->
insert
(
$data
);
// $contactModel->insert($data);
}
// }
$i
++
;
// $i++;
if
(
!
empty
(
$limit
))
{
// if (!empty($limit)) {
print_r
(
$supplier
[
'supplier_id'
]
.
"<br>"
);
// print_r($supplier['supplier_id'] . "<br>");
}
// }
// dd($supplier['supplier_id']);
//// dd($supplier['supplier_id']);
}
// }
echo
"已经处理"
.
$i
.
"家供应商的联系方式"
;
// echo "已经处理" . $i . "家供应商的联系方式";
}
// }
//
//导出不合理的采购员的供应商
// //导出不合理的采购员的供应商
public
function
exportNotValidChannelUid
()
// public function exportNotValidChannelUid()
{
// {
$supplierModel
=
new
SupplierChannelModel
();
// $supplierModel = new SupplierChannelModel();
$list
=
$supplierModel
->
where
(
'is_type'
,
0
)
->
whereRaw
(
'length(channel_uid) > 5'
)
->
get
();
// $list = $supplierModel->where('is_type', 0)->whereRaw('length(channel_uid) > 5')->get();
$result
=
[];
// $result = [];
foreach
(
$list
as
$key
=>
$item
)
{
// foreach ($list as $key => $item) {
$channelUid
=
explode
(
','
,
$item
[
'channel_uid'
]);
// $channelUid = explode(',', $item['channel_uid']);
$adminService
=
new
AdminUserService
();
// $adminService = new AdminUserService();
$names
=
[];
// $names = [];
foreach
(
$channelUid
as
$codeId
)
{
// foreach ($channelUid as $codeId) {
$user
=
$adminService
->
getAdminUserInfoByCodeId
(
$codeId
);
// $user = $adminService->getAdminUserInfoByCodeId($codeId);
$name
=
array_get
(
$user
,
'name'
);
// $name = array_get($user, 'name');
$names
[]
=
$name
;
// $names[] = $name;
}
// }
$names
=
implode
(
'|'
,
$names
);
// $names = implode('|', $names);
$result
[]
=
[
// $result[] = [
'name'
=>
'"'
.
$item
[
'supplier_name'
]
.
'"'
,
// 'name' => '"' . $item['supplier_name'] . '"',
'value'
=>
$names
,
// 'value' => $names,
'code'
=>
$item
[
'supplier_code'
]
// 'code' => $item['supplier_code']
];
// ];
}
// }
//
// 需要导出的内容
// // 需要导出的内容
//
// 文件名,这里都要将utf-8编码转为gbk,要不可能出现乱码现象
// // 文件名,这里都要将utf-8编码转为gbk,要不可能出现乱码现象
$filename
=
$this
->
utfToGbk
(
'导出csv文件.csv'
);
// $filename = $this->utfToGbk('导出csv文件.csv');
//
// 拼接文件信息,这里注意两点
// // 拼接文件信息,这里注意两点
// 1、字段与字段之间用逗号分隔开
// // 1、字段与字段之间用逗号分隔开
// 2、行与行之间需要换行符
// // 2、行与行之间需要换行符
$fileData
=
$this
->
utfToGbk
(
'编码, 姓名, 采购'
)
.
"
\n
"
;
// $fileData = $this->utfToGbk('编码, 姓名, 采购') . "\n";
foreach
(
$result
as
$value
)
{
// foreach ($result as $value) {
$temp
=
$value
[
'code'
]
.
','
.
$value
[
'name'
]
.
','
.
// $temp = $value['code'] . ',' . $value['name'] . ',' .
$value
[
'value'
];
// $value['value'];
$fileData
.=
$this
->
utfToGbk
(
$temp
)
.
"
\n
"
;
// $fileData .= $this->utfToGbk($temp) . "\n";
}
// }
//
// 头信息设置
// // 头信息设置
header
(
"Content-type:text/csv"
);
// header("Content-type:text/csv");
header
(
"Content-Disposition:attachment;filename="
.
$filename
);
// header("Content-Disposition:attachment;filename=" . $filename);
header
(
'Cache-Control:must-revalidate,post-check=0,pre-check=0'
);
// header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
header
(
'Expires:0'
);
// header('Expires:0');
header
(
'Pragma:public'
);
// header('Pragma:public');
echo
$fileData
;
// echo $fileData;
exit
;
// exit;
}
// }
//
// function utfToGbk($data)
// {
// return iconv('utf-8', 'GBK', $data);
// }
function
utfToGbk
(
$data
)
public
function
test
(
)
{
{
return
iconv
(
'utf-8'
,
'GBK'
,
$data
);
$model
=
new
BrandModel
();
dd
(
DB
::
connection
(
'spu'
)
->
table
(
'brand'
)
->
count
());
}
}
}
}
\ No newline at end of file
app/Http/routes.php
View file @
f3019cfb
...
@@ -42,6 +42,7 @@ Route::group(['middleware' => ['web'], 'namespace' => 'Api'], function () {
...
@@ -42,6 +42,7 @@ Route::group(['middleware' => ['web'], 'namespace' => 'Api'], function () {
});
});
Route
::
match
([
'get'
,
'post'
],
'/test'
,
function
()
{
Route
::
match
([
'get'
,
'post'
],
'/test'
,
function
()
{
$service
=
new
\App\Http\Services\DataService
();
$service
=
new
\App\Http\Services\DataService
();
$service
->
repairData
(
10
);
$service
->
test
();
// $service->repairData(10);
// $service->completeContact(10);
// $service->completeContact(10);
});
});
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