WechatReplyDao.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020-04-24
  7. *
  8. *
  9. */
  10. namespace app\common\dao\wechat;
  11. use app\common\dao\BaseDao;
  12. use app\common\model\BaseModel;
  13. use app\common\model\wechat\WechatReply;
  14. use think\db\BaseQuery;
  15. use think\db\exception\DataNotFoundException;
  16. use think\db\exception\DbException;
  17. use think\db\exception\ModelNotFoundException;
  18. use think\Model;
  19. /**
  20. * Class WechatReplyDao
  21. * @package app\common\dao\wechat
  22. * @author xaboy
  23. * @day 2020-04-24
  24. */
  25. class WechatReplyDao extends BaseDao
  26. {
  27. /**
  28. * @return BaseModel
  29. * @author xaboy
  30. * @day 2020-03-30
  31. */
  32. protected function getModel(): string
  33. {
  34. return WechatReply::class;
  35. }
  36. /**
  37. * @param string $key
  38. * @return array|Model|null
  39. * @throws DataNotFoundException
  40. * @throws DbException
  41. * @throws ModelNotFoundException
  42. * @author xaboy
  43. * @day 2020-04-24
  44. */
  45. public function keyByReply(string $key)
  46. {
  47. return WechatReply::where('key', $key)->find();
  48. }
  49. /**
  50. * @param array $where
  51. * @return BaseQuery
  52. * @author xaboy
  53. * @day 2020-04-24
  54. */
  55. public function search(array $where)
  56. {
  57. $query = WechatReply::getDB()->where('hidden', 0);
  58. if (isset($where['keyword']) && $where['keyword'])
  59. $query->whereLike('key', "%{$where['keyword']}%");
  60. return $query;
  61. }
  62. /**
  63. * @param int $id
  64. * @return int
  65. * @throws DbException
  66. * @author xaboy
  67. * @day 2020-04-24
  68. */
  69. public function delete(int $id)
  70. {
  71. return ($this->getModel())::getDB()->where($this->getPk(), $id)->where('hidden', 0)->delete();
  72. }
  73. /**
  74. * @param $key
  75. * @return array|Model|null
  76. * @throws DataNotFoundException
  77. * @throws DbException
  78. * @throws ModelNotFoundException
  79. * @author xaboy
  80. * @day 2020-04-27
  81. */
  82. public function keyByValidData($key)
  83. {
  84. return WechatReply::getDB()->where('key', $key)->where('status', 1)->find();
  85. }
  86. }