StoreActivityRelated.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 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\form\Form;
  15. use app\common\model\system\Relevance;
  16. use app\common\model\user\User;
  17. use app\common\repositories\store\StoreActivityRepository;
  18. use app\common\repositories\system\RelevanceRepository;
  19. class StoreActivityRelated extends BaseModel
  20. {
  21. public static function tablePk(): string
  22. {
  23. return 'id';
  24. }
  25. public static function tableName(): string
  26. {
  27. return 'store_activity_related';
  28. }
  29. public function getValueAttr($value)
  30. {
  31. return json_decode($value,true);
  32. }
  33. public function getKeysAttr($value)
  34. {
  35. return json_decode($value,true);
  36. }
  37. public function getFormValueAttr($value)
  38. {
  39. return json_decode($value,true);
  40. }
  41. public function activity()
  42. {
  43. return $this->hasOne(StoreActivity::class, 'activity_id','activity_id');
  44. }
  45. public function systemForm()
  46. {
  47. return $this->hasOne(Form::class, 'form_id','link_id');
  48. }
  49. public function user()
  50. {
  51. return $this->hasOne(User::class,'uid','uid');
  52. }
  53. public function searchUidAttr($query,$value)
  54. {
  55. $query->where('uid',$value);
  56. }
  57. public function searchActivityIdAttr($query,$value)
  58. {
  59. $query->where('activity_id',$value);
  60. }
  61. public function searchIdAttr($query,$value)
  62. {
  63. $query->where('id',$value);
  64. }
  65. public function searchActivityTypeAttr($query,$value)
  66. {
  67. $query->where('activity_type',$value);
  68. }
  69. public function searchLinkIdAttr($query,$value)
  70. {
  71. $query->where('link_id',$value);
  72. }
  73. public function searchCreateTimeAttr($query, $value)
  74. {
  75. if(!empty($value)){
  76. return getModelTime($query, $value);
  77. }
  78. }
  79. public function searchKeywordAttr($query, $value)
  80. {
  81. if ($value !== '') {
  82. $query->whereLike('uid|nickname|phone', "%{$value}%");
  83. }
  84. }
  85. }