WechatReplyDao.php 2.7 KB

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