StoreGroupOrder.php 2.5 KB

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