ZxcZxc123 преди 1 година
родител
ревизия
b679d024de
променени са 4 файла, в които са добавени 149 реда и са изтрити 57 реда
  1. 1 20
      app/model/api/CourseModel.php
  2. 23 0
      app/system/controller/CourseController.php
  3. 57 23
      app/system/controller/Upload.php
  4. 68 14
      library/utils/Qiniu.php

+ 1 - 20
app/model/api/CourseModel.php

@@ -23,26 +23,7 @@ class CourseModel extends Model
     }
 
 
-//    /**
-//     * 获取所有课程
-//     *
-//     * @param string $keyword 模糊查询关键字
-//     * @return mixed
-//     */
-//    public function getCourse($keyword = '')
-//    {
-//        $query = Db::table($this->table)
-//            ->order('course_create_time', 'desc')
-//            ->field('course_id, course_topic, course_speaker, course_speaker_intro, course_price, course_play_count, course_create_time, course_audit, course_cover');
-//
-//        if (!empty($keyword)) {
-//            $query->where('course_topic', 'like', "%{$keyword}%");
-//        }
-//
-//        $courseList = $query->select();
-//
-//        return $courseList;
-//    }
+
 
 
     /**

+ 23 - 0
app/system/controller/CourseController.php

@@ -87,6 +87,29 @@ class CourseController
 
 
 
+    /**
+     * 获取课程详情并编辑课程
+     * @param Request $request
+     * @return mixed
+     */
+    public function editCourse(Request $request)
+    {
+        $course_id = $request->param('course_id');
+        $course = $request->param('course/a');
+
+        $courseModel = new CourseModel();
+        $result = $courseModel->where('course_id', $course_id)->update($course);
+
+        if ($result !== false) {
+            $course = $courseModel->find($course_id);
+            return app('json')->success($course->toArray());
+        }
+        return app('json')->fail("编辑课程失败");
+    }
+
+
+
+
     /**
      * 添加课程
      */

+ 57 - 23
app/system/controller/Upload.php

@@ -20,41 +20,75 @@ use think\Image;
 class Upload extends AuthController{
 
 
+//    /**
+//     * 七牛上传
+//     * @param Request $request
+//     */
+//    public function index(Request $request){
+//        $file = $request->file('file');
+//        if (empty($file)) {
+//            return app('json')->fail("未上传文件");
+//        }
+//        $file = $request->file('file');
+//        if (empty($file)) {
+//            return app('json')->fail("未上传文件");
+//        }
+//        $code = $request->post("code","");
+//        $codes = $request->post("codes","");
+//        $rootTmp    = config('filesystem.disks.local.root') . '/' . \think\facade\Filesystem::putFile('tmp', $file);
+//        $image_size = @getimagesize($rootTmp);
+//        if ($image_size[0] > 1000) {
+//            $imgS = Image::open($rootTmp);
+//            $imgS->thumb(1000, $image_size[1]);
+//            $imgS->save($rootTmp);
+//        } else {
+//            if ($image_size[1] > 1000) {
+//                $imgS = Image::open($rootTmp);
+//                $imgS->thumb($image_size[0], 1000);
+//                $imgS->save($rootTmp);
+//            }
+//        }
+//        $qiniu   = new  Qiniu;
+//        $img_url = $qiniu->updateFile('sysimg', $rootTmp, $rootTmp);
+//        if (empty($img_url['url'])) {
+//            return app('json')->fail($qiniu->getError());
+//        }
+//        @unlink($rootTmp);
+//        return app('json')->success(['img' => $img_url['url']]);
+//    }
+
+
     /**
      * 七牛上传
      * @param Request $request
      */
-    public function index(Request $request){
+    public function index(Request $request)
+    {
         $file = $request->file('file');
         if (empty($file)) {
             return app('json')->fail("未上传文件");
         }
-        $file = $request->file('file');
-        if (empty($file)) {
-            return app('json')->fail("未上传文件");
+
+        $code = $request->post("code", "");
+        $codes = $request->post("codes", "");
+
+        // 限制上传文件的后缀名为 mp3 和 mp4
+        $ext = ['mp3', 'mp4'];
+        $validate = validate(['file' => ['fileSize:104857600', 'fileExt:' . implode(',', $ext)]]);
+        if (!$validate->check(['file' => $file])) {
+            return app('json')->fail($validate->getError());
         }
-        $code = $request->post("code","");
-        $codes = $request->post("codes","");
-        $rootTmp    = config('filesystem.disks.local.root') . '/' . \think\facade\Filesystem::putFile('tmp', $file);
-        $image_size = @getimagesize($rootTmp);
-        if ($image_size[0] > 1000) {
-            $imgS = Image::open($rootTmp);
-            $imgS->thumb(1000, $image_size[1]);
-            $imgS->save($rootTmp);
-        } else {
-            if ($image_size[1] > 1000) {
-                $imgS = Image::open($rootTmp);
-                $imgS->thumb($image_size[0], 1000);
-                $imgS->save($rootTmp);
-            }
-        }
-        $qiniu   = new  Qiniu;
-        $img_url = $qiniu->updateFile('sysimg', $rootTmp, $rootTmp);
-        if (empty($img_url['url'])) {
+
+        $rootTmp = config('filesystem.disks.local.root') . '/' . \think\facade\Filesystem::putFile('tmp', $file);
+
+        $qiniu = new Qiniu;
+        $file_url = $qiniu->updateFile('sysfile', $rootTmp, $rootTmp);
+        if (empty($file_url['url'])) {
             return app('json')->fail($qiniu->getError());
         }
         @unlink($rootTmp);
-        return app('json')->success(['img' => $img_url['url']]);
+
+        return app('json')->success(['file' => $file_url['url']]);
     }
     /**
      * 本地上传

+ 68 - 14
library/utils/Qiniu.php

@@ -197,6 +197,63 @@ class Qiniu {
         return $token;
     }
 
+//    /**
+//     * 上传文件
+//     * @param type $path 目录
+//     * @param type $name 上传文件名称【后缀记录】
+//     * @param type $files 上传实际文件
+//     * @param type $ext 限制后缀名
+//     * @return boolean
+//     */
+//    public function updateFile($path,$name,$files,$ext = array('jpg','png','gif','webp')) {
+//        if (empty($files)) {
+//            $this->error = '没有上传的文件!';
+//            return false;
+//        }
+//
+//        $file['ext']    = strtolower(pathinfo($name, PATHINFO_EXTENSION));
+//
+//        if($file['ext'] == 'jpeg'){
+//            $file['ext'] = 'jpg';
+//        }
+//
+//
+//        if(!in_array($file['ext'], $ext)){
+//            $this->error = '上传格式发生错误!';
+//            return false;
+//        }
+//
+//        if(!file_exists($files)){
+//            $this->error = '上传文件不存在!';
+//            return false;
+//        }
+//
+//
+//
+//        $object = $this->mk_str().'.'.$file['ext'];
+//
+//        $os_path = $path.'/'.date('Y').'/'.date('m').'/'.date('d').'/';
+//
+//        $token = $this->qiniu->uploadToken($this->config['bucket']);
+//
+//        $uploadMgr = new \Qiniu\Storage\UploadManager();
+//
+//        list($ret, $err) = $uploadMgr->putFile($token, $os_path.$object, $files);
+//
+//
+//        $r['status'] = 0;
+//        if ($err !== null) {
+//            $r['status'] = 0;
+//            $this->error = $err;
+//        } else{
+//            $r['status'] = 1;
+//            $r['key'] = $ret['key'];
+//            $r['url'] = $this->config['endpoint'].$ret['key'];
+//        }
+//        return $r;
+//    }
+
+
     /**
      * 上传文件
      * @param type $path 目录
@@ -205,50 +262,47 @@ class Qiniu {
      * @param type $ext 限制后缀名
      * @return boolean
      */
-    public function updateFile($path,$name,$files,$ext = array('jpg','png','gif','webp')) {
+    public function updateFile($path, $name, $files, $ext = array('jpg', 'png', 'gif', 'webp', 'mp3', 'mp4'))
+    {
         if (empty($files)) {
             $this->error = '没有上传的文件!';
             return false;
         }
 
-        $file['ext']    = strtolower(pathinfo($name, PATHINFO_EXTENSION));
+        $file['ext'] = strtolower(pathinfo($name, PATHINFO_EXTENSION));
 
-        if($file['ext'] == 'jpeg'){
+        if ($file['ext'] == 'jpeg') {
             $file['ext'] = 'jpg';
         }
 
-
-        if(!in_array($file['ext'], $ext)){
+        if (!in_array($file['ext'], $ext)) {
             $this->error = '上传格式发生错误!';
             return false;
         }
 
-        if(!file_exists($files)){
+        if (!file_exists($files)) {
             $this->error = '上传文件不存在!';
             return false;
         }
 
+        $object = $this->mk_str() . '.' . $file['ext'];
 
-
-        $object = $this->mk_str().'.'.$file['ext'];
-
-        $os_path = $path.'/'.date('Y').'/'.date('m').'/'.date('d').'/';
+        $os_path = $path . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/';
 
         $token = $this->qiniu->uploadToken($this->config['bucket']);
 
         $uploadMgr = new \Qiniu\Storage\UploadManager();
 
-        list($ret, $err) = $uploadMgr->putFile($token, $os_path.$object, $files);
-
+        list($ret, $err) = $uploadMgr->putFile($token, $os_path . $object, $files);
 
         $r['status'] = 0;
         if ($err !== null) {
             $r['status'] = 0;
             $this->error = $err;
-        } else{
+        } else {
             $r['status'] = 1;
             $r['key'] = $ret['key'];
-            $r['url'] = $this->config['endpoint'].$ret['key'];
+            $r['url'] = $this->config['endpoint'] . $ret['key'];
         }
         return $r;
     }