UserHistory.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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\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){
  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. }
  41. public function spu()
  42. {
  43. return $this->hasOne(Spu::class,'spu_id','res_id');
  44. }
  45. public function searchUidAttr($query,$value)
  46. {
  47. $query->where('uid',$value);
  48. }
  49. public function searchHistoryIdAttr($query,$value)
  50. {
  51. $query->where('history_id',$value);
  52. }
  53. public function searchHistoryIdsAttr($query,$value)
  54. {
  55. $query->where('history_id','in',$value);
  56. }
  57. }