You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StorePromotionsAuxiliary.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. namespace app\model\activity\promotions;
  3. use app\model\activity\coupon\StoreCouponIssue;
  4. use app\model\product\product\StoreProduct;
  5. use app\model\product\sku\StoreProductAttrValue;
  6. use crmeb\basic\BaseModel;
  7. use crmeb\traits\ModelTrait;
  8. /**
  9. * 优惠活动辅助表
  10. */
  11. class StorePromotionsAuxiliary extends BaseModel
  12. {
  13. use ModelTrait;
  14. /**
  15. * @var string
  16. */
  17. protected $key = 'id';
  18. /**
  19. * @var string
  20. */
  21. protected $name = 'store_promotions_auxiliary';
  22. /**
  23. * 商品规格
  24. * @param $value
  25. * @return array|mixed
  26. */
  27. protected function getUniqueAttr($value, $data)
  28. {
  29. if ($value) {
  30. return is_string($value) && (!isset($data['type']) || $data['type'] != 3) ? explode(',', $value) : $value;
  31. }
  32. return [];
  33. }
  34. /**
  35. * 关联优惠券
  36. * @return \think\model\relation\HasOne
  37. */
  38. public function coupon()
  39. {
  40. return $this->hasOne(StoreCouponIssue::class, 'id', 'coupon_id');
  41. }
  42. /**
  43. * 关联商品
  44. * @return \think\model\relation\HasOne
  45. */
  46. public function productInfo()
  47. {
  48. return $this->hasOne(StoreProduct::class, 'id', 'product_id');
  49. }
  50. /**
  51. * 赠送sku一对一
  52. * @return \think\model\relation\HasMany
  53. */
  54. public function giveAttrValue()
  55. {
  56. return $this->hasOne(StoreProductAttrValue::class, 'unique', 'unique')->where('type', 0);
  57. }
  58. /**
  59. * sku一对多
  60. * @return \think\model\relation\HasMany
  61. */
  62. public function attrValue()
  63. {
  64. return $this->hasMany(StoreProductAttrValue::class, 'product_id', 'product_id')->where('type', 0);
  65. }
  66. /**
  67. * type搜索器
  68. * @param Model $query
  69. * @param $value
  70. */
  71. public function searchTypeAttr($query, $value)
  72. {
  73. if ($value) $query->where('type', $value);
  74. }
  75. /**
  76. * promotions_id搜索器
  77. * @param $query
  78. * @param $value
  79. */
  80. public function searchPromotionsIdAttr($query, $value)
  81. {
  82. if (is_array($value)) {
  83. if ($value) $query->whereIn('promotions_id', $value);
  84. } else {
  85. if ($value !== '') $query->where('promotions_id', $value);
  86. }
  87. }
  88. /**
  89. * coupon_id搜索器
  90. * @param $query
  91. * @param $value
  92. */
  93. public function searchCouponIdAttr($query, $value)
  94. {
  95. if (is_array($value)) {
  96. if ($value) $query->whereIn('coupon_id', $value);
  97. } else {
  98. if ($value !== '') $query->where('coupon_id', $value);
  99. }
  100. }
  101. /**
  102. * product_id搜索器
  103. * @param $query
  104. * @param $value
  105. */
  106. public function searchProductIdAttr($query, $value)
  107. {
  108. if (is_array($value)) {
  109. if ($value) $query->whereIn('product_id', $value);
  110. } else {
  111. if ($value !== '') $query->where('product_id', $value);
  112. }
  113. }
  114. /**
  115. * is_all搜索器
  116. * @param $query
  117. * @param $value
  118. */
  119. public function searchIsAllAttr($query, $value)
  120. {
  121. if ($value !== '') {
  122. $query->where('is_all', $value);
  123. }
  124. }
  125. }