UserHistory.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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\user;
  12. use app\common\model\BaseModel;
  13. use app\common\model\store\product\Spu;
  14. class UserHistory extends BaseModel
  15. {
  16. public static function tablePk(): ?string
  17. {
  18. return 'user_history_id';
  19. }
  20. public static function tableName(): string
  21. {
  22. return 'user_history';
  23. }
  24. public function getUpdateTimeAttr($value)
  25. {
  26. return date('Y-m-d H:i:s',$value);
  27. }
  28. public function getStopTimeAttr()
  29. {
  30. if (!$this->spu) return '';
  31. if ($this->spu->product_type == 1 && $this->spu->seckillActive) {
  32. $day = date('Y-m-d', time());
  33. $_day = strtotime($day);
  34. $end_day = strtotime($this->spu->seckillActive['end_day']);
  35. if ($end_day >= $_day)
  36. return strtotime($day . $this->spu->seckillActive['end_time'] . ':00:00');
  37. if ($end_day < strtotime($day))
  38. return strtotime(date('Y-m-d', $end_day) . $this->spu->seckillActive['end_time'] . ':00:00');
  39. }
  40. return '';
  41. }
  42. public function spu()
  43. {
  44. return $this->hasOne(Spu::class,'spu_id','res_id');
  45. }
  46. public function searchUidAttr($query,$value)
  47. {
  48. $query->where('uid',$value);
  49. }
  50. public function searchHistoryIdAttr($query,$value)
  51. {
  52. $query->where('history_id',$value);
  53. }
  54. public function searchHistoryIdsAttr($query,$value)
  55. {
  56. $query->where('history_id','in',$value);
  57. }
  58. }