Moment.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace app\controller\admin\v1\work;
  3. use app\controller\admin\AuthController;
  4. use app\services\work\WorkMomentSendResultServices;
  5. use app\services\work\WorkMomentServices;
  6. use think\facade\App;
  7. /**
  8. * 朋友圈
  9. * Class Moment
  10. * @package app\controller\admin\v1\work
  11. */
  12. class Moment extends AuthController
  13. {
  14. /**
  15. * Moment constructor.
  16. * @param App $app
  17. * @param WorkMomentServices $services
  18. */
  19. public function __construct(App $app, WorkMomentServices $services)
  20. {
  21. parent::__construct($app);
  22. $this->services = $services;
  23. }
  24. /**
  25. * 查看列表
  26. * @return mixed
  27. */
  28. public function index()
  29. {
  30. $where = $this->request->getMore([
  31. ['time', ''],
  32. ['name', '', '', 'name_like'],
  33. ]);
  34. return $this->success($this->services->getList($where));
  35. }
  36. /**
  37. * 保存
  38. * @return mixed
  39. */
  40. public function save()
  41. {
  42. $data = $this->request->postMore([
  43. ['name', ''],
  44. ['type', 0],
  45. ['user_ids', []],
  46. ['client_type', 0],
  47. ['client_tag_list', []],
  48. ['welcome_words', []],
  49. ['send_type', 0],
  50. ['send_time', 0],
  51. ]);
  52. if ($data['type'] && !$data['user_ids']) {
  53. return $this->fail('请选择成员');
  54. }
  55. if ($data['client_type'] && !$data['client_tag_list']) {
  56. return $this->fail('请选择客户标签');
  57. }
  58. if ($data['send_type']) {
  59. if (!$data['send_time']) {
  60. return $this->fail('请选择定时发送时间');
  61. }
  62. $data['send_time'] = strtotime($data['send_time']);
  63. }
  64. $this->services->createMomentTask($data);
  65. return $this->success('添加成功');
  66. }
  67. /**
  68. * 查看任务发送详情
  69. * @param $id
  70. * @return mixed
  71. */
  72. public function read($id)
  73. {
  74. if (!$id) {
  75. return $this->fail('缺少参数');
  76. }
  77. return $this->success($this->services->getMomentInfo((int)$id));
  78. }
  79. /**
  80. * 删除朋友圈
  81. * @param $id
  82. * @return mixed
  83. * @throws \think\db\exception\DataNotFoundException
  84. * @throws \think\db\exception\DbException
  85. * @throws \think\db\exception\ModelNotFoundException
  86. */
  87. public function delete($id)
  88. {
  89. if (!$id) {
  90. return $this->fail('缺少参数');
  91. }
  92. if ($this->services->deleteMoment($id)) {
  93. return $this->success('删除成功');
  94. } else {
  95. return $this->fail('删除失败');
  96. }
  97. }
  98. /**
  99. * 朋友圈发送列表
  100. * @param WorkMomentSendResultServices $services
  101. * @return mixed
  102. */
  103. public function sendResultList(WorkMomentSendResultServices $services)
  104. {
  105. $where = $this->request->getMore([
  106. ['status', ''],
  107. ['userid', []],
  108. ['moment_id', '']
  109. ]);
  110. $where['userid'] = array_filter($where['userid']);
  111. if (!$where['moment_id']) {
  112. return $this->success(['list' => [], 'count' => 0]);
  113. }
  114. return $this->success($services->getList($where));
  115. }
  116. }