title = '图文列表'; $video_cate = VCM::field('id,title')->select()->toArray(); $this->video_cate = array_column($video_cate,null,'id'); $sel_where = []; $sel_where[] = ['v.is_deleted','=',0]; if($title = $this->request->get('title')) $sel_where[] = ['v.title','like','%'.$title.'%']; if($phone = $this->request->get('phone')) $sel_where[] = ['m.phone','like','%'.$phone.'%']; $this->status = $this->request->get('status',-1); if( $this->status >= 0 ) $sel_where[] = ['v.status','=', $this->status ]; $query = $this->_query($this->table)->field('v.*,m.phone,m.name user_name, m.headimg')->alias('v') ->leftJoin('StoreMember m','m.id = v.user_id'); $arr = ['is_new' => 0]; \app\common\model\UserArticle::alias('f')->where('is_new',1)->update($arr); $query->where($sel_where)->order('v.status desc ,v.id desc')->page(); } /** * 数据列表处理 * @auth true * @menu true * @param array $data * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ protected function _index_page_filter(&$data) { } /** * 编辑 * @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 * @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() { $this->_save($this->table, ['status' => '0']); } /** * 启用 * @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 enable() { $this->_save($this->table, ['status' => 1]); } /** * 删除图文 * @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 del() { $this->_save($this->table, ['is_deleted' => 1]); } /** * 表单数据处理 * @auth true * @menu true * @param array $data */ protected function _form_filter(&$data) { if($this->request->isGet() && in_array($this->request->action(),['add','edit'])){ $all_cate = VCM::where(['is_deleted'=>0])->order('sort desc ,id desc')->select(); $this->cate_tree = make_tree($all_cate); } if($this->request->isPost() && in_array($this->request->action(),['add','edit'])) { if($data['status'] > 0 ) UserMessage::sendUserMessage($data['user_id'],'article',2,$data['status']-1,0,$data['id']); } } protected function _form_result($result){ } /** * 图文添加到系列 * @auth true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function series() { if ($this->request->isGet()) { $id = $this->request->get('id'); $has_series = \app\common\model\ArticleItem::where('rel_id',$id)->column('article_id'); $user_article = \app\common\model\UserArticle::where(['id' => $id])->find()->toArray(); $series_list = ArticleIntro::where(['is_deleted'=>0,'type'=>2])->where('id','not in',$has_series)->column('title','id'); $this->fetch('', ['vo' => $user_article,'series_list'=>$series_list]); } else { $id = input('post.id'); $series_id = input('post.series_id'); if(!$series_id) $this->error('请选择系列'); $is_vip = input('post.is_vip'); $user_article = \app\common\model\UserArticle::where(['id' => $id])->find()->toArray(); $user_phone = User::where('id',$user_article['user_id'])->value('phone'); \app\common\model\ArticleItem::create([ 'article_id'=>$series_id, 'cover'=>explode('|',$user_article['images'])[0], 'images'=>$user_article['images'], 'sort'=>0, 'is_vip'=>$is_vip, 'source'=>2, 'rel_id'=>$id, 'content'=>$user_article['desc'], 'title'=>$user_article['title'], 'user_id' => $user_article['user_id'], 'phone' => $user_phone, 'release_time' => date("Y-m-d H:i:s"), ]); ArticleIntro::where('id',$series_id)->setInc('item_num'); $this->success('添加成功!'); } } public function new_article(){ if($this->request->isGet()) { $user_article = \app\common\model\UserArticle::where('id',input('id'))->find()->toArray(); $all_cate = ArticleCate::where(['is_deleted'=>0])->order('sort desc ,id desc')->select(); $cate_tree = make_tree($all_cate); $this->cate_tree = $cate_tree; $this->fetch('',['vo'=>$user_article,'cate_tree '=>$cate_tree]); }else{ $user_article_id= input('user_article_id'); $user_article = \app\common\model\UserArticle::where('id',$user_article_id)->find()->toArray(); $user_phone = User::where('id',$user_article['user_id'])->value('phone'); $new_article = [ 'title' => $user_article['title'], 'content' => $user_article['desc'], 'cover' => explode('|',$user_article['images'])[0], 'images' => $user_article['images'], 'first_classify' => input('first_classify'), 'second_classify' => input('second_classify'), 'type' => 1, 'is_over' => 1, 'label' => $user_article['label'], 'is_vip' => input('is_vip'), ]; $result = ArticleIntro::create($new_article); $article_item = [ 'article_id' => $result->id, 'cover' => $new_article['cover'], 'images' => $new_article['images'], 'content' => $new_article['content'], 'is_vip' => $new_article['is_vip'], 'source' => 2, 'title' => $new_article['title'], 'rel_id' => $user_article_id, 'user_id' => $user_article['user_id'], 'phone' => $user_phone, 'release_time' => date("Y-m-d H:i:s"), ]; Data::save('ArticleItem',$article_item,'article_id',['article_id' => $result->id]); $this->success('创建成功'); } } }