Commit bb99ccb0 by 杨树贤

导出数据

parent bed61d3a
......@@ -38,7 +38,7 @@ class SetSupplierFollowUp extends Command
// $service->importSupplierGroup(true);
// $service->changeSupplierType();
// $service->generateYunxinAccount(true);
$service->dealYunxinAccountCreateTime();
$service->exportSupplierForUnionData();
// $service->makeSupplierSystemTagAbnormal();
}
}
......@@ -20,6 +20,14 @@ class AdminUserService
return $userInfoModel->where('userId', $adminId)->first();
}
public function getAdminUserListByCodeIds($codeIds = [])
{
$intraCodeModel = new IntracodeModel();
$userInfoModel = new UserInfoModel();
$adminIds = $intraCodeModel->whereIn('code_id', $codeIds)->pluck('admin_id');
return $userInfoModel->whereIn('userId', $adminIds)->get()->toArray();
}
public function getCodeIdByUserName($userName)
{
$userId = UserInfoModel::where('name', $userName)->value('userId');
......@@ -54,7 +62,7 @@ class AdminUserService
{
$userInfoModel = new UserInfoModel();
$count = $userInfoModel->leftJoin('lie_intracode', 'user_info.userId', '=', 'lie_intracode.admin_id')
->where('lie_intracode.code_id',$codeId)
->where('lie_intracode.code_id', $codeId)
->where('user_info.status', 4)->where('lie_intracode.code_id', '!=', '')->count();
return (bool)$count;
}
......
......@@ -5,6 +5,7 @@ namespace App\Http\Services;
//后台用户相关信息服务
use App\Http\Transformers\SupplierContactTransformer;
use App\Http\Transformers\SupplierTransformer;
use App\Model\DepartmentModel;
use App\Model\IntracodeModel;
use App\Model\LogModel;
use App\Model\RedisModel;
......@@ -436,6 +437,61 @@ class DataService
}
}
}
//导出供应商
public function exportSupplierForUnionData()
{
$suppliers = SupplierChannelModel::select([
'supplier_code',
'supplier_name',
'channel_uid',
])->where('is_type', 0)
->whereRaw('supplier_name NOT LIKE "%-1"')->get();
$excelData = [];
$header = [
'供应商编码',
'供应商名称',
'创建时间',
'对应采购员',
'采购组别',
'所有采购员',
'系统来源',
];
foreach ($suppliers as $supplier) {
$firstChannelUserName = $firstChannelUserDepartmentName = $allChannelUserName = '';
$channelUids = $supplier['channel_uid'] ? explode(',', $supplier['channel_uid']) : [];
if ($channelUids) {
$channelUsers = (new AdminUserService())->getAdminUserListByCodeIds($channelUids);
if (empty($channelUsers)) {
continue;
}
$firstChannelUser = $channelUsers[0];
$firstChannelUserDepartmentName = (new DepartmentModel())->where('department_id',
$firstChannelUser['department_id'])
->value('department_name');
$firstChannelUserName = $firstChannelUser['name'];
$allChannelUserName = implode(',', array_column($channelUsers, 'name'));
}
$itemData = [
$supplier['supplier_code'],
$supplier['supplier_name'],
$supplier['create_time'] ? date('Y-m-d H:i:s', $supplier['create_time']) : '',
$firstChannelUserName,
$firstChannelUserDepartmentName,
$allChannelUserName,
'科技',
];
$excelData[] = $itemData;
}
array_unshift($excelData, $header);
Excel::create('供应商导出', function ($excel) use ($excelData) {
$excel->sheet('sheet1', function ($sheet) use ($excelData) {
$sheet->fromArray($excelData);
});
})->export('xlsx');
}
}
......@@ -54,6 +54,5 @@ Route::group(['middleware' => ['external'],'namespace' => 'Api'], function () {
});
Route::match(['get', 'post'], '/test', function () {
$departmentService = new DepartmentService();
$subordinateUserIds = $departmentService->getSubordinateUserIds(1368);
(new \App\Http\Services\DataService())->exportSupplierForUnionData();
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment