Manage.php 19 KB

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