123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- declare (strict_types = 1);
- namespace app\model;
- use think\Model;
- /**
- * @mixin \think\Model
- */
- class Account extends Model
- {
- public static $account_start=1;
- public static $account_end=0;
- public static $account_del=0;
- protected $globalScope=['Del'];
- protected $append=['depart_name','company_relaton',"is_wx"];
-
- public function scopeDel($query){
- $query->where('is_del',0);
- }
-
- public function getDepartNameAttr($v,$row){
- $item = new AccountItem();
- $depart=$item->where(['account_id'=>$row['id']])->with(['depart'])->findOrEmpty();
- return $depart->isEmpty()?'':$depart->depart_name;
- }
-
- public function getCompanyRelatonAttr($v,$row){
- $item = new AccountCompany();
- $company=$item->where(['account_id'=>$row['id'],'is_del' => 0])->column("companyCode,companyCode companyNo,companyName,companyName company_name,company_type,is_main,status");
- return $company;
- }
- public function UserInfo(){
- return $this->belongsTo(User::class,'id','account_id')->bind(["nickname","openId"]);
- }
-
- public function AccountItem(){
- return $this->belongsTo(AccountItem::class,'id','account_id')->bind(["itemid"]);
- }
-
- public function getIsWxAttr($v,$row){
- return $row['openId']==''?0:1;
- }
-
- public function setIsWxAttr($v,$data){
- if($v==0){
- $this->UserInfo()->where('account_id',$data['id'])->update(['openId'=>'']);
- }
- }
- }
|