Browse Source

迁移数据和修改上传图片名唯一

master
liangyuyan 6 years ago
parent
commit
8cdf7a2895
  1. 2
      app/Admin/Controllers/v3/BannersController.php
  2. 2
      app/Admin/Controllers/v3/CategoryController.php
  3. 6
      app/Admin/Controllers/v3/GoodsActivityController.php
  4. 2
      app/Admin/Controllers/v3/GoodsCategoryController.php
  5. 4
      app/Admin/Controllers/v3/GoodsController.php
  6. 6
      app/Admin/Controllers/v3/GoodsNewController.php
  7. 10
      app/Admin/Controllers/v3/StoreController.php
  8. 3
      app/Console/Commands/MigrateGoods.php
  9. 2
      app/Console/Commands/MigrateShoppingCart.php
  10. 4
      app/Console/Commands/MigrateStore.php
  11. 79
      app/Console/Commands/MigrateStoreImg.php
  12. 4
      app/Console/Commands/MigrateStoreWithdrawal.php
  13. 10
      app/Console/Commands/MigrateUser.php
  14. 34
      app/Console/Commands/MigrateUserCollection.php
  15. 6
      config/filesystems.php
  16. BIN
      public/uploads/mp_images/dic_banner_1.jpg

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

@ -105,7 +105,7 @@ class BannersController extends AdminController
});
});
$form->column(6, function (Form $form) {
$form->image('cover')->required();
$form->image('cover')->required()->uniqueName();//->disk('admin')
$form->select('cover_type')->options(BannersModel::$_coverType)->required();
$form->text('path')->default('');
$form->select('path_type')->options(BannersModel::$_pathType)->default('');

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

@ -53,7 +53,7 @@ class CategoryController extends AdminController
$form->select('parent_id')->default(0)->options($parentList);
$form->text('title')->required();
$form->image('cover_img')->required();
$form->image('cover_img')->required()->uniqueName();
$form->number('sort');

6
app/Admin/Controllers/v3/GoodsActivityController.php

@ -141,7 +141,7 @@ class GoodsActivityController extends AdminController
$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->image('cover_img')->required()->uniqueName();
$form->select('type')->options(GoodsActivityModel::$_type)->default('flash_sale');
$form->datetime('expire_time')->value($form->model()->expire_time_text);
$form->number('time_limit_days');
@ -161,13 +161,13 @@ class GoodsActivityController extends AdminController
});
$form->column(12, function (Form $form) {
$form->hasMany('image_banners', function (Form\NestedForm $form) {
$form->image('path')->width(2);
$form->image('path')->width(2)->uniqueName();
$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->file('path')->width(2);
$form->file('path')->width(2)->uniqueName();
$form->number('sort')->width(2)->default(0);
$form->hidden('type')->value(2)->default(2);
});

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

@ -75,7 +75,7 @@ class GoodsCategoryController extends AdminController
$category = CategoryModel::getArray([['parent_id','>',0]]);
$form->select('category_id')->width(4)->required()->options($category);
$form->text('title')->width(4)->required();
$form->image('cover_img')->width(2);
$form->image('cover_img')->width(2)->uniqueName();
$form->number('sort');
$form->disableResetButton();

4
app/Admin/Controllers/v3/GoodsController.php

@ -164,7 +164,7 @@ class GoodsController extends AdminController
$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->image('cover_img')->required()->uniqueName();
$form->number('sort');
});
$form->column(6, function (Form $form) {
@ -179,7 +179,7 @@ class GoodsController extends AdminController
});
$form->column(12, function (Form $form) {
$form->hasMany('image_banners', function (Form\NestedForm $form) {
$form->image('path')->width(2);
$form->image('path')->width(2)->uniqueName();
$form->number('sort')->width(2)->default(0);
$form->hidden('type')->value(1)->default(1);
})->required();

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

@ -27,7 +27,7 @@ class GoodsNewController extends AdminController
return Grid::make(new GoodsNew(), function (Grid $grid) {
// 二级分类
$categoryList = CategoryModel::getArray([['parent_id','>',0]],[0=>'选择分类']);
$categoryList = CategoryModel::getArray([['parent_id','>',0]],['选择分类'=>0]);
// 店铺
$storeList = StoreModel::getStoreArray();
@ -170,7 +170,7 @@ class GoodsNewController extends AdminController
$form->select('goods_category_id');
$form->select('store_id')->required()->options($storeList);
$form->text('name')->required()->maxLength(20);
$form->image('cover_img')->required();
$form->image('cover_img')->required()->uniqueName();
$form->number('sort');
});
$form->column(6, function (Form $form) {
@ -185,7 +185,7 @@ class GoodsNewController extends AdminController
});
$form->column(12, function (Form $form) {
$form->hasMany('image_new_banners', function (Form\NestedForm $form) {
$form->image('path')->width(2);
$form->image('path')->width(2)->uniqueName();
$form->number('sort')->width(2)->default(0);
$form->hidden('type')->value(1)->default(1);
})->required();

10
app/Admin/Controllers/v3/StoreController.php

@ -153,7 +153,7 @@ class StoreController extends AdminController
$form->select('market_id')->required()->options($marketList);
$form->select('category_id')->options($categoryList);
$form->text('name')->required()->maxLength(50);
$form->image('logo')->required();
$form->image('logo')->required()->uniqueName();
$form->mobile('tel');
$form->text('link_name')->required();
$form->mobile('link_tel')->required();
@ -175,9 +175,9 @@ class StoreController extends AdminController
$form->text('address');
});
$form->column(6, function (Form $form) use($userList){
$form->image('business_license')->required();
$form->image('zm_img')->required();
$form->image('fm_img')->required();
$form->image('business_license')->required()->uniqueName();
$form->image('zm_img')->required()->uniqueName();
$form->image('fm_img')->required()->uniqueName();
$form->select('admin_id')->options($userList)->required();/*需要优化 一个用户只能绑定一家店铺*/
$form->select('user_id')->options($userList)->required();/*需要优化 一个用户只能绑定一家店铺*/
$form->time('time1','时间段一开始')->format('HH:mm');
@ -228,7 +228,7 @@ class StoreController extends AdminController
$store->cash_code_img = $pRes['status'] ? $pRes['path'] : '';
$store->save();
// 剪裁图片
// $form->image('cash_code_img')->crop(270, 270, [5, 5]);
// $form->image('cash_code_img')->crop(270, 270, [5, 5])->uniqueName();
//店长账号
$storeUsersInfo = StoreUsersModel::where('store_id',$id)->where('user_category',1)->first();

3
app/Console/Commands/MigrateGoods.php

@ -102,6 +102,9 @@ class MigrateGoods extends Command
'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){

2
app/Console/Commands/MigrateShoppingCart.php

@ -60,7 +60,7 @@ class MigrateShoppingCart extends Command
$error = [];
foreach ($oldData as $key => $value){
$cartId = $value->id;
// 判断在新表是否存在
// 判断是否存在
$exist = DB::table($newTableName)->where('id',$cartId)->exists();
if($exist){
continue;

4
app/Console/Commands/MigrateStore.php

@ -61,7 +61,7 @@ class MigrateStore extends Command
$newData = [];
foreach ($oldData as $key => $value){
$storeId = $value->id;
// 判断在新表是否存在
// 判断是否存在
$exist = DB::table($newTableName)->where('id',$storeId)->exists();
if($exist){
continue;
@ -109,7 +109,7 @@ class MigrateStore extends Command
'store_applet_img' => $storeImgPath.$storeId.'.jpg',
'cash_code_img' => $storePayPath.$storeId.'.jpg',
'created_at' => time(),
'created_at' => strtotime($value->sq_time),
'updated_at' => time(),
];

79
app/Console/Commands/MigrateStoreImg.php

@ -0,0 +1,79 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class MigrateStoreImg extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'migrateData:storeImg';
/**
* 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()
{
$newTableName = 'lanzu_store_new';
$storeImgPath = 'QR_code/code_store_img/wx_store_';/* 商户小程序码 */
$storePayPath = 'QR_code/code_pay_img/wx_pay_';/* 收银二维码 */
if(!Schema::hasTable($newTableName)){
var_dump('新表不存在');
return 0;
}
$oldData = DB::table($newTableName)->orderBy('id','desc')->get();
$bar = $this->output->createProgressBar(count($oldData));
$bar->start();
$startTime = time();
$error = [];
$newData = [];
foreach ($oldData as $key => $value){
$storeId = $value->id;
$storeData =[
'store_applet_img' => $storeImgPath.$storeId.'.jpg',
'cash_code_img' => $storePayPath.$storeId.'.jpg',
'updated_at' => time(),
];
$newData = $storeData;
$res = DB::table($newTableName)->where('id',$storeId)->update($newData);
if(!$res){
$error[] = ['id'=>$storeId];
break;
}
$bar->advance();
}
$bar->finish();
var_dump([time()-$startTime]);
var_dump($error);
return 0;
}
}

4
app/Console/Commands/MigrateStoreWithdrawal.php

@ -59,7 +59,7 @@ class MigrateStoreWithdrawal extends Command
$error = [];
foreach ($oldData as $key => $value){
$withdrawalId = $value->id;
// 判断记录在新表是否存在
// 判断是否存在
$exist = DB::table($newTableName)->where('id',$withdrawalId)->exists();
if($exist){
continue;
@ -68,7 +68,7 @@ class MigrateStoreWithdrawal extends Command
'id'=>$withdrawalId,
'store_id'=>$value->store_id,
'name'=>$value->name,
'name'=> ($value->name == 'undefined') ? '': $value->name,
'tel'=>$value->tel,
'type'=> isset($typeData[$value->type])?$typeData[$value->type]:0,
'check_time'=>strtotime($value->sh_time),

10
app/Console/Commands/MigrateUser.php

@ -59,7 +59,7 @@ class MigrateUser extends Command
$error = [];
foreach ($oldData as $key => $value){
$userId = $value->id;
// 判断记录在新表是否存在
// 判断是否存在
$exist = DB::table($newTableName)->where('id',$userId)->exists();
if($exist){
continue;
@ -70,17 +70,17 @@ class MigrateUser extends Command
'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,
'real_name'=>$value->user_name,
'tel'=>$value->user_tel,
'unionid'=>$value->unionid,
'status'=>$value->status,
'created_at' => strtotime($value->join_time),
'updated_at' => strtotime($value->sh_time),
'updated_at' => $value->updated_at,
];
$res = DB::table($newTableName)->insert($newData);

34
app/Console/Commands/MigrateUserCollection.php

@ -60,26 +60,30 @@ class MigrateUserCollection extends Command
$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;
// 店铺存在
if(isset($oldStoreData[$value->store_id])){
$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' => $value->time,
'updated_at' => time(),
];
$res = DB::table($newTableName)->insert($newData);
if(!$res){
$error[] = ['id'=>$collectionId];
break;
}
}
$bar->advance();
}
$bar->finish();

6
config/filesystems.php

@ -54,11 +54,11 @@ return [
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
'image' => [
'admin' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/public/uploads',
'root' => public_path('uploads'),
'visibility' => 'public',
'url' => env('APP_URL').'/uploads',
],
'oss' => [
'driver' => 'oss',

BIN
public/uploads/mp_images/dic_banner_1.jpg

After

Width: 750  |  Height: 280  |  Size: 52 KiB

Loading…
Cancel
Save