|
@@ -0,0 +1,137 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace Collection\Lib;
|
|
|
+
|
|
|
+use Dever;
|
|
|
+use Dever\Support\Img as Handle;
|
|
|
+
|
|
|
+class Spider
|
|
|
+{
|
|
|
+ public function test_api()
|
|
|
+ {
|
|
|
+ Dever::setInut('id', 3);
|
|
|
+ Dever::setInut('name', '美女图');
|
|
|
+ $data = array
|
|
|
+ (
|
|
|
+ 'project_id' => 12,
|
|
|
+ 'cdate' => '2021-12-01',
|
|
|
+ 'name' => '吴倩COSMO武汉姑娘大片感受武汉日夜烟火',
|
|
|
+ 'pic' => 'http://192.168.33.10/dreamland/data/upload/1/2021/12/01/8e3699accf599a6d8029eb5a397d582a.jpg',
|
|
|
+ );
|
|
|
+ $this->pic($data);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function pic($data)
|
|
|
+ {
|
|
|
+ $id = Dever::input('info_id');
|
|
|
+ $name = Dever::input('time_name');
|
|
|
+ if (!$id || !$name) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!isset($data['pic'])) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!$data['pic']) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $pic = explode(',', $data['pic']);
|
|
|
+ $source_id = $data['project_id'];
|
|
|
+ $date = explode('-', $data['cdate']);
|
|
|
+
|
|
|
+
|
|
|
+ $year = $date[0];
|
|
|
+
|
|
|
+
|
|
|
+ $month = $date[1] . '月';
|
|
|
+
|
|
|
+
|
|
|
+ $day = $date[2] . '日';
|
|
|
+
|
|
|
+
|
|
|
+ $times_id_parent = $this->createTimes($id, $source_id, $name);
|
|
|
+ if ($times_id_parent) {
|
|
|
+ $times_id = $this->createTimes($id, $source_id, $year . '年', $year, $times_id_parent);
|
|
|
+ if ($times_id) {
|
|
|
+
|
|
|
+ $page_id = $this->createPage($id, $source_id, $month, -1, $times_id_parent, $times_id);
|
|
|
+
|
|
|
+ if ($page_id) {
|
|
|
+ $cover = Dever::pic($pic[0], 't1_c1');
|
|
|
+ $page_id = $this->createPage($id, $source_id, $day, $page_id, $times_id_parent, $times_id, $data['name'], $cover);
|
|
|
+
|
|
|
+ if ($page_id) {
|
|
|
+ $content_id = $this->createContent($id, $source_id, $page_id, 11, $data['name'], $cover);
|
|
|
+ if ($content_id) {
|
|
|
+ $this->createPic($id, $content_id, $pic);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function createTimes($info_id, $source_id, $name, $year = '', $parent = -1)
|
|
|
+ {
|
|
|
+ $table = 'collection/times';
|
|
|
+ $where['info_id'] = $info_id;
|
|
|
+ $where['source_id'] = $source_id;
|
|
|
+ $where['times_id'] = $parent;
|
|
|
+ $param['name'] = $name;
|
|
|
+ if ($year) {
|
|
|
+ $param['year'] = $year;
|
|
|
+ }
|
|
|
+ return Dever::upinto($table, $where, $param);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function createPage($info_id, $source_id, $name, $parent = -1, $times_id_parent, $times_id, $desc = '', $pic = '')
|
|
|
+ {
|
|
|
+ $table = 'collection/page';
|
|
|
+ $where['info_id'] = $info_id;
|
|
|
+ $where['source_id'] = $source_id;
|
|
|
+ $where['name'] = $name;
|
|
|
+ $where['page_id'] = $parent;
|
|
|
+ $param['times_id_parent'] = $times_id_parent;
|
|
|
+ $param['times_id'] = $times_id;
|
|
|
+ if ($desc) {
|
|
|
+ $param['desc'] = $desc;
|
|
|
+ }
|
|
|
+ if ($pic) {
|
|
|
+ $param['pic'] = $pic;
|
|
|
+ }
|
|
|
+
|
|
|
+ return Dever::upinto($table, $where, $param);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function createContent($info_id, $source_id, $page_id, $type, $name, $pic)
|
|
|
+ {
|
|
|
+ $table = 'collection/content';
|
|
|
+ $where['info_id'] = $info_id;
|
|
|
+ $where['source_id'] = $source_id;
|
|
|
+ $where['name'] = $name;
|
|
|
+ $where['page_id'] = $page_id;
|
|
|
+ $where['type'] = $type;
|
|
|
+
|
|
|
+ if ($pic) {
|
|
|
+ $param['pic'] = $pic;
|
|
|
+ }
|
|
|
+
|
|
|
+ return Dever::upinto($table, $where, $param);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function createPic($id, $content_id, $pic)
|
|
|
+ {
|
|
|
+ $table = 'content/pic';
|
|
|
+ $where['info_id'] = $id;
|
|
|
+ $where['content_id'] = $content_id;
|
|
|
+ foreach ($pic as $k => $v) {
|
|
|
+ $where['pic_key'] = md5($v);
|
|
|
+ $param['pic'] = $v;
|
|
|
+ Dever::upinto($table, $where, $param);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|