PresellOrder.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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\store\order;
  12. use app\common\model\BaseModel;
  13. use app\common\model\user\User;
  14. use app\common\repositories\store\order\PresellOrderRepository;
  15. class PresellOrder extends BaseModel
  16. {
  17. public static function tablePk(): ?string
  18. {
  19. return 'presell_order_id';
  20. }
  21. public static function tableName(): string
  22. {
  23. return 'presell_order';
  24. }
  25. public function user()
  26. {
  27. return $this->hasOne(User::class, 'uid', 'uid');
  28. }
  29. public function order()
  30. {
  31. return $this->hasOne(StoreOrder::class, 'order_id', 'order_id');
  32. }
  33. public function searchOrderIdAttr($query,$value)
  34. {
  35. $query->where('order_id',$value);
  36. }
  37. public function getActiveStatusAttr()
  38. {
  39. $status = 1;
  40. $now = time();
  41. if (strtotime($this->final_start_time) > $now) $status = 0;
  42. else if (strtotime($this->final_end_time) < $now) {
  43. if ($this->status && $this->presell_order_id)
  44. app()->make(PresellOrderRepository::class)->cancel($this->presell_order_id);
  45. $status = 2;
  46. }
  47. return $status;
  48. }
  49. }