修改测试案例

This commit is contained in:
Anyon 2020-09-02 16:02:33 +08:00
parent ab1fdaaad2
commit 5d5e38361f
17 changed files with 260 additions and 253 deletions

View File

@ -6,22 +6,16 @@ use think\admin\Controller;
/** /**
* 文章内容管理 * 文章内容管理
* Class ArticleContent * Class NewsItem
* @package app\data\controller * @package app\data\controller
*/ */
class ArticleContent extends Controller class NewsItem extends Controller
{ {
/** /**
* 绑定数据表 * 绑定数据表
* @var string * @var string
*/ */
private $table = 'DataArticleContent'; private $table = 'DataNewsItem';
/**
* 平台标签配置
* @var array
*/
protected $types = ['video' => '视频', 'article' => '文章', 'audio' => '音频'];
/** /**
* 文章内容管理 * 文章内容管理
@ -35,7 +29,7 @@ class ArticleContent extends Controller
{ {
$this->title = '文章内容管理'; $this->title = '文章内容管理';
$query = $this->_query($this->table); $query = $this->_query($this->table);
$query->like('title,tags')->dateBetween('create_at'); $query->like('title,mark')->dateBetween('create_at');
$query->where(['deleted' => 0])->order('sort desc,id desc')->page(); $query->where(['deleted' => 0])->order('sort desc,id desc')->page();
} }
@ -58,7 +52,8 @@ class ArticleContent extends Controller
protected function _page_filter(&$data) protected function _page_filter(&$data)
{ {
foreach ($data as &$vo) { foreach ($data as &$vo) {
$vo['tags'] = explode(',', trim($vo['tags'], ',')); $vo['mark'] = trim($vo['mark'], ',');
$vo['mark'] = $vo['mark'] ? explode(',', $vo['mark']) : [];
} }
} }
@ -99,10 +94,10 @@ class ArticleContent extends Controller
{ {
if ($this->request->isGet()) { if ($this->request->isGet()) {
[$map, $sort] = [['deleted' => 0, 'status' => 1], 'sort desc,id desc']; [$map, $sort] = [['deleted' => 0, 'status' => 1], 'sort desc,id desc'];
$this->tags = $this->app->db->name('DataArticleTags')->where($map)->order($sort)->select()->toArray(); $this->mark = $this->app->db->name('DataNewsMark')->where($map)->order($sort)->select()->toArray();
$data['tags'] = isset($data['tags']) && $data['tags'] ? explode(',', trim($data['tags'], ',')) : []; $data['mark'] = isset($data['mark']) && $data['mark'] ? explode(',', trim($data['mark'], ',')) : [];
} else { } else {
$data['tags'] = ',' . join(',', isset($data['tags']) && is_array($data['tags']) ? $data['tags'] : []) . ','; $data['mark'] = ',' . join(',', isset($data['mark']) && is_array($data['mark']) ? $data['mark'] : []) . ',';
} }
} }

View File

@ -6,16 +6,16 @@ use think\admin\Controller;
/** /**
* 文章标签管理 * 文章标签管理
* Class ArticleTags * Class NewsMark
* @package app\data\controller * @package app\data\controller
*/ */
class ArticleTags extends Controller class NewsMark extends Controller
{ {
/** /**
* 绑定数据表 * 绑定数据表
* @var string * @var string
*/ */
private $table = 'DataArticleTags'; private $table = 'DataNewsMark';
/** /**
* 文章标签管理 * 文章标签管理

View File

@ -2,14 +2,15 @@
namespace app\data\controller\api; namespace app\data\controller\api;
use app\data\service\NewsService;
use think\admin\Controller; use think\admin\Controller;
/** /**
* 文章接口控制器 * 文章接口控制器
* Class Article * Class News
* @package app\data\controller\api * @package app\data\controller\api
*/ */
class Article extends Controller class News extends Controller
{ {
/** /**
* 获取文章标签列表 * 获取文章标签列表
@ -17,9 +18,9 @@ class Article extends Controller
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
*/ */
public function getTags() public function getMark()
{ {
$query = $this->_query('DataArticleTags')->like('title'); $query = $this->_query('DataNewsMark')->like('title');
$query->where(['deleted' => 0, 'status' => 1])->withoutField('sort,status,deleted'); $query->where(['deleted' => 0, 'status' => 1])->withoutField('sort,status,deleted');
$this->success('获取文章标签列表', $query->order('sort desc,id desc')->page(false, false)); $this->success('获取文章标签列表', $query->order('sort desc,id desc')->page(false, false));
} }
@ -30,22 +31,24 @@ class Article extends Controller
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
*/ */
public function getContent() public function getItem()
{ {
if (($id = intval(input('id', 0))) > 0) { if (($id = intval(input('id', 0))) > 0) {
$this->app->db->name('DataArticleContent')->where(['id' => $id])->update([ $this->app->db->name('DataNewsItem')->where(['id' => $id])->update([
'number_reads' => $this->app->db->raw('`number_reads`+1'), 'num_read' => $this->app->db->raw('`num_read`+1'),
]); ]);
if (input('mid') > 0) { if (input('mid') > 0) {
$history = ['mid' => input('mid'), 'cid' => $id]; $history = ['mid' => input('mid'), 'cid' => $id];
$this->app->db->name('DataArticleHistory')->where($history)->delete(); $this->app->db->name('DataNewsHistory')->where($history)->delete();
$this->app->db->name('DataArticleHistory')->insert($history); $this->app->db->name('DataNewsHistory')->insert($history);
} }
} }
$query = $this->_query('DataArticleContent')->equal('type,id')->like('title,tags'); $query = $this->_query('DataNewsItem')->equal('id')->like('title,mark');
$query->where(['deleted' => 0, 'status' => 1])->withoutField('sort,status,deleted'); $query->where(['deleted' => 0, 'status' => 1])->withoutField('sort,status,deleted');
$result = $query->order('sort desc,id desc')->page(true, false, false, 15); $result = $query->order('sort desc,id desc')->page(true, false, false, 15);
foreach ($result['list'] as &$vo) $vo['tags'] = trim($vo['tags'], ','); if (count($result['list']) > 0 && input('mid') > 0) {
NewsService::instance()->buildListState($result['list'], input('mid'));
}
$this->success('获取文章内容列表', $result); $this->success('获取文章内容列表', $result);
} }
@ -58,13 +61,9 @@ class Article extends Controller
public function getComment() public function getComment()
{ {
$data = $this->_vali(['cid.require' => '文章ID不能为空']); $data = $this->_vali(['cid.require' => '文章ID不能为空']);
$query = $this->_query('DataArticleComment')->where($data); $query = $this->_query('DataNewsXComment')->where($data);
$result = $query->order('id desc')->page(false, false, false, 5); $result = $query->order('id desc')->page(false, false, false, 5);
if (count($result['list']) > 0) { NewsService::instance()->buildListByMid($result['list']);
$ids = array_unique(array_column($result['list'], 'mid'));
$mems = $this->app->db->name('DataMember')->whereIn('id', $ids)->column('id,nickname,username,headimg', 'id');
foreach ($result['list'] as &$vo) $vo['member'] = $mems[$vo['mid']] ?? [];
}
$this->success('获取文章评论成功!', $result); $this->success('获取文章评论成功!', $result);
} }
@ -74,17 +73,17 @@ class Article extends Controller
public function getLike() public function getLike()
{ {
$data = $this->_vali(['cid.require' => '文章ID不能为空']); $data = $this->_vali(['cid.require' => '文章ID不能为空']);
$query = $this->app->db->name('DataArticleLike')->where($data); $query = $this->app->db->name('DataNewsXLike')->where($data);
$this->success('获取已点赞的会员', ['list' => $query->order('mid asc')->column('mid')]); $this->success('获取已点赞的会员', ['list' => $query->order('mid asc')->column('mid')]);
} }
/** /**
* 获取已收藏的会员 * 获取已收藏的会员
*/ */
public function getCollection() public function getCollect()
{ {
$data = $this->_vali(['cid.require' => '文章ID不能为空']); $data = $this->_vali(['cid.require' => '文章ID不能为空']);
$query = $this->app->db->name('DataArticleCollection')->where($data); $query = $this->app->db->name('DataNewsXCollect')->where($data);
$this->success('获取已收藏的会员', ['list' => $query->order('mid asc')->column('mid')]); $this->success('获取已收藏的会员', ['list' => $query->order('mid asc')->column('mid')]);
} }
} }

View File

@ -3,14 +3,14 @@
namespace app\data\controller\api\member; namespace app\data\controller\api\member;
use app\data\controller\api\Member; use app\data\controller\api\Member;
use app\data\service\ArticleService; use app\data\service\NewsService;
/** /**
* 文章评论内容 * 文章评论内容
* Class Article * Class News
* @package app\data\controller\api\member * @package app\data\controller\api\member
*/ */
class Article extends Member class News extends Member
{ {
/** /**
* 会员评论内容 * 会员评论内容
@ -23,8 +23,8 @@ class Article extends Member
'cid.require' => '文章ID不能为空', 'cid.require' => '文章ID不能为空',
'content.require' => '评论内容不能为空!', 'content.require' => '评论内容不能为空!',
]); ]);
if ($this->app->db->name('DataArticleComment')->insert($data) !== false) { if ($this->app->db->name('DataNewsXComment')->insert($data) !== false) {
ArticleService::instance()->syncTotal($data['cid']); NewsService::instance()->syncTotal($data['cid']);
$this->success('添加评论成功!'); $this->success('添加评论成功!');
} else { } else {
$this->error('添加评论失败!'); $this->error('添加评论失败!');
@ -42,7 +42,7 @@ class Article extends Member
'id.require' => '评论ID不能为空', 'id.require' => '评论ID不能为空',
'cid.require' => '文章ID不能为空', 'cid.require' => '文章ID不能为空',
]); ]);
if ($this->app->db->name('DataArticleComment')->where($data)->delete() !== false) { if ($this->app->db->name('DataNewsXComment')->where($data)->delete() !== false) {
$this->success('评论删除成功!'); $this->success('评论删除成功!');
} else { } else {
$this->error('认证删除失败!'); $this->error('认证删除失败!');
@ -58,23 +58,22 @@ class Article extends Member
public function getComment() public function getComment()
{ {
$data = $this->_vali(['mid.value' => $this->mid, 'cid.require' => '内容ID不能为空']); $data = $this->_vali(['mid.value' => $this->mid, 'cid.require' => '内容ID不能为空']);
$this->success('获取评论列表成功', [ $query = $this->app->db->name('DataNewsXComment')->where($data)->order('id desc');
'list' => $this->app->db->name('DataArticleComment')->where($data)->order('id desc')->select()->toArray(), $this->success('获取评论列表成功', ['list' => $query->select()->toArray()]);
]);
} }
/** /**
* 添加内容收藏 * 添加内容收藏
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
*/ */
public function addCollection() public function addCollect()
{ {
$data = $this->_vali(['mid.value' => $this->mid, 'cid.require' => '内容ID不能为空']); $data = $this->_vali(['mid.value' => $this->mid, 'cid.require' => '内容ID不能为空']);
if ($this->app->db->name('DataArticleCollection')->where($data)->count() > 0) { if ($this->app->db->name('DataNewsXCollect')->where($data)->count() > 0) {
$this->success('您已收藏!'); $this->success('您已收藏!');
} }
if ($this->app->db->name('DataArticleCollection')->insert($data) !== false) { if ($this->app->db->name('DataNewsXCollect')->insert($data) !== false) {
ArticleService::instance()->syncTotal($data['cid']); NewsService::instance()->syncTotal($data['cid']);
$this->success('收藏成功!'); $this->success('收藏成功!');
} else { } else {
$this->error('收藏失败!'); $this->error('收藏失败!');
@ -85,11 +84,11 @@ class Article extends Member
* 取消收藏文章 * 取消收藏文章
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
*/ */
public function delCollection() public function delCollect()
{ {
$data = $this->_vali(['mid.value' => $this->mid, 'cid.require' => '文章ID不能为空']); $data = $this->_vali(['mid.value' => $this->mid, 'cid.require' => '文章ID不能为空']);
if ($this->app->db->name('DataArticleCollection')->where($data)->delete() !== false) { if ($this->app->db->name('DataNewsXCollect')->where($data)->delete() !== false) {
ArticleService::instance()->syncTotal($data['cid']); NewsService::instance()->syncTotal($data['cid']);
$this->success('取消收藏成功!'); $this->success('取消收藏成功!');
} else { } else {
$this->error('取消收藏失败!'); $this->error('取消收藏失败!');
@ -100,18 +99,12 @@ class Article extends Member
* 获取我收藏的资讯 * 获取我收藏的资讯
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
*/ */
public function getMyCollection() public function getMyCollect()
{ {
$query = $this->_query('DataArticleCollection')->where(['mid' => $this->mid]); $query = $this->_query('DataNewsXCollect')->where(['mid' => $this->mid]);
$result = $query->order('id desc')->page(true, false, false, 15); $result = $query->order('id desc')->page(true, false, false, 15);
if (count($result['list']) > 0) { NewsService::instance()->buildListByCid($result['list']);
$ids = array_unique(array_column($result['list'], 'cid'));
$fields = 'id,title,logo,source,number_likes,number_reads,number_comment,number_collection,status,deleted,create_at';
$Articles = $this->app->db->name('DataArticleContent')->whereIn('id', $ids)->column($fields, 'id');
foreach ($result['list'] as &$vo) $vo['record'] = $Articles[$vo['cid']] ?? [];
}
$this->success('获取收藏记录成功!', $result); $this->success('获取收藏记录成功!', $result);
} }
/** /**
@ -121,11 +114,11 @@ class Article extends Member
public function addLike() public function addLike()
{ {
$data = $this->_vali(['mid.value' => $this->mid, 'cid.require' => '内容ID不能为空']); $data = $this->_vali(['mid.value' => $this->mid, 'cid.require' => '内容ID不能为空']);
if ($this->app->db->name('DataArticleLike')->where($data)->count() > 0) { if ($this->app->db->name('DataNewsXLike')->where($data)->count() > 0) {
$this->success('您已点赞!'); $this->success('您已点赞!');
} }
if ($this->app->db->name('DataArticleLike')->insert($data) !== false) { if ($this->app->db->name('DataNewsXLike')->insert($data) !== false) {
ArticleService::instance()->syncTotal($data['cid']); NewsService::instance()->syncTotal($data['cid']);
$this->success('点赞成功!'); $this->success('点赞成功!');
} else { } else {
$this->error('点赞失败!'); $this->error('点赞失败!');
@ -139,8 +132,8 @@ class Article extends Member
public function delLike() public function delLike()
{ {
$data = $this->_vali(['mid.value' => $this->mid, 'cid.require' => '内容ID不能为空']); $data = $this->_vali(['mid.value' => $this->mid, 'cid.require' => '内容ID不能为空']);
if ($this->app->db->name('DataArticleLike')->where($data)->delete() !== false) { if ($this->app->db->name('DataNewsXLike')->where($data)->delete() !== false) {
ArticleService::instance()->syncTotal($data['cid']); NewsService::instance()->syncTotal($data['cid']);
$this->success('取消点赞成功!'); $this->success('取消点赞成功!');
} else { } else {
$this->error('取消点赞失败!'); $this->error('取消点赞失败!');
@ -155,14 +148,10 @@ class Article extends Member
*/ */
public function getHistory() public function getHistory()
{ {
$query = $this->_query('DataArticleHistory')->where(['mid' => $this->mid]); $query = $this->_query('DataNewsXHistory');
$result = $query->order('id desc')->page(true, false, false, 15); $query->where(['mid' => $this->mid])->order('id desc');
if (count($result['list']) > 0) { $result = $query->page(true, false, false, 15);
$ids = array_unique(array_column($result['list'], 'cid')); NewsService::instance()->buildListByCid($result['list']);
$fields = 'id,title,logo,source,number_likes,number_reads,number_comment,number_collection,status,deleted,create_at';
$articles = $this->app->db->name('DataArticleContent')->whereIn('id', $ids)->column($fields, 'id');
foreach ($result['list'] as &$vo) $vo['record'] = $articles[$vo['cid']] ?? [];
}
$this->success('获取浏览历史成功!', $result); $this->success('获取浏览历史成功!', $result);
} }

View File

@ -11,114 +11,12 @@
Target Server Version : 50562 Target Server Version : 50562
File Encoding : 65001 File Encoding : 65001
Date: 13/07/2020 16:11:40 Date: 02/09/2020 16:01:59
*/ */
SET NAMES utf8mb4; SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0; SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for data_article_collection
-- ----------------------------
DROP TABLE IF EXISTS `data_article_collection`;
CREATE TABLE `data_article_collection` (
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`cid` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '文章编号',
`mid` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '会员MID',
`content` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '评论内容',
`create_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
PRIMARY KEY (`id`) USING BTREE,
INDEX `idx_data_article_comment_cid`(`cid`) USING BTREE,
INDEX `idx_data_article_comment_mid`(`mid`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '数据-文章-收藏' ROW_FORMAT = Compact;
-- ----------------------------
-- Table structure for data_article_comment
-- ----------------------------
DROP TABLE IF EXISTS `data_article_comment`;
CREATE TABLE `data_article_comment` (
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`cid` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '文章编号',
`mid` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '会员MID',
`content` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '评论内容',
`create_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
PRIMARY KEY (`id`) USING BTREE,
INDEX `idx_data_article_comment_cid`(`cid`) USING BTREE,
INDEX `idx_data_article_comment_mid`(`mid`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '数据-文章-评论' ROW_FORMAT = Compact;
-- ----------------------------
-- Table structure for data_article_content
-- ----------------------------
DROP TABLE IF EXISTS `data_article_content`;
CREATE TABLE `data_article_content` (
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`title` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '文章标题',
`type` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '文章类型(video,article,audio)',
`logo` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '攻略图片',
`tags` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '文章标签',
`source` varchar(900) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '媒体资源',
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '备注说明',
`content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '文章内容',
`number_likes` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '文章点赞数',
`number_reads` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '文章阅读数',
`number_comment` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '文章评论数',
`number_collection` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '文章收藏数',
`sort` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '排序权重',
`status` tinyint(1) UNSIGNED NULL DEFAULT 1 COMMENT '权限状态(1使用,0禁用)',
`deleted` tinyint(1) NULL DEFAULT 0 COMMENT '删除状态(0未删,1已删)',
`create_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
PRIMARY KEY (`id`) USING BTREE,
INDEX `idx_data_article_content_type`(`type`) USING BTREE,
INDEX `idx_data_article_content_status`(`status`) USING BTREE,
INDEX `idx_data_article_content_deleted`(`deleted`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '数据-文章-内容' ROW_FORMAT = Compact;
-- ----------------------------
-- Table structure for data_article_history
-- ----------------------------
DROP TABLE IF EXISTS `data_article_history`;
CREATE TABLE `data_article_history` (
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`cid` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '文章编号',
`mid` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '会员MID',
`create_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
PRIMARY KEY (`id`) USING BTREE,
INDEX `idx_data_article_history_cid`(`cid`) USING BTREE,
INDEX `idx_data_article_history_mid`(`mid`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '数据-文章-历史' ROW_FORMAT = Compact;
-- ----------------------------
-- Table structure for data_article_like
-- ----------------------------
DROP TABLE IF EXISTS `data_article_like`;
CREATE TABLE `data_article_like` (
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`cid` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '文章编号',
`mid` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '会员MID',
`create_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
PRIMARY KEY (`id`) USING BTREE,
INDEX `idx_data_article_comment_cid`(`cid`) USING BTREE,
INDEX `idx_data_article_comment_mid`(`mid`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '数据-文章-点赞' ROW_FORMAT = Compact;
-- ----------------------------
-- Table structure for data_article_tags
-- ----------------------------
DROP TABLE IF EXISTS `data_article_tags`;
CREATE TABLE `data_article_tags` (
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`title` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '标签名称',
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '标签说明',
`sort` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '排序权重',
`status` tinyint(1) UNSIGNED NULL DEFAULT 1 COMMENT '权限状态(1使用,0禁用)',
`deleted` tinyint(1) UNSIGNED NULL DEFAULT 0 COMMENT '删除状态',
`create_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
PRIMARY KEY (`id`) USING BTREE,
INDEX `idx_data_article_tags_status`(`status`) USING BTREE,
INDEX `idx_data_article_tags_deleted`(`deleted`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '数据-文章-标签' ROW_FORMAT = Compact;
-- ---------------------------- -- ----------------------------
-- Table structure for data_member -- Table structure for data_member
-- ---------------------------- -- ----------------------------
@ -194,4 +92,103 @@ CREATE TABLE `data_member_coin_used` (
INDEX `idx_data_member_coin_used_name`(`name`) USING BTREE INDEX `idx_data_member_coin_used_name`(`name`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '数据-会员-金币-消费' ROW_FORMAT = Compact; ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '数据-会员-金币-消费' ROW_FORMAT = Compact;
-- ----------------------------
-- Table structure for data_news_item
-- ----------------------------
DROP TABLE IF EXISTS `data_news_item`;
CREATE TABLE `data_news_item` (
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`title` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '文章标题',
`mark` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '文章标签',
`cover` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '文章封面',
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '备注说明',
`content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '文章内容',
`num_like` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '文章点赞数',
`num_read` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '文章阅读数',
`num_collect` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '文章收藏数',
`num_comment` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '文章评论数',
`sort` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '排序权重',
`status` tinyint(1) UNSIGNED NULL DEFAULT 1 COMMENT '权限状态(1使用,0禁用)',
`deleted` tinyint(1) NULL DEFAULT 0 COMMENT '删除状态(0未删,1已删)',
`create_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
PRIMARY KEY (`id`) USING BTREE,
INDEX `idx_data_news_item_status`(`status`) USING BTREE,
INDEX `idx_data_news_item_deleted`(`deleted`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '数据-文章-内容' ROW_FORMAT = Compact;
-- ----------------------------
-- Table structure for data_news_mark
-- ----------------------------
DROP TABLE IF EXISTS `data_news_mark`;
CREATE TABLE `data_news_mark` (
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`title` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '标签名称',
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '标签说明',
`sort` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '排序权重',
`status` tinyint(1) UNSIGNED NULL DEFAULT 1 COMMENT '权限状态(1使用,0禁用)',
`deleted` tinyint(1) UNSIGNED NULL DEFAULT 0 COMMENT '删除状态',
`create_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
PRIMARY KEY (`id`) USING BTREE,
INDEX `idx_data_news_mark_status`(`status`) USING BTREE,
INDEX `idx_data_news_mark_deleted`(`deleted`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '数据-文章-标签' ROW_FORMAT = Compact;
-- ----------------------------
-- Table structure for data_news_x_collect
-- ----------------------------
DROP TABLE IF EXISTS `data_news_x_collect`;
CREATE TABLE `data_news_x_collect` (
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`cid` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '文章编号',
`mid` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '会员MID',
`content` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '评论内容',
`create_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
PRIMARY KEY (`id`) USING BTREE,
INDEX `idx_data_news_x_collect_cid`(`cid`) USING BTREE,
INDEX `idx_data_news_x_collect_mid`(`mid`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '数据-文章-会员-收藏' ROW_FORMAT = Compact;
-- ----------------------------
-- Table structure for data_news_x_comment
-- ----------------------------
DROP TABLE IF EXISTS `data_news_x_comment`;
CREATE TABLE `data_news_x_comment` (
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`cid` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '文章编号',
`mid` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '会员MID',
`content` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '评论内容',
`create_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
PRIMARY KEY (`id`) USING BTREE,
INDEX `idx_data_news_x_comment_cid`(`cid`) USING BTREE,
INDEX `idx_data_news_x_comment_mid`(`mid`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '数据-文章-会员-评论' ROW_FORMAT = Compact;
-- ----------------------------
-- Table structure for data_news_x_history
-- ----------------------------
DROP TABLE IF EXISTS `data_news_x_history`;
CREATE TABLE `data_news_x_history` (
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`cid` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '文章编号',
`mid` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '会员MID',
`create_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
PRIMARY KEY (`id`) USING BTREE,
INDEX `idx_data_news_x_history_cid`(`cid`) USING BTREE,
INDEX `idx_data_news_x_history_mid`(`mid`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '数据-文章-会员-历史' ROW_FORMAT = Compact;
-- ----------------------------
-- Table structure for data_news_x_like
-- ----------------------------
DROP TABLE IF EXISTS `data_news_x_like`;
CREATE TABLE `data_news_x_like` (
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`cid` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '文章编号',
`mid` bigint(20) UNSIGNED NULL DEFAULT 0 COMMENT '会员MID',
`create_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
PRIMARY KEY (`id`) USING BTREE,
INDEX `idx_data_news_x_like_cid`(`cid`) USING BTREE,
INDEX `idx_data_news_x_like_mid`(`mid`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '数据-文章-会员-点赞' ROW_FORMAT = Compact;
SET FOREIGN_KEY_CHECKS = 1; SET FOREIGN_KEY_CHECKS = 1;

View File

@ -1,28 +0,0 @@
<?php
namespace app\data\service;
use think\admin\Service;
/**
* 文章数据处理服务
* Class ArticleService
* @package app\data\service
*/
class ArticleService extends Service
{
/**
* 同步文章数据统计
* @param integer $cid 文章ID
* @throws \think\db\exception\DbException
*/
public function syncTotal($cid)
{
$this->app->db->name('DataArticleContent')->where(['id' => $cid])->update([
'number_likes' => $this->app->db->name('DataArticleLike')->where(['cid' => $cid])->count(),
'number_comment' => $this->app->db->name('DataArticleComment')->where(['cid' => $cid])->count(),
'number_collection' => $this->app->db->name('DataArticleCollection')->where(['cid' => $cid])->count(),
]);
}
}

View File

@ -0,0 +1,80 @@
<?php
namespace app\data\service;
use think\admin\Service;
/**
* 文章数据处理服务
* Class NewsService
* @package app\data\service
*/
class NewsService extends Service
{
/**
* 同步文章数据统计
* @param integer $cid 文章ID
* @throws \think\db\exception\DbException
*/
public function syncTotal($cid)
{
$this->app->db->name('DataNewsItem')->where(['id' => $cid])->update([
'num_like' => $this->app->db->name('DataNewsXLike')->where(['cid' => $cid])->count(),
'num_comment' => $this->app->db->name('DataNewsXComment')->where(['cid' => $cid])->count(),
'num_collect' => $this->app->db->name('DataNewsXCollect')->where(['cid' => $cid])->count(),
]);
}
/**
* 根据CID绑定列表数据
* @param array $list
* @return array
*/
public function buildListByCid(array &$list = []): array
{
if (count($list) > 0) {
$cids = array_unique(array_column($list, 'cid'));
$cols = 'id,title,logo,status,deleted,create_at,num_like,num_read,num_comment,num_collect';
$news = $this->app->db->name('DataNewsItem')->whereIn('id', $cids)->column($cols, 'id');
foreach ($list as &$vo) $vo['record'] = $news[$vo['cid']] ?? [];
}
return $list;
}
/**
* 根据MID绑定列表数据
* @param array $list
* @return array
*/
public function buildListByMid(array &$list = []): array
{
if (count($list) > 0) {
$ids = array_unique(array_column($list, 'mid'));
$cols = 'id,phone,nickname,username,headimg,status';
$mems = $this->app->db->name('DataMember')->whereIn('id', $ids)->column($cols, 'id');
foreach ($list as &$vo) $vo['member'] = $mems[$vo['mid']] ?? [];
}
return $list;
}
/**
* 获取列表状态
* @param array $list
* @param integer $mid
* @return array
*/
public function buildListState(array &$list, int $mid = 0): array
{
if (count($list) > 0 && $mid > 0) {
$map = [['mid', '=', $mid], ['cid', 'in', array_column($list, 'id')]];
$cid1s = $this->app->db->name('DataNewsXLike')->where($map)->column('cid');
$cid2s = $this->app->db->name('DataNewsXCollect')->where($map)->column('cid');
foreach ($list as &$vo) {
$vo['my_like_state'] = in_array($vo['id'], $cid1s) ? 1 : 0;
$vo['my_collect_state'] = in_array($vo['id'], $cid2s) ? 1 : 0;
}
}
return $list;
}
}

View File

@ -62,10 +62,10 @@
})(); })();
/*! 轮播选项操作 */ /*! 轮播选项操作 */
$('[data-slider-box]').on('click', '[data-item-article]', function ($that) { $('[data-slider-box]').on('click', '[data-item-article]', function ($that) {
$that = $(this), top.setAttackId = function (id) { $that = $(this), top.setNewsId = function (id) {
$that.prevAll('input').val('article#{v}'.replace('{v}', id)); $that.prevAll('input').val('news#{v}'.replace('{v}', id));
}; };
$.form.iframe('{:url("data/article_content/select")}', '选择文章', ['930px', '600px']); $.form.iframe('{:url("data/news_item/select")}', '选择文章', ['930px', '600px']);
}).on('click', '[data-item-add]', function () { }).on('click', '[data-item-add]', function () {
addItem(); addItem();
}).on('click', '[data-item-rm]', function () { }).on('click', '[data-item-rm]', function () {

View File

@ -5,42 +5,24 @@
<div class="layui-card-body padding-40"> <div class="layui-card-body padding-40">
<div class="layui-form-item relative block">
<span class="color-green font-w7 label-required-prev">文章类型</span>
<div class="tags-container layui-textarea">
{empty name='vo.type'}{assign name='vo.type' value='video'}{/empty}
{foreach $types as $key=>$type}{if isset($vo.type) and $key eq $vo.type}
<label class="think-radio notselect"><input checked type="radio" name="type" value="{$key}" lay-ignore> {$type}</label>
{else}
<label class="think-radio notselect"><input type="radio" name="type" value="{$key}" lay-ignore> {$type}</label>
{/if}{/foreach}
</div>
</div>
<div class="layui-form-item relative block"> <div class="layui-form-item relative block">
<span class="color-green font-w7 label-required-prev">文章标签</span> <span class="color-green font-w7 label-required-prev">文章标签</span>
<div class="tags-container layui-textarea"> <div class="tags-container layui-textarea">
{foreach $tags as $tag}{if isset($vo.tags) && is_array($vo.tags) && in_array($tag.title, $vo.tags)} {foreach $mark as $tag}{if isset($vo.mark) && is_array($vo.mark) && in_array($tag.title, $vo.mark)}
<label class="think-checkbox notselect"><input checked type="checkbox" name="tags[]" value="{$tag.title}" lay-ignore> {$tag.title}</label> <label class="think-checkbox notselect"><input checked type="checkbox" name="mark[]" value="{$tag.title}" lay-ignore> {$tag.title}</label>
{else} {else}
<label class="think-checkbox notselect"><input type="checkbox" name="tags[]" value="{$tag.title}" lay-ignore> {$tag.title}</label> <label class="think-checkbox notselect"><input type="checkbox" name="mark[]" value="{$tag.title}" lay-ignore> {$tag.title}</label>
{/if}{/foreach} {/if}{/foreach}
</div> </div>
</div> </div>
<div class="layui-form-item relative block">
<span class="color-green font-w7 label-required-prev">资源文件</span>
<label class="relative block label-required-null">
<input required name="source" value='{$vo.source|default=""}' placeholder="请上传资源文件&nbsp; &nbsp; &nbsp; &nbsp;" class="layui-input">
<a data-file data-type="png,jpg,gif,mp4,mp3" data-field="source" class="input-right-icon layui-icon layui-icon-upload"></a>
</label>
</div>
<div class="layui-form-item relative block"> <div class="layui-form-item relative block">
<span class="color-green font-w7 label-required-prev">文章图片</span> <span class="color-green font-w7 label-required-prev">文章图片</span>
<label class="relative block label-required-null"> <label class="relative block label-required-null">
<input required name="logo" value='{$vo.logo|default=""}' placeholder="请上传图片&nbsp; &nbsp; &nbsp; &nbsp;" class="layui-input"> <input required name="cover" value='{$vo.cover|default=""}' placeholder="请上传图片&nbsp; &nbsp; &nbsp; &nbsp;" class="layui-input">
<a data-file data-type="png,jpg,gif" data-field="logo" class="input-right-icon layui-icon layui-icon-upload"></a> <a data-file data-type="png,jpg,gif" data-field="cover" class="input-right-icon layui-icon layui-icon-upload"></a>
<script>$('[name="cover"]').uploadOneImage()</script>
</label> </label>
</div> </div>

View File

@ -14,7 +14,7 @@
<p class=" margin-bottom-15"> <p class=" margin-bottom-15">
演示接口文档:<a target="_blank" href="http://www.docway.net/project/1WkI0ZyQ7M1/share/1Wld0z7b1zE">http://www.docway.net/project/1WkI0ZyQ7M1/share/1Wld0z7b1zE</a> 演示接口文档:<a target="_blank" href="http://www.docway.net/project/1WkI0ZyQ7M1/share/1Wld0z7b1zE">http://www.docway.net/project/1WkI0ZyQ7M1/share/1Wld0z7b1zE</a>
</p> </p>
{include file='article_content/index_search'} {include file='news_item/index_search'}
<table class="layui-table margin-top-10" lay-skin="line"> <table class="layui-table margin-top-10" lay-skin="line">
{notempty name='list'} {notempty name='list'}
<thead> <thead>
@ -43,7 +43,7 @@
<label><input data-action-blur="{:request()->url()}" data-value="id#{$vo.id};action#sort;sort#{value}" data-loading="false" value="{$vo.sort}" class="list-sort-input"></label> <label><input data-action-blur="{:request()->url()}" data-value="id#{$vo.id};action#sort;sort#{value}" data-loading="false" value="{$vo.sort}" class="list-sort-input"></label>
</td> </td>
<td class="text-left nowrap">{$vo.title|default=''}</td> <td class="text-left nowrap">{$vo.title|default=''}</td>
<td class="text-left nowrap">{notempty name='vo.tags'}{foreach $vo.tags as $tag}<span data-tips-text="热搜标签" class="margin-right-5 layui-badge layui-bg-cyan">{$tag}</span>{/foreach}{/notempty}<br></td> <td class="text-left nowrap">{notempty name='vo.mark'}{foreach $vo.mark as $tag}<span data-tips-text="热搜标签" class="margin-right-5 layui-badge layui-bg-cyan">{$tag}</span>{/foreach}{/notempty}<br></td>
<td class="text-left nowrap">{if $vo.status eq 0}<span class="color-red">已禁用</span>{elseif $vo.status eq 1}<span class="color-green">使用中</span>{/if}</td> <td class="text-left nowrap">{if $vo.status eq 0}<span class="color-red">已禁用</span>{elseif $vo.status eq 1}<span class="color-green">使用中</span>{/if}</td>
<td class="text-left nowrap">{$vo.create_at|format_datetime}</td> <td class="text-left nowrap">{$vo.create_at|format_datetime}</td>
<td class='text-left nowrap'> <td class='text-left nowrap'>

View File

@ -10,7 +10,7 @@
<div class="layui-form-item layui-inline"> <div class="layui-form-item layui-inline">
<label class="layui-form-label">搜索标签</label> <label class="layui-form-label">搜索标签</label>
<label class="layui-input-inline"> <label class="layui-input-inline">
<input name="tags" value="{:input('tags','')}" placeholder="请输入搜索标签" class="layui-input"> <input name="mark" value="{:input('mark','')}" placeholder="请输入搜索标签" class="layui-input">
</label> </label>
</div> </div>
<div class="layui-form-item layui-inline"> <div class="layui-form-item layui-inline">

View File

@ -2,7 +2,7 @@
{block name='content'} {block name='content'}
<div class="padding-25" data-select-container> <div class="padding-25" data-select-container>
{include file='article_content/select_search'} {include file='news_item/select_search'}
<table class="layui-table margin-top-10" lay-skin="line"> <table class="layui-table margin-top-10" lay-skin="line">
{notempty name='list'} {notempty name='list'}
<thead> <thead>
@ -20,11 +20,7 @@
<td class="text-left nowrap">{$vo.title|default=''}</td> <td class="text-left nowrap">{$vo.title|default=''}</td>
<td class="text-left nowrap">{if $vo.status eq 0}<span class="color-red">已禁用</span>{elseif $vo.status eq 1}<span class="color-green">使用中</span>{/if}</td> <td class="text-left nowrap">{if $vo.status eq 0}<span class="color-red">已禁用</span>{elseif $vo.status eq 1}<span class="color-green">使用中</span>{/if}</td>
<td class="text-left nowrap">{$vo.create_at|format_datetime}</td> <td class="text-left nowrap">{$vo.create_at|format_datetime}</td>
<td class='text-left nowrap'> <td class='text-left nowrap'><a class="layui-btn layui-btn-sm layui-btn-normal" data-news="{$vo.id}">选择文章</a></td>
<a class="layui-btn layui-btn-sm layui-btn-normal" data-article="{$vo.id}">选择文章</a>
</td>
</tr> </tr>
{/foreach} {/foreach}
</tbody> </tbody>
@ -37,8 +33,8 @@
<script> <script>
$(function () { $(function () {
layui.form.render(); layui.form.render();
$('[data-article]').on('click', function () { $('[data-news]').on('click', function () {
top.setAttackId(this.getAttribute('data-article') || ''); top.setNewsId(this.getAttribute('data-news') || '');
parent.layer.close(parent.layer.getFrameIndex(window.name)); parent.layer.close(parent.layer.getFrameIndex(window.name));
}); });
$.form.reInit($('[data-select-container]')); $.form.reInit($('[data-select-container]'));

View File

@ -1,15 +1,12 @@
{extend name="../../admin/view/main"} {extend name="../../admin/view/main"}
{block name="button"} {block name="button"}
<!--{if auth("add")}-->
{if auth("add")}
<button data-modal='{:url("add")}' data-title="添加标签" class='layui-btn layui-btn-sm layui-btn-primary'>添加标签</button> <button data-modal='{:url("add")}' data-title="添加标签" class='layui-btn layui-btn-sm layui-btn-primary'>添加标签</button>
{/if} <!--{/if}-->
<!--{if auth("remove")}-->
{if auth("remove")}
<button data-action='{:url("remove")}' data-rule="id#{key}" data-confirm="确定要删除这些标签吗?" class='layui-btn layui-btn-sm layui-btn-primary'>删除标签</button> <button data-action='{:url("remove")}' data-rule="id#{key}" data-confirm="确定要删除这些标签吗?" class='layui-btn layui-btn-sm layui-btn-primary'>删除标签</button>
{/if} <!--{/if}-->
{/block} {/block}
{block name='content'} {block name='content'}
@ -17,7 +14,7 @@
<p class=" margin-bottom-15"> <p class=" margin-bottom-15">
演示接口文档:<a target="_blank" href="http://www.docway.net/project/1WkI0ZyQ7M1/share/1Wld0z7b1zE">http://www.docway.net/project/1WkI0ZyQ7M1/share/1Wld0z7b1zE</a> 演示接口文档:<a target="_blank" href="http://www.docway.net/project/1WkI0ZyQ7M1/share/1Wld0z7b1zE">http://www.docway.net/project/1WkI0ZyQ7M1/share/1Wld0z7b1zE</a>
</p> </p>
{include file='article_tags/index_search'} {include file='news_mark/index_search'}
<table class="layui-table margin-top-10" lay-skin="line"> <table class="layui-table margin-top-10" lay-skin="line">
{notempty name='list'} {notempty name='list'}
<thead> <thead>

2
vendor/services.php vendored
View File

@ -1,5 +1,5 @@
<?php <?php
// This file is automatically generated at:2020-09-02 11:49:20 // This file is automatically generated at:2020-09-02 14:11:14
declare (strict_types = 1); declare (strict_types = 1);
return array ( return array (
0 => 'think\\admin\\Library', 0 => 'think\\admin\\Library',