StoreCouponIssue.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. namespace app\model\activity\coupon;
  12. use crmeb\basic\BaseModel;
  13. use crmeb\traits\ModelTrait;
  14. use think\Model;
  15. /**
  16. * TODO 发布优惠券Model
  17. * Class StoreCouponIssue
  18. * @package app\model\coupon
  19. */
  20. class StoreCouponIssue 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 = 'store_coupon_issue';
  33. /**
  34. * 用户是否拥有
  35. * @return \think\model\relation\HasOne
  36. */
  37. public function used()
  38. {
  39. return $this->hasMany(StoreCouponIssueUser::class, 'issue_coupon_id', 'id');
  40. }
  41. /**
  42. * id
  43. * @param Model $query
  44. * @param $value
  45. */
  46. public function searchIdAttr($query, $value)
  47. {
  48. if (is_array($value))
  49. $query->whereIn('id', $value);
  50. else
  51. $query->where('id', $value);
  52. }
  53. /**
  54. * 优惠券模板搜索器
  55. * @param Model $query
  56. * @param $value
  57. * @param $data
  58. */
  59. public function searchCidAttr($query, $value, $data)
  60. {
  61. $query->where('cid', $value);
  62. }
  63. /**
  64. * 优惠券是否不限量
  65. * @param Model $query
  66. * @param $value
  67. * @param $data
  68. */
  69. public function searchIsPermanentAttr($query, $value, $data)
  70. {
  71. $query->where('is_permanent', $value);
  72. }
  73. /**
  74. * 优惠券是否新人券
  75. * @param Model $query
  76. * @param $value
  77. * @param $data
  78. */
  79. public function searchIsGiveSubscribeAttr($query, $value, $data)
  80. {
  81. $query->where('is_give_subscribe', $value);
  82. }
  83. /**
  84. * 优惠券是否满赠
  85. * @param Model $query
  86. * @param $value
  87. * @param $data
  88. */
  89. public function searchIsFullGiveAttr($query, $value, $data)
  90. {
  91. $query->where('is_full_give', $value);
  92. }
  93. /**
  94. * 优惠券状态
  95. * @param Model $query
  96. * @param $value
  97. * @param $data
  98. */
  99. public function searchStatusAttr($query, $value, $data)
  100. {
  101. if ($value != '') $query->where('status', $value);
  102. }
  103. /**
  104. * 优惠券是否删除
  105. * @param Model $query
  106. * @param $value
  107. * @param $data
  108. */
  109. public function searchIsDelAttr($query, $value, $data)
  110. {
  111. $query->where('is_del', $value ?? 0);
  112. }
  113. /**
  114. * 优惠券名称
  115. * @param Model $query
  116. * @param $value
  117. * @param $data
  118. */
  119. public function searchCouponTitleAttr($query, $value, $data)
  120. {
  121. if ($value) $query->whereLike('coupon_title', '%' . $value . '%');
  122. }
  123. /**
  124. * 优惠券类型
  125. * @param Model $query
  126. * @param $value
  127. */
  128. public function searchCouponTypeAttr($query, $value)
  129. {
  130. if ($value != '') $query->where('type', $value);
  131. }
  132. }