Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.4 kB
1
Indexable
Never
public function getAvailableVoucher($user){
        //
        $allCodes = $this->getUserVoucherListWithRule($user->id, country()->country_id);
        $voucherLists = array();

        foreach ($allCodes as $allCode) {

            foreach ($allCode->voucher as $couponCode) {

                if($couponCode->general_type == 'breakdown') {
                    $totalUsageThisMonths = $this->monthlyUsageShipping($user->id,str_replace("-","",$couponCode->coupon_code));
                    if ($couponCode->coupon_status == 'valid' && $totalUsageThisMonths < $allCode->rule->limit) {
                        // return $allCode->rule->limit;
                        // dd($couponCode);
                        $voucherLists[$couponCode->coupon_code]['discount_code'] = $couponCode->coupon_code;
                        $voucherLists[$couponCode->coupon_code]['discount_amount'] = $couponCode->coupon_amount;
                    }
                }
                else {
                    if ($couponCode->coupon_status == 'valid') {
                        $voucherLists[$couponCode->coupon_code]['discount_code'] = $couponCode->coupon_code;
                        $voucherLists[$couponCode->coupon_code]['discount_amount'] = $couponCode->coupon_amount;
                    }
                }
            }
        }

        return $voucherLists;
    }