Project.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace Spider\Lib;
  3. use Dever;
  4. class Project
  5. {
  6. private $config;
  7. public function status($id)
  8. {
  9. $data = $this->get($id);
  10. if (!$data) {
  11. return '';
  12. }
  13. $num = Dever::db('spider/data')->total(array('pid' => $id));
  14. $status = Dever::db('spider/project')->config['status'];
  15. $table['采集状态'] = $status[$data['status']];
  16. $table['采集次数'] = $data['num'];
  17. $table['采集间隔'] = $data['interval'] . '秒';
  18. $table['采集页数'] = $data['cur_page'];
  19. $table['采集数据'] = $num . '条';
  20. $table['采集时间'] = $data['sdate'] > 0 ? date('Y-m-d H:i:s', $data['sdate']) : '无';
  21. return Dever::table($table);
  22. }
  23. public function get($id)
  24. {
  25. if (!$id) {
  26. return false;
  27. }
  28. $config = Dever::db('spider/project')->one($id);
  29. if ($config) {
  30. if ($config['project_id'] == -1) {
  31. return false;
  32. }
  33. return $config;
  34. } else {
  35. return false;
  36. }
  37. }
  38. public function set($config, $status, $page = false)
  39. {
  40. $test = Dever::input('test');
  41. if ($test == 1) {
  42. return false;
  43. }
  44. $data['status'] = $status;
  45. if ($page) {
  46. $data['cur_page'] = $page;
  47. }
  48. $data['where_id'] = $config['id'];
  49. if ($status == 3) {
  50. $data['num'] = $config['num'] + 1;
  51. }
  52. if ($status == 2 && $config['interval'] > 0) {
  53. # 已结束,设置下次的时间
  54. $data['sdate'] = time() + $config['interval'];
  55. }
  56. return Dever::db('spider/project')->update($data);
  57. }
  58. # 获取可以运行的项目
  59. public function getAll()
  60. {
  61. $where['interval'] = 1;
  62. $where['sdate'] = time();
  63. $data = Dever::db('spider/project')->getAll($where);
  64. return $data;
  65. }
  66. }