Account.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\model;
  4. 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',"is_wx"];
  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])->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')->bind(["nickname","openId"]);
  30. }
  31. public function AccountItem(){
  32. return $this->belongsTo(AccountItem::class,'id','account_id')->bind(["itemid"]);
  33. }
  34. public function getIsWxAttr($v,$row){
  35. return $row['openId']==''?0:1;
  36. }
  37. public function setIsWxAttr($v,$data){
  38. if($v==0){
  39. $this->UserInfo()->where('account_id',$data['id'])->update(['openId'=>'']);
  40. }
  41. }
  42. }