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.
|
|
<?php namespace App\Http\Controllers\Api; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\DB; use Illuminate\Http\Request; use App\Common\ReturnData; use App\Common\Helper; use App\Common\Token; use App\Http\Model\Article; use App\Http\Logic\ArticleLogic;
class ArticleController extends BaseController { public function __construct() { parent::__construct(); } public function getLogic() { return logic('Article'); } public function articleList(Request $request) { //参数
$limit = $request->input('limit', 10); $offset = $request->input('offset', 0); if($request->input('typeid', null) != null){$where['typeid'] = $request->input('typeid');} $where['ischeck'] = Article::IS_CHECK; $res = $this->getLogic()->getList($where, array('id', 'desc'), '*', $offset, $limit);
if($res['count']>0) { foreach($res['list'] as $k=>$v) { $res['list'][$k]->article_detail_url = route('weixin_article_detail',array('id'=>$v->id)); $res['list'][$k]->url = get_front_url(array("id"=>$v->id,"type"=>'content')); $res['list'][$k]->pubdatetext = date("Y-m-d", $v->pubdate);
} } return ReturnData::create(ReturnData::SUCCESS,$res); } public function articleDetail(Request $request) { //参数
if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);} $id = $request->input('id'); $where['id'] = $id; $where['ischeck'] = Article::IS_CHECK; $res = $this->getLogic()->getOne($where); if(!$res) { return ReturnData::create(ReturnData::RECORD_NOT_EXIST); } //$res->pubdate = date('Y-m-d H:i',$res->pubdate);
//$res->addtime = date('Y-m-d H:i',$res->addtime);
return ReturnData::create(ReturnData::SUCCESS,$res); } //添加
public function articleAdd(Request $request) { if(Helper::isPostRequest()) { $_POST['user_id'] = Token::$uid; return $this->getLogic()->add($_POST); } } //修改
public function articleUpdate(Request $request) { if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);} $id = $request->input('id'); if(Helper::isPostRequest()) { unset($_POST['id']); $where['id'] = $id; //$where['user_id'] = Token::$uid;
return $this->getLogic()->edit($_POST,$where); } } //删除
public function articleDelete(Request $request) { if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);} $id = $request->input('id'); if(Helper::isPostRequest()) { $where['id'] = $id; //$where['user_id'] = Token::$uid;
return $this->getLogic()->del($where); } } }
|