AuthorcenterController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. <?php
  2. /**
  3. * 短视频分类
  4. */
  5. namespace app\admin\controller;
  6. use cmf\controller\AdminBaseController;
  7. use think\facade\Db;
  8. use think\db\Query;
  9. class AuthorcenterController extends AdminbaseController {
  10. private function getClassList($k=''){
  11. $key='authorCenterClass';
  12. $class_list = getcaches($key);
  13. if(!$class_list){
  14. $class_list= Db::name("author_center_class")
  15. ->field('id,title,title_en')
  16. ->where("status=1")
  17. ->order('orderno asc')
  18. ->select();
  19. setcaches($key,$class_list);
  20. }
  21. if($k==''){
  22. return $class_list;
  23. }
  24. return isset($class_list[$k]) ? $class_list[$k]: '';
  25. }
  26. /*视频分类列表*/
  27. public function classlist(){
  28. $video_model=Db::name("author_center_class");
  29. $lists = $video_model
  30. ->where(function(Query $query){
  31. $data = $this->request->param();
  32. $keyword=isset($data['keyword']) ? $data['keyword']: '';
  33. if(!empty($keyword)){
  34. $query->where('title', 'like', "%$keyword%");
  35. }
  36. })
  37. ->order("orderno asc")
  38. ->paginate(20);
  39. //分页-->筛选条件参数
  40. $data = $this->request->param();
  41. $lists->appends($data);
  42. // 获取分页显示
  43. $page = $lists->render();
  44. $this->assign('lists', $lists);
  45. $this->assign("page", $page);
  46. return $this->fetch();
  47. }
  48. //排序
  49. public function listordersset() {
  50. $ids=$this->request->param('listorders');
  51. foreach ($ids as $key => $r) {
  52. $data['orderno'] = $r;
  53. Db::name("author_center_class")->where(array('id' => $key))->update($data);
  54. }
  55. $status = true;
  56. if ($status) {
  57. $this->resetCache();
  58. $this->success("排序更新成功!");
  59. } else {
  60. $this->error("排序更新失败!");
  61. }
  62. }
  63. public function resetCache(){
  64. $key='authorCenterClass';
  65. $rules= Db::name("author_center_class")
  66. ->field('id,title')
  67. ->where("status=1")
  68. ->order('orderno asc')
  69. ->select();
  70. setcaches($key,$rules);
  71. return 1;
  72. }
  73. public function delclass(){
  74. $id=$this->request->param('id',0,'intval');
  75. if($id){
  76. $result=Db::name("author_center_class")->where(["id"=>$id])->delete();
  77. if($result){
  78. $this->resetCache();
  79. $this->success('删除成功');
  80. }else{
  81. $this->error('删除失败');
  82. }
  83. }else{
  84. $this->error('数据传入失败!');
  85. }
  86. return $this->fetch();
  87. }
  88. public function addclass(){
  89. return $this->fetch();
  90. }
  91. public function addclass_post(){
  92. if($this->request->isPost()){
  93. $data=$this->request->param();
  94. $data['addtime']=time();
  95. $title=$data['title'];
  96. if($title==""){
  97. $this->error("请填写分类标题");
  98. }
  99. //判断标题是否存在
  100. $info=Db::name("author_center_class")->where("title='{$title}'")->find();
  101. if($info){
  102. $this->error("分类标题已经存在");
  103. }
  104. $result=Db::name("author_center_class")->insert($data);
  105. if($result){
  106. $this->resetCache();
  107. $this->success('添加成功','admin/authorcenter/classlist');
  108. }else{
  109. $this->error('添加失败');
  110. }
  111. }
  112. }
  113. public function editclass(){
  114. $id=$this->request->param('id',0,'intval');
  115. if($id){
  116. $info=Db::name("author_center_class")->where("id={$id}")->find();
  117. $this->assign('info', $info);
  118. }else{
  119. $this->error('数据传入失败!');
  120. }
  121. return $this->fetch();
  122. }
  123. public function editclass_post(){
  124. if($this->request->isPost()){
  125. $data=$this->request->param();
  126. $id=$data['id'];
  127. $title=trim($data['title']);
  128. if($title==""){
  129. $this->error("请填写分类标题");
  130. }
  131. $data['title']=$title;
  132. //判断名称是否存在
  133. $info=Db::name("author_center_class")->where("id !={$id} and title='{$title}'")->find();
  134. if($info){
  135. $this->error("分类标题已经存在");
  136. }
  137. $result=Db::name("author_center_class")->update($data);
  138. if($result!==false){
  139. $this->resetCache();
  140. $this->success('修改成功');
  141. }else{
  142. $this->error('修改失败');
  143. }
  144. }
  145. }
  146. /**
  147. * 添加活动
  148. * @return [type] [description]
  149. */
  150. public function addactive(){
  151. $class_list = $this->getClassList();
  152. $this->assign('class_list',$class_list);
  153. return $this->fetch();
  154. }
  155. /**
  156. * 添加活动保存
  157. * @return [type] [description]
  158. */
  159. public function addactive_post(){
  160. if($this->request->isPost()) {
  161. $data=$this->request->param();
  162. if($data['title']==''){
  163. $this->error("请填写活动标题");
  164. }
  165. if($data['thumb']==''){
  166. $this->error("请上传活动封面");
  167. }
  168. if($data['starttime']==''){
  169. $this->error("请选择活动开始时间");
  170. }
  171. if($data['endtime']==''){
  172. $this->error("请选择活动结束时间");
  173. }
  174. $starttime=strtotime($data['starttime']);
  175. $endtime=strtotime($data['endtime']);
  176. if($endtime < $starttime){
  177. $this->error("活动结束时间必须晚于活动开始时间");
  178. }
  179. $data['starttime']=$starttime;
  180. $data['endtime']=$endtime;
  181. if($data['draft_starttime']==''){
  182. $this->error("请选择投稿开始时间");
  183. }
  184. if($data['draft_endtime']==''){
  185. $this->error("请选择投稿结束时间");
  186. }
  187. $draft_starttime=strtotime($data['draft_starttime']);
  188. $draft_endtime=strtotime($data['draft_endtime']);
  189. if($draft_endtime<$draft_starttime){
  190. $this->error("投稿结束时间必须晚于投稿开始时间");
  191. }
  192. $data['draft_starttime']=$draft_starttime;
  193. $data['draft_endtime']=$draft_endtime;
  194. if($draft_starttime < $starttime){
  195. $this->error("投稿开始时间必须晚于活动开始时间");
  196. }
  197. if($draft_endtime > $endtime){
  198. $this->error("投稿结束时间必须早于活动结束时间");
  199. }
  200. if($data['playway']==''){
  201. $this->error("请填写活动玩法");
  202. }
  203. if(count($data['subject'])==1 && $data['subject'][0]==''){
  204. $this->error("请填写关联话题");
  205. }
  206. if($data['reward']==''){
  207. $this->error("请填写活动奖励");
  208. }
  209. $subject_arr = $data['subject'];
  210. $new_arr=[];
  211. foreach ($subject_arr as $k => $v) {
  212. if($v !=''){
  213. $new_arr[]=$v;
  214. }
  215. }
  216. $data['subject'] = json_encode($new_arr);
  217. $data['addtime']=time();
  218. $res = Db::name("author_center_activity")->insert($data);
  219. if($res==false){
  220. $this->error("活动添加失败");
  221. }
  222. $this->success("活动添加成功");
  223. }
  224. }
  225. /**
  226. * 活动列表
  227. * @return array 活动列表
  228. */
  229. public function activelist(){
  230. $data = $this->request->param();
  231. $map=[];
  232. $classid = isset($data['classid']) ? $data['classid']:'';
  233. if($classid){
  234. $map[]=['classid','=',$classid];
  235. }
  236. $status = isset($data['status']) ? $data['status']:'';
  237. if($status){
  238. $map[]=['status','=',$status];
  239. }
  240. $starttime=isset($data['starttime']) ? $data['starttime']: '';
  241. $endtime=isset($data['endtime']) ? $data['endtime']: '';
  242. if($starttime!=""){
  243. $map[]=['starttime','>=',strtotime($starttime)];
  244. }
  245. if($endtime!=""){
  246. $map[]=['endtime','<=',strtotime($endtime)];
  247. }
  248. $title = isset($data['title']) ? $data['title']:'';
  249. if($title){
  250. $map[]=['title','like',"%".$title."%"];
  251. }
  252. /*var_dump($map);
  253. die;*/
  254. $lists = DB::name("author_center_activity")
  255. ->where($map)
  256. ->order('id desc')
  257. ->paginate(20);
  258. $lists->each(function($v,$k){
  259. $class_info= Db::name("author_center_class")
  260. ->field('id,title')
  261. ->where(['id'=>$v['classid']])
  262. ->find();
  263. if(!empty($class_info)){
  264. $v['class_name']=$class_info['title'];
  265. }else{
  266. $v['class_name']='';
  267. }
  268. $subject_arr = json_decode($v['subject'],true);
  269. $v['subject_str'] = '#'.implode('#',$subject_arr);
  270. if(!$v['status']){
  271. $v['status_name']='不显示';
  272. }else{
  273. $v['status_name']='显示';
  274. }
  275. return $v;
  276. });
  277. $lists->appends($data);
  278. $page = $lists->render();
  279. $this->assign('lists', $lists);
  280. $this->assign("page", $page);
  281. $class_list = $this->getClassList();
  282. $this->assign('class_list',$class_list);
  283. return $this->fetch();
  284. }
  285. /**
  286. * 修改活动
  287. * @return [type] [description]
  288. */
  289. public function editactive(){
  290. $id = $this->request->param('id', 0, 'intval');
  291. $data=Db::name('author_center_activity')
  292. ->where("id={$id}")
  293. ->find();
  294. if(!$data){
  295. $this->error("信息错误");
  296. }
  297. $subject_arr = json_decode($data['subject'],true);
  298. $data['subject'] = $subject_arr[0];
  299. unset($subject_arr[0]);
  300. $class_list = $this->getClassList();
  301. $this->assign('class_list',$class_list);
  302. $this->assign('data', $data);
  303. $this->assign('subject_arr', $subject_arr);
  304. return $this->fetch();
  305. }
  306. /**
  307. * 活动编辑提交
  308. * @return [type] [description]
  309. */
  310. public function editactive_post(){
  311. if ($this->request->isPost()) {
  312. $data = $this->request->param();
  313. if($data['title']==''){
  314. $this->error("请填写活动标题");
  315. }
  316. if($data['thumb']==''){
  317. $this->error("请上传活动封面");
  318. }
  319. if($data['starttime']==''){
  320. $this->error("请选择活动开始时间");
  321. }
  322. if($data['endtime']==''){
  323. $this->error("请选择活动结束时间");
  324. }
  325. $starttime=strtotime($data['starttime']);
  326. $endtime=strtotime($data['endtime']);
  327. if($endtime < $starttime){
  328. $this->error("活动结束时间必须晚于活动开始时间");
  329. }
  330. $data['starttime']=$starttime;
  331. $data['endtime']=$endtime;
  332. if($data['draft_starttime']==''){
  333. $this->error("请选择投稿开始时间");
  334. }
  335. if($data['draft_endtime']==''){
  336. $this->error("请选择投稿结束时间");
  337. }
  338. $draft_starttime=strtotime($data['draft_starttime']);
  339. $draft_endtime=strtotime($data['draft_endtime']);
  340. if($draft_endtime<$draft_starttime){
  341. $this->error("投稿结束时间必须晚于投稿开始时间");
  342. }
  343. $data['draft_starttime']=$draft_starttime;
  344. $data['draft_endtime']=$draft_endtime;
  345. if($draft_starttime < $starttime){
  346. $this->error("投稿开始时间必须晚于活动开始时间");
  347. }
  348. if($draft_endtime > $endtime){
  349. $this->error("投稿结束时间必须早于活动结束时间");
  350. }
  351. if($data['playway']==''){
  352. $this->error("请填写活动玩法");
  353. }
  354. if(count($data['subject'])==1 && $data['subject'][0]==''){
  355. $this->error("请填写关联话题");
  356. }
  357. if($data['reward']==''){
  358. $this->error("请填写活动奖励");
  359. }
  360. $subject_arr = $data['subject'];
  361. $new_arr=[];
  362. foreach ($subject_arr as $k => $v) {
  363. if($v !=''){
  364. $new_arr[]=$v;
  365. }
  366. }
  367. $data['subject'] = json_encode($new_arr);
  368. $data['uptime']=time();
  369. $res = Db::name("author_center_activity")->update($data);
  370. if($res==false){
  371. $this->error("活动修改失败");
  372. }
  373. $this->success("活动修改成功");
  374. }
  375. }
  376. /**
  377. * 删除活动
  378. * @return [type] [description]
  379. */
  380. public function delactive(){
  381. $id = $this->request->param('id', 0, 'intval');
  382. if($id){
  383. $result=DB::name("author_center_activity")->delete($id);
  384. if($result){
  385. Db::name("author_center_activity_collect")->where(['activeid'=>$id])->delete();
  386. $this->success('删除成功');
  387. }else{
  388. $this->error('删除失败');
  389. }
  390. }else{
  391. $this->error('数据传入失败!');
  392. }
  393. }
  394. }