Manage.php 9.5 KB

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