| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
- /**
- * @package merchant
- *
- * @author xaboy
- * @day 2020-04-20
- *
- *
- */
- namespace app\common\repositories\article;
- use app\common\dao\article\ArticleDao;
- use app\common\model\article\ArticleContent;
- use app\common\repositories\BaseRepository;
- use think\facade\Db;
- class ArticleRepository extends BaseRepository
- {
- public function __construct(ArticleDao $dao)
- {
- $this->dao = $dao;
- }
- public function getFormatList($merId = 0)
- {
- return $this->dao->getAll($merId)->toArray();
- }
- /**
- * 一对一关联保存
- * @param $data
- * @return mixed
- * @author Qinii
- */
- public function create($data)
- {
- return $this->dao->create($data);
- }
- /**
- * 一对一 关联更新
- * @param $id
- * @param $data
- * @author Qinii
- */
- public function update($id,$data)
- {
- return $this->dao->update($id,$data);
- }
- /**
- * 关联删除
- * @param int $id
- * @param int $merId
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @author Qinii
- */
- public function delete(int $id,$merId = 0)
- {
- return $this->dao->delete($id,$merId);
- $article = $this->dao->get($id,$merId);
- $article->together(['content'])->delete();
- }
- /**
- * @param int $merId
- * @param array $where
- * @param $page
- * @param $limit
- * @return array
- * @author Qinii
- */
- public function search(int $merId, array $where, $page, $limit)
- {
- $query = $this->dao->search($merId, $where);
- $count = $query->count($this->dao->getPk());
- $list = $query->page($page, $limit)->hidden(['update_time'])->order("create_time desc")->select()->toArray();
- foreach($list as $k=>$v){
- $cate = Db::name("article_category")
- ->where('article_category_id',$v['articleCategory']['pid'])
- ->field("article_category_id,title")
- ->find();
- $list[$k]['articleCategory']['title'] = $cate['title'].'-'.$v['articleCategory']['title'];
- }
- return compact('count', 'list');
- }
- /**
- * 根据主键查询
- * @param int $merId
- * @param int $id
- * @param null $except
- * @return bool
- * @author Qinii
- */
- public function merExists(int $merId, int $id, $except = null)
- {
- return $this->dao->merFieldExists($merId, $this->dao->getPk(), $id, $except);
- }
- public function merApiExists(int $id)
- {
- return $this->dao->getWhere([$this->dao->getPk() => $id,'status' => 1]);
- }
- /**
- 创建公告
- */
- public function noticeCreate($data)
- {
- return Db::name("notice")->insert($data);
- }
- /*系统公告详情*/
- public function noticeExists(int $id)
- {
- return Db::name("notice")->where(['is_del'=>0,'notice_id'=>$id])->find();
- }
- /*系统公告详情*/
- public function noticeExist(int $id)
- {
- $data=Db::name("notice")->where(['notice_id'=>$id])->find();
- if($data){
- $data['status']=(int)$data['status'];
- }
- return $data;
- }
- /*系统公告删除*/
- public function noticeDelete(int $id)
- {
- return Db::name("notice")->where(['notice_id'=>$id])->update(['is_del'=>1]);
- }
- /*修改公告*/
- public function noticeUpdate($id,$data)
- {
- return Db::name("notice")->where(['notice_id'=>$id])->update($data);
- }
- /*系统公告*/
- public function notice($where=[],$page, $limit){
- $query = Db::name("notice");
- $count = $query->where($where)->count();
- $list = $query->page($page, $limit)->where($where)->select()->each(function ($item){
- $item['status']=(int)$item['status'];
- return $item;
- });
- return compact('count', 'list');
- }
- }
|