Przeglądaj źródła

图片上传和文件上传

qiuenguang 1 rok temu
rodzic
commit
3a9b1e0277

+ 1 - 1
application/api/controller/Common.php

@@ -17,7 +17,7 @@ use think\Hook;
  */
 class Common extends Api
 {
-    protected $noNeedLogin = ['init', 'captcha'];
+    protected $noNeedLogin = '*';
     protected $noNeedRight = '*';
 
     public function _initialize()

+ 60 - 39
application/api/controller/WorkOrder.php

@@ -6,6 +6,7 @@ namespace app\api\controller;
 use app\common\controller\Api;
 use Monolog\Handler\IFTTTHandler;
 use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
+use think\Config;
 use think\Db;
 use think\Request;
 use PhpOffice\PhpSpreadsheet\IOFactory;
@@ -18,6 +19,21 @@ class WorkOrder extends Api
     protected $noNeedLogin = ['*'];
     protected $noNeedRight = ['*'];
 
+    public function _initialize()
+    {
+
+        if (isset($_SERVER['HTTP_ORIGIN'])) {
+            header('Access-Control-Expose-Headers: __token__');//跨域让客户端获取到
+        }
+        //跨域检测
+        check_cors_request();
+
+        if (!isset($_COOKIE['PHPSESSID'])) {
+            Config::set('session.id', $this->request->server("HTTP_SID"));
+        }
+        parent::_initialize();
+    }
+
     /**
      * 工单资料菜单列表
      *
@@ -1678,45 +1694,44 @@ class WorkOrder extends Api
     /**
      * 产品附件新增
      */
-//    public function gdAnnexAdd(){
-//        if(!$this->request->isPost()){
-//            $this->error('请求方式错误');
-//        }
-//        $req = $this->request->param();
-//
-//        $arr = [
-//            'sys_id',
-//            '附件备注',
-//            '附件内容',
-//            '附件类型',
-//            '关联编号'
-//            ];
-//        $data = [];
-//        foreach ($arr as $key => $value){
-//            if (!isset($req[$value])){
-//                $this->error('参数错误',$value,$key+1);
-//            }
-//            $data[$value] = $req[$value];
-//        }
-//        $data['sys_rq'] = date('Y-m-d H:i:s');
-//
-//        //开启事务
-//        db()->startTrans();
-//        try{
-//            $sql = db('工单_相关附件')->fetchSql(true)->insert($data);
-//            $bool = db()->query($sql);
-//            // 提交事务
-//            db()->commit();
-//        } catch (\Exception $e) {
-//            // 回滚事务
-//            db()->rollback();
-//            $this->error($e->getMessage());
-//        }
-//
-//        if($bool===false) $this->error('失败');
-//
-//        $this->success('成功');
-//    }
+    public function gdAnnexAdd(){
+        if(!$this->request->isPost()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+        $arr = [
+            'sys_id',
+            '附件备注',
+            '附件内容',
+            '附件类型',
+            '关联编号'
+            ];
+        $data = [];
+        foreach ($arr as $key => $value){
+            if (!isset($req[$value])){
+                $this->error('参数错误',$value,$key+1);
+            }
+            $data[$value] = $req[$value];
+        }
+        $data['sys_rq'] = date('Y-m-d H:i:s');
+
+        //开启事务
+        db()->startTrans();
+        try{
+            $sql = db('工单_相关附件')->fetchSql(true)->insert($data);
+            $bool = db()->query($sql);
+            // 提交事务
+            db()->commit();
+        } catch (\Exception $e) {
+            // 回滚事务
+            db()->rollback();
+            $this->error($e->getMessage());
+        }
+
+        if($bool===false) $this->error('失败');
+
+        $this->success('成功');
+    }
     
     /**
      * 产品附件修改
@@ -2340,4 +2355,10 @@ class WorkOrder extends Api
             $this->success('修改成功');
         }
     }
+
+    //图片上传
+    public function photoAdd()
+    {
+
+    }
 }