job.mod.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. function job_list($uid, $isfounder = false) {
  8. $table = table('job')->where('isdeleted',0);
  9. if (!$isfounder) {
  10. $table->where('uid', $uid);
  11. }
  12. return $table->getall('id');
  13. }
  14. function job_single($id) {
  15. return table('job')->getById($id);
  16. }
  17. function job_create_delete_account($uniacid, $accountName, $uid) {
  18. global $_W;
  19. $job = table('job');
  20. $core_count = table('core_attachment')->where('uniacid', $uniacid)->count();
  21. $wechat_count = table('wechat_attachment')->where('uniacid', $uniacid)->count();
  22. $total = $core_count + intval($wechat_count);
  23. return $job->createDeleteAccountJob($uniacid, $accountName, $total, $uid);
  24. }
  25. function job_execute($id) {
  26. $job = job_single($id);
  27. $type = $job['type'];
  28. if (intval($job['status']) == 1) {
  29. return error(1, '任务已结束');
  30. }
  31. $result = null;
  32. switch ($type) {
  33. case $type : $result = job_execute_delete_account($job); break;
  34. }
  35. return $result;
  36. }
  37. function job_execute_delete_account($job) {
  38. $uniacid = $job['uniacid'];
  39. $core_attchments = table('core_attachment')->where('uniacid', $uniacid)
  40. ->searchWithPage(1, 10)->getall('id');
  41. array_walk($core_attchments, function($item) {
  42. $path = $item['attachment'];
  43. file_delete($path);
  44. });
  45. $wechat_attachments = table('wechat_attachment')->where('uniacid', $uniacid)
  46. ->searchWithPage(1, 10)->getall('id');
  47. array_walk($wechat_attachments, function($item) {
  48. $path = $item['attachment'];
  49. file_delete($path);
  50. });
  51. if (count($core_attchments) == 0 && count($wechat_attachments) == 0) {
  52. table('core_attachment_group')->where('uniacid', $uniacid)->delete();
  53. $upjob = table('job')->where('id', $job['id']);
  54. $upjob->fill('status', 1); $upjob->fill('endtime', TIMESTAMP); $upjob->save();
  55. return error(0, array('finished'=>1, 'progress'=>100, 'id'=>$job['id'], 'endtime'=>time()));
  56. }
  57. $core_ids = array_keys($core_attchments);
  58. $wechat_ids = array_keys($wechat_attachments);
  59. if (count($core_ids) > 0) {
  60. table('core_attachment')->deleteById($core_ids);
  61. }
  62. if (count($wechat_ids) > 0) {
  63. table('wechat_attachment')->deleteById($wechat_ids);
  64. }
  65. $handled = count($core_ids) + count($wechat_ids);
  66. $all_handled = intval($job['handled']) + $handled;
  67. $total = intval($job['total']);
  68. table('job')->where('id', $job['id'])->fill('handled', $all_handled)
  69. ->fill('updatetime',TIMESTAMP)->save();
  70. return error(0, array('finished'=>0, 'progress'=>intval($all_handled/$total*100), 'id'=>$job['id']));
  71. }
  72. function job_clear($uid, $isfounder = false) {
  73. return table('job')->clear($uid, $isfounder);
  74. }