StoreIntegral.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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\integral;
  12. use app\model\product\product\StoreDescription;
  13. use app\model\product\product\StoreProduct;
  14. use crmeb\traits\ModelTrait;
  15. use crmeb\basic\BaseModel;
  16. use think\Model;
  17. /**
  18. * TODO 积分商品Model
  19. * Class StoreCombination
  20. * @package app\model\activity
  21. */
  22. class StoreIntegral extends BaseModel
  23. {
  24. /**
  25. * 数据表主键
  26. * @var string
  27. */
  28. protected $pk = 'id';
  29. /**
  30. * 模型名称
  31. * @var string
  32. */
  33. protected $name = 'store_integral';
  34. use ModelTrait;
  35. /**
  36. * 一对一获取原价
  37. * @return \think\model\relation\HasOne
  38. */
  39. public function getPrice()
  40. {
  41. return $this->hasOne(StoreProduct::class, 'id', 'product_id')->bind(['ot_price', 'product_price' => 'price']);
  42. }
  43. /**
  44. * 一对一关联
  45. * 商品关联商品商品详情
  46. * @return \think\model\relation\HasOne
  47. */
  48. public function description()
  49. {
  50. return $this->hasOne(StoreDescription::class, 'product_id', 'id')->where('type', 4)->bind(['description']);
  51. }
  52. /**
  53. * 添加时间获取器
  54. * @param $value
  55. * @return false|string
  56. */
  57. protected function getAddTimeAttr($value)
  58. {
  59. if ($value) return date('Y-m-d H:i:s', (int)$value);
  60. return '';
  61. }
  62. /**
  63. * 轮播图获取器
  64. * @param $value
  65. * @return mixed
  66. */
  67. public function getImagesAttr($value)
  68. {
  69. return json_decode($value, true) ?? [];
  70. }
  71. /**
  72. * 积分商品名称搜索器
  73. * @param Model $query
  74. * @param $value
  75. * @param $data
  76. */
  77. public function searchStoreNameAttr($query, $value, $data)
  78. {
  79. if ($value) $query->where('title|id', 'like', '%' . $value . '%');
  80. }
  81. /**
  82. * 是否推荐搜索器
  83. * @param Model $query
  84. * @param $value
  85. * @param $data
  86. */
  87. public function searchIsHostAttr($query, $value, $data)
  88. {
  89. $query->where('is_host', $value ?? 1);
  90. }
  91. /**
  92. * 状态搜索器
  93. * @param Model $query
  94. * @param $value
  95. * @param $data
  96. */
  97. public function searchIsShowAttr($query, $value, $data)
  98. {
  99. if ($value != '') $query->where('is_show', $value ?: 0);
  100. }
  101. /**
  102. * 是否删除搜索器
  103. * @param Model $query
  104. * @param $value
  105. * @param $data
  106. */
  107. public function searchIsDelAttr($query, $value, $data)
  108. {
  109. $query->where('is_del', $value ?? 0);
  110. }
  111. /**
  112. * 商品ID搜索器
  113. * @param Model $query
  114. * @param $value
  115. * @param $data
  116. */
  117. public function searchProductIdAttr($query, $value, $data)
  118. {
  119. if ($value) {
  120. if (is_array($value)) {
  121. $query->whereIn('product_id', $value);
  122. } else {
  123. $query->where('product_id', $value);
  124. }
  125. }
  126. }
  127. }