StoreActivity.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\model\store;
  12. use app\common\model\BaseModel;
  13. use app\common\model\store\product\Spu;
  14. use app\common\model\system\Relevance;
  15. use app\common\repositories\system\RelevanceRepository;
  16. class StoreActivity extends BaseModel
  17. {
  18. public static function tablePk(): string
  19. {
  20. return 'activity_id';
  21. }
  22. public static function tableName(): string
  23. {
  24. return 'store_activity';
  25. }
  26. public function getFullAttr($val)
  27. {
  28. return $val ? (float)$val : $val;
  29. }
  30. public function spu()
  31. {
  32. return $this->hasMany(Spu::class, 'activity_id', 'activity_id');
  33. }
  34. public function socpeData()
  35. {
  36. return $this->hasMany(Relevance::class,'left_id','activity_id')->whereIn('type',[RelevanceRepository::SCOPE_TYPE_STORE,RelevanceRepository::SCOPE_TYPE_CATEGORY,RelevanceRepository::SCOPE_TYPE_PRODUCT]);
  37. }
  38. public function searchIsShowAttr($query, $value)
  39. {
  40. if ($value !== '') {
  41. $query->where('is_show', $value);
  42. }
  43. }
  44. public function searchStatusAttr($query, $value)
  45. {
  46. if ($value !== '') {
  47. $query->where('status',$value);
  48. }
  49. }
  50. public function searchActivityTypeAttr($query, $value)
  51. {
  52. if ($value !== '') {
  53. $query->where('activity_type', $value);
  54. }
  55. }
  56. public function searchIsStatusAttr($query, $value)
  57. {
  58. $query->whereIn('status',[0,1]);
  59. }
  60. public function searchActivityIdAttr($query, $value)
  61. {
  62. if ($value !== '') {
  63. $query->where('activity_id', $value);
  64. }
  65. }
  66. public function searchDateAttr($query, $value)
  67. {
  68. if ($value !== '') {
  69. getModelTime($query, $value, 'create_time');
  70. }
  71. }
  72. public function searchKeywordAttr($query, $value)
  73. {
  74. if ($value !== '') {
  75. $query->whereLike('activity_id|activity_name', '%' . $value . '%');
  76. }
  77. }
  78. public function searchIsDelAttr($query, $value)
  79. {
  80. if ($value !== '') {
  81. $query->where('is_del', $value);
  82. }
  83. }
  84. public function searchGtEndTimeAttr($query, $value)
  85. {
  86. if ($value !== '') {
  87. $query->whereTime('end_time','>', $value);
  88. }
  89. }
  90. }