Excel.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\merchant\store;
  12. use app\common\repositories\store\ExcelRepository;
  13. use crmeb\exceptions\UploadException;
  14. use think\App;
  15. use crmeb\basic\BaseController;
  16. class Excel extends BaseController
  17. {
  18. protected $repository;
  19. public function __construct(App $app, ExcelRepository $repository)
  20. {
  21. parent::__construct($app);
  22. $this->repository = $repository;
  23. }
  24. /**
  25. * TODO
  26. * @return mixed
  27. * @author Qinii
  28. * @day 2020-08-15
  29. */
  30. public function lst()
  31. {
  32. [$page, $limit] = $this->getPage();
  33. $where['type'] = $this->request->param('type','');
  34. $where['mer_id'] = $this->request->merId();
  35. $where['admin_id'] = $this->request->adminId();
  36. return app('json')->success($this->repository->getList($where,$page,$limit));
  37. }
  38. /**
  39. * TODO 下载文件
  40. * @param $id
  41. * @return \think\response\File
  42. * @author Qinii
  43. * @day 2020-07-30
  44. */
  45. public function download($id)
  46. {
  47. try{
  48. if($id == 'express'){
  49. $file['name'] = 'express';
  50. $path = app()->getRootPath().'extend/express.xlsx';
  51. if(!$file || !file_exists($path)) return app('json')->fail('文件不存在');
  52. return download($path,$file['name']);
  53. }
  54. $file = $this->repository->getWhere(['excel_id' => $id,'mer_id' => $this->request->merId()]);
  55. $path = app()->getRootPath().'public'.$file['path'];
  56. if(!$file || !file_exists($path)) return app('json')->fail('文件不存在');
  57. return download($path,$file['name']);
  58. }catch (UploadException $e){
  59. return app('json')->fail('下载失败');
  60. }
  61. }
  62. }