Manage.php 17 KB

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