job.mod.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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('core_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('core_job')->getById($id);
  16. }
  17. function job_create_delete_account($uniacid, $accountName, $uid) {
  18. $core_count = table('core_attachment')->where('uniacid', $uniacid)->count();
  19. $wechat_count = table('wechat_attachment')->where('uniacid', $uniacid)->count();
  20. $total = $core_count + intval($wechat_count);
  21. return table('core_job')->createDeleteAccountJob($uniacid, $accountName, $total, $uid);
  22. }
  23. function job_execute($id) {
  24. $job = job_single($id);
  25. $type = $job['type'];
  26. if (intval($job['status']) == 1) {
  27. return error(1, '任务已结束');
  28. }
  29. $result = null;
  30. switch ($type) {
  31. case $type : $result = job_execute_delete_account($job); break;
  32. }
  33. return $result;
  34. }
  35. function job_execute_delete_account($job) {
  36. $uniacid = $job['uniacid'];
  37. $core_attchments = table('core_attachment')
  38. ->where('uniacid', $uniacid)
  39. ->searchWithPage(1, 10)
  40. ->getall('id');
  41. $wechat_attachments = table('wechat_attachment')
  42. ->where('uniacid', $uniacid)
  43. ->searchWithPage(1, 10)
  44. ->getall('id');
  45. if (count($core_attchments) == 0 && count($wechat_attachments) == 0) {
  46. table('core_attachment_group')->where('uniacid', $uniacid)->delete();
  47. table('core_job')
  48. ->where('id', $job['id'])
  49. ->fill('status', 1)
  50. ->fill('endtime', TIMESTAMP)
  51. ->save();
  52. return error(0, array('finished' => 1, 'progress' => 100, 'id' => $job['id'], 'endtime' => TIMESTAMP));
  53. }
  54. array_walk($core_attchments, function($item) {
  55. $path = $item['attachment'];
  56. file_delete($path);
  57. });
  58. array_walk($wechat_attachments, function($item) {
  59. $path = $item['attachment'];
  60. file_delete($path);
  61. });
  62. $core_ids = array_keys($core_attchments);
  63. $wechat_ids = array_keys($wechat_attachments);
  64. if (count($core_ids) > 0) {
  65. table('core_attachment')->deleteById($core_ids);
  66. }
  67. if (count($wechat_ids) > 0) {
  68. table('wechat_attachment')->deleteById($wechat_ids);
  69. }
  70. $handled = count($core_ids) + count($wechat_ids);
  71. table('core_job')
  72. ->where('id', $job['id'])
  73. ->fill('handled', $handled)
  74. ->fill('status', 1)
  75. ->fill('endtime', TIMESTAMP)
  76. ->fill('updatetime',TIMESTAMP)
  77. ->save();
  78. return error(0, array('finished' => 1, 'progress' => 100, 'id'=>$job['id'], 'endtime' => TIMESTAMP));
  79. }
  80. function job_clear($uid, $isfounder = false) {
  81. return table('core_job')->clear($uid, $isfounder);
  82. }