Message.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * Message.php UTF-8
  4. * 消息类
  5. *
  6. * @date : 2017/11/24 18:20
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\controller\message;
  13. use huo\controller\common\Base;
  14. use huo\logic\message\MessageLogic;
  15. class Message extends Base {
  16. protected $msg_logic;
  17. public function __construct(MessageLogic $msg_logic = null) {
  18. if (null === $msg_logic) {
  19. $this->msg_logic = new MessageLogic();
  20. } else {
  21. $this->msg_logic = $msg_logic;
  22. }
  23. }
  24. /**
  25. * 获取消息数量
  26. *
  27. * @param $param
  28. * @param int $mem_id
  29. *
  30. * @return int
  31. */
  32. public function getCnt($param, $mem_id = 0) {
  33. if (empty($mem_id)) {
  34. return 0;
  35. }
  36. // TODO: wuyonghong 2018/4/24 添加消息数量函数
  37. return rand(0, 2);
  38. }
  39. /**
  40. * 获取文章列表
  41. *
  42. * @param array $param
  43. * @param string $page
  44. *
  45. * @param int $mem_id
  46. *
  47. * @internal param $where
  48. * @return array
  49. */
  50. public function getList($param = [], $page, $mem_id = 0) {
  51. $_map['gameid'] = $this->getVal($param, 'gameid', 0);
  52. $_map['type'] = $this->getVal($param, 'type', 0);
  53. $_map['mem_id'] = $mem_id;
  54. $_data = [
  55. 'count' => 0,
  56. 'list' => []
  57. ];
  58. $_cnt = $this->msg_logic->getCnt($_map);
  59. if (empty($_cnt)) {
  60. return $this->huoSuccess(200, '', $_data);
  61. }
  62. $_data['count'] = $_cnt;
  63. $_order = '-create_time';
  64. $_data['list'] = $this->msg_logic->getList($_map, $page, $_order);
  65. return $this->huoSuccess(200, '', $_data);
  66. }
  67. /**
  68. * 获取消息详情
  69. *
  70. * @param int $msg_id
  71. * @param int $mem_id
  72. *
  73. * @return array
  74. */
  75. public function getDetail($msg_id = 0, $mem_id = 0) {
  76. if (empty($msg_id)) {
  77. return $this->huoError(400);
  78. }
  79. $_data = $this->msg_logic->getDetail($msg_id, $mem_id);
  80. if (false === $_data) {
  81. return $this->huoError(1000);
  82. }
  83. if (is_numeric($_data)) {
  84. return $this->huoError($_data);
  85. }
  86. return $this->huoSuccess(200, '', $_data);
  87. }
  88. /**
  89. * 添加消息
  90. *
  91. * @param $_param
  92. * @param $mem_id
  93. *
  94. * @return array
  95. */
  96. public function addMessage($_param, $mem_id) {
  97. $title = $this->getVal($_param, 'title', '');
  98. $content = $this->getVal($_param, 'content', '');
  99. $type = $this->getVal($_param, 'type', 2);
  100. $app_id = $this->getVal($_param, 'app_id', 0);
  101. $_rs = $this->msg_logic->addMessage($mem_id, $title, $content, $type, $app_id);
  102. if ($_rs) {
  103. return $this->huoSuccess(200);
  104. } else {
  105. return $this->huoError(1000);
  106. }
  107. }
  108. }