UserSiteMsg.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\SiteMsg;
  5. use app\common\model\SiteMsgRead;
  6. /**
  7. * 会员站内信息接口
  8. */
  9. class UserSiteMsg extends Api
  10. {
  11. protected $noNeedRight="*";
  12. /**
  13. * 列表
  14. * @ApiParams (name=type,description=不传全部1已读2未读)
  15. * @ApiParams (name=page,description=分页)
  16. * @ApiParams (name=limit,description=分页)
  17. * @ApiReturnParams (name=source,description=来源)
  18. * @ApiReturnParams (name=title,description=标题)
  19. * @ApiReturnParams (name=content,description=内容)
  20. * @ApiReturnParams (name=create_time,description=发布时间)
  21. */
  22. public function index(){
  23. $user=$this->auth->getUser();
  24. $query=(new SiteMsg)->getQuery();
  25. $query->whereIn('user_id',[0,$user['id']]);
  26. $query->order('id','desc');
  27. $type=input('type');
  28. if($type==1){
  29. $query
  30. ->whereExists("select * from site_msg_read where site_msg_read.site_msg_id=site_msg.id and site_msg_read.user_id={$user['id']}");
  31. }elseif ($type==2){
  32. $query
  33. ->whereNotExists("select * from site_msg_read where site_msg_read.site_msg_id=site_msg.id and site_msg_read.user_id={$user['id']}");
  34. }
  35. $list=$query
  36. ->field('user_id',true)
  37. ->paginate(input('limit',15));
  38. $this->success('',$list);
  39. }
  40. /**
  41. * 详情
  42. * @ApiParams (name=id,description=信ID)
  43. */
  44. public function show(){
  45. $data=$this->_validate([
  46. 'id'=>['require'],
  47. ]);
  48. $user=$this->auth->getUser();
  49. $msg=SiteMsg::findOrFail($data['id']);
  50. if(!$msg->read()->filterUser($user)->find()) {
  51. $msg->read()->save([
  52. 'user_id' => $user->id,
  53. ]);
  54. }
  55. $this->success('',$msg);
  56. }
  57. }