diff --git a/application/wechat/controller/Fans.php b/application/wechat/controller/Fans.php index 72efe9dd7..3ad6eff7c 100644 --- a/application/wechat/controller/Fans.php +++ b/application/wechat/controller/Fans.php @@ -15,6 +15,7 @@ namespace app\wechat\controller; use controller\BasicAdmin; +use service\LogService; use service\WechatService; use think\Db; diff --git a/application/wechat/controller/News.php b/application/wechat/controller/News.php index 84de693e2..3de6c681f 100644 --- a/application/wechat/controller/News.php +++ b/application/wechat/controller/News.php @@ -14,6 +14,8 @@ namespace app\wechat\controller; use controller\BasicAdmin; +use service\DataService; +use think\Db; /** * 微信图文管理 @@ -24,7 +26,54 @@ use controller\BasicAdmin; */ class News extends BasicAdmin { - public function index() { + /** + * 设置默认操作表 + * @var string + */ + protected $table = 'WechatNews'; + public function add() { + if ($this->request->isGet()) { + $this->assign('title', '新建图文'); + return view('form'); + } + if ($this->request->isPost()) { + $data = $this->request->post(); + if (($ids = $this->_apply_news_article($data['data'])) && !empty($ids)) { + $post = ['article_id' => $ids, 'create_by' => session('user.id')]; + if (DataService::save($this->table, $post, 'id') !== FALSE) { + $this->success('图文添加成功!', url('@wechat/news')); + } + } + $this->error('图文添加失败,请稍候再试!'); + } + } + + /** + * 图文更新操作 + * @param array $data + * @param array $ids + * @return string + */ + protected function _apply_news_article($data, $ids = []) { + foreach ($data as &$vo) { + $vo['create_by'] = session('user.id'); + $vo['create_at'] = date('Y-m-d H:i:s'); + $vo['digest'] = empty($vo['digest']) ? mb_substr(strip_tags($vo['content']), 0, 120) : $vo['digest']; + if (empty($vo['id'])) { + $result = $id = Db::name('WechatNewsArticle')->insertGetId($vo); + } else { + $id = intval($vo['id']); + $result = Db::name('WechatNewsArticle')->where('id', $id)->update($vo); + } + if ($result !== FALSE) { + $ids[] = $id; + } + } + return join(',', $ids); + } + + public function select() { + return '开发中'; } } diff --git a/application/wechat/view/news.form.html b/application/wechat/view/news.form.html new file mode 100644 index 000000000..ff896686c --- /dev/null +++ b/application/wechat/view/news.form.html @@ -0,0 +1,362 @@ +{extend name='extra@admin/content' /} + +{block name="style"} + +{/block} + +{block name='content'} +