StoreDiscounts.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\discounts;
  12. use crmeb\basic\BaseModel;
  13. use crmeb\traits\ModelTrait;
  14. use think\Model;
  15. /**
  16. * 优惠套餐
  17. * Class StoreDiscounts
  18. * @package app\model\activity\discounts
  19. */
  20. class StoreDiscounts extends BaseModel
  21. {
  22. /**
  23. * 数据表主键
  24. * @var string
  25. */
  26. protected $pk = 'id';
  27. /**
  28. * 模型名称
  29. * @var string
  30. */
  31. protected $name = 'store_discounts';
  32. use ModelTrait;
  33. /**
  34. * 套餐商品关联
  35. * @return \think\model\relation\HasMany
  36. */
  37. public function products()
  38. {
  39. return $this->hasMany(StoreDiscountsProducts::class, 'discount_id', 'id');
  40. }
  41. /**
  42. * 类型搜索器
  43. * @param Model $query
  44. * @param $value
  45. * @param $data
  46. */
  47. public function searchTypeAttr($query, $value)
  48. {
  49. if ($value != '') $query->where('type', $value);
  50. }
  51. /**
  52. * 名称搜索器
  53. * @param Model $query
  54. * @param $value
  55. * @param $data
  56. */
  57. public function searchTitleAttr($query, $value)
  58. {
  59. if ($value != '') $query->where('title', 'like', '%' . $value . '%');
  60. }
  61. /**
  62. * 状态搜索器
  63. * @param Model $query
  64. * @param $value
  65. * @param $data
  66. */
  67. public function searchStatusAttr($query, $value)
  68. {
  69. if ($value !== '') $query->where('status', $value);
  70. }
  71. /**
  72. * 是否删除搜索器
  73. * @param Model $query
  74. * @param $value
  75. * @param $data
  76. */
  77. public function searchIsDelAttr($query, $value)
  78. {
  79. if ($value !== '') $query->where('is_del', $value);
  80. }
  81. /**
  82. * 商品id搜索器
  83. * @param Model $query
  84. * @param $value
  85. */
  86. public function searchProductIdsAttr($query, $value)
  87. {
  88. if ($value != '') $query->whereFindInSet('product_ids', $value);
  89. }
  90. }