Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. {
  2. "user":{
  3. "id":6,
  4. "vouchers":[
  5. {
  6. "id":2,
  7. "affects":"subscription_items",
  8. "type":"percentage",
  9. "value":"20",
  10. "pivot":{
  11. "user_id":6,
  12. "voucher_id":2,
  13. "duration":4,
  14. "created_at":"2015-04-26 20:44:46",
  15. "updated_at":"2015-04-26 20:49:05"
  16. }
  17. },
  18. {
  19. "id":3,
  20. "code":"giftbox",
  21. "affects":"giftboxes",
  22. "type":"percentage",
  23. "value":"25",
  24. "pivot":{
  25. "user_id":6,
  26. "voucher_id":3,
  27. "duration":1,
  28. "created_at":"2015-04-26 21:25:15",
  29. "updated_at":"2015-04-26 21:25:15"
  30. }
  31. }
  32. ]
  33. },
  34. }
  35.  
  36. private function vouchers_that_affect($list)
  37. {
  38. /*
  39. * If there is no user, abort
  40. */
  41. if( ! $this->user ) return false;
  42. return array_where($this->user->vouchers, function($key, $voucher) use ($list)
  43. {
  44. return
  45. /*
  46. * Where they effect the right thing, they
  47. * haven't already been used too many times.
  48. */
  49. in_array($voucher->affects, $list)
  50. && $voucher->pivot->duration > 0;
  51. });
  52. }
  53.  
  54. $this->giftbox_vouchers = $this->vouchers_that_affect(['giftboxes', 'giftbox_additional_items']);
  55. $this->subscription_vouchers = $this->vouchers_that_affect(['subscription_items', 'additional_items', 'subscription_base_price']);
  56.  
  57. "subscription_vouchers":[
  58. {
  59. "id":2,
  60. "code":"subscription",
  61. "affects":"subscription_items",
  62. "type":"percentage",
  63. "value":"20",
  64. "pivot":{
  65. "user_id":6,
  66. "voucher_id":2,
  67. "duration":4,
  68. "created_at":"2015-04-26 20:44:46",
  69. "updated_at":"2015-04-26 20:49:05"
  70. }
  71. }
  72. ],
  73. "giftbox_vouchers":{
  74. "1":{
  75. "id":3,
  76. "code":"giftbox",
  77. "affects":"giftboxes",
  78. "type":"percentage",
  79. "value":"25",
  80. "pivot":{
  81. "user_id":6,
  82. "voucher_id":3,
  83. "duration":1,
  84. "created_at":"2015-04-26 21:25:15",
  85. "updated_at":"2015-04-26 21:25:15"
  86. }
  87. }
  88. },
  89.  
  90. "subscription_vouchers":[
  91. {
  92. "id":2,
  93. }
  94. ],
  95. "giftbox_vouchers":{
  96. "1":{
  97. "id":3,
  98. }
  99. },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement