123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400 |
- <?php
- namespace Collection\Lib;
- use Dever;
- class Manage
- {
- public function getManageData()
- {
- $data = array();
- $data = Dever::db('collection/cate')->state();
- if ($data) {
- foreach ($data as $k => $v) {
- $data[$k]['child'] = Dever::db('collection/info')->state(array('cate_id' => $v['id']));
- }
- }
- return $data;
- }
- # 获取数据
- public function num($id)
- {
- $data = Dever::db('collection/info')->one($id);
- $data = Dever::load('collection/lib/info')->one($data);
- $cate = Dever::db('collection/cate')->one($data['cate_id']);
- $html = '《' . $cate['name'] . '》<br />';
- if ($data['buy'] == 1) {
- $name = '购买总数';
- $html .= '<font style="color:red">收费</font><br />';
- } else {
- $name = '阅读人数';
- $html .= '<font style="color:blue">免费</font><br />';
- }
-
- $html .= $name . ':('.$data['num_buy'].'+'.$data['num_add_buy'].')*'.$data['num_ratio_buy'].'='.$data['num_buy_total'];
-
- $html .= '<br />阅读次数:'.$data['num_view'].'+'.$data['num_add_view'].'='.$data['num_view_total'];
-
- return $html;
- }
- # 获取数据
- public function objectNum($id)
- {
- $data = Dever::db('collection/object')->one($id);
- $data = Dever::load('collection/lib/info')->one($data);
- $html = '购买数:('.$data['num_buy'].'+'.$data['num_add_buy'].')*'.$data['num_ratio_buy'].'='.$data['num_buy_total'];
-
- return $html;
- }
- private function search($table = 'content/article')
- {
- $keyword = Dever::input('keyword');
- $yes = Dever::input('yes');
- $where = array();
- $cate = Dever::input('cate');
- if ($cate) {
- $where['cate_id'] = $cate;
- }
- if ($yes) {
- $yes = Dever::db($table)->search(array('ids' => $yes));
- }
- if (!$keyword) {
- $where['limit'] = '0,50';
- $data = Dever::db($table)->search($where);
- } else {
- $where['name'] = $keyword;
- $data = Dever::db($table)->search($where);
- }
- $result = array();
- if ($yes) {
- foreach ($yes as $k => $v) {
- if (isset($data[$k])) {
- unset($data[$k]);
- }
- $yes[$k]['selected'] = 'selected';
- }
- $data = $yes + $data;
- $data = array_merge($data, array());
- } else {
- $data = array_merge($data, array());
- }
- if (!$data) {
- Dever::alert('暂无数据');
- }
- return $data;
- }
- # 搜索
- public function search_journal_api()
- {
- return $this->search('collection/info');
- }
- # 按照分类搜索
- public function search_cate_journal_api()
- {
- $level_num = Dever::input('level_num');
- $level_id = Dever::input('level_id');
-
- $auth = Dever::tops();
- $where = array();
- if ($level_num == 1) {
- $default = array
- (
- 'value' => -1,
- 'name' => '选择分类',
- );
- if ($auth) {
- $where['ids'] = $auth;
- }
- $data = Dever::db('collection/cate')->getIds($where);
- } elseif ($level_num == 2 && $level_id > 0) {
- $default = array
- (
- 'value' => -1,
- 'name' => '选择合集',
- );
- if ($level_id > 0) {
- $where['cate_id'] = $level_id;
- } elseif ($auth) {
- $where['cate_id'] = $auth;
- }
-
- $data = Dever::db('collection/info')->getIds($where);
- } else {
- return array();
- }
-
- array_unshift($data, $default);
- $result['level_total'] = 2;
- $result['list'] = $data;
- return $result;
- }
- # 显示内页
- public function content()
- {
- $where['info_id'] = Dever::input('search_option_info_id');
- $where['page_id'] = Dever::input('send_page_id');
- $where['state'] = Dever::input('search_option_state');
- $data = Dever::db('collection/content')->all($where);
- $database = Dever::load('manage/database');
- $type = Dever::db('collection/cate')->config['gettype'];
- if ($data) {
- foreach ($data as $k => $v) {
- $data[$k]['height'] = 'height: 154px;';
- $data[$k]['info_height'] = 'height: auto;';
- $data[$k]['type_name'] = '[' . $type[$v['type']]['name'] . ']';
- $data[$k]['text'] = '';
- $link = $database->url('edit', $v['id']) . '&search_option_info_id=' . $where['info_id'];
- $data[$k]['edit'] = "fastEdit($(this), '".$link."', '编辑数据内容', '', 1)";
- $data[$k]['editurl'] = $link;
- $table = $type[$v['type']]['table'];
- $list = false;
- $method = 'edit';
- if (strstr($table, '-')) {
- $list = true;
- $temp = explode('-', $table);
- $table = $temp[0];
- $method = 'list';
- }
- # 验证有没有数据
- $info = Dever::db($table)->one(array('content_id' => $v['id'], 'info_id' => $v['info_id']));
- $id = false;
- if ($list) {
- $data[$k]['data_name'] = '内容列表';
- } elseif ($info) {
- $id = $info['id'];
- $data[$k]['data_name'] = '更新内容';
- } else {
- $data[$k]['data_name'] = '新增内容';
- }
- $temp = explode('/', $table);
- $project_name = $temp[0];
- $table_name = $temp[1];
- $param['search_option_info_id'] = $v['info_id'];
- $param['search_option_content_id'] = $v['id'];
- # 当前表和项目
- $param['table'] = $table_name;
- $param['project'] = $project_name;
- # 保存之后要跳转的表和项目
- if ($list) {
- $param['oper_page_type'] = 1;
- # 更新后要跳转的
- $param['oper_save_table'] = $table_name;
- $param['oper_save_project'] = $project_name;
- # 上级表和项目
- $param['oper_table'] = 'content';
- $param['oper_project'] = 'collection';
- $param['top_table'] = 'page.info';
- $param['top_project'] = 'collection';
- } else {
- $param['oper_save_table'] = 'content';
- $param['oper_save_project'] = 'collection';
- $param['oper_table'] = 'page';
- $param['oper_project'] = 'collection';
- $param['top_table'] = 'info';
- $param['top_project'] = 'collection';
- }
-
- $data[$k]['data_editurl'] = $database->url($method, $id, $table_name, '', $project_name, $param);
-
- $data[$k]['delete'] = $database->url('delete', $v['id']);
- }
- }
- return $data;
- }
- private function text_name($link, $content_id, $info_id, $location, $name)
- {
- $where['info_id'] = $info_id;
- $where['content_id'] = $content_id;
- $where['location'] = $location;
- $info = Dever::db('collection/content_text')->one($where);
- $link .= '&search_option_info_id=' . $info_id. '&search_option_content_id=' . $content_id.'&table=content_text&search_option_location='.$location;
- if ($info) {
- $link .= '&where_id=' . $info['id'];
- }
- $html = '<a style="cursor:pointer;" href="javascript:;" onclick="fastEdit($(this), \''.$link.'\', \'编辑'.$name.'文字\', \'\')">'.$name.'</a>';
- return $html;
- }
- public function text($database, $content_id, $info_id)
- {
- $link = $database->url('edit');
- $location = Dever::db('collection/content_text')->config['location'];
- $html = '<table class="layui-table"><tbody><tr>';
- $i = 0;
- foreach ($location as $k => $v) {
- $name = $this->text_name($link, $content_id, $info_id, $k, $v);
- $html .= '<td>'.$name.'</td>';
- if ($i == 2 || $i == 5) {
- $html .= '</tr><tr>';
- }
- $i++;
- }
- $html .= '</tr></tbody></table>';
- return $html;
- }
- public function updateContent_api()
- {
- $data = Dever::input('data');
- if ($data) {
- $data = explode(',', str_replace('data-', '', $data));
- foreach ($data as $k => $v) {
- $k = $k + 1;
- $where['where_id'] = $v;
- $where['reorder'] = $k;
- Dever::db('collection/content')->update($where);
- }
- }
- return $data;
- }
- public function addContent($id, $name, $data)
- {
- # 获取最新的reorder
- $info_id = Dever::param('info_id', $data);
- $data = Dever::db('collection/content')->getAllByReorder(array('info_id' => $info_id));
- if ($data) {
- $update['where_id'] = $id;
- $update['reorder'] = $data['reorder'] + 1;
- Dever::db('collection/content')->update($update);
- }
- }
- public function setInfo($id, $name, $param)
- {
- $score_type = Dever::param('score_type', $param);
- if ($score_type) {
- $score_id = Dever::param('score_id', $param);
- $name = Dever::param('score_name', $param);
- Dever::load('score/lib/core')->setScoreChild($score_type, $score_id, 'collection/info', $id, $name);
- }
- }
- public function setTop($id, $name, $param)
- {
- $top = Dever::param('top', $param);
- if ($top) {
- $info = Dever::db('collection/info')->one($id);
- if ($info['cate_id']) {
- $cate = Dever::db('collection/info')->one(array('cate_id' => $info['cate_id'], 'top' => 1));
- if ($cate) {
- Dever::db('collection/cate')->update(array('where_id' => $info['cate_id'], 'top' => 1));
- }
- }
- }
- }
- # 获取预览
- public function preview_api()
- {
- $type = Dever::input('type');
- $id = Dever::input('id');
- /*
- $audit = Dever::input('audit');
- if ($audit) {
- $audit = Dever::db('audit/data')->one($id);
- $type = $audit['type'];
- $id = $audit['data_id'];
- }
- */
- $table = Dever::config('base')->table_name[$type];
- $info = Dever::db($table)->one($id);
- if (!$info) {
- return '暂无数据';
- }
- $table = array();
- /*
- $path = Dever::config('base')->applet['index'];
- //$scene = Dever::login(-1) . ',' . $type . ',' . $id;
- if ($type == 1) {
- $scene = -1 . ',' . $type . ',' . 'preview_' . $id;
- } else {
- $scene = -1 . ',' . $type . ',' . $id;
- }
- $send['project'] = 1;
- $send['send'] = $scene;
- $send['width'] = 152;
- $send['path'] = $path;
- $logo = Dever::load('wechat_applet/code.get', $send);
- $html = '<img src="'.$logo.'" width="150">';
- $table['预览小程序码'] = $html;
- */
- if ($type == 1) {
- //$link = Dever::url('view.get?type=' . $type . '&id=' . $id, 'h5');
- $key = Dever::config('base', 'project')->encode_key;
- $id = Dever::encode($id, $key);
- $link = 'https://he.shemic.com/web/#/pages/dream/index?id=' . $id;
- $table['预览地址'] = '<a class="clipboard" href="javascript:;" data-clipboard-text="'.$link.'">复制链接</a>';
- } elseif ($type == 3) {
- if ($info['url_m3u8']) {
- $table['m3u8回放地址'] = $info['url_m3u8'];
- $table['mp4回放地址'] = $info['url_mp4'];
- }
- }
- return Dever::table($table);
- }
- }
|