| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- /**
- * @package merchant
- *
- * @author Qinii
- * @day 2020-08-15
- *
- *
- */
- namespace app\controller\merchant\store;
- use app\common\repositories\store\ExcelRepository;
- use crmeb\exceptions\UploadException;
- use think\App;
- use crmeb\basic\BaseController;
- class Excel extends BaseController
- {
- protected $repository;
- public function __construct(App $app, ExcelRepository $repository)
- {
- parent::__construct($app);
- $this->repository = $repository;
- }
- /**
- * TODO
- * @return mixed
- * @author Qinii
- * @day 2020-08-15
- */
- public function lst()
- {
- [$page, $limit] = $this->getPage();
- $where['type'] = $this->request->param('type','');
- $where['mer_id'] = $this->request->merId();
- $where['admin_id'] = $this->request->adminId();
- return app('json')->success($this->repository->getList($where,$page,$limit));
- }
- /**
- * TODO 下载文件
- * @param $id
- * @return \think\response\File
- * @author Qinii
- * @day 2020-07-30
- */
- public function download()
- {
- try{
- $id = $this->request->param('id');
- $file = $this->repository->getWhere(['excel_id' => $id,'mer_id' => $this->request->merId()]);
- $parsedUrl = parse_url($file['path']);
- if(isset($parsedUrl['host'])){
- //从oss下载
- echo "<script>window.location.href = '".$file['path']."';</script>";die;
- }
- $path = app()->getRootPath().'public'.$file['path'];
- if(!$file || !file_exists($path)){
- $path = $this->request->param('path','');
- if($path){
- $path = app()->getRootPath().'public'.$path;
- }
- if(!$path || !file_exists($path)){
- return app('json')->fail('文件不存在');
- }
- $file['name']= basename($path); // 使用basename函数获取图片的名称
- }
- return download($path,$file['name']);
- }catch (UploadException $e){
- return app('json')->fail('下载失败');
- }
- }
- }
|