Excel.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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 crmeb\services\ExcelService;
  15. use think\App;
  16. use crmeb\basic\BaseController;
  17. class Excel extends BaseController
  18. {
  19. protected $repository;
  20. public function __construct(App $app, ExcelRepository $repository)
  21. {
  22. parent::__construct($app);
  23. $this->repository = $repository;
  24. }
  25. /**
  26. * TODO
  27. * @return mixed
  28. * @author Qinii
  29. * @day 2020-08-15
  30. */
  31. public function lst()
  32. {
  33. $admin = $this->request->adminInfo();
  34. if($admin['level']) $where['admin_id'] = $this->request->adminId();
  35. [$page, $limit] = $this->getPage();
  36. $where['type'] = $this->request->param('type','');
  37. $where['mer_id'] = $this->request->merId();
  38. $data = $this->repository->getList($where,$page,$limit);
  39. return app('json')->success($data);
  40. }
  41. /**
  42. * TODO 下载文件
  43. * @param $id
  44. * @return \think\response\File
  45. * @author Qinii
  46. * @day 2020-07-30
  47. */
  48. public function download($id)
  49. {
  50. try{
  51. if($id == 'express'){
  52. $file['name'] = 'express';
  53. $path = app()->getRootPath().'extend/express.xlsx';
  54. if(!$file || !file_exists($path)) return app('json')->fail('文件不存在');
  55. return download($path,$file['name']);
  56. }
  57. $file = $this->repository->getWhere(['excel_id' => $id,'mer_id' => $this->request->merId()]);
  58. $path = app()->getRootPath().'public'.$file['path'];
  59. if(!$file || !file_exists($path)) return app('json')->fail('文件不存在');
  60. return download($path,$file['name']);
  61. }catch (UploadException $e){
  62. return app('json')->fail('下载失败');
  63. }
  64. }
  65. /**
  66. * TODO 所有类型
  67. * @return \think\response\Json
  68. * @author Qinii
  69. * @day 7/2/21
  70. */
  71. public function type()
  72. {
  73. $data = $this->repository->getTypeData();
  74. return app('json')->success($data);
  75. }
  76. }