PresellOrder.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 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\system\merchant\Merchant;
  14. use app\common\model\user\User;
  15. use app\common\repositories\store\order\PresellOrderRepository;
  16. class PresellOrder extends BaseModel
  17. {
  18. public static function tablePk(): ?string
  19. {
  20. return 'presell_order_id';
  21. }
  22. public static function tableName(): string
  23. {
  24. return 'presell_order';
  25. }
  26. public function user()
  27. {
  28. return $this->hasOne(User::class, 'uid', 'uid');
  29. }
  30. public function order()
  31. {
  32. return $this->hasOne(StoreOrder::class, 'order_id', 'order_id');
  33. }
  34. public function merchant()
  35. {
  36. return $this->hasOne(Merchant::class, 'mer_id', 'mer_id');
  37. }
  38. public function searchOrderIdAttr($query, $value)
  39. {
  40. $query->where('order_id', $value);
  41. }
  42. public function getActiveStatusAttr()
  43. {
  44. $status = 1;
  45. $now = time();
  46. if (strtotime($this->final_start_time) > $now) $status = 0;
  47. else if (strtotime($this->final_end_time) < $now) {
  48. if ($this->status && $this->presell_order_id)
  49. app()->make(PresellOrderRepository::class)->cancel($this->presell_order_id);
  50. $status = 2;
  51. }
  52. return $status;
  53. }
  54. public function getCombinePayParams()
  55. {
  56. return [
  57. 'order_sn' => $this->presell_order_sn,
  58. 'sub_orders' => [
  59. [
  60. 'pay_price' => $this->pay_price,
  61. 'order_sn' => $this->presell_order_sn,
  62. 'sub_mchid' => $this->merchant->sub_mchid,
  63. ]
  64. ],
  65. 'attach' => 'presell',
  66. 'body' => '尾款支付',
  67. ];
  68. }
  69. public function getPayParams($return_url = '')
  70. {
  71. $params = [
  72. 'order_sn' => $this->presell_order_sn,
  73. 'pay_price' => $this->pay_price,
  74. 'attach' => 'presell',
  75. 'body' => '尾款支付'
  76. ];
  77. if ($return_url) {
  78. $params['return_url'] = $return_url;
  79. }
  80. return $params;
  81. }
  82. }