StoreCoupon.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 StoreCoupon
  18. * @package app\model\coupon
  19. */
  20. class StoreCoupon 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';
  33. /**
  34. * 优惠卷类型
  35. * @var string[]
  36. */
  37. protected $couponType = [0 => '通用券', 1 => '品类券', 2 => '商品券'];
  38. /**
  39. * 一对多关联
  40. * @return \think\model\relation\HasMany
  41. */
  42. public function productId()
  43. {
  44. return $this->hasMany(StoreCouponProduct::class, 'coupon_id', 'id');
  45. }
  46. /**
  47. * 优惠券类型获取器
  48. * @param $value
  49. * @return string
  50. */
  51. public function getTypeAttr($value)
  52. {
  53. return $this->couponType[$value];
  54. }
  55. /**
  56. * 优惠券模板标题搜索器
  57. * @param Model $query
  58. * @param $value
  59. * @param $data
  60. */
  61. public function searchTitleAttr($query, $value, $data)
  62. {
  63. if ($value) $query->where('title', 'like', '%' . $value . '%');
  64. }
  65. /**
  66. * 优惠券模板状态搜索器
  67. * @param Model $query
  68. * @param $value
  69. * @param $data
  70. */
  71. public function searchStatusAttr($query, $value, $data)
  72. {
  73. if ($value != '') $query->where('status', $value);
  74. }
  75. /**
  76. * 最低消费金额搜索器
  77. * @param Model $query
  78. * @param $value
  79. * @param $data
  80. */
  81. public function searchUseMinPriceAttr($query, $value, $data)
  82. {
  83. $query->where('use_min_price', $value);
  84. }
  85. /**
  86. * 优惠券面值搜索器
  87. * @param Model $query
  88. * @param $value
  89. * @param $data
  90. */
  91. public function searchCouponPriceAttr($query, $value, $data)
  92. {
  93. $query->where('coupon_price', $value);
  94. }
  95. /**
  96. * 是否删除搜索器
  97. * @param Model $query
  98. * @param $value
  99. * @param $data
  100. */
  101. public function searchIsDelAttr($query, $value, $data)
  102. {
  103. $query->where('is_del', $value ?? 0);
  104. }
  105. /**
  106. * 优惠券类型搜索器
  107. * @param Model $query
  108. * @param $value
  109. * @param $data
  110. */
  111. public function searchTypeAttr($query, $value, $data)
  112. {
  113. $query->where('type', $value ?? 0);
  114. }
  115. /**
  116. * 分类ID搜索器
  117. * @param Model $query
  118. * @param $value
  119. * @param $data
  120. */
  121. public function searchCategoryIdAttr($query, $value, $data)
  122. {
  123. $query->where('category_id', $value);
  124. }
  125. }