123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace app\common\model;
- use library\tools\Data;
- use think\Model;
- use function Symfony\Component\String\b;
- // 用户开关
- class PlatformSwitch extends Model
- {
- static $type_desc = [
- 1=>'问答通知开关',
- 2=>'视频追更',
- 3=>'图文追更',
- 4=>'资料追更',
- 5=>'供应商订阅',
- 6=>'招聘追更',
- 7=>'视频通知',
- 8=>'图文通知',
- 9=>'资料通知',
- 10=>'新闻通知',
- 11=>'供应商通知',
- ];
- /**
- * 验证开关状态
- * @param $user_id
- * @param $id
- * @param $type 1问答
- * @return int
- */
- public static function checkSwitch($user_id,$id,$type){
- $switch_value = self::where(['user_id'=>$user_id,'switch_id'=>$id,'type'=>$type])->value('switch_value');
- if($switch_value !== null) return $switch_value;
- return in_array($type,[2,3,4,5,6]) ? 0 : 1;
- }
- /**
- * @param $user_id
- * @param $id
- * @param $type 1问答
- */
- public static function userSwitch($user_id,$id,$type)
- {
- $check_tags = self::checkSwitch($user_id,$id,$type);
- $switch_value = $check_tags ? 0:1;
- Data::save('PlatformSwitch',
- ['user_id'=>$user_id,'switch_id'=>$id,'type'=>$type,'switch_value'=>$switch_value],'user_id',
- ['user_id'=>$user_id,'switch_id'=>$id,'type'=>$type]);
- return $switch_value;
- }
- /**
- * 更消息推送
- * @param $type 类型
- * @param $id 相关id
- * @param $up_title 上级标题
- * @param $title 更新的标题
- */
- public static function followMsg($type,$id,$up_title,$title,$children_id = 0)
- {
- $module = '';
- $content = '';
- switch ($type) {
- case 2:
- $module = 'video';
- $content = '您追播的【'.$up_title.'】'.$title.'已更新!';
- break;
- case 3:
- $module = 'article';
- $content = '您订阅的【'.$up_title.'】'.$title.'已更新!';
- break;
- case 4:
- $module = 'datum';
- $content = '您订阅的【'.$up_title.'】'.$title.'已更新!';
- break;
- case 5:
- $module = 'supplier';
- $content = '您订阅的【'.$up_title.'】'.$title.'已更新!';
- break;
- }
- $all_user = static::where(['type'=>$type,'switch_id'=>$id,'switch_value'=>1])->column('user_id');
- array_walk($all_user,function ($v) use ($module,$type,$id,$content,$children_id){
- UserMessage::sendUserMessage($v,$module,5,0,0,$id,$content,$children_id,$id);
- });
- }
- }
|