Manage.php 13 KB

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