SecurityCodeRecord.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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\user;
  12. use crmeb\basic\BaseModel;
  13. use crmeb\traits\ModelTrait;
  14. class SecurityCodeRecord extends BaseModel
  15. {
  16. use ModelTrait;
  17. /**
  18. * 数据表主键
  19. * @var string
  20. */
  21. protected $pk = 'id';
  22. /**
  23. * 模型名称
  24. * @var string
  25. */
  26. protected $name = 'security_code_record';
  27. protected $insert = ['add_time', 'update_time'];
  28. protected $hidden = ['update_time'];
  29. protected $updateTime = false;
  30. protected function setAddTimeAttr($value)
  31. {
  32. return time();
  33. }
  34. /**
  35. * 添加时间获取器
  36. * @param $value
  37. * @return false|string
  38. */
  39. public function getAddTimeAttr($value)
  40. {
  41. if (!empty($value)) {
  42. if (is_string($value)) {
  43. return $value;
  44. } elseif (is_int($value)) {
  45. return date('Y-m-d H:i:s', (int)$value);
  46. }
  47. }
  48. return '';
  49. }
  50. /**
  51. * 关联分类
  52. * @return model\relation\HasOne
  53. */
  54. public function category()
  55. {
  56. return $this->hasOne(SecurityCategory::class, 'id', 'category_id');
  57. }
  58. /**
  59. * 关联分类
  60. * @return model\relation\HasOne
  61. */
  62. public function user()
  63. {
  64. return $this->hasOne(User::class, 'uid', 'scan_uid');
  65. }
  66. /**
  67. * 添加时间获取器
  68. * @param $value
  69. * @return false|string
  70. */
  71. public function getScanTimeAttr($value)
  72. {
  73. if (!empty($value)) {
  74. if (is_string($value)) {
  75. return $value;
  76. } elseif (is_int($value)) {
  77. return date('Y-m-d H:i:s', (int)$value);
  78. }
  79. }
  80. return '';
  81. }
  82. /**状态搜索器
  83. * @param $query
  84. * @param $value
  85. */
  86. public function searchStatusAttr($query, $value)
  87. {
  88. if ($value) {
  89. $query->where('status', $value);
  90. }
  91. }
  92. /**状态搜索器
  93. * @param $query
  94. * @param $value
  95. */
  96. public function searchCategoryIdAttr($query, $value)
  97. {
  98. if ($value) {
  99. $query->where('category_id', $value);
  100. }
  101. }
  102. /**状态搜索器
  103. * @param $query
  104. * @param $value
  105. */
  106. public function searchScanUidAttr($query, $value)
  107. {
  108. if ($value) {
  109. $query->where('scan_uid', $value);
  110. }
  111. }
  112. /**状态搜索器
  113. * @param $query
  114. * @param $value
  115. */
  116. public function searchSecurityCodeAttr($query, $value)
  117. {
  118. if ($value) {
  119. $query->where('security_code', $value);
  120. }
  121. }
  122. /**状态搜索器
  123. * @param $query
  124. * @param $value
  125. */
  126. public function searchWxUrlAttr($query, $value)
  127. {
  128. if ($value) {
  129. $query->whereLike('wx_url', '%' . $value . '%');
  130. }
  131. }
  132. }