Browse Source

包装计件单据获取定额代号

曹鹤洋 1 year ago
parent
commit
255b636d3d
1 changed files with 67 additions and 11 deletions
  1. 67 11
      application/api/controller/PackagingCountDocument.php

+ 67 - 11
application/api/controller/PackagingCountDocument.php

@@ -33,18 +33,26 @@ class PackagingCountDocument extends Api
         if(!$this->request->isGet()){
             $this->error('请求方式错误');
         }
-        $rows = db()->table('db_包装计件')->cache(true,300)
-            ->field('LEFT(sys_rq, 10) as date, COUNT(*) as counts')
-            ->group('date')
-            ->order('UniqId desc')
-            ->limit(30)
-            ->select();
+        //判断是否存在缓存
+        if (!cache('PackagingCountDocument-getTab')){
+            $rows = db()->table('db_包装计件')
+                ->field('LEFT(sys_rq, 10) as date, COUNT(*) as counts')
+                ->group('date')
+                ->order('UniqId desc')
+                ->limit(30)
+                ->select();
 
-        $arr = db()->table('db_包装计件')->cache(true,300)
-            ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(*) as count')
-            ->where('sys_rq','>=',$rows[count($rows)-1]['date'])
-            ->group('date, sys_id')
-            ->select();
+            $arr = db()->table('db_包装计件')
+                ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(*) as count')
+                ->where('sys_rq','>=',$rows[count($rows)-1]['date'])
+                ->group('date, sys_id')
+                ->select();
+            //设置缓存
+            cache('PackagingCountDocument-getTab',['rows'=>$rows,'arr'=>$arr],3600);
+        }else{
+            $rows = cache('PackagingCountDocument-getTab')['rows'];
+            $arr = cache('PackagingCountDocument-getTab')['arr'];
+        }
 
         foreach($rows as $key=>$value){
             $rows[$key]['sys'] = [];
@@ -293,7 +301,52 @@ class PackagingCountDocument extends Api
         $this->success('成功',$rs);
     }
 
+/**
+     * 查询定额代号
+     * @ApiMethod (GET)
+     */
+    public function getDedh()
+    {
+        //get请求
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+
+        $row = db('dic_lzde')
+            ->field('Key_, sys_bh, rtrim(sys_mc) as sys_mc')
+            ->where('sys_mc','包装')
+            ->find();
+        $rows = db('dic_lzde')
+            ->field('Key_, sys_bh, rtrim(sys_mc) as sys_mc')
+            ->where('Parent',$row['Key_'])
+            ->order('sys_bh asc')
+            ->select();
+        foreach ($rows as $key=>$value){
+            $bool = db('dic_lzde')
+                ->field('Key_,sys_bh, rtrim(sys_mc) as sys_mc')
+                ->where('Parent',$value['Key_'])
+                ->order('sys_bh asc')
+                ->select();
+            if ($bool){
+                foreach ($bool as $k=>$v){
+                    $bool1 = db('dic_lzde')
+                        ->field('sys_bh, rtrim(sys_mc) as sys_mc')
+                        ->where('Parent',$v['Key_'])
+                        ->order('sys_bh asc')
+                        ->select();
+
+                    if ($bool1){
+                        $bool[$k]['bh_mc'] = $bool1;
+                    }
+                }
+                $rows[$key]['bh_mc'] = $bool;
+            }
+        }
+        $row['bh_mc'] = $rows;
 
+        $this->success('成功',$row);
+    }
+    
     /**
      * 新增
      * @ApiMethod (POST)
@@ -338,6 +391,7 @@ class PackagingCountDocument extends Api
             $bool = db()->query($sql);
             // 提交事务
             db()->commit();
+            cache('PackagingCountDocument-getTab',null);
         } catch (\Exception $e) {
             // 回滚事务
             db()->rollback();
@@ -396,6 +450,7 @@ class PackagingCountDocument extends Api
             $bool = db()->query($sql);
             // 提交事务
             db()->commit();
+            cache('PackagingCountDocument-getTab',null);
         } catch (\Exception $e) {
             // 回滚事务
             db()->rollback();
@@ -429,6 +484,7 @@ class PackagingCountDocument extends Api
             $bool = db()->table('db_包装计件')->where('UniqId',$req['UniqId'])->delete();
             // 提交事务
             db()->commit();
+            cache('PackagingCountDocument-getTab',null);
         } catch (\Exception $e) {
             // 回滚事务
             db()->rollback();