From c5ff8db836651fc82873856d40d8b02693e2d173 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Wed, 9 Sep 2020 17:06:37 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=BF=E4=B8=8A=E5=95=86=E5=93=81=E6=B8=85?= =?UTF-8?q?=E6=B4=97=E5=8A=9F=E8=83=BD=E5=92=8C=E8=BF=81=E7=A7=BB=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Actions/Grid/GoodsCopy.php | 3 - app/Admin/Actions/Grid/GoodsNewCopy.php | 36 ++++++ .../Controllers/v3/GoodsNewController.php | 11 +- app/Admin/Forms/GoodsNewCopyForm.php | 105 ++++++++++++++++ app/Console/Commands/MigrateGoods.php | 112 ++++++++++-------- app/Console/Commands/MigrateShoppingCart.php | 93 +++++++++++++++ app/Console/Commands/MigrateStore.php | 21 +++- .../Commands/MigrateStoreWithdrawal.php | 98 +++++++++++++++ app/Console/Commands/MigrateUser.php | 98 +++++++++++++++ .../Commands/MigrateUserCollection.php | 90 ++++++++++++++ app/Models/v3/GoodsNew.php | 8 +- resources/lang/zh-CN/goods-new.php | 4 +- 12 files changed, 609 insertions(+), 70 deletions(-) create mode 100644 app/Admin/Actions/Grid/GoodsNewCopy.php create mode 100644 app/Admin/Forms/GoodsNewCopyForm.php create mode 100644 app/Console/Commands/MigrateShoppingCart.php create mode 100644 app/Console/Commands/MigrateStoreWithdrawal.php create mode 100644 app/Console/Commands/MigrateUser.php create mode 100644 app/Console/Commands/MigrateUserCollection.php diff --git a/app/Admin/Actions/Grid/GoodsCopy.php b/app/Admin/Actions/Grid/GoodsCopy.php index e144d7b..00be8b5 100644 --- a/app/Admin/Actions/Grid/GoodsCopy.php +++ b/app/Admin/Actions/Grid/GoodsCopy.php @@ -4,9 +4,6 @@ namespace App\Admin\Actions\Grid; use Dcat\Admin\Grid\RowAction; use Dcat\Admin\Widgets\Modal; -use App\Models\v3\Store as StoreModel; -use Dcat\Admin\Form; -use App\Models\v3\Goods as GoodsModel; use App\Admin\Forms\GoodsCopyForm; class GoodsCopy extends RowAction diff --git a/app/Admin/Actions/Grid/GoodsNewCopy.php b/app/Admin/Actions/Grid/GoodsNewCopy.php new file mode 100644 index 0000000..58ef25e --- /dev/null +++ b/app/Admin/Actions/Grid/GoodsNewCopy.php @@ -0,0 +1,36 @@ +getKey(); + + $modal = Modal::make() + ->xl() + ->title($this->title) + ->body(GoodsNewCopyForm::make()->setKey($id)) + ->button($this->title); + + return $modal; + } + + public function parameters() + { + + return [ + + ]; + } +} diff --git a/app/Admin/Controllers/v3/GoodsNewController.php b/app/Admin/Controllers/v3/GoodsNewController.php index 5b4b975..5de9282 100644 --- a/app/Admin/Controllers/v3/GoodsNewController.php +++ b/app/Admin/Controllers/v3/GoodsNewController.php @@ -2,7 +2,7 @@ namespace App\Admin\Controllers\v3; -use App\Admin\Actions\Grid\GoodsCopy; +use App\Admin\Actions\Grid\GoodsNewCopy; use App\Admin\Repositories\v3\GoodsNew; use Dcat\Admin\Form; use Dcat\Admin\Grid; @@ -13,7 +13,6 @@ use App\Models\v3\StoreNew as StoreModel; use Dcat\Admin\Form\NestedForm; use App\Models\v3\GoodsNew as GoodsModel; use App\Models\v3\Market as MarketModel; -use Dcat\Admin\Grid\Displayers\Actions; use App\Models\v3\GoodsCategory as GoodsCategoryModel; class GoodsNewController extends AdminController @@ -51,7 +50,7 @@ class GoodsNewController extends AdminController $grid->sort->sortable(); $grid->on_sale->switch(); - $grid->actions([new GoodsCopy()]); + $grid->actions([new GoodsNewCopy()]); $grid->filter(function (Grid\Filter $filter) { $filter->like('name'); }); @@ -144,7 +143,7 @@ class GoodsNewController extends AdminController */ protected function form() { - $builder = GoodsModel::with(['ImageBanners','VideoBanners']); + $builder = GoodsModel::with(['ImageNewBanners','VideoNewBanners']); return Form::make($builder, function (Form $form) { $form->hidden('id'); @@ -178,13 +177,13 @@ class GoodsNewController extends AdminController $form->number('start_num')->attribute('min', 1)->default(1); }); $form->column(12, function (Form $form) { - $form->hasMany('image_banners', function (Form\NestedForm $form) { + $form->hasMany('image_new_banners', function (Form\NestedForm $form) { $form->image('path')->width(2); $form->number('sort')->width(2)->default(0); $form->hidden('type')->value(1)->default(1); })->required(); $form->divider(); - $form->hasMany('video_banners', function (Form\NestedForm $form) { + $form->hasMany('video_new_banners', function (Form\NestedForm $form) { $form->file('path')->width(2); $form->number('sort')->width(2)->default(0); $form->hidden('type')->value(2)->default(2); diff --git a/app/Admin/Forms/GoodsNewCopyForm.php b/app/Admin/Forms/GoodsNewCopyForm.php new file mode 100644 index 0000000..52e1abb --- /dev/null +++ b/app/Admin/Forms/GoodsNewCopyForm.php @@ -0,0 +1,105 @@ +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); + } + }; + } + + return $this->success('修改成功', '/goods'); + } + + /** + * Build a form here. + */ + public function form() + { + $id = $this->getKey(); + $goods = GoodsModel::select('name')->find($id); + $this->hidden('goods_id')->value($id); + $this->display('name')->value($goods->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/Console/Commands/MigrateGoods.php b/app/Console/Commands/MigrateGoods.php index 6795bb2..146d08d 100644 --- a/app/Console/Commands/MigrateGoods.php +++ b/app/Console/Commands/MigrateGoods.php @@ -4,6 +4,7 @@ namespace App\Console\Commands; use Illuminate\Console\Command; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Schema; class MigrateGoods extends Command { @@ -38,41 +39,52 @@ class MigrateGoods extends Command */ public function handle() { - // 如果表不存在则创建 - // if(!Schema::hasTable('lanzu_store_users')){ - // Schema::create('lanzu_store_users',function (Blueprint $table){ - // $table->id(); - // }); - // } - $specData = [ - '克' => '净含量', - '斤' => '净含量', - '两' => '净含量', - '只' => '净含量', - '份' => '净含量', - 'g' => '净含量', - 'l' => '净含量', - 'ml' => '净含量', - 'ML' => '净含量', - 'L' => '净含量', - '个' => '净含量', - '条' => '净含量', - '公分' => '净含量', - '边' => '净含量', - '包' => '净含量', - '辣' => '口味', - '馅' => '馅料', - 'mm' => '尺寸' - ]; - $oldData = DB::table('ims_cjdc_goods_new')->get(); + $oldTableName = 'ims_cjdc_goods_new'; + $oldSpecTableName = 'ims_cjdc_spec_combination_new'; + $oldStoreTableName = 'ims_cjdc_store_new'; + + $newTableName = 'lanzu_goods_new'; + $newBannerTableName = 'lanzu_goods_banners_new'; + + // 判断表是否存在 + if(!Schema::hasTable($oldTableName)){ + var_dump('旧商品表不存在'); + return 0; + } + if(!Schema::hasTable($oldSpecTableName)){ + var_dump('旧规格表不存在'); + return 0; + } + if(!Schema::hasTable($oldStoreTableName)){ + var_dump('旧的店铺表不存在'); + return 0; + } + if(!Schema::hasTable($newTableName)){ + var_dump('新商品表不存在'); + return 0; + } + if(!Schema::hasTable($newBannerTableName)){ + var_dump('新商品的banners表不存在'); + return 0; + } + + $oldData = DB::table($oldTableName)->orderBy('id','asc')->get(); + $oldStoreData = DB::table($oldStoreTableName)->pluck('market_id','id'); $bar = $this->output->createProgressBar(count($oldData)); $bar->start(); $startTime = time(); $total = 0; + $error = []; foreach ($oldData as $value){ + $goodsId = $value->id; + // 判断店铺是否存在,如果商品的店铺不在,则不存这个商品 + $storeExist = DB::table($oldStoreTableName)->where('id',$value->store_id)->exists(); + if(!$storeExist){ + continue; + } $goodsData =[ // 'id'=>$value->id, - 'market_id'=>$value->market_id, + 'market_id' => $oldStoreData[$value->store_id], 'store_id'=>$value->store_id, 'on_sale'=> $value->is_show == 1 ? 1 : 0, 'sort'=>$value->num, @@ -88,13 +100,11 @@ class MigrateGoods extends Command 'cover_img'=>$value->logo, 'goods_unit'=>$value->good_unit, - 'spec'=>$value->spec, - - 'content'=>$value->content, - 'details'=>$value->details, + 'content'=> strip_tags($value->content), + 'details'=> strip_tags($value->details), ]; - $specs = DB::table('ims_cjdc_spec_combination_new')->where('good_id',$value->id)->get(); - if(!empty($specs)){ + $specs = DB::table($oldSpecTableName)->where('good_id',$goodsId)->get(); + if(count($specs) > 0){ foreach($specs as $vs){ $spec = ['spec_key'=>'净含量','spec_value'=>$vs->combination]; if(strstr($vs->combination,'辣')){ @@ -104,7 +114,9 @@ class MigrateGoods extends Command }else if(strstr($vs->combination,'mm')){ $spec['spec_key'] = '尺寸'; } - $goodsData['spec'] = json_encode($spec); + + $goodsData['spec'] = json_encode([$spec]); + $newData = $goodsData; $newBanner = [ 'type' =>1, @@ -112,32 +124,34 @@ class MigrateGoods extends Command 'created_at' =>time(), 'updated_at' =>time(), ]; - $id = DB::table('lanzu_goods_new')->insertGetId($newData); - $newBanner['goods_id'] = $id; - DB::table('lanzu_goods_banners_new')->insertGetId($newBanner); - $total++; - if($total == 2){ + $id = DB::table($newTableName)->insertGetId($newData); + + if(!$id){ + $error[] = ['id'=>$goodsId]; break; } + $newBanner['goods_id'] = $id; + DB::table($newBannerTableName)->insertGetId($newBanner); + $total++; } }else{ $newData = $goodsData; - $id = DB::table('lanzu_goods_new')->insertGetId($newData); - $newBanner['goods_id'] = $id; - DB::table('lanzu_goods_banners_new')->insertGetId($newBanner); - $total++; - if($total == 2){ + $res= $id = DB::table($newTableName)->insertGetId($newData); + if(!$res){ + $error[] = ['id'=>$goodsId]; break; } + $newBanner['goods_id'] = $id; + DB::table($newBannerTableName)->insertGetId($newBanner); + $total++; } - $bar->advance(); } $bar->finish(); - echo '\r\n '; - echo time()-$startTime; - echo '\r\n '.$total; + var_dump([time()-$startTime]); + var_dump($total); + var_dump($error); return 0; } } diff --git a/app/Console/Commands/MigrateShoppingCart.php b/app/Console/Commands/MigrateShoppingCart.php new file mode 100644 index 0000000..7e7db70 --- /dev/null +++ b/app/Console/Commands/MigrateShoppingCart.php @@ -0,0 +1,93 @@ +orderBy('id','asc')->get(); + $oldStoreData = DB::table($oldStoreTableName)->pluck('market_id','id'); + $bar = $this->output->createProgressBar(count($oldData)); + $bar->start(); + $startTime = time(); + $error = []; + foreach ($oldData as $key => $value){ + $cartId = $value->id; + // 判断在新表是否存在 + $exist = DB::table($newTableName)->where('id',$cartId)->exists(); + if($exist){ + continue; + } + $newData =[ + 'id'=>$cartId, + 'market_id'=> isset($oldStoreData[$value->store_id])?$oldStoreData[$value->store_id]:0, + 'store_id'=>$value->store_id, + 'goods_id'=>$value->good_id, + 'user_id'=>$value->user_id, + + 'num'=>$value->num, + 'activity_type'=>1, + 'created_at' => time(), + 'updated_at' => time(), + ]; + + $res = DB::table($newTableName)->insert($newData); + if(!$res){ + $error[] = ['id'=>$cartId]; + break; + } + $bar->advance(); + } + $bar->finish(); + var_dump([time()-$startTime]); + var_dump($error); + return 0; + } +} diff --git a/app/Console/Commands/MigrateStore.php b/app/Console/Commands/MigrateStore.php index b885032..33dd897 100644 --- a/app/Console/Commands/MigrateStore.php +++ b/app/Console/Commands/MigrateStore.php @@ -4,6 +4,7 @@ namespace App\Console\Commands; use Illuminate\Console\Command; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Schema; class MigrateStore extends Command { @@ -38,14 +39,19 @@ class MigrateStore extends Command */ public function handle() { - // 如果表不存在则创建 - // if(!Schema::hasTable('lanzu_store_users')){ - // Schema::create('lanzu_store_users',function (Blueprint $table){ - // $table->id(); - // }); - // } $oldTableName = 'ims_cjdc_store_new'; $newTableName = 'lanzu_store_new'; + $storeImgPath = 'QR_code/code_store_img/wx_store_';/* 商户小程序码 */ + $storePayPath = 'QR_code/code_pay_img/wx_pay_';/* 收银二维码 */ + // 判断表是否存在 + if(!Schema::hasTable($oldTableName)){ + var_dump('旧表不存在'); + return 0; + } + if(!Schema::hasTable($newTableName)){ + var_dump('新表不存在'); + return 0; + } $oldData = DB::table($oldTableName)->orderBy('id','desc')->get(); $bar = $this->output->createProgressBar(count($oldData)); @@ -100,6 +106,9 @@ class MigrateStore extends Command 'introduction'=> strip_tags($value->details), + 'store_applet_img' => $storeImgPath.$storeId.'.jpg', + 'cash_code_img' => $storePayPath.$storeId.'.jpg', + 'created_at' => time(), 'updated_at' => time(), ]; diff --git a/app/Console/Commands/MigrateStoreWithdrawal.php b/app/Console/Commands/MigrateStoreWithdrawal.php new file mode 100644 index 0000000..57bf9d1 --- /dev/null +++ b/app/Console/Commands/MigrateStoreWithdrawal.php @@ -0,0 +1,98 @@ + 1,3 => 3, 1 => 4]; + $oldData = DB::table($oldTableName)->orderBy('id','asc')->get(); + $bar = $this->output->createProgressBar(count($oldData)); + $bar->start(); + $startTime = time(); + $error = []; + foreach ($oldData as $key => $value){ + $withdrawalId = $value->id; + // 判断记录在新表是否存在 + $exist = DB::table($newTableName)->where('id',$withdrawalId)->exists(); + if($exist){ + continue; + } + $newData =[ + 'id'=>$withdrawalId, + 'store_id'=>$value->store_id, + + 'name'=>$value->name, + 'tel'=>$value->tel, + 'type'=> isset($typeData[$value->type])?$typeData[$value->type]:0, + 'check_time'=>strtotime($value->sh_time), + 'state'=>$value->state, + + 'apply_cash'=>$value->tx_cost, + 'real_cash'=>$value->sj_cost, + 'bank_card'=>$value->yhk_num, + 'bank_info'=>$value->yh_info, + + 'created_at' => strtotime($value->time), + 'updated_at' => strtotime($value->sh_time), + ]; + + $res = DB::table($newTableName)->insert($newData); + if(!$res){ + $error[] = ['id'=>$withdrawalId]; + break; + } + $bar->advance(); + } + $bar->finish(); + var_dump([time()-$startTime]); + var_dump($error); + return 0; + } +} diff --git a/app/Console/Commands/MigrateUser.php b/app/Console/Commands/MigrateUser.php new file mode 100644 index 0000000..f39aaf2 --- /dev/null +++ b/app/Console/Commands/MigrateUser.php @@ -0,0 +1,98 @@ + 1,3 => 3, 1 => 4]; + $oldData = DB::table($oldTableName)->orderBy('id','asc')->get(); + $bar = $this->output->createProgressBar(count($oldData)); + $bar->start(); + $startTime = time(); + $error = []; + foreach ($oldData as $key => $value){ + $userId = $value->id; + // 判断记录在新表是否存在 + $exist = DB::table($newTableName)->where('id',$userId)->exists(); + if($exist){ + continue; + } + $newData =[ + 'id'=>$userId, + 'nick_name'=>$value->name, + + 'avatar'=>$value->img, + 'openid'=>$value->openid, + // 'type'=> isset($typeData[$value->type])?$typeData[$value->type]:0, + 'total_score'=>$value->total_score, + 'wallet'=>$value->wallet, + + 'real_name'=>$value->real_name, + 'tel'=>$value->tel, + 'unionid'=>$value->unionid, + 'status'=>$value->status, + + 'created_at' => strtotime($value->join_time), + 'updated_at' => strtotime($value->sh_time), + ]; + + $res = DB::table($newTableName)->insert($newData); + if(!$res){ + $error[] = ['id'=>$userId]; + break; + } + $bar->advance(); + } + $bar->finish(); + var_dump([time()-$startTime]); + var_dump($error); + return 0; + } +} diff --git a/app/Console/Commands/MigrateUserCollection.php b/app/Console/Commands/MigrateUserCollection.php new file mode 100644 index 0000000..1e65173 --- /dev/null +++ b/app/Console/Commands/MigrateUserCollection.php @@ -0,0 +1,90 @@ +orderBy('id','asc')->get(); + $oldStoreData = DB::table($oldStoreTableName)->pluck('market_id','id'); + $bar = $this->output->createProgressBar(count($oldData)); + $bar->start(); + $startTime = time(); + $error = []; + foreach ($oldData as $key => $value){ + $collectionId = $value->id; + // 判断记录在新表是否存在 + $exist = DB::table($newTableName)->where('id',$collectionId)->exists(); + if($exist){ + continue; + } + $newData =[ + 'id'=>$collectionId, + 'store_id'=>$value->store_id, + 'user_id'=>$value->user_id, + 'market_id'=> isset($oldStoreData[$value->store_id])?$oldStoreData[$value->store_id]:0, + + 'created_at' => time(), + 'updated_at' => time(), + ]; + + $res = DB::table($newTableName)->insert($newData); + if(!$res){ + $error[] = ['id'=>$collectionId]; + break; + } + $bar->advance(); + } + $bar->finish(); + var_dump([time()-$startTime]); + var_dump($error); + return 0; + } +} diff --git a/app/Models/v3/GoodsNew.php b/app/Models/v3/GoodsNew.php index a7a5876..026e2b2 100644 --- a/app/Models/v3/GoodsNew.php +++ b/app/Models/v3/GoodsNew.php @@ -45,12 +45,12 @@ class GoodsNew extends Model $value = $value ? $value : $this->is_infinite; return isset(self::$_isInfinite[$value]) ? self::$_isInfinite[$value] : ''; } - public function ImageBanners(){ - return $this->hasMany('\App\Models\v3\GoodsBanners','goods_id','id')->where('type',1); + public function ImageNewBanners(){ + return $this->hasMany('\App\Models\v3\GoodsNewBanners','goods_id','id')->where('type',1); } - public function VideoBanners(){ - return $this->hasMany('\App\Models\v3\GoodsBanners','goods_id','id')->where('type',2); + public function VideoNewBanners(){ + return $this->hasMany('\App\Models\v3\GoodsNewBanners','goods_id','id')->where('type',2); } diff --git a/resources/lang/zh-CN/goods-new.php b/resources/lang/zh-CN/goods-new.php index c67f24e..63251c9 100644 --- a/resources/lang/zh-CN/goods-new.php +++ b/resources/lang/zh-CN/goods-new.php @@ -34,8 +34,8 @@ return [ 'spec_key' =>'规格名称', 'spec_value' => '规格参数', 'market_id' => '市场', - 'image_banners' => '轮播图片', - 'video_banners' => '轮播视频' + 'image_new_banners' => '轮播图片', + 'video_new_banners' => '轮播视频' ], 'options' => [ ],