SystemMessage.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace app\api\controller\v2;
  3. use app\api\controller\Api;
  4. class SystemMessage extends Api
  5. {
  6. public function getMessageList()
  7. {
  8. $checkResult = $this->validate($this->input,
  9. [
  10. ['page', 'require|integer|egt:1', '页数不能为空|页数必须是整数|页数必须大于1'],
  11. ['pageSize', 'require|integer|egt:10', '页码不能为空|页码必须是整数|页码必须大于10'],
  12. ]);
  13. if (true !== $checkResult) {
  14. $this->jsonResult('', 0, $checkResult);
  15. }
  16. $list = model('SystemMessage')
  17. ->where('member_id', $this->input['userid'])
  18. ->order("id desc")
  19. ->paginate(['list_rows' => $this->input['pageSize'], 'page' => $this->input['page']])
  20. ->toArray();
  21. $this->jsonResult($list, 1, '获取数据成功');
  22. }
  23. public function getMessageDetail(){
  24. $checkResult = $this->validate($this->input,
  25. [
  26. ['id', 'require|integer|egt:1', '记录不能为空|记录必须是整数|记录必须大于1']
  27. ]);
  28. if (true !== $checkResult) {
  29. $this->jsonResult('', 0, $checkResult);
  30. }
  31. $info = model('SystemMessage')
  32. ->where('id', $this->input['id'])
  33. ->where('member_id', $this->input['userid'])
  34. ->find();
  35. if($info && $info['is_show'] == 1){
  36. model('SystemMessage')
  37. ->where('id', $this->input['id'])
  38. ->where('member_id', $this->input['userid'])
  39. ->update(['is_show'=>2,'update_time'=>time()]);
  40. }
  41. $this->jsonResult($info, 1, '获取数据成功');
  42. }
  43. public function read(){
  44. model('SystemMessage')
  45. ->where('is_show', 1)
  46. ->where('member_id', $this->input['userid'])
  47. ->update(['is_show'=>2,'update_time'=>time()]);
  48. $this->jsonResult([], 1, '操作成功');
  49. }
  50. }