Manage.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. <?php
  2. namespace Journal\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. public function getManageData()
  7. {
  8. $data = array();
  9. $data = Dever::db('journal/cate')->state();
  10. if ($data) {
  11. foreach ($data as $k => $v) {
  12. $data[$k]['child'] = Dever::db('journal/info')->state(array('cate_id' => $v['id']));
  13. }
  14. }
  15. return $data;
  16. }
  17. public function showOrderUser($id)
  18. {
  19. $info = Dever::db('journal/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. return Dever::table($table);
  45. }
  46. public function showOrderUserV1($id)
  47. {
  48. $info = Dever::db('act/order')->one($id);
  49. $table = array();
  50. $user = Dever::db('passport/user')->one($info['uid']);
  51. $table['用户名'] = $user['username'] . '('.$info['uid'].')';
  52. $table['手机号'] = $user['mobile'];
  53. $table['产品名'] = $info['name'];
  54. if ($info['type'] == 1) {
  55. $table['支付方式'] = '购买小刊';
  56. $table['支付金额'] = $info['cash'];
  57. } elseif ($info['type'] == 3) {
  58. $table['支付方式'] = '购买小刊兑换码';
  59. $table['兑换码'] = $info['code'];
  60. $table['支付金额'] = $info['cash'];
  61. } elseif ($info['type'] == 2) {
  62. $table['支付方式'] = '兑换小刊';
  63. $table['兑换码'] = $info['code'];
  64. } elseif ($info['type'] == 4) {
  65. $table['支付方式'] = '使用通用兑换码';
  66. $table['兑换码'] = $info['code'];
  67. }
  68. //$table['购买数量'] = $info['num'];
  69. if ($info['source_uid'] && $info['source_uid'] != $info['uid']) {
  70. $user = Dever::db('passport/user')->one($info['source_uid']);
  71. $table['邀请人'] = $user['username'];
  72. }
  73. if ($info['star_id']) {
  74. $star = Dever::db('journal/star')->one($info['star_id']);
  75. $table['明星'] = $star['name'];
  76. }
  77. return Dever::table($table);
  78. }
  79. # 获取订阅本数
  80. public function ding($id)
  81. {
  82. $data = Dever::db('journal/info')->one($id);
  83. $data = Dever::load('journal/api')->ding($data);
  84. $num_ding = $data['num_ding'];
  85. $num_add_ding = $data['num_add_ding'];
  86. $num_ratio_ding = $data['num_ratio_ding'];
  87. $num_view = $data['num_view'];
  88. $num_add_view = $data['num_add_view'];
  89. $num_comment = $data['num_comment'];
  90. $buy_num = $data['buy_num'];
  91. //$html = '订阅本数:('.$buy_num.'+'.$num_add_ding.')*'.$num_ratio_ding.'='.$num_ding.'<br />阅读数:'.$num_view.'+'.$num_add_view.'<br />评论数:'.$num_comment.'<br />';
  92. $cate = Dever::db('journal/cate')->one($data['cate_id']);
  93. $html = '《' . $cate['name'] . '》<br />';
  94. if ($data['buy'] == 1) {
  95. $html .= '<font style="color:red">收费电子刊</font><br />';
  96. $html .= '订阅本数:('.$buy_num.'+'.$num_add_ding.')*'.$num_ratio_ding.'='.$num_ding;
  97. } else {
  98. $html .= '<font style="color:blue">免费电子刊</font><br />';
  99. $html .= '订阅数:('.$buy_num.'+'.$num_add_ding.')*'.$num_ratio_ding.'='.$num_ding;
  100. }
  101. return $html;
  102. }
  103. public function showOrderStatus($id)
  104. {
  105. $info = Dever::db('journal/order')->one($id);
  106. if ($info) {
  107. if ($info['status'] == 1) {
  108. #return '*已支付';
  109. return '待支付';
  110. } elseif ($info['status'] == 2) {
  111. return '已支付';
  112. } elseif ($info['status'] == 3) {
  113. return '支付失败';
  114. } elseif ($info['status'] == 5) {
  115. $table['状态'] = '已退款';
  116. $manage = Dever::db('manage/admin')->one($info['tk_admin']);
  117. $table['备注'] = $info['tk_desc'];
  118. $table['截图'] = '<a><img src="'.$info['tk_pic'].'" style="width:150px" /></a>';
  119. //$table['退款时间'] = date('Y-m-d H:i:s', $info['tk_time']);
  120. $table['操作人'] = $manage['username'];
  121. return Dever::table($table);
  122. }
  123. }
  124. }
  125. public function showOrderStatusV1($id)
  126. {
  127. $info = Dever::db('act/order')->one($id);
  128. if ($info) {
  129. if ($info['status'] == 1) {
  130. #return '*已支付';
  131. return '待支付';
  132. } elseif ($info['status'] == 2) {
  133. return '已支付';
  134. } elseif ($info['status'] == 3) {
  135. return '支付失败';
  136. } elseif ($info['status'] == 5) {
  137. $table['状态'] = '已退款';
  138. $manage = Dever::db('manage/admin')->one($info['tk_admin']);
  139. $table['备注'] = $info['tk_desc'];
  140. $table['截图'] = '<a><img src="'.$info['tk_pic'].'" style="width:150px" /></a>';
  141. //$table['退款时间'] = date('Y-m-d H:i:s', $info['tk_time']);
  142. $table['操作人'] = $manage['username'];
  143. return Dever::table($table);
  144. }
  145. }
  146. }
  147. private function search($table = 'content/article')
  148. {
  149. $keyword = Dever::input('keyword');
  150. $yes = Dever::input('yes');
  151. $where = array();
  152. $cate = Dever::input('cate');
  153. if ($cate) {
  154. $where['cate_id'] = $cate;
  155. }
  156. if ($yes) {
  157. $yes = Dever::db($table)->search(array('ids' => $yes));
  158. }
  159. if (!$keyword) {
  160. $where['limit'] = '0,50';
  161. $data = Dever::db($table)->search($where);
  162. } else {
  163. $where['name'] = $keyword;
  164. $data = Dever::db($table)->search($where);
  165. }
  166. $result = array();
  167. if ($yes) {
  168. foreach ($yes as $k => $v) {
  169. if (isset($data[$k])) {
  170. unset($data[$k]);
  171. }
  172. $yes[$k]['selected'] = 'selected';
  173. }
  174. $data = $yes + $data;
  175. $data = array_merge($data, array());
  176. } else {
  177. $data = array_merge($data, array());
  178. }
  179. if (!$data) {
  180. Dever::alert('暂无数据');
  181. }
  182. return $data;
  183. }
  184. # 搜索文章
  185. public function search_article_api()
  186. {
  187. return $this->search('content/article');
  188. }
  189. # 搜索视频
  190. public function search_vod_api()
  191. {
  192. return $this->search('video/vod');
  193. }
  194. # 搜索直播
  195. public function search_live_api()
  196. {
  197. return $this->search('video/live');
  198. }
  199. # 搜索小刊
  200. public function search_journal_api()
  201. {
  202. return $this->search('journal/info');
  203. }
  204. # 搜索专题
  205. public function search_feature_api()
  206. {
  207. return $this->search('feature/info');
  208. }
  209. # 搜索小程序
  210. public function search_applet_api()
  211. {
  212. return $this->search('content/applet');
  213. }
  214. # 按照分类搜索小刊
  215. public function search_cate_journal_api()
  216. {
  217. $level_num = Dever::input('level_num');
  218. $level_id = Dever::input('level_id');
  219. $auth = Dever::tops();
  220. $where = array();
  221. if ($level_num == 1) {
  222. $default = array
  223. (
  224. 'value' => -1,
  225. 'name' => '选择分类',
  226. );
  227. if ($auth) {
  228. $where['ids'] = $auth;
  229. }
  230. $data = Dever::db('journal/cate')->getIds($where);
  231. } elseif ($level_num == 2 && $level_id > 0) {
  232. $default = array
  233. (
  234. 'value' => -1,
  235. 'name' => '选择小刊',
  236. );
  237. if ($level_id > 0) {
  238. $where['cate_id'] = $level_id;
  239. } elseif ($auth) {
  240. $where['cate_id'] = $auth;
  241. }
  242. $data = Dever::db('journal/info')->getIds($where);
  243. } else {
  244. return array();
  245. }
  246. array_unshift($data, $default);
  247. $result['level_total'] = 2;
  248. $result['list'] = $data;
  249. return $result;
  250. }
  251. # 显示杂志内页
  252. public function journalContent()
  253. {
  254. $where['info_id'] = Dever::input('search_option_info_id');
  255. $where['state'] = Dever::input('search_option_state');
  256. $data = Dever::db('journal/content')->all($where);
  257. $database = Dever::load('manage/database');
  258. $type = Dever::db('journal/content')->config['gettype'];
  259. if ($data) {
  260. foreach ($data as $k => $v) {
  261. $data[$k]['height'] = 'height: 154px;';
  262. $data[$k]['info_height'] = 'height: auto;';
  263. if ($v['type'] > 2) {
  264. $data[$k]['height'] = 'height: 104px;';
  265. $data[$k]['info_height'] = 'height: 47px;';
  266. }
  267. if ($v['type'] <= 2) {
  268. $data[$k]['name'] = '';
  269. } elseif ($v['type'] == 3) {
  270. $data[$k]['pic'] = $v['focus'];
  271. }
  272. if ($v['type'] == 4 || $v['type'] == 5 || $v['type'] == 6) {
  273. $data[$k]['name'] = '';
  274. $data[$k]['pic'] = $v['cover'];
  275. }
  276. if ($v['type'] == 11) {
  277. # 图文
  278. $info = Dever::load('content/lib/article')->get($v['article_id']);
  279. if ($info) {
  280. $data[$k]['pic'] = $info['pic_cover'];
  281. $data[$k]['name'] = $info['name'];
  282. }
  283. } elseif ($v['type'] == 12) {
  284. # 视频
  285. $info = Dever::load('video/lib/vod')->get($v['vod_id']);
  286. if ($info) {
  287. $data[$k]['pic'] = $info['pic_cover'];
  288. $data[$k]['name'] = $info['name'];
  289. }
  290. } elseif ($v['type'] == 13) {
  291. # 直播
  292. $info = Dever::load('video/lib/live')->get($v['live_id']);
  293. if ($info) {
  294. $data[$k]['pic'] = $info['pic_cover'];
  295. $data[$k]['name'] = $info['name'];
  296. }
  297. }
  298. if ($v['type'] == 10) {
  299. $palaces = Dever::array_decode($v['palaces']);
  300. if (isset($palaces[0])) {
  301. $data[$k]['pic'] = $palaces[0]['pic'];
  302. }
  303. }
  304. if ($v['type'] == 21) {
  305. if ($data[$k]['talk_pic']) {
  306. $data[$k]['pic'] = $data[$k]['talk_pic'];
  307. } else {
  308. $talk = Dever::array_decode($v['talk']);
  309. if ($talk) {
  310. foreach ($talk as $tk => $tv) {
  311. if ($tv['pic']) {
  312. $data[$k]['pic'] = $tv['pic'];
  313. break;
  314. }
  315. }
  316. }
  317. }
  318. }
  319. $data[$k]['typename'] = $type[$v['type']];
  320. /*
  321. if ($v['type'] == 1) {
  322. $data[$k]['text'] = $this->text($database, $v['id'], $where['info_id']);
  323. } else {
  324. $data[$k]['text'] = '';
  325. }
  326. */
  327. $data[$k]['text'] = '';
  328. $link = $database->url('edit', $v['id']) . '&search_option_info_id=' . $where['info_id'];
  329. $data[$k]['edit'] = "fastEdit($(this), '".$link."', '编辑内页', '', 1)";
  330. $data[$k]['editurl'] = $link;
  331. $data[$k]['delete'] = $database->url('delete', $v['id']);
  332. }
  333. }
  334. return $data;
  335. }
  336. private function text_name($link, $content_id, $info_id, $location, $name)
  337. {
  338. $where['info_id'] = $info_id;
  339. $where['content_id'] = $content_id;
  340. $where['location'] = $location;
  341. $info = Dever::db('journal/content_text')->one($where);
  342. $link .= '&search_option_info_id=' . $info_id. '&search_option_content_id=' . $content_id.'&table=content_text&search_option_location='.$location;
  343. if ($info) {
  344. $link .= '&where_id=' . $info['id'];
  345. }
  346. $html = '<a style="cursor:pointer;" href="javascript:;" onclick="fastEdit($(this), \''.$link.'\', \'编辑'.$name.'文字\', \'\')">'.$name.'</a>';
  347. return $html;
  348. }
  349. public function text($database, $content_id, $info_id)
  350. {
  351. $link = $database->url('edit');
  352. $location = Dever::db('journal/content_text')->config['location'];
  353. $html = '<table class="layui-table"><tbody><tr>';
  354. $i = 0;
  355. foreach ($location as $k => $v) {
  356. $name = $this->text_name($link, $content_id, $info_id, $k, $v);
  357. $html .= '<td>'.$name.'</td>';
  358. if ($i == 2 || $i == 5) {
  359. $html .= '</tr><tr>';
  360. }
  361. $i++;
  362. }
  363. $html .= '</tr></tbody></table>';
  364. return $html;
  365. }
  366. public function updateJournalContent_api()
  367. {
  368. $data = Dever::input('data');
  369. if ($data) {
  370. $data = explode(',', str_replace('data-', '', $data));
  371. foreach ($data as $k => $v) {
  372. $k = $k + 1;
  373. $where['where_id'] = $v;
  374. $where['reorder'] = $k;
  375. Dever::db('journal/content')->update($where);
  376. }
  377. }
  378. return $data;
  379. }
  380. public function addContent($id, $name, $data)
  381. {
  382. # 获取最新的reorder
  383. $info_id = Dever::param('info_id', $data);
  384. $data = Dever::db('journal/content')->getAllByReorder(array('info_id' => $info_id));
  385. if ($data) {
  386. $update['where_id'] = $id;
  387. $update['reorder'] = $data['reorder'] + 1;
  388. Dever::db('journal/content')->update($update);
  389. }
  390. }
  391. public function getName($id)
  392. {
  393. $info = Dever::db('journal/buy_num')->one($id);
  394. if ($info && $info['name']) {
  395. return $info['name'];
  396. } else {
  397. return '购买' . $info['num'] . '本';
  398. }
  399. }
  400. public function getPrice($id)
  401. {
  402. $info = Dever::db('journal/buy_num')->one($id);
  403. $journal = Dever::db('journal/info')->one($info['info_id']);
  404. if ($info && $info['price']) {
  405. return $info['price'];
  406. } else {
  407. return $info['num'] * $journal['cash'] . '元';
  408. }
  409. }
  410. public function mobileTemplate_api()
  411. {
  412. $host = 'http://' . $_SERVER['HTTP_HOST'] . '/wonderful/';
  413. $file = $host . 'doc/mobile.xlsx';
  414. Dever::location($file);
  415. }
  416. public function setJournalCache($id, $name, $param)
  417. {
  418. Dever::load('act/order')->setCache($id, 1);
  419. }
  420. public function setBuyCache($id, $name, $param)
  421. {
  422. Dever::load('act/order')->setCache($id, 2);
  423. }
  424. public function setActiveCache($id, $name, $param)
  425. {
  426. Dever::load('act/order')->setCache($id, 3);
  427. }
  428. public function setStarCache($id, $name, $param)
  429. {
  430. Dever::load('act/order')->setCache($id, 4);
  431. }
  432. # 获取明星订阅本数
  433. public function starDing($id)
  434. {
  435. $data = Dever::db('journal/star')->one($id);
  436. $data = Dever::load('journal/api')->starDing($data);
  437. $num_ding = $data['num_ding'];
  438. $num_add_ding = $data['num_add_ding'];
  439. $num_ratio_ding = $data['num_ratio_ding'];
  440. $buy_num = $data['buy_num'];
  441. $html = '订阅本数:('.$buy_num.'+'.$num_add_ding.')*'.$num_ratio_ding.'='.$num_ding;
  442. return $html;
  443. }
  444. /**
  445. * 导入用户
  446. *
  447. * @return mixed
  448. */
  449. public function mobileImport($id, $name, $param)
  450. {
  451. $file = Dever::param('file', $param);
  452. if ($file) {
  453. $file = str_replace('wonderful', 'upload', Dever::local($file));
  454. $file = str_replace('https://api.huoxingkandiqiu.com/', '/www/', $file);
  455. //$file = '/www/upload/data/upload/4/2019/04/11/f730437f0b5764790baed3c96c5264b2.xlsx';
  456. $data = Dever::excelImport($file);
  457. if ($data) {
  458. foreach ($data as $k => $v) {
  459. if ($k > 1) {
  460. if (isset($v['A']) && isset($v['B'])) {
  461. if ($v['A']) {
  462. $name = $v['A'];
  463. }
  464. $journal = Dever::db('journal/info')->one(array('name' => $name));
  465. if ($journal) {
  466. $info = Dever::db('journal/mobile')->one(array('product_id' => $journal['id'], 'mobile' => $v['B']));
  467. if (!$info) {
  468. Dever::db('journal/mobile')->insert(array('product_id' => $journal['id'], 'mobile' => $v['B']));
  469. }
  470. }
  471. }
  472. }
  473. }
  474. }
  475. }
  476. }
  477. }