Browse Source

店铺_new换表

master
liangyuyan 5 years ago
parent
commit
e2973cbffb
  1. 2
      app/Admin/Controllers/v3/GoodsNewController.php
  2. 160
      app/Console/Commands/MigrateGoods.php
  3. 2
      app/Console/Commands/MigrateOrderStatistics.php
  4. 4
      app/Console/Commands/MigrateStore.php
  5. 2
      app/Models/v3/Store.php

2
app/Admin/Controllers/v3/GoodsNewController.php

@ -89,7 +89,7 @@ class GoodsNewController extends AdminController
$filter->equal('goods_unit');
});
$grid->model()->orderBy('category_id', 'asc');
$grid->model()->orderBy('goods_category_id', 'asc');
// 每页10条
$grid->paginate(10);
});

160
app/Console/Commands/MigrateGoods.php

@ -1,160 +0,0 @@
<?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 < $value->money)?$value->money:$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),
'created_at' => time(),
'updated_at' => time(),
];
$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;
}
}

2
app/Console/Commands/MigrateOrderStatistics.php

@ -40,7 +40,7 @@ class MigrateOrderStatistics extends Command
public function handle()
{
$oldTableName = 'ims_cjdc_order_sales_statistics';
$newTableName = 'lanzu_order_sales_statistics_copy';
$newTableName = 'lanzu_order_sales_statistics';
// 判断表是否存在
if(!Schema::hasTable($oldTableName)){
var_dump('旧表不存在');

4
app/Console/Commands/MigrateStore.php

@ -39,8 +39,8 @@ class MigrateStore extends Command
*/
public function handle()
{
$oldTableName = 'ims_cjdc_store_new';
$newTableName = 'lanzu_store_new';
$oldTableName = 'ims_cjdc_store';
$newTableName = 'lanzu_store';
// $storeImgPath = 'QR_code/code_store_img/wx_store_';/* 商户小程序码 */
// $storePayPath = 'QR_code/code_pay_img/wx_pay_';/* 收银二维码 */
// 判断表是否存在

2
app/Models/v3/Store.php

@ -11,7 +11,7 @@ class Store extends Model
use HasDateTimeFormatter;
use SoftDeletes;
protected $table = 'lanzu_store_new';
protected $table = 'lanzu_store';
protected $dateFormat = 'U';
/* 查询记录数 limit */

Loading…
Cancel
Save