ArticleRepository.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\repositories\article;
  12. use app\common\dao\article\ArticleDao;
  13. use app\common\model\article\ArticleContent;
  14. use app\common\repositories\BaseRepository;
  15. use think\facade\Db;
  16. /**
  17. * 文章内容
  18. */
  19. class ArticleRepository extends BaseRepository
  20. {
  21. public function __construct(ArticleDao $dao)
  22. {
  23. $this->dao = $dao;
  24. }
  25. public function getFormatList($merId = 0)
  26. {
  27. return $this->dao->getAll($merId)->toArray();
  28. }
  29. /**
  30. * 列表搜索
  31. * @param int $merId
  32. * @param array $where
  33. * @param $page
  34. * @param $limit
  35. * @return array
  36. * @author Qinii
  37. */
  38. public function search(int $merId, array $where, $page, $limit)
  39. {
  40. $where['wechat_news_id'] = 0;
  41. $query = $this->dao->search($merId, $where)->order('create_time DESC');
  42. $count = $query->count($this->dao->getPk());
  43. $list = $query->page($page, $limit)->hidden(['update_time'])->select();
  44. return compact('count', 'list');
  45. }
  46. /**
  47. * 根据主键查询
  48. * @param int $merId
  49. * @param int $id
  50. * @param null $except
  51. * @return bool
  52. * @author Qinii
  53. */
  54. public function merExists(int $merId, int $id, $except = null)
  55. {
  56. return $this->dao->merFieldExists($merId, $this->dao->getPk(), $id, $except);
  57. }
  58. /**
  59. * 根据主键查询开启的文章
  60. * @param int $id
  61. * @return array|\think\Model|null
  62. * @throws \think\db\exception\DataNotFoundException
  63. * @throws \think\db\exception\DbException
  64. * @throws \think\db\exception\ModelNotFoundException
  65. * @author wuhaotian
  66. * @email 442384644@qq.com
  67. * @date 2024/7/5
  68. */
  69. public function merApiExists(int $id)
  70. {
  71. return $this->dao->getWhere([$this->dao->getPk() => $id, 'status' => 1]);
  72. }
  73. /**
  74. * 根据微信文章id查询删除
  75. * @param int $newId
  76. * @return array|\think\Model|null
  77. * @throws \think\db\exception\DataNotFoundException
  78. * @throws \think\db\exception\DbException
  79. * @throws \think\db\exception\ModelNotFoundException
  80. * @author wuhaotian
  81. * @email 442384644@qq.com
  82. * @date 2024/7/5
  83. */
  84. public function clearByNewId($newId)
  85. {
  86. Db::transaction(function () use ($newId) {
  87. $article_id = $this->dao->search(0, ['wechat_news_id' => $newId])->column('article_id');
  88. foreach ($article_id as $item) {
  89. $this->dao->delete($item, 0);
  90. }
  91. });
  92. }
  93. }