where('super_type_id', 0)->field('type_id as id, type_name as name')->select(); for ($i = 0; $i < count($FirstLeveType); $i++) { $SecondLeveType = db('supplier_type')->where('super_type_id', $FirstLeveType[$i]['id'])->field('type_id as id, type_name as name')->select(); /*for ($m = 0; $m < count($SecondLeveType); $m++) { $count = db('supplier_info')->where('supplier_type', $SecondLeveType[$m]['type_id'])->count(); if ($count>0) { $SecondLeveType[$m]['type_name'] .= '【'.$count.'】'; } }*/ for ($j = 0; $j < count($SecondLeveType); $j++) { $ThridLeveType = db('supplier_info')->where('supplier_type', $SecondLeveType[$j]['id'])->field('supplier_id as id, supplier_name as name')->select(); /*for ($k = 0; $k < count($ThridLeveType); $k++) { $count = db('supplier_info')->where('supplier_type', $ThridLeveType[$k]['type_id'])->count(); if ($count>0) { $ThridLeveType[$k]['type_name'] .= '【'.$count.'】'; } }*/ $SecondLeveType[$j]['sub_type'] = $ThridLeveType; } $FirstLeveType[$i]['sub_type'] = $SecondLeveType; } //dump($FirstLeveType); return $this->sendSuccess($FirstLeveType); } //根据资产类型获取资产列表 public function GetSupplierInfo() { $param = request()->post(); $SupplierInfo = db('supplier_info')->where('supplier_id', $param['supplier_id'])->find(); $contacts = db('supplier_contacts')->where('customer_id', $param['supplier_id'])->select(); $SupplierInfo['contacts'] = $contacts; return $this->sendSuccess($SupplierInfo); } //添加合同类型 public function AddSupplierType() { $param = request()->post(); $ret = []; if ($param['type_id']>0) { //添加子类型 $ret = db('supplier_type')->where('type_id', $param['type_id'])->field('type_id,super_type_id')->find(); } else { //添加基类型 $ret['type_id'] = 0; } if ($ret != null) { $insert = []; $insert['type_name'] = $param['type_name']; $insert['super_type_id'] = $ret['type_id']; $insert['create_time'] = date('Y-m-d H:i:s'); db('supplier_type')->insert($insert); } } public function AddSupplierInfo() { $param = request()->post(); $ret = db('supplier_type')->where('type_id', $param['supplier_type'])->field('type_id,super_type_id')->find(); if ($ret != null) { $insert_info = []; $insert_info['supplier_type'] = $param['supplier_type']; $insert_info['supplier_name'] = $param['supplier_name']; $insert_info['supplier_intro'] = $param['supplier_intro']; $insert_info['create_time'] = $param['create_time']; if($param['supplier_url'] == '') { $insert_info['supplier_url'] = ''; } else { $insert_info['supplier_url'] = $param['supplier_url']; } db('supplier_info')->insert($insert_info); } } public function UpdateSupplierInfo() { $param = request()->post(); if($param != null){ $update = []; $update['supplier_name'] = $param['supplier_name']; $update['contacts_name'] = $param['contacts_name']; $update['contacts_phone'] = $param['contacts_phone']; if($param['supplier_url'] != '') { $update['supplier_url'] = $param['supplier_url']; } $update['create_time'] = $param['create_time']; $ret = db('supplier_info')->where('supplier_id',$param['supplier_id'])->update($update); if($ret){ return $this->sendSuccess('修改成功'); }else{ return $this->sendError('修改失败'); } } } public function AddContractsInfo() { $param = request()->post(); if($param != null) { $param['create_time'] = date('Y-m-d H:i:s'); db('supplier_contacts')->insert($param); return $this->sendSuccess('添加成功'); } } // 供应商检索 public function searchSuppliers() { $param = request()->param(); $currPage = isset($param['currPage']) ? $param['currPage'] : 1; $pageSize = isset($param['pageSize']) ? $param['pageSize'] : 20; // 构建查询条件 $where = []; $where['company_type'] = 4; // 4代表供应商 // 公司名模糊搜索 if (isset($param['company_name']) && !empty($param['company_name'])) { $where['company_name'] = ['like', '%' . $param['company_name'] . '%']; } // 查询供应商列表 $supplierList = db('partner_company') ->where($where) ->order('company_id', 'desc') ->page($currPage, $pageSize) ->select(); // 遍历供应商列表,补充服务类型信息 foreach ($supplierList as &$supplier) { // 获取服务类型名称 if ($supplier['service_type']) { $serviceType = db('partner_service_type') ->where('type_id', $supplier['service_type']) ->field('type_name') ->find(); $supplier['service_type_name'] = $serviceType ? $serviceType['type_name'] : ''; } else { $supplier['service_type_name'] = ''; } } unset($supplier); // 查询总记录数 $total = db('partner_company')->where($where)->count(); $res['list'] = $supplierList; $res['total'] = $total; return $this->sendSuccess($res); } }