Sample.old.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\business\SampleBus;
  4. use app\api\model\Ry;
  5. use app\api\model\Ryjr as RyjrModel;
  6. use app\api\model\Subject;
  7. use app\api\model\Ry as RyModel;
  8. use OpenApi\Annotations as OA;
  9. use app\BaseController;
  10. use thans\jwt\facade\JWTAuth;
  11. use think\exception\ValidateException;
  12. use think\facade\Db;
  13. use think\facade\Filesystem;
  14. use think\facade\Request as re;
  15. use think\Request;
  16. use think\facade\Cache;
  17. use thans\jwt\JWT;
  18. use rsa\Rsa;
  19. class Sample extends BaseController{
  20. use ResponseJson;
  21. protected $request;
  22. protected $middleware = [
  23. 'jwt' => ['except' => ['uploadfile']],
  24. // 'check' => ['except' => ['login']]
  25. ];
  26. public function __construct(Request $request)
  27. {
  28. $this->request = $request;
  29. }
  30. /*
  31. * 上传文件
  32. */
  33. public function uploadfile(){
  34. $file = request() -> file('file'); //接收文件
  35. // dump($file);die();
  36. if ($file == null) { //判断文件是否为空
  37. return $this ->jsonResponse(-1,'未上传文件');
  38. }
  39. /*
  40. * 截取上传文件名后缀
  41. * 将文件名以.分割为数组
  42. * 用PHP end函数取数组最后一个
  43. * 即可得到上传文件后缀
  44. */
  45. $temp = explode(".", $_FILES["file"]["name"]);
  46. // dump($temp);die();
  47. $extension = end($temp);
  48. /*
  49. * 判断上传文件是否合法
  50. * 判断截取上传文件名是否为
  51. * jpeg,jpg,png其中之一
  52. */
  53. if(!in_array($extension, array("pdf","PDF","DOC","doc","docx","DOCX","PNG","png"))){
  54. return $this ->jsonResponse(-2,'上传文件不合法');
  55. }
  56. try {
  57. validate(['file' => ['fileSize:10*1024*1024']])->check(['file' => $file]);
  58. } catch (ValidateException $e) {
  59. $return['msg'] = $e->getMessage();
  60. }
  61. /*
  62. * 调用disk方法
  63. * 此时根目录为/public/uploads
  64. * 再把文件移动至uploads下的photo文件夹里
  65. * 文件名用md5
  66. */
  67. $saveName = Filesystem::disk('public') -> putFile('file', $file, 'md5');
  68. /*
  69. * 这里只返回从uploads开始的路径
  70. * 可以根据自己的需求返回需要的路径
  71. */
  72. $res = str_replace('\\', '/', 'http://syjc.aielab.net/uploads/'.$saveName);
  73. // $res=(str_replace('\\', '', '/uploads/' . $saveName));
  74. if($res){
  75. return $this->jsonSuccessData($res);
  76. }
  77. else{
  78. return $this->jsonData(-1,"上传文件失败");
  79. }
  80. }
  81. /**
  82. * @return \think\response\Json
  83. * @throws \think\db\exception\DataNotFoundException
  84. * @throws \think\db\exception\DbException
  85. * @throws \think\db\exception\ModelNotFoundException
  86. * 获取任务接口:param: id pageNum pageSize
  87. */
  88. public function getSampleList(){
  89. $data = $this->request->post();
  90. $id=$data['id'];
  91. $pageNum=$data['pageNum'];
  92. $pageSize=$data['pageSize'];
  93. $res['rows'] = Db::name("cyd")->where('rwid','=',$id)->field('ypmc,ypbh,cyjs,cycs,status,brand')->page($pageNum,$pageSize)->select();
  94. $res['total'] = Db::name("cyd")->count();
  95. return $this->jsonSuccessData($res);
  96. }
  97. //获取抽样单详情
  98. public function getSampleDetail(){
  99. $data = $this->request->post();
  100. $id=$data['id'];
  101. $res['rows'] = Db::name("cyd")->where('id','=',$id)
  102. ->field('ypmc,ypbh,cyjs,cycs,status,brand')
  103. ->leftJoin('t_','student_user.auth=student_teacher.auth and student_user.login_name=student_teacher.number and student_user.name=student_teacher.name')
  104. ->find();
  105. $res['total'] = Db::name("cyd")->count();
  106. return $this->jsonSuccessData($res);
  107. }
  108. /**、
  109. * @return \think\response\Json
  110. * 添加任务
  111. */
  112. public function addSample(){
  113. $data = $this->request->post();
  114. $resid=Db::name("cyd")->strict(false)->insertGetId($data);
  115. return $this->jsonSuccessData($resid);
  116. }
  117. }