Manage.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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/api')->ding($data);
  22. $num_buy = $data['num_buy'];
  23. $num_add_buy = $data['num_add_buy'];
  24. $num_ratio_buy = $data['num_ratio_buy'];
  25. $num_view = $data['num_view'];
  26. $num_add_view = $data['num_add_view'];
  27. $buy_num = $data['buy_num'];
  28. //$html = '订阅本数:('.$buy_num.'+'.$num_add_buy.')*'.$num_ratio_buy.'='.$num_buy.'<br />阅读数:'.$num_view.'+'.$num_add_view.'<br />评论数:'.$num_comment.'<br />';
  29. $cate = Dever::db('collection/cate')->one($data['cate_id']);
  30. $html = '《' . $cate['name'] . '》<br />';
  31. if ($data['buy'] == 1) {
  32. $html .= '<font style="color:red">收费</font><br />';
  33. $html .= '购买数:('.$buy_num.'+'.$num_add_buy.')*'.$num_ratio_buy.'='.$num_buy;
  34. } else {
  35. $html .= '<font style="color:blue">免费</font><br />';
  36. $html .= '阅读数:'.$num_view.'+'.$num_add_view.'='.($num_view+$num_add_view);
  37. }
  38. return $html;
  39. }
  40. private function search($table = 'content/article')
  41. {
  42. $keyword = Dever::input('keyword');
  43. $yes = Dever::input('yes');
  44. $where = array();
  45. $cate = Dever::input('cate');
  46. if ($cate) {
  47. $where['cate_id'] = $cate;
  48. }
  49. if ($yes) {
  50. $yes = Dever::db($table)->search(array('ids' => $yes));
  51. }
  52. if (!$keyword) {
  53. $where['limit'] = '0,50';
  54. $data = Dever::db($table)->search($where);
  55. } else {
  56. $where['name'] = $keyword;
  57. $data = Dever::db($table)->search($where);
  58. }
  59. $result = array();
  60. if ($yes) {
  61. foreach ($yes as $k => $v) {
  62. if (isset($data[$k])) {
  63. unset($data[$k]);
  64. }
  65. $yes[$k]['selected'] = 'selected';
  66. }
  67. $data = $yes + $data;
  68. $data = array_merge($data, array());
  69. } else {
  70. $data = array_merge($data, array());
  71. }
  72. if (!$data) {
  73. Dever::alert('暂无数据');
  74. }
  75. return $data;
  76. }
  77. # 搜索
  78. public function search_journal_api()
  79. {
  80. return $this->search('collection/info');
  81. }
  82. # 按照分类搜索
  83. public function search_cate_journal_api()
  84. {
  85. $level_num = Dever::input('level_num');
  86. $level_id = Dever::input('level_id');
  87. $auth = Dever::tops();
  88. $where = array();
  89. if ($level_num == 1) {
  90. $default = array
  91. (
  92. 'value' => -1,
  93. 'name' => '选择分类',
  94. );
  95. if ($auth) {
  96. $where['ids'] = $auth;
  97. }
  98. $data = Dever::db('collection/cate')->getIds($where);
  99. } elseif ($level_num == 2 && $level_id > 0) {
  100. $default = array
  101. (
  102. 'value' => -1,
  103. 'name' => '选择合集',
  104. );
  105. if ($level_id > 0) {
  106. $where['cate_id'] = $level_id;
  107. } elseif ($auth) {
  108. $where['cate_id'] = $auth;
  109. }
  110. $data = Dever::db('collection/info')->getIds($where);
  111. } else {
  112. return array();
  113. }
  114. array_unshift($data, $default);
  115. $result['level_total'] = 2;
  116. $result['list'] = $data;
  117. return $result;
  118. }
  119. # 显示内页
  120. public function content()
  121. {
  122. $where['info_id'] = Dever::input('search_option_info_id');
  123. $where['state'] = Dever::input('search_option_state');
  124. $data = Dever::db('collection/content')->all($where);
  125. $database = Dever::load('manage/database');
  126. $type = Dever::db('collection/cate')->config['gettype'];
  127. if ($data) {
  128. foreach ($data as $k => $v) {
  129. $data[$k]['height'] = 'height: 154px;';
  130. $data[$k]['info_height'] = 'height: auto;';
  131. $data[$k]['type_name'] = '[' . $type[$v['type']]['name'] . ']';
  132. $data[$k]['text'] = '';
  133. $link = $database->url('edit', $v['id']) . '&search_option_info_id=' . $where['info_id'];
  134. $data[$k]['edit'] = "fastEdit($(this), '".$link."', '编辑数据内容', '', 1)";
  135. $data[$k]['editurl'] = $link;
  136. if ($v['type_id'] > 0) {
  137. $data[$k]['data_name'] = '更新内容';
  138. } else {
  139. $data[$k]['data_name'] = '新增内容';
  140. }
  141. $table = $type[$v['type']]['table'];
  142. # 验证有没有数据
  143. $info = Dever::load($table)->one(array('content_id' => $v['id'], 'info_id' => $v['info_id']));
  144. $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';
  145. $data[$k]['data_editurl'] = $link;
  146. $data[$k]['delete'] = $database->url('delete', $v['id']);
  147. }
  148. }
  149. return $data;
  150. }
  151. private function text_name($link, $content_id, $info_id, $location, $name)
  152. {
  153. $where['info_id'] = $info_id;
  154. $where['content_id'] = $content_id;
  155. $where['location'] = $location;
  156. $info = Dever::db('collection/content_text')->one($where);
  157. $link .= '&search_option_info_id=' . $info_id. '&search_option_content_id=' . $content_id.'&table=content_text&search_option_location='.$location;
  158. if ($info) {
  159. $link .= '&where_id=' . $info['id'];
  160. }
  161. $html = '<a style="cursor:pointer;" href="javascript:;" onclick="fastEdit($(this), \''.$link.'\', \'编辑'.$name.'文字\', \'\')">'.$name.'</a>';
  162. return $html;
  163. }
  164. public function text($database, $content_id, $info_id)
  165. {
  166. $link = $database->url('edit');
  167. $location = Dever::db('collection/content_text')->config['location'];
  168. $html = '<table class="layui-table"><tbody><tr>';
  169. $i = 0;
  170. foreach ($location as $k => $v) {
  171. $name = $this->text_name($link, $content_id, $info_id, $k, $v);
  172. $html .= '<td>'.$name.'</td>';
  173. if ($i == 2 || $i == 5) {
  174. $html .= '</tr><tr>';
  175. }
  176. $i++;
  177. }
  178. $html .= '</tr></tbody></table>';
  179. return $html;
  180. }
  181. public function updateContent_api()
  182. {
  183. $data = Dever::input('data');
  184. if ($data) {
  185. $data = explode(',', str_replace('data-', '', $data));
  186. foreach ($data as $k => $v) {
  187. $k = $k + 1;
  188. $where['where_id'] = $v;
  189. $where['reorder'] = $k;
  190. Dever::db('collection/content')->update($where);
  191. }
  192. }
  193. return $data;
  194. }
  195. public function addContent($id, $name, $data)
  196. {
  197. # 获取最新的reorder
  198. $info_id = Dever::param('info_id', $data);
  199. $data = Dever::db('collection/content')->getAllByReorder(array('info_id' => $info_id));
  200. if ($data) {
  201. $update['where_id'] = $id;
  202. $update['reorder'] = $data['reorder'] + 1;
  203. Dever::db('collection/content')->update($update);
  204. }
  205. }
  206. public function getName($id)
  207. {
  208. $info = Dever::db('collection/buy')->one($id);
  209. if ($info && $info['name']) {
  210. return $info['name'];
  211. } else {
  212. return '购买' . $info['num'] . '张';
  213. }
  214. }
  215. public function getPrice($id)
  216. {
  217. $info = Dever::db('collection/buy')->one($id);
  218. $collection = Dever::db('collection/info')->one($info['info_id']);
  219. if ($info && $info['price']) {
  220. return $info['price'];
  221. } else {
  222. return $info['num'] * $collection['cash'] . '元';
  223. }
  224. }
  225. public function setJournalCache($id, $name, $param)
  226. {
  227. Dever::load('act/order')->setCache($id, 1);
  228. }
  229. public function setBuyCache($id, $name, $param)
  230. {
  231. Dever::load('act/order')->setCache($id, 2);
  232. }
  233. public function setRankingCache($id, $name, $param)
  234. {
  235. Dever::load('act/order')->setCache($id, 3);
  236. }
  237. }