Manage.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <?php
  2. namespace Collection\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. public function getManageData()
  7. {
  8. $data = array();
  9. $data = Dever::db('collection/cate')->state();
  10. if ($data) {
  11. foreach ($data as $k => $v) {
  12. $data[$k]['child'] = Dever::db('collection/info')->state(array('cate_id' => $v['id']));
  13. }
  14. }
  15. return $data;
  16. }
  17. # 获取数据
  18. public function num($id)
  19. {
  20. $data = Dever::db('collection/info')->one($id);
  21. $data = Dever::load('collection/lib/info')->one($data);
  22. $cate = Dever::db('collection/cate')->one($data['cate_id']);
  23. $html = '《' . $cate['name'] . '》<br />';
  24. if ($data['buy'] == 1) {
  25. $name = '购买总数';
  26. $html .= '<font style="color:red">收费</font><br />';
  27. } else {
  28. $name = '阅读人数';
  29. $html .= '<font style="color:blue">免费</font><br />';
  30. }
  31. $html .= $name . ':('.$data['num_buy'].'+'.$data['num_add_buy'].')*'.$data['num_ratio_buy'].'='.$data['num_buy_total'];
  32. $html .= '<br />阅读次数:'.$data['num_view'].'+'.$data['num_add_view'].'='.$data['num_view_total'];
  33. return $html;
  34. }
  35. # 获取数据
  36. public function objectNum($id)
  37. {
  38. $data = Dever::db('collection/object')->one($id);
  39. $data = Dever::load('collection/lib/info')->one($data);
  40. $html = '购买数:('.$data['num_buy'].'+'.$data['num_add_buy'].')*'.$data['num_ratio_buy'].'='.$data['num_buy_total'];
  41. return $html;
  42. }
  43. private function search($table = 'content/article')
  44. {
  45. $keyword = Dever::input('keyword');
  46. $yes = Dever::input('yes');
  47. $where = array();
  48. $cate = Dever::input('cate');
  49. if ($cate) {
  50. $where['cate_id'] = $cate;
  51. }
  52. if ($yes) {
  53. $yes = Dever::db($table)->search(array('ids' => $yes));
  54. }
  55. if (!$keyword) {
  56. $where['limit'] = '0,50';
  57. $data = Dever::db($table)->search($where);
  58. } else {
  59. $where['name'] = $keyword;
  60. $data = Dever::db($table)->search($where);
  61. }
  62. $result = array();
  63. if ($yes) {
  64. foreach ($yes as $k => $v) {
  65. if (isset($data[$k])) {
  66. unset($data[$k]);
  67. }
  68. $yes[$k]['selected'] = 'selected';
  69. }
  70. $data = $yes + $data;
  71. $data = array_merge($data, array());
  72. } else {
  73. $data = array_merge($data, array());
  74. }
  75. if (!$data) {
  76. Dever::alert('暂无数据');
  77. }
  78. return $data;
  79. }
  80. # 搜索
  81. public function search_journal_api()
  82. {
  83. return $this->search('collection/info');
  84. }
  85. # 按照分类搜索
  86. public function search_cate_journal_api()
  87. {
  88. $level_num = Dever::input('level_num');
  89. $level_id = Dever::input('level_id');
  90. $auth = Dever::tops();
  91. $where = array();
  92. if ($level_num == 1) {
  93. $default = array
  94. (
  95. 'value' => -1,
  96. 'name' => '选择分类',
  97. );
  98. if ($auth) {
  99. $where['ids'] = $auth;
  100. }
  101. $data = Dever::db('collection/cate')->getIds($where);
  102. } elseif ($level_num == 2 && $level_id > 0) {
  103. $default = array
  104. (
  105. 'value' => -1,
  106. 'name' => '选择合集',
  107. );
  108. if ($level_id > 0) {
  109. $where['cate_id'] = $level_id;
  110. } elseif ($auth) {
  111. $where['cate_id'] = $auth;
  112. }
  113. $data = Dever::db('collection/info')->getIds($where);
  114. } else {
  115. return array();
  116. }
  117. array_unshift($data, $default);
  118. $result['level_total'] = 2;
  119. $result['list'] = $data;
  120. return $result;
  121. }
  122. # 显示内页
  123. public function content()
  124. {
  125. $where['info_id'] = Dever::input('search_option_info_id');
  126. $where['page_id'] = Dever::input('send_page_id');
  127. $where['state'] = Dever::input('search_option_state');
  128. $data = Dever::db('collection/content')->all($where);
  129. $database = Dever::load('manage/database');
  130. $type = Dever::db('collection/cate')->config['gettype'];
  131. if ($data) {
  132. foreach ($data as $k => $v) {
  133. $data[$k]['height'] = 'height: 154px;';
  134. $data[$k]['info_height'] = 'height: auto;';
  135. $data[$k]['type_name'] = '[' . $type[$v['type']]['name'] . ']';
  136. $data[$k]['text'] = '';
  137. $link = $database->url('edit', $v['id']) . '&search_option_info_id=' . $where['info_id'];
  138. $data[$k]['edit'] = "fastEdit($(this), '".$link."', '编辑数据内容', '', 1)";
  139. $data[$k]['editurl'] = $link;
  140. $table = $type[$v['type']]['table'];
  141. $list = false;
  142. $method = 'edit';
  143. if (strstr($table, '-')) {
  144. $list = true;
  145. $temp = explode('-', $table);
  146. $table = $temp[0];
  147. $method = 'list';
  148. }
  149. # 验证有没有数据
  150. $info = Dever::db($table)->one(array('content_id' => $v['id'], 'info_id' => $v['info_id']));
  151. $id = false;
  152. if ($list) {
  153. $data[$k]['data_name'] = '内容列表';
  154. } elseif ($info) {
  155. $id = $info['id'];
  156. $data[$k]['data_name'] = '更新内容';
  157. } else {
  158. $data[$k]['data_name'] = '新增内容';
  159. }
  160. $temp = explode('/', $table);
  161. $project_name = $temp[0];
  162. $table_name = $temp[1];
  163. $param['search_option_info_id'] = $v['info_id'];
  164. $param['search_option_content_id'] = $v['id'];
  165. # 当前表和项目
  166. $param['table'] = $table_name;
  167. $param['project'] = $project_name;
  168. # 保存之后要跳转的表和项目
  169. if ($list) {
  170. $param['oper_page_type'] = 1;
  171. # 更新后要跳转的
  172. $param['oper_save_table'] = $table_name;
  173. $param['oper_save_project'] = $project_name;
  174. # 上级表和项目
  175. $param['oper_table'] = 'content';
  176. $param['oper_project'] = 'collection';
  177. $param['top_table'] = 'page.info';
  178. $param['top_project'] = 'collection';
  179. } else {
  180. $param['oper_save_table'] = 'content';
  181. $param['oper_save_project'] = 'collection';
  182. $param['oper_table'] = 'page';
  183. $param['oper_project'] = 'collection';
  184. $param['top_table'] = 'info';
  185. $param['top_project'] = 'collection';
  186. }
  187. $data[$k]['data_editurl'] = $database->url($method, $id, $table_name, '', $project_name, $param);
  188. $data[$k]['delete'] = $database->url('delete', $v['id']);
  189. }
  190. }
  191. return $data;
  192. }
  193. private function text_name($link, $content_id, $info_id, $location, $name)
  194. {
  195. $where['info_id'] = $info_id;
  196. $where['content_id'] = $content_id;
  197. $where['location'] = $location;
  198. $info = Dever::db('collection/content_text')->one($where);
  199. $link .= '&search_option_info_id=' . $info_id. '&search_option_content_id=' . $content_id.'&table=content_text&search_option_location='.$location;
  200. if ($info) {
  201. $link .= '&where_id=' . $info['id'];
  202. }
  203. $html = '<a style="cursor:pointer;" href="javascript:;" onclick="fastEdit($(this), \''.$link.'\', \'编辑'.$name.'文字\', \'\')">'.$name.'</a>';
  204. return $html;
  205. }
  206. public function text($database, $content_id, $info_id)
  207. {
  208. $link = $database->url('edit');
  209. $location = Dever::db('collection/content_text')->config['location'];
  210. $html = '<table class="layui-table"><tbody><tr>';
  211. $i = 0;
  212. foreach ($location as $k => $v) {
  213. $name = $this->text_name($link, $content_id, $info_id, $k, $v);
  214. $html .= '<td>'.$name.'</td>';
  215. if ($i == 2 || $i == 5) {
  216. $html .= '</tr><tr>';
  217. }
  218. $i++;
  219. }
  220. $html .= '</tr></tbody></table>';
  221. return $html;
  222. }
  223. public function updateContent_api()
  224. {
  225. $data = Dever::input('data');
  226. if ($data) {
  227. $data = explode(',', str_replace('data-', '', $data));
  228. foreach ($data as $k => $v) {
  229. $k = $k + 1;
  230. $where['where_id'] = $v;
  231. $where['reorder'] = $k;
  232. Dever::db('collection/content')->update($where);
  233. }
  234. }
  235. return $data;
  236. }
  237. public function addContent($id, $name, $data)
  238. {
  239. # 获取最新的reorder
  240. $info_id = Dever::param('info_id', $data);
  241. $data = Dever::db('collection/content')->getAllByReorder(array('info_id' => $info_id));
  242. if ($data) {
  243. $update['where_id'] = $id;
  244. $update['reorder'] = $data['reorder'] + 1;
  245. Dever::db('collection/content')->update($update);
  246. }
  247. }
  248. public function setInfo($id, $name, $param)
  249. {
  250. $score_type = Dever::param('score_type', $param);
  251. if ($score_type) {
  252. $score_id = Dever::param('score_id', $param);
  253. $name = Dever::param('score_name', $param);
  254. Dever::load('score/lib/core')->setScoreChild($score_type, $score_id, 'collection/info', $id, $name);
  255. }
  256. }
  257. public function setTop($id, $name, $param)
  258. {
  259. $top = Dever::param('top', $param);
  260. if ($top) {
  261. $info = Dever::db('collection/info')->one($id);
  262. if ($info['cate_id']) {
  263. $cate = Dever::db('collection/info')->one(array('cate_id' => $info['cate_id'], 'top' => 1));
  264. if ($cate) {
  265. Dever::db('collection/cate')->update(array('where_id' => $info['cate_id'], 'top' => 1));
  266. }
  267. }
  268. }
  269. }
  270. # 获取预览
  271. public function preview_api()
  272. {
  273. $type = Dever::input('type');
  274. $id = Dever::input('id');
  275. /*
  276. $audit = Dever::input('audit');
  277. if ($audit) {
  278. $audit = Dever::db('audit/data')->one($id);
  279. $type = $audit['type'];
  280. $id = $audit['data_id'];
  281. }
  282. */
  283. $table = Dever::config('base')->table_name[$type];
  284. $info = Dever::db($table)->one($id);
  285. if (!$info) {
  286. return '暂无数据';
  287. }
  288. $table = array();
  289. /*
  290. $path = Dever::config('base')->applet['index'];
  291. //$scene = Dever::login(-1) . ',' . $type . ',' . $id;
  292. if ($type == 1) {
  293. $scene = -1 . ',' . $type . ',' . 'preview_' . $id;
  294. } else {
  295. $scene = -1 . ',' . $type . ',' . $id;
  296. }
  297. $send['project'] = 1;
  298. $send['send'] = $scene;
  299. $send['width'] = 152;
  300. $send['path'] = $path;
  301. $logo = Dever::load('wechat_applet/code.get', $send);
  302. $html = '<img src="'.$logo.'" width="150">';
  303. $table['预览小程序码'] = $html;
  304. */
  305. if ($type == 1) {
  306. //$link = Dever::url('view.get?type=' . $type . '&id=' . $id, 'h5');
  307. $key = Dever::config('base', 'project')->encode_key;
  308. $id = Dever::encode($id, $key);
  309. $link = 'https://he.shemic.com/web/#/pages/dream/index?id=' . $id;
  310. $table['预览地址'] = '<a class="clipboard" href="javascript:;" data-clipboard-text="'.$link.'">复制链接</a>';
  311. } elseif ($type == 3) {
  312. if ($info['url_m3u8']) {
  313. $table['m3u8回放地址'] = $info['url_m3u8'];
  314. $table['mp4回放地址'] = $info['url_mp4'];
  315. }
  316. }
  317. return Dever::table($table);
  318. }
  319. }