Manage.php 17 KB

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