StoreAdvance.php 3.5 KB

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