当前位置: 首页>>代码示例>>PHP>>正文


PHP Plan::findOrFail方法代码示例

本文整理汇总了PHP中Plan::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Plan::findOrFail方法的具体用法?PHP Plan::findOrFail怎么用?PHP Plan::findOrFail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Plan的用法示例。


在下文中一共展示了Plan::findOrFail方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: generate

 public static function generate($input)
 {
     $res = [];
     $plan = Plan::findOrFail($input['plan_id']);
     $voucher['expires_on'] = self::_makeExpiry($input['validity'], $input['validity_unit']);
     $voucher['created_at'] = time();
     $voucher['plan_name'] = $plan->name;
     $voucher['plan_type'] = $plan->plan_type;
     $voucher['sim_sessions'] = $plan->sim_sessions;
     $voucher['interim_updates'] = $plan->interim_updates;
     $voucher['price'] = $plan->price;
     $voucher['validity'] = $plan->validity;
     $voucher['validity_unit'] = $plan->validity_unit;
     $voucher['policy_type'] = $plan->policy_type;
     if ($plan->plan_type == 1) {
         //if limited
         $limit = $plan->limit->toArray();
         if ($plan->limit->aq_access == 1) {
             // $limit['aq_access'] = 1;
             $aq_policy = Policy::findOrFail($plan->limit->aq_policy);
             $limit['aq_policy'] = mikrotikRateLimit($aq_policy->toArray());
         }
         $voucher_limit = VoucherLimit::create($limit);
         $voucher['limit_id'] = $voucher_limit->id;
     }
     if ($plan->policy_type == 'Policy') {
         $policy = new VoucherPolicy(['bw_policy' => mikrotikRateLimit($plan->policy->toArray())]);
         $policy->save();
     } elseif ($plan->policy_type == 'PolicySchema') {
         $days = ['mo' => 'monday', 'tu' => 'tuesday', 'we' => 'wednesday', 'th' => 'thursday', 'fr' => 'friday', 'sa' => 'saturday', 'su' => 'sunday'];
         foreach ($days as $d => $day) {
             $tpl = $plan->policy->{$day}->toArray();
             $type = ['bw_policy', 'pr_policy', 'sec_policy'];
             foreach ($type as $t) {
                 if (!is_null($tpl[$t])) {
                     $policy = Policy::find($tpl[$t])->toArray();
                     $tpl[$t] = mikrotikRateLimit($policy);
                 }
             }
             $template = VoucherPolicySchemaTemplate::create($tpl);
             $schema[$d] = $template->id;
         }
         $policy = VoucherPolicySchema::create($schema);
     }
     $voucher['policy_id'] = $policy->id;
     for ($i = 0; $i < $input['count']; $i++) {
         $voucher['pin'] = self::generatePin();
         $voucher['expires_on'] = self::_makeExpiry($input['validity'], $input['validity_unit']);
         $v = new Voucher($voucher);
         if (!$v->save()) {
             return FALSE;
         }
         $res[] = $v->pin;
     }
     return $res;
 }
开发者ID:guilhermefilippo,项目名称:access-manager,代码行数:56,代码来源:Voucher.php

示例2: AssignPlan

 public static function AssignPlan($user_id, $plan_id, $price = NULL)
 {
     DB::transaction(function () use($user_id, $plan_id, $price) {
         $oldPlan = APActivePlan::where('user_id', $user_id)->first();
         if (!is_null($oldPlan)) {
             self::updatePlanHistory($oldPlan);
         } else {
             $oldPlan = new ApActivePlan();
         }
         $plan = Plan::findOrFail($plan_id);
         $newPlan = ['user_id' => $user_id, 'plan_name' => $plan->name, 'plan_type' => $plan->plan_type, 'policy_type' => $plan->policy_type, 'sim_sessions' => $plan->sim_sessions, 'interim_updates' => $plan->interim_updates, 'aq_invocked' => 0, 'price' => $plan->price, 'time_balance' => NULL, 'data_balance' => NULL, 'assigned_on' => date("Y-m-d H:i:s"), 'validity' => $plan->validity, 'validity_unit' => $plan->validity_unit];
         if ($price != NULL) {
             $newPlan['price'] = $price;
         }
         if ($plan->plan_type == LIMITED) {
             $limit = $plan->limit;
             if ($limit->limit_type == TIME_LIMIT || $limit->limit_type == BOTH_LIMITS) {
                 $newPlan['time_balance'] = $limit->time_limit * constant($limit->time_unit);
             }
             if ($limit->limit_type == DATA_LIMIT || $limit->limit_type == BOTH_LIMITS) {
                 $newPlan['data_balance'] = $limit->data_limit * constant($limit->data_unit);
             }
             if ($limit->aq_access == ALLOWED) {
                 $aq_policy = Policy::findOrFail($limit->aq_policy);
                 $limit->aq_policy = mikrotikRateLimit($aq_policy->toArray());
             }
             $planLimit = APLimit::create($limit->toArray());
             $newPlan['limit_id'] = $planLimit->id;
         }
         if ($plan->policy_type == 'Policy') {
             $policy = APPolicy::create(['bw_policy' => mikrotikRateLimit($plan->policy->toArray())]);
         } elseif ($plan->policy_type == 'PolicySchema') {
             $days = ['mo' => 'monday', 'tu' => 'tuesday', 'we' => 'wednesday', 'th' => 'thursday', 'fr' => 'friday', 'sa' => 'saturday', 'su' => 'sunday'];
             foreach ($days as $d) {
                 $tpl = $plan->policy->{$day}->toArray();
                 $types = ['bw_policy', 'pr_policy', 'sec_policy'];
                 foreach ($types as $t) {
                     if (!is_null($tpl[$t])) {
                         $policy = Policy::find($tpl[$t])->toArray();
                         $tpl[$t] = mikrotikRateLimit($policy);
                     }
                 }
                 $template = APPolicySchemaTemplate::create($tpl);
                 $schema[$d] = $template->id;
             }
             $policy = APPolicySchema::create($schema);
         }
         $newPlan['policy_id'] = $policy->id;
         $oldPlan->fill($newPlan);
         $oldPlan->save();
         return TRUE;
     });
 }
开发者ID:guilhermefilippo,项目名称:access-manager,代码行数:53,代码来源:APActivePlan.php


注:本文中的Plan::findOrFail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。