Type.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class Type extends Base
  5. {
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. $this->assign('title',lang('admin/type/title'));
  10. }
  11. public function index()
  12. {
  13. $order='type_sort asc';
  14. $where=[];
  15. $res = model('Type')->listData($where,$order,'tree');
  16. $list_count =[];
  17. //视频数量
  18. $tmp = model('Vod')->field('type_id_1,type_id,count(vod_id) as cc')->where($where)->group('type_id_1,type_id')->select();
  19. foreach($tmp as $k=>$v){
  20. $list_count[$v['type_id_1']] += $v['cc'];
  21. $list_count[$v['type_id']] = $v['cc'];
  22. }
  23. //文章数量
  24. $tmp = model('Art')->field('type_id_1,type_id,count(art_id) as cc')->where($where)->group('type_id_1,type_id')->select();
  25. foreach($tmp as $k=>$v){
  26. $list_count[$v['type_id_1']] += $v['cc'];
  27. $list_count[$v['type_id']] = $v['cc'];
  28. }
  29. //演员数量
  30. $tmp = model('Actor')->field('type_id_1,type_id,count(actor_id) as cc')->where($where)->group('type_id_1,type_id')->select();
  31. foreach($tmp as $k=>$v){
  32. $list_count[$v['type_id_1']] += $v['cc'];
  33. $list_count[$v['type_id']] = $v['cc'];
  34. }
  35. //网址数量
  36. $tmp = model('Website')->field('type_id_1,type_id,count(website_id) as cc')->where($where)->group('type_id_1,type_id')->select();
  37. foreach($tmp as $k=>$v){
  38. $list_count[$v['type_id_1']] += $v['cc'];
  39. $list_count[$v['type_id']] = $v['cc'];
  40. }
  41. //漫画数量
  42. $tmp = model('Manga')->field('type_id_1,type_id,count(manga_id) as cc')->where($where)->group('type_id_1,type_id')->select();
  43. foreach($tmp as $k=>$v){
  44. $list_count[$v['type_id_1']] += $v['cc'];
  45. $list_count[$v['type_id']] = $v['cc'];
  46. }
  47. //重新整合
  48. foreach($res['list'] as $k=>$v){
  49. $res['list'][$k]['cc'] = intval($list_count[$v['type_id']]);
  50. foreach($v['child'] as $k2=>$v2){
  51. $res['list'][$k]['child'][$k2]['cc'] = intval($list_count[$v2['type_id']]);
  52. }
  53. }
  54. $this->assign('list',$res['list']);
  55. $this->assign('total',$res['total']);
  56. return $this->fetch('admin@type/index');
  57. }
  58. public function info()
  59. {
  60. if (Request()->isPost()) {
  61. $param = input('post.');
  62. $validate = \think\Loader::validate('Token');
  63. if(!$validate->check($param)){
  64. return $this->error($validate->getError());
  65. }
  66. $res = model('Type')->saveData($param);
  67. if($res['code']>1){
  68. return $this->error($res['msg']);
  69. }
  70. model('Type')->setCache();
  71. return $this->success($res['msg']);
  72. }
  73. $id = input('id');
  74. $pid = input('pid');
  75. $where=[];
  76. $where['type_id'] = ['eq',$id];
  77. $res = model('Type')->infoData($where);
  78. $where=[];
  79. $where['type_id'] = ['eq',$pid];
  80. $resp = model('Type')->infoData($where);
  81. $this->assign('info',$res['info']);
  82. $this->assign('infop',$resp['info']);
  83. $this->assign('pid',$pid);
  84. $where=[];
  85. $where['type_pid'] = ['eq','0'];
  86. $order='type_sort asc';
  87. $parent = model('Type')->listData($where,$order);
  88. $this->assign('parent',$parent['list']);
  89. return $this->fetch('admin@type/info');
  90. }
  91. public function del()
  92. {
  93. $param = input();
  94. $ids = $param['ids'];
  95. if(!empty($ids)){
  96. $where=[];
  97. $where['type_id'] = ['in',$ids];
  98. $res = model('Type')->delData($where);
  99. if($res['code']>1){
  100. return $this->error($res['msg']);
  101. }
  102. return $this->success($res['msg']);
  103. }
  104. return $this->error(lang('param_err'));
  105. }
  106. public function field()
  107. {
  108. $param = input();
  109. $ids = $param['ids'];
  110. $col = $param['col'];
  111. $val = $param['val'];
  112. if(!empty($ids) && in_array($col,['type_status']) && in_array($val,['0','1'])){
  113. $where=[];
  114. $where['type_id'] = ['in',$ids];
  115. $res = model('Type')->fieldData($where,$col,$val);
  116. if($res['code']>1){
  117. return $this->error($res['msg']);
  118. }
  119. return $this->success($res['msg']);
  120. }
  121. return $this->error(lang('param_err'));
  122. }
  123. public function batch()
  124. {
  125. $param = input();
  126. $ids = $param['ids'];
  127. foreach ($ids as $k=>$id) {
  128. $data = [];
  129. $data['type_id'] = intval($id);
  130. $data['type_name'] = $param['type_name_'.$id];
  131. $data['type_sort'] = $param['type_sort_'.$id];
  132. $data['type_en'] = $param['type_en_'.$id];
  133. $data['type_tpl'] = $param['type_tpl_'.$id];
  134. $data['type_tpl_list'] = $param['type_tpl_list_'.$id];
  135. $data['type_tpl_detail'] = $param['type_tpl_detail_'.$id];
  136. if (empty($data['type_name'])) {
  137. $data['type_name'] = lang('unknown');
  138. }
  139. $res = model('Type')->saveData($data);
  140. if($res['code']>1){
  141. return $this->error($res['msg']);
  142. }
  143. }
  144. $this->success($res['msg']);
  145. }
  146. public function extend()
  147. {
  148. $param = input();
  149. if(!empty($param['id'])){
  150. $type_list = model('Type')->getCache('type_list');
  151. $type_info = $type_list[$param['id']];
  152. if(!empty($type_info)){
  153. $type_mid = $type_info['type_mid'];
  154. $type_pid = $type_info['type_pid'];
  155. $type_pinfo = $type_list[$type_pid];
  156. $type_extend = $type_info['type_extend'];
  157. $type_pextend = $type_pinfo['type_extend'];
  158. $config = config('maccms.app');
  159. if($type_mid==2) {
  160. if(empty($type_extend['class']) && !empty($type_pextend['class'])){
  161. $type_extend['class'] = $type_pextend['class'];
  162. }
  163. elseif(empty($type_extend['class']) && !empty($config['art_extend_class'])){
  164. $type_extend['class'] = $config['art_extend_class'];
  165. }
  166. }
  167. else{
  168. if(empty($type_extend['class']) && !empty($type_pextend['class'])){
  169. $type_extend['class'] = $type_pextend['class'];
  170. }
  171. elseif(empty($type_extend['class']) && !empty($config['vod_extend_class'])){
  172. $type_extend['class'] = $config['vod_extend_class'];
  173. }
  174. if(empty($type_extend['state']) && !empty($type_pextend['state'])){
  175. $type_extend['state'] = $type_pextend['state'];
  176. }
  177. elseif(empty($type_extend['state']) && !empty($config['vod_extend_state'])){
  178. $type_extend['state'] = $config['vod_extend_state'];
  179. }
  180. if(empty($type_extend['version']) && !empty($type_pextend['version'])){
  181. $type_extend['version'] = $type_pextend['version'];
  182. }
  183. elseif(empty($type_extend['version']) && !empty($config['vod_extend_version'])){
  184. $type_extend['version'] = $config['vod_extend_version'];
  185. }
  186. if(empty($type_extend['area']) && !empty($type_pextend['area'])){
  187. $type_extend['area'] = $type_pextend['area'];
  188. }
  189. elseif(empty($type_extend['area']) && !empty($config['vod_extend_area'])){
  190. $type_extend['area'] = $config['vod_extend_area'];
  191. }
  192. if(empty($type_extend['lang']) && !empty($type_pextend['lang'])){
  193. $type_extend['lang'] = $type_pextend['lang'];
  194. }
  195. elseif(empty($type_extend['lang']) && !empty($config['vod_extend_lang'])){
  196. $type_extend['lang'] = $config['vod_extend_lang'];
  197. }
  198. if(empty($type_extend['year']) && !empty($type_pextend['year'])){
  199. $type_extend['year'] = $type_pextend['year'];
  200. }
  201. elseif(empty($type_extend['year']) && !empty($config['vod_extend_year'])){
  202. $type_extend['year'] = $config['vod_extend_year'];
  203. }
  204. }
  205. if(!empty($type_extend)){
  206. foreach($type_extend as $key=>$value){
  207. $options = '';
  208. foreach(explode(',',$value) as $option){
  209. $extend[$key][] = $option;
  210. }
  211. }
  212. }
  213. return $this->success('ok',null,$extend);
  214. }
  215. return $this->error(lang('get_info_err'));
  216. }
  217. }
  218. public function move()
  219. {
  220. $param = input();
  221. $ids = $param['ids'];
  222. $val = $param['val'];
  223. if(!empty($ids) && !empty($val)){
  224. $where=[];
  225. $where['type_id'] = ['in',$ids];
  226. $res = model('Type')->moveData($where,$val);
  227. if($res['code']>1){
  228. return $this->error($res['msg']);
  229. }
  230. return $this->success($res['msg']);
  231. }
  232. return $this->error(lang('param_err'));
  233. }
  234. }