PlatformSwitch.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\common\model;
  3. use library\tools\Data;
  4. use think\Model;
  5. use function Symfony\Component\String\b;
  6. // 用户开关
  7. class PlatformSwitch extends Model
  8. {
  9. static $type_desc = [
  10. 1=>'问答通知开关',
  11. 2=>'视频追更',
  12. 3=>'图文追更',
  13. 4=>'资料追更',
  14. 5=>'供应商订阅',
  15. 6=>'招聘追更',
  16. 7=>'视频通知',
  17. 8=>'图文通知',
  18. 9=>'资料通知',
  19. 10=>'新闻通知',
  20. 11=>'供应商通知',
  21. ];
  22. /**
  23. * 验证开关状态
  24. * @param $user_id
  25. * @param $id
  26. * @param $type 1问答
  27. * @return int
  28. */
  29. public static function checkSwitch($user_id,$id,$type){
  30. $switch_value = self::where(['user_id'=>$user_id,'switch_id'=>$id,'type'=>$type])->value('switch_value');
  31. if($switch_value !== null) return $switch_value;
  32. return in_array($type,[2,3,4,5,6]) ? 0 : 1;
  33. }
  34. /**
  35. * @param $user_id
  36. * @param $id
  37. * @param $type 1问答
  38. */
  39. public static function userSwitch($user_id,$id,$type)
  40. {
  41. $check_tags = self::checkSwitch($user_id,$id,$type);
  42. $switch_value = $check_tags ? 0:1;
  43. Data::save('PlatformSwitch',
  44. ['user_id'=>$user_id,'switch_id'=>$id,'type'=>$type,'switch_value'=>$switch_value],'user_id',
  45. ['user_id'=>$user_id,'switch_id'=>$id,'type'=>$type]);
  46. return $switch_value;
  47. }
  48. /**
  49. * 更消息推送
  50. * @param $type 类型
  51. * @param $id 相关id
  52. * @param $up_title 上级标题
  53. * @param $title 更新的标题
  54. */
  55. public static function followMsg($type,$id,$up_title,$title,$children_id = 0)
  56. {
  57. $module = '';
  58. $content = '';
  59. switch ($type) {
  60. case 2:
  61. $module = 'video';
  62. $content = '您追播的【'.$up_title.'】'.$title.'已更新!';
  63. break;
  64. case 3:
  65. $module = 'article';
  66. $content = '您订阅的【'.$up_title.'】'.$title.'已更新!';
  67. break;
  68. case 4:
  69. $module = 'datum';
  70. $content = '您订阅的【'.$up_title.'】'.$title.'已更新!';
  71. break;
  72. case 5:
  73. $module = 'supplier';
  74. $content = '您订阅的【'.$up_title.'】'.$title.'已更新!';
  75. break;
  76. }
  77. $all_user = static::where(['type'=>$type,'switch_id'=>$id,'switch_value'=>1])->column('user_id');
  78. array_walk($all_user,function ($v) use ($module,$type,$id,$content,$children_id){
  79. UserMessage::sendUserMessage($v,$module,5,0,0,$id,$content,$children_id,$id);
  80. });
  81. }
  82. }