CouponSet.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 CouponSet 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. $obj = \App\Models\Config::where("key", "coupon_configs")->first();
  21. if(!$obj) {
  22. $obj = new \App\Models\Config();
  23. $obj->key = "coupon_configs";
  24. }
  25. $obj->val = json_encode($input);
  26. $obj->save();
  27. //
  28. return $this
  29. ->response()
  30. ->success('修改成功')
  31. ->refresh();
  32. }
  33. /**
  34. * Build a form here.
  35. */
  36. public function form()
  37. {
  38. //
  39. $this->text("img_title", "排期标题")->required();
  40. $this->image("img", "排期图片")->uniqueName()->removable(false)->autoUpload()->required();
  41. $this->text("desc_title", "规则标题")->required();
  42. $this->textarea("desc", "规则文案")->required();
  43. $this->textarea("pop_desc", "弹窗规则文案")->required();
  44. //
  45. }
  46. /**
  47. * The data of the form.
  48. *
  49. * @return array
  50. */
  51. public function default()
  52. {
  53. //
  54. $obj = \App\Models\Config::where("key", "coupon_configs")->first();
  55. if ($obj && $obj->val) {
  56. $data = json_decode($obj->val, true);
  57. if ($data) {
  58. return $data;
  59. }
  60. }
  61. return [
  62. 'img_title'=> '限定活动排期',
  63. 'img'=> '',
  64. 'desc_title'=> '如何获得更多礼劵?',
  65. 'desc'=> '',
  66. 'pop_desc'=> '',
  67. ];
  68. }
  69. }