WechatNewsDao.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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\dao\wechat;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\wechat\WechatNews;
  14. class WechatNewsDao extends BaseDao
  15. {
  16. protected function getModel(): string
  17. {
  18. return WechatNews::class;
  19. }
  20. /**
  21. * 根据主键查询
  22. * @param int $merId
  23. * @param int $id
  24. * @param null $except
  25. * @return bool
  26. * @author Qinii
  27. */
  28. public function merExists(int $merId, int $id, $except = null)
  29. {
  30. return $this->merFieldExists($merId, $this->getPk(), $id, $except);
  31. }
  32. /**
  33. * 根据 字段名查询
  34. * @param int $merId
  35. * @param $field
  36. * @param $value
  37. * @param null $except
  38. * @return bool
  39. * @author Qinii
  40. */
  41. public function merFieldExists(int $merId, $field, $value, $except = null)
  42. {
  43. return ($this->getModel())::getDB()->when($except, function ($query, $except) use ($field) {
  44. $query->where($field, '<>', $except);
  45. })->where('mer_id', $merId)->where($field, $value)->count() > 0;
  46. }
  47. public function getAll(array $where)
  48. {
  49. if(isset($where['cate_name']) && $where['cate_name'] !== ''){
  50. $query = WechatNews::hasWhere('article',function ($query)use($where){
  51. $query->whereLike('title',"%{$where['cate_name']}%");
  52. });
  53. }else{
  54. $query = WechatNews::alias('WechatNews');
  55. }
  56. $query->with('article');
  57. return $query->order('WechatNews.create_time DESC');
  58. }
  59. public function get( $id, int $merId = 0)
  60. {
  61. return ($this->getModel())::getDB()->where('mer_id',$merId)->with('article.content')->find($id);
  62. }
  63. }