Manage.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. } else {
  22. $table['支付方式'] = '兑换小刊';
  23. $table['兑换码'] = $info['code'];
  24. }
  25. //$table['购买数量'] = $info['num'];
  26. if ($info['source_uid'] && $info['source_uid'] != $info['uid']) {
  27. $user = Dever::db('passport/user')->one($info['source_uid']);
  28. $table['邀请人'] = $user['username'];
  29. }
  30. return Dever::table($table);
  31. }
  32. public function showOrderStatus($id)
  33. {
  34. $info = Dever::db('journal/order')->one($id);
  35. if ($info) {
  36. if ($info['status'] == 1) {
  37. #return '*已支付';
  38. return '待支付';
  39. } elseif ($info['status'] == 2) {
  40. return '已支付';
  41. } elseif ($info['status'] == 3) {
  42. return '支付失败';
  43. } elseif ($info['status'] == 5) {
  44. $table['状态'] = '已退款';
  45. $manage = Dever::db('manage/admin')->one($info['tk_admin']);
  46. $table['备注'] = $info['tk_desc'];
  47. $table['截图'] = '<a href="'.$info['tk_pic'].'" target="_blank"><img src="'.$info['tk_pic'].'" style="width:150px" /></a>';
  48. //$table['退款时间'] = date('Y-m-d H:i:s', $info['tk_time']);
  49. $table['操作人'] = $manage['username'];
  50. return Dever::table($table);
  51. }
  52. }
  53. }
  54. private function search($table = 'content/article')
  55. {
  56. $keyword = Dever::input('keyword');
  57. $yes = Dever::input('yes');
  58. $where = array();
  59. $cate = Dever::input('cate');
  60. if ($cate) {
  61. $where['cate_id'] = $cate;
  62. }
  63. if ($yes) {
  64. $yes = Dever::db($table)->search(array('ids' => $yes));
  65. }
  66. if (!$keyword) {
  67. $where['limit'] = '0,50';
  68. $data = Dever::db($table)->search($where);
  69. } else {
  70. $where['name'] = $keyword;
  71. $data = Dever::db($table)->search($where);
  72. }
  73. $result = array();
  74. if ($yes) {
  75. foreach ($yes as $k => $v) {
  76. if (isset($data[$k])) {
  77. unset($data[$k]);
  78. }
  79. $yes[$k]['selected'] = 'selected';
  80. }
  81. $data = $yes + $data;
  82. $data = array_merge($data, array());
  83. } else {
  84. $data = array_merge($data, array());
  85. }
  86. if (!$data) {
  87. Dever::alert('暂无数据');
  88. }
  89. return $data;
  90. }
  91. # 搜索文章
  92. public function search_article_api()
  93. {
  94. return $this->search('content/article');
  95. }
  96. # 搜索视频
  97. public function search_vod_api()
  98. {
  99. return $this->search('video/vod');
  100. }
  101. # 搜索直播
  102. public function search_live_api()
  103. {
  104. return $this->search('video/live');
  105. }
  106. # 搜索小刊
  107. public function search_journal_api()
  108. {
  109. return $this->search('journal/info');
  110. }
  111. # 搜索专题
  112. public function search_feature_api()
  113. {
  114. return $this->search('feature/info');
  115. }
  116. # 搜索小程序
  117. public function search_applet_api()
  118. {
  119. return $this->search('content/applet');
  120. }
  121. # 按照分类搜索小刊
  122. public function search_cate_journal_api()
  123. {
  124. $level_num = Dever::input('level_num');
  125. $level_id = Dever::input('level_id');
  126. $auth = Dever::tops();
  127. $where = array();
  128. if ($level_num == 1) {
  129. $default = array
  130. (
  131. 'value' => -1,
  132. 'name' => '选择分类',
  133. );
  134. if ($auth) {
  135. $where['ids'] = $auth;
  136. }
  137. $data = Dever::db('journal/cate')->getIds($where);
  138. } elseif ($level_num == 2 && $level_id > 0) {
  139. $default = array
  140. (
  141. 'value' => -1,
  142. 'name' => '选择小刊',
  143. );
  144. if ($level_id > 0) {
  145. $where['cate_id'] = $level_id;
  146. } elseif ($auth) {
  147. $where['cate_id'] = $auth;
  148. }
  149. $data = Dever::db('journal/info')->getIds($where);
  150. } else {
  151. return array();
  152. }
  153. array_unshift($data, $default);
  154. $result['level_total'] = 2;
  155. $result['list'] = $data;
  156. return $result;
  157. }
  158. # 显示杂志内页
  159. public function journalContent()
  160. {
  161. $where['info_id'] = Dever::input('search_option_info_id');
  162. $where['state'] = Dever::input('search_option_state');
  163. $data = Dever::db('journal/content')->all($where);
  164. $database = Dever::load('manage/database');
  165. $type = Dever::db('journal/content')->config['gettype'];
  166. if ($data) {
  167. foreach ($data as $k => $v) {
  168. $data[$k]['height'] = 'height: 154px;';
  169. $data[$k]['info_height'] = 'height: auto;';
  170. if ($v['type'] > 2) {
  171. $data[$k]['height'] = 'height: 104px;';
  172. $data[$k]['info_height'] = 'height: 47px;';
  173. }
  174. if ($v['type'] <= 2) {
  175. $data[$k]['name'] = '';
  176. } elseif ($v['type'] == 3) {
  177. $data[$k]['pic'] = $v['focus'];
  178. }
  179. if ($v['type'] == 4 || $v['type'] == 5 || $v['type'] == 6) {
  180. $data[$k]['name'] = '';
  181. $data[$k]['pic'] = $v['cover'];
  182. }
  183. if ($v['type'] == 11) {
  184. # 图文
  185. $info = Dever::load('content/lib/article')->get($v['article_id']);
  186. if ($info) {
  187. $data[$k]['pic'] = $info['pic_cover'];
  188. $data[$k]['name'] = $info['name'];
  189. }
  190. } elseif ($v['type'] == 12) {
  191. # 视频
  192. $info = Dever::load('video/lib/vod')->get($v['vod_id']);
  193. if ($info) {
  194. $data[$k]['pic'] = $info['pic_cover'];
  195. $data[$k]['name'] = $info['name'];
  196. }
  197. } elseif ($v['type'] == 13) {
  198. # 直播
  199. $info = Dever::load('video/lib/live')->get($v['live_id']);
  200. if ($info) {
  201. $data[$k]['pic'] = $info['pic_cover'];
  202. $data[$k]['name'] = $info['name'];
  203. }
  204. }
  205. $data[$k]['typename'] = $type[$v['type']];
  206. /*
  207. if ($v['type'] == 1) {
  208. $data[$k]['text'] = $this->text($database, $v['id'], $where['info_id']);
  209. } else {
  210. $data[$k]['text'] = '';
  211. }
  212. */
  213. $data[$k]['text'] = '';
  214. $link = $database->url('edit', $v['id']) . '&search_option_info_id=' . $where['info_id'];
  215. $data[$k]['edit'] = "fastEdit($(this), '".$link."', '编辑内页', '', 1)";
  216. $data[$k]['editurl'] = $link;
  217. $data[$k]['delete'] = $database->url('delete', $v['id']);
  218. }
  219. }
  220. return $data;
  221. }
  222. private function text_name($link, $content_id, $info_id, $location, $name)
  223. {
  224. $where['info_id'] = $info_id;
  225. $where['content_id'] = $content_id;
  226. $where['location'] = $location;
  227. $info = Dever::db('journal/content_text')->one($where);
  228. $link .= '&search_option_info_id=' . $info_id. '&search_option_content_id=' . $content_id.'&table=content_text&search_option_location='.$location;
  229. if ($info) {
  230. $link .= '&where_id=' . $info['id'];
  231. }
  232. $html = '<a style="cursor:pointer;" href="javascript:;" onclick="fastEdit($(this), \''.$link.'\', \'编辑'.$name.'文字\', \'\')">'.$name.'</a>';
  233. return $html;
  234. }
  235. public function text($database, $content_id, $info_id)
  236. {
  237. $link = $database->url('edit');
  238. $location = Dever::db('journal/content_text')->config['location'];
  239. $html = '<table class="layui-table"><tbody><tr>';
  240. $i = 0;
  241. foreach ($location as $k => $v) {
  242. $name = $this->text_name($link, $content_id, $info_id, $k, $v);
  243. $html .= '<td>'.$name.'</td>';
  244. if ($i == 2 || $i == 5) {
  245. $html .= '</tr><tr>';
  246. }
  247. $i++;
  248. }
  249. $html .= '</tr></tbody></table>';
  250. return $html;
  251. }
  252. public function updateJournalContent_api()
  253. {
  254. $data = Dever::input('data');
  255. if ($data) {
  256. $data = explode(',', str_replace('data-', '', $data));
  257. foreach ($data as $k => $v) {
  258. $k = $k + 1;
  259. $where['where_id'] = $v;
  260. $where['reorder'] = $k;
  261. Dever::db('journal/content')->update($where);
  262. }
  263. }
  264. return $data;
  265. }
  266. public function addContent($id, $name, $data)
  267. {
  268. # 获取最新的reorder
  269. $info_id = Dever::param('info_id', $data);
  270. $data = Dever::db('journal/content')->getAllByReorder(array('info_id' => $info_id));
  271. if ($data) {
  272. $update['where_id'] = $id;
  273. $update['reorder'] = $data['reorder'] + 1;
  274. Dever::db('journal/content')->update($update);
  275. }
  276. }
  277. public function getName($id)
  278. {
  279. $info = Dever::db('journal/buy_num')->one($id);
  280. if ($info && $info['name']) {
  281. return $info['name'];
  282. } else {
  283. return '购买' . $info['num'] . '本';
  284. }
  285. }
  286. public function getPrice($id)
  287. {
  288. $info = Dever::db('journal/buy_num')->one($id);
  289. $journal = Dever::db('journal/info')->one($info['info_id']);
  290. if ($info && $info['price']) {
  291. return $info['price'];
  292. } else {
  293. return $info['num'] * $journal['cash'] . '元';
  294. }
  295. }
  296. }