hasOne(OrderAttachment::class, 'attachment_ids'); } /** * 下载文件 * @return bool * @throws \think\db\exception\DataNotFoundException * @param $id 与数据库字段对应的数组集合 */ public function downFilelocal($id) { if ($id) { $fileinfo = $this->where('id', $id)->field('name,url,path,filesize')->find()->toArray(); // 文件信息 $fileurl = config('uploadFile.url') . $fileinfo['url']; //绝对路径D:\wamp\www\businesssys_api\public\uploads\20180426\24dc7b794230dc2e5d1d7f75dbacb86d.htm header("Cache-Control:"); header("Cache-Control: public"); //设置输出浏览器格式 $data = date('Ymd'); header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=" . $data . "|" . $fileinfo['name']); header("Accept-Ranges: bytes"); header("Accept-Length:" . $fileinfo['filesize']); readfile($fileurl); } else { return FALSE; } } /** * 查询图片url * @return bool * @throws \think\db\exception\DataNotFoundException * @param $id 图片id */ public function getUrl($id) { $picinfo = $this->where('id', $id)->field('name,url,id,ext,thum1')->find(); if(!$picinfo) { return null; } $picinfo['id'] = (string)$picinfo['id']; // 前端要求 图片id转成string类型 tr 2020-8-4 // $picinfo['url'] = config('uploadFile.url') . $picinfo['url']; if (strpos($picinfo['url'], '/Content/') !== false || strpos($picinfo['url'], '/HousingPhotos/') !== false) { $picinfo['url'] = config('uploadFile.old_cspg_url') . $picinfo['url']; $picinfo['thum1'] = config('uploadFile.old_cspg_url') . DS . $picinfo['thum1']; } elseif (strpos($picinfo['url'], 'http') !== false) { return $picinfo; } else { $picinfo['url'] = config('uploadFile.url') . $picinfo['url']; $picinfo['thum1'] = config('uploadFile.url') . DS . $picinfo['thum1']; } return $picinfo; } /** * 查询图片url */ public function getUrls($ids) { // if(is_array($ids)) $ids = implode(',', $ids); if(is_array($ids)){ $result = array_filter($ids, function($item) { return $item !== ""; }); $ids = implode(',', $result); } $sql = "SELECT `name`,`url`,`id`,`ext`,`thum1` FROM `pg_attachment` WHERE `id` IN ($ids) ORDER BY field(id,$ids)"; $picinfo = $this->query($sql); // $picinfo = $this->where('id',"in",$ids)->field('name,url,id,ext')->order($order_str)->select(); foreach ($picinfo as $k => &$value) { // $value['url'] = config('uploadFile.url') . $value['url']; if (strpos($value['url'], '/Content/') !== false || strpos($value['url'], '/HousingPhotos/') !== false) { $value['url'] = config('uploadFile.old_cspg_url') . $value['url']; $value['thum1'] = config('uploadFile.old_cspg_url') . DS . $value['thum1']; } elseif (strpos($value['url'], 'http') !== false) { } else { $value['url'] = config('uploadFile.url') . $value['url']; $value['thum1'] = config('uploadFile.url') . DS . $value['thum1']; } } return $picinfo; } }