MArticle.Class.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: phperstar
  5. * Date: 2020/2/11
  6. * Time: 下午3:38
  7. */
  8. namespace JinDouYun\Model\Manage;
  9. use Mall\Framework\Core\ErrorCode;
  10. use Mall\Framework\Core\ResultWrapper;
  11. use JinDouyun\Dao\Manage\DArticle;
  12. use Mall\Framework\Core\StatusCode;
  13. class MArticle
  14. {
  15. protected $objDArticle;
  16. public function __construct()
  17. {
  18. $this->objDArticle = new DArticle();
  19. }
  20. // 添加文章
  21. public function addArticle($params)
  22. {
  23. $dbResult = $this->objDArticle->insert($params);
  24. if($dbResult === false){
  25. return ResultWrapper::fail($this->objDArticle->error(), ErrorCode::$dberror);
  26. }else{
  27. return ResultWrapper::success($dbResult);
  28. }
  29. }
  30. // 修改文章删除状态
  31. public function deleteArticle($params)
  32. {
  33. $dbResult = $this->objDArticle->update(['deleteStatus'=>StatusCode::$delete], $params['id']);
  34. if($dbResult === false){
  35. return ResultWrapper::fail($this->objDArticle->error(), ErrorCode::$dberror);
  36. }else{
  37. return ResultWrapper::success($dbResult);
  38. }
  39. }
  40. // 获取指定频道下所有的文章
  41. public function getListByCategory($categoryId, $selectParams)
  42. {
  43. $conditon = [
  44. 'deleteStatus' => StatusCode::$standard,
  45. ];
  46. if($categoryId){
  47. $conditon['categoryId'] = $categoryId;
  48. }
  49. $dbResult = $this->objDArticle->select($conditon, 'id,title,createTime,image,description,content', 'id desc', $selectParams['limit'],$selectParams['offset']);
  50. if($dbResult === false){
  51. return ResultWrapper::fail($this->objDArticle->error(), ErrorCode::$dberror);
  52. }
  53. $total = $this->objDArticle->count($conditon);
  54. $returnData = [
  55. 'data' => $dbResult,
  56. 'total' => $total ? $total : 0,
  57. ];
  58. return ResultWrapper::success($returnData);
  59. }
  60. // 获取指定文章信息
  61. public function getArticleInfo($params)
  62. {
  63. $dbResult = $this->objDArticle->get($params);
  64. if ($dbResult === false) {
  65. return ResultWrapper::fail($this->objDArticle->error(), ErrorCode::$dberror);
  66. } else {
  67. return ResultWrapper::success($dbResult);
  68. }
  69. }
  70. // 修改文章信息
  71. public function editArticle($params)
  72. {
  73. if (empty($params['id'])) {
  74. return ResultWrapper::fail('没有指定要修改的文章id', ErrorCode::$paramError);
  75. }
  76. $dbResult = $this->objDArticle->update($params, $params['id']);
  77. if ($dbResult === false) {
  78. return ResultWrapper::fail($this->objDArticle->error(), ErrorCode::$dberror);
  79. } else {
  80. return ResultWrapper::success($dbResult);
  81. }
  82. }
  83. }