Times.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace Collection\Lib;
  3. use Dever;
  4. class Times
  5. {
  6. private $times = false;
  7. /**
  8. * 获取所有数据
  9. *
  10. * @return mixed
  11. */
  12. public function all()
  13. {
  14. $info_id = Dever::input('search_option_info_id');
  15. $data = Dever::db('collection/times')->mainAll(array('info_id' => $info_id));
  16. if ($data) {
  17. $child = Dever::db('collection/times')->childAll(array('info_id' => $info_id));
  18. foreach ($data as $k => $v) {
  19. if (isset($child[$k])) {
  20. $data[$k]['child'] = $child[$k];
  21. }
  22. }
  23. }
  24. return $data;
  25. }
  26. public function getName($id, $parent_id)
  27. {
  28. $parent = Dever::db('collection/times')->one($parent_id);
  29. $info = Dever::db('collection/times')->one($id);
  30. return $parent['name'] . '·' . $info['name'];
  31. }
  32. # 获取当前时间
  33. public function getDate($day, $cdate, $times = false, $array = false)
  34. {
  35. if (!$this->times && $times && $times > 0) {
  36. $this->times = Dever::db('collection/times')->one($times);
  37. }
  38. if ($day > 0) {
  39. if ($this->times && $this->times['year']) {
  40. $year = $this->times['year'];
  41. } else {
  42. $year = substr($day,0,4);
  43. }
  44. $month = substr($day,4,2);
  45. $day = substr($day,6,2);
  46. $string = $year . '-' . $month . '-' . $day;
  47. } elseif ($this->times && $this->times['year']) {
  48. $string = $this->times['year'] . '-m-d';
  49. } else {
  50. $string = 'Y-m-d';
  51. }
  52. $cdate = date($string . ' H:i', $cdate);
  53. if ($array) {
  54. $temp = explode(' ', $cdate);
  55. $cdate = array
  56. (
  57. $temp[0],
  58. $temp[1]
  59. );
  60. }
  61. return $cdate;
  62. }
  63. }