wugg 3 years ago
parent
commit
a30482d214
3 changed files with 140 additions and 0 deletions
  1. 133 0
      app/admin/controller/Good.php
  2. 1 0
      app/admin/controller/Menu.php
  3. 6 0
      app/admin/route/app.php

+ 133 - 0
app/admin/controller/Good.php

@@ -0,0 +1,133 @@
+<?php
+
+
+namespace app\admin\controller;
+
+use think\App;
+use think\facade\Db;
+class Good extends \app\BaseController
+{
+        public $post="";
+        public function __construct(App $app)
+        {
+            parent::__construct($app);
+            $this->post = $this->request->post();
+//            $token = isset($this->post['token']) ? trim($this->post['token']) : "";
+//            if($token==""){
+//                return error_show(101,'token不能为空');
+//            }
+//            $effetc = VerifyTokens($token);
+//            if(!empty($effetc) && $effetc['code']!=0){
+//                return error_show($effetc['code'],$effetc['message']);
+//            }
+        }
+
+        public function list(){
+            $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
+            $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
+            $condtion=["a.is_del"=>0,"b.is_del"=>0];
+            $wsmcode =isset($this->post['wsmcode']) &&$this->post['wsmcode'] !=="" ? trim($this->post['wsmcode']):"";
+            if($wsmcode!=""){
+                $typecode = Db::name("good_stock")->where(["is_del"=>0,"wsm_code"=>$wsmcode])->column("good_type_code");
+                if(empty($typecode)){
+                    return error_show(1004,"未找到供应商有关的商品信息");
+                }
+                $condtion["type_code"] = $typecode;
+            }
+            $good_code =isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
+            if($good_code!=""){
+                $condtion['type_code'] = $good_code;
+            }
+            $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
+            if($supplierNo!=""){
+                $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find();
+                if(empty($supplier)){
+                    return error_show(1004,"未找到供应商信息");
+                }
+                $typecode = Db::name("good_stock")->alias("a")->join("warehouse_info b","a.wsm_code=b.wsm_code","left")->where(["a.is_del"=>0,
+                    "b.is_del"=>0,"b.supplierNo"=>$supplierNo])->column("a.good_type_code");
+                if(empty($typecode)){
+                    return error_show(1004,"未找到供应商有关的商品信息");
+                }
+                $condtion["type_code"] = $typecode;
+            }
+
+            $count = Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")->where
+            ($condtion)->count();
+            $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
+            $list = Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")->where
+            ($condtion)
+                ->field("b.id,a.good_code,a.good_name,a.good_desc,a.brand,a.original_price,a.status,b.type_code,b.attribute,b.status as bstatus")->page($page,$size)->select();
+            $data=[];
+            foreach ($list as $key=>$value){
+                $stock = Db::name("good_stock")->where(["good_type_code"=>$value['type_code'],"is_del"=>0])->sum("usable_stock");
+                $value['usable_stock']=$stock;
+                $data[]=$value;
+            }
+            return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
+        }
+
+        public function SetWarn(){
+            $id = isset($this->post['id']) &&$this->post['id'] !=="" ? intval($this->post['id']):"";
+           if($id===""){
+               return error_show(1005,"参数id 不能为空");
+           }
+           $good= Db::name("good_stock")->where(["id"=>$id,"is_del"=>0])->find();
+           if(empty($good)){
+               return error_show(1005,"未找到数据");
+           }
+           $warn_stock = isset($this->post['warn_stock']) &&$this->post['warn_stock'] !=="" ? intval($this->post['warn_stock']):"";
+           if($warn_stock===""){
+               return error_show(1005,"参数warn_stock 不能为空");
+           }
+           $good['warn_stock'] = $warn_stock;
+           $good['updatetime'] = date("Y-m-d H:i:s");
+            $up= Db::name("good_stock")->save($good);
+            return $up ? app_show(0,"预警库存更新成功"): error_show(1005,"预警库存更新失败");
+        }
+
+    public function SetStatus(){
+        $id = isset($this->post['id']) &&$this->post['id'] !=="" ? intval($this->post['id']):"";
+        if($id===""){
+            return error_show(1005,"参数id 不能为空");
+        }
+        $good= Db::name("good_type")->where(["id"=>$id,"is_del"=>0])->find();
+        if(empty($good)){
+            return error_show(1005,"未找到数据");
+        }
+        $good['status'] = $good['status']==1?0 :1;
+        $good['updatetime'] = date("Y-m-d H:i:s");
+        $msg = $good['status']==1?"下架" :"上架";
+        $up= Db::name("good_type")->save($good);
+        return $up ? app_show(0,"商品{$msg}成功"): error_show(1005,"商品{$msg}失败");
+    }
+
+    public function GetStock(){
+        $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
+        if($type_code===""){
+            return error_show(1005,"参数type_code 不能为空");
+        }
+        $good= Db::name("good_type")->where(["type_code"=>$type_code,"is_del"=>0])->find();
+        if(empty($good)){
+            return error_show(1005,"未找到数据");
+        }
+       $list = Db::name("good_stock")->alias("a")->join("warehouse_info b","a.wsm_code=b.wsm_code","left")->join("supplier c","b.supplierNo=c.code","left")
+           ->where(["a.is_del"=>0,"good_type_code"=>$type_code])->field("a.id,b.name,c.code,c.name,a.wait_in_stock,a.wait_out_stock,a.usable_stock,a.intra_stock,a.total_stock,a.status,a.warn_stock")->select();
+     return app_show(0,"获取成功",$list);
+    }
+
+    public function Stat(){
+        $condition =["is_del"=>0];
+        $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
+        if($wsm_code!=""){
+          $condition["wsm_code"] = $wsm_code;
+        }
+        $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
+        if($type_code!=""){
+            $condition["good_type_code"] = $type_code;
+        }
+        $statlist = Db::name("good_stock")->where($condition)->field("sum(wait_in_stock) as wait_in_stock,sum(wait_out_stock) as wait_out_stock ,sum(usable_stock) as usable_stock,sum(intra_stock) as intra_stock,sum(total_stock) as total_stock,sum(warn_stock) as warn_stock")->find();
+        return app_show(0,"获取成功",$statlist);
+    }
+
+}

+ 1 - 0
app/admin/controller/Menu.php

@@ -67,6 +67,7 @@ class Menu extends BaseController
             $temp['menu_url']=$value['cmenu_url'];
             $temp['status']=$value['cstatus'];
             $temp['is_private']=$value['cprivate'];
+            $temp['is_display']=$value['cis_display'];
             $list[$value["id"]]['child'][$value['cid']]=$temp;
             $act[$value['id']][$value['cid']][]=$value['acode'];
             $list[$value["id"]]['child'][$value['cid']]['action']= $act[$value['id']][$value['cid']];

+ 6 - 0
app/admin/route/app.php

@@ -97,3 +97,9 @@ Route::rule("province","admin/Addr/province");
 Route::rule("city","admin/Addr/city");
 Route::rule("area","admin/Addr/area");
 
+Route::rule("goodlist","admin/Good/list");
+Route::rule("goodwarn","admin/Good/SetWarn");
+Route::rule("goodstatus","admin/Good/SetStatus");
+Route::rule("goodstat","admin/Good/Stat");
+Route::rule("goodstock","admin/Good/GetStock");
+