BehaviorController.php 3.9 KB

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