Stakeholder.php
1.44 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
<?php
namespace App\Models\Legal;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
 * Class Stakeholder
 * @package App\Models\Legal
 */
class Stakeholder extends Model
{
    use HasFactory;
    /**
     * @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)
    {
        $stakeholders_model = Stakeholder::query();
        switch (intval($identifier->type)) {
            case 1:
                //个人
                $s_table = Stakeholder::table();
                $sbd_table = StakeholderBankDetail::table();
                $stakeholder = $stakeholders_model->where(['type' => 1, "{$sbd_table}.card_no"=>$identifier->identifier])
                    ->join($sbd_table, "{$s_table}.id", '=', "{$sbd_table}.stakeholder_id")
                    ->pluck("{$s_table}.id");
                break;
            case 2:
                $stakeholder = $stakeholders_model->where(['type' => 2, 'company_no' => $identifier->identifier])->pluck('id');
                break;
            default:
                return [];
                break;
        }
        return array_unique($stakeholder->toArray());
    }
}