Welcome.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\v1\work;
  12. use app\controller\admin\AuthController;
  13. use app\services\work\WorkWelcomeServices;
  14. use think\db\exception\DataNotFoundException;
  15. use think\db\exception\DbException;
  16. use think\db\exception\ModelNotFoundException;
  17. use think\facade\App;
  18. /**
  19. * 企业微信欢迎语
  20. * Class Welcome
  21. * @package app\controller\admin\v1\work
  22. */
  23. class Welcome extends AuthController
  24. {
  25. /**
  26. * Welcome constructor.
  27. * @param App $app
  28. * @param WorkWelcomeServices $services
  29. */
  30. public function __construct(App $app, WorkWelcomeServices $services)
  31. {
  32. parent::__construct($app);
  33. $this->services = $services;
  34. }
  35. /**
  36. * @return mixed
  37. * @throws DataNotFoundException
  38. * @throws DbException
  39. * @throws ModelNotFoundException
  40. */
  41. public function index()
  42. {
  43. $where = $this->request->getMore([
  44. ['add_time', ''],
  45. ['userids', []]
  46. ]);
  47. return $this->success($this->services->getList($where));
  48. }
  49. /**
  50. * 欢迎语
  51. * @param $id
  52. * @return mixed
  53. */
  54. public function read($id)
  55. {
  56. if (!$id) {
  57. return $this->fail('缺少参数');
  58. }
  59. return $this->success($this->services->getWelcomeInfo((int)$id));
  60. }
  61. /**
  62. * 保存
  63. * @return mixed
  64. */
  65. public function save()
  66. {
  67. $data = $this->request->postMore([
  68. ['type', 0],
  69. ['content', ''],
  70. ['attachments', []],
  71. ['userids', []],
  72. ['sort', 0]
  73. ]);
  74. if (!$data['attachments'] && !$data['content']) {
  75. return $this->fail('欢迎语内容和欢迎语消息体不能同时为空');
  76. }
  77. if (!$data['content']) {
  78. return $this->fail('缺少消息内容');
  79. }
  80. if ($data['type'] == 1 && !$data['userids']) {
  81. return $this->fail('至少选择一个成员');
  82. }
  83. if ($this->services->saveWelcome($data)) {
  84. return $this->success('添加成功');
  85. } else {
  86. return $this->fail('添加失败');
  87. }
  88. }
  89. /**
  90. * 修改
  91. * @param $id
  92. * @return mixed
  93. */
  94. public function update($id)
  95. {
  96. $data = $this->request->postMore([
  97. ['type', 0],
  98. ['content', ''],
  99. ['attachments', []],
  100. ['userids', []],
  101. ['sort', 0]
  102. ]);
  103. if (!$data['attachments'] && !$data['content']) {
  104. return $this->fail('欢迎语内容和欢迎语消息体不能同时为空');
  105. }
  106. if (!$data['content']) {
  107. return $this->fail('缺少消息内容');
  108. }
  109. if ($data['type'] == 1 && !$data['userids']) {
  110. return $this->fail('至少选择一个成员');
  111. }
  112. if ($this->services->saveWelcome($data, (int)$id)) {
  113. return $this->success('修改成功');
  114. } else {
  115. return $this->fail('修改失败');
  116. }
  117. }
  118. /**
  119. * 删除
  120. * @param $id
  121. * @return mixed
  122. */
  123. public function delete($id)
  124. {
  125. if (!$id) {
  126. return $this->fail('缺少参数');
  127. }
  128. if ($this->services->deleteWelcome($id)) {
  129. return $this->success('删除成功');
  130. } else {
  131. return $this->fail('删除失败');
  132. }
  133. }
  134. }