LuckLottery.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. declare (strict_types=1);
  12. namespace app\model\activity\lottery;
  13. use crmeb\basic\BaseModel;
  14. use crmeb\traits\ModelTrait;
  15. use think\Model;
  16. /**
  17. * 抽奖活动
  18. * Class LuckLottery
  19. * @package app\model\activity\lottery
  20. */
  21. class LuckLottery extends BaseModel
  22. {
  23. use ModelTrait;
  24. /**
  25. * 数据表主键
  26. * @var string
  27. */
  28. protected $pk = 'id';
  29. /**
  30. * 模型名称
  31. * @var string
  32. */
  33. protected $name = 'luck_lottery';
  34. /**
  35. * 抽奖用户等级修改器
  36. * @param $value
  37. * @return false|string
  38. */
  39. protected function setUserLevelAttr($value)
  40. {
  41. if ($value) {
  42. return is_array($value) ? json_encode($value) : $value;
  43. }
  44. return '';
  45. }
  46. /**
  47. * 抽奖用户等级获取器
  48. * @param $value
  49. * @param $data
  50. * @return mixed
  51. */
  52. protected function getUserLevelAttr($value)
  53. {
  54. return $value ? json_decode($value, true) : [];
  55. }
  56. /**
  57. * 抽奖用户标签修改器
  58. * @param $value
  59. * @return false|string
  60. */
  61. protected function setUserLabelAttr($value)
  62. {
  63. if ($value) {
  64. return is_array($value) ? json_encode($value) : $value;
  65. }
  66. return '';
  67. }
  68. /**
  69. * 抽奖用户标签获取器
  70. * @param $value
  71. * @param $data
  72. * @return mixed
  73. */
  74. protected function getUserLabelAttr($value)
  75. {
  76. return $value ? json_decode($value, true) : [];
  77. }
  78. /**
  79. * 关联奖品
  80. * @return \think\model\relation\HasOne
  81. */
  82. public function prize()
  83. {
  84. return $this->hasMany(LuckPrize::class, 'lottery_id', 'id')->where('status', 1)->where('is_del', 0)->order('sort asc,id asc');
  85. }
  86. /**
  87. * 关键词搜索器
  88. * @param $query Model
  89. * @param $value
  90. */
  91. public function searchKeywordAttr($query, $value)
  92. {
  93. if ($value !== '') $query->where('id|name|desc|content', 'like', '%' . $value . '%');
  94. }
  95. /**
  96. * 抽奖形式搜索器
  97. * @param $query Model
  98. * @param $value
  99. */
  100. public function searchTypeAttr($query, $value)
  101. {
  102. if ($value) $query->where('type', $value);
  103. }
  104. /**
  105. * 抽奖类型搜索器
  106. * @param $query Model
  107. * @param $value
  108. */
  109. public function searchFactorAttr($query, $value)
  110. {
  111. if ($value !== '') $query->where('factor', $value);
  112. }
  113. /**
  114. * 状态搜索器
  115. * @param $query Model
  116. * @param $value
  117. */
  118. public function searchStatusAttr($query, $value)
  119. {
  120. if ($value !== '') $query->where('status', $value);
  121. }
  122. /**
  123. * 是否删除搜索器
  124. * @param $query Model
  125. * @param $value
  126. */
  127. public function searchIsDelAttr($query, $value)
  128. {
  129. if ($value !== '') $query->where('is_del', $value);
  130. }
  131. }