AccountCompany.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace app\user\model;
  3. class AccountCompany extends Base
  4. {
  5. //设置字段信息
  6. protected $schema = [
  7. 'id' =>'bigint',//
  8. 'account_id' =>'bigint',//账户id
  9. 'companyCode' =>'varchar',//公司编号
  10. 'companyName' =>'varchar',//公司名称
  11. 'company_type' =>'tinyint',//公司类型:0无设置,1供应商,2业务公司
  12. 'is_main' =>'tinyint',//是否为默认公司
  13. 'status' =>'tinyint',//使用状态 1启用 0禁用
  14. 'is_del' =>'tinyint',//删除1是 0否
  15. 'addtime' =>'datetime',//
  16. 'updatetime' =>'datetime',//
  17. ];
  18. protected $updateTime='updatetime';
  19. protected $createTime='addtime';
  20. protected $append= ['invoice_code'];
  21. // protected $visible = ["id","companyCode","companyName","company_type","is_main","status","addtime"];
  22. public function accountInfo(){
  23. return $this->belongsTo(Account::class,"account_id","id")->bind(['nickname','user_mobile','mobile','openId','depart_name','itemid','depart_link','position',"username"]);
  24. }
  25. public function getInvoiceCodeAttr($value,$data){
  26. return Headquarters::where(['code'=>$data['companyCode']])->value("invoice_code",'');
  27. }
  28. public static function SupplierHasAcount($code){
  29. $isRela=self::where(['companyCode'=>$code,'status'=>1,'is_del'=>0])->select();
  30. if ($isRela->isEmpty()) return false;
  31. $account_id = $isRela->column("account_id");
  32. $info = Account::whereIn("id",$account_id)->where(["status"=>1,"level"=>3])->select();
  33. return !$info->isEmpty();
  34. }
  35. }