Browse Source

Merge branch 'phoenix' into develop

master
liangyuyan 6 years ago
parent
commit
19dc882741
  1. 21
      app/Admin/Forms/CategoryTieForm.php
  2. 39
      app/Console/Commands/MigrateStoreAccount.php
  3. 80
      app/Console/Commands/MigrateStoreBalance.php

21
app/Admin/Forms/CategoryTieForm.php

@ -6,6 +6,7 @@ use Dcat\Admin\Widgets\Form;
use Symfony\Component\HttpFoundation\Response;
use App\Libs\SsdbClient;
use App\Models\v3\Category as CategoryModel;
use Illuminate\Support\Facades\DB;
class CategoryTieForm extends Form
{
@ -22,37 +23,31 @@ class CategoryTieForm extends Form
public function handle(array $input)
{
$ids = $input['category_ids'];
$category = CategoryModel::select('id','title','cover_img','sort')->whereIn('id',$ids)->get();
$category = CategoryModel::select('id','title','cover_img','sort')->whereIn('id',$ids)->orderBy('sort','desc')->get();
$data = [];
if(!empty($category)){
foreach ($category as $key => $value){
$data[$value->sort] = [
$data[$value->id] = json_encode([
'icon' => $value->cover_img,
'name' => $value->title,
'sort' => $value->sort,
'id' => $value->id
];
]);
}
if(count($data) > 0){
// 根据sort排序
krsort($data);
$save = array_column($data,null,'id');
foreach($save as &$cate){
$cate = json_encode($cate);
}
$this->ssdb->client()->hclear('applet_index_category');
$category = $this->ssdb->client()->multi_hset('applet_index_category',$save);
$category = $this->ssdb->client()->multi_hset('applet_index_category',$data);
if($category === false){
return $this->error('修改失败');
return $this->error('绑定失败');
}
return $this->success('修改成功', '/category');
return $this->success('绑定成功', '/category');
}
}
return $this->success('未进行修改或者查询不到分类', '/category');
return $this->success('未进行绑定或者查询不到分类', '/category');
}
/**

39
app/Console/Commands/MigrateStoreAccount.php

@ -77,11 +77,14 @@ class MigrateStoreAccount extends Command
foreach ($oldData as $key => $value){
$storeId = $value->store_id;
$userId = $value->user_id;
if(empty($userId)){
$error[] = ['id'=>$userId];
if(empty($userId) || empty($storeId)){
$error[] = ['user_id'=>$userId,'store_id'=>$storeId];
break;
}
$userType = 0;
$moneyType = 0;
$sourceId = $value->order_id;
$sourceType = 0;
// 判断是否存在 总账
$exist = DB::table($newTableName)
->where('user_id',$userId)
@ -90,24 +93,25 @@ class MigrateStoreAccount extends Command
->where('source_type',0)
->where('money_type')
->exists();
$desc = '';
$comment = '';
if(!$exist){
$newData =[
'id'=>$userId,
'nick_name'=>$value->name,
'user_id'=>$userId,
'user_type'=>$userType,
'avatar'=>$value->img,
'openid'=>$value->openid,
'money'=>$value->money,
'money_type'=>$moneyType,
'total_score'=>$value->total_score,
'wallet'=>$value->wallet,
'source_id'=>$sourceId,
'source_type'=>$sourceType,
'real_name'=>$value->user_name,
'tel'=>$value->user_tel,
'unionid'=>$value->unionid,
'desc'=>$desc,
'comment'=>$comment,
'status'=>1,
'created_at' => strtotime($value->join_time),
'updated_at' => $value->updated_at,
'created_at' => time(),
'updated_at' => time(),
];
$res = DB::table($newTableName)->insert($newData);
@ -154,4 +158,9 @@ class MigrateStoreAccount extends Command
var_dump($error);
return 0;
}
public function getMoneyType($type,$note)
{
}
}

80
app/Console/Commands/MigrateStoreBalance.php

@ -0,0 +1,80 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class MigrateStoreBalance extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'migrateData:storeBalance';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command 迁移商户余额数据到lanzu_user_balance表';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$oldOrderTableName = 'ims_cjdc_order';
$oldWithdrawalTableName = 'ims_cjdc_withdrawal';
$oldAccountTableName = 'ims_cjdc_store_account';
$newTableName = 'lanzu_user_balance';
// 判断表是否存在
if(!Schema::hasTable($oldAccountTableName)){
var_dump('旧表不存在');
return 0;
}
if(!Schema::hasTable($newTableName)){
var_dump('新表不存在');
return 0;
}
$oldData = DB::table($oldAccountTableName)->orderBy('id','asc')->get();
$bar = $this->output->createProgressBar(count($oldData));
$bar->start();
$startTime = time();
$error = [];
$newData = [];
foreach ($oldData as $key => $value){
$storeId = $value->store_id;
$bar->advance();
}
DB::table($newTableName)->insert($newData);
$bar->finish();
var_dump([time()-$startTime]);
var_dump($error);
return 0;
}
}
Loading…
Cancel
Save