123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420 |
- <?php
- namespace app\admin\controller\article;
- use app\admin\controller\AuthController;
- use app\admin\model\system\SystemAttachment;
- use app\admin\model\enterprise\EnterPriseUser;
- use app\models\user\InterestUser;
- use crmeb\services\{JsonService, UtilService as Util, JsonService as Json, UtilService};
- use app\admin\model\article\{ArticleCategory as ArticleCategoryModel, Article as ArticleModel, ArticleReply};
- use crmeb\services\FormBuilder as Form;
- use think\facade\Route as Url;
- /**
- * 图文管理
- * Class WechatNews
- * @package app\admin\controller\wechat
- */
- class Article extends AuthController
- {
- /**
- * TODO 显示后台管理员添加的图文
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function index()
- {
- $where = Util::getMore([
- ['title', ''],
- ['cid', $this->request->param('pid', '')],
- ], $this->request);
- $where['merchant'] = $this->adminInfo['mer_id'];//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1
- $tree = sort_list_tier(ArticleCategoryModel::getArticleCategoryList());
- $this->assign(compact('tree'));
- $this->assign('mer_id', $this->adminInfo['mer_id']);
- $this->assign('where', $where);
- $this->assign(ArticleModel::getAll($where));
- return $this->fetch();
- }
- /**
- * TODO 文件添加和修改
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function create()
- {
- $id = $this->request->param('id');
- $cid = $this->request->param('cid');
- $news = [];
- $all = [];
- $news['id'] = '';
- $news['image_input'] = '';
- $news['title'] = '';
- $news['author'] = '';
- $news['is_banner'] = '';
- $news['is_hot'] = '';
- $news['content'] = '';
- $news['synopsis'] = '';
- $news['url'] = '';
- $news['cid'] = [];
- $news['mer_id'] = [];
- $news['mer'] = [];
- $news['add_time']='';
- $mer_id = $this->adminInfo['mer_id'];
- $select = 0;
- if ($id) {
- $news = ArticleModel::where('n.id', $id)->alias('n')->field('n.*,c.content')->join('ArticleContent c', 'c.nid=n.id', 'left')->find();
- if (!$news) return $this->failed('数据不存在!');
- $news['image_input'] = explode(',', $news['image_input']);
- $news['cid'] = explode(',', $news['cid']);
- // 通过文章ID获取文章企业名
- $news['add_time']=date("Y-m-d H:i:s",$news['add_time']);
- $news['rename'] =EnterPriseUser::where('id',$news['mer_id'])->value('name');
- $news['mer_id'] = explode(',', $news['mer_id']);
- $news['content'] = htmlspecialchars_decode($news['content']);
- }
- if ($cid && in_array($cid, ArticleCategoryModel::getArticleCategoryInfo(0, 'id'))) {
- $all = ArticleCategoryModel::getArticleCategoryInfo($cid);
- $select = 1;
- }
- if (!$select) {
- $list = ArticleCategoryModel::getTierList();
- foreach ($list as $menu) {
- $all[$menu['id']] = $menu['html'] . $menu['title'];
- }
- }
- $this->assign('all', $all);
- $this->assign('news', $news);
- $this->assign('mer_id', $mer_id);
- $this->assign('cid', $cid);
- $this->assign('select', $select);
- return $this->fetch();
- }
- public function preview()
- {
- return $this->create();
- }
- /**
- * 上传图文图片
- * @return \think\response\Json
- */
- public function upload_image()
- {
- $res = Upload::instance()->setUploadPath('wechat/image/' . date('Ymd'))->image($_POST['file']);
- if (!is_array($res)) return Json::fail($res);
- SystemAttachment::attachmentAdd($res['name'], $res['size'], $res['type'], $res['dir'], $res['thumb_path'], 5, $res['image_type'], $res['time'], 1, $this->adminInfo['mer_id']);
- return Json::successful('上传成功!', ['url' => $res['dir']]);
- }
- /**
- * 添加和修改图文
- */
- public function add_new()
- {
- $data = Util::postMore([
- ['id', 0],
- ['cid', []],
- ['mer',0],
- 'title',
- 'author',
- 'content',
- 'synopsis',
- 'share_title',
- 'share_synopsis',
- ['visit', 0],
- ['sort', 0],
- 'url',
- ['is_banner', 0],
- 'add_time',
- ['is_hot', 0],
- ['status', 1],]);
- $data['image_input'] = implode(',', $this->request->post('image_input'));
- $data['cid'] = implode(',', $data['cid']);
- $content = $data['content'];
- $data['add_time'] =strtotime($data['add_time']);
- //判断是新增还是修改
- if($this->adminInfo['mer_id']==0){
- $data['is_check'] =1;
- }else{
- $data['is_check'] =0;
- }
- unset($data['content']);
- if ($data['id']) {
- $id = $data['id'];
- unset($data['id']);
- $res = false;
- ArticleModel::beginTrans();
- $res1 = ArticleModel::edit($data, $id, 'id');
- $res2 = ArticleModel::setContent($id, $content);
- if ($res1 && $res2) {
- $res = true;
- }
- ArticleModel::checkTrans($res);
- if ($res)
- return Json::successful('修改图文成功!', $id);
- else
- return Json::fail('修改图文失败,您并没有修改什么!', $id);
- } else {
- $data['mer_id'] = $this->adminInfo['mer_id'];
- $data['admin_id'] = $this->adminId;
- //判断是否是总后台添加的文章
- if($data['mer_id']==0){
- $data['is_check'] =1;
- }else{
- $data['is_check'] =0;
- }
- $res = false;
- ArticleModel::beginTrans();
- $res1 = ArticleModel::create($data);
- $res2 = false;
- if ($res1)
- $res2 = ArticleModel::setContent($res1->id, $content);
- if ($res1 && $res2) {
- $res = true;
- }
- ArticleModel::checkTrans($res);
- if ($res)
- return Json::successful('添加图文成功!', $res1->id);
- else
- return Json::successful('添加图文失败!', $res1->id);
- }
- }
- /**
- * 删除图文
- * @param $id
- * @return \think\response\Json
- */
- public function delete($id)
- {
- $res = ArticleModel::del($id);
- if (!$res)
- return Json::fail('删除失败,请稍候再试!');
- else
- return Json::successful('删除成功!');
- }
- public function merchantIndex()
- {
- $where = Util::getMore([
- ['title', '']
- ], $this->request);
- $this->assign('where', $where);
- $where['cid'] = input('cid');
- $where['merchant'] = 1;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1
- $this->assign(ArticleModel::getAll($where));
- return $this->fetch();
- }
- /**
- * 关联文章 id
- * @param int $id
- */
- public function relation($id = 0)
- {
- $this->assign('id', $id);
- return $this->fetch();
- }
- /**
- * 取消绑定的产品id
- * @param int $id
- */
- public function unrelation($id = 0)
- {
- if (!$id) return Json::fail('缺少参数');
- if (ArticleModel::edit(['product_id' => 0], $id))
- return Json::successful('取消关联成功!');
- else
- return Json::fail('取消失败');
- }
- /**
- * 文章评论
- * @param $id
- * @return void
- */
- public function reply_list($id)
- {
- $where = Util::getMore([
- ['title', ''],
- ], $this->request);
- $this->assign('where', $where);
- $this->assign(ArticleReply::list($where, $id));
- $this->assign('id', $id);
- return $this->fetch();
- }
- public function delete_reply($id)
- {
- $res = ArticleReply::del($id);
- if (!$res)
- return Json::fail('删除失败,请稍候再试!');
- else
- return Json::successful('删除成功!');
- }
- public function reply($id)
- {
- $this->assign('id', $id);
- return $this->fetch();
- }
- /*
- * 创建form表单
- * */
- public function upcreate($id =0)
- {
- $vipinfo = ArticleModel::where('id',$id)->find();
- $field[] = Form::input('off', '拒绝理由', isset($vipinfo) ? $vipinfo->off: '')->col(Form::col(24));
- $form = Form::make_post_form('添加拒绝理由', $field, Url::buildUrl('save', ['id' => $id]), 2);
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- }
- /*
- * 审核/拒绝
- * @param $id 文章id
- * @return json
- * */
- public function save($id = 0)
- {
- $data = UtilService::postMore([
- ['off', ''],
- ]);
- if (!$data['off']) return JsonService::fail('请输入拒绝理由');
- if($data['off']){
- $res=ArticleModel::where('id',$id)->update(['reason' =>$data['off'],'is_check' =>2]);
- if($res>0){
- return Json::successful('审核成功');
- }else{
- return Json::fail('审核失败');
- }
- }
- }
- public function add_reply()
- {
- $data = Util::postMore([
- 'content',
- 'id'
- ]);
- $reply = ArticleReply::where('id', $data['id'])->find();
- if (empty($reply)) return Json::fail('数据不存在');
- $admin = $this->adminInfo;
- $res = ArticleReply::create([
- 'aid' => $reply['aid'],
- 'content' => $data['content'],
- 'uid' => $admin['mer_id'],
- 'to_id' => $data['id'],
- 'add_time' => time()
- ]);
- if (!$res)
- return Json::fail('回复失败!');
- else
- return Json::successful('回复成功!');
- }
- public function fans()
- {
- return $this->fetch();
- }
- public function fansList()
- {
- $where = UtilService::getMore([
- ['page', 1],
- ['limit', 20],
- ]);
- $where['mer_id'] = $this->adminInfo['mer_id'];
- JsonService::successlayui(InterestUser::getList($where));
- }
- public function delete_fan($id)
- {
- $info = InterestUser::where('id', $id)->find();
- if (!$info) {
- JsonService::fail('移除失败,找不到记录');
- }
- if ($this->adminInfo['mer_id'] > 0 && $this->adminInfo['mer_id'] != $info['mer_id']) {
- JsonService::fail('移除失败,不可移除非自己媒体的粉丝');
- }
- $res = InterestUser::remove($id);
- if ($res) {
- JsonService::success('移除成功');
- } else {
- JsonService::fail('移除失败');
- }
- }
- public function set_top($id)
- {
- if ($this->adminInfo['mer_id']) {
- JsonService::fail('权限不足');
- }
- $info = \app\models\article\Article::where('id', $id)->find();
- if (!$info) {
- JsonService::fail('置顶失败,找不到记录');
- }
- $res1 = \app\models\article\Article::where('is_top',1)->find();
- if($res1){
- $res = \app\models\article\Article::where(1)->update(['is_top' => 0]) && \app\models\article\Article::where('id', $id)->update(['is_top' => 1]);
- }else{
- $res=\app\models\article\Article::where('id', $id)->update(['is_top' => 1]);
- }
- if ($res) {
- JsonService::success('置顶成功');
- } else {
- JsonService::fail('置顶失败');
- }
- }
- public function set_check($id)
- {
- if ($this->adminInfo['mer_id']) {
- JsonService::fail('权限不足');
- }
- $info = \app\models\article\Article::where('id', $id)->find();
- if (!$info) {
- JsonService::fail('审核失败,找不到记录');
- }
- $res=\app\models\article\Article::where('id', $id)->update(['is_check' => 1]);
- if ($res) {
- JsonService::success('审核成功');
- } else {
- JsonService::fail('审核失败');
- }
- }
- public function set_hot($id)
- {
- if ($this->adminInfo['mer_id']) {
- JsonService::fail('权限不足');
- }
- $info = \app\models\article\Article::where('id', $id)->find();
- if (!$info) {
- JsonService::fail('推荐失败,找不到记录');
- }
- if($info['is_hot']==0){
- $type=1;
- }else{
- $type=0;
- }
- $res=\app\models\article\Article::where('id', $id)->update(['is_hot' =>$type]);
- if ($res) {
- JsonService::success('成功');
- } else {
- JsonService::fail('失败');
- }
- }
- }
|