123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace app\common\model;
- use think\Model;
- use JPush\Client;
- require_once env('root_path').'vendor/jpush/jpush/autoload.php';
- // 会员消息
- class UserMessage extends Model
- {
- // ['$module'=>['$type'=>['title'=>'标题','msg'=>['$msg_key'=>'','$msg_key'=>'']]]
- static $type_desc = [
- 'video'=>[
- 1=>['title'=>'视频投稿','msg'=>['视频投稿成功请等待审核']],
- 2=>['title'=>'视频审核','msg'=>['恭喜您视频审核成功','抱歉啦视频审核失败~~']],
- 3=>['title'=>'视频评论回复','msg'=>['有会员评论了您的回复']],
- 4=>['title'=>'视频评论','msg'=>['有会员评论了您的视频']],
- 5=>['title'=>'追更','msg'=>['您追更的视频有更新']],
- ],// 视频
- 'article'=>[
- 1=>['title'=>'图文投稿','msg'=>['图文投稿成功请等待审核']],
- 2=>['title'=>'图文审核','msg'=>['恭喜您图文审核成功','抱歉啦图文审核失败~~']],
- 3=>['title'=>'图文评论回复','msg'=>['有会员评论了您的回复']],
- 4=>['title'=>'图文评论','msg'=>['有会员评论了您的图文']],
- ],//图文
- 'datum'=>[
- 1=>['title'=>'资料投稿','msg'=>['资料投稿成功请等待审核']],
- 2=>['title'=>'资料审核','msg'=>['恭喜您资料审核成功','抱歉啦资料审核失败~~']],
- 3=>['title'=>'资料评论回复','msg'=>['有会员评论了您的回复']],
- ],// 资料
- 'activity'=>[
- 1=>['title'=>'活动报名','msg'=>['恭喜您活动报名成功']],
- ],// 活动
- 'demand'=>[
- 1=>['title'=>'需求投稿','msg'=>['需求投稿成功请等待审核']],
- 2=>['title'=>'需求审核','msg'=>['恭喜您需求审核成功','抱歉啦需求审核失败~~']],
- 3=>['title'=>'需求评论回复','msg'=>['有会员评论了您的回复']],
- 4=>['title'=>'需求评论','msg'=>['有会员评论了您的需求']],
- ],// 需求
- 'forum'=>[
- 1=>['title'=>'问答投稿','msg'=>['问答投稿成功']],
- 2=>['title'=>'问答审核','msg'=>['恭喜您问答审核成功','抱歉啦问答审核失败']],
- 3=>['title'=>'回复的评论','msg'=>['有会员评论了您的回复']],
- 4=>['title'=>'评论的回复','msg'=>['有会员回复了您的评论']],
- 5=>['title'=>'问答回复','msg'=>['有会员回复了您的问题']],
- ],// 问答
- 'press'=>[
- 1=>['title'=>'评论回复','msg'=>['有会员回复了您的评论']],
- ],// 新闻
- 'mall'=>[
- ],// 商城
- 'feedback'=>[
- 1=>['title'=>'反馈内容回复','msg'=>['平台回复了您的反馈']],
- ],// 反馈
- 'user' =>[
- 1=>['title'=>'反馈内容回复','msg'=>['平台回复了您的反馈']],
- ],// 会员管理
- ];
- /**
- * 发送会员消息
- * @param $to_user 发送给谁
- * @param $module 模块
- * @param $type 模块类型
- * @param $msg_key 内容key[msg的key]
- * @param $from_user 哪个会员发送的
- * @param $rel_id 关联的id
- * @param string $content
- */
- public static function sendUserMessage($to_user,$module,$type,$msg_key,$from_user,$rel_id,$content = '')
- {
- $message = [
- 'user_id'=>$to_user,
- 'from_user'=>$from_user,
- 'content'=> $content ? $content : static::$type_desc[$module][$type]['msg'][$msg_key] ,
- 'relation_id'=>$rel_id,
- 'type_id'=>$type,
- 'module'=>$module,
- 'title'=>static::$type_desc[$module][$type]['title'],
- ];
- $from_name = User::where('id',$from_user)->value('name');
- switch ($module) {
- case 'video':
- if(in_array($type,[3,4]))Jpush($to_user,$from_name.$message['content'],$module,$type,$rel_id);// $message['jg_type'] = 1;
- break;
- case 'article':
- if(in_array($type,[3,4]))Jpush($to_user,$from_name.$message['content'],$module,$type,$rel_id);// $message['jg_type'] = 1;
- break;
- case 'press':
- if(in_array($type,[1])) Jpush($to_user,$from_name.$message['content'],$module,$type,$rel_id);// $message['jg_type'] = 1;
- break;
- case 'forum':
- $switch = PlatformSwitch::checkSwitch($to_user,$rel_id,1);
- if($switch && in_array($type,[3,4,5]))Jpush($to_user,$from_name.$message['content'],$module,$type,$rel_id);// $message['jg_type'] = 1;
- break;
- case 'feedback':
- if(in_array($type,[1]))Jpush($to_user,$from_name.$message['content'],$module,$type,$rel_id);// $message['jg_type'] = 1;
- break;
- }
- self::create($message);
- // 哪些模块中的某些类型需要极光推送
- }
- /**
- * 获取消息未读数量
- * @param $user_id 发送给谁
- * @param $module 模块
- * @param $type 模块类型
- * @param $msg_key 内容key[msg的key]
- */
- public static function getUnreadNum($user_id,$module,$type)
- {
- return static::where(['user_id'=>$user_id,'module'=>$module,'type'=>$type,'is_read'=>0])->count();
- }
- }
|