Excel.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace app\controller\merchant\store;
  3. use app\common\repositories\store\ExcelRepository;
  4. use ln\exceptions\UploadException;
  5. use ln\services\ExcelService;
  6. use think\App;
  7. use ln\basic\BaseController;
  8. class Excel extends BaseController
  9. {
  10. protected $repository;
  11. public function __construct(App $app, ExcelRepository $repository)
  12. {
  13. parent::__construct($app);
  14. $this->repository = $repository;
  15. }
  16. /**
  17. * TODO
  18. * @return mixed
  19. * @author Qinii
  20. * @day 2020-08-15
  21. */
  22. public function lst()
  23. {
  24. $admin = $this->request->adminInfo();
  25. if($admin['level']) $where['admin_id'] = $this->request->adminId();
  26. [$page, $limit] = $this->getPage();
  27. $where['type'] = $this->request->param('type','');
  28. $where['mer_id'] = $this->request->merId();
  29. return app('json')->success($this->repository->getList($where,$page,$limit));
  30. }
  31. /**
  32. * TODO 下载文件
  33. * @param $id
  34. * @return \think\response\File
  35. * @author Qinii
  36. * @day 2020-07-30
  37. */
  38. public function download($id)
  39. {
  40. try{
  41. if($id == 'express'){
  42. $file['name'] = 'express';
  43. $path = app()->getRootPath().'extend/express.xlsx';
  44. if(!$file || !file_exists($path)) return app('json')->fail('文件不存在');
  45. return download($path,$file['name']);
  46. }
  47. $file = $this->repository->getWhere(['excel_id' => $id,'mer_id' => $this->request->merId()]);
  48. $path = app()->getRootPath().'public'.$file['path'];
  49. if(!$file || !file_exists($path)) return app('json')->fail('文件不存在');
  50. return download($path,$file['name']);
  51. }catch (UploadException $e){
  52. return app('json')->fail('下载失败');
  53. }
  54. }
  55. /**
  56. * TODO 所有类型
  57. * @return \think\response\Json
  58. * @author Qinii
  59. * @day 7/2/21
  60. */
  61. public function type()
  62. {
  63. $data = [
  64. ['key' => 'order', 'value' => '订单列表'],
  65. ['key' => 'delivery', 'value' => '待发货订单'],
  66. ['key' => 'searchLog', 'value' => '搜索记录'],
  67. ['key' => 'financial', 'value' => '流水记录'],
  68. ['key' => 'refundOrder', 'value' => '退款单'],
  69. ['key' => 'integralLog', 'value' => '积分日志'],
  70. ['key' => 'importDelivery', 'value' => '发货导入'],
  71. ['key' => 'exportFinancial', 'value' => '日/月账单'],
  72. ];
  73. // $data['data'] = [
  74. // 'order' => '订单列表',
  75. // 'delivery' => '待发货订单',
  76. // 'searchLog' => '搜索记录',
  77. // 'financial' => '流水记录',
  78. // 'refundOrder' => '退款单',
  79. // 'integralLog' => '积分日志',
  80. // 'importDelivery' => '发货导入',
  81. // 'exportFinancial' => '日/月账单',
  82. // ];
  83. return app('json')->success($data);
  84. }
  85. }