ArticleRepository.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020-04-20
  7. *
  8. *
  9. */
  10. namespace app\common\repositories\article;
  11. use app\common\dao\article\ArticleDao;
  12. use app\common\model\article\ArticleContent;
  13. use app\common\repositories\BaseRepository;
  14. use think\facade\Db;
  15. class ArticleRepository extends BaseRepository
  16. {
  17. public function __construct(ArticleDao $dao)
  18. {
  19. $this->dao = $dao;
  20. }
  21. public function getFormatList($merId = 0)
  22. {
  23. return $this->dao->getAll($merId)->toArray();
  24. }
  25. /**
  26. * 一对一关联保存
  27. * @param $data
  28. * @return mixed
  29. * @author Qinii
  30. */
  31. public function create($data)
  32. {
  33. return $this->dao->create($data);
  34. }
  35. /**
  36. * 一对一 关联更新
  37. * @param $id
  38. * @param $data
  39. * @author Qinii
  40. */
  41. public function update($id,$data)
  42. {
  43. return $this->dao->update($id,$data);
  44. }
  45. /**
  46. * 关联删除
  47. * @param int $id
  48. * @param int $merId
  49. * @throws \think\db\exception\DataNotFoundException
  50. * @throws \think\db\exception\DbException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. * @author Qinii
  53. */
  54. public function delete(int $id,$merId = 0)
  55. {
  56. return $this->dao->delete($id,$merId);
  57. $article = $this->dao->get($id,$merId);
  58. $article->together(['content'])->delete();
  59. }
  60. /**
  61. * @param int $merId
  62. * @param array $where
  63. * @param $page
  64. * @param $limit
  65. * @return array
  66. * @author Qinii
  67. */
  68. public function search(int $merId, array $where, $page, $limit)
  69. {
  70. $query = $this->dao->search($merId, $where);
  71. $count = $query->count($this->dao->getPk());
  72. $list = $query->page($page, $limit)->hidden(['update_time'])->order("create_time desc")->select()->toArray();
  73. foreach($list as $k=>$v){
  74. $cate = Db::name("article_category")
  75. ->where('article_category_id',$v['articleCategory']['pid'])
  76. ->field("article_category_id,title")
  77. ->find();
  78. $list[$k]['articleCategory']['title'] = $cate['title'].'-'.$v['articleCategory']['title'];
  79. }
  80. return compact('count', 'list');
  81. }
  82. /**
  83. * 根据主键查询
  84. * @param int $merId
  85. * @param int $id
  86. * @param null $except
  87. * @return bool
  88. * @author Qinii
  89. */
  90. public function merExists(int $merId, int $id, $except = null)
  91. {
  92. return $this->dao->merFieldExists($merId, $this->dao->getPk(), $id, $except);
  93. }
  94. public function merApiExists(int $id)
  95. {
  96. return $this->dao->getWhere([$this->dao->getPk() => $id,'status' => 1]);
  97. }
  98. /**
  99. 创建公告
  100. */
  101. public function noticeCreate($data)
  102. {
  103. return Db::name("notice")->insert($data);
  104. }
  105. /*系统公告详情*/
  106. public function noticeExists(int $id)
  107. {
  108. return Db::name("notice")->where(['is_del'=>0,'notice_id'=>$id])->find();
  109. }
  110. /*系统公告详情*/
  111. public function noticeExist(int $id)
  112. {
  113. $data=Db::name("notice")->where(['notice_id'=>$id])->find();
  114. if($data){
  115. $data['status']=(int)$data['status'];
  116. }
  117. return $data;
  118. }
  119. /*系统公告删除*/
  120. public function noticeDelete(int $id)
  121. {
  122. return Db::name("notice")->where(['notice_id'=>$id])->update(['is_del'=>1]);
  123. }
  124. /*修改公告*/
  125. public function noticeUpdate($id,$data)
  126. {
  127. return Db::name("notice")->where(['notice_id'=>$id])->update($data);
  128. }
  129. /*系统公告*/
  130. public function notice($where=[],$page, $limit){
  131. $query = Db::name("notice");
  132. $count = $query->where($where)->count();
  133. $list = $query->page($page, $limit)->where($where)->select()->each(function ($item){
  134. $item['status']=(int)$item['status'];
  135. return $item;
  136. });
  137. return compact('count', 'list');
  138. }
  139. }