SystemTimer.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. 'integral_send' => '参考分释放'
  61. ];
  62. return $this->success($data);
  63. }
  64. /**
  65. * 显示列表
  66. * @return mixed
  67. */
  68. public function index()
  69. {
  70. $where['is_del'] = 0;
  71. $data = $this->services->getTimerList($where);
  72. $cacheCount = $this->services->cacheCount();
  73. if ($data['count'] != $cacheCount) {
  74. $this->services->setAllTimerCache();
  75. }
  76. return $this->success($data);
  77. }
  78. /**
  79. * 删除指定资源
  80. * @param string $id
  81. * @return \think\Response
  82. */
  83. public function delete($id)
  84. {
  85. $this->services->del($id);
  86. $this->services->delOneTimerCache($id);
  87. return $this->success('删除成功');
  88. }
  89. /**
  90. * 修改状态
  91. * @param string $is_show
  92. * @param string $id
  93. */
  94. public function set_show($id = '', $is_show = '')
  95. {
  96. if ($is_show == '' || $id == '') return $this->fail('缺少参数');
  97. $this->services->setShow($id, $is_show);
  98. $this->services->updateOneTimerCache($id);
  99. return $this->success($is_show == 1 ? '显示成功' : '隐藏成功');
  100. }
  101. /**获取单条定时器数据
  102. * @param $id
  103. * @return void
  104. */
  105. public function get_timer_one($id)
  106. {
  107. return $this->success($this->services->getOneTimer($id));
  108. }
  109. /**
  110. * 保存定时任务
  111. * @return mixed
  112. */
  113. public function save()
  114. {
  115. $data = $this->request->postMore([
  116. ['name', ''],
  117. ['mark', ''],
  118. ['type', 0],
  119. ['title', ''],
  120. ['is_open', 0],
  121. ['cycle', '']
  122. ]);
  123. if (!$data['name']) {
  124. return $this->fail('请输入定时任务名称');
  125. }
  126. if (!$data['mark']) {
  127. return $this->fail('请输入定时任务标识');
  128. }
  129. $this->services->createData($data);
  130. $this->services->setAllTimerCache();
  131. return $this->success('添加定时器成功!');
  132. }
  133. /**
  134. * 更新定时任务
  135. * @param $id
  136. * @return mixed
  137. */
  138. public function update($id)
  139. {
  140. $data = $this->request->postMore([
  141. ['name', ''],
  142. ['mark', ''],
  143. ['type', 0],
  144. ['title', ''],
  145. ['is_open', 0],
  146. ['cycle', '']
  147. ]);
  148. if (!$data['name']) {
  149. return $this->fail('请输入定时任务名称');
  150. }
  151. if (!$data['mark']) {
  152. return $this->fail('请输入定时任务标识');
  153. }
  154. $this->services->editData($id, $data);
  155. $this->services->updateOneTimerCache($id);
  156. return $this->success('修改成功!');
  157. }
  158. }