Manage.php 18 KB

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