| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // | Author: 小夏 < 449134904@qq.com>
- // +----------------------------------------------------------------------
- namespace app\admin\controller;
- use app\portal\model\PortalPostModel;
- use cmf\controller\AdminBaseController;
- use think\Db;
- use think\db\Query;
- /**
- * Class PicController
- */
- class PicController extends AdminBaseController
- {
- /**
- * 列表
- */
- public function index(){
- /**搜索条件**/
- $params = input();
- $params['type'] = isset($params['type'])? $params['type'] : 0;
- $params['keyword'] = isset($params['keyword'])? $params['keyword'] : '';
- $datas = PortalPostModel::alias('p')
- ->leftJoin('sg_user u','u.id=p.user_id')
- ->where(['p.post_status'=>1,'p.post_type'=>3])
- ->where(function (Query $query) use ($params) {
- $keyword = isset($params['keyword'])? $params['keyword'] : '';
- if ($keyword) {
- $query->where('p.post_title', 'like', "%$keyword%");
- }
- $type = isset($params['type'])? $params['type'] : 0;
- if($type){
- $query->where('p.type', $type);
- }
- })
- ->field('p.id,p.post_title,p.post_type,p.type,p.user_id,p.update_time,p.create_time,p.published_time,p.post_excerpt,p.thumbnail,p.albums,p.post_status,u.user_nickname')
- ->order("p.is_top DESC,p.published_time DESC")
- ->paginate(10,false,['query'=>request()->param()])
- ->each(function($item,$key){
- $albums = isset($item['albums']) && $item['albums']? explode(',', $item['albums']) : [];
- foreach ($albums as &$v){
- $v = $v? cmf_get_image_preview_url($v) : '';
- }
- unset($v);
- $item['albums_list'] = $albums;
- return $item;
- });
- // 获取分页显示
- $page = $datas->render();
- $this->assign("params", $params);
- $this->assign("page", $page);
- $this->assign("datas", $datas);
- return $this->fetch();
- }
- /**
- * 删除
- */
- public function delete()
- {
- $param = $this->request->param();
- if (isset($param['ids']) && isset($param["yes"])) {
- $ids = $this->request->param('ids/a');
- PortalPostModel::where('id', 'in', $ids)->update(['post_status' => 2]);
- PortalPostModel::where('post_status', 2)
- ->where('update_time','<', time() - 3 * 24 * 3600)
- ->delete();
- $this->success("删除成功!", '');
- }
- }
- //增加
- public function add()
- {
- return $this->fetch('add');
- }
- /**
- * 添加提交
- */
- public function addPost(){
- if($this->request->isPost()){
- $data = $this->request->param();
- $result = $this->validate($data['post'], 'PortalPost');
- if ($result !== true) {
- $this->error($result);
- }
- $post = isset($data['post'])? $data['post'] : [];
- if (empty($post['post_title'])) {
- $this->error('标题不为空!');
- }
- $albums = isset($data['photo_urls']) && $data['photo_urls']? join(',', $data['photo_urls']) : '';
- if(count($data['photo_urls']) > 6){
- $this->error('相册最多6张图!');
- }
- if($albums){
- $post['albums'] = $albums;
- }
- $post['published_time'] = isset($post['published_time']) && $post['published_time']? strtotime($post['published_time']) : time();
- $post['create_time'] = time();
- $post['user_id'] = cmf_get_current_admin_id();
- $post['post_type'] = 3;
- PortalPostModel::insertGetId($post);
- $this->success("添加成功!",url("Pic/index"));
- }
- }
- /**
- * 编辑
- */
- public function edit(){
- $id = $this->request->param('id', 0, 'intval');
- $model = new PortalPostModel();
- $info = $model->get($id);
- $info['albums'] = isset($info['albums']) && $info['albums']? explode(',', $info['albums']) : [];
- $this->assign('info', $info);
- return $this->fetch();
- }
- /**
- * 编辑提交
- */
- public function editPost()
- {
- $data = $this->request->param();
- $result = $this->validate($data['post'], 'PortalPost');
- if ($result !== true) {
- $this->error($result);
- }
- $post = isset($data['post'])? $data['post'] : [];
- if (empty($post['post_title'])) {
- $this->error('标题不为空!');
- }
- $albums = isset($data['photo_urls']) && $data['photo_urls']? join(',', $data['photo_urls']) : '';
- if(count($data['photo_urls']) > 6){
- $this->error('相册最多6张图!');
- }
- if($albums){
- $post['albums'] = $albums;
- }
- $post['published_time'] = isset($post['published_time']) && $post['published_time']? strtotime($post['published_time']) : time();
- $post['post_type'] = 3;
- PortalPostModel::where(['id'=>$post['id']])->update($post);
- $this->success("保存成功!", url("Pic/index"));
- }
-
- }
|