Account.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\model;
  4. use app\account\model\AccountItem;use app\account\model\User;use think\Model;
  5. /**
  6. * @mixin \think\Model
  7. */
  8. class Account extends Model
  9. {
  10. public static $account_start=1;
  11. public static $account_end=0;
  12. public static $account_del=0;
  13. protected $globalScope=['Del'];
  14. protected $append=['depart_name','company_relaton'];
  15. public function scopeDel($query){
  16. $query->where('is_del',0);
  17. }
  18. public function getDepartNameAttr($v,$row){
  19. $item = new AccountItem();
  20. $depart=$item->where(['account_id'=>$row['id']])->with(['depart'])->findOrEmpty();
  21. return $depart->isEmpty()?'':$depart->depart_name;
  22. }
  23. public function getCompanyRelatonAttr($v,$row){
  24. $item = new AccountCompany();
  25. $company=$item->where(['account_id'=>$row['id'],'is_del' => 0, 'status' => 1])->column("companyCode,companyCode companyNo,companyName,companyName company_name,company_type,is_main,status");
  26. return $company;
  27. }
  28. public function UserInfo(){
  29. return $this->belongsTo(User::class,'id','account_id');
  30. }
  31. public function AccountItem(){
  32. return $this->belongsTo(AccountItem::class,'id','account_id');
  33. }
  34. public function CompanyRelat(){
  35. }
  36. }