From 82770610c78e6eca4e95e31d234fca036c84d707 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Wed, 23 Sep 2020 14:16:02 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=95=86=E5=93=81=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E5=8F=AF=E4=B8=BA0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v3/GoodsActivityController.php | 21 +++++++++++++------ app/Admin/Controllers/v3/GoodsController.php | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/Admin/Controllers/v3/GoodsActivityController.php b/app/Admin/Controllers/v3/GoodsActivityController.php index 18dffd7..75512dc 100644 --- a/app/Admin/Controllers/v3/GoodsActivityController.php +++ b/app/Admin/Controllers/v3/GoodsActivityController.php @@ -47,7 +47,7 @@ class GoodsActivityController extends AdminController $grid->column('name')->editable(); $grid->column('price')->editable(); $grid->column('type_text'); - + $grid->column('inventory')->editable(); $grid->column('market_id')->display(function($marketId){ $item = MarketModel::getMarketInfo($marketId,'name'); return empty($item) ? '' : $item->name; @@ -60,10 +60,10 @@ class GoodsActivityController extends AdminController $item = CategoryModel::getInfo($categoryId,'title'); return empty($item) ? '' : $item->title; }); - $grid->goods_category_id->display(function ($goodsCategoryId){ - $item = GoodsCategoryModel::getInfo($goodsCategoryId,'title'); - return empty($item) ? '' : $item->title; - }); + // $grid->goods_category_id->display(function ($goodsCategoryId){ + // $item = GoodsCategoryModel::getInfo($goodsCategoryId,'title'); + // return empty($item) ? '' : $item->title; + // }); $grid->column('expire_time_text'); $grid->column('sort'); $grid->column('on_sale')->switch(); @@ -181,7 +181,7 @@ class GoodsActivityController extends AdminController $form->currency('vip_price')->required()->floatTwo()->symbol('¥'); $form->text('goods_unit')->help('如:斤,个,盒,500克,1000克,1500克等'); $form->radio('is_infinite')->options(['关闭','开启'])->default(1); - $form->number('inventory')->required()->attribute('min', 1)->default(1); + $form->number('inventory')->required()->attribute('min', 0)->default(1); $form->number('restrict_num')->attribute('min', 0)->default(1)->help('0表示不限购,单笔订单限购数量'); $form->number('start_num')->attribute('min', 1)->default(1); $form->number('time_limit_days')->help('A时间段内限购'); @@ -225,6 +225,15 @@ class GoodsActivityController extends AdminController $spec = $form->input('spec'); $detailsImgs = $form->input('details_imgs'); $goodsCategoryId = $form->input('goods_category_id'); + + $inventory = $form->input('inventory'); + // 规格 + if(!empty($inventory)){ + if(!is_numeric($inventory) || $inventory < 0){ + return $form->error('库存必须为大于等于0的数字'); + } + } + if(!empty($storeId)){ // 商品所属市场,根据店铺查询市场 $info = StoreModel::getStoreInfo($storeId,'market_id'); diff --git a/app/Admin/Controllers/v3/GoodsController.php b/app/Admin/Controllers/v3/GoodsController.php index 7dae3fd..a5a3d1e 100644 --- a/app/Admin/Controllers/v3/GoodsController.php +++ b/app/Admin/Controllers/v3/GoodsController.php @@ -219,7 +219,7 @@ class GoodsController extends AdminController $form->currency('vip_price')->required()->symbol('¥'); $form->text('goods_unit')->help('如:斤,个,盒,500克,1000克,1500克等'); $form->radio('is_infinite')->options(['关闭','开启'])->default(1); - $form->number('inventory')->required()->attribute('min', 1)->default(1); + $form->number('inventory')->required()->attribute('min', 0)->default(1); $form->number('restrict_num')->attribute('min', 0)->default(0)->help('0表示不限购'); $form->number('start_num')->attribute('min', 1)->default(1); }); From 339e11edc2ad2b89e3d5a5d0953033a221a95561 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Wed, 23 Sep 2020 17:06:30 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=E5=95=86=E5=93=81=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Forms/GoodsNewCopyForm.php | 108 -------------------- app/Admin/Forms/GoodsNewImageForm.php | 73 ------------- app/Admin/Forms/v3/GoodsActivitySetting.php | 52 ++++++++++ 3 files changed, 52 insertions(+), 181 deletions(-) delete mode 100644 app/Admin/Forms/GoodsNewCopyForm.php delete mode 100644 app/Admin/Forms/GoodsNewImageForm.php create mode 100644 app/Admin/Forms/v3/GoodsActivitySetting.php diff --git a/app/Admin/Forms/GoodsNewCopyForm.php b/app/Admin/Forms/GoodsNewCopyForm.php deleted file mode 100644 index 6fda924..0000000 --- a/app/Admin/Forms/GoodsNewCopyForm.php +++ /dev/null @@ -1,108 +0,0 @@ -get(); - $markets = StoreModel::whereIn('id',$storeIds)->pluck('market_id','id'); - foreach($storeIds as $key =>$value){ - $storeId = $value; - $model = new GoodsModel(); - - $model->store_id = $storeId; - $model->market_id = $markets[$storeId]; - $model->category_id = $goods->category_id; - - $model->name = $goods->name; - $model->cover_img = $goods->cover_img; - $model->goods_unit = $goods->goods_unit; - - $model->tags = $goods->tags; - $model->spec = $goods->spec; - $model->details_imgs = $goods->details_imgs; - $model->content = $goods->content; - $model->details = $goods->details; - - $model->price = $goods->price; - $model->original_price = $goods->original_price; - $model->vip_price = $goods->vip_price; - - $model->start_num = $goods->start_num; - $model->restrict_num = $goods->restrict_num; - $model->is_infinite = $goods->is_infinite; - $model->inventory = $goods->inventory; - - $model->on_sale = $goods->on_sale; - $model->sort = $goods->sort; - $model->remark = $goods->remark; - - if($model->save() && !empty($goodsBanners)){ - $goodsId = $model->getKey(); - $banners = []; - foreach($goodsBanners as $kb => $vb){ - $banners[] = [ - 'goods_id' => $goodsId, - 'type' => $vb->type, - 'path' => $vb->path, - 'sort' => $vb->sort, - 'created_at' => time(), - 'updated_at' => time(), - ]; - GoodsBannerModel::insert($banners); - } - }else{ - return $this->error('修改失败'); - }; - } - - return $this->error('修改成功'); - } - - /** - * Build a form here. - */ - public function form() - { - $id = $this->getKey(); - $goods = GoodsModel::select('name')->find($id); - $this->hidden('goods_id')->value($id); - $name = empty($goods->name)?'':$goods->name; - $this->display('name')->value($name); - $stores = StoreModel::getStoreArray(); - $this->multipleSelect('store_ids','选择店铺')->required()->options($stores)->help('选择店铺,将当前商品复制到所选店铺。注意选择重复店铺问题!!!'); - } - - /** - * The data of the form. - * - * @return array - */ - public function default() - { - return []; - } - -} diff --git a/app/Admin/Forms/GoodsNewImageForm.php b/app/Admin/Forms/GoodsNewImageForm.php deleted file mode 100644 index f418ff0..0000000 --- a/app/Admin/Forms/GoodsNewImageForm.php +++ /dev/null @@ -1,73 +0,0 @@ - 0 && !empty($coverImg)){ - $data = ['cover_img' => $coverImg]; - GoodsModel::where('id',$goodsId)->update($data); - } - if($goodsId > 0 && !empty($bannerImg)){ - $banner = GoodsBannerModel::where('goods_id',$goodsId)->first(); - if(empty($banner)){ - $banner = new GoodsBanners(); - $banner->goods_id = $goodsId; - $banner->type = 1; - $banner->created_at = time(); - } - $banner->path = $bannerImg; - $banner->updated_at = time(); - $banner->save(); - } - - return $this->error('修改成功'); - } - - /** - * Build a form here. - */ - public function form() - { - $id = $this->getKey(); - $goods = GoodsModel::select('name')->find($id); - $goodName = empty($goods->name)?'':$goods->name; - $this->hidden('goods_id')->value($id); - $this->display('name','商品名称')->value($goodName); - $this->image('cover_img','封面图')->url('ops/files'); - $this->image('img_banner','轮播图')->url('ops/files'); - } - - /** - * The data of the form. - * - * @return array - */ - public function default() - { - return []; - } - -} diff --git a/app/Admin/Forms/v3/GoodsActivitySetting.php b/app/Admin/Forms/v3/GoodsActivitySetting.php new file mode 100644 index 0000000..38895a7 --- /dev/null +++ b/app/Admin/Forms/v3/GoodsActivitySetting.php @@ -0,0 +1,52 @@ +error('修改成功'); + } + + /** + * Build a form here. + */ + public function form() + { + $id = $this->getKey(); + + $this->display('activity_type_limit_nums','同一活动类型商品单笔订单可购买商品种数'); + $this->number('flash_sale','秒杀')->value()->default(); + $this->image('group_buy','团购')->value()->default(); + $this->image('new_product','新品')->value()->default(); + } + + /** + * The data of the form. + * + * @return array + */ + public function default() + { + return []; + } + +} From c7d1ca343fa05c0687c2ee455a39eb399433ec15 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Wed, 23 Sep 2020 19:59:06 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E5=95=86=E5=93=81--?= =?UTF-8?q?=E8=AE=BE=E7=BD=AEredis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Actions/Grid/v3/GoodsActivitySetting.php | 74 +++++++++++++++++++ .../v3/GoodsActivityController.php | 14 ++++ app/Admin/Forms/v3/GoodsActivitySetting.php | 52 ------------- .../Forms/v3/GoodsActivitySettingForm.php | 68 +++++++++++++++++ app/Admin/routes.php | 1 + app/Libs/Redis/RedisKey.php | 12 +++ 6 files changed, 169 insertions(+), 52 deletions(-) create mode 100644 app/Admin/Actions/Grid/v3/GoodsActivitySetting.php delete mode 100644 app/Admin/Forms/v3/GoodsActivitySetting.php create mode 100644 app/Admin/Forms/v3/GoodsActivitySettingForm.php create mode 100644 app/Libs/Redis/RedisKey.php diff --git a/app/Admin/Actions/Grid/v3/GoodsActivitySetting.php b/app/Admin/Actions/Grid/v3/GoodsActivitySetting.php new file mode 100644 index 0000000..068b7af --- /dev/null +++ b/app/Admin/Actions/Grid/v3/GoodsActivitySetting.php @@ -0,0 +1,74 @@ +response() + ->success('跳转到设置页面' ) + ->redirect('/activity_setting'); + } + + /** + * @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 <<paginate(10); + + $grid->tools([new GoodsActivitySetting()]); }); } @@ -281,4 +287,12 @@ class GoodsActivityController extends AdminController }); }); } + + + public function SettingForm(Content $content) + { + return $content + ->title('活动设置') + ->body(new Card(new GoodsActivitySettingForm())); + } } diff --git a/app/Admin/Forms/v3/GoodsActivitySetting.php b/app/Admin/Forms/v3/GoodsActivitySetting.php deleted file mode 100644 index 38895a7..0000000 --- a/app/Admin/Forms/v3/GoodsActivitySetting.php +++ /dev/null @@ -1,52 +0,0 @@ -error('修改成功'); - } - - /** - * Build a form here. - */ - public function form() - { - $id = $this->getKey(); - - $this->display('activity_type_limit_nums','同一活动类型商品单笔订单可购买商品种数'); - $this->number('flash_sale','秒杀')->value()->default(); - $this->image('group_buy','团购')->value()->default(); - $this->image('new_product','新品')->value()->default(); - } - - /** - * The data of the form. - * - * @return array - */ - public function default() - { - return []; - } - -} diff --git a/app/Admin/Forms/v3/GoodsActivitySettingForm.php b/app/Admin/Forms/v3/GoodsActivitySettingForm.php new file mode 100644 index 0000000..a1d1648 --- /dev/null +++ b/app/Admin/Forms/v3/GoodsActivitySettingForm.php @@ -0,0 +1,68 @@ + $flashSale, + 'group_buy' => $groupBuy, + 'new_product' => $newProduct, + ]; + + $res = Redis::hmset(RedisKey::ACTIVITY_TYPE_LIMIT_NUMS , $data); + if($res){ + return $this->success('修改成功','/goods_activity'); + }else{ + return $this->error('修改失败'); + } + } + + /** + * Build a form here. + */ + public function form() + { + $data = Redis::hgetall('activity_type_limit_nums'); + + $flashSale = $data['flash_sale']?$data['flash_sale']:0; + $groupBuy= $data['group_buy']?$data['group_buy']:0; + $newProduct= $data['new_product']?$data['new_product']:0; + + $this->display(RedisKey::ACTIVITY_TYPE_LIMIT_NUMS , '设置')->value('同一活动类型的商品,单笔订单可购买商品种数'); + $this->number('flash_sale','秒杀')->attribute('min', 0)->default(1)->value($flashSale); + $this->number('group_buy','团购')->attribute('min', 0)->default(1)->value($groupBuy); + $this->number('new_product','新品')->attribute('min', 0)->default(1)->value($newProduct); + } + + /** + * The data of the form. + * + * @return array + */ + public function default() + { + return []; + } + +} diff --git a/app/Admin/routes.php b/app/Admin/routes.php index aa9ac7c..a729727 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -59,6 +59,7 @@ Route::group([ $router->resource('/goods', 'v3\GoodsController'); $router->resource('/goods_activity', 'v3\GoodsActivityController'); $router->resource('/goods_new', 'v3\GoodsNewController'); + $router->get('/activity_setting', 'v3\GoodsActivityController@SettingForm'); // 平台管理 $router->resource('/banners', 'v3\BannersController'); diff --git a/app/Libs/Redis/RedisKey.php b/app/Libs/Redis/RedisKey.php new file mode 100644 index 0000000..1ce5a70 --- /dev/null +++ b/app/Libs/Redis/RedisKey.php @@ -0,0 +1,12 @@ + Date: Wed, 23 Sep 2020 20:04:23 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E5=95=86=E5=93=81?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE--=E6=B7=BB=E5=8A=A0=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Forms/v3/GoodsActivitySettingForm.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Admin/Forms/v3/GoodsActivitySettingForm.php b/app/Admin/Forms/v3/GoodsActivitySettingForm.php index a1d1648..d4811df 100644 --- a/app/Admin/Forms/v3/GoodsActivitySettingForm.php +++ b/app/Admin/Forms/v3/GoodsActivitySettingForm.php @@ -45,9 +45,9 @@ class GoodsActivitySettingForm extends Form { $data = Redis::hgetall('activity_type_limit_nums'); - $flashSale = $data['flash_sale']?$data['flash_sale']:0; - $groupBuy= $data['group_buy']?$data['group_buy']:0; - $newProduct= $data['new_product']?$data['new_product']:0; + $flashSale = isset($data['flash_sale'])?$data['flash_sale']:0; + $groupBuy= isset($data['group_buy'])?$data['group_buy']:0; + $newProduct= isset($data['new_product'])?$data['new_product']:0; $this->display(RedisKey::ACTIVITY_TYPE_LIMIT_NUMS , '设置')->value('同一活动类型的商品,单笔订单可购买商品种数'); $this->number('flash_sale','秒杀')->attribute('min', 0)->default(1)->value($flashSale);