Commit 69530911 by 杨树贤

导出供应商脚本

parent 38ccd26c
...@@ -830,12 +830,49 @@ class DataService ...@@ -830,12 +830,49 @@ class DataService
} }
} }
public function repairData() public static function exportSupplierByDepartment($topDepartmentId)
{ {
dd(SupplierChannelModel::where('supplier_id',13854)->first());
SupplierChannelModel::where('supplier_id',13854)->update([ Excel::create('采购供应商数据导出', function ($excel) use ($topDepartmentId) {
'status' => SupplierChannelModel::STATUS_IN_REVIEW, $departmentIds = DepartmentModel::where('parent_id', $topDepartmentId)->pluck('department_id')->toArray();
'update_time'=>time() $userIds = UserInfoModel::whereIn('department_id', $departmentIds)->pluck('userId')->toArray();
]); $suppliers2022 = $suppliersZhangQi2022 = $suppliersAll = $suppliersZhangQi = [];
//找出相关用户创建的所有供应商
$suppliersAll = SupplierChannelModel::whereIn('create_uid', $userIds)->where('is_type',
0)->get()->toArray();
foreach ($suppliersAll as $supplier) {
$createTime = date('Y-m-d H:i:s', $supplier['create_time']);
$creatName = UserInfoModel::where('userId', $supplier['create_uid'])->value('name');
$data = [
$creatName,
$supplier['supplier_name'],
$createTime,
];
if ($supplier['create_time'] >= 1640966400 - 3600 * 24 * 365) {
$suppliers2022[] = $data;
if ($supplier['pay_type'] == 1) {
$suppliersZhangQi2022[] = $data;
}
}
if ($supplier['pay_type'] == 1) {
$suppliersZhangQi[] = $data;
}
}
$header = ['创建人', '供应商名称', '创建时间'];
// dd($suppliersZhangQi,$header);
$excel->sheet('2022年创建的供应商', function ($sheet) use ($header, $suppliers2022) {
array_unshift($suppliers2022, $header);
$sheet->fromArray($suppliers2022);
});
$excel->sheet('2022年创建的账期供应商', function ($sheet) use ($header, $suppliersZhangQi2022) {
array_unshift($suppliersZhangQi2022, $header);
$sheet->fromArray($suppliersZhangQi2022);
});
$excel->sheet('全部账期供应商', function ($sheet) use ($header, $suppliersZhangQi) {
array_unshift($suppliersZhangQi, $header);
$sheet->fromArray($suppliersZhangQi);
});
})->export('xlsx');
} }
} }
\ No newline at end of file
...@@ -63,4 +63,9 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function () ...@@ -63,4 +63,9 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function ()
}); });
Route::match(['get', 'post'], '/test', function () { Route::match(['get', 'post'], '/test', function () {
$departmentId = request()->input('department_id');
if (empty($departmentId)) {
return '部门id不能为空';
}
\App\Http\Services\DataService::exportSupplierByDepartment($departmentId);
}); });
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