Manage.php 12 KB

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