request->isAjax) { if (\Yii::$app->request->isGet) { $params = Yii::$app->request->get(); $params['where'] = [['mall_id'=>$this->mall_id,'store_id' => 0, 'mch_id' => 0],['<>','status',StatusEnum::DELETE]]; if(!empty($params['name'])){ $params['where'][] = ['like','name',$params['name']]; } if(!empty($params['datetime'][0])){ $params['where'][] = ['>=','created_at',strtotime($params['datetime'][0])]; } if(!empty($params['datetime'][1])){ $params['where'][] = ['<=','created_at',strtotime($params['datetime'][1])]; } $params['order'] = 'id desc'; $list = Download::listPage($params); $list['status_list']=DownloadEnum::getStatusMap(); $list['type_list']=DownloadEnum::getTypeMap(); return $this->success('操作成功', $list); } } return $this->render($this->action->id); } /** * 删除 * @Author: hua * @DateTime: 2021/10/11 16:05 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|void */ public function actionDel() { $request = Yii::$app->request; if ($request->isAjax) { if ($request->isGet) { $params = Yii::$app->request->get(); $params['mall_id'] = $this->mall_id; $params['status'] = StatusEnum::DELETE; $res = Download::setData($params); if ($res === false) return $this->error(Download::getStaticError()); return $this->success('操作成功'); } } } /** * 下载 * @Author: hua * @DateTime: 2021/10/13 14:53 * @Copyright: copyright (c) 2021 广东七件事集团 */ public function actionDown(){ try{ $download_id = Yii::$app->request->get('download_id'); ob_start(); $download = Download::findOne($download_id); if (empty($download)) { $url = \Yii::$app->urlManager->createAbsoluteUrl('mall/download/index'); return $this->redirect($url, 301); } $filename= $download->name; $path_info = pathinfo($download->url); $size=readfile($download->url); header( "Content-type: application/octet-stream "); header( "Accept-Ranges: bytes "); header( "Content-Disposition: attachment; filename= {$filename}.".$path_info['extension']); header( "Accept-Length: " .$size); }catch (\Exception $e){ $url = \Yii::$app->urlManager->createAbsoluteUrl('mall/download/index'); return $this->redirect($url, 301); } } /** * @name: * @msg: 重新生成下载文件 * @param {*} * @return {*} */ public function actionRegenerate() { if (!\Yii::$app->request->isGet) { return $this->error('请求方式错误'); } $download_id = Yii::$app->request->get('download_id'); $res = CsvExportHelper::regenerateDownloadFile($download_id); if ($res) { return $this->success('操作成功'); } else { return $this->error('操作失败'); } } /** * @name: * @msg: 批量下载导出文件 * @param {*} * @return {*} */ public function actionMultipleDownload() { if (!\Yii::$app->request->isGet) { return $this->error('请求方式错误'); } $download_id = \Yii::$app->request->get('download_id'); if (empty($download_id)) { return $this->error('参数错误'); } $download_ids = explode(',', $download_id); $downloads = Download::findAll(['id' => $download_ids]); if (count($download_ids) != count($downloads)) { return $this->error('选择的文件中有不能下载的文件,请重新选择'); } if (empty($downloads)) { return $this->error('选择的文件不存在,请重新选择'); } $files = []; foreach ($downloads as $down) { $files[] = trim($down->url, '/'); } // dd($files); $filename = FileHelper::packFiles($files, '导出文件'); // dd($filename); ob_start(); $path_info = pathinfo($filename); $size=readfile($filename); header( "Content-type: application/octet-stream "); header( "Accept-Ranges: bytes "); header( "Content-Disposition: attachment; filename= {$path_info['filename']}." . $path_info['extension']); header( "Accept-Length: " .$size); return $this->success('操作成功'); } }