PresellOrder.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace app\common\model\store\order;
  3. use app\common\model\BaseModel;
  4. use app\common\model\system\merchant\Merchant;
  5. use app\common\model\user\User;
  6. use app\common\repositories\store\order\PresellOrderRepository;
  7. class PresellOrder extends BaseModel
  8. {
  9. public static function tablePk(): ?string
  10. {
  11. return 'presell_order_id';
  12. }
  13. public static function tableName(): string
  14. {
  15. return 'presell_order';
  16. }
  17. public function user()
  18. {
  19. return $this->hasOne(User::class, 'uid', 'uid');
  20. }
  21. public function order()
  22. {
  23. return $this->hasOne(StoreOrder::class, 'order_id', 'order_id');
  24. }
  25. public function merchant()
  26. {
  27. return $this->hasOne(Merchant::class, 'mer_id', 'mer_id');
  28. }
  29. public function searchOrderIdAttr($query, $value)
  30. {
  31. $query->where('order_id', $value);
  32. }
  33. public function getActiveStatusAttr()
  34. {
  35. $status = 1;
  36. $now = time();
  37. if (strtotime($this->final_start_time) > $now) $status = 0;
  38. else if (strtotime($this->final_end_time) < $now) {
  39. if ($this->status && $this->presell_order_id)
  40. app()->make(PresellOrderRepository::class)->cancel($this->presell_order_id);
  41. $status = 2;
  42. }
  43. return $status;
  44. }
  45. public function getCombinePayParams()
  46. {
  47. return [
  48. 'order_sn' => $this->presell_order_sn,
  49. 'sub_orders' => [
  50. [
  51. 'pay_price' => $this->pay_price,
  52. 'order_sn' => $this->presell_order_sn,
  53. 'sub_mchid' => $this->merchant->sub_mchid,
  54. ]
  55. ],
  56. 'attach' => 'presell',
  57. 'body' => '尾款支付',
  58. ];
  59. }
  60. public function getPayParams($return_url = '')
  61. {
  62. $params = [
  63. 'order_sn' => $this->presell_order_sn,
  64. 'pay_price' => $this->pay_price,
  65. 'attach' => 'presell',
  66. 'body' => '尾款支付'
  67. ];
  68. if ($return_url) {
  69. $params['return_url'] = $return_url;
  70. }
  71. return $params;
  72. }
  73. }