Message.Class.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. * 消息Controller
  4. * Created by PhpStorm.
  5. * User: 小威
  6. * Date: 2020/03/31
  7. * Time: 16:00
  8. */
  9. namespace JinDouYun\Controller\Message;
  10. use Exception;
  11. use Mall\Framework\Core\ErrorCode;
  12. use Mall\Framework\Core\StatusCode;
  13. use JinDouYun\Controller\BaseController;
  14. use JinDouYun\Model\Message\MMessage;
  15. class Message extends BaseController
  16. {
  17. private $objMMessage;
  18. public function __construct($isCheckAcl = true, $isMustLogin = true)
  19. {
  20. parent::__construct($isCheckAcl, $isMustLogin);
  21. $this->objMMessage = new MMessage($this->onlineEnterpriseId, $this->onlineUserId);
  22. }
  23. /**
  24. * 消息添加
  25. * @throws Exception
  26. */
  27. public function addMessage()
  28. {
  29. $params = $this->request->getRawJson();
  30. if (empty($params)) {
  31. parent::sendOutput('参数为空', ErrorCode::$paramError);
  32. }
  33. $data = [
  34. 'receiveId' => isset($params['receiveId']) ? $params['receiveId'] : '',
  35. 'title' => isset($params['title']) ? $params['title'] : '',
  36. 'content' => isset($params['content']) ? $params['content'] : '',
  37. ];
  38. foreach($data as $key => $value){
  39. if(empty($value)){
  40. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  41. }
  42. }
  43. $result = $this->objMMessage->addMessage($data);
  44. if ($result->isSuccess()) {
  45. parent::sendOutput($result->getData());
  46. } else {
  47. parent::sendOutput($result->getData(), $result->getErrorCode());
  48. }
  49. }
  50. /**
  51. * 消息删除
  52. */
  53. public function delMessage()
  54. {
  55. $params['id'] = $this->request->param('request_id');
  56. if (empty($params)) {
  57. $this->sendOutput('参数为空', ErrorCode::$paramError);
  58. }
  59. $result = $this->objMMessage->delMessage($params);
  60. if ($result->isSuccess()) {
  61. parent::sendOutput($result->getData());
  62. } else {
  63. parent::sendOutput($result->getData(), $result->getErrorCode());
  64. }
  65. }
  66. /**
  67. * 消息列表
  68. */
  69. public function getAllMessage()
  70. {
  71. $params = $this->request->getRawJson();
  72. if (empty($params)) {
  73. parent::sendOutput('参数为空', ErrorCode::$paramError);
  74. }
  75. $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10);
  76. $selectParams['limit'] = $pageParams['limit'];
  77. $selectParams['offset'] = $pageParams['offset'];
  78. isset($params['receiveStatus']) && $selectParams['receiveStatus'] = $params['receiveStatus'];
  79. $result = $this->objMMessage->getAllMessage($selectParams);
  80. if ($result->isSuccess()) {
  81. $returnData = $result->getData();
  82. $pageData = [
  83. 'pageIndex' => $params['page'],
  84. 'pageSize' => $params['pageSize'],
  85. 'pageTotal' => $returnData['total'],
  86. ];
  87. parent::sendOutput($returnData['data'], 0, $pageData);
  88. } else {
  89. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  90. }
  91. }
  92. /**
  93. * 消息详情
  94. */
  95. public function getMessageInfo()
  96. {
  97. $params['id'] = $this->request->param('request_id');
  98. if (empty($params['id'])) {
  99. $this->sendOutput('参数为空', ErrorCode::$paramError);
  100. }
  101. $result = $this->objMMessage->getMessageInfo($params);
  102. if ($result->isSuccess()) {
  103. parent::sendOutput($result->getData());
  104. } else {
  105. parent::sendOutput($result->getData(), $result->getErrorCode());
  106. }
  107. }
  108. /**
  109. * 消息已读
  110. */
  111. public function receiveMessage()
  112. {
  113. $params['id'] = $this->request->param('request_id');
  114. if(!$params['id']){
  115. $data = $this->request->getRawJson();
  116. $params['id'] = isset($data['id']) ? $data['id'] : '';
  117. }
  118. if (empty($params['id'])) {
  119. $this->sendOutput('参数为空', ErrorCode::$paramError);
  120. }
  121. $result = $this->objMMessage->receiveMessage($params);
  122. if ($result->isSuccess()) {
  123. parent::sendOutput($result->getData());
  124. } else {
  125. parent::sendOutput($result->getData(), $result->getErrorCode());
  126. }
  127. }
  128. }