|
|
|
@ -6,6 +6,7 @@ use Dcat\Admin\Widgets\Form; |
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
|
|
use App\Libs\SsdbClient; |
|
|
|
use App\Models\v3\Category as CategoryModel; |
|
|
|
use Illuminate\Support\Facades\DB; |
|
|
|
|
|
|
|
class CategoryTieForm extends Form |
|
|
|
{ |
|
|
|
@ -22,37 +23,31 @@ class CategoryTieForm extends Form |
|
|
|
public function handle(array $input) |
|
|
|
{ |
|
|
|
$ids = $input['category_ids']; |
|
|
|
$category = CategoryModel::select('id','title','cover_img','sort')->whereIn('id',$ids)->get(); |
|
|
|
$category = CategoryModel::select('id','title','cover_img','sort')->whereIn('id',$ids)->orderBy('sort','desc')->get(); |
|
|
|
$data = []; |
|
|
|
if(!empty($category)){ |
|
|
|
foreach ($category as $key => $value){ |
|
|
|
$data[$value->sort] = [ |
|
|
|
$data[$value->id] = json_encode([ |
|
|
|
'icon' => $value->cover_img, |
|
|
|
'name' => $value->title, |
|
|
|
'sort' => $value->sort, |
|
|
|
'id' => $value->id |
|
|
|
]; |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
if(count($data) > 0){ |
|
|
|
// 根据sort排序
|
|
|
|
krsort($data); |
|
|
|
$save = array_column($data,null,'id'); |
|
|
|
foreach($save as &$cate){ |
|
|
|
$cate = json_encode($cate); |
|
|
|
} |
|
|
|
|
|
|
|
$this->ssdb->client()->hclear('applet_index_category'); |
|
|
|
|
|
|
|
$category = $this->ssdb->client()->multi_hset('applet_index_category',$save); |
|
|
|
$category = $this->ssdb->client()->multi_hset('applet_index_category',$data); |
|
|
|
|
|
|
|
if($category === false){ |
|
|
|
return $this->error('修改失败'); |
|
|
|
return $this->error('绑定失败'); |
|
|
|
} |
|
|
|
return $this->success('修改成功', '/category'); |
|
|
|
return $this->success('绑定成功', '/category'); |
|
|
|
} |
|
|
|
} |
|
|
|
return $this->success('未进行修改或者查询不到分类', '/category'); |
|
|
|
return $this->success('未进行绑定或者查询不到分类', '/category'); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
|