StoreOrder.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace app\common\model\store\order;
  3. use app\common\model\BaseModel;
  4. use app\common\model\store\product\ProductGroupUser;
  5. use app\common\model\store\service\StoreService;
  6. use app\common\model\store\shipping\Express;
  7. use app\common\model\system\merchant\Merchant;
  8. use app\common\model\user\User;
  9. use app\common\repositories\store\MerchantTakeRepository;
  10. class StoreOrder extends BaseModel
  11. {
  12. public static function tablePk(): ?string
  13. {
  14. return 'order_id';
  15. }
  16. public static function tableName(): string
  17. {
  18. return 'store_order';
  19. }
  20. public function orderProduct()
  21. {
  22. return $this->hasMany(StoreOrderProduct::class, 'order_id', 'order_id');
  23. }
  24. public function refundProduct()
  25. {
  26. return $this->orderProduct()->where('refund_num', '>', 0);
  27. }
  28. public function merchant()
  29. {
  30. return $this->hasOne(Merchant::class, 'mer_id', 'mer_id');
  31. }
  32. public function user()
  33. {
  34. return $this->hasOne(User::class, 'uid', 'uid');
  35. }
  36. public function groupOrder()
  37. {
  38. return $this->hasOne(StoreGroupOrder::class, 'group_order_id', 'group_order_id');
  39. }
  40. public function verifyService()
  41. {
  42. return $this->hasOne(StoreService::class, 'service_id', 'verify_service_id');
  43. }
  44. public function getTakeAttr()
  45. {
  46. return app()->make(MerchantTakeRepository::class)->get($this->mer_id);
  47. }
  48. public function searchDataAttr($query, $value)
  49. {
  50. return getModelTime($query, $value);
  51. }
  52. public function presellOrder()
  53. {
  54. return $this->hasOne(PresellOrder::class, 'order_id', 'order_id');
  55. }
  56. public function finalOrder()
  57. {
  58. return $this->hasOne(PresellOrder::class,'order_id','order_id');
  59. }
  60. public function groupUser()
  61. {
  62. return $this->hasOne(ProductGroupUser::class,'order_id','order_id');
  63. }
  64. public function profitsharing()
  65. {
  66. return $this->hasMany(StoreOrderProfitsharing::class, 'order_id', 'order_id');
  67. }
  68. public function firstProfitsharing()
  69. {
  70. return $this->hasOne(StoreOrderProfitsharing::class, 'order_id', 'order_id')->where('type', 'order');
  71. }
  72. public function presellProfitsharing()
  73. {
  74. return $this->hasOne(StoreOrderProfitsharing::class, 'order_id', 'order_id')->where('type', 'presell');
  75. }
  76. public function searchMerIdAttr($query, $value)
  77. {
  78. return $query->where('mer_id', $value);
  79. }
  80. public function getRefundStatusAttr()
  81. {
  82. $day = (int)systemConfig('sys_refund_timer') ?: 15;
  83. return ($this->verify_time ? strtotime($this->verify_time) > strtotime('-' . $day . ' day') : true);
  84. }
  85. }