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
74 lines
1.7 KiB
<?php
|
|
|
|
namespace App\Admin\Forms\v3;
|
|
|
|
use Dcat\Admin\Widgets\Form;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Illuminate\Support\Facades\Redis;
|
|
use App\Libs\Redis\RedisKey;
|
|
|
|
class ShareCardCreateForm extends Form
|
|
{
|
|
|
|
/**
|
|
* Handle the form request.
|
|
*
|
|
* @param array $input
|
|
*
|
|
* @return Response
|
|
*/
|
|
public function handle(array $input)
|
|
{
|
|
$list = Redis::hgetall(RedisKey::PROGRAM_SHARE_CARD);
|
|
|
|
$id = count($list) + 1;
|
|
if(key_exists($id,$list)){
|
|
$rand = [];
|
|
for($i = 1; $i <= $id; $i++){
|
|
$rand[] = $i;
|
|
}
|
|
$keyExist = array_keys($list);
|
|
$vacant = array_diff($rand,$keyExist);
|
|
$id = array_shift($vacant) ?? time();
|
|
}
|
|
$ossImageDir = config('filesystems.disks.oss.img_host');
|
|
|
|
$data = [
|
|
'id' => $id,
|
|
'title' => $input['title'],
|
|
'image' => $ossImageDir.'/'.$input['image'],
|
|
'relative_path' => $input['image'],
|
|
];
|
|
|
|
$data = json_encode($data);
|
|
|
|
$res = Redis::hset(RedisKey::PROGRAM_SHARE_CARD ,$id, $data);
|
|
if($res){
|
|
return $this->success('添加成功','/share_card_setting');
|
|
}else{
|
|
return $this->error('添加失败或被替换');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Build a form here.
|
|
*/
|
|
public function form()
|
|
{
|
|
$this->display('setting' , ' ')->value('小程序分享卡片设置');
|
|
|
|
$this->text('title','标题')->required();
|
|
$this->image('image','图片')->required()->autoUpload()->width(3);
|
|
}
|
|
|
|
/**
|
|
* The data of the form.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function default()
|
|
{
|
|
return [];
|
|
}
|
|
|
|
}
|