Task.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php namespace Pan\Api;
  2. use Dever;
  3. use Dever\Helper\Cmd;
  4. class Task
  5. {
  6. private $type = array
  7. (
  8. 1 => 'quark',
  9. );
  10. # 执行任务
  11. public function run()
  12. {
  13. $id = Dever::input('id');
  14. $task = Dever::db('task', 'pan')->find(array('id' => $id, 'status' => array('in', '1,3')));
  15. if ($task) {
  16. $partition = Dever::call("manage/common.system", array(false, false));
  17. $partition['id'] = $id;
  18. Cmd::run('task.runAct', $partition, 'pan');
  19. }
  20. return '操作成功,后台程序运行中,请点击右上角刷新页面';
  21. }
  22. public function runAct()
  23. {
  24. $id = Dever::input('id');
  25. $partition = Dever::input();
  26. $id = $partition['id'];
  27. unset($partition['id']);
  28. $task_db = Dever::db('task', 'pan', 'default', $partition);
  29. $task = $task_db->find(array('id' => $id));
  30. $task_db->update(array('id' => $id), array('status' => 2));
  31. $account = Dever::db('account', 'pan', 'default', $partition)->find($task['account_id']);
  32. $class = $this->type[$account['type']];
  33. Dever::load($class, 'pan')->run($account, $task, $partition);
  34. $task_db->update(array('id' => $id), array('status' => 3));
  35. }
  36. # 导入分享
  37. public function import()
  38. {
  39. $id = Dever::input('set')['account_task_id'] ?? false;
  40. if ($id) {
  41. $task = Dever::db('task', 'pan')->find(array('id' => $id));
  42. if ($task) {
  43. $partition = Dever::call("manage/common.system", array(false, false));
  44. $partition['id'] = $id;
  45. Cmd::run('task.importAct', $partition, 'pan');
  46. }
  47. }
  48. return '操作成功,后台程序运行中,请点击右上角刷新页面';
  49. }
  50. public function importAct()
  51. {
  52. $id = Dever::input('id');
  53. $partition = Dever::input();
  54. $id = $partition['id'];
  55. unset($partition['id']);
  56. $task = Dever::db('task', 'pan', 'default', $partition)->find(array('id' => $id));
  57. $account = Dever::db('account', 'pan', 'default', $partition)->find($task['account_id']);
  58. $class = $this->type[$account['type']];
  59. Dever::load($class, 'pan')->import($account, $task, $partition);
  60. }
  61. # 取消分享
  62. public function delete()
  63. {
  64. $id = Dever::input('id');
  65. $data = Dever::db('task_data', 'pan')->select(array('id' => array('in', $id)));
  66. if ($data) {
  67. $share_id = array();
  68. $account = array();
  69. foreach ($data as $k => $v) {
  70. if (!$account) {
  71. $account = Dever::db('account', 'pan')->find($v['account_id']);
  72. }
  73. $share_id[] = $v['share_id'];
  74. }
  75. $class = $this->type[$account['type']];
  76. $state = Dever::load($class, 'pan')->delete($share_id, $account['cookie']);
  77. if ($state) {
  78. Dever::db('task_data', 'pan')->delete(array('id' => array('in', $id)));
  79. }
  80. }
  81. return '取消分享成功';
  82. }
  83. }