12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace Collection\Lib;
- use Dever;
- class Times
- {
- private $times = false;
- /**
- * 获取所有数据
- *
- * @return mixed
- */
- public function all()
- {
- $info_id = Dever::input('search_option_info_id');
- $data = Dever::db('collection/times')->mainAll(array('info_id' => $info_id));
- if ($data) {
- $child = Dever::db('collection/times')->childAll(array('info_id' => $info_id));
- foreach ($data as $k => $v) {
- if (isset($child[$k])) {
- $data[$k]['child'] = $child[$k];
- }
- }
- }
- return $data;
- }
- public function getName($id, $parent_id)
- {
- $parent = Dever::db('collection/times')->one($parent_id);
- $info = Dever::db('collection/times')->one($id);
- return $parent['name'] . '·' . $info['name'];
- }
- # 获取当前时间
- public function getDate($day, $cdate, $times = false, $array = false)
- {
- if (!$this->times && $times && $times > 0) {
- $this->times = Dever::db('collection/times')->one($times);
- }
- if ($day > 0) {
- if ($this->times && $this->times['year']) {
- $year = $this->times['year'];
- } else {
- $year = substr($day,0,4);
- }
-
- $month = substr($day,4,2);
- $day = substr($day,6,2);
- $string = $year . '-' . $month . '-' . $day;
- } elseif ($this->times && $this->times['year']) {
- $string = $this->times['year'] . '-m-d';
- } else {
- $string = 'Y-m-d';
- }
- $cdate = date($string . ' H:i', $cdate);
- if ($array) {
- $temp = explode(' ', $cdate);
- $cdate = array
- (
- $temp[0],
- $temp[1]
- );
- }
- return $cdate;
- }
- }
|