first commit
This commit is contained in:
146
application/mobile/controller/Article.php
Normal file
146
application/mobile/controller/Article.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\mobile\controller;
|
||||
|
||||
use app\common\model\Article as ArticleModel;
|
||||
use app\common\model\MemberInfo as MemberInfoModel;
|
||||
use app\common\service\Article as ArticleService;
|
||||
|
||||
class Article extends _Init
|
||||
{
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->nav = 1;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$map = [
|
||||
'uid' => UID,
|
||||
'status' => 1,
|
||||
];
|
||||
$list = ArticleModel::where($map)->order("id desc")->paginate(10);
|
||||
$this->assign('list', $list);
|
||||
if (IS_AJAX) {
|
||||
if (count($list) > 0) {
|
||||
return $this->success($this->fetch('article/lists'));
|
||||
} else {
|
||||
return $this->error('已经到最后一页');
|
||||
}
|
||||
}
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$info = ArticleModel::find($id);
|
||||
if (!empty($info)) {
|
||||
$info->setInc('click');
|
||||
}
|
||||
$this->assign('info', $info);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$data = $this->request->post();
|
||||
$data['uid'] = UID;
|
||||
$res = ArticleService::userAdd($data);
|
||||
if ($res === true) {
|
||||
return $this->success('发布成功', url('mobile/article/index'));
|
||||
} else {
|
||||
return $this->error('发布失败,' . $res);
|
||||
}
|
||||
} else {
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
public function edit($id = '')
|
||||
{
|
||||
if (IS_POST) {
|
||||
$data = $this->request->post();
|
||||
$info = ArticleModel::find($data['id'] ?: 0);
|
||||
|
||||
if ($info) {
|
||||
unset($data['id']);
|
||||
if ($info->save($data)) {
|
||||
return $this->success('发表成功', url('mobile/article/index'));
|
||||
} else {
|
||||
return $this->error('发表失败');
|
||||
}
|
||||
} else {
|
||||
return $this->error('您修改的文章已不存在');
|
||||
}
|
||||
} else {
|
||||
$info = ArticleModel::find($id);
|
||||
if ($info->uid != UID) {
|
||||
$this->redirect(url('center/index'));
|
||||
}
|
||||
$this->assign('info', $info);
|
||||
return $this->fetch('add');
|
||||
}
|
||||
}
|
||||
|
||||
public function collect()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$info = MemberInfoModel::get(UID);
|
||||
if (!$info->is_vip) {
|
||||
return $this->error('采集失败,您还不是VIP。', url('vip/index'));
|
||||
}
|
||||
$url = $this->request->post('url') ?: '';
|
||||
if ($url) {
|
||||
if (!preg_match('/(http:\/\/)|(https:\/\/)/i', $url)) {
|
||||
return $this->error('您粘贴的地址不正确!');
|
||||
}
|
||||
if (!preg_match('/(mp.weixin.qq.com)/i', $url)) {
|
||||
return $this->error('您粘贴的地址不是微信文章地址!');
|
||||
}
|
||||
$id = ArticleService::collect($url, UID);
|
||||
if ($id) {
|
||||
return $this->success('采集成功', url('mobile/article/edit', 'id=' . $id));
|
||||
} else {
|
||||
return $this->error('采集失败');
|
||||
}
|
||||
} else {
|
||||
return $this->error('请输入文章地址');
|
||||
}
|
||||
} else {
|
||||
$this->nav = 2;
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
public function del($id)
|
||||
{
|
||||
if (IS_AJAX) {
|
||||
$info = ArticleModel::find($id);
|
||||
if ($info->uid != UID) {
|
||||
return $this->error('非法操作');
|
||||
} else {
|
||||
if ($info->delete()) {
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->error('删除失败');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return $this->error('请不要非法访问');
|
||||
}
|
||||
}
|
||||
|
||||
public function video()
|
||||
{
|
||||
$this->meta_title = '发布文章视频教程';
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user