75 lines
2.4 KiB
PHP
75 lines
2.4 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace app\KitchenScale2\controller\app;
|
||
|
|
|
||
|
|
// use think\Controller;
|
||
|
|
use think\Db;
|
||
|
|
|
||
|
|
class Product extends Base
|
||
|
|
{
|
||
|
|
protected $is_default = 1;
|
||
|
|
|
||
|
|
// 获取配置信息
|
||
|
|
public function get_default_configuration()
|
||
|
|
{
|
||
|
|
$cfc = Db::connect('cfc_db');
|
||
|
|
// $data = input();
|
||
|
|
|
||
|
|
|
||
|
|
// 2. 获取所点击选项的所有直属上级配置项
|
||
|
|
$content_num = $cfc->table("ceshi3_option")
|
||
|
|
->alias('xuanxiang')
|
||
|
|
->join('ceshi2_configuration peizhi','xuanxiang.parent_id = peizhi.id','LEFT')
|
||
|
|
->where(['peizhi.is_default'=>$this->is_default])
|
||
|
|
->field("xuanxiang.*,peizhi.name")
|
||
|
|
->select();
|
||
|
|
$temporary = [];
|
||
|
|
foreach ($content_num as $key => $value) {
|
||
|
|
$temporary[$value['name']]['id'] = $value['parent_id'];
|
||
|
|
$temporary[$value['name']]['name'] = $value['name'];
|
||
|
|
$temporary[$value['name']]['type'] = "configuration";
|
||
|
|
$temporary[$value['name']]['list'][$value['value']] = [];
|
||
|
|
$temporary[$value['name']]['list'][$value['value']]['id'] = $value['id'];
|
||
|
|
$temporary[$value['name']]['list'][$value['value']]['name'] = $value['value'];
|
||
|
|
$temporary[$value['name']]['list'][$value['value']]['type'] = "parameter";
|
||
|
|
$temporary[$value['name']]['list'][$value['value']]['list'] = [];
|
||
|
|
}
|
||
|
|
// dump($temporary);
|
||
|
|
// die;
|
||
|
|
return $this->msg($temporary);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取所点击选项的所有直属上级配置项
|
||
|
|
private function getAncestorConfigurations($cfc, $optionId)
|
||
|
|
{
|
||
|
|
$ancestors = [];
|
||
|
|
|
||
|
|
// 获取当前选项的配置项
|
||
|
|
$currentConfig = $cfc->query("
|
||
|
|
SELECT c.id, c.name, c.parent_id
|
||
|
|
FROM configurations c
|
||
|
|
JOIN options o ON c.id = o.config_id
|
||
|
|
WHERE o.id = ?
|
||
|
|
", [$optionId]);
|
||
|
|
|
||
|
|
if (!empty($currentConfig)) {
|
||
|
|
$currentConfig = $currentConfig[0];
|
||
|
|
|
||
|
|
// 获取直属上级配置项
|
||
|
|
if ($currentConfig['parent_id']) {
|
||
|
|
$parentConfig = $cfc->query("
|
||
|
|
SELECT c.id, c.name
|
||
|
|
FROM configurations c
|
||
|
|
WHERE c.id = ?
|
||
|
|
", [$currentConfig['parent_id']]);
|
||
|
|
|
||
|
|
if (!empty($parentConfig)) {
|
||
|
|
$parentConfig = $parentConfig[0];
|
||
|
|
$ancestors[] = $parentConfig;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return $ancestors;
|
||
|
|
}
|
||
|
|
}
|