123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- <?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/api')->ding($data);
- $num_buy = $data['num_buy'];
- $num_add_buy = $data['num_add_buy'];
- $num_ratio_buy = $data['num_ratio_buy'];
- $num_view = $data['num_view'];
- $num_add_view = $data['num_add_view'];
- $buy_num = $data['buy_num'];
- //$html = '订阅本数:('.$buy_num.'+'.$num_add_buy.')*'.$num_ratio_buy.'='.$num_buy.'<br />阅读数:'.$num_view.'+'.$num_add_view.'<br />评论数:'.$num_comment.'<br />';
- $cate = Dever::db('collection/cate')->one($data['cate_id']);
- $html = '《' . $cate['name'] . '》<br />';
- if ($data['buy'] == 1) {
- $html .= '<font style="color:red">收费</font><br />';
- $html .= '购买数:('.$buy_num.'+'.$num_add_buy.')*'.$num_ratio_buy.'='.$num_buy;
- } else {
- $html .= '<font style="color:blue">免费</font><br />';
- $html .= '阅读数:'.$num_view.'+'.$num_add_view.'='.($num_view+$num_add_view);
- }
-
- 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['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;
- if ($v['type_id'] > 0) {
- $data[$k]['data_name'] = '更新内容';
- } else {
- $data[$k]['data_name'] = '新增内容';
- }
- $table = $type[$v['type']]['table'];
- # 验证有没有数据
- $info = Dever::load($table)->one(array('content_id' => $v['id'], 'info_id' => $v['info_id']));
- $link = $database->url('edit', $v['id']) . '&search_option_info_id=' . $v['info_id'] . '&search_option_content_id=' . $v['id'] . '&project=content&table=news&oper_parent=content&oper_project=collection&oper_save_jump=content';
- $data[$k]['data_editurl'] = $link;
- $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 getName($id)
- {
- $info = Dever::db('collection/buy')->one($id);
- if ($info && $info['name']) {
- return $info['name'];
- } else {
- return '购买' . $info['num'] . '张';
- }
- }
- public function getPrice($id)
- {
- $info = Dever::db('collection/buy')->one($id);
- $collection = Dever::db('collection/info')->one($info['info_id']);
- if ($info && $info['price']) {
- return $info['price'];
- } else {
- return $info['num'] * $collection['cash'] . '元';
- }
- }
- public function setJournalCache($id, $name, $param)
- {
- Dever::load('act/order')->setCache($id, 1);
- }
- public function setBuyCache($id, $name, $param)
- {
- Dever::load('act/order')->setCache($id, 2);
- }
- public function setRankingCache($id, $name, $param)
- {
- Dever::load('act/order')->setCache($id, 3);
- }
- }
|