123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- <?php
- namespace Collection\Lib;
- use Dever;
- use Dever\Support\Img as Handle;
- class Create
- {
- # 自动创建
- public function up($info_id, $source_id, $name, $desc, $year, $type = 11, $data, $cover = '', $num = 9)
- {
- Dever::config('base')->hook = true;
- $where['info_id'] = $info_id;
- $where['clear'] = true;
- $info = Dever::db('collection/content')->getNew($where);
- $result = array();
- $result['cover'] = $cover;
- if ($type == 11) {
- if (is_string($data)) {
- $data = explode(',', $data);
- }
-
- if (!$cover) {
- $cover = $data[0];
- $result['cover'] = $cover;
- $cover = Dever::load('upload/view')->get($cover, 't', 1);
- $cover = Dever::load('upload/view')->get($cover, 'c', 1);
- }
- }
- $result['cover_center'] = $cover;
- # 内容最大值
- $content_max = $num;
- # 章节最大值
- $parent_page_max = 12;
- # 子章节最大值
- $page_max = 4;
- if ($info) {
- $result['page_id'] = $info['page_id'];
- $page = Dever::db('collection/page')->find($info['page_id']);
- if (!$page) {
- return false;
- }
- $result['parent_times_id'] = $page['times_id_parent'];
- $result['times_id'] = $page['times_id'];
- $result['parent_page_id'] = $page['page_id'];
- if ($info['reorder'] >= $content_max) {
- $result['reorder'] = $info['reorder'] = 1;
-
- if ($page['reorder'] >= $page_max) {
- $parent_page = Dever::db('collection/page')->find($result['parent_page_id']);
-
- if ($parent_page['reorder'] >= $parent_page_max) {
- $result['parent_page_reorder'] = 1;
- $times = Dever::db('collection/times')->find($page['times_id']);
- $result['times_reorder'] = $times['reorder'] + 1;
- $result['times_id'] = $this->createTimes($info_id, $source_id, $result['times_reorder'], '', $times['year'] + 1, $result['parent_times_id']);
- } else {
- $result['parent_page_reorder'] = $parent_page['reorder'] + 1;
- }
- $result['parent_page_id'] = $this->createPage($info_id, $source_id, $result['parent_times_id'], $result['times_id'], $result['parent_page_reorder']);
- $result['page_reorder'] = 1;
- } else {
- # 直接创建子章节
- $result['page_reorder'] = $page['reorder'] + 1;
- }
- $result['page_id'] = $this->createPage($info_id, $source_id, $result['parent_times_id'], $result['times_id'], $result['page_reorder'], $result['parent_page_id'], $desc, $cover);
- } else {
- $result['reorder'] = $info['reorder'] + 1;
- }
- $result['content_id'] = $this->createContent($info_id, $source_id, $result['page_id'], $type, $result['reorder'], $cover);
- } else {
- $result['reorder'] = $result['times_reorder'] = $result['parent_page_reorder'] = $result['page_reorder'] = 1;
- $result['parent_times_id'] = $this->createTimes($info_id, $source_id, $result['times_reorder'], $name);
- if ($result['parent_times_id']) {
- $result['times_id'] = $this->createTimes($info_id, $source_id, $result['times_reorder'], '', $year, $result['parent_times_id']);
- if ($result['times_id']) {
- $result['parent_page_id'] = $this->createPage($info_id, $source_id, $result['parent_times_id'], $result['times_id'], $result['parent_page_reorder'], -1);
- if ($result['parent_page_id']) {
- $result['page_id'] = $this->createPage($info_id, $source_id, $result['parent_times_id'], $result['times_id'], $result['page_reorder'], $result['parent_page_id'], $desc, $cover);
- if ($result['page_id']) {
- $result['content_id'] = $this->createContent($info_id, $source_id, $result['page_id'], $type, $result['reorder'], $cover);
- }
- }
- }
- }
- }
- if ($result['content_id'] && $data) {
- if ($type == 11) {
- $this->createPic($info_id, $result['content_id'], $data);
- }
- }
- return $result;
- }
- # 生成时光
- public function createTimes($info_id, $source_id, $reorder, $name, $year = '', $parent = -1)
- {
- $table = 'collection/times';
- $where['info_id'] = $info_id;
- $where['source_id'] = $source_id;
- $where['parent_id'] = $parent;
- if ($name) {
- $where['name'] = $name;
- } else {
- $where['name'] = '第' . $reorder . '卷';
- }
-
- $param = array();
- if ($year) {
- $param['year'] = $year;
- }
- $param['reorder'] = $reorder;
- return Dever::upinto($table, $where, $param);
- }
- # 生成章节
- public function createPage($info_id, $source_id, $times_id_parent, $times_id, $reorder = 1, $parent_page_id = -1, $desc = '', $pic = '')
- {
- $table = 'collection/page';
- $where['info_id'] = $info_id;
- $where['source_id'] = $source_id;
- $where['page_id'] = $parent_page_id;
- if ($parent_page_id > 0) {
- $where['name'] = '第' . $reorder . '章';
- } else {
- $where['name'] = '第' . $reorder . '季';
- }
-
- $where['times_id_parent'] = $times_id_parent;
- $where['times_id'] = $times_id;
- $param = array();
- $param['reorder'] = $reorder;
- if ($desc) {
- $param['desc'] = $desc;
- }
- if ($pic) {
- $param['pic'] = $pic;
- }
- $id = Dever::upinto($table, $where, $param);
- return $id;
- }
- # 生成内容
- public function createContent($info_id, $source_id, $page_id, $type, $reorder, $pic)
- {
- $table = 'collection/content';
- $where['info_id'] = $info_id;
- $where['source_id'] = $source_id;
- $where['name'] = '第' . $reorder . '篇';
- $where['page_id'] = $page_id;
- $where['type'] = $type;
- $param = array();
- if ($pic) {
- $param['pic'] = $pic;
- }
- $param['reorder'] = $reorder;
- 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;
- $info = parse_url($v);
- $v = ltrim($info['path'], '/');
- $file = Dever::db('upload/file')->find(array('file' => $v));
- if ($file) {
- $param['pic_info'] = $file['width'] . ',' . $file['height'] . ',' . $file['size'];
- }
- Dever::upinto($table, $where, $param);
- Dever::load('collection/lib/content')->updateTypeId($id, '', $where);
- /*
- $v = Dever::curl($v . '?imageInfo');
- $v = Dever::json_decode($v);
- if (isset($v['width']) && $v['width'] > 0) {
- Dever::upinto($table, $where, $param);
- Dever::load('collection/lib/content')->updateTypeId($id, '', $where);
- }
- */
- }
- }
- }
|