SmsRecord.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\model\sms;
  12. use crmeb\basic\BaseModel;
  13. use crmeb\traits\ModelTrait;
  14. use think\Model;
  15. /**
  16. * 短信记录Model
  17. * Class SmsRecord
  18. * @package app\model\sms
  19. */
  20. class SmsRecord extends BaseModel
  21. {
  22. use ModelTrait;
  23. /**
  24. * 数据表主键
  25. * @var string
  26. */
  27. protected $pk = 'id';
  28. /**
  29. * 模型名称
  30. * @var string
  31. */
  32. protected $name = 'sms_record';
  33. /**
  34. * 短信状态
  35. * @var array
  36. */
  37. protected $resultcode = ['100' => '成功', '130' => '失败', '131' => '空号', '132' => '停机', '133' => '关机', '134' => '无状态'];
  38. /**
  39. * 时间获取器
  40. * @param $value
  41. * @return false|string
  42. */
  43. protected function getAddTimeAttr($value)
  44. {
  45. return $value ? date('Y-m-d H:i:s', $value) : '';
  46. }
  47. /**
  48. * 状态码获取器
  49. * @param $value
  50. * @return mixed|string
  51. */
  52. protected function getResultcodeAttr($value)
  53. {
  54. return $this->resultcode[$value] ?? '无状态';
  55. }
  56. /**
  57. * 电话号码搜索器
  58. * @param Model $query
  59. * @param $value
  60. * @param $data
  61. */
  62. public function searchPhoneAttr($query, $value)
  63. {
  64. $query->where('phone', $value);
  65. }
  66. /**
  67. * 短信状态搜索器
  68. * @param Model $query
  69. * @param $value
  70. * @param $data
  71. */
  72. public function searchResultcodeAttr($query, $value)
  73. {
  74. $query->where('resultcode', $value);
  75. }
  76. /**
  77. * uid搜索器
  78. * @param Model $query
  79. * @param $value
  80. */
  81. public function searchUidAttr($query, $value)
  82. {
  83. if ($value) {
  84. $query->where('uid', $value);
  85. }
  86. }
  87. /**
  88. * ip
  89. * @param Model $query
  90. * @param $value
  91. * @param $data
  92. */
  93. public function searchAddIpAttr($query, $value)
  94. {
  95. $query->where('add_ip', $value);
  96. }
  97. /**
  98. * resultcode
  99. * @param Model $query
  100. * @param $value
  101. * @param $data
  102. */
  103. public function searchTypeAttr($query, $value)
  104. {
  105. if ($value !== '') {
  106. if (is_array($value)) {
  107. $query->whereIn('resultcode', $value)->when(in_array('134', $value), function ($query) {
  108. $query->whereOr('resultcode', NULL);
  109. });
  110. } else {
  111. $query->where('resultcode', $value)->when($value == 134, function ($query) {
  112. $query->whereOr('resultcode', NULL);
  113. });
  114. }
  115. }
  116. }
  117. }