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'] . '》
'; if ($data['buy'] == 1) { $name = '购买总数'; $html .= '收费
'; } else { $name = '阅读人数'; $html .= '免费
'; } $html .= $name . ':('.$data['num_buy'].'+'.$data['num_add_buy'].')*'.$data['num_ratio_buy'].'='.$data['num_buy_total']; $html .= '
阅读次数:'.$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 = ''.$name.''; return $html; } public function text($database, $content_id, $info_id) { $link = $database->url('edit'); $location = Dever::db('collection/content_text')->config['location']; $html = ''; $i = 0; foreach ($location as $k => $v) { $name = $this->text_name($link, $content_id, $info_id, $k, $v); $html .= ''; if ($i == 2 || $i == 5) { $html .= ''; } $i++; } $html .= '
'.$name.'
'; 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 = ''; $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['预览地址'] = '复制链接'; } elseif ($type == 3) { if ($info['url_m3u8']) { $table['m3u8回放地址'] = $info['url_m3u8']; $table['mp4回放地址'] = $info['url_mp4']; } } return Dever::table($table); } }