MessageSystemController.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\api\controller\v1\user;
  12. use app\Request;
  13. use app\services\message\MessageSystemServices;
  14. /**
  15. * 用户地址类
  16. * Class UserController
  17. * @package app\api\controller\store
  18. */
  19. class MessageSystemController
  20. {
  21. protected $services = NUll;
  22. /**
  23. * MessageSystemController constructor.
  24. * @param MessageSystemServices $services
  25. */
  26. public function __construct(MessageSystemServices $services)
  27. {
  28. $this->services = $services;
  29. }
  30. /**
  31. * 站内信消息列表
  32. * @param Request $request
  33. * @return mixed
  34. * @throws \think\db\exception\DataNotFoundException
  35. * @throws \think\db\exception\DbException
  36. * @throws \think\db\exception\ModelNotFoundException
  37. */
  38. public function message_list(Request $request)
  39. {
  40. $uid = (int)$request->uid();
  41. return app('json')->success($this->services->getMessageSystemList($uid));
  42. }
  43. /**
  44. * 站内信消息详情
  45. * @param Request $request
  46. * @param $id
  47. * @return mixed
  48. * @throws \think\db\exception\DataNotFoundException
  49. * @throws \think\db\exception\DbException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. */
  52. public function detail(Request $request, $id)
  53. {
  54. if (!$id) {
  55. app('json')->fail(100100);
  56. }
  57. $uid = (int)$request->uid();
  58. $where['uid'] = $uid;
  59. $where['id'] = $id;
  60. return app('json')->success($this->services->getInfo($where));
  61. }
  62. /**
  63. * 消息列表字段编辑/修改
  64. * @param Request $request
  65. * @return mixed
  66. */
  67. public function edit_message(Request $request)
  68. {
  69. $data = $request->getMore([
  70. ['id', 0],
  71. ['key', ''],
  72. ['value', ''],
  73. ['all', 0]
  74. ]);
  75. $all = (int)$data['all'];
  76. if ($all === 1) {
  77. $this->services->update(['uid' => $request->uid()], [$data['key'] => $data['value']]);
  78. } else {
  79. $this->services->update($data['id'], [$data['key'] => $data['value']]);
  80. }
  81. return app('json')->success(100014);
  82. }
  83. }