UserHistory.php 1.4 KB

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