Commit 03d412a7 by 杨树贤

Merge branch 'master' into ysx-供应商新建-20220701

parents e79fedb2 c4e86d79
......@@ -16,6 +16,7 @@ use App\Model\SupplierAttachmentsModel;
use App\Model\SupplierChannelModel;
use App\Model\SupplierContactModel;
use App\Model\SupplierPayTypeModel;
use App\Model\UserInfoModel;
use Carbon\Carbon;
use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
......@@ -662,18 +663,6 @@ class DataService
}
}
public function reSyncSupplierToErp()
{
ini_set('memory_limit', -1);
$suppliers = SupplierChannelModel::select(['supplier_id', 'supplier_name'])->where('is_type', 0)
->where('status', 2)->offset(200)->limit(200)->get()->toArray();
foreach ($suppliers as $supplier) {
if (!empty($supplier['supplier_name'])) {
echo "同步供应商到金蝶 : " . $supplier['supplier_name'] . PHP_EOL;
(new SyncSupplierService())->syncSupplierToErp($supplier['supplier_id']);
}
}
}
//导出重复的供应商
public function findDuplicateSupplier()
......@@ -708,5 +697,50 @@ class DataService
});
})->export('xlsx');
}
public function exportHalfYearSupplier()
{
$starTime = Carbon::now()->startOfYear()->timestamp;
$suppliers = SupplierChannelModel::where('create_time', '>=', $starTime)
->select([
'supplier_name',
'supplier_code',
'create_uid',
])->get();
$excelData = [];
$header = [
'供应商名字',
'编码',
'建档采购员',
'采购主管',
];
foreach ($suppliers as $supplier) {
$supervisor = '';
$user = UserInfoModel::where('userId', $supplier['create_uid'])->first();
$user = !empty($user) ? $user->toArray() : [];
$supervisorDepartmentId = $user['department_id'];
$positionId = \DB::table('user_position')->where('department_id', $supervisorDepartmentId)
->where('position_name', '采购总监')->value('position_id');
if (empty($positionId)) {
$positionId = \DB::table('user_position')
->where('position_name', '运营总监')->value('position_id');
}
$supervisor = UserInfoModel::where('position_id',$positionId)->value('name');
$excelData[] = [
$supplier['supplier_name'],
$supplier['supplier_code'],
array_get($user, 'name'),
$supervisor,
];
}
array_unshift($excelData, $header);
dd($excelData);
Excel::create('2022年新建供应商导出', function ($excel) use ($excelData) {
$excel->sheet('sheet1', function ($sheet) use ($excelData) {
$sheet->fromArray($excelData);
});
})->export('csv');
}
}
......@@ -60,5 +60,5 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function ()
});
Route::match(['get', 'post'], '/test', function () {
// (new \App\Http\Services\DataService())->findDuplicateSupplier();
(new \App\Http\Services\DataService())->exportHalfYearSupplier();
});
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