链街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.

74 lines
1.7 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. class ShareCardCreateForm extends Form
  8. {
  9. /**
  10. * Handle the form request.
  11. *
  12. * @param array $input
  13. *
  14. * @return Response
  15. */
  16. public function handle(array $input)
  17. {
  18. $list = Redis::hgetall(RedisKey::PROGRAM_SHARE_CARD);
  19. $id = count($list) + 1;
  20. if(key_exists($id,$list)){
  21. $rand = [];
  22. for($i = 1; $i <= $id; $i++){
  23. $rand[] = $i;
  24. }
  25. $keyExist = array_keys($list);
  26. $vacant = array_diff($rand,$keyExist);
  27. $id = array_shift($vacant) ?? time();
  28. }
  29. $ossImageDir = config('filesystems.disks.oss.img_host');
  30. $data = [
  31. 'id' => $id,
  32. 'title' => $input['title'],
  33. 'image' => $ossImageDir.'/'.$input['image'],
  34. 'relative_path' => $input['image'],
  35. ];
  36. $data = json_encode($data);
  37. $res = Redis::hset(RedisKey::PROGRAM_SHARE_CARD ,$id, $data);
  38. if($res){
  39. return $this->success('添加成功','/share_card_setting');
  40. }else{
  41. return $this->error('添加失败或被替换');
  42. }
  43. }
  44. /**
  45. * Build a form here.
  46. */
  47. public function form()
  48. {
  49. $this->display('setting' , ' ')->value('小程序分享卡片设置');
  50. $this->text('title','标题')->required();
  51. $this->image('image','图片')->required()->autoUpload()->width(3);
  52. }
  53. /**
  54. * The data of the form.
  55. *
  56. * @return array
  57. */
  58. public function default()
  59. {
  60. return [];
  61. }
  62. }