CompanyCatProfit.php 869 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\model;
  4. use think\Model;
  5. /**
  6. * @mixin \think\Model
  7. */
  8. class CompanyCatProfit extends Model
  9. {
  10. public function GetRate($companyNo,$cat_id,$field){
  11. $rate=$this->where(["companyNo"=>$companyNo,"cat_id"=>$cat_id])->value($field,0);
  12. if($rate==0){
  13. $parent = $this->name("cat")->where(["id"=>$cat_id])->value("pid",0);
  14. if($parent>0)$rate=$this->GetRate($companyNo,$parent,$field);
  15. }
  16. return $rate;
  17. }
  18. public function GetAllRate($companyNo,$cat_id){
  19. $rate=$this->where(['companyNo'=>$companyNo,'cat_id'=>$cat_id])->findOrEmpty();
  20. if($rate->isEmpty()){
  21. $parent = $this->name('cat')->where(['id'=>$cat_id])->value('pid',0);
  22. if($parent>0)$rate=$this->GetAllRate($companyNo,$parent);
  23. }
  24. return $rate;
  25. }
  26. }