Browse Source
Merge branch 'develop' of http://120.24.33.109:11081/hyzjshwo/mp_lanzu_cat into develop
master
Merge branch 'develop' of http://120.24.33.109:11081/hyzjshwo/mp_lanzu_cat into develop
master
8 changed files with 203 additions and 46 deletions
-
76app/Admin/Actions/Tree/CategoryTie.php
-
29app/Admin/Controllers/v3/CategoryController.php
-
23app/Admin/Controllers/v3/StoreController.php
-
34app/Admin/Extensions/TypeCorrelationBind.php
-
69app/Admin/Forms/CategoryTieForm.php
-
2app/Admin/routes.php
-
3app/Models/v3/Category.php
-
13resources/lang/zh-CN/category-tie.php
@ -0,0 +1,76 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Actions\Tree; |
|||
|
|||
use Dcat\Admin\Actions\Response; |
|||
use Dcat\Admin\Form; |
|||
use Dcat\Admin\Traits\HasPermissions; |
|||
use Dcat\Admin\Tree\AbstractTool; |
|||
use Illuminate\Contracts\Auth\Authenticatable; |
|||
use Illuminate\Database\Eloquent\Model; |
|||
use Illuminate\Http\Request; |
|||
use App\Models\v3\Category as CategoryModel; |
|||
|
|||
class CategoryTie extends AbstractTool |
|||
{ |
|||
|
|||
/** |
|||
* @return string |
|||
*/ |
|||
protected $title = '绑定分类到首页导航'; |
|||
|
|||
/** |
|||
* Handle the action request. |
|||
* |
|||
* @param Request $request |
|||
* |
|||
* @return Response |
|||
*/ |
|||
public function handle(Request $request) |
|||
{ |
|||
return $this->response() |
|||
->success('跳转到绑定页面' ) |
|||
->redirect('/categoryTie'); |
|||
} |
|||
|
|||
/** |
|||
* @return string|void |
|||
*/ |
|||
// public function href()
|
|||
// {
|
|||
// return admin_url('category/tie');
|
|||
// }
|
|||
|
|||
/** |
|||
* @return string|array|void |
|||
*/ |
|||
public function confirm() |
|||
{ |
|||
// return ['Confirm?', 'contents'];
|
|||
} |
|||
|
|||
// protected function actionScript()
|
|||
// {
|
|||
|
|||
// return <<<JS
|
|||
// function (data, target, action) {
|
|||
// console.log('发起请求之前', data, target, action);
|
|||
|
|||
// // return false; 在这里return false可以终止执行后面的操作
|
|||
|
|||
// // 更改传递到接口的主键值
|
|||
// action.options.key = 123;
|
|||
// }
|
|||
// JS;
|
|||
// }
|
|||
|
|||
/** |
|||
* @param Model|Authenticatable|HasPermissions|null $user |
|||
* |
|||
* @return bool |
|||
*/ |
|||
protected function authorize($user): bool |
|||
{ |
|||
return true; |
|||
} |
|||
} |
|||
@ -1,34 +0,0 @@ |
|||
<?php |
|||
namespace App\Admin\Extensions; |
|||
|
|||
use Dcat\Admin\Grid\RowAction; |
|||
|
|||
class TypeCorrelationBind extends RowAction |
|||
{ |
|||
public function title() |
|||
{ |
|||
return '绑定'; |
|||
} |
|||
|
|||
/** |
|||
* 添加JS |
|||
* |
|||
* @return string |
|||
*/ |
|||
protected function script() |
|||
{ |
|||
return <<<JS |
|||
$('.type-bind-row').on('click', function () { |
|||
// Your code.
|
|||
window.location.href ='/admin/coupon/TieForm'; |
|||
}); |
|||
JS; |
|||
} |
|||
|
|||
public function html() |
|||
{ |
|||
$this->setHtmlAttribute(['class' => 'coupon-edit-row']); |
|||
return parent::html(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,69 @@ |
|||
<?php |
|||
|
|||
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; |
|||
|
|||
/** |
|||
* Handle the form request. |
|||
* |
|||
* @param array $input |
|||
* |
|||
* @return Response |
|||
*/ |
|||
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 |
|||
]); |
|||
} |
|||
} |
|||
|
|||
$category = $this->ssdb->client()->multi_hset('applet_index_category',$data); |
|||
if($category === false){ |
|||
return $this->error('修改失败'); |
|||
} |
|||
|
|||
return $this->success('修改成功', '/category'); |
|||
} |
|||
|
|||
/** |
|||
* Build a form here. |
|||
*/ |
|||
public function form() |
|||
{ |
|||
$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->multipleSelect('category_ids','选择分类')->required()->options($parentList)->value($select)->default($select); |
|||
} |
|||
|
|||
/** |
|||
* The data of the form. |
|||
* |
|||
* @return array |
|||
*/ |
|||
public function default() |
|||
{ |
|||
return []; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
<?php |
|||
return [ |
|||
'labels' => [ |
|||
'CategoryTie' => '绑定', |
|||
'categoryTie' => '绑定', |
|||
], |
|||
'fields' => [ |
|||
'category_ids' => '选择分类', |
|||
], |
|||
'options' => [ |
|||
'actions' => '操作' |
|||
], |
|||
]; |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue