LiveGoods.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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\live;
  12. use app\model\product\product\StoreProduct;
  13. use crmeb\basic\BaseModel;
  14. use crmeb\traits\ModelTrait;
  15. use think\Model;
  16. /**
  17. * 直播商品
  18. * Class LiveGoods
  19. * @package app\model\activity\live
  20. */
  21. class LiveGoods extends BaseModel
  22. {
  23. use ModelTrait;
  24. protected $pk = 'id';
  25. protected $name = 'live_goods';
  26. protected $autoWriteTimestamp = 'int';
  27. protected $createTime = 'add_time';
  28. protected function setAddTimeAttr()
  29. {
  30. return time();
  31. }
  32. /**
  33. * 添加时间获取器
  34. * @param $value
  35. * @return false|string
  36. */
  37. public function getAddTimeAttr($value)
  38. {
  39. if (!empty($value)) {
  40. return date('Y-m-d H:i:s', (int)$value);
  41. }
  42. return '';
  43. }
  44. public function product()
  45. {
  46. return $this->hasOne(StoreProduct::class, 'id', 'product_id');
  47. }
  48. /**
  49. * 微信商品id
  50. * @param Model $query
  51. * @param $value
  52. */
  53. public function searchGoodIdAttr($query, $value)
  54. {
  55. if (is_array($value))
  56. $query->whereIn('goods_id', $value);
  57. else
  58. $query->where('good_id', $value);
  59. }
  60. /**
  61. * @param Model $query
  62. * @param $value
  63. */
  64. public function searchKerwordAttr($query, $value)
  65. {
  66. if ($value !== '') $query->whereLike('id|goods_id|product_id|name', "%{$value}%");
  67. }
  68. /**
  69. * @param Model $query
  70. * @param $value
  71. */
  72. public function searchIsDelAttr($query, $value)
  73. {
  74. if ($value !== '') $query->where('is_del', $value);
  75. }
  76. /**
  77. * @param Model $query
  78. * @param $value
  79. */
  80. public function searchIsShowAttr($query, $value)
  81. {
  82. if ($value !== '') $query->where('is_show', $value);
  83. }
  84. /**
  85. * @param Model $query
  86. * @param $value
  87. */
  88. public function searchStatusAttr($query, $value)
  89. {
  90. if ($value !== '') {
  91. switch ($value) {
  92. case 1:
  93. $query->where('audit_status', 2);
  94. break;
  95. case -1:
  96. $query->where('audit_status', 3);
  97. break;
  98. case 0:
  99. $query->whereIn('audit_status', [0, 1]);
  100. break;
  101. }
  102. }
  103. }
  104. public function searchLiveIdAttr($query, $value)
  105. {
  106. if ($value > 0) {
  107. $query->whereNotIn('id', function ($query) use ($value) {
  108. $query->name('live_room_goods')->where('live_room_id', $value)->field('live_goods_id')->select();
  109. });
  110. }
  111. }
  112. }