WechatNewsDao.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. *
  4. * User: Qinii
  5. * Date: 2020-04-26
  6. * Time: 11:14
  7. */
  8. namespace app\common\dao\wechat;
  9. use app\common\dao\BaseDao;
  10. use app\common\model\wechat\WechatNews;
  11. class WechatNewsDao extends BaseDao
  12. {
  13. protected function getModel(): string
  14. {
  15. return WechatNews::class;
  16. }
  17. /**
  18. * 根据主键查询
  19. * @param int $merId
  20. * @param int $id
  21. * @param null $except
  22. * @return bool
  23. * @author Qinii
  24. */
  25. public function merExists(int $merId, int $id, $except = null)
  26. {
  27. return $this->merFieldExists($merId, $this->getPk(), $id, $except);
  28. }
  29. /**
  30. * 根据 字段名查询
  31. * @param int $merId
  32. * @param $field
  33. * @param $value
  34. * @param null $except
  35. * @return bool
  36. * @author Qinii
  37. */
  38. public function merFieldExists(int $merId, $field, $value, $except = null)
  39. {
  40. return ($this->getModel())::getDB()->when($except, function ($query, $except) use ($field) {
  41. $query->where($field, '<>', $except);
  42. })->where('mer_id', $merId)->where($field, $value)->count() > 0;
  43. }
  44. public function getAll(int $merId)
  45. {
  46. return ($this->getModel())::getDB()->where('mer_id',$merId)->with('article.content')->order('create_time DESC');
  47. }
  48. public function get( $id, int $merId = 0)
  49. {
  50. return ($this->getModel())::getDB()->where('mer_id',$merId)->with('article.content')->find($id);
  51. }
  52. }