Manage.php 11 KB

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