Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "user":{
- "id":6,
- "vouchers":[
- {
- "id":2,
- "affects":"subscription_items",
- "type":"percentage",
- "value":"20",
- "pivot":{
- "user_id":6,
- "voucher_id":2,
- "duration":4,
- "created_at":"2015-04-26 20:44:46",
- "updated_at":"2015-04-26 20:49:05"
- }
- },
- {
- "id":3,
- "code":"giftbox",
- "affects":"giftboxes",
- "type":"percentage",
- "value":"25",
- "pivot":{
- "user_id":6,
- "voucher_id":3,
- "duration":1,
- "created_at":"2015-04-26 21:25:15",
- "updated_at":"2015-04-26 21:25:15"
- }
- }
- ]
- },
- }
- private function vouchers_that_affect($list)
- {
- /*
- * If there is no user, abort
- */
- if( ! $this->user ) return false;
- return array_where($this->user->vouchers, function($key, $voucher) use ($list)
- {
- return
- /*
- * Where they effect the right thing, they
- * haven't already been used too many times.
- */
- in_array($voucher->affects, $list)
- && $voucher->pivot->duration > 0;
- });
- }
- $this->giftbox_vouchers = $this->vouchers_that_affect(['giftboxes', 'giftbox_additional_items']);
- $this->subscription_vouchers = $this->vouchers_that_affect(['subscription_items', 'additional_items', 'subscription_base_price']);
- "subscription_vouchers":[
- {
- "id":2,
- "code":"subscription",
- "affects":"subscription_items",
- "type":"percentage",
- "value":"20",
- "pivot":{
- "user_id":6,
- "voucher_id":2,
- "duration":4,
- "created_at":"2015-04-26 20:44:46",
- "updated_at":"2015-04-26 20:49:05"
- }
- }
- ],
- "giftbox_vouchers":{
- "1":{
- "id":3,
- "code":"giftbox",
- "affects":"giftboxes",
- "type":"percentage",
- "value":"25",
- "pivot":{
- "user_id":6,
- "voucher_id":3,
- "duration":1,
- "created_at":"2015-04-26 21:25:15",
- "updated_at":"2015-04-26 21:25:15"
- }
- }
- },
- "subscription_vouchers":[
- {
- "id":2,
- }
- ],
- "giftbox_vouchers":{
- "1":{
- "id":3,
- }
- },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement