store_id; $fromIndex_ = NewDiyTemplate::findOne([ 'is_delete' => 0, 'is_index' => 1, 'store_id' => $store_id, 'name' => 'DIY', ]); $template = \json_decode($fromIndex_->template, true); if ($template) { foreach ($template['templates'] as &$index_item) { if ($index_item['type'] === 'productClassify') { if (intval($index_item['params']['type']) === 2) { if (isset($index_item['params']['classifyList'])) { $cat_list = Cat::find()->where(['store_id' => $store_id, 'is_show' => 1, 'is_delete' => 0, 'parent_id' => 0]) ->select('id, name')->asArray()->all(); $classify_diy = []; foreach ($cat_list as $cat_item) { $classify_diy[] = [ "id" => $cat_item['id'], "title" => $cat_item['name'], "subTitle" => $cat_item['name'], "link" => null, "dataFrom" => "select", "classifyId" => $cat_item['id'], "data" => [] ]; } $index_item['params']['classifyList'] = $classify_diy; } } } } $fromIndex_->template = json_encode($template, JSON_UNESCAPED_UNICODE); $fromIndex_->save(); } } }