Excel.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 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. * 获取列表数据
  27. *
  28. * @return \think\response\Json
  29. */
  30. public function lst()
  31. {
  32. // 获取当前管理员信息
  33. $admin = $this->request->adminInfo();
  34. if ($admin['level']) $where['admin_id'] = $this->request->adminId();
  35. // 获取分页参数
  36. [$page, $limit] = $this->getPage();
  37. $where['type'] = $this->request->param('type', '');
  38. $where['mer_id'] = $this->request->merId();
  39. $data = $this->repository->getList($where, $page, $limit);
  40. // 返回JSON格式的数据
  41. return app('json')->success($data);
  42. }
  43. /**
  44. * 下载文件
  45. * @param $id
  46. * @return \think\response\File
  47. * @author Qinii
  48. * @day 2020-07-30
  49. */
  50. public function downloadExpress($type)
  51. {
  52. try{
  53. switch ($type) {
  54. case 'cdkey':
  55. $file['name'] = 'cdkey_template';
  56. $path = app()->getRootPath().'extend/cdkey_template.xlsx';
  57. break;
  58. default:
  59. $file['name'] = 'express';
  60. $path = app()->getRootPath().'extend/express.xlsx';
  61. break;
  62. }
  63. if(!$file || !file_exists($path)) return app('json')->fail('文件不存在');
  64. return download($path,$file['name']);
  65. }catch (UploadException $e){
  66. return app('json')->fail('下载失败');
  67. }
  68. }
  69. /**
  70. * 所有类型
  71. * @return \think\response\Json
  72. * @author Qinii
  73. * @day 7/2/21
  74. */
  75. public function type()
  76. {
  77. $data = $this->repository->getTypeData();
  78. return app('json')->success($data);
  79. }
  80. }