ReportCode.php 953 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\model;
  4. use think\Model;
  5. /**
  6. * @mixin \think\Model
  7. */
  8. class ReportCode extends Model
  9. {
  10. public function setField($filed,$vale){
  11. $arr= explode(",",$this->$filed);
  12. if(!in_array($vale,$arr)) $this->$filed == '' ? $this->$filed =$vale : $this->$filed .=",".$vale;
  13. }
  14. public function rmField($filed,$vale){
  15. $arr= explode(",",$this->$filed);
  16. if(is_array($vale)){
  17. foreach ($vale as $v){
  18. if(in_array($v,$arr)){
  19. $key = array_search($v,$arr);
  20. unset($arr[$key]);
  21. }
  22. }
  23. }else{
  24. if(in_array($vale,$arr)){
  25. $key = array_search($vale,$arr);
  26. unset($arr[$key]);
  27. }
  28. }
  29. $this->$filed=implode(",",$arr);
  30. }
  31. public function __destruct(){
  32. $this->save();
  33. }
  34. }