StoreGroupOrder.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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. }