链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
3.6 KiB

  1. <?php
  2. namespace App\Admin\Forms\v3;
  3. use Dcat\Admin\Widgets\Form;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Illuminate\Support\Facades\Redis;
  6. use App\Libs\Redis\RedisKey;
  7. use Dcat\Admin\Contracts\LazyRenderable;
  8. use Dcat\Admin\Traits\LazyWidget;
  9. use function Graze\GuzzleHttp\JsonRpc\json_decode;
  10. class OfficialSubscribeInfoForm extends Form implements LazyRenderable
  11. {
  12. use LazyWidget;
  13. /**
  14. * Handle the form request.
  15. *
  16. * @param array $input
  17. *
  18. * @return Response
  19. */
  20. public function handle(array $input)
  21. {
  22. $subscribed = [
  23. 'head_title' => $input['head_title'],
  24. 'logo' => $input['logo'],
  25. 'title' => $input['title'],
  26. 'sub_title' => $input['sub_title'],
  27. 'redirect_url' => $input['redirect_url'],
  28. ];
  29. $notSubscribed = [
  30. 'head_title' => $input['not_head_title'],
  31. 'logo' => $input['not_logo'],
  32. 'title' => $input['not_title'],
  33. 'sub_title' => $input['not_sub_title'],
  34. 'redirect_url' => $input['not_redirect_url'],
  35. ];
  36. $data = [
  37. 'subscribed' => json_encode($subscribed),
  38. 'not_subscribed' => json_encode($notSubscribed)
  39. ];
  40. $res = Redis::hmset(RedisKey::OFFICIAL_SUBSCRIBE_INFO, $data);
  41. if($res !== false){
  42. return $this->success('修改成功','/official_subscribe_info');
  43. }else{
  44. return $this->error('修改失败');
  45. }
  46. }
  47. /**
  48. * Build a form here.
  49. */
  50. public function form()
  51. {
  52. $data = Redis::hgetall(RedisKey::OFFICIAL_SUBSCRIBE_INFO);
  53. $subscribed = isset($data['subscribed']) ? json_decode( $data['subscribed'],true):[];
  54. $notSubscribed = isset($data['not_subscribed']) ? json_decode( $data['not_subscribed'],true):[];
  55. $this->column(6,function(Form $form) use($subscribed){
  56. $this->display( 'setting', ' ')->value('已关注公众号提示信息设置');
  57. $this->text('head_title','顶部标题')->required()->value($subscribed['head_title']);
  58. $this->image('logo','公众号logo连接')->required()->autoUpload()->saveFullUrl()
  59. ->customFormat(function() use($subscribed){
  60. return [$subscribed['logo']];
  61. });
  62. $this->text('title','公众号名称或标题')->required()->value($subscribed['title']);
  63. $this->text('sub_title','副标题,提示语')->required()->value($subscribed['sub_title']);
  64. $this->text('redirect_url','跳转连接')->required()->value($subscribed['redirect_url']);
  65. });
  66. $this->column(6,function(Form $form) use($notSubscribed){
  67. $this->display( 'setting', ' ')->value('未关注公众号提示信息设置');
  68. $this->text('not_head_title','顶部标题')->required()->value($notSubscribed['head_title']);
  69. $this->image('not_logo','公众号logo连接')->required()->autoUpload()->saveFullUrl()
  70. ->customFormat(function() use($notSubscribed){
  71. return [$notSubscribed['logo']];
  72. });
  73. $this->text('not_title','公众号名称或标题')->required()->value($notSubscribed['title']);
  74. $this->text('not_sub_title','副标题,提示语')->required()->value($notSubscribed['sub_title']);
  75. $this->text('not_redirect_url','跳转连接')->required()->value($notSubscribed['redirect_url']);
  76. });
  77. }
  78. /**
  79. * The data of the form.
  80. *
  81. * @return array
  82. */
  83. public function default()
  84. {
  85. return [];
  86. }
  87. }