18 changed files with 1312 additions and 7 deletions
-
3app/Admin/Actions/Grid/GoodsCopy.php
-
36app/Admin/Actions/Grid/GoodsNewCopy.php
-
225app/Admin/Controllers/v3/GoodsNewController.php
-
105app/Admin/Forms/GoodsNewCopyForm.php
-
16app/Admin/Repositories/v3/GoodsNew.php
-
2app/Admin/routes.php
-
4app/Console/Commands/CouponReport.php
-
157app/Console/Commands/MigrateGoods.php
-
93app/Console/Commands/MigrateShoppingCart.php
-
143app/Console/Commands/MigrateStore.php
-
98app/Console/Commands/MigrateStoreWithdrawal.php
-
98app/Console/Commands/MigrateUser.php
-
90app/Console/Commands/MigrateUserCollection.php
-
4app/Console/Commands/SetStoreUsers.php
-
70app/Models/v3/GoodsNew.php
-
18app/Models/v3/GoodsNewBanners.php
-
115app/Models/v3/StoreNew.php
-
42resources/lang/zh-CN/goods-new.php
@ -0,0 +1,36 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Actions\Grid; |
|||
|
|||
use Dcat\Admin\Grid\RowAction; |
|||
use Dcat\Admin\Widgets\Modal; |
|||
use App\Admin\Forms\GoodsNewCopyForm; |
|||
|
|||
class GoodsNewCopy extends RowAction |
|||
{ |
|||
/** |
|||
* @return string |
|||
*/ |
|||
protected $title = '复制'; |
|||
|
|||
public function render() |
|||
{ |
|||
$id = $this->getKey(); |
|||
|
|||
$modal = Modal::make() |
|||
->xl() |
|||
->title($this->title) |
|||
->body(GoodsNewCopyForm::make()->setKey($id)) |
|||
->button($this->title); |
|||
|
|||
return $modal; |
|||
} |
|||
|
|||
public function parameters() |
|||
{ |
|||
|
|||
return [ |
|||
|
|||
]; |
|||
} |
|||
} |
|||
@ -0,0 +1,225 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Controllers\v3; |
|||
|
|||
use App\Admin\Actions\Grid\GoodsNewCopy; |
|||
use App\Admin\Repositories\v3\GoodsNew; |
|||
use Dcat\Admin\Form; |
|||
use Dcat\Admin\Grid; |
|||
use Dcat\Admin\Show; |
|||
use Dcat\Admin\Controllers\AdminController; |
|||
use App\Models\v3\Category as CategoryModel; |
|||
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 App\Models\v3\GoodsCategory as GoodsCategoryModel; |
|||
|
|||
class GoodsNewController extends AdminController |
|||
{ |
|||
/** |
|||
* Make a grid builder. |
|||
* |
|||
* @return Grid |
|||
*/ |
|||
protected function grid() |
|||
{ |
|||
return Grid::make(new GoodsNew(), function (Grid $grid) { |
|||
$grid->id->sortable(); |
|||
$grid->cover_img_url->image('',50); |
|||
$grid->name; |
|||
$grid->price; |
|||
$grid->column('market_id')->display(function($marketId){ |
|||
$item = MarketModel::getMarketInfo($marketId,'name'); |
|||
return empty($item) ? '' : $item->name; |
|||
}); |
|||
$grid->store_id->display(function ($storeId){ |
|||
$store = StoreModel::getStoreInfo($storeId,'name'); |
|||
return empty($store) ? '' : $store->name; |
|||
}); |
|||
$grid->category_id->display(function ($categoryId){ |
|||
$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->sort->sortable(); |
|||
$grid->on_sale->switch(); |
|||
|
|||
$grid->actions([new GoodsNewCopy()]); |
|||
$grid->filter(function (Grid\Filter $filter) { |
|||
$filter->like('name'); |
|||
}); |
|||
|
|||
$grid->model()->orderBy('id', 'desc'); |
|||
// 每页10条
|
|||
$grid->paginate(10); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Make a show builder. |
|||
* |
|||
* @param mixed $id |
|||
* |
|||
* @return Show |
|||
*/ |
|||
protected function detail($id) |
|||
{ |
|||
// $g = GoodsModel::find(1572);
|
|||
// dd($g->toArray());
|
|||
return Show::make($id, new GoodsNew(), function (Show $show) { |
|||
$show->row(function (Show\Row $show) { |
|||
$show->width(6)->field('id'); |
|||
$show->width(6)->field('name'); |
|||
$show->width(6)->category_id->as(function ($categoryId){ |
|||
$item = CategoryModel::getInfo($categoryId,'title'); |
|||
return empty($item) ? '' : $item->title; |
|||
}); |
|||
$show->width(6)->store_id->as(function ($storeId){ |
|||
$item = GoodsCategoryModel::getInfo($storeId,'name'); |
|||
return empty($item) ? '' : $item->name; |
|||
}); |
|||
$show->width(6)->store_id->as(function ($goodsCategoryId){ |
|||
$item = StoreModel::getStoreInfo($goodsCategoryId,'name'); |
|||
return empty($item) ? '' : $item->name; |
|||
}); |
|||
$show->width(6)->cover_img->image(); |
|||
$show->width(6)->price; |
|||
$show->width(6)->original_price; |
|||
$show->width(6)->vip_price; |
|||
$show->width(6)->inventory; |
|||
$show->width(6)->goods_unit; |
|||
|
|||
}); |
|||
$show->row(function (Show\Row $show) { |
|||
$show->width(6)->on_sale_text; |
|||
$show->width(6)->content; |
|||
$show->width(6)->sort; |
|||
$show->width(6)->restrict_num; |
|||
$show->width(6)->start_num; |
|||
$show->width(6)->is_infinite_text; |
|||
|
|||
$show->width(6)->tags->as(function ($value){ |
|||
return $value; |
|||
}); |
|||
$show->width(6)->spec->as(function ($value){ |
|||
$text = ''; |
|||
foreach ($value as $v){ |
|||
$text .= '【'.$v['spec_key'] .':'.$v['spec_value'].'】 '; |
|||
} |
|||
return $text; |
|||
}); |
|||
$goodsModel = new GoodsModel(); |
|||
$show->html(function () use($goodsModel){ |
|||
if(empty($this->details_imgs)){ |
|||
return ''; |
|||
}else{ |
|||
// 还需要优化
|
|||
$value = $this->details_imgs; |
|||
$text = ''; |
|||
foreach ($value as $v){ |
|||
$img = $goodsModel->imageUrl($v); |
|||
$text .= "<img src='$img' />"; |
|||
} |
|||
return $text; |
|||
} |
|||
}); |
|||
|
|||
// $show->created_at;
|
|||
// $show->updated_at;
|
|||
}); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Make a form builder. |
|||
* |
|||
* @return Form |
|||
*/ |
|||
protected function form() |
|||
{ |
|||
$builder = GoodsModel::with(['ImageNewBanners','VideoNewBanners']); |
|||
|
|||
return Form::make($builder, function (Form $form) { |
|||
$form->hidden('id'); |
|||
|
|||
// 二级分类
|
|||
$categoryList = CategoryModel::getArray([['parent_id','>',0]]); |
|||
// 商品类目
|
|||
$goodsCategoryList = GoodsCategoryModel::getArray(); |
|||
// 店铺
|
|||
$storeList = StoreModel::getStoreArray(); |
|||
//市场
|
|||
// $marketList = MarketModel::getMarketArray();
|
|||
|
|||
$form->column(6, function (Form $form) use($storeList,$categoryList,$goodsCategoryList ){ |
|||
// $form->select('market_id')->required()->options($marketList);
|
|||
$form->select('category_id')->required()->options($categoryList)->load('goods_category_id', '/api/goods_category_list'); |
|||
$form->select('goods_category_id')->required(); |
|||
$form->select('store_id')->required()->options($storeList); |
|||
$form->text('name')->required()->maxLength(20); |
|||
$form->image('cover_img')->required(); |
|||
$form->number('sort'); |
|||
}); |
|||
$form->column(6, function (Form $form) { |
|||
$form->currency('price')->required()->floatTwo()->symbol('¥'); |
|||
$form->currency('original_price')->required()->floatTwo()->symbol('¥'); |
|||
$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('restrict_num')->attribute('min', 0)->default(0)->help('0表示不限购'); |
|||
$form->number('start_num')->attribute('min', 1)->default(1); |
|||
}); |
|||
$form->column(12, function (Form $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_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); |
|||
}); |
|||
$form->divider(); |
|||
|
|||
$form->multipleImage('details_imgs')->help('按图片顺序上传'); |
|||
$form->text('content')->maxLength(50); |
|||
$form->text('remark')->maxLength(50); |
|||
|
|||
$form->tags('tags','标签')->options(['新品','热销','新鲜']); |
|||
$form->table('spec', function (NestedForm $table) { |
|||
$table->text('spec_key')->help('如:净含量:500克,保质期:120天,包装:12个/盒等'); |
|||
$table->text('spec_value'); |
|||
}); |
|||
$form->switch('on_sale') |
|||
->customFormat(function ($v) { |
|||
return $v == '上架' ? 1 : 0; |
|||
}) |
|||
->saving(function ($v) { |
|||
return $v; |
|||
}); |
|||
|
|||
$form->disableResetButton(); |
|||
$form->disableViewCheck(); |
|||
$form->disableEditingCheck(); |
|||
$form->disableCreatingCheck(); |
|||
}); |
|||
$form->saved(function (Form $form){ |
|||
$storeId = $form->input('store_id'); |
|||
|
|||
// 商品所属市场,根据店铺查询市场
|
|||
$info = StoreModel::getStoreInfo($storeId,'market_id'); |
|||
$form->market_id = $info->market_id; |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,105 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Forms; |
|||
|
|||
use Dcat\Admin\Widgets\Form; |
|||
use Symfony\Component\HttpFoundation\Response; |
|||
use App\Models\v3\StoreNew as StoreModel; |
|||
use App\Models\v3\GoodsNew as GoodsModel; |
|||
use App\Models\v3\GoodsNewBanners as GoodsBannerModel; |
|||
use Illuminate\Support\Facades\DB; |
|||
|
|||
class GoodsNewCopyForm extends Form |
|||
{ |
|||
|
|||
/** |
|||
* Handle the form request. |
|||
* |
|||
* @param array $input |
|||
* |
|||
* @return Response |
|||
*/ |
|||
public function handle(array $input) |
|||
{ |
|||
// 获取外部传递参数
|
|||
$goodsId = $input['goods_id']; |
|||
$storeIds= $input['store_ids']; |
|||
|
|||
$goods = GoodsModel::find($goodsId); |
|||
$goodsBanners = GoodsBannerModel::where('goods_id',$goodsId)->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 []; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Repositories\v3; |
|||
|
|||
use App\Models\v3\GoodsNew as Model; |
|||
use Dcat\Admin\Repositories\EloquentRepository; |
|||
|
|||
class GoodsNew extends EloquentRepository |
|||
{ |
|||
/** |
|||
* Model. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $eloquentClass = Model::class; |
|||
} |
|||
@ -0,0 +1,157 @@ |
|||
<?php |
|||
|
|||
namespace App\Console\Commands; |
|||
|
|||
use Illuminate\Console\Command; |
|||
use Illuminate\Support\Facades\DB; |
|||
use Illuminate\Support\Facades\Schema; |
|||
|
|||
class MigrateGoods extends Command |
|||
{ |
|||
/** |
|||
* The name and signature of the console command. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $signature = 'migrateData:goods'; |
|||
|
|||
/** |
|||
* The console command description. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $description = 'Command 迁移商品数据'; |
|||
|
|||
/** |
|||
* Create a new command instance. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
/** |
|||
* Execute the console command. |
|||
* |
|||
* @return int |
|||
*/ |
|||
public function handle() |
|||
{ |
|||
$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' => $oldStoreData[$value->store_id], |
|||
'store_id'=>$value->store_id, |
|||
'on_sale'=> $value->is_show == 1 ? 1 : 0, |
|||
'sort'=>$value->num, |
|||
'price'=>$value->money, |
|||
'original_price'=>$value->money2, |
|||
'vip_price'=>$value->vip_money, |
|||
'sales'=>$value->sales, |
|||
'start_num'=>$value->start_num, |
|||
'restrict_num'=>$value->restrict_num, |
|||
'is_infinite'=> $value->is_max == 1 ? 1 :0, |
|||
'inventory'=>$value->inventory, |
|||
'name'=>$value->name, |
|||
'cover_img'=>$value->logo, |
|||
'goods_unit'=>$value->good_unit, |
|||
|
|||
'content'=> strip_tags($value->content), |
|||
'details'=> strip_tags($value->details), |
|||
]; |
|||
$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,'辣')){ |
|||
$spec['spec_key'] = '口味'; |
|||
}else if(strstr($vs->combination,'馅')){ |
|||
$spec['spec_key'] = '馅料'; |
|||
}else if(strstr($vs->combination,'mm')){ |
|||
$spec['spec_key'] = '尺寸'; |
|||
} |
|||
|
|||
$goodsData['spec'] = json_encode([$spec]); |
|||
|
|||
$newData = $goodsData; |
|||
$newBanner = [ |
|||
'type' =>1, |
|||
'path' =>$value->logo, |
|||
'created_at' =>time(), |
|||
'updated_at' =>time(), |
|||
]; |
|||
$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; |
|||
$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(); |
|||
var_dump([time()-$startTime]); |
|||
var_dump($total); |
|||
var_dump($error); |
|||
return 0; |
|||
} |
|||
} |
|||
@ -0,0 +1,93 @@ |
|||
<?php |
|||
|
|||
namespace App\Console\Commands; |
|||
|
|||
use Illuminate\Console\Command; |
|||
use Illuminate\Support\Facades\DB; |
|||
use Illuminate\Support\Facades\Schema; |
|||
|
|||
class MigrateShoppingCart extends Command |
|||
{ |
|||
/** |
|||
* The name and signature of the console command. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $signature = 'migrateData:shoppingCart'; |
|||
|
|||
/** |
|||
* The console command description. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $description = 'Command 迁移购物车数据'; |
|||
|
|||
/** |
|||
* Create a new command instance. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
/** |
|||
* Execute the console command. |
|||
* |
|||
* @return int |
|||
*/ |
|||
public function handle() |
|||
{ |
|||
$oldTableName = 'ims_cjdc_shopcar'; |
|||
$oldStoreTableName = 'ims_cjdc_store'; |
|||
$newTableName = 'lanzu_shopping_cart'; |
|||
// 判断表是否存在
|
|||
if(!Schema::hasTable($oldTableName)){ |
|||
var_dump('旧表不存在'); |
|||
return 0; |
|||
} |
|||
if(!Schema::hasTable($newTableName)){ |
|||
var_dump('新表不存在'); |
|||
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(); |
|||
$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; |
|||
} |
|||
} |
|||
@ -0,0 +1,143 @@ |
|||
<?php |
|||
|
|||
namespace App\Console\Commands; |
|||
|
|||
use Illuminate\Console\Command; |
|||
use Illuminate\Support\Facades\DB; |
|||
use Illuminate\Support\Facades\Schema; |
|||
|
|||
class MigrateStore extends Command |
|||
{ |
|||
/** |
|||
* The name and signature of the console command. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $signature = 'migrateData:store'; |
|||
|
|||
/** |
|||
* The console command description. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $description = 'Command 迁移店铺数据'; |
|||
|
|||
/** |
|||
* Create a new command instance. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
/** |
|||
* Execute the console command. |
|||
* |
|||
* @return int |
|||
*/ |
|||
public function handle() |
|||
{ |
|||
$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)); |
|||
$bar->start(); |
|||
$startTime = time(); |
|||
$error = []; |
|||
$newData = []; |
|||
foreach ($oldData as $key => $value){ |
|||
$storeId = $value->id; |
|||
// 判断在新表是否存在
|
|||
$exist = DB::table($newTableName)->where('id',$storeId)->exists(); |
|||
if($exist){ |
|||
continue; |
|||
} |
|||
$storeData =[ |
|||
'id'=>$storeId, |
|||
'market_id'=>$value->market_id, |
|||
'is_open'=> $value->is_open == 1 ? 1 : 0, |
|||
'is_rest'=> $value->is_rest == 1 ? 1 : 0, |
|||
'status'=>$value->state, |
|||
'category_id'=>$value->md_type, |
|||
'user_id'=>$value->user_id, |
|||
'admin_id'=>$value->admin_id, |
|||
|
|||
'mm_user_id'=>$value->mm_user_id, |
|||
'sort'=>$value->number, |
|||
'loudspeaker_imei'=>$value->loudspeaker_imei, |
|||
'name'=>$value->name, |
|||
'logo'=>$value->logo, |
|||
|
|||
'announcement'=>$value->announcement, |
|||
'address' => $value->address, |
|||
'business_license'=> ($storeId == 365) ? '' :$value->yyzz,/* 因为365的数据的营业资质数据乱码,目前只有365这个店铺的有问题 */ |
|||
'zm_img' => $value->zm_img, |
|||
'fm_img'=>$value->fm_img, |
|||
|
|||
'tel' => $value->tel, |
|||
'link_name'=>$value->link_name, |
|||
'link_tel' => $value->link_tel, |
|||
'expire_time'=> strtotime($value->rzdq_time), |
|||
'time1' => $value->time, |
|||
'time2'=>$value->time2, |
|||
'time3' => $value->time3, |
|||
'time4'=>$value->time4, |
|||
|
|||
'award_money' => $value->award_money, |
|||
'sales'=>$value->score, |
|||
'grade' => $value->sales, |
|||
|
|||
'code'=>$value->code, |
|||
'environment' => $value->environment, |
|||
|
|||
'introduction'=> strip_tags($value->details), |
|||
|
|||
'store_applet_img' => $storeImgPath.$storeId.'.jpg', |
|||
'cash_code_img' => $storePayPath.$storeId.'.jpg', |
|||
|
|||
'created_at' => time(), |
|||
'updated_at' => time(), |
|||
]; |
|||
|
|||
// 获商户摊号
|
|||
$stallInfo = ''; |
|||
$res = preg_match('/[0-9]/', $value->name, $matches, PREG_OFFSET_CAPTURE); |
|||
if($res && count($matches)>0){ |
|||
$stallInfo = substr($value->name,$matches[0][1]); |
|||
} |
|||
$storeData['stall_info'] = $stallInfo; |
|||
|
|||
// 商户经纬度
|
|||
if(!empty($value->coordinates)){ |
|||
$coordinatesArr = explode(',',$value->coordinates); |
|||
$storeData['lng'] = $coordinatesArr[1]; |
|||
$storeData['lat'] = $coordinatesArr[0]; |
|||
} |
|||
$newData = $storeData; |
|||
$res = DB::table($newTableName)->insert($newData); |
|||
if(!$res){ |
|||
$error[] = ['id'=>$storeId]; |
|||
break; |
|||
} |
|||
$bar->advance(); |
|||
} |
|||
$bar->finish(); |
|||
var_dump([time()-$startTime]); |
|||
var_dump($error); |
|||
return 0; |
|||
} |
|||
} |
|||
@ -0,0 +1,98 @@ |
|||
<?php |
|||
|
|||
namespace App\Console\Commands; |
|||
|
|||
use Illuminate\Console\Command; |
|||
use Illuminate\Support\Facades\DB; |
|||
use Illuminate\Support\Facades\Schema; |
|||
|
|||
class MigrateStoreWithdrawal extends Command |
|||
{ |
|||
/** |
|||
* The name and signature of the console command. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $signature = 'migrateData:storeWithdrawal'; |
|||
|
|||
/** |
|||
* The console command description. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $description = 'Command 迁移店铺提现记录数据'; |
|||
|
|||
/** |
|||
* Create a new command instance. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
/** |
|||
* Execute the console command. |
|||
* |
|||
* @return int |
|||
*/ |
|||
public function handle() |
|||
{ |
|||
$oldTableName = 'ims_cjdc_withdrawal'; |
|||
$newTableName = 'lanzu_store_withdrawal'; |
|||
// 判断表是否存在
|
|||
if(!Schema::hasTable($oldTableName)){ |
|||
var_dump('旧表不存在'); |
|||
return 0; |
|||
} |
|||
if(!Schema::hasTable($newTableName)){ |
|||
var_dump('新表不存在'); |
|||
return 0; |
|||
} |
|||
|
|||
$typeData = [2 => 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; |
|||
} |
|||
} |
|||
@ -0,0 +1,98 @@ |
|||
<?php |
|||
|
|||
namespace App\Console\Commands; |
|||
|
|||
use Illuminate\Console\Command; |
|||
use Illuminate\Support\Facades\DB; |
|||
use Illuminate\Support\Facades\Schema; |
|||
|
|||
class MigrateUser extends Command |
|||
{ |
|||
/** |
|||
* The name and signature of the console command. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $signature = 'migrateData:user'; |
|||
|
|||
/** |
|||
* The console command description. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $description = 'Command 迁移微信用户数据'; |
|||
|
|||
/** |
|||
* Create a new command instance. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
/** |
|||
* Execute the console command. |
|||
* |
|||
* @return int |
|||
*/ |
|||
public function handle() |
|||
{ |
|||
$oldTableName = 'ims_cjdc_user'; |
|||
$newTableName = 'lanzu_user'; |
|||
// 判断表是否存在
|
|||
if(!Schema::hasTable($oldTableName)){ |
|||
var_dump('旧表不存在'); |
|||
return 0; |
|||
} |
|||
if(!Schema::hasTable($newTableName)){ |
|||
var_dump('新表不存在'); |
|||
return 0; |
|||
} |
|||
|
|||
$typeData = [2 => 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; |
|||
} |
|||
} |
|||
@ -0,0 +1,90 @@ |
|||
<?php |
|||
|
|||
namespace App\Console\Commands; |
|||
|
|||
use Illuminate\Console\Command; |
|||
use Illuminate\Support\Facades\DB; |
|||
use Illuminate\Support\Facades\Schema; |
|||
|
|||
class MigrateUserCollection extends Command |
|||
{ |
|||
/** |
|||
* The name and signature of the console command. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $signature = 'migrateData:userCollection'; |
|||
|
|||
/** |
|||
* The console command description. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $description = 'Command 迁移用户收藏店铺数据'; |
|||
|
|||
/** |
|||
* Create a new command instance. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
/** |
|||
* Execute the console command. |
|||
* |
|||
* @return int |
|||
*/ |
|||
public function handle() |
|||
{ |
|||
$oldTableName = 'ims_cjdc_collection'; |
|||
$oldStoreTableName = 'ims_cjdc_store'; |
|||
$newTableName = 'lanzu_user_collection'; |
|||
// 判断表是否存在
|
|||
if(!Schema::hasTable($oldTableName)){ |
|||
var_dump('旧表不存在'); |
|||
return 0; |
|||
} |
|||
if(!Schema::hasTable($newTableName)){ |
|||
var_dump('新表不存在'); |
|||
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(); |
|||
$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; |
|||
} |
|||
} |
|||
@ -0,0 +1,70 @@ |
|||
<?php |
|||
|
|||
namespace App\Models\v3; |
|||
|
|||
use Dcat\Admin\Traits\HasDateTimeFormatter; |
|||
use Illuminate\Database\Eloquent\SoftDeletes; |
|||
use Illuminate\Database\Eloquent\Model; |
|||
|
|||
class GoodsNew extends Model |
|||
{ |
|||
use HasDateTimeFormatter; |
|||
use SoftDeletes; |
|||
|
|||
protected $table = 'lanzu_goods_new'; |
|||
protected $dateFormat = 'U'; |
|||
/* 查询记录数 limit */ |
|||
protected $perPage = 10; |
|||
protected $appends = [ |
|||
'cover_img_url', |
|||
'on_sale_text', |
|||
'is_infinite_text' |
|||
]; |
|||
|
|||
protected $casts = [ |
|||
'details_imgs'=>'array', |
|||
'tags'=>'array', |
|||
'spec'=>'array', |
|||
]; |
|||
|
|||
public static $_onSale = ['否','是']; |
|||
public static $_isInfinite = ['关闭','开启']; |
|||
|
|||
public function getCoverImgUrlAttribute($value) |
|||
{ |
|||
$value = $value ? $value : $this->cover_img; |
|||
return $this->imageUrl($value); |
|||
} |
|||
public function getOnSaleTextAttribute($value) |
|||
{ |
|||
$value = $value ? $value : $this->on_sale; |
|||
return isset(self::$_onSale[$value]) ? self::$_onSale[$value] : ''; |
|||
} |
|||
public function getIsInfiniteTextAttribute($value) |
|||
{ |
|||
$value = $value ? $value : $this->is_infinite; |
|||
return isset(self::$_isInfinite[$value]) ? self::$_isInfinite[$value] : ''; |
|||
} |
|||
public function ImageNewBanners(){ |
|||
return $this->hasMany('\App\Models\v3\GoodsNewBanners','goods_id','id')->where('type',1); |
|||
} |
|||
|
|||
public function VideoNewBanners(){ |
|||
return $this->hasMany('\App\Models\v3\GoodsNewBanners','goods_id','id')->where('type',2); |
|||
|
|||
} |
|||
|
|||
/** |
|||
* 处理旧图片 |
|||
* @param $value |
|||
* @return string |
|||
*/ |
|||
public function imageUrl($value) |
|||
{ |
|||
if(strripos($value,"http") === false){ |
|||
return env('OSS_IMG_HOST').'/'.$value; |
|||
}else{ |
|||
return $value; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
<?php |
|||
|
|||
namespace App\Models\v3; |
|||
|
|||
use Dcat\Admin\Traits\HasDateTimeFormatter; |
|||
use Illuminate\Database\Eloquent\SoftDeletes; |
|||
use Illuminate\Database\Eloquent\Model; |
|||
|
|||
class GoodsNewBanners extends Model |
|||
{ |
|||
use HasDateTimeFormatter; |
|||
use SoftDeletes; |
|||
|
|||
protected $table = 'lanzu_goods_banners_new'; |
|||
protected $dateFormat = 'U'; |
|||
protected $fillable = ['path', 'id', 'goods_id','type','url']; |
|||
|
|||
} |
|||
@ -0,0 +1,115 @@ |
|||
<?php |
|||
|
|||
namespace App\Models\v3; |
|||
|
|||
use Dcat\Admin\Traits\HasDateTimeFormatter; |
|||
use Illuminate\Database\Eloquent\SoftDeletes; |
|||
use Illuminate\Database\Eloquent\Model; |
|||
|
|||
class StoreNew extends Model |
|||
{ |
|||
use HasDateTimeFormatter; |
|||
use SoftDeletes; |
|||
|
|||
protected $table = 'lanzu_store_new'; |
|||
protected $dateFormat = 'U'; |
|||
|
|||
/* 查询记录数 limit */ |
|||
protected $perPage = 10; |
|||
|
|||
public static $_isRest= ['否','是']; |
|||
public static $_isOpen = ['关闭','开启']; |
|||
|
|||
protected $appends = [ |
|||
'logo_url', |
|||
'is_rest_text', |
|||
'is_open_text' |
|||
]; |
|||
|
|||
public function getLogoUrlAttribute($value) |
|||
{ |
|||
$value = $value ? $value : $this->logo; |
|||
return $this->imageUrl($value); |
|||
} |
|||
|
|||
public function getIsRestTextAttribute($value) |
|||
{ |
|||
$value = $value ? $value : $this->is_rest; |
|||
return isset(self::$_onRest[$value]) ? self::$_onRest[$value] : ''; |
|||
} |
|||
public function getIsOpenTextAttribute($value) |
|||
{ |
|||
$value = $value ? $value : $this->is_iopen; |
|||
return isset(self::$_isOpen[$value]) ? self::$_isOpen[$value] : ''; |
|||
} |
|||
|
|||
/** |
|||
* 获取商家环境图片 |
|||
* @param $value $this->environment |
|||
* @return array |
|||
*/ |
|||
public function getEnvironmentAttribute($value) |
|||
{ |
|||
$value = $value ? $value : $this->environmant; |
|||
return $value ? explode(',',$value) : []; |
|||
} |
|||
public function setEnvironmentAttribute($value) |
|||
{ |
|||
$this->attributes['environment'] = implode(',',$value); |
|||
} |
|||
|
|||
/** |
|||
* 是否开启店铺 |
|||
*/ |
|||
public function getIsOpenAttribute($value) |
|||
{ |
|||
$value = $value ? $value : ''; |
|||
return $value ? explode(',',$value) : []; |
|||
} |
|||
public function setIsOpenAttribute($value) |
|||
{ |
|||
$this->attributes['is_open'] = 1; |
|||
} |
|||
|
|||
/** |
|||
* 获取单个店铺信息 |
|||
* @param int $id |
|||
* @param string $field |
|||
* @return string |
|||
*/ |
|||
public static function getStoreInfo($id,$field = '*') |
|||
{ |
|||
return self::select($field)->find($id); |
|||
} |
|||
|
|||
/** |
|||
* 获取店铺数组 |
|||
* id为键,name为值 |
|||
* @return array |
|||
*/ |
|||
public static function getStoreArray() |
|||
{ |
|||
$list = self::select('id','name') |
|||
->where('status',2) |
|||
->whereNull('deleted_at') |
|||
->get(); |
|||
$array = []; |
|||
if(count($list) > 0){ |
|||
foreach ($list as $value) { |
|||
$array[$value->id] = $value->name; |
|||
} |
|||
} |
|||
|
|||
return $array; |
|||
} |
|||
|
|||
// 处理图片
|
|||
public function imageUrl($value) |
|||
{ |
|||
if(strripos($value,"http") === false){ |
|||
return env('OSS_IMG_HOST').'/'.$value; |
|||
}else{ |
|||
return $value; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
<?php |
|||
return [ |
|||
'labels' => [ |
|||
'GoodsNew' => '线上商品清洗', |
|||
'goods_new' => '线上商品清洗', |
|||
], |
|||
'fields' => [ |
|||
'name' => '商品名称', |
|||
'category_id' => '所属分类', |
|||
'goods_category_id' => '商品类目', |
|||
'store_id' => '所属商家', |
|||
'cover_img' => '封面图', |
|||
'cover_img_url' => '封面图', |
|||
'banners' => '轮播图', |
|||
|
|||
'price' => '售价', |
|||
'original_price' => '原价', |
|||
'vip_price' => '会员价', |
|||
'on_sale' => '是否上架', |
|||
'on_sale_text' => '是否上架', |
|||
'inventory' => '库存', |
|||
'content' => '简介', |
|||
'sort' => '排序', |
|||
'restrict_num' => '限购份数', |
|||
'start_num' => '起售份数', |
|||
'is_infinite' => '开启无限库存', |
|||
'is_infinite_text' => '开启无限库存', |
|||
'goods_unit' => '商品单位', |
|||
'tags' => '标签', |
|||
'details_imgs' => '详情图片', |
|||
'spec' => '规格', |
|||
'unit_number' => '单位前的数', |
|||
'remark' => '备注', |
|||
'spec_key' =>'规格名称', |
|||
'spec_value' => '规格参数', |
|||
'market_id' => '市场', |
|||
'image_new_banners' => '轮播图片', |
|||
'video_new_banners' => '轮播视频' |
|||
], |
|||
'options' => [ |
|||
], |
|||
]; |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue