LevelPercent.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace App\Admin\Forms;
  3. use Dcat\Admin\Widgets\Form;
  4. use Dcat\Admin\Traits\LazyWidget;
  5. use Dcat\Admin\Contracts\LazyRenderable;
  6. // 修改礼盒不同级别的概率和回收的贴纸数
  7. class LevelPercent extends Form implements LazyRenderable
  8. {
  9. use LazyWidget;
  10. /**
  11. * Handle the form request.
  12. *
  13. * @param array $input
  14. *
  15. * @return mixed
  16. */
  17. public function handle(array $input)
  18. {
  19. //
  20. $val = 0;
  21. foreach($input as $k=>$v) {
  22. $val += $v;
  23. }
  24. if($val !=100) {
  25. return $this->response()->error('出错了,概率之和不等于100');
  26. }
  27. //
  28. $obj = \App\Models\Config::where("key", "box_level_percent")->first();
  29. if(!$obj) {
  30. $obj = new \App\Models\Config();
  31. $obj->key = "box_level_percent";
  32. }
  33. $obj->val = json_encode($input);
  34. $obj->save();
  35. //
  36. return $this
  37. ->response()
  38. ->success('修改成功')
  39. ->refresh();
  40. }
  41. /**
  42. * Build a form here.
  43. */
  44. public function form()
  45. {
  46. //
  47. $this->currency("N", "N级")->symbol('%')->required();
  48. $this->currency("R", "R级")->symbol('%')->required();
  49. $this->currency("SR", "SR级")->symbol('%')->required();
  50. $this->currency("SSR", "SSR级")->symbol('%')->required();
  51. //
  52. }
  53. /**
  54. * The data of the form.
  55. *
  56. * @return array
  57. */
  58. public function default()
  59. {
  60. //
  61. return (new \App\Http\Controllers\BoxController())->getLevelPercent();
  62. // $obj = \App\Models\Config::where("key", "box_level_percent")->first();
  63. // if ($obj && $obj->val) {
  64. // $data = json_decode($obj->val, true);
  65. // if ($data) {
  66. // return $data;
  67. // }
  68. // }
  69. // //
  70. // return config("avatar.box_level_percent");
  71. }
  72. }