c494fa8d23b2033790c920f3395e24a95fe5f636.svn-base 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | project.php 后台管理 项目管理
  5. |--------------------------------------------------------------------------
  6. */
  7. namespace MazeApp\Manage;
  8. use Maze;
  9. use Maze\Config\Project as Config;
  10. use Maze\Http\Input;
  11. //Maze::load('manage/auth.init');
  12. class Project
  13. {
  14. /**
  15. * get
  16. *
  17. * @return string
  18. */
  19. public function get()
  20. {
  21. $list = Config::read();
  22. //unset($list['manage']);
  23. /*
  24. 取消排序,放到数据表中排序
  25. $order = array();
  26. foreach($list as $v)
  27. {
  28. $order[] = $v['order'];
  29. }
  30. array_multisort($order, SORT_DESC, $list);
  31. */
  32. return $list;
  33. }
  34. /**
  35. * 生成key->value的形式
  36. *
  37. * @return string
  38. */
  39. public function key()
  40. {
  41. $list = Config::read();
  42. //unset($list['manage']);
  43. return $list;
  44. }
  45. /**
  46. * set
  47. *
  48. * @return string
  49. */
  50. public function set()
  51. {
  52. $config = $this->get();
  53. $key = Input::get('key');
  54. $index = Input::get('index', 'lang');
  55. $value = Input::get('value');
  56. Config::update($key, $index, $value);
  57. }
  58. /**
  59. * name
  60. *
  61. * @return string
  62. */
  63. public function name($key)
  64. {
  65. $project = Config::load($key);
  66. if($project)
  67. {
  68. return $project['lang'];
  69. }
  70. else
  71. {
  72. return $key;
  73. }
  74. }
  75. /**
  76. * config
  77. *
  78. * @return string
  79. */
  80. public function config($key)
  81. {
  82. $project = Config::load($key);
  83. if($project)
  84. {
  85. return $project;
  86. }
  87. else
  88. {
  89. return $key;
  90. }
  91. }
  92. /**
  93. * path
  94. *
  95. * @return string
  96. */
  97. public function path($key)
  98. {
  99. $project = Config::load($key);
  100. if($project)
  101. {
  102. return $project['path'];
  103. }
  104. else
  105. {
  106. return $key;
  107. }
  108. }
  109. public function loop()
  110. {
  111. while(true)
  112. {
  113. $this->cron();
  114. sleep(10);
  115. }
  116. }
  117. /**
  118. * cron
  119. *
  120. * @return string
  121. */
  122. public function cron()
  123. {
  124. $time = time();
  125. # 获取所有的计划任务
  126. $data = Maze::load('manage/cron-get', array('where_ldate' => $time));
  127. if($data)
  128. {
  129. # 比如属于weixin项目的group_list
  130. # weixin.mazephp.com/data.group_list
  131. foreach($data as $k => $v)
  132. {
  133. Maze::daemon($v['interface'], $v['project']);
  134. $param['where_id'] = $v['id'];
  135. $param['set_ldate'] = $time + $v['time'];
  136. if($v['time'] <= 0)
  137. {
  138. $param['set_state'] = 2;
  139. }
  140. Maze::load('manage/cron-update',$param);
  141. }
  142. }
  143. }
  144. }