12 changed files with 609 additions and 70 deletions
-
3app/Admin/Actions/Grid/GoodsCopy.php
-
36app/Admin/Actions/Grid/GoodsNewCopy.php
-
11app/Admin/Controllers/v3/GoodsNewController.php
-
105app/Admin/Forms/GoodsNewCopyForm.php
-
112app/Console/Commands/MigrateGoods.php
-
93app/Console/Commands/MigrateShoppingCart.php
-
21app/Console/Commands/MigrateStore.php
-
98app/Console/Commands/MigrateStoreWithdrawal.php
-
98app/Console/Commands/MigrateUser.php
-
90app/Console/Commands/MigrateUserCollection.php
-
8app/Models/v3/GoodsNew.php
-
4resources/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,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,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,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; |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue