SmsRecordDao.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace app\common\dao\system\sms;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\BaseModel;
  5. use app\common\model\system\sms\SmsRecord;
  6. use think\db\BaseQuery;
  7. use think\db\exception\DbException;
  8. /**
  9. * Class SmsRecordDao
  10. * @package app\common\dao\system\sms
  11. * @author zfy
  12. * @day 2020-05-18
  13. */
  14. class SmsRecordDao extends BaseDao
  15. {
  16. /**
  17. * @return BaseModel
  18. * @author zfy
  19. * @day 2020-03-30
  20. */
  21. protected function getModel(): string
  22. {
  23. return SmsRecord::class;
  24. }
  25. /**
  26. * @param array $where
  27. * @return BaseQuery
  28. * @author zfy
  29. * @day 2020-05-18
  30. */
  31. public function search(array $where)
  32. {
  33. return SmsRecord::getDB()->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) {
  34. $query->where('resultcode', $where['type']);
  35. })->order('create_time DESC');
  36. }
  37. /**
  38. * @return int
  39. * @author zfy
  40. * @day 2020-05-18
  41. */
  42. public function count()
  43. {
  44. return SmsRecord::count($this->getPk());
  45. }
  46. /**
  47. * @param $record_id
  48. * @param $resultcode
  49. * @return int
  50. * @throws DbException
  51. * @author zfy
  52. * @day 2020-05-18
  53. */
  54. public function updateRecordStatus($record_id, $resultcode)
  55. {
  56. return SmsRecord::getDB()->where('record_id', $record_id)->update(['resultcode' => $resultcode]);
  57. }
  58. /**
  59. * @param $time
  60. * @return array
  61. * @author zfy
  62. * @day 2020/6/9
  63. */
  64. public function getTimeOutIds($time)
  65. {
  66. return SmsRecord::getDB()->where('resultcode', null)->where('create_time', '<=', $time)->column('record_id');
  67. }
  68. }