ArticleRepository.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace app\common\repositories\article;
  3. use app\common\dao\article\ArticleDao;
  4. use app\common\model\article\ArticleContent;
  5. use app\common\repositories\BaseRepository;
  6. use think\facade\Db;
  7. class ArticleRepository extends BaseRepository
  8. {
  9. public function __construct(ArticleDao $dao)
  10. {
  11. $this->dao = $dao;
  12. }
  13. public function getFormatList($merId = 0)
  14. {
  15. return $this->dao->getAll($merId)->toArray();
  16. }
  17. /**
  18. * @param int $merId
  19. * @param array $where
  20. * @param $page
  21. * @param $limit
  22. * @return array
  23. * @author Qinii
  24. */
  25. public function search(int $merId, array $where, $page, $limit)
  26. {
  27. $where['wechat_news_id'] = 0;
  28. $query = $this->dao->search($merId, $where);
  29. $count = $query->count($this->dao->getPk());
  30. $list = $query->page($page, $limit)->hidden(['update_time'])->select();
  31. return compact('count', 'list');
  32. }
  33. /**
  34. * 根据主键查询
  35. * @param int $merId
  36. * @param int $id
  37. * @param null $except
  38. * @return bool
  39. * @author Qinii
  40. */
  41. public function merExists(int $merId, int $id, $except = null)
  42. {
  43. return $this->dao->merFieldExists($merId, $this->dao->getPk(), $id, $except);
  44. }
  45. public function merApiExists(int $id)
  46. {
  47. return $this->dao->getWhere([$this->dao->getPk() => $id,'status' => 1]);
  48. }
  49. public function clearByNewId($newId)
  50. {
  51. Db::transaction(function()use($newId){
  52. $article_id = $this->dao->search(0,['wechat_news_id' => $newId])->column('article_id');
  53. foreach ($article_id as $item){
  54. $this->dao->delete($item,0);
  55. }
  56. });
  57. }
  58. }