Manage.php 17 KB

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