From 12c47091c4fea9cd21cb39c947a0013fe56f077b Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Fri, 4 Sep 2020 17:08:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=B1=BB=E7=BB=91=E5=AE=9A=E5=88=B0?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E9=A6=96=E9=A1=B5=E5=AF=BC=E8=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Actions/Tree/CategoryTie.php | 41 +++++++------- .../Controllers/v3/CategoryController.php | 18 +++--- app/Admin/Extensions/TypeCorrelationBind.php | 34 ------------ app/Admin/Forms/CategoryTieForm.php | 55 +++++++++---------- app/Admin/routes.php | 7 ++- app/Models/v3/Category.php | 3 +- resources/lang/zh-CN/category-tie.php | 13 +++++ 7 files changed, 75 insertions(+), 96 deletions(-) delete mode 100644 app/Admin/Extensions/TypeCorrelationBind.php create mode 100644 resources/lang/zh-CN/category-tie.php diff --git a/app/Admin/Actions/Tree/CategoryTie.php b/app/Admin/Actions/Tree/CategoryTie.php index 2a07335..f98d23a 100644 --- a/app/Admin/Actions/Tree/CategoryTie.php +++ b/app/Admin/Actions/Tree/CategoryTie.php @@ -13,10 +13,11 @@ use App\Models\v3\Category as CategoryModel; class CategoryTie extends AbstractTool { + /** * @return string */ - protected $title = '绑定分类到首页'; + protected $title = '绑定分类到首页导航'; /** * Handle the action request. @@ -28,17 +29,17 @@ class CategoryTie extends AbstractTool public function handle(Request $request) { return $this->response() - ->success('Processed successfully.') - ->redirect('/category'); + ->success('跳转到绑定页面' ) + ->redirect('/categoryTie'); } /** * @return string|void */ - public function href() - { + // public function href() + // { // return admin_url('category/tie'); - } + // } /** * @return string|array|void @@ -48,20 +49,20 @@ class CategoryTie extends AbstractTool // return ['Confirm?', 'contents']; } - /** - * 添加JS - * - * @return string - */ - protected function script() - { - return <<branch(function ($branch) { // 查询分类ssdb + $ssdb = new SsdbClient(); + $category = $ssdb->client()->hgetall('applet_index_category'); + $select = array_keys($category); $src = $branch['cover_img_url']; $logo = ""; $actions = ''; - $actions = ($branch['parent_id'] == 0) ?'已绑定':$actions; - + $actions = (in_array($branch['id'],$select)) ?'已绑定':$actions; + return "{$branch['id']} - {$branch['title']} $logo $actions"; }); $tree->tools(function (Tree\Tools $tools) { @@ -43,14 +47,14 @@ class CategoryController extends AdminController public function form() { return Form::make(new Category(),function (Form $form){ - + // 只查一级 $parentList = Category::getCategoryArray([['parent_id','=',0]],[0=>'顶级']); $form->select('parent_id')->default(0)->options($parentList); $form->text('title'); $form->image('cover_img'); - + $form->number('sort'); $form->disableResetButton(); @@ -60,13 +64,11 @@ class CategoryController extends AdminController }); } - public function CategoryTieForm(Content $content) + public function CategoryTieForms(Content $content) { - return $content ->title('绑定分类到首页') - ->body(new Card(new CategoryTieForm()), function (Form $form) { - }); + ->body(new Card(new CategoryTieForm())); } /** diff --git a/app/Admin/Extensions/TypeCorrelationBind.php b/app/Admin/Extensions/TypeCorrelationBind.php deleted file mode 100644 index d1f1fb5..0000000 --- a/app/Admin/Extensions/TypeCorrelationBind.php +++ /dev/null @@ -1,34 +0,0 @@ -setHtmlAttribute(['class' => 'coupon-edit-row']); - return parent::html(); - } - -} diff --git a/app/Admin/Forms/CategoryTieForm.php b/app/Admin/Forms/CategoryTieForm.php index 5a9dc05..01f7e36 100644 --- a/app/Admin/Forms/CategoryTieForm.php +++ b/app/Admin/Forms/CategoryTieForm.php @@ -5,12 +5,11 @@ namespace App\Admin\Forms; use Dcat\Admin\Widgets\Form; use Symfony\Component\HttpFoundation\Response; use App\Libs\SsdbClient; +use App\Models\v3\Category as CategoryModel; class CategoryTieForm extends Form { - /** - * - */ + protected $ssdb; /** @@ -22,19 +21,24 @@ class CategoryTieForm extends Form */ public function handle(array $input) { + $ids = $input['category_ids']; + $category = CategoryModel::select('id','title','cover_img')->whereIn('id',$ids)->get(); + $data = []; + if(!empty($category)){ + foreach ($category as $key => $value){ + $data[$value->id] = json_encode([ + 'icon' => $value->cover_img, + 'name' => $value->title + ]); + } + } - $data = [ - 'activity' => $input['activity'], - 'forward' => $input['forward'], - 'repay' => $input['repay'], - ]; - - $coupon = $this->ssdb->client()->multi_hset('coupon_rebate_activity',$data); - if($coupon === false){ + $category = $this->ssdb->client()->multi_hset('applet_index_category',$data); + if($category === false){ return $this->error('修改失败'); } - - return $this->success('修改成功', '/couponTie'); + + return $this->success('修改成功', '/category'); } /** @@ -42,19 +46,14 @@ class CategoryTieForm extends Form */ public function form() { - // $this->ssdb = new SsdbClient(); - // $coupon = $this->ssdb->client()->hgetall('coupon_rebate_activity'); - // if(empty($coupon)){ - // $coupon = [ - // 'activity'=> 0, - // 'forward'=> '', - // 'repay' => '' - // ]; - // } + $this->ssdb = new SsdbClient(); + $category = $this->ssdb->client()->hgetall('applet_index_category'); + $select = array_keys($category); + + // 只查一级 + $parentList = CategoryModel::where('parent_id',0)->pluck('title','id')->toArray(); - $this->text('id')->required(); - $this->image('cover_img')->required(); - $this->text('title')->required(); + $this->multipleSelect('category_ids','选择分类')->required()->options($parentList)->value($select)->default($select); } /** @@ -64,11 +63,7 @@ class CategoryTieForm extends Form */ public function default() { - return [ - 'activity' => '2', - 'forward' => '', - 'repay' => '', - ]; + return []; } } diff --git a/app/Admin/routes.php b/app/Admin/routes.php index 8e1c9ce..65a6675 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -12,8 +12,8 @@ Route::group([ 'middleware' => config('admin.route.middleware'), ], function (Router $router) { - //$router->get('/', 'HomeController@index'); - $router->resource('/', 'LanzuCsInfoController'); + $router->get('/', 'HomeController@index'); + //$router->resource('/', 'LanzuCsInfoController'); $router->resource('/speaker', 'LanzuServiceSpeakerController'); $router->resource('/mp', 'LanzuMpInfoController'); $router->any('/mp_data', 'LanzuMpInfoController@showData'); @@ -46,7 +46,7 @@ Route::group([ // 分类 $router->resource('/category', 'v3\CategoryController'); - $router->get('/category/tie', 'v3\CategoryController@CategoryTieForm'); + $router->get('/categoryTie', 'v3\CategoryController@CategoryTieForms'); // 店铺 $router->resource('/store', 'v3\StoreController'); @@ -54,5 +54,6 @@ Route::group([ $router->resource('/goods', 'v3\GoodsController'); // banner $router->resource('/banner', 'v3\BannerController'); + $router->any('/test', 'Test@test'); }); diff --git a/app/Models/v3/Category.php b/app/Models/v3/Category.php index 5f4a950..90fe607 100644 --- a/app/Models/v3/Category.php +++ b/app/Models/v3/Category.php @@ -67,7 +67,7 @@ class Category extends Model return $array; } - + /** * 处理旧图片 * @param $value @@ -81,4 +81,5 @@ class Category extends Model return $value; } } + } diff --git a/resources/lang/zh-CN/category-tie.php b/resources/lang/zh-CN/category-tie.php new file mode 100644 index 0000000..46424de --- /dev/null +++ b/resources/lang/zh-CN/category-tie.php @@ -0,0 +1,13 @@ + [ + 'CategoryTie' => '绑定', + 'categoryTie' => '绑定', + ], + 'fields' => [ + 'category_ids' => '选择分类', + ], + 'options' => [ + 'actions' => '操作' + ], +];