Manage.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <?php
  2. namespace Magazine\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. public function getManageData()
  7. {
  8. $data = array();
  9. $data = Dever::db('magazine/cate')->state();
  10. if ($data) {
  11. foreach ($data as $k => $v) {
  12. $data[$k]['child'] = Dever::db('magazine/info')->state(array('cate_id' => $v['id']));
  13. }
  14. }
  15. return $data;
  16. }
  17. public function showOrderUserV1($id)
  18. {
  19. $info = Dever::db('act/order')->one($id);
  20. $table = array();
  21. $user = Dever::db('passport/user')->one($info['uid']);
  22. $table['用户名'] = $user['username'] . '('.$info['uid'].')';
  23. $table['手机号'] = $user['mobile'];
  24. $table['产品名'] = $info['name'];
  25. if ($info['type'] == 1) {
  26. $table['支付方式'] = '购买小刊';
  27. $table['支付金额'] = $info['cash'];
  28. } elseif ($info['type'] == 3) {
  29. $table['支付方式'] = '购买小刊兑换码';
  30. $table['兑换码'] = $info['code'];
  31. $table['支付金额'] = $info['cash'];
  32. } elseif ($info['type'] == 2) {
  33. $table['支付方式'] = '兑换小刊';
  34. $table['兑换码'] = $info['code'];
  35. } elseif ($info['type'] == 4) {
  36. $table['支付方式'] = '使用通用兑换码';
  37. $table['兑换码'] = $info['code'];
  38. }
  39. //$table['购买数量'] = $info['num'];
  40. if ($info['source_uid'] && $info['source_uid'] != $info['uid']) {
  41. $user = Dever::db('passport/user')->one($info['source_uid']);
  42. $table['邀请人'] = $user['username'];
  43. }
  44. if ($info['star_id']) {
  45. $star = Dever::db('magazine/star')->one($info['star_id']);
  46. $table['明星'] = $star['name'];
  47. }
  48. return Dever::table($table);
  49. }
  50. # 获取数据
  51. public function num($id)
  52. {
  53. $data = Dever::db('magazine/info')->one($id);
  54. $data = Dever::load('magazine/api')->ding($data);
  55. $num_ding = $data['num_ding'];
  56. $num_add_ding = $data['num_add_ding'];
  57. $num_ratio_ding = $data['num_ratio_ding'];
  58. $num_view = $data['num_view'];
  59. $num_add_view = $data['num_add_view'];
  60. $buy_num = $data['buy_num'];
  61. //$html = '订阅本数:('.$buy_num.'+'.$num_add_ding.')*'.$num_ratio_ding.'='.$num_ding.'<br />阅读数:'.$num_view.'+'.$num_add_view.'<br />评论数:'.$num_comment.'<br />';
  62. $cate = Dever::db('magazine/cate')->one($data['cate_id']);
  63. $html = '《' . $cate['name'] . '》<br />';
  64. if ($data['buy'] == 1) {
  65. $html .= '<font style="color:red">收费电子刊</font><br />';
  66. $html .= '订阅本数:('.$buy_num.'+'.$num_add_ding.')*'.$num_ratio_ding.'='.$num_ding;
  67. } else {
  68. $html .= '<font style="color:blue">免费电子刊</font><br />';
  69. $html .= '订阅数:('.$buy_num.'+'.$num_add_ding.')*'.$num_ratio_ding.'='.$num_ding;
  70. }
  71. return $html;
  72. }
  73. public function showOrderStatusV1($id)
  74. {
  75. $info = Dever::db('act/order')->one($id);
  76. if ($info) {
  77. if ($info['status'] == 1) {
  78. #return '*已支付';
  79. return '待支付';
  80. } elseif ($info['status'] == 2) {
  81. return '已支付';
  82. } elseif ($info['status'] == 3) {
  83. return '支付失败';
  84. } elseif ($info['status'] == 5) {
  85. $table['状态'] = '已退款';
  86. $manage = Dever::db('manage/admin')->one($info['tk_admin']);
  87. $table['备注'] = $info['tk_desc'];
  88. $table['截图'] = '<a><img src="'.$info['tk_pic'].'" style="width:150px" /></a>';
  89. //$table['退款时间'] = date('Y-m-d H:i:s', $info['tk_time']);
  90. $table['操作人'] = $manage['username'];
  91. return Dever::table($table);
  92. }
  93. }
  94. }
  95. private function search($table = 'content/article')
  96. {
  97. $keyword = Dever::input('keyword');
  98. $yes = Dever::input('yes');
  99. $where = array();
  100. $cate = Dever::input('cate');
  101. if ($cate) {
  102. $where['cate_id'] = $cate;
  103. }
  104. if ($yes) {
  105. $yes = Dever::db($table)->search(array('ids' => $yes));
  106. }
  107. if (!$keyword) {
  108. $where['limit'] = '0,50';
  109. $data = Dever::db($table)->search($where);
  110. } else {
  111. $where['name'] = $keyword;
  112. $data = Dever::db($table)->search($where);
  113. }
  114. $result = array();
  115. if ($yes) {
  116. foreach ($yes as $k => $v) {
  117. if (isset($data[$k])) {
  118. unset($data[$k]);
  119. }
  120. $yes[$k]['selected'] = 'selected';
  121. }
  122. $data = $yes + $data;
  123. $data = array_merge($data, array());
  124. } else {
  125. $data = array_merge($data, array());
  126. }
  127. if (!$data) {
  128. Dever::alert('暂无数据');
  129. }
  130. return $data;
  131. }
  132. # 搜索电子刊
  133. public function search_journal_api()
  134. {
  135. return $this->search('magazine/info');
  136. }
  137. # 按照分类搜索电子刊
  138. public function search_cate_journal_api()
  139. {
  140. $level_num = Dever::input('level_num');
  141. $level_id = Dever::input('level_id');
  142. $auth = Dever::tops();
  143. $where = array();
  144. if ($level_num == 1) {
  145. $default = array
  146. (
  147. 'value' => -1,
  148. 'name' => '选择分类',
  149. );
  150. if ($auth) {
  151. $where['ids'] = $auth;
  152. }
  153. $data = Dever::db('magazine/cate')->getIds($where);
  154. } elseif ($level_num == 2 && $level_id > 0) {
  155. $default = array
  156. (
  157. 'value' => -1,
  158. 'name' => '选择电子刊',
  159. );
  160. if ($level_id > 0) {
  161. $where['cate_id'] = $level_id;
  162. } elseif ($auth) {
  163. $where['cate_id'] = $auth;
  164. }
  165. $data = Dever::db('magazine/info')->getIds($where);
  166. } else {
  167. return array();
  168. }
  169. array_unshift($data, $default);
  170. $result['level_total'] = 2;
  171. $result['list'] = $data;
  172. return $result;
  173. }
  174. # 显示内页
  175. public function journalContent()
  176. {
  177. $where['info_id'] = Dever::input('search_option_info_id');
  178. $where['state'] = Dever::input('search_option_state');
  179. $data = Dever::db('magazine/content')->all($where);
  180. $database = Dever::load('manage/database');
  181. $type = Dever::db('magazine/content')->config['gettype'];
  182. if ($data) {
  183. foreach ($data as $k => $v) {
  184. $data[$k]['height'] = 'height: 154px;';
  185. $data[$k]['info_height'] = 'height: auto;';
  186. if ($v['type'] > 2) {
  187. $data[$k]['height'] = 'height: 104px;';
  188. $data[$k]['info_height'] = 'height: 47px;';
  189. }
  190. if ($v['type'] <= 2) {
  191. $data[$k]['name'] = '';
  192. } elseif ($v['type'] == 3) {
  193. $data[$k]['pic'] = $v['focus'];
  194. }
  195. if ($v['type'] == 21 || $v['type'] == 22 || $v['type'] == 23) {
  196. $data[$k]['name'] = '';
  197. $data[$k]['pic'] = $v['cover'];
  198. }
  199. if ($v['type'] == 61) {
  200. # 图文
  201. $info = Dever::load('content/lib/article')->get($v['article_id']);
  202. if ($info) {
  203. $data[$k]['pic'] = $info['pic_cover'];
  204. $data[$k]['name'] = $info['name'];
  205. }
  206. } elseif ($v['type'] == 62) {
  207. # 视频
  208. $info = Dever::load('video/lib/vod')->get($v['vod_id']);
  209. if ($info) {
  210. $data[$k]['pic'] = $info['pic_cover'];
  211. $data[$k]['name'] = $info['name'];
  212. }
  213. } elseif ($v['type'] == 63) {
  214. # 直播
  215. $info = Dever::load('video/lib/live')->get($v['live_id']);
  216. if ($info) {
  217. $data[$k]['pic'] = $info['pic_cover'];
  218. $data[$k]['name'] = $info['name'];
  219. }
  220. }
  221. if ($v['type'] == 13) {
  222. $palaces = Dever::array_decode($v['palaces']);
  223. if (isset($palaces[0])) {
  224. $data[$k]['pic'] = $palaces[0]['pic'];
  225. }
  226. }
  227. if ($v['type'] == 41) {
  228. if ($data[$k]['talk_pic']) {
  229. $data[$k]['pic'] = $data[$k]['talk_pic'];
  230. } else {
  231. $talk = Dever::array_decode($v['talk']);
  232. if ($talk) {
  233. foreach ($talk as $tk => $tv) {
  234. if ($tv['pic']) {
  235. $data[$k]['pic'] = $tv['pic'];
  236. break;
  237. }
  238. }
  239. }
  240. }
  241. }
  242. $data[$k]['typename'] = $type[$v['type']];
  243. /*
  244. if ($v['type'] == 1) {
  245. $data[$k]['text'] = $this->text($database, $v['id'], $where['info_id']);
  246. } else {
  247. $data[$k]['text'] = '';
  248. }
  249. */
  250. $data[$k]['text'] = '';
  251. $link = $database->url('edit', $v['id']) . '&search_option_info_id=' . $where['info_id'];
  252. $data[$k]['edit'] = "fastEdit($(this), '".$link."', '编辑内页', '', 1)";
  253. $data[$k]['editurl'] = $link;
  254. $data[$k]['delete'] = $database->url('delete', $v['id']);
  255. }
  256. }
  257. return $data;
  258. }
  259. private function text_name($link, $content_id, $info_id, $location, $name)
  260. {
  261. $where['info_id'] = $info_id;
  262. $where['content_id'] = $content_id;
  263. $where['location'] = $location;
  264. $info = Dever::db('magazine/content_text')->one($where);
  265. $link .= '&search_option_info_id=' . $info_id. '&search_option_content_id=' . $content_id.'&table=content_text&search_option_location='.$location;
  266. if ($info) {
  267. $link .= '&where_id=' . $info['id'];
  268. }
  269. $html = '<a style="cursor:pointer;" href="javascript:;" onclick="fastEdit($(this), \''.$link.'\', \'编辑'.$name.'文字\', \'\')">'.$name.'</a>';
  270. return $html;
  271. }
  272. public function text($database, $content_id, $info_id)
  273. {
  274. $link = $database->url('edit');
  275. $location = Dever::db('magazine/content_text')->config['location'];
  276. $html = '<table class="layui-table"><tbody><tr>';
  277. $i = 0;
  278. foreach ($location as $k => $v) {
  279. $name = $this->text_name($link, $content_id, $info_id, $k, $v);
  280. $html .= '<td>'.$name.'</td>';
  281. if ($i == 2 || $i == 5) {
  282. $html .= '</tr><tr>';
  283. }
  284. $i++;
  285. }
  286. $html .= '</tr></tbody></table>';
  287. return $html;
  288. }
  289. public function updateJournalContent_api()
  290. {
  291. $data = Dever::input('data');
  292. if ($data) {
  293. $data = explode(',', str_replace('data-', '', $data));
  294. foreach ($data as $k => $v) {
  295. $k = $k + 1;
  296. $where['where_id'] = $v;
  297. $where['reorder'] = $k;
  298. Dever::db('magazine/content')->update($where);
  299. }
  300. }
  301. return $data;
  302. }
  303. public function addContent($id, $name, $data)
  304. {
  305. # 获取最新的reorder
  306. $info_id = Dever::param('info_id', $data);
  307. $data = Dever::db('magazine/content')->getAllByReorder(array('info_id' => $info_id));
  308. if ($data) {
  309. $update['where_id'] = $id;
  310. $update['reorder'] = $data['reorder'] + 1;
  311. Dever::db('magazine/content')->update($update);
  312. }
  313. }
  314. public function getName($id)
  315. {
  316. $info = Dever::db('magazine/buy')->one($id);
  317. if ($info && $info['name']) {
  318. return $info['name'];
  319. } else {
  320. return '购买' . $info['num'] . '张';
  321. }
  322. }
  323. public function getPrice($id)
  324. {
  325. $info = Dever::db('magazine/buy')->one($id);
  326. $magazine = Dever::db('magazine/info')->one($info['info_id']);
  327. if ($info && $info['price']) {
  328. return $info['price'];
  329. } else {
  330. return $info['num'] * $magazine['cash'] . '元';
  331. }
  332. }
  333. public function setJournalCache($id, $name, $param)
  334. {
  335. Dever::load('act/order')->setCache($id, 1);
  336. }
  337. public function setBuyCache($id, $name, $param)
  338. {
  339. Dever::load('act/order')->setCache($id, 2);
  340. }
  341. public function setRankingCache($id, $name, $param)
  342. {
  343. Dever::load('act/order')->setCache($id, 3);
  344. }
  345. }