修改微信图文

This commit is contained in:
Anyon 2019-12-14 15:07:03 +08:00
parent 8610fece9c
commit 9bfd5eed5c
2 changed files with 19 additions and 21 deletions

View File

@ -50,12 +50,12 @@ class News extends Controller
* 图文列表数据处理 * 图文列表数据处理
* @param array $data * @param array $data
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/ */
protected function _index_page_filter(&$data) protected function _index_page_filter(&$data)
{ {
foreach ($data as &$vo) $vo = MediaService::news($vo['id']); foreach ($data as &$vo) $vo = MediaService::instance()->news($vo['id']);
} }
/** /**
@ -75,12 +75,12 @@ class News extends Controller
* 图文列表数据处理 * 图文列表数据处理
* @param array $data * @param array $data
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/ */
protected function _select_page_filter(&$data) protected function _select_page_filter(&$data)
{ {
foreach ($data as &$vo) $vo = MediaService::news($vo['id']); foreach ($data as &$vo) $vo = MediaService::instance()->news($vo['id']);
} }
/** /**
@ -98,7 +98,7 @@ class News extends Controller
$this->fetch('form'); $this->fetch('form');
} else { } else {
$data = $this->request->post(); $data = $this->request->post();
if (($ids = $this->_apply_news_article($data['data'])) && !empty($ids)) { if (($ids = $this->_buildArticle($data['data'])) && !empty($ids)) {
if (data_save($this->table, ['article_id' => $ids, 'create_by' => session('user.id')], 'id') !== false) { if (data_save($this->table, ['article_id' => $ids, 'create_by' => session('user.id')], 'id') !== false) {
$url = url('@admin') . '#' . url('@wechat/news/index') . '?spm=' . $this->request->get('spm'); $url = url('@admin') . '#' . url('@wechat/news/index') . '?spm=' . $this->request->get('spm');
$this->success('图文添加成功!', $url); $this->success('图文添加成功!', $url);
@ -111,7 +111,6 @@ class News extends Controller
/** /**
* 编辑微信图文 * 编辑微信图文
* @auth true * @auth true
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
@ -123,15 +122,15 @@ class News extends Controller
} }
if ($this->request->isGet()) { if ($this->request->isGet()) {
if ($this->request->get('output') === 'json') { if ($this->request->get('output') === 'json') {
$this->success('获取数据成功!', MediaService::news($this->id)); $this->success('获取数据成功!', MediaService::instance()->news($this->id));
} else { } else {
$this->fetch('form', ['title' => '编辑图文']); $this->fetch('form', ['title' => '编辑图文']);
} }
} else { } else {
$post = $this->request->post(); $post = $this->request->post();
if (isset($post['data']) && ($ids = $this->_apply_news_article($post['data']))) { if (isset($post['data']) && ($ids = $this->_buildArticle($post['data']))) {
if (data_save('wechat_news', ['id' => $this->id, 'article_id' => $ids], 'id')) { if (data_save('wechat_news', ['id' => $this->id, 'article_id' => $ids], 'id')) {
$this->success('图文更新成功!', url('@admin') . '#' . url('@wechat/news/index')); $this->success('图文更新成功!', 'javascript:history.back()');
} }
} }
$this->error('图文更新失败,请稍候再试!'); $this->error('图文更新失败,请稍候再试!');
@ -143,8 +142,9 @@ class News extends Controller
* @param array $data * @param array $data
* @param array $ids * @param array $ids
* @return string * @return string
* @throws \think\db\exception\DbException
*/ */
private function _apply_news_article($data, $ids = []) private function _buildArticle($data, $ids = [])
{ {
foreach ($data as &$vo) { foreach ($data as &$vo) {
if (empty($vo['digest'])) { if (empty($vo['digest'])) {
@ -152,10 +152,10 @@ class News extends Controller
} }
$vo['create_at'] = date('Y-m-d H:i:s'); $vo['create_at'] = date('Y-m-d H:i:s');
if (empty($vo['id'])) { if (empty($vo['id'])) {
$result = $id = Db::name('WechatNewsArticle')->insertGetId($vo); $result = $id = $this->app->db->name('WechatNewsArticle')->insertGetId($vo);
} else { } else {
$id = intval($vo['id']); $id = intval($vo['id']);
$result = Db::name('WechatNewsArticle')->where('id', $id)->update($vo); $result = $this->app->db->name('WechatNewsArticle')->where('id', $id)->update($vo);
} }
if ($result !== false) { if ($result !== false) {
array_push($ids, $id); array_push($ids, $id);

View File

@ -99,11 +99,7 @@
function apply(list) { function apply(list) {
if (list.length < 1) list.push({ if (list.length < 1) list.push({
title: '新建图文', title: '新建图文', author: '管理员', content: '文章内容', read_num: 0, local_url: '__ROOT__/static/theme/img/image.png',
author: '管理员',
content: '文章内容',
read_num: 0,
local_url: '__ROOT__/static/theme/img/image.png',
}); });
for (var i in list) { for (var i in list) {
list[i].active = false; list[i].active = false;
@ -116,7 +112,7 @@
$vali.checkAllInput(); $vali.checkAllInput();
editor.setData($rootScope.item.content); editor.setData($rootScope.item.content);
$('.layui-card-body.layui-hide').removeClass('layui-hide'); $('.layui-card-body.layui-hide').removeClass('layui-hide');
}, 100); }, 200);
} }
$rootScope.upItem = function (index, $event) { $rootScope.upItem = function (index, $event) {
@ -171,7 +167,9 @@
}; };
$rootScope.addItem = function () { $rootScope.addItem = function () {
if ($rootScope.list.length > 7) return $.msg.tips('最多允许增加7篇文章哦'); if ($rootScope.list.length > 7) {
return $.msg.tips('最多允许增加7篇文章哦');
}
$rootScope.list.push({ $rootScope.list.push({
title: '新建图文', title: '新建图文',
author: '管理员', author: '管理员',
@ -203,8 +201,8 @@
$.form.load('{:request()->url()}', {data: data}, "post"); $.form.load('{:request()->url()}', {data: data}, "post");
}; };
$('[name="local_url"]').on('change', function () { $('[name="local_url"]').on('change', function (value) {
var value = this.value; value = this.value;
$rootScope.$apply(function () { $rootScope.$apply(function () {
$rootScope.setItemValue('local_url', value); $rootScope.setItemValue('local_url', value);
}); });