From 0cfc673a2195e8a7b69f550f84e16222147e5075 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Fri, 4 Sep 2020 12:08:50 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E7=BB=91=E5=AE=9A=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E5=88=B0=E9=A6=96=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Actions/Tree/CategoryTie.php | 75 +++++++++++++++++++ .../Controllers/v3/CategoryController.php | 23 +++++- app/Admin/Controllers/v3/StoreController.php | 10 ++- app/Admin/Forms/CategoryTieForm.php | 74 ++++++++++++++++++ app/Admin/routes.php | 2 +- 5 files changed, 177 insertions(+), 7 deletions(-) create mode 100644 app/Admin/Actions/Tree/CategoryTie.php create mode 100644 app/Admin/Forms/CategoryTieForm.php diff --git a/app/Admin/Actions/Tree/CategoryTie.php b/app/Admin/Actions/Tree/CategoryTie.php new file mode 100644 index 0000000..2a07335 --- /dev/null +++ b/app/Admin/Actions/Tree/CategoryTie.php @@ -0,0 +1,75 @@ +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 <<branch(function ($branch) { + // 查询分类ssdb + $src = $branch['cover_img_url']; $logo = ""; - $actions = '绑定'; - + $actions = ''; + $actions = ($branch['parent_id'] == 0) ?'已绑定':$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. * diff --git a/app/Admin/Controllers/v3/StoreController.php b/app/Admin/Controllers/v3/StoreController.php index ff08d63..ef66301 100644 --- a/app/Admin/Controllers/v3/StoreController.php +++ b/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(); diff --git a/app/Admin/Forms/CategoryTieForm.php b/app/Admin/Forms/CategoryTieForm.php new file mode 100644 index 0000000..5a9dc05 --- /dev/null +++ b/app/Admin/Forms/CategoryTieForm.php @@ -0,0 +1,74 @@ + $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' => '', + ]; + } + +} diff --git a/app/Admin/routes.php b/app/Admin/routes.php index 2f4919f..8e1c9ce 100644 --- a/app/Admin/routes.php +++ b/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'); From 718039f8877583e0b62f91442bae7ee4695e8387 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Fri, 4 Sep 2020 12:22:32 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=BA=97=E9=93=BA=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E6=97=B6=E5=A6=82=E6=9E=9C=E9=92=B1=E5=8C=85Balance=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E8=AE=B0=E5=BD=95=E5=88=99=E6=B7=BB=E5=8A=A0=E4=B8=80?= =?UTF-8?q?=E6=9D=A1=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Controllers/v3/StoreController.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/Admin/Controllers/v3/StoreController.php b/app/Admin/Controllers/v3/StoreController.php index ef66301..7faea5a 100644 --- a/app/Admin/Controllers/v3/StoreController.php +++ b/app/Admin/Controllers/v3/StoreController.php @@ -13,6 +13,7 @@ use App\Admin\Common\StoreQRCode; use App\Models\v3\Store as StoreModel; use App\Models\v3\User as UserModel; use App\Models\v3\Category as CategoryModel; +use App\Models\LanzuUserBalance as UserBalanceModel; class StoreController extends AdminController { @@ -167,12 +168,21 @@ class StoreController extends AdminController $form->saved(function (Form $form){ $id = $form->getKey(); $store = StoreModel::find($id); - // 添加商户钱包 - if($form->isCreating()){ + // 添加商户钱包 + $userBalance = UserBalanceModel::where([ + ['user_type','=',5], + ['source_id','=',$id] + ])->first(); + + if(empty($userBalance)){ + $userBalance = new UserBalanceModel(); + $userBalance->user_type = 5; + $userBalance->source_id = $id; + $userBalance->save(); } - // $form->isCreating() && - if(!empty($id)){ + + if($form->isCreating() && !empty($id)){ $qrCode = new StoreQRCode(); // 生成小程序码 店铺 $sRes = $qrCode->SetStoreWeChatCode($id); @@ -187,7 +197,6 @@ class StoreController extends AdminController // 剪裁图片 // $form->image('cash_code_img')->crop(270, 270, [5, 5]); } - }); $form->disableResetButton(); 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 3/3] =?UTF-8?q?=E5=88=86=E7=B1=BB=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E5=88=B0=E5=B0=8F=E7=A8=8B=E5=BA=8F=E9=A6=96=E9=A1=B5=E5=AF=BC?= =?UTF-8?q?=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' => '操作' + ], +];