SystemTimer.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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\system;
  12. use think\facade\App;
  13. use app\controller\admin\AuthController;
  14. use app\services\system\timer\SystemTimerServices;
  15. /**
  16. * 定时任务表控制器
  17. * Class SystemTimer
  18. * @package app\controller\admin\v1\system
  19. */
  20. class SystemTimer extends AuthController
  21. {
  22. protected $services;
  23. /**
  24. * 构造方法
  25. * SystemTimer constructor.
  26. * @param App $app
  27. * @param SystemTimerServices $services
  28. */
  29. public function __construct(App $app, SystemTimerServices $services)
  30. {
  31. parent::__construct($app);
  32. $this->services = $services;
  33. }
  34. /**定时任务名称及标识
  35. * @return mixed
  36. */
  37. public function task_name()
  38. {
  39. $data = [
  40. 'auto_cancel' => '自动取消订单',
  41. 'auto_take' => '自动确认收货',
  42. 'auto_comment' => '自动好评',
  43. 'auto_clear_integral' => '自动清空用户积分',
  44. 'auto_off_user_svip' => '自动取消用户到期svip',
  45. 'auto_agent' => '自动解绑上下级',
  46. 'auto_clear_poster' => '自动清除昨日海报',
  47. 'auto_sms_code' => '更新短信状态',
  48. 'auto_live' => '自动更新直播产品状态和直播间状态',
  49. 'auto_pink' => '拼团状态自动更新',
  50. 'auto_show' => '自动上下架商品',
  51. 'auto_channel' => '渠道码定时任务',
  52. 'auto_moment' => '定时创建发送朋友圈任务',
  53. 'auto_group_task' => '定时发送群发任务',
  54. 'auto_seckill' => '定时清理秒杀数据过期的数据缓存',
  55. 'rebate_points_orders' => '未支付积分订单退积分',
  56. 'code_not_operating' => '桌码长期未操作取消桌码记录',
  57. 'collate_not_operating' => '拼单长期未操作取消拼单记录',
  58. 'reminder_unverified_remind' => '次卡商品未核销短信提醒',
  59. 'area_award' => '定时发放分红'
  60. ];
  61. return $this->success($data);
  62. }
  63. /**
  64. * 显示列表
  65. * @return mixed
  66. */
  67. public function index()
  68. {
  69. $where['is_del'] = 0;
  70. $data = $this->services->getTimerList($where);
  71. $cacheCount = $this->services->cacheCount();
  72. if ($data['count'] != $cacheCount) {
  73. $this->services->setAllTimerCache();
  74. }
  75. return $this->success($data);
  76. }
  77. /**
  78. * 删除指定资源
  79. * @param string $id
  80. * @return \think\Response
  81. */
  82. public function delete($id)
  83. {
  84. $this->services->del($id);
  85. $this->services->delOneTimerCache($id);
  86. return $this->success('删除成功');
  87. }
  88. /**
  89. * 修改状态
  90. * @param string $is_show
  91. * @param string $id
  92. */
  93. public function set_show($id = '', $is_show = '')
  94. {
  95. if ($is_show == '' || $id == '') return $this->fail('缺少参数');
  96. $this->services->setShow($id, $is_show);
  97. $this->services->updateOneTimerCache($id);
  98. return $this->success($is_show == 1 ? '显示成功' : '隐藏成功');
  99. }
  100. /**获取单条定时器数据
  101. * @param $id
  102. * @return void
  103. */
  104. public function get_timer_one($id)
  105. {
  106. return $this->success($this->services->getOneTimer($id));
  107. }
  108. /**
  109. * 保存定时任务
  110. * @return mixed
  111. */
  112. public function save()
  113. {
  114. $data = $this->request->postMore([
  115. ['name', ''],
  116. ['mark', ''],
  117. ['type', 0],
  118. ['title', ''],
  119. ['is_open', 0],
  120. ['cycle', '']
  121. ]);
  122. if (!$data['name']) {
  123. return $this->fail('请输入定时任务名称');
  124. }
  125. if (!$data['mark']) {
  126. return $this->fail('请输入定时任务标识');
  127. }
  128. $this->services->createData($data);
  129. $this->services->setAllTimerCache();
  130. return $this->success('添加定时器成功!');
  131. }
  132. /**
  133. * 更新定时任务
  134. * @param $id
  135. * @return mixed
  136. */
  137. public function update($id)
  138. {
  139. $data = $this->request->postMore([
  140. ['name', ''],
  141. ['mark', ''],
  142. ['type', 0],
  143. ['title', ''],
  144. ['is_open', 0],
  145. ['cycle', '']
  146. ]);
  147. if (!$data['name']) {
  148. return $this->fail('请输入定时任务名称');
  149. }
  150. if (!$data['mark']) {
  151. return $this->fail('请输入定时任务标识');
  152. }
  153. $this->services->editData($id, $data);
  154. $this->services->updateOneTimerCache($id);
  155. return $this->success('修改成功!');
  156. }
  157. }