|
@@ -38,6 +38,7 @@ class Spider
|
|
|
$main_name = Dever::input('main_name', '图片收集序列');
|
|
|
$page_name = Dever::input('page_name');
|
|
|
$page_desc = Dever::input('page_desc');
|
|
|
+ $day_name_type = Dever::input('day_name_type', 1);
|
|
|
if (!$id || !$main_name || !$page_name || !$page_desc) {
|
|
|
return;
|
|
|
}
|
|
@@ -49,62 +50,94 @@ class Spider
|
|
|
}
|
|
|
$pic = explode(',', $data['pic']);
|
|
|
$source_id = $data['project_id'];
|
|
|
- $date = explode('-', $data['cdate']);
|
|
|
-
|
|
|
- $year = intval($date[0]);
|
|
|
- $month = intval($date[1]);
|
|
|
- $day = intval($date[2]);
|
|
|
-
|
|
|
- if ($month < 4) {
|
|
|
- $page_name .= '第1季';
|
|
|
- } elseif ($month >= 4 && $month <= 6) {
|
|
|
- $page_name .= '第2季';
|
|
|
- } elseif ($month >= 7 && $month <= 9) {
|
|
|
- $page_name .= '第3季';
|
|
|
- } elseif ($month > 9) {
|
|
|
- $page_name .= '第4季';
|
|
|
+ $date = array();
|
|
|
+ if (isset($data['cdate'])) {
|
|
|
+ $date = explode('-', $data['cdate']);
|
|
|
+ } else {
|
|
|
+ if (isset($data['year']) && $data['year']) {
|
|
|
+ $date[0] = $data['year'];
|
|
|
+ }
|
|
|
+ if (isset($data['month']) && $data['month']) {
|
|
|
+ $date[1] = $data['month'];
|
|
|
+ }
|
|
|
+ if (isset($data['day']) && $data['day']) {
|
|
|
+ $date[2] = $data['day'];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- # 按年生成子时光
|
|
|
- $year_name = $year . '年';
|
|
|
-
|
|
|
- # 按月生成子章节
|
|
|
- $month_name = $month . '月';
|
|
|
-
|
|
|
- # 按天生成内容名称
|
|
|
- $day_name = $data['name'];
|
|
|
- $day_name = '第' . $day . '日';
|
|
|
-
|
|
|
- if ($day <= 10) {
|
|
|
- $month_name .= '上旬';
|
|
|
- } elseif ($day > 10 && $day <= 20) {
|
|
|
- $month_name .= '中旬';
|
|
|
- } elseif ($day > 20) {
|
|
|
- $month_name .= '下旬';
|
|
|
- }
|
|
|
-
|
|
|
- # 按项目生成主时光
|
|
|
- $times_id_parent = $this->createTimes($id, $source_id, $main_name);
|
|
|
- if ($times_id_parent) {
|
|
|
- $times_id = $this->createTimes($id, $source_id, $year_name, $year, $times_id_parent);
|
|
|
- if ($times_id) {
|
|
|
-
|
|
|
- $parent_page_id = $this->createPage($id, $source_id, $page_name, -1, $times_id_parent, $times_id);
|
|
|
-
|
|
|
- if ($parent_page_id) {
|
|
|
- $cover = $pic[0];
|
|
|
- $cover = Dever::load('upload/view')->get($cover, 't', 1);
|
|
|
- $cover = Dever::load('upload/view')->get($cover, 'c', 1);
|
|
|
- $page_id = $this->createPage($id, $source_id, $month_name, $parent_page_id, $times_id_parent, $times_id, $page_desc, $cover);
|
|
|
-
|
|
|
- if ($page_id) {
|
|
|
- $content_id = $this->createContent($id, $source_id, $page_id, 11, $day_name, $cover);
|
|
|
- if ($content_id) {
|
|
|
- $this->createPic($id, $content_id, $pic);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ if (isset($date[0]) && isset($date[1]) && isset($date[2])) {
|
|
|
+ $year = intval($date[0]);
|
|
|
+ if (!$year) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $month = intval($date[1]);
|
|
|
+ if (!$month) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $day = intval($date[2]);
|
|
|
+ if (!$day) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($month < 4) {
|
|
|
+ $page_name .= '第1季';
|
|
|
+ } elseif ($month >= 4 && $month <= 6) {
|
|
|
+ $page_name .= '第2季';
|
|
|
+ } elseif ($month >= 7 && $month <= 9) {
|
|
|
+ $page_name .= '第3季';
|
|
|
+ } elseif ($month > 9) {
|
|
|
+ $page_name .= '第4季';
|
|
|
+ }
|
|
|
+
|
|
|
+ # 按年生成子时光
|
|
|
+ $year_name = $year . '年';
|
|
|
+
|
|
|
+ # 按月生成子章节
|
|
|
+ $month_name = $month . '月';
|
|
|
+
|
|
|
+ # 按天生成内容名称
|
|
|
+ if ($day_name_type == 1) {
|
|
|
+ $day_name = '第' . $day . '天';
|
|
|
+ } else {
|
|
|
+ $day_name = $data['name'];
|
|
|
+ }
|
|
|
+ # 每期最多12个,多了有点卡顿,后续要优化的
|
|
|
+ $max = 12;
|
|
|
+ /*
|
|
|
+ if ($day <= 10) {
|
|
|
+ $month_name .= '上旬';
|
|
|
+ } elseif ($day > 10 && $day <= 20) {
|
|
|
+ $month_name .= '中旬';
|
|
|
+ } elseif ($day > 20) {
|
|
|
+ $month_name .= '下旬';
|
|
|
+ }
|
|
|
+ */
|
|
|
+ $reorder = -1*($month - 12) + 1;
|
|
|
+
|
|
|
+ # 按项目生成主时光
|
|
|
+ $times_id_parent = $this->createTimes($id, $source_id, $main_name);
|
|
|
+ if ($times_id_parent) {
|
|
|
+ $times_id = $this->createTimes($id, $source_id, $year_name, $year, $times_id_parent);
|
|
|
+ if ($times_id) {
|
|
|
+
|
|
|
+ $parent_page_id = $this->createPage($id, $source_id, $page_name, -1, $times_id_parent, $times_id);
|
|
|
+
|
|
|
+ if ($parent_page_id) {
|
|
|
+ $cover = $pic[0];
|
|
|
+ $cover = Dever::load('upload/view')->get($cover, 't', 1);
|
|
|
+ $cover = Dever::load('upload/view')->get($cover, 'c', 1);
|
|
|
+
|
|
|
+ $page_id = $this->createPage($id, $source_id, $month_name, $parent_page_id, $times_id_parent, $times_id, $page_desc, $cover, $reorder, $max);
|
|
|
+
|
|
|
+ if ($page_id) {
|
|
|
+ $content_id = $this->createContent($id, $source_id, $page_id, 11, $day_name, $cover);
|
|
|
+ if ($content_id) {
|
|
|
+ $this->createPic($id, $content_id, $pic);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -115,7 +148,8 @@ class Spider
|
|
|
$where['info_id'] = $info_id;
|
|
|
$where['source_id'] = $source_id;
|
|
|
$where['times_id'] = $parent;
|
|
|
- $param['name'] = $name;
|
|
|
+ $where['name'] = $name;
|
|
|
+ $param = array();
|
|
|
if ($year) {
|
|
|
$param['year'] = $year;
|
|
|
}
|
|
@@ -123,7 +157,7 @@ class Spider
|
|
|
}
|
|
|
|
|
|
# 生成章节
|
|
|
- public function createPage($info_id, $source_id, $name, $parent = -1, $times_id_parent, $times_id, $desc = '', $pic = '')
|
|
|
+ public function createPage($info_id, $source_id, $name, $parent = -1, $times_id_parent, $times_id, $desc = '', $pic = '', $reorder = 1, $max = 12, $num = 1)
|
|
|
{
|
|
|
$table = 'collection/page';
|
|
|
$where['info_id'] = $info_id;
|
|
@@ -138,8 +172,32 @@ class Spider
|
|
|
if ($pic) {
|
|
|
$param['pic'] = $pic;
|
|
|
}
|
|
|
-
|
|
|
- return Dever::upinto($table, $where, $param);
|
|
|
+ if ($reorder) {
|
|
|
+ $param['reorder'] = $reorder;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($parent > 0) {
|
|
|
+ $where['clear'] = true;
|
|
|
+ $where['name'] .= '第'.$num.'期';
|
|
|
+ $info = Dever::db($table)->one($where);
|
|
|
+ if (!$info) {
|
|
|
+ $param = array_merge($where, $param);
|
|
|
+ $id = Dever::db($table)->insert($param);
|
|
|
+ } else {
|
|
|
+ $total = Dever::db('collection/content')->total(array('info_id' => $info_id, 'page_id' => $info['id']));
|
|
|
+
|
|
|
+ if ($total >= $max) {
|
|
|
+ $num = $num+1;
|
|
|
+ $id = $this->createPage($info_id, $source_id, $name, $parent, $times_id_parent, $times_id, $desc, $pic, $reorder, $max, $num);
|
|
|
+ } else {
|
|
|
+ $id = $info['id'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $id = Dever::upinto($table, $where, $param);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $id;
|
|
|
}
|
|
|
|
|
|
# 生成内容
|