Order.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace app\admin\model\shopro\activity;
  3. use app\admin\model\shopro\Common;
  4. use addons\shopro\facade\Activity as ActivityFacade;
  5. class Order extends Common
  6. {
  7. protected $name = 'shopro_activity_order';
  8. protected $type = [
  9. 'ext' => 'json',
  10. ];
  11. // 追加属性
  12. protected $append = [
  13. 'status_text',
  14. 'activity_type_text',
  15. 'discount_text'
  16. ];
  17. const STATUS_UNPAID = 'unpaid';
  18. const STATUS_PAID = 'paid';
  19. public function statusList()
  20. {
  21. return [
  22. 'unpaid' => '未支付',
  23. 'paid' => '已支付',
  24. ];
  25. }
  26. // 未支付
  27. public function scopeUnpaid($query)
  28. {
  29. return $query->where('status', self::STATUS_UNPAID);
  30. }
  31. // 已支付
  32. public function scopePaid($query)
  33. {
  34. return $query->whereIn('status', [self::STATUS_PAID]);
  35. }
  36. public function getActivityTypeTextAttr($value, $data)
  37. {
  38. $value = $value ?: ($data['activity_type'] ?? null);
  39. $ext = $this->ext;
  40. $list = (new Activity)->typeList();
  41. $text = isset($list[$value]) ? $list[$value] : '';
  42. if (in_array($value, ['groupon', 'groupon_ladder'])) {
  43. if (in_array($data['status'], [self::STATUS_PAID]) && (!isset($ext['groupon_id']) || !$ext['groupon_id'])) {
  44. // 已支付,并且没有团 id,就是单独购买
  45. $text .= '-单独购买';
  46. }
  47. }
  48. return $text;
  49. }
  50. public function getDiscountTextAttr($value, $data)
  51. {
  52. $ext = $this->ext;
  53. $discount_text = '';
  54. if ($ext && isset($ext['rules']) && $ext['rules']) {
  55. $tags = ActivityFacade::formatRuleTags([
  56. 'type' => $ext['rules']['rule_type'],
  57. 'discounts' => [$ext['rules']['discount_rule']]
  58. ], $data['activity_type']);
  59. $discount_text = $tags[0] ?? '';
  60. }
  61. return $discount_text ?: $this->activity_type_text;
  62. }
  63. public function getGoodsIdsAttr($value, $data)
  64. {
  65. return $this->attrFormatComma($value, $data, 'goods_ids', true);
  66. }
  67. }