You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

API传入shop_id查询门店服务返回全部门店数据问题排查

问题原因

getAllDataWhere1方法查询价目表时仅过滤了服务ID,没有限制门店ID,同一份服务会在多个门店上架,导致查询时返回了所有门店下对应服务的价目数据。

修复方案

步骤1:修改getAllDataWhere1方法,增加门店过滤逻辑

调整方法入参,追加shop_id参数并在查询条件中增加门店限制,代码修改如下:

public function getAllDataWhere1($service_id, $shop_id)
{
    $this->db->select('pl.*,s.service_name');
    // $this->db->select('CONCAT("'.base_url().'assets/images/Product/",pl.image) as image');
    $this->db->from('la_price_list pl');
    $this->db->join('la_service s', 's.service_id = pl.service_id');
    // 新增门店过滤条件
    $this->db->where('pl.shop_id',$shop_id);
    $this->db->where('pl.service_id',$service_id);
    $query = $this->db->get();
    return $query->result();
}

步骤2:修改getItembyShopId中调用getAllDataWhere1的逻辑

调用时传入当前接口接收的shop_id,同时可以把货币查询逻辑移到循环外避免重复查询数据库,优化后代码如下:

public function getItembyShopId($shop_id)
{
    $this->form_validation->set_rules('shop_id', 'shop_id', 'required');
    if ($this->form_validation->run() == false) 
    {
        $this->Api_Auth_model->responseFailed(0,ALL_FIELD_MANDATORY);
        exit();
    }
    $query = $this->db->where('shop_id',$shop_id)->where('status','1')->get('la_price_list')->num_rows();
    if($query > 0)
    {
        $price_list = $this->Api_Price_list_model->getPriceforService($shop_id);
        $price_lists = array();
        // 货币查询移到循环外,仅查询一次
        $cur = $this->db->where('status','1')->get('la_currency')->row_array();
        $data['currency_code'] = $cur['currency_symbol'];
        foreach($price_list as $price_list)
        {
            // 调用时传入shop_id
            $service = $this->Api_Price_list_model->getAllDataWhere1($price_list->service_id, $shop_id);
            $price_list->services = $service;
            array_push($price_lists, $price_list);
            $data['item_list'] = $price_lists;
        }
        return $data;
    }else{
        return 0;
    }
}

修改完成后接口就只会返回指定门店下的服务数据。

内容的提问来源于stack exchange,提问作者Sandeep Kumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 20:57:01