LuckLotteryRecord.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 app\model\user\User;
  14. use crmeb\basic\BaseModel;
  15. use crmeb\traits\ModelTrait;
  16. use think\Model;
  17. /**
  18. *
  19. * Class LuckLotteryRecordDao
  20. * @package app\model\activity\lottery
  21. */
  22. class LuckLotteryRecord extends BaseModel
  23. {
  24. use ModelTrait;
  25. /**
  26. * 数据表主键
  27. * @var string
  28. */
  29. protected $pk = 'id';
  30. /**
  31. * 模型名称
  32. * @var string
  33. */
  34. protected $name = 'luck_lottery_record';
  35. /**
  36. * 收货信息修改器
  37. * @param $value
  38. * @return false|string
  39. */
  40. protected function setReceiveInfoAttr($value)
  41. {
  42. if ($value) {
  43. return is_array($value) ? json_encode($value) : $value;
  44. }
  45. return '';
  46. }
  47. /**
  48. * 收货信息获取器
  49. * @param $value
  50. * @param $data
  51. * @return mixed
  52. */
  53. protected function getReceiveInfoAttr($value)
  54. {
  55. return $value ? json_decode($value, true) : [];
  56. }
  57. /**
  58. * 发货信息修改器
  59. * @param $value
  60. * @return false|string
  61. */
  62. protected function setDeliverInfoAttr($value)
  63. {
  64. if ($value) {
  65. return is_array($value) ? json_encode($value) : $value;
  66. }
  67. return '';
  68. }
  69. /**
  70. * 发货信息获取器
  71. * @param $value
  72. * @param $data
  73. * @return mixed
  74. */
  75. protected function getDeliverInfoAttr($value)
  76. {
  77. return $value ? json_decode($value, true) : [];
  78. }
  79. /**
  80. * 关联抽奖
  81. * @return \think\model\relation\HasOne
  82. */
  83. public function lottery()
  84. {
  85. return $this->hasOne(LuckLottery::class, 'id', 'lottery_id');
  86. }
  87. /**
  88. * 关联奖品
  89. * @return \think\model\relation\HasOne
  90. */
  91. public function prize()
  92. {
  93. return $this->hasOne(LuckPrize::class, 'id', 'prize_id');
  94. }
  95. /**
  96. * 关联用户
  97. * @return \think\model\relation\HasOne
  98. */
  99. public function user()
  100. {
  101. return $this->hasOne(User::class, 'uid', 'uid')->field('uid,real_name,nickname,phone');
  102. }
  103. /**
  104. * 用户uid搜索器
  105. * @param $query Model
  106. * @param $value
  107. */
  108. public function searchUidAttr($query, $value)
  109. {
  110. if ($value) $query->where('uid', $value);
  111. }
  112. /**
  113. * 关键词搜索器
  114. * @param $query Model
  115. * @param $value
  116. */
  117. public function searchKeywordAttr($query, $value)
  118. {
  119. if ($value !== '') {
  120. $query->where(function ($query1) use ($value) {
  121. $query1->where('id|uid|lottery_id|prize_id', 'LIKE', '%' . $value . '%')->whereOr('uid', 'IN', function ($query1) use ($value) {
  122. $query1->name('user')->field('uid')->where('account|nickname|phone|real_name|uid', 'LIKE', "%$value%")->select();
  123. })->whereOr('lottery_id', 'IN', function ($query1) use ($value) {
  124. $query1->name('luck_lottery')->field('id')->where('name|desc|content', 'LIKE', "%$value%")->select();
  125. })->whereOr('prize_id', 'IN', function ($query1) use ($value) {
  126. $query1->name('luck_prize')->field('id')->where('name|prompt', 'LIKE', "%$value%")->select();
  127. });
  128. });
  129. }
  130. }
  131. /**
  132. * 抽奖id搜索器
  133. * @param $query Model
  134. * @param $value
  135. */
  136. public function searchLotteryIdAttr($query, $value)
  137. {
  138. if ($value !== '') $query->where('lottery_id', $value);
  139. }
  140. /**
  141. * 奖品id搜索器
  142. * @param $query Model
  143. * @param $value
  144. */
  145. public function searchPrizeIdAttr($query, $value)
  146. {
  147. if ($value) $query->where('prize_id', $value);
  148. }
  149. /**
  150. * 奖品类型搜索器
  151. * @param $query Model
  152. * @param $value
  153. */
  154. public function searchTypeAttr($query, $value)
  155. {
  156. if ($value) {
  157. if (is_array($value)) {
  158. $query->whereIn('type', $value);
  159. } else {
  160. $query->where('type', $value);
  161. }
  162. }
  163. }
  164. /**
  165. * 奖品不再这个类型中搜索器
  166. * @param $query Model
  167. * @param $value
  168. */
  169. public function searchNotTypeAttr($query, $value)
  170. {
  171. if ($value) {
  172. if (is_array($value)) {
  173. $query->whereNotIn('type', $value);
  174. } else {
  175. $query->where('type', '<>', $value);
  176. }
  177. }
  178. }
  179. /**
  180. * 是否领取
  181. * @param $query Model
  182. * @param $value
  183. */
  184. public function searchIsReceiveAttr($query, $value)
  185. {
  186. if ($value !== '') $query->where('is_reveive', $value);
  187. }
  188. /**
  189. * 是否发货处理
  190. * @param $query Model
  191. * @param $value
  192. */
  193. public function searchIsDeliverAttr($query, $value)
  194. {
  195. if ($value !== '') $query->where('is_deliver', $value);
  196. }
  197. }