Type.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. foreach($res['list'] as $k=>$v){
  43. $res['list'][$k]['cc'] = intval($list_count[$v['type_id']]);
  44. foreach($v['child'] as $k2=>$v2){
  45. $res['list'][$k]['child'][$k2]['cc'] = intval($list_count[$v2['type_id']]);
  46. }
  47. }
  48. $this->assign('list',$res['list']);
  49. $this->assign('total',$res['total']);
  50. return $this->fetch('admin@type/index');
  51. }
  52. public function info()
  53. {
  54. if (Request()->isPost()) {
  55. $param = input('post.');
  56. $validate = \think\Loader::validate('Token');
  57. if(!$validate->check($param)){
  58. return $this->error($validate->getError());
  59. }
  60. $res = model('Type')->saveData($param);
  61. if($res['code']>1){
  62. return $this->error($res['msg']);
  63. }
  64. model('Type')->setCache();
  65. return $this->success($res['msg']);
  66. }
  67. $id = input('id');
  68. $pid = input('pid');
  69. $where=[];
  70. $where['type_id'] = ['eq',$id];
  71. $res = model('Type')->infoData($where);
  72. $where=[];
  73. $where['type_id'] = ['eq',$pid];
  74. $resp = model('Type')->infoData($where);
  75. $this->assign('info',$res['info']);
  76. $this->assign('infop',$resp['info']);
  77. $this->assign('pid',$pid);
  78. $where=[];
  79. $where['type_pid'] = ['eq','0'];
  80. $order='type_sort asc';
  81. $parent = model('Type')->listData($where,$order);
  82. $this->assign('parent',$parent['list']);
  83. return $this->fetch('admin@type/info');
  84. }
  85. public function del()
  86. {
  87. $param = input();
  88. $ids = $param['ids'];
  89. if(!empty($ids)){
  90. $where=[];
  91. $where['type_id'] = ['in',$ids];
  92. $res = model('Type')->delData($where);
  93. if($res['code']>1){
  94. return $this->error($res['msg']);
  95. }
  96. return $this->success($res['msg']);
  97. }
  98. return $this->error(lang('param_err'));
  99. }
  100. public function field()
  101. {
  102. $param = input();
  103. $ids = $param['ids'];
  104. $col = $param['col'];
  105. $val = $param['val'];
  106. if(!empty($ids) && in_array($col,['type_status']) && in_array($val,['0','1'])){
  107. $where=[];
  108. $where['type_id'] = ['in',$ids];
  109. $res = model('Type')->fieldData($where,$col,$val);
  110. if($res['code']>1){
  111. return $this->error($res['msg']);
  112. }
  113. return $this->success($res['msg']);
  114. }
  115. return $this->error(lang('param_err'));
  116. }
  117. public function batch()
  118. {
  119. $param = input();
  120. $ids = $param['ids'];
  121. foreach ($ids as $k=>$id) {
  122. $data = [];
  123. $data['type_id'] = intval($id);
  124. $data['type_name'] = $param['type_name_'.$id];
  125. $data['type_sort'] = $param['type_sort_'.$id];
  126. $data['type_en'] = $param['type_en_'.$id];
  127. $data['type_tpl'] = $param['type_tpl_'.$id];
  128. $data['type_tpl_list'] = $param['type_tpl_list_'.$id];
  129. $data['type_tpl_detail'] = $param['type_tpl_detail_'.$id];
  130. if (empty($data['type_name'])) {
  131. $data['type_name'] = lang('unknown');
  132. }
  133. $res = model('Type')->saveData($data);
  134. if($res['code']>1){
  135. return $this->error($res['msg']);
  136. }
  137. }
  138. $this->success($res['msg']);
  139. }
  140. public function extend()
  141. {
  142. $param = input();
  143. if(!empty($param['id'])){
  144. $type_list = model('Type')->getCache('type_list');
  145. $type_info = $type_list[$param['id']];
  146. if(!empty($type_info)){
  147. $type_mid = $type_info['type_mid'];
  148. $type_pid = $type_info['type_pid'];
  149. $type_pinfo = $type_list[$type_pid];
  150. $type_extend = $type_info['type_extend'];
  151. $type_pextend = $type_pinfo['type_extend'];
  152. $config = config('maccms.app');
  153. if($type_mid==2) {
  154. if(empty($type_extend['class']) && !empty($type_pextend['class'])){
  155. $type_extend['class'] = $type_pextend['class'];
  156. }
  157. elseif(empty($type_extend['class']) && !empty($config['art_extend_class'])){
  158. $type_extend['class'] = $config['art_extend_class'];
  159. }
  160. }
  161. else{
  162. if(empty($type_extend['class']) && !empty($type_pextend['class'])){
  163. $type_extend['class'] = $type_pextend['class'];
  164. }
  165. elseif(empty($type_extend['class']) && !empty($config['vod_extend_class'])){
  166. $type_extend['class'] = $config['vod_extend_class'];
  167. }
  168. if(empty($type_extend['state']) && !empty($type_pextend['state'])){
  169. $type_extend['state'] = $type_pextend['state'];
  170. }
  171. elseif(empty($type_extend['state']) && !empty($config['vod_extend_state'])){
  172. $type_extend['state'] = $config['vod_extend_state'];
  173. }
  174. if(empty($type_extend['version']) && !empty($type_pextend['version'])){
  175. $type_extend['version'] = $type_pextend['version'];
  176. }
  177. elseif(empty($type_extend['version']) && !empty($config['vod_extend_version'])){
  178. $type_extend['version'] = $config['vod_extend_version'];
  179. }
  180. if(empty($type_extend['area']) && !empty($type_pextend['area'])){
  181. $type_extend['area'] = $type_pextend['area'];
  182. }
  183. elseif(empty($type_extend['area']) && !empty($config['vod_extend_area'])){
  184. $type_extend['area'] = $config['vod_extend_area'];
  185. }
  186. if(empty($type_extend['lang']) && !empty($type_pextend['lang'])){
  187. $type_extend['lang'] = $type_pextend['lang'];
  188. }
  189. elseif(empty($type_extend['lang']) && !empty($config['vod_extend_lang'])){
  190. $type_extend['lang'] = $config['vod_extend_lang'];
  191. }
  192. if(empty($type_extend['year']) && !empty($type_pextend['year'])){
  193. $type_extend['year'] = $type_pextend['year'];
  194. }
  195. elseif(empty($type_extend['year']) && !empty($config['vod_extend_year'])){
  196. $type_extend['year'] = $config['vod_extend_year'];
  197. }
  198. }
  199. if(!empty($type_extend)){
  200. foreach($type_extend as $key=>$value){
  201. $options = '';
  202. foreach(explode(',',$value) as $option){
  203. $extend[$key][] = $option;
  204. }
  205. }
  206. }
  207. return $this->success('ok',null,$extend);
  208. }
  209. return $this->error(lang('get_info_err'));
  210. }
  211. }
  212. public function move()
  213. {
  214. $param = input();
  215. $ids = $param['ids'];
  216. $val = $param['val'];
  217. if(!empty($ids) && !empty($val)){
  218. $where=[];
  219. $where['type_id'] = ['in',$ids];
  220. $res = model('Type')->moveData($where,$val);
  221. if($res['code']>1){
  222. return $this->error($res['msg']);
  223. }
  224. return $this->success($res['msg']);
  225. }
  226. return $this->error(lang('param_err'));
  227. }
  228. }