ArticleRepository.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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. class ArticleRepository extends BaseRepository
  17. {
  18. public function __construct(ArticleDao $dao)
  19. {
  20. $this->dao = $dao;
  21. }
  22. public function getFormatList($merId = 0)
  23. {
  24. return $this->dao->getAll($merId)->toArray();
  25. }
  26. /**
  27. * @param int $merId
  28. * @param array $where
  29. * @param $page
  30. * @param $limit
  31. * @return array
  32. * @author Qinii
  33. */
  34. public function search(int $merId, array $where, $page, $limit)
  35. {
  36. $where['wechat_news_id'] = 0;
  37. $query = $this->dao->search($merId, $where);
  38. $count = $query->count($this->dao->getPk());
  39. $list = $query->page($page, $limit)->hidden(['update_time'])->select();
  40. return compact('count', 'list');
  41. }
  42. /**
  43. * 根据主键查询
  44. * @param int $merId
  45. * @param int $id
  46. * @param null $except
  47. * @return bool
  48. * @author Qinii
  49. */
  50. public function merExists(int $merId, int $id, $except = null)
  51. {
  52. return $this->dao->merFieldExists($merId, $this->dao->getPk(), $id, $except);
  53. }
  54. public function merApiExists(int $id)
  55. {
  56. return $this->dao->getWhere([$this->dao->getPk() => $id,'status' => 1]);
  57. }
  58. public function clearByNewId($newId)
  59. {
  60. Db::transaction(function()use($newId){
  61. $article_id = $this->dao->search(0,['wechat_news_id' => $newId])->column('article_id');
  62. foreach ($article_id as $item){
  63. $this->dao->delete($item,0);
  64. }
  65. });
  66. }
  67. }