Browse Source

绑定分类到首页

master
liangyuyan 6 years ago
parent
commit
0cfc673a21
  1. 75
      app/Admin/Actions/Tree/CategoryTie.php
  2. 23
      app/Admin/Controllers/v3/CategoryController.php
  3. 10
      app/Admin/Controllers/v3/StoreController.php
  4. 74
      app/Admin/Forms/CategoryTieForm.php
  5. 2
      app/Admin/routes.php

75
app/Admin/Actions/Tree/CategoryTie.php

@ -0,0 +1,75 @@
<?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('Processed successfully.')
->redirect('/category');
}
/**
* @return string|void
*/
public function href()
{
// return admin_url('category/tie');
}
/**
* @return string|array|void
*/
public function confirm()
{
// return ['Confirm?', 'contents'];
}
/**
* 添加JS
*
* @return string
*/
protected function script()
{
return <<<JS
$('.category-tie-row').on('click', function () {
// Your code.
window.location.href ='/admin/category/tie';
});
JS;
}
/**
* @param Model|Authenticatable|HasPermissions|null $user
*
* @return bool
*/
protected function authorize($user): bool
{
return true;
}
}

23
app/Admin/Controllers/v3/CategoryController.php

@ -2,6 +2,7 @@
namespace App\Admin\Controllers\v3;
use App\Admin\Actions\Tree\CategoryTie;
use App\Models\v3\Category;
use Dcat\Admin\Form;
use Dcat\Admin\Layout\Row;
@ -9,6 +10,8 @@ use Dcat\Admin\Layout\Content;
use Dcat\Admin\Tree;
use Dcat\Admin\Controllers\AdminController;
use Dcat\Admin\Show;
use Dcat\Admin\Widgets\Card;
use App\Admin\Forms\CategoryTieForm;
class CategoryController extends AdminController
{
@ -19,13 +22,19 @@ class CategoryController extends AdminController
$tree = new Tree(new Category);
$tree->branch(function ($branch) {
// 查询分类ssdb
$src = $branch['cover_img_url'];
$logo = "<img src='$src' style='margin-left: 20px; max-width:35px;max-height:35px' class='img'/>";
$actions = '<a href="/admin/category/TieForm/'.$branch['id'].'" style="margin-left: 20px;">绑定</a>';
$actions = '';
$actions = ($branch['parent_id'] == 0) ?'<a href="/admin/category/'.$branch['id'].'/tie" style="margin-left: 20px;">已绑定</a>':$actions;
return "{$branch['id']} - {$branch['title']} $logo $actions";
});
$tree->tools(function (Tree\Tools $tools) {
$tools->add(new CategoryTie());
});
$row->column(12, $tree);
});
@ -51,7 +60,15 @@ class CategoryController extends AdminController
});
}
public function CategoryTieForm(Content $content)
{
return $content
->title('绑定分类到首页')
->body(new Card(new CategoryTieForm()), function (Form $form) {
});
}
/**
* Make a show builder.
*

10
app/Admin/Controllers/v3/StoreController.php

@ -166,6 +166,11 @@ class StoreController extends AdminController
$form->saved(function (Form $form){
$id = $form->getKey();
$store = StoreModel::find($id);
// 添加商户钱包
if($form->isCreating()){
}
// $form->isCreating() &&
if(!empty($id)){
$qrCode = new StoreQRCode();
@ -176,14 +181,13 @@ class StoreController extends AdminController
$pRes = $qrCode->SetPayWeChatCode($id);
// 保存图片
$store = StoreModel::find($id);
$store->store_applet_img = $sRes['status'] ? $sRes['path'] : '';
$store->cash_code_img = $pRes['status'] ? $pRes['path'] : '';;
$store->cash_code_img = $pRes['status'] ? $pRes['path'] : '';
$store->save();
// 剪裁图片
// $form->image('cash_code_img')->crop(270, 270, [5, 5]);
}
});
$form->disableResetButton();

74
app/Admin/Forms/CategoryTieForm.php

@ -0,0 +1,74 @@
<?php
namespace App\Admin\Forms;
use Dcat\Admin\Widgets\Form;
use Symfony\Component\HttpFoundation\Response;
use App\Libs\SsdbClient;
class CategoryTieForm extends Form
{
/**
*
*/
protected $ssdb;
/**
* Handle the form request.
*
* @param array $input
*
* @return Response
*/
public function handle(array $input)
{
$data = [
'activity' => $input['activity'],
'forward' => $input['forward'],
'repay' => $input['repay'],
];
$coupon = $this->ssdb->client()->multi_hset('coupon_rebate_activity',$data);
if($coupon === false){
return $this->error('修改失败');
}
return $this->success('修改成功', '/couponTie');
}
/**
* Build a form here.
*/
public function form()
{
// $this->ssdb = new SsdbClient();
// $coupon = $this->ssdb->client()->hgetall('coupon_rebate_activity');
// if(empty($coupon)){
// $coupon = [
// 'activity'=> 0,
// 'forward'=> '',
// 'repay' => ''
// ];
// }
$this->text('id')->required();
$this->image('cover_img')->required();
$this->text('title')->required();
}
/**
* The data of the form.
*
* @return array
*/
public function default()
{
return [
'activity' => '2',
'forward' => '',
'repay' => '',
];
}
}

2
app/Admin/routes.php

@ -46,7 +46,7 @@ Route::group([
// 分类
$router->resource('/category', 'v3\CategoryController');
$router->get('/category/TieForm', 'v3\CategoryTieController@CategoryTieForm');
$router->get('/category/tie', 'v3\CategoryController@CategoryTieForm');
// 店铺
$router->resource('/store', 'v3\StoreController');

Loading…
Cancel
Save