SmsRecordDao.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\system\sms;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\BaseModel;
  14. use app\common\model\system\sms\SmsRecord;
  15. use think\db\BaseQuery;
  16. use think\db\exception\DbException;
  17. /**
  18. * Class SmsRecordDao
  19. * @package app\common\dao\system\sms
  20. * @author xaboy
  21. * @day 2020-05-18
  22. */
  23. class SmsRecordDao extends BaseDao
  24. {
  25. /**
  26. * @return BaseModel
  27. * @author xaboy
  28. * @day 2020-03-30
  29. */
  30. protected function getModel(): string
  31. {
  32. return SmsRecord::class;
  33. }
  34. /**
  35. * @param array $where
  36. * @return BaseQuery
  37. * @author xaboy
  38. * @day 2020-05-18
  39. */
  40. public function search(array $where)
  41. {
  42. return SmsRecord::getDB()->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) {
  43. $query->where('resultcode', $where['type']);
  44. })->order('create_time DESC');
  45. }
  46. /**
  47. * @return int
  48. * @author xaboy
  49. * @day 2020-05-18
  50. */
  51. public function count()
  52. {
  53. return SmsRecord::count($this->getPk());
  54. }
  55. /**
  56. * @param $record_id
  57. * @param $resultcode
  58. * @return int
  59. * @throws DbException
  60. * @author xaboy
  61. * @day 2020-05-18
  62. */
  63. public function updateRecordStatus($record_id, $resultcode)
  64. {
  65. return SmsRecord::getDB()->where('record_id', $record_id)->update(['resultcode' => $resultcode]);
  66. }
  67. /**
  68. * @param $time
  69. * @return array
  70. * @author xaboy
  71. * @day 2020/6/9
  72. */
  73. public function getTimeOutIds($time)
  74. {
  75. return SmsRecord::getDB()->where('resultcode', null)->where('create_time', '<=', $time)->column('record_id');
  76. }
  77. }