Upload.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\Admin\controller;
  4. use app\BaseController;
  5. use think\Request;
  6. use think\facade\Filesystem;
  7. class Upload extends BaseController
  8. {
  9. /**
  10. * 显示资源列表
  11. *
  12. * @return \think\Response
  13. */
  14. public function index()
  15. {
  16. $post =$this->request->post();
  17. $token = isset($post['token']) ? trim($post['token']) : "";
  18. if($token==""){
  19. return error_show(101,'token不能为空');
  20. }
  21. $effetc = VerifyTokens($token);
  22. if(!empty($effetc) && $effetc['code']!=0){
  23. return error_show($effetc['code'],$effetc['message']);
  24. }
  25. $files = $this->request->file('image');
  26. $list="";
  27. if($files!=""){
  28. $list=UploadImg($files);
  29. }
  30. if(is_array($list)&&!empty($list)){
  31. return app_show(0, "上传成功!",$list);
  32. }else{
  33. return error_show(1005, "上传失败!".$list);
  34. }
  35. }
  36. /**
  37. * 显示创建资源表单页.
  38. *
  39. * @return \think\Response
  40. */
  41. public function create()
  42. {
  43. //
  44. }
  45. /**
  46. * 保存新建的资源
  47. *
  48. * @param \think\Request $request
  49. * @return \think\Response
  50. */
  51. public function save(Request $request)
  52. {
  53. //
  54. }
  55. /**
  56. * 显示指定的资源
  57. *
  58. * @param int $id
  59. * @return \think\Response
  60. */
  61. public function read($id)
  62. {
  63. //
  64. }
  65. /**
  66. * 显示编辑资源表单页.
  67. *
  68. * @param int $id
  69. * @return \think\Response
  70. */
  71. public function edit($id)
  72. {
  73. //
  74. }
  75. /**
  76. * 保存更新的资源
  77. *
  78. * @param \think\Request $request
  79. * @param int $id
  80. * @return \think\Response
  81. */
  82. public function QRDLoad()
  83. {
  84. $files = $this->request->file('file');
  85. try {
  86. validate([
  87. 'file' => [
  88. // 限制文件大小(单位b),这里限制为4M
  89. //fileSize' => 4 * 1024 * 1024,
  90. 'fileExt' => 'xlsx,xls'
  91. ]
  92. ],
  93. [
  94. //'file.fileSize' => '文件太大',
  95. 'file.fileExt' => '不支持的文件',
  96. ]
  97. )->check(['file' => $files]);
  98. $savename = Filesystem::disk('public')->putFileAs('topic/QRD', $files,"qrd.".$files->getOriginalExtension
  99. ());
  100. shell_exec("php /data/invoice/think qrdupload");
  101. return ['code' => 0, "msg" =>'确认单上传成功,数据在导入'];
  102. } catch (think\exception\ValidateException $e) {
  103. // echo $e->getMessage();
  104. return ['code' => 1003, "msg" => $e->getMessage()];
  105. }
  106. }
  107. /**
  108. * 删除指定资源
  109. *
  110. * @param int $id
  111. * @return \think\Response
  112. */
  113. public function CGDLoad()
  114. {
  115. $files = $this->request->file('file');
  116. try {
  117. validate([
  118. 'file' => [
  119. // 限制文件大小(单位b),这里限制为4M
  120. //fileSize' => 4 * 1024 * 1024,
  121. 'fileExt' => 'xlsx,xls'
  122. ]
  123. ],
  124. [
  125. //'file.fileSize' => '文件太大',
  126. 'file.fileExt' => '不支持的文件',
  127. ]
  128. )->check(['file' => $files]);
  129. $savename = Filesystem::disk('public')->putFileAs('topic/CGD', $files,"cgd.".$files->getOriginalExtension());
  130. shell_exec("php /data/invoice/think cgdupload");
  131. return ['code' => 0, "msg" =>'采购单上传成功,数据在导入'];
  132. } catch (think\exception\ValidateException $e) {
  133. // echo $e->getMessage();
  134. return ['code' => 1003, "msg" => $e->getMessage()];
  135. }
  136. }
  137. }