|
@@ -1,9 +1,12 @@
|
|
|
<?php
|
|
|
-namespace App\Repositories;
|
|
|
+namespace App\Repositories\Behavior;
|
|
|
use App\Models\Behavior;
|
|
|
use GuzzleHttp\Client;
|
|
|
use GuzzleHttp\Exception\RequestException;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
use Tymon\JWTAuth\Facades\JWTAuth;
|
|
|
+use Dingo\Api\Http\Response;
|
|
|
+use Symfony\Component\HttpKernel\Exception\HttpException;
|
|
|
|
|
|
/**
|
|
|
* Created by PhpStorm.
|
|
@@ -39,5 +42,42 @@ class BehaviorRepository
|
|
|
return [];
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public function create($request)
|
|
|
+ {
|
|
|
+ $behavior_name = $this->behavior->where(['name'=>$request['name']])->first();
|
|
|
+ if($behavior_name){
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '该行为已存在',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ $data = [
|
|
|
+ 'virus_behavior_id' => $request['virus_behavior_id'],
|
|
|
+ 'name' => $request['name'],
|
|
|
+ 'behavior_level' => $request['behavior_level'],
|
|
|
+ 'behavior_cycle_type' => $request['behavior_cycle_type'],
|
|
|
+ 'is_open' => 0,
|
|
|
+ 'behavior_action_id' => isset($request['behavior_action_id']) ? $request['behavior_action_id'] : 0,
|
|
|
+ 'behavior_cycle' => isset($request['behavior_cycle']) ? $request['behavior_cycle'] : '',
|
|
|
+ 'behavior_binding_users' => isset($request['behavior_binding_users']) ? $request['behavior_binding_users'] : 0,
|
|
|
+ 'physical_strength' => isset($request['physical_strength']) ? $request['physical_strength'] : '',
|
|
|
+ 'rainbow_beans' => isset($request['rainbow_beans']) ? $request['rainbow_beans'] : '',
|
|
|
+ 'remarks' => isset($request['remarks']) ? $request['remarks'] : '',
|
|
|
+ 'behavioral_cycle_start_time' => isset($request['behavioral_cycle_start_time']) ? $request['behavioral_cycle_start_time'] : null,
|
|
|
+ 'behavioral_cycle_end_time' => isset($request['behavioral_cycle_end_time']) ? $request['behavioral_cycle_end_time'] : null,
|
|
|
+ 'allotted_quantity_rule' => isset($request['allotted_quantity_rule']) ? json_encode($request['allotted_quantity_rule']) : '',
|
|
|
+ 'behavior_identification' => isset($request['behavior_identification']) ? $request['behavior_identification'] : '',
|
|
|
+ 'trigger_times' => isset($request['trigger_times']) ? $request['trigger_times'] : 0,
|
|
|
+ 'effective_trigger' => isset($request['effective_trigger']) ? $request['effective_trigger'] : 0,
|
|
|
+ 'relative_series' => isset($request['relative_series']) ? $request['relative_series'] : 0,
|
|
|
+ 'absolute_progression' => isset($request['absolute_progression']) ? $request['absolute_progression'] : 0,
|
|
|
+ ];
|
|
|
+
|
|
|
+ if (!$this->behavior->create($data)) {
|
|
|
+ throw new HttpException(500, '添加失败,请重试');
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|