123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- /**
- * Created by PhpStorm.
- * User: phperstar
- * Date: 2020/2/11
- * Time: 下午3:38
- */
- namespace JinDouYun\Model\Manage;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\ResultWrapper;
- use JinDouyun\Dao\Manage\DArticle;
- use Mall\Framework\Core\StatusCode;
- class MArticle
- {
- protected $objDArticle;
- public function __construct()
- {
- $this->objDArticle = new DArticle();
- }
- // 添加文章
- public function addArticle($params)
- {
- $dbResult = $this->objDArticle->insert($params);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDArticle->error(), ErrorCode::$dberror);
- }else{
- return ResultWrapper::success($dbResult);
- }
- }
- // 修改文章删除状态
- public function deleteArticle($params)
- {
- $dbResult = $this->objDArticle->update(['deleteStatus'=>StatusCode::$delete], $params['id']);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDArticle->error(), ErrorCode::$dberror);
- }else{
- return ResultWrapper::success($dbResult);
- }
- }
- // 获取指定频道下所有的文章
- public function getListByCategory($categoryId, $selectParams)
- {
- $conditon = [
- 'deleteStatus' => StatusCode::$standard,
- ];
- if($categoryId){
- $conditon['categoryId'] = $categoryId;
- }
- $dbResult = $this->objDArticle->select($conditon, 'id,title,createTime,image,description,content', 'id desc', $selectParams['limit'],$selectParams['offset']);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDArticle->error(), ErrorCode::$dberror);
- }
- $total = $this->objDArticle->count($conditon);
- $returnData = [
- 'data' => $dbResult,
- 'total' => $total ? $total : 0,
- ];
- return ResultWrapper::success($returnData);
- }
- // 获取指定文章信息
- public function getArticleInfo($params)
- {
- $dbResult = $this->objDArticle->get($params);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDArticle->error(), ErrorCode::$dberror);
- } else {
- return ResultWrapper::success($dbResult);
- }
- }
-
- // 修改文章信息
- public function editArticle($params)
- {
- if (empty($params['id'])) {
- return ResultWrapper::fail('没有指定要修改的文章id', ErrorCode::$paramError);
- }
- $dbResult = $this->objDArticle->update($params, $params['id']);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDArticle->error(), ErrorCode::$dberror);
- } else {
- return ResultWrapper::success($dbResult);
- }
- }
- }
|