public function exportcsvAction() { $request = $this->getRequest()->getParams(); if (isset($request['source']) && $request['source'] == 'list') { $whereSearch = "t1.state != 'Reviewing' and t1.state != 'Return' "; } else { $whereSearch = "1=1"; } foreach ($request as $k => $v) { if ($v) { if ($k == 'search_tag') { $whereSearch .= " and (t1.name like '%{$v}%' or t1.remark like '%{$v}%' or t1.manufacturers like '%{$v}%' or t1.code like '%{$v}%' or t1.description like '%{$v}%')"; } else { if ($k == 'search_state' && $v == 1) { $whereSearch .= " and (state = 'Active' or state = 'APL' or state = 'Preliminary')"; } else { if ($k == 'search_state') { $whereSearch .= " and state = '{$v}'"; } else { if ("search_archive_date_from" == $k && $v) { $whereSearch .= " and t1.archive_time >= '" . str_replace('T', ' ', $v) . "'"; } else { if ("search_archive_date_to" == $k && $v) { $whereSearch .= " and t1.archive_time <= '" . str_replace('T00:00:00', ' 23:59:59', $v) . "'"; } else { $col = str_replace('search_', '', $k); if ($col != $k) { // 查询条件 $whereSearch .= " and t1." . $col . " like '%" . $v . "%'"; } } } } } } } } print chr(0xef) . chr(0xbb) . chr(0xbf); $materiel = new Product_Model_Materiel(); $record = new Dcc_Model_Record(); // 获取物料数据 $data = $materiel->getList($whereSearch, null, null); $data_csv = array(); $title = array('cnt' => '#', 'id' => 'ID', 'code' => '物料号', 'name' => '名称', 'description' => '描述', 'type_name' => '物料类别', 'state' => '状态', 'ver' => '版本', 'unit' => '单位', 'project_name' => '产品型号', 'supply1' => '供应商1', 'supply2' => '供应商2', 'manufacturers' => '制造商', 'mpq' => 'MPQ', 'moq' => 'MOQ', 'tod' => '标准货期', 'data_file' => '数据手册', 'tsr' => 'TSR', 'first_report' => '样品检验报告', 'remark' => '备注', 'archive_time' => '发布日期', 'creater' => '申请人', 'create_time' => '申请时间'); $title = $this->object_array($title); $date = date('YmdHsi'); $filename = "materiel_list" . $date; $path = "../temp/" . $filename . ".csv"; $file = fopen($path, "w"); fputcsv($file, $title); array_push($data_csv, $title); $typeids = array(); $typenames = array(); $k = 0; for ($i = 0; $i < count($data); $i++) { if (($typeId = $data[$i]['type']) != '') { if (in_array($typeId, $typeids)) { $data[$i]['type_name'] = $typenames[$typeId]; } else { $typeName = $this->getTypeByConnectForExport($typeId, ''); $data[$i]['type_name'] = $typeName; $typeids[] = $typeId; $typenames[$typeId] = $typeName; } } //$data[$i]['record'] = $record->getHis($data[$i]['id'], 'materiel'); $d = $data[$i]; $k++; $info = array('cnt' => $k, 'id' => $d['id'], 'code' => $d['code'], 'name' => $d['name'], 'description' => $d['description'], 'type_name' => $d['type_name'], 'state' => $d['state'], 'ver' => 'V' . $d['ver'], 'unit' => $d['unit_name'], 'project_name' => $d['project_name'], 'supply1' => $d['supply_code1'] . $d['supply_cname1'], 'supply2' => $d['supply_code2'] . $d['supply_cname2'], 'manufacturers' => $d['manufacturers'], 'mpq' => $d['mpq'], 'moq' => $d['moq'], 'tod' => $d['tod'], 'data_file' => $d['data_file'], 'tsr' => $d['tsr'], 'first_report' => $d['first_report'], 'remark' => $d['remark'], 'archive_time' => $d['archive_time'], 'creater' => $d['creater'], 'create_time' => $d['create_time']); $d = $this->object_array($info); array_push($data_csv, $info); fputcsv($file, $d); } fclose($file); $this->operate("物料导出"); echo $filename; exit; }