Selaa lähdekoodia

其他计件新增,删除

曹鹤洋 1 vuosi sitten
vanhempi
commit
bf9fc4da3f
1 muutettua tiedostoa jossa 83 lisäystä ja 23 poistoa
  1. 83 23
      application/api/controller/OtherCountDocument.php

+ 83 - 23
application/api/controller/OtherCountDocument.php

@@ -160,6 +160,62 @@ class OtherCountDocument extends Api
 
         $this->success('成功',$rows);
     }
+
+    /**
+     * 新增
+     * @ApiMethod (POST)
+     * @param string
+     */
+    public function add()
+    {
+        if(!$this->request->isPost()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+        $arr = [
+            'Sys_id',
+            'Sczl_bh1',
+            'sczl_Type',
+            'Sczl_rq',
+            'Sczl_gdbh',
+            'Sczl_gxmc',
+            'sczl_gxh',
+            'Sczl_cl',
+            'Sczl_dedh',
+            'Sczl_desc',
+        ];
+        $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');
+
+        //查询UniqId
+        $UniqId = db()->table('db_拉料计件')->max('UniqId');
+        $data['UniqId'] = $UniqId+1;
+
+        //开启事务
+        db()->startTrans();
+        try{
+            $sql = db()->table('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('成功');
+
+    }
+
     /**
      * 拉料计件产量维护修改
      * @ApiMethod POST
@@ -183,34 +239,38 @@ class OtherCountDocument extends Api
             $this->error('更新失败');
         }
     }
+
     /**
-     * 获取拉料计件产量维护其他信息
-     * @ApiMethod GET
-     * @params string Sczl_bh1
-     * @params string Sczl_gdbh
-     * @params string Sczl_dedh
-    */
-    public function getOtherInfo(){
-        if (Request::instance()->isGet() == false){
-            $this->error('非法请求');
-        }
-        $params = Request::instance()->param();
-        if (empty($params['Sczl_bh1']) && empty($params['Sczl_gdbh']) && empty($params['Sczl_dedh']) ){
-            $this->error('参数错误');
-        }
-        $data = [];
-        if (!empty($params['Sczl_bh1'])){
-            $data = Db::name('人事_基本资料')->where('员工编号',$params['Sczl_bh1'])->field('rtrim(员工姓名) as name')->find();
+     * 修改
+     * @ApiMethod (POST)
+     * @param string 'UniqId'
+     */
+    public function del()
+    {
+        if(!$this->request->isPost()){
+            $this->error('请求方式错误');
         }
-        if (!empty($params['Sczl_gdbh'])){
-            $data = Db::name('工单_基本资料')->where('Gd_gdbh',$params['Sczl_gdbh'])->field('rtrim(成品名称) as name')->find();
+        $req = $this->request->param();
+
+        if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
+            $this->error('参数错误','UniqId',100);
         }
-        if (!empty($params['Sczl_dedh'])){
-            $data = Db::name('dic_lzde')->where('sys_bh',$params['Sczl_dedh'])->field('rtrim(sys_mc) as name')->find();
+
+        //开启事务
+        db()->startTrans();
+        try{
+            $bool = db()->table('db_拉料计件')->where('UniqId',$req['UniqId'])->delete();
+            // 提交事务
+            db()->commit();
+        } catch (\Exception $e) {
+            // 回滚事务
+            db()->rollback();
+            $this->error($e->getMessage());
         }
-        $this->success('请求成功',$data);
-    }
 
+        if($bool===false) $this->error('失败');
 
+        $this->success('成功');
 
+    }
 }