title = '列表'; $where = []; $where[] = ['f.is_deleted','=',0]; if($title = input('title')) $where[] = ['f.title','like','%'.$title.'%']; $query = $this->_query($this->table)->alias('f') ->field('f.*') ->where($where) ->order('sort desc,f.id desc')->page(); } /** * 添加 * @auth true * @menu true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function add() { $this->title = '添加'; $this->_form($this->table, 'form'); } /** * 编辑 * @auth true * @menu true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function edit() { $this->title = '编辑'; $this->_form($this->table, 'form'); } /** * 删除 * @auth true * @throws \think\Exception * @throws \think\exception\PDOException */ public function del() { \app\common\model\Press::where('id',input('id'))->update(['is_deleted'=>1]); \app\common\model\Press::esAdd(input('id')); \app\common\model\TopSearch::saveData(input('id'),'press'); $this->success('已删除!'); } /** * 删除 * @auth true * @throws \think\Exception * @throws \think\exception\PDOException */ public function remove() { $ids = input('id'); foreach (explode(',',$ids) as $id) { \app\common\model\Press::where('id',$id)->update(['is_deleted'=>1]); \app\common\model\Press::esAdd($id); \app\common\model\TopSearch::saveData($id,'press'); } $this->success('已删除!'); } /** * 启用 * @auth true * @menu true * @throws \think\Exception * @throws \think\exception\PDOException */ public function enable() { \app\common\model\Press::where('id',input('id'))->update(['status'=>1]); \app\common\model\Press::esAdd(input('id')); $this->success('已上架!'); } /** * 禁用 * @auth true * @menu true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function forbidden() { \app\common\model\Press::where('id',input('id'))->update(['status'=>0]); \app\common\model\Press::esAdd(input('id')); \app\common\model\TopSearch::saveData(input('id'),'press'); $this->success('已下架!'); } protected function _form_filter(&$data){ // 文章列表 $this->article_list =\app\common\model\ArticleIntro::with('itemChildren') ->field('id,title') ->where(['is_deleted'=>0])->order('id asc') ->select()->toArray(); // 视频 $this->video_list = \app\common\model\VideoIntro::with('videoArr') ->where(['is_deleted'=>0])->order('id desc') ->select()->toArray(); // 资料 $this->datum_list = DatumIntro::with('urlArr') ->where(['is_deleted'=>0])->order('id desc') ->select()->toArray(); $this->supplier = Supplier::with('goodsList') ->where(['is_deleted'=>0]) ->where('status',1) ->select()->toArray(); $this->supplier_goods = SupplierGoods::getSupplierGoodsList($this->request->action() == 'add' ? ['s.is_deleted'=>0,'g.is_deleted'=>0]: ['s.is_deleted'=>0,'g.is_deleted'=>0]); if($this->request->isPost()) { if(empty($data['title']))$this->error('请输入标题'); if(empty($data['images']))$this->error('请上传封面'); if(!$data['release_time']) $data['release_time'] = date("Y-m-d H:i:s"); if($data['hot_num'] != $data['hot_num_old']) $data['hot_time'] = date("Y-m-d H:i:s"); if(!empty($data['phone'])) { $user_id = User::where('phone|email',$data['phone'])->value('id'); if(!$user_id) $this->error('账号未注册'); $data['user_id'] = $user_id; }else{ $data['user_id'] = ''; } list($post) = [$this->request->post()]; //定时热搜 if(!$post['hot_num']){ $post['hot_num'] = 0; } if(isset($post['id'])){ $info = \app\common\model\Press::where('id',$data['id'])->find(); if(($post['regular_hot_end_time'] && $post['hot_target_num'] && $info['regular_hot_end_time'] != $post['regular_hot_end_time']) || ($info['hot_num'] != $post['hot_num'] && $post['regular_hot_end_time'] && $post['hot_target_num'])){ $data['regular_hot_start_time'] = date("Y-m-d H:i:s"); $startdate = strtotime($data['regular_hot_start_time']); $enddate = strtotime($post['regular_hot_end_time']); $diff_seconds = ($enddate-$startdate)/60; $min_num = ceil($diff_seconds/10); $hot_num = $post['hot_target_num'] - $post['hot_num']; $num = ceil($hot_num/$min_num); $data['regular_num'] = $num; } }else{ if($post['regular_hot_end_time'] && $post['hot_target_num']){ $data['regular_hot_start_time'] = date("Y-m-d H:i:s"); $startdate = strtotime($data['regular_hot_start_time']); $enddate = strtotime($post['regular_hot_end_time']); $diff_seconds = ($enddate-$startdate)/60; $min_num = ceil($diff_seconds/10); $hot_num = $post['hot_target_num'] - $post['hot_num']; $num = ceil($hot_num/$min_num); $data['regular_num'] = $num; } } if(!$post['regular_hot_end_time']){ unset($data['regular_hot_end_time']); } //定时热搜end } } protected function _form_result(&$data) { \app\common\model\Press::esAdd($data); \app\common\model\TopSearch::saveData($data,'press'); $this->success('操作成功', 'javascript:history.back()'); } }