ProjectIndustryRelated.php
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace App\Models\Industry;
use App\Helper\Arr;
use App\Models\Base;
class ProjectIndustryRelated extends Base
{
protected $table = 'gl_project_industry_related';
/**
* 项目行业数据关联
* @param $project_id
* @param $industry_ids
* @author Akun
* @date 2025/03/05 10:52
*/
public static function saveRelated($project_id, $industry_ids)
{
if (!is_array($industry_ids)) {
$industry_ids = array_filter(Arr::splitFilterToArray($industry_ids), 'intval');
}
//先删除
self::where('project_id', $project_id)->delete();
//批量保存
if (!empty($industry_ids)) {
$data = [];
foreach ($industry_ids as $industry_id) {
$data[] = [
'project_id' => $project_id,
'industry_id' => $industry_id,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s')
];
}
self::insert($data);
}
}
}