BehaviorController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace App\Http\Controllers\Behavior;
  3. /**
  4. * Created by PhpStorm.
  5. * User: durong
  6. * Date: 2019/6/12
  7. * Time: 上午11:09
  8. */
  9. use App\Http\Controllers\Controller;
  10. use App\Repositories\Behavior\BehaviorRepository;
  11. use App\Transformers\Behavior\BehaviorTransformer;
  12. use Illuminate\Http\Request;
  13. use Illuminate\Validation\Rule;
  14. use League\Fractal\Manager;
  15. use League\Fractal\Pagination\IlluminatePaginatorAdapter;
  16. use League\Fractal\Resource\Collection;
  17. use Illuminate\Support\Facades\Validator;
  18. class BehaviorController extends Controller
  19. {
  20. public function __construct(BehaviorRepository $behaviorRepository)
  21. {
  22. $this->behaviorRepository = $behaviorRepository;
  23. }
  24. /**
  25. * 行为列表
  26. */
  27. public function index(Request $request)
  28. {
  29. $behavior_list = $this->behaviorRepository->index($request->all());
  30. if (count($behavior_list)>0){
  31. foreach ($behavior_list as $k=>$v){
  32. if (isset($behavior_list[$k]['_id']) || isset($behavior_list[$k]['behavior_name'])){
  33. $behavior_list[$k]['_id'] = $v['_id'];
  34. $behavior_list[$k]['behavior_name'] = $v['behavior_name'];
  35. $behavior_list[$k]['virus_behavior_id'] = $v['_id'];
  36. $behavior_list[$k]['name'] = $v['behavior_name'];
  37. unset($behavior_list[$k]['_id']);
  38. unset($behavior_list[$k]['behavior_name']);
  39. }
  40. }
  41. }
  42. $data['data'] = $behavior_list;
  43. $data['extra'] = [
  44. 'filters' => [
  45. 'virus_behavior_id',
  46. 'behavior_status',
  47. 'name',
  48. ],
  49. 'columns' => [
  50. 'id',
  51. 'virus_behavior_id',
  52. 'name',
  53. 'behavior_level',
  54. 'behavior_cycle_type',
  55. 'behavior_action_id',
  56. 'behavior_cycle',
  57. 'behavior_binding_users',
  58. 'physical_strength',
  59. 'rainbow_beans',
  60. 'remarks',
  61. 'is_open',
  62. 'behavioral_cycle_start_time',
  63. 'behavioral_cycle_end_time',
  64. 'allotted_quantity_rule',
  65. 'behavior_identification',
  66. 'trigger_times',
  67. 'effective_trigger',
  68. 'relative_series',
  69. 'absolute_progression',
  70. 'created_at',
  71. 'updated_at'
  72. ]
  73. ];
  74. return $data;
  75. }
  76. //登记行为
  77. public function create(Request $request)
  78. {
  79. $validator = Validator::make($request->all(), [
  80. 'virus_behavior_id' => 'required',
  81. 'name' => 'required|string',
  82. 'behavior_level' => ['required',Rule::in(0, 1)],
  83. 'behavior_cycle_type' => ['required',Rule::in(0, 1)],
  84. ]);
  85. if ($validator->fails()) {
  86. return $this->response->error($validator->errors()->first(), 500);
  87. }
  88. return $this->behaviorRepository->create($request->all());
  89. }
  90. //编辑行为
  91. public function edit(Request $request)
  92. {
  93. $validator = Validator::make($request->all(), [
  94. 'id' => 'required|exists:behavior',
  95. 'virus_behavior_id' => 'required',
  96. 'name' => 'required|string',
  97. 'behavior_level' => 'required|integer',
  98. 'behavior_cycle_type' => ['required',Rule::in(0, 1)],
  99. ]);
  100. if ($validator->fails()) {
  101. return $this->response->error($validator->errors()->first(), 500);
  102. }
  103. return $this->behaviorRepository->edit($request->all());
  104. }
  105. //行为管理
  106. public function editStatus(Request $request)
  107. {
  108. $validator = Validator::make($request->all(), [
  109. 'id' => 'required|exists:behavior',
  110. 'is_open' => ['required', Rule::in(0,1)],
  111. ]);
  112. if ($validator->fails()) {
  113. return $this->response->error($validator->errors()->first(), 500);
  114. }
  115. return $this->behaviorRepository->editStatus($request->all());
  116. }
  117. }