Manage.php 16 KB

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