Browse Source

分类选择上级分类问题修复

master
liangyuyan 5 years ago
parent
commit
09a6ecc9c4
  1. 2
      app/Admin/Controllers/v3/CategoryController.php
  2. 3
      app/Console/Commands/MigrateMarketData.php
  3. 5
      app/Models/v3/Category.php

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

@ -49,7 +49,7 @@ class CategoryController extends AdminController
return Form::make(new Category(),function (Form $form){
// 只查一级
$parentList = Category::getArray([['parent_id','=',0]],[0=>'顶级']);
$parentList = Category::getArray([['parent_id','=',0]],['顶级'=>0]);
$form->select('parent_id')->default(0)->options($parentList);
$form->text('title')->required();

3
app/Console/Commands/MigrateMarketData.php

@ -40,7 +40,7 @@ class MigrateMarketData extends Command
{
// get old data from old table
$oldData = DB::table('ims_cjdc_market')->get();
$oldData = DB::table('ims_cjdc_market_new')->get();
$bar = $this->output->createProgressBar(count($oldData));
$bar->start();
@ -49,6 +49,7 @@ class MigrateMarketData extends Command
foreach ($oldData as $key => $value) {
$coordinates = explode(',', $value->coordinates);
$newData[] = [
'id' => $value->id,
'mp_id' => $value->mp_id ?? 0,
'name' => $value->name ?? '',
'logo' => $value->logo ?? '',

5
app/Models/v3/Category.php

@ -56,9 +56,10 @@ class Category extends Model
if(count($where) > 0){
$model->where($where);
}
$list = $model->pluck('title','id')->toArray();
$list = $model->pluck('id','title')->toArray();
if(!empty($options)){
return array_merge($options,$list);
$new = array_merge($options,$list);
return array_flip($new);
}else{
return $list;
}

Loading…
Cancel
Save