Manage.php 14 KB

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