Article.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\common\model\article;
  15. use app\common\enum\YesNoEnum;
  16. use app\common\model\BaseModel;
  17. use think\model\concern\SoftDelete;
  18. /**
  19. * 资讯管理模型
  20. * Class Article
  21. * @package app\common\model\article;
  22. */
  23. class Article extends BaseModel
  24. {
  25. use SoftDelete;
  26. protected $deleteTime = 'delete_time';
  27. /**
  28. * @notes 获取分类名称
  29. * @param $value
  30. * @param $data
  31. * @return string
  32. * @author heshihu
  33. * @date 2022/2/22 9:53
  34. */
  35. public function getCateNameAttr($value, $data)
  36. {
  37. return ArticleCate::where('id', $data['cid'])->value('name');
  38. }
  39. /**
  40. * @notes 浏览量
  41. * @param $value
  42. * @param $data
  43. * @return mixed
  44. * @author 段誉
  45. * @date 2022/9/15 11:33
  46. */
  47. public function getClickAttr($value, $data)
  48. {
  49. return $data['click_actual'] + $data['click_virtual'];
  50. }
  51. /**
  52. * @notes 设置图片域名
  53. * @param $value
  54. * @param $data
  55. * @return array|string|string[]|null
  56. * @author 段誉
  57. * @date 2022/9/28 10:17
  58. */
  59. public function getContentAttr($value, $data)
  60. {
  61. return get_file_domain($value);
  62. }
  63. /**
  64. * @notes 清除图片域名
  65. * @param $value
  66. * @param $data
  67. * @return array|string|string[]
  68. * @author 段誉
  69. * @date 2022/9/28 10:17
  70. */
  71. public function setContentAttr($value, $data)
  72. {
  73. return clear_file_domain($value);
  74. }
  75. /**
  76. * @notes 获取文章详情
  77. * @param $id
  78. * @return array
  79. * @author 段誉
  80. * @date 2022/10/20 15:23
  81. */
  82. public static function getArticleDetailArr(int $id)
  83. {
  84. $article = Article::where(['id' => $id, 'is_show' => YesNoEnum::YES])
  85. ->findOrEmpty();
  86. if ($article->isEmpty()) {
  87. return [];
  88. }
  89. // 增加点击量
  90. $article->click_actual += 1;
  91. $article->save();
  92. return $article->append(['click'])
  93. ->hidden(['click_virtual', 'click_actual'])
  94. ->toArray();
  95. }
  96. }