You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
zhishifufei_php/application/admin/controller/study/ClearanceSubjectChapter.php

326 lines
12 KiB

<?php
// +----------------------------------------------------------------------
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
// +----------------------------------------------------------------------
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
// +----------------------------------------------------------------------
namespace app\admin\controller\study;
use app\admin\controller\AuthController;
use app\admin\model\article\ArticleCategory as ArticleCategoryModel;
use app\admin\model\article\ArticleContent;
use service\JsonService as Json;
use service\UploadService as Upload;
use think\Request;
use app\admin\model\article\Article;
use app\admin\model\system\Recommend;
use app\admin\model\system\WebRecommend;
use app\admin\model\system\RecommendRelation;
use app\admin\model\system\WebRecommendRelation;
use think\Url;
use service\FormBuilder as Form;
use app\admin\model\wechat\WechatNewsCategory as WechatNewsCategoryModel;
use app\wap\model\wap\Clearance as ClearanceModel;
use app\wap\model\wap\ClearanceSubject as ClearanceSubjectModel;
use app\wap\model\wap\UserStudy;
use app\wap\model\wap\ClearanceSubjectChapter as ClearanceSubjectChapterModel;
use app\wap\model\wap\UserClearanceDetail;
use app\wap\model\wap\UserClearance;
use app\wap\model\special\SpecialSubject;
use app\wap\model\activity\EventRegistration;
use app\wap\model\special\Special as SpecialModel;
use app\wap\model\topic\Relation;
/**
* 图文管理
* Class WechatNews
* @package app\admin\controller\wechat
*/
class ClearanceSubjectChapter extends AuthController
{
public function index($recite_subject_id = 0)
{
$this->assign('recite_subject_id', $recite_subject_id);
$this->assign('cate', ClearanceSubjectModel::where('is_del',0)->where('is_show',1)->select());
$this->assign('type', $this->request->param('type', 1));
return $this->fetch();
}
/**
* 新闻列表
*/
public function article_list($recite_subject_id)
{
$where = parent::getMore([
['limit', 20],
['page', 1],
['recite_subject_id', 0],
['name', ''],
['order', ''],
['is_show', ''],
]);
if (!$where['recite_subject_id'] && $recite_subject_id) $where['recite_subject_id'] = $recite_subject_id;
return Json::successlayui(ClearanceSubjectChapterModel::getArticleLayList($where));
}
/**
* 设置单个产品上架|下架
*
* @return json
*/
public function set_show($is_show = '', $id = '')
{
if (!$id) Json::fail('缺少参数3');
$res = ClearanceSubjectChapterModel::where('id', $id)->update(["is_show" => $is_show]);
if ($res)
return Json::successful('保存成功');
else
return Json::fail('保存失败');
}
/**
* 快速编辑
*
* @return json
*/
public function set_value($field = '', $id = '', $value = '')
{
($field == '' || $id == '' || $value == '') && Json::fail('缺少参数');
$res = parent::getDataModification('article', $id, $field, $value);
if ($res)
return Json::successful('保存成功');
else
return Json::fail('保存失败');
}
public function add_article($id = 0)
{
$this->assign('id', $id);
if ($id) {
$article = ClearanceSubjectChapterModel::get($id);
$article->content = htmlspecialchars_decode($article->content);
$this->assign('article', $article->toJson());
}
if (empty($all)) {
$list = ClearanceSubjectModel::where('is_del',0)->where('is_show',1)->select();
$all = [];
foreach ($list as $menu) {
$all[$menu['id']] = $menu['name'];
}
$list = ClearanceSubjectChapterModel::where('is_del',0)->where('is_show',1)->where('pid',0)->select();
$all1 = [];
foreach ($list as $menu) {
$info = ClearanceSubjectModel::where('id',$menu['recite_subject_id'])->where('is_del',0)->where('is_show',1)->find();
$all1[$menu['id']] = ($info['name'] ?? "")."-".$menu['name'];
}
}
$this->assign('all1', json_encode($all1));
$this->assign('all', json_encode($all));
$this->assign('type', $this->request->param('type', 2));
return $this->fetch();
}
public function save_article($id = 0)
{
$data = parent::postMore([
['name', ''],
['en_name', ''],
['us_name', ''],
['sort', 0],
['recite_subject_id', 0],
['pid', 0],
['content', ''],
]);
if (!$data['name']) return Json::fail('请输入图文标题');
$data['content'] = htmlspecialchars($data['content']);
ClearanceSubjectChapterModel::beginTrans();
if ($id) {
$res = ClearanceSubjectChapterModel::edit($data, $id);
} else {
$data['add_time'] = time();
if (ClearanceSubjectChapterModel::be(['name' => $data['name'], 'is_del' => 0])) {
return Json::fail('标题已存在!');
}
$res = ClearanceSubjectChapterModel::insertGetId($data);
}
if ($res) {
ClearanceSubjectChapterModel::commitTrans();
return Json::successful('添加/编辑成功');
} else {
ClearanceSubjectChapterModel::rollbackTrans();
return Json::fail('添加/编辑失败');
}
}
public function delete($id = 0)
{
if (!$id) return Json::fail('缺少参数');
$article = Article::get($id);
if (!$article) return Json::fail('没有查找到图文');
Article::beginTrans();
try {
$res = $article->delete();
$res1 = ArticleContent::where('nid', $id)->delete();
if ($res1 && $res) {
if ($article['hide'] == 1) {
WechatNewsCategoryModel::where('new_id', $id)->delete();
}
Article::commitTrans();
return Json::successful('删除成功');
} else {
Article::rollbackTrans();
return Json::fail('删除失败');
}
} catch (\Exception $e) {
Article::rollbackTrans();
return Json::fail($e->getMessage());
}
}
/**
* 添加推荐
* */
public function recommend($article_id = 0)
{
if (!$article_id) $this->failed('缺少参数');
$article = Article::get($article_id);
if (!$article) $this->failed('没有查到此新闻');
$form = Form::create(Url::build('save_recommend', ['article_id' => $article_id]), [
Form::select('recommend_id', '推荐')->setOptions(function () {
$list = Recommend::where(['is_show' => 1, 'type' => 1])->field('title,id')->order('sort desc,add_time desc')->select();
$menus = [];
foreach ($list as $menu) {
$menus[] = ['value' => $menu['id'], 'label' => $menu['title']];
}
return $menus;
})->filterable(1),
Form::number('sort', '排序'),
]);
$form->setMethod('post')->setTitle('推荐设置')->setSuccessScript('parent.$(".J_iframe:visible")[0].contentWindow.location.reload(); setTimeout(function(){parent.layer.close(parent.layer.getFrameIndex(window.name));},800);');
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
}
/**
* 保存推荐
* */
public function save_recommend($article_id = 0)
{
if (!$article_id) $this->failed('缺少参数');
$data = parent::postMore([
['recommend_id', 0],
['sort', 0],
]);
if (!$data['recommend_id']) return Json::fail('请选择推荐');
$recommend = Recommend::get($data['recommend_id']);
if (!$recommend) return Json::fail('导航菜单不存在');
$data['add_time'] = time();
$data['type'] = 1;
$data['link_id'] = $article_id;
if (RecommendRelation::be(['type' => 1, 'link_id' => $article_id, 'recommend_id' => $data['recommend_id']])) return Json::fail('已推荐,请勿重复推荐');
if (RecommendRelation::set($data))
return Json::successful('推荐成功');
else
return Json::fail('推荐失败');
}
/**取消推荐
* @param int $id
*/
public function cancel_recommendation($id = 0, $article_id = 0)
{
if (!$id || !$article_id) $this->failed('缺少参数');
if (RecommendRelation::be(['id' => $id, 'link_id' => $article_id])) {
$res = RecommendRelation::where(['id' => $id, 'link_id' => $article_id])->delete();
if ($res)
return Json::successful('取消推荐成功');
else
return Json::fail('取消推荐失败');
} else {
return Json::fail('推荐不存在');
}
}
/**
* 添加推荐
* @param int $special_id
* @return mixed
* @throws \think\exception\DbException
*/
public function web_recommend($article_id = 0)
{
if (!$article_id) $this->failed('缺少参数');
$article = Article::get($article_id);
if (!$article) $this->failed('没有查到此新闻');
$form = Form::create(Url::build('save_web_recommend', ['article_id' => $article_id]), [
Form::select('recommend_id', '推荐')->setOptions(function () {
$model = WebRecommend::where(['is_show' => 1, 'type' => 4]);
$list = $model->field('title,id')->order('sort desc,add_time desc')->select();
$menus = [];
foreach ($list as $menu) {
$menus[] = ['value' => $menu['id'], 'label' => $menu['title']];
}
return $menus;
})->filterable(1),
Form::number('sort', '排序'),
]);
$form->setMethod('post')->setTitle('推荐设置')->setSuccessScript('parent.$(".J_iframe:visible")[0].contentWindow.location.reload(); setTimeout(function(){parent.layer.close(parent.layer.getFrameIndex(window.name));},800);');
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
}
/**
* 保存推荐
* @param int $special_id
* @throws \think\exception\DbException
*/
public function save_web_recommend($article_id = 0)
{
if (!$article_id) $this->failed('缺少参数');
$data = parent::postMore([
['recommend_id', 0],
['sort', 0],
]);
if (!$data['recommend_id']) return Json::fail('请选择推荐');
$recommend = WebRecommend::get($data['recommend_id']);
if (!$recommend) return Json::fail('导航菜单不存在');
$data['add_time'] = time();
$data['type'] = $recommend->type;
$data['link_id'] = $article_id;
if (WebRecommendRelation::be(['type' => $recommend->type, 'link_id' => $article_id, 'recommend_id' => $data['recommend_id']])) return Json::fail('已推荐,请勿重复推荐');
if (WebRecommendRelation::set($data))
return Json::successful('推荐成功');
else
return Json::fail('推荐失败');
}
/**取消推荐
* @param int $id
*/
public function cancel_web_recommendation($id = 0, $article_id = 0)
{
if (!$id || !$article_id) return Json::fail('缺少参数');
if (WebRecommendRelation::be(['id' => $id, 'link_id' => $article_id])) {
$res = WebRecommendRelation::where(['id' => $id, 'link_id' => $article_id])->delete();
if ($res)
return Json::successful('取消推荐成功');
else
return Json::fail('取消推荐失败');
} else {
return Json::fail('推荐不存在');
}
}
}