StoreGroupOrder.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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\user\User;
  14. use app\common\repositories\store\coupon\StoreCouponRepository;
  15. class StoreGroupOrder extends BaseModel
  16. {
  17. public static function tablePk(): ?string
  18. {
  19. return 'group_order_id';
  20. }
  21. public static function tableName(): string
  22. {
  23. return 'store_group_order';
  24. }
  25. public function orderList()
  26. {
  27. return $this->hasMany(StoreOrder::class, 'group_order_id', 'group_order_id');
  28. }
  29. public function user()
  30. {
  31. return $this->hasOne(User::class, 'uid', 'uid');
  32. }
  33. public function getGiveCouponAttr()
  34. {
  35. if (count($this->give_coupon_ids))
  36. return app()->make(StoreCouponRepository::class)->getGiveCoupon($this->give_coupon_ids);
  37. return [];
  38. }
  39. public function getCancelTimeAttr()
  40. {
  41. $timer = ((int)systemConfig('auto_close_order_timer')) ?: 15;
  42. return date('m-d H:i', strtotime("+ $timer minutes", strtotime($this->create_time)));
  43. }
  44. public function getCancelUnixAttr()
  45. {
  46. $timer = ((int)systemConfig('auto_close_order_timer')) ?: 15;
  47. return strtotime("+ $timer minutes", strtotime($this->create_time));
  48. }
  49. public function getGiveCouponIdsAttr($value)
  50. {
  51. return $value ? explode(',', $value) : [];
  52. }
  53. public function setGiveCouponIdsAttr($value)
  54. {
  55. return $value ? implode(',', $value) : '';
  56. }
  57. public function getCombinePayParams()
  58. {
  59. $params = [
  60. 'order_sn' => $this->group_order_sn,
  61. 'sub_orders' => [],
  62. 'attach' => 'order',
  63. 'body' => '订单支付',
  64. ];
  65. foreach ($this->orderList as $order) {
  66. if ($order->pay_price > 0) {
  67. $subOrder = [
  68. 'pay_price' => $order->pay_price,
  69. 'order_sn' => $order->order_sn,
  70. 'sub_mchid' => $order->merchant->sub_mchid,
  71. ];
  72. $params['sub_orders'][] = $subOrder;
  73. }
  74. }
  75. return $params;
  76. }
  77. public function getPayParams($return_url = '', $auth_code = '')
  78. {
  79. $params = [
  80. 'order_sn' => $this->group_order_sn,
  81. 'pay_price' => $this->pay_price,
  82. 'attach' => 'order',
  83. 'body' => '订单支付'
  84. ];
  85. if ($return_url) {
  86. $params['return_url'] = $return_url;
  87. }
  88. if ($auth_code) {
  89. $params['auth_code'] = $auth_code;
  90. }
  91. return $params;
  92. }
  93. }