dever 3 tahun lalu
induk
melakukan
ade87d9b31

+ 9 - 0
app/collection/database/content.php

@@ -66,6 +66,15 @@ return array
             'value'     => Dever::input('search_option_info_id')
         ),
 
+        'source_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '来源id-一般为采集器的采集规则id,用以区分导入的数据是否重复',
+            'default'   => '-1',
+            'desc'      => '来源id',
+            'match'     => 'is_numeric',
+        ),
+
         'page_id'      => array
         (
             'type'      => 'int-11',

+ 10 - 1
app/collection/database/page.php

@@ -6,7 +6,7 @@ $page = function() use ($info_id)
 {
 	$array = array
 	(
-		-1 => array('id' => '-1', 'name' => '父级章节'),
+		//-1 => array('id' => '-1', 'name' => '父级章节'),
 	);
 	$info = Dever::db('collection/page')->state(array('info_id' => $info_id, 'page_id' => -1));
 	if($info)
@@ -94,6 +94,15 @@ return array
             'value'     => $info_id
         ),
 
+        'source_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '来源id-一般为采集器的采集规则id,用以区分导入的数据是否重复',
+            'default'   => '-1',
+            'desc'      => '来源id',
+            'match'     => 'is_numeric',
+        ),
+
 		'name'		=> array
 		(
 			'type' 		=> 'varchar-150',

+ 9 - 0
app/collection/database/times.php

@@ -36,6 +36,15 @@ return array
             'value'     => Dever::input('search_option_info_id')
         ),
 
+        'source_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '来源id-一般为采集器的采集规则id,用以区分导入的数据是否重复',
+            'default'   => '-1',
+            'desc'      => '来源id',
+            'match'     => 'is_numeric',
+        ),
+
 		'name'		=> array
 		(
 			'type' 		=> 'varchar-150',

+ 0 - 5
app/collection/lib/Content.php

@@ -7,11 +7,6 @@ use Dever\Support\Img as Handle;
 
 class Content
 {
-    public function spider($data)
-    {
-        //print_r($data);die;
-    }
-
     public function updateTypeId($id, $name, $data)
     {
         # 同步更新到content的type_id

+ 137 - 0
app/collection/lib/Spider.php

@@ -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);
+    	}
+    }
+}

+ 9 - 0
app/content/database/pic.php

@@ -95,6 +95,15 @@ return array
             'update'    => 'radio',
             'option'    => $type,
         ),
+
+        'pic_key'        => array
+        (
+            'type'      => 'varchar-80',
+            'name'      => '图片md5信息',
+            'default'   => '',
+            'desc'      => '图片md5信息',
+            'match'     => 'is_string',
+        ),
 		
 		'pic'     => array
         (