PlatformSwitch.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace app\common\model;
  3. use library\tools\Data;
  4. use think\Model;
  5. // 用户开关
  6. class PlatformSwitch extends Model
  7. {
  8. static $type_desc = [
  9. 1=>'问答通知开关', 2=>'视频追更', 3=>'图文追更', 4=>'资料追更', 5=>'供应商追更', 6=>'招聘追更'
  10. ];
  11. /**
  12. * 验证开关状态
  13. * @param $user_id
  14. * @param $id
  15. * @param $type 1问答
  16. * @return int
  17. */
  18. public static function checkSwitch($user_id,$id,$type){
  19. $switch_value = self::where(['user_id'=>$user_id,'switch_id'=>$id,'type'=>$type])->value('switch_value');
  20. return $switch_value === 0 ? 0 : 1;
  21. }
  22. /**
  23. * @param $user_id
  24. * @param $id
  25. * @param $type 1问答
  26. */
  27. public static function userSwitch($user_id,$id,$type)
  28. {
  29. $check_tags = self::checkSwitch($user_id,$id,$type);
  30. $switch_value = $check_tags ? 0:1;
  31. Data::save('PlatformSwitch',
  32. ['user_id'=>$user_id,'switch_id'=>$id,'type'=>$type,'switch_value'=>$switch_value],'user_id',
  33. ['user_id'=>$user_id,'switch_id'=>$id,'type'=>$type]);
  34. return $switch_value;
  35. }
  36. }