MemberCard.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. use think\Model;
  15. class MemberCard extends BaseModel
  16. {
  17. use ModelTrait;
  18. /**
  19. * 数据表主键
  20. * @var string
  21. */
  22. protected $pk = 'id';
  23. /**
  24. * 模型名称
  25. * @var string
  26. */
  27. protected $name = 'member_card';
  28. protected $insert = ['add_time', 'update_time'];
  29. protected $hidden = ['update_time', 'add_time'];
  30. protected $updateTime = false;
  31. /**
  32. * 卡号搜索器
  33. * @param Model $query
  34. * @param $value
  35. */
  36. public function searchCardNumberAttr($query, $value)
  37. {
  38. if ($value) {
  39. $query->whereLike('card_number', '%' . $value . '%');
  40. }
  41. }
  42. /**
  43. * 用户uid搜索器
  44. * @param Model $query
  45. * @param $value
  46. */
  47. public function searchUseUidAttr($query, $value)
  48. {
  49. if (is_array($value)) {
  50. $query->whereIn('use_uid', $value);
  51. } else {
  52. $query->where('use_uid', $value);
  53. }
  54. }
  55. /**
  56. * 手机号搜索器
  57. * @param Model $query
  58. * @param $value
  59. */
  60. public function searchPhoneAttr($query, $value)
  61. {
  62. if ($value) {
  63. $query->whereIn('use_uid', function ($query) use ($value) {
  64. $query->name('user')->whereLike('phone', $value . '%')->field('uid')->select();
  65. });
  66. }
  67. }
  68. /**
  69. * 批次id搜索器
  70. * @param Model $query
  71. * @param $value
  72. */
  73. public function searchBatchCardIdAttr($query, $value)
  74. {
  75. $query->where('card_batch_id', $value);
  76. }
  77. /**
  78. * 用户use_time搜索器
  79. * @param Model $query
  80. * @param $value
  81. */
  82. public function searchUseTimeAttr($query, $value)
  83. {
  84. if ($value > 0) {
  85. $query->where('use_time', '>', 0);
  86. }
  87. if ($value == 0) {
  88. $query->where('use_time', 0);
  89. }
  90. }
  91. public function searchIsStatusAttr($query, $value)
  92. {
  93. if ($value) {
  94. $query->where('status', $value);
  95. }
  96. }
  97. }