Queue.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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\supplier\queue;
  12. use app\controller\supplier\AuthController;
  13. use app\services\other\queue\QueueAuxiliaryServices;
  14. use app\services\other\queue\QueueServices;
  15. use think\facade\App;
  16. /**
  17. * Class Queue
  18. * @package app\controller\supplier
  19. */
  20. class Queue extends AuthController
  21. {
  22. /**
  23. * Queue constructor.
  24. * @param App $app
  25. * @param QueueServices $queueServices
  26. */
  27. public function __construct(App $app, QueueServices $queueServices)
  28. {
  29. parent::__construct($app);
  30. $this->services = $queueServices;
  31. }
  32. /**
  33. * 队列任务列表
  34. * @return mixed
  35. */
  36. public function index()
  37. {
  38. $where = $this->request->getMore([
  39. ['data', '', '', 'time'],
  40. ['type', []],
  41. ['status', [0, 1, 2, 3]],
  42. ['page', 1],
  43. ['limit', 20],
  44. ]);
  45. $data = $this->services->getList($where);
  46. return $this->success($data);
  47. }
  48. /**
  49. * 批量发货记录
  50. * @param $id
  51. * @return mixed
  52. * @throws \think\db\exception\DataNotFoundException
  53. * @throws \think\db\exception\DbException
  54. * @throws \think\db\exception\ModelNotFoundException
  55. */
  56. public function delivery_log($id, $type)
  57. {
  58. /** @var QueueAuxiliaryServices $auxiliaryService */
  59. $auxiliaryService = app()->make(QueueAuxiliaryServices::class);
  60. $data = $auxiliaryService->deliveryLogList(['binding_id' => $id, 'type' => $type]);
  61. return $this->success($data);
  62. }
  63. /**
  64. * 再次执行批量任务
  65. * @param $id
  66. * @param $type
  67. * @return mixed
  68. * @throws \think\db\exception\DataNotFoundException
  69. * @throws \think\db\exception\DbException
  70. * @throws \think\db\exception\ModelNotFoundException
  71. */
  72. public function again_do_queue($id, $type)
  73. {
  74. if (!$id || !$type) return $this->fail("参数缺失");
  75. $this->services->againDoQueue($id, $type);
  76. return $this->success("后台程序已再次执行此批量任务");
  77. }
  78. /**
  79. * 清除异常任务
  80. * @param $id
  81. * @param $type
  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 del_wrong_queue($id, $type)
  88. {
  89. if (!$id || !$type) return $this->fail("参数缺失");
  90. $res = $this->services->delWrongQueue($id, $type);
  91. return $this->success($res ? "异常任务清除成功" : "数据无异常");
  92. }
  93. /**
  94. * 任务停止
  95. * @param $id
  96. * @return mixed
  97. * @throws \think\db\exception\DataNotFoundException
  98. * @throws \think\db\exception\DbException
  99. * @throws \think\db\exception\ModelNotFoundException
  100. */
  101. public function stop_wrong_queue($id)
  102. {
  103. if (!$id) return $this->fail("参数缺失");
  104. $queueInfo = $this->services->getQueueOne(['id' => $id]);
  105. if (!$queueInfo) $this->fail('任务不存在');
  106. $this->services->delWrongQueue($id, $queueInfo['type'], false);
  107. return $this->success("任务停止成功");
  108. }
  109. }