Stakeholder.php
1.72 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace App\Models\Legal;
use App\Models\BaseModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Class Stakeholder
* @package App\Models\Legal
*/
class Stakeholder extends BaseModel
{
use HasFactory,SoftDeletes;
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function detail()
{
return $this->hasMany(StakeholderBankDetail::class, 'stakeholder_id', 'id');
}
/**
* 获取用户的所有关联id
* @param object $identifier
* @return array
*/
public static function stakeholderIds(object $identifier)
{
switch (intval($identifier->type)) {
case 1:
//个人
$s_table = Stakeholder::table();
$sbd_table = StakeholderBankDetail::table();
$stakeholder = Stakeholder::query()->where(['type' => 1, "{$sbd_table}.card_no"=>$identifier->identifier])
->join($sbd_table, "{$s_table}.id", '=', "{$sbd_table}.stakeholder_id")
->pluck("{$s_table}.id")->toArray();
$stakeholder_ids = Stakeholder::query()->where(['type'=>1 , 'card_no'=>$identifier->identifier])
->pluck('id')->toArray();
$stakeholder = array_merge($stakeholder, $stakeholder_ids);
break;
case 2:
$stakeholder = Stakeholder::query()->where(['type' => 2, 'company_no' => $identifier->identifier])->pluck('id')->toArray();
break;
default:
return [];
break;
}
return array_unique($stakeholder);
}
}