原因说明:对外接口获取分类报错
修改文件:app\dao\product\category\StoreProductCategoryDao
修改方法:getALlByIndex()
public function getALlByIndex(array $where, string $field = 'id,cate_name,pid,pic,relation_id', $limit = 0)
{
$pid = $where['pid'] ?? -1;
if (isset($where['relation_id']) && (int)$where['relation_id'] == 0 || !isset($where['relation_id'])) {
$where['type'] = 0;
} elseif (isset($where['relation_id']) && (int)$where['relation_id'] > 0) {
$where['type'] = 1;
}else{
$where['type'] = 0;
}
return $this->getModel()->where('is_show', 1)->field($field)
->when(in_array($pid, [0, -1]), function ($query) use ($pid) {
switch ($pid) {
case -1://所有一级
$query->where('pid', 0);
break;
case 0://所有二级
$query->where('pid', '>', 0);
break;
}
})->when((int)$pid > 0, function ($query) use ($pid) {
$query->where('pid', $pid);
})->when(isset($where['relation_id']) && (int)$where['relation_id'] > 0, function ($query) use ($where) {
$query->where('relation_id', $where['relation_id']);
})->when(isset($where['type']), function ($query) use ($where) {
$query->where('type', $where['type']);
})->when(isset($where['name']) && $where['name'], function ($query) use ($where) {
$query->whereLike('id|cate_name', '%' . $where['name'] . '%');
})->when($limit > 0, function ($query) use ($limit) {
$query->limit($limit);
})->order('sort DESC')->select()->toArray();
}