Browse Source

aa
git commit -a -m aa

wugg 2 năm trước cách đây
mục cha
commit
ab34475141
60 tập tin đã thay đổi với 1900 bổ sung1032 xóa
  1. 5 2
      app/admin/controller/Activity.php
  2. 79 31
      app/admin/controller/After.php
  3. 70 53
      app/admin/controller/Allot.php
  4. 1 0
      app/admin/controller/Attr.php
  5. 2 1
      app/admin/controller/Base.php
  6. 1 0
      app/admin/controller/Brand.php
  7. 1 0
      app/admin/controller/Business.php
  8. 1 0
      app/admin/controller/Cat.php
  9. 1 0
      app/admin/controller/Catdesc.php
  10. 50 11
      app/admin/controller/Check.php
  11. 1 0
      app/admin/controller/Conf.php
  12. 173 250
      app/admin/controller/Consult.php
  13. 1 0
      app/admin/controller/Customar.php
  14. 1 0
      app/admin/controller/Customer.php
  15. 2 0
      app/admin/controller/Departuser.php
  16. 1 0
      app/admin/controller/Exclusive.php
  17. 1 0
      app/admin/controller/Express.php
  18. 1 0
      app/admin/controller/Gold.php
  19. 1 0
      app/admin/controller/Goldprice.php
  20. 396 260
      app/admin/controller/Good.php
  21. 9 4
      app/admin/controller/Goodup.php
  22. 1 0
      app/admin/controller/Group.php
  23. 1 0
      app/admin/controller/Keepbrand.php
  24. 2 0
      app/admin/controller/Listcustomer.php
  25. 4 3
      app/admin/controller/Log.php
  26. 1 0
      app/admin/controller/Menu.php
  27. 2 0
      app/admin/controller/Newfill.php
  28. 1 0
      app/admin/controller/Orderback.php
  29. 1 0
      app/admin/controller/Orderuse.php
  30. 1 0
      app/admin/controller/Platform.php
  31. 2 0
      app/admin/controller/Process.php
  32. 12 26
      app/admin/controller/Project.php
  33. 1 0
      app/admin/controller/Proorder.php
  34. 76 50
      app/admin/controller/Purch.php
  35. 2 1
      app/admin/controller/Purchback.php
  36. 237 51
      app/admin/controller/Purchin.php
  37. 19 5
      app/admin/controller/Reorder.php
  38. 39 37
      app/admin/controller/Resign.php
  39. 2 0
      app/admin/controller/Resigninfo.php
  40. 2 0
      app/admin/controller/Result.php
  41. 3 1
      app/admin/controller/Role.php
  42. 327 210
      app/admin/controller/Sale.php
  43. 3 3
      app/admin/controller/Salezx.php
  44. 2 0
      app/admin/controller/Share.php
  45. 1 12
      app/admin/controller/Specs.php
  46. 1 0
      app/admin/controller/Specvalue.php
  47. 1 0
      app/admin/controller/Suppler.php
  48. 1 0
      app/admin/controller/System.php
  49. 1 0
      app/admin/controller/Title.php
  50. 1 0
      app/admin/controller/Unit.php
  51. 2 0
      app/admin/controller/User.php
  52. 327 0
      app/admin/controller/Version.php
  53. 10 1
      app/admin/controller/WareHouse.php
  54. 1 3
      app/admin/model/ActionLog.php
  55. 1 0
      app/admin/model/ChangeLog.php
  56. 1 0
      app/admin/model/GoodLog.php
  57. 1 0
      app/admin/model/OrderMsg.php
  58. 3 2
      app/admin/model/ProcessOrder.php
  59. 1 0
      app/admin/model/Workflow.php
  60. 8 15
      app/admin/route/app.php

+ 5 - 2
app/admin/controller/Activity.php

@@ -191,7 +191,7 @@ class Activity extends Base
         }
         $createrid= isset($user["data"]['id']) ?  $user["data"]['id'] : "";
         $creater= isset($user["data"]['nickname']) ?  $user["data"]['nickname'] : "";
-        $activity_code = makeNo("ACT");
+        $activity_code = makeNo("AT");
         Db::startTrans();
         try{
             $data=[
@@ -451,7 +451,10 @@ class Activity extends Base
             foreach ($good as $value){
                 $temp=[];
                 $stock =Db::name("good_stock")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->sum('usable_stock');
-                $temp['stock_num'] = intval($stock);
+
+                //如果是非库存商品,库存数改为最大(即将库存设为无限)
+                $temp['stock_num'] = $value['is_stock'] == 1 ? intval($stock) : 9999;
+
                 $temp['skuCode']=$value['skuCode'];
                 $temp['spuCode']=$value['spuCode'];
                 $temp['is_stock']=$value['is_stock'];

+ 79 - 31
app/admin/controller/After.php

@@ -5,9 +5,11 @@ namespace app\admin\controller;
 use app\admin\model\ActionLog;
 use app\admin\model\ProcessOrder;
 use think\App;
+use think\Exception;
 use think\facade\Db;
+use think\facade\Validate;
 
-
+//售后
 class After extends \app\BaseController
 {
     public $post=[];
@@ -64,7 +66,7 @@ class After extends \app\BaseController
         }
         $rm= isset($user["data"]['id']) ?  $user["data"]['id'] : "";
         $ri= isset($user["data"]['nickname']) ?  $user["data"]['nickname'] : "";
-        $returnCode=makeNo("RXS");
+        $returnCode=makeNo("RS");
         Db::startTrans();
         try{
             $in = [
@@ -86,7 +88,7 @@ class After extends \app\BaseController
                 "remark"=>'',
                 "except_code"=>$except_code,
                 "order_type"=>$orderout['order_type'],
-                "status"=>0,
+                "status"=>1,
                 "is_del"=>0,
                 "addtime"=>date("Y-m-d H:i:s"),
                 "updatetime"=>date("Y-m-d H:i:s")
@@ -217,15 +219,33 @@ class After extends \app\BaseController
         $info["addr_code"]=json_decode($info['addr_code'],true);
         $out =Db::name("order_out")->where(["outCode"=>$info['outCode']])->find();
         $info['out_num'] = isset($out['send_num'])?$out['send_num']:'';
-        $customer = Db::name("customer_info")->where(["companyNo"=>$info['customer_code']])->find();
-        $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
-            ->where(["a.wsm_code"=>$info['return_wsm']])->field("a.name as wsm_name,b.name,b.code,a.wsm_code")->find();
+//        $customer = Db::name("customer_info")->where(["companyNo"=>$info['customer_code']])->find();
+
+        $wsmcode = Db::name("warehouse_info")
+            ->alias("a")
+            ->leftJoin("supplier b","a.supplierNo=b.code")
+            ->where(["a.wsm_code"=>$info['return_wsm']])
+            ->field("a.name as wsm_name,b.name,b.code,a.wsm_code,a.contactor_name,a.position,a.mobile,a.addrs_code,a.addr,a.companyNo")
+            ->find();
         $info['wsm_code'] =isset($wsmcode['wsm_code']) ? $wsmcode['wsm_code']:"";
         $info['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
         $info['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
         $info['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
-        $info['customer_name'] = isset($customer['companyName']) ?trim($customer['companyName']):'';
+
+        $customer = Db::name("business")->field('id,company,companyNo')->where(["companyNo"=>$wsmcode['companyNo']])->find();
+        $info['customer_name'] = isset($customer['company']) ?trim($customer['company']):'';
+        $info['customer_code'] = isset($customer['companyNo']) ?trim($customer['companyNo']):'';
         $info['can']=$int;
+
+        //仓库的联系人、职位、电话、省市区和地址
+        $info['contactor_name'] = $wsmcode['contactor_name'];//联系人
+        $info['position'] = $wsmcode['position'];//职位
+        $info['mobile'] = $wsmcode['mobile'];//电话
+        $info['addrs_code'] = json_decode($wsmcode['addrs_code'], true);//省市区编码
+        $info['addr'] = $wsmcode['addr'];//地址
+        $info['spuCode'] = $orderinfo['good_code'];//地址
+        $info['skuCode'] = $orderinfo['skuCode'];//地址
+
         return app_show(0,"获取成功",$info);
     }
     public function status(){
@@ -242,8 +262,8 @@ class After extends \app\BaseController
         if($status===""){
             return error_show(1005,"参数status 不能为空");
         }
-        $orde= Db::name("order_out")->where(["outCode"=>$info['outCode'],"is_del"=>0])->find();
-        if(empty($orde)){
+        $orde= Db::name("order_out")->where(["outCode"=>$info['outCode']])->find();
+        if($orde==false){
             return error_show(1005,"未找到出库单数据");
         }
       $remark = isset($this->post['remark'])&&$this->post['remark']!=''?trim($this->post['remark']):"";
@@ -265,20 +285,6 @@ class After extends \app\BaseController
             $info['updatetime']=date("Y-m-d H:i:s");
             $up =Db::name("order_return")->save($info);
             if($up){
-//                if($info['order_status']==1&&$info['order_type']==1 && $status==4){
-//                    $orderout= Db::name("order_out")->where($orde)->save(['status'=>3,"updatetime"=>date("Y-m-d H:i:s")]);
-//                    $order = ["order_code"=>$orde['outCode'],"status"=>$orde['status'],"action_remark"=>'',"action_type"=>"edit"];
-//                    ActionLog::logAdd($this->post['token'],$order,$orde['order_type']==1?'CKD':"ZXCKD", 3,['status'=>3,"updatetime"=>date("Y-m-d H:i:s")]);
-//                    $process=["order_code"=>$orde['outCode'],"order_id"=>$orde['id'],"order_status"=>3,"order_type"=>$orde['order_type']==1?'CKD':"ZXCKD"];
-//                    ProcessOrder::AddProcess($this->post['token'],$process);
-//                    if($orderout){
-//                        Db::commit();
-//                        return app_show(0,"更新成功");
-//                    }else{
-//                        Db::rollback();
-//                        return error_show(1004,"更新失败");
-//                    }
-//                }
                 $order = ["order_code"=>$info['returnCode'],"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
                 ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'SHD':"ZXSHD", $info['status'],$this->post);
                 $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$status,"order_type"=>$info['order_type']==1?'SHD':"ZXSHD"];
@@ -537,7 +543,7 @@ class After extends \app\BaseController
                 $in=Db::name("order_returninfo")->save($return_info);
                 if($in){
                     $data=[
-                        'thNo'=>makeNo("TH"),
+                        'thNo'=>makeNo("ST"),
                         "orderCode"=>$info['orderCode'],
                         "order_type"=>$info['order_type'],
                         "outCode"=>$info['outCode'],
@@ -785,10 +791,11 @@ class After extends \app\BaseController
             if($post_code==""){
                 return error_show(1005,"参数post_code不能为空");
             }
-            if($post_fee==""){
+            if($post_fee===""){
                 return error_show(1005,"参数post_fee不能为空");
             }
         }
+        Db::startTrans();
         try {
             $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
             if($returninfo==false){
@@ -816,7 +823,7 @@ class After extends \app\BaseController
                 $info['updatetime']=date("y-m-d H:i:s");
                 $ro =Db::name("order_return")->save($info);
                 if($ro){
-                    $thNo =makeNo("TH");
+                    $thNo =makeNo("ST");
                     $thdata=[
                         "thNo"=>$thNo,
                         "orderCode"=>$out["orderCode"],
@@ -826,13 +833,13 @@ class After extends \app\BaseController
                         "good_code"=>$info["good_code"],
                         "good_name"=>$info["good_name"],
                         "return_wsm"=>$returninfo["return_wsm"],
-                        "defective_wsm"=>'',
-                        "return_msg"=>$out["error_msg"],
+//                        "defective_wsm"=>'',
+                        "return_msg"=>$info["error_msg"],
                         "return_num"=>$info["total_num"],
                         "normal_num"=>0,
                         "received_num"=>0,
-                        "defective_num"=>0,
-                        "loss_num"=>0,
+                      //  "defective_num"=>0,
+                      //  "loss_num"=>0,
                         "contactor"=>$returninfo["contactor"],
                         "mobile"=>$returninfo["mobile"],
                         "addr"=>$returninfo["addr"],
@@ -841,7 +848,7 @@ class After extends \app\BaseController
                         "post_fee"=>$returninfo["post_fee"],
                         "post_code"=>$returninfo["post_code"],
                         "post_company"=>$returninfo["post_company"],
-                        "customer_code"=>$returninfo["customer_code"],
+                        "customer_code"=>$info["customer_code"],
                         "status"=>1,
                         "addtime"=>date("Y-m-d H:i:s"),
                         "updatetime"=>date("Y-m-d H:i:s")
@@ -860,4 +867,45 @@ class After extends \app\BaseController
             return error_show(1004,$e->getMessage());
         }
     }
+
+    //取消售后
+    public function Cancel()
+    {
+        //接收参数
+        $data = $this->request->only(['token', 'returnCode'], 'post', 'trim');
+
+        $val = Validate::rule(['returnCode|售后单编号' => 'require']);
+
+        if (!$val->check($data)) return error_show(1005, $val->getError());
+
+        Db::startTrans();
+        try {
+
+            $rs = Db::name('order_return')->field('id,status')->where([['returnCode', '=', $data['returnCode']], ['is_del', '=', 0], ['status', '<>', 8]])->find();
+
+            if (!$rs) throw new Exception('该售后单记录不存在');
+
+            //修改记录
+            $res = Db::name('order_return')->where(['id' => $rs['id']])->update(['status' => 8, 'updatetime' => date('Y-m-d H:i:s')]);
+
+            if (!$res) throw new Exception('该售后单记录修改失败');
+
+            //记录日志
+            ActionLog::logAdd($data['token'], ["order_code" => $data['returnCode'], "status" => 8, "action_remark" => '', "action_type" => "cancel"], 'SHD', 8, $this->post);
+            ProcessOrder::AddProcess($this->post['token'], ["order_code" => $data['returnCode'], "order_id" => $rs['id'], "order_status" => 8, "order_type" => 'SHD']);
+
+            //提交
+            Db::commit();
+
+            return app_show(0, "取消成功");
+
+        } catch (\Exception $e) {
+
+            Db::rollback();
+
+            return error_show(1004, $e->getMessage());
+        }
+
+    }
+
 }

+ 70 - 53
app/admin/controller/Allot.php

@@ -9,6 +9,8 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 
+//调拨  allot_info(从表)和allot_stock(主表)
+//调拨之后,修改库存,采购单的仓库编号是否也需要修改
 class Allot extends BaseController
 {
     public $post= "";
@@ -47,15 +49,13 @@ class Allot extends BaseController
             $where[]=['addtime',"<=",$end];
         }
 
-        $out_supplierNo =isset($this->post['wsm_out_supplierNo']) &&$this->post['wsm_out_supplierNo'] !=="" ? trim
-        ($this->post['wsm_out_supplierNo']):"";
+        $out_supplierNo =isset($this->post['wsm_out_supplierNo']) &&$this->post['wsm_out_supplierNo'] !=="" ? trim($this->post['wsm_out_supplierNo']):"";
         if($out_supplierNo!=""){
             $supplier = Db::name("supplier")->where(["code"=>$out_supplierNo])->find();
             if(empty($supplier)){
                 return error_show(1004,"未找到出库供应商信息");
             }
-            $wsmcode = Db::name("warehouse_info")->where([
-                "is_del"=>0,"wsm_type"=>1,"supplierNo"=>$out_supplierNo])->column("wsm_code");
+            $wsmcode = Db::name("warehouse_info")->where(["is_del"=>0,"wsm_type"=>1,"supplierNo"=>$out_supplierNo])->column("wsm_code");
             //$condtion["c.wsm_code"] = $wsmcode;
             $where[]=['wsm_out',"in",$wsmcode];
         }
@@ -64,22 +64,19 @@ class Allot extends BaseController
 
             $where[]=["out_companyNo","=",$out_companyNo];
         }
-        $in_companyNo = isset($this->post['in_companyNo']) && $this->post['in_companyNo'] !== "" ? trim
-        ($this->post['in_companyNo']) : "";
+        $in_companyNo = isset($this->post['in_companyNo']) && $this->post['in_companyNo'] !== "" ? trim($this->post['in_companyNo']) : "";
         if ($in_companyNo !== "") {
 
             $where[]=["in_companyNo","=",$in_companyNo];
         }
 
-        $in_supplierNo =isset($this->post['wsm_in_supplierNo']) &&$this->post['wsm_in_supplierNo'] !=="" ? trim
-        ($this->post['wsm_in_supplierNo']):"";
+        $in_supplierNo =isset($this->post['wsm_in_supplierNo']) &&$this->post['wsm_in_supplierNo'] !=="" ? trim($this->post['wsm_in_supplierNo']):"";
         if($in_supplierNo!=""){
             $supplier = Db::name("supplier")->where(["code"=>$in_supplierNo])->find();
             if(empty($supplier)){
                 return error_show(1004,"未找到入库供应商信息");
             }
-            $wsmcode = Db::name("warehouse_info")->where([
-                "is_del"=>0,"wsm_type"=>1,"supplierNo"=>$in_supplierNo])->column("wsm_code");
+            $wsmcode = Db::name("warehouse_info")->where(["is_del"=>0,"wsm_type"=>1,"supplierNo"=>$in_supplierNo])->column("wsm_code");
             //$condtion["c.wsm_code"] = $wsmcode;
             $where[]=['wsm_in',"in",$wsmcode];
         }
@@ -91,28 +88,40 @@ class Allot extends BaseController
         $count = Db::name('allot_stock')->where($where)->count();
         $total = ceil($count/$size);
         $page = $page >= $total ? $total : $page;
-        $list = Db::name('allot_stock')->where($where)->order("addtime desc")->page($page,$size)->select();
+        $list = Db::name('allot_stock')->where($where)->order("addtime desc")->page($page,$size)->select()->toArray();
       // var_dump(Db::name('allot_stock')->getLastSql());
         $data=[];
         foreach ($list as $value){
-            $db = Db::name('warehouse_info')->alias('a')->join("supplier b","b.code=a.supplierNo","left")
-                ->field("a.name,a.wsm_code,b.name rname,b.code")->where(['a.wsm_code'=>$value['wsm_out'],"
-                a.wsm_type"=>1,'a.is_del'=>0])->find();
+            $db = Db::name('warehouse_info')
+                ->alias('a')
+                ->join("supplier b","b.code=a.supplierNo","left")
+                ->join("business bus","bus.companyNo=a.companyNo","left")
+                ->field("a.name,a.wsm_code,b.name rname,b.code,bus.company")
+                ->where(['a.wsm_code'=>$value['wsm_out'],"a.wsm_type"=>1,'a.is_del'=>0])
+                ->find();
             $value['name'] =isset($db['name']) ? $db['name']:"";
             $value['wsm_code'] =isset($db['wsm_code']) ? $db['wsm_code']:"";
-            $value['rname'] =isset($db['rname']) ? $db['rname']:"";
-           $value['code'] =isset($db['code']) ? $db['code']:"";
-            $dc = Db::name('warehouse_info')->alias('a')->join("supplier b","b.code=a.supplierNo","left")
-                ->field("a.name,a.wsm_code,b.name tname,b.code")->where(['a.wsm_code'=>$value['wsm_in'],"a.wsm_type"=>1,'a.is_del'=>0])->find();
+            $value['rname'] = isset($db['rname']) ? $db['rname'] : "";
+            $value['code'] = isset($db['code']) ? $db['code'] : "";
+            $value['out_company_name'] = isset($db['company']) ? $db['company'] : "";
+            $dc = Db::name('warehouse_info')
+                ->alias('a')
+                ->join("business bus","bus.companyNo=a.companyNo","left")
+                ->join("supplier b","b.code=a.supplierNo","left")
+                ->field("a.name,a.wsm_code,b.name tname,b.code,bus.company")
+                ->where(['a.wsm_code'=>$value['wsm_in'],"a.wsm_type"=>1,'a.is_del'=>0])
+                ->find();
             $value['wsm_in_name'] =isset($dc['name']) ? $dc['name']:"";
             $value['wsm_in_code'] =isset($dc['wsm_code']) ? $dc['wsm_code']:"";
             $value['tname'] =isset($dc['tname']) ? $dc['tname']:"";
             $value['rcode'] =isset($dc['code']) ? $dc['code']:"";
+            $value['in_company_name'] =isset($dc['company']) ? $dc['company']:"";
             $data []=$value;
         }
         return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
     }
     public function create(){
+
         $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
     $wsm_out = isset($this->post['wsm_out']) && $this->post['wsm_out'] !=="" ? trim($this->post['wsm_out']) :"";
     if($wsm_out==""){
@@ -122,22 +131,29 @@ class Allot extends BaseController
     if($wsm_in==""){
         return error_show(1002,"入库仓库不能为空");
     }
-        $in_companyNo = isset($this->post['in_companyNo']) && $this->post['in_companyNo'] !=="" ? trim($this->post['in_companyNo']) :"";
-        if($in_companyNo==""){
-            return error_show(1002,"in_companyNo不能为空");
-        }
-        $out_companyNo = isset($this->post['out_companyNo']) && $this->post['out_companyNo'] !=="" ? trim($this->post['out_companyNo']) :"";
-        if($out_companyNo==""){
-            return error_show(1002,"out_companyNo不能为空");
-        }
-        $company =Db::name("business")->where(['companyNo'=>$in_companyNo,"is_del"=>0])->find();
-        if($company==false){
-            return error_show(1002,"未找到入库业务公司");
-        }
-        $company =Db::name("business")->where(['companyNo'=>$out_companyNo,"is_del"=>0])->find();
-        if($company==false){
-            return error_show(1002,"未找到出库业务公司");
-        }
+
+        //根据出入库的仓库编码,查出对应的公司、业务公司
+        $warehouse_temp_info = Db::name('warehouse_info')
+            ->where(['is_del' => 0, 'status' => 1])
+            ->whereIn('wsm_code', [$wsm_out, $wsm_in])
+            ->column('supplierNo,companyNo', 'wsm_code');//supplierNo所属供货商,companyNo业务企业
+
+//        $in_companyNo = isset($this->post['in_companyNo']) && $this->post['in_companyNo'] !=="" ? trim($this->post['in_companyNo']) :"";
+//        if($in_companyNo==""){
+//            return error_show(1002,"in_companyNo不能为空");
+//        }
+//        $out_companyNo = isset($this->post['out_companyNo']) && $this->post['out_companyNo'] !=="" ? trim($this->post['out_companyNo']) :"";
+//        if($out_companyNo==""){
+//            return error_show(1002,"out_companyNo不能为空");
+//        }
+//        $company =Db::name("business")->where(['companyNo'=>$in_companyNo,"is_del"=>0])->find();
+//        if($company==false){
+//            return error_show(1002,"未找到入库业务公司");
+//        }
+//        $company =Db::name("business")->where(['companyNo'=>$out_companyNo,"is_del"=>0])->find();
+//        if($company==false){
+//            return error_show(1002,"未找到出库业务公司");
+//        }
 //    $good_type_code = isset($this->post['good_type_code']) && $this->post['good_type_code'] !=="" ? trim($this->post['good_type_code']) :"";
 //    if($good_type_code==""){
 //        return error_show(1002,"商品属性不能为空");
@@ -171,8 +187,8 @@ class Allot extends BaseController
                 "allot_code"=>$allot_code,
                 "wsm_out"=>$wsm_out,
                 "wsm_in"=>$wsm_in,
-                "out_companyNo"=>$out_companyNo,
-                "in_companyNo"=>$in_companyNo,
+                "out_companyNo"=>$warehouse_temp_info[$wsm_out]['companyNo'],
+                "in_companyNo"=>$warehouse_temp_info[$wsm_in]['companyNo'],
                 "apply_name"=>$ri,
                 "apply_id"=>$rm,
                 "post_name"=>$post_name,
@@ -194,8 +210,9 @@ class Allot extends BaseController
                         ->join("good_stock c", "c.spuCode = b.spuCode", "left")
                         ->join("warehouse_info v","v.wsm_code=c.wsm_code","left")
                         ->join("supplier n","n.code=v.supplierNo","left")
-                        ->where(['c.wsm_code' => $wsm_out,"v.wsm_type"=>1, 'b.spuCode' => $value['good_code'], 'b.is_del' => 0, 'a.is_del' => 0])->where("c.is_del=0 or c.is_del is null")
-                        ->field("b.spuCode,b.good_name,b.unit,c.wsm_code,c.usable_stock,c.good_type_code,c.wait_out_stock,c.wait_in_stock,n.name")->find();
+                        ->where(['c.wsm_code' => $wsm_out,"v.wsm_type"=>1, 'b.spuCode' => $value['spuCode'], 'b.is_del' => 0])->where("c.is_del=0 or c.is_del is null")
+                        ->field("b.spuCode,b.good_name,b.good_unit,c.wsm_code,c.usable_stock,c.good_type_code,c.wait_out_stock,c.wait_in_stock,n.name")->find();
+
                     if (empty($st)) {
                         Db::rollback();
                         return error_show(1003, "商品不能为空");
@@ -206,7 +223,7 @@ class Allot extends BaseController
                         $temp = [];
                         $temp['good_name'] = $st['good_name'];
                         $temp['allot_code'] =$allot_code;
-                        $temp['good_type_code'] = $value['good_code'];
+                        $temp['good_type_code'] = $value['spuCode'];
                         $temp['allot_num'] = $value['allot_num'];
                         $temp['usable_num'] = 0;
                         $temp['error_num'] = 0;
@@ -274,7 +291,7 @@ class Allot extends BaseController
 
             $data=[];
         foreach ($vmp as $k=>$value){
-            $s =Db::name('good_stock')->where(['spuCode'=>$value['spuCode'],'wsm_code'=>$str['wsm_out']])
+            $s =Db::name('good_stock')->where(['spuCode'=>$value['good_type_code'],'wsm_code'=>$str['wsm_out']])
                 ->find();
             if($str['status']<=1) {
                 $value['usable_num'] = $s['usable_stock'];
@@ -349,8 +366,8 @@ class Allot extends BaseController
                         ->join("good_stock c", "c.spuCode = b.spuCode", "left")
                         ->join("warehouse_info v","v.wsm_code=c.wsm_code","left")
                         ->join("supplier n","n.code=v.supplierNo","left")
-                        ->where(['c.wsm_code' => $wsm_out,"v.wsm_type"=>1, 'b.spuCode' => $value['good_code'], 'b.is_del' => 0, 'a.is_del' => 0])->where("c.is_del=0 or c.is_del is null")
-                        ->field("b.spuCode,b.good_name,b.unit,c.wsm_code,c.usable_stock,c.good_type_code,c.wait_out_stock,c.wait_in_stock,n.name")->find();
+                        ->where(['c.wsm_code' => $wsm_out,"v.wsm_type"=>1, 'b.spuCode' => $value['spuCode'], 'b.is_del' => 0, 'a.is_del' => 0])->where("c.is_del=0 or c.is_del is null")
+                        ->field("b.spuCode,b.good_name,b.good_unit,c.wsm_code,c.usable_stock,c.good_type_code,c.wait_out_stock,c.wait_in_stock,n.name")->find();
                     if (empty($st)) {
                         Db::rollback();
                         return error_show(1003, "商品不能为空");
@@ -370,7 +387,7 @@ class Allot extends BaseController
                     $temp = [];
                    isset($value['id'])&&$value['id']!=="" ? $temp['id'] = $value['id']:'';
                     $temp['good_name'] = $st['good_name'];
-                    $temp['good_type_code'] = $value['good_code'];
+                    $temp['good_type_code'] = $value['spuCode'];
                     $temp['allot_num'] = $value['allot_num'];
                     $temp['usable_num'] = 0;
                     $temp['error_num'] = 0;
@@ -579,13 +596,13 @@ class Allot extends BaseController
             $good_data=[];
             foreach ($dain as $value) {
                 $st = Db::name("good")->alias("b")
-                    ->join("good_stock c", "c.spuCode = b.spuCode", "left")->where(['wsm_code' => $al['wsm_out'], 'b.spuCode' => $value['good_code'], 'b.is_del' => 0, 'a.is_del' => 0])->where("c.is_del=0 or c.is_del is null")
+                    ->join("good_stock c", "c.spuCode = b.spuCode", "left")->where(['wsm_code' => $al['wsm_out'], 'b.spuCode' => $value['spuCode'], 'b.is_del' => 0, 'a.is_del' => 0])->where("c.is_del=0 or c.is_del is null")
                     ->field("b.spuCode,b.good_name,c.wsm_code,c.usable_stock")->find();
                 if (empty($st)) {
                     Db::rollback();
                     return error_show(1003, "未找到商品");
                 }
-                $n = Db::name('allot_info')->where(['good_type_code'=>$value['good_code'],'allot_code'=> $al['allot_code'],'is_del'=>0])->find();
+                $n = Db::name('allot_info')->where(['good_type_code'=>$value['spuCode'],'allot_code'=> $al['allot_code'],'is_del'=>0])->find();
                 if(empty($n)){
                     Db::rollback();
                     return error_show(10032, "未找到数据");
@@ -601,13 +618,13 @@ class Allot extends BaseController
                 $temp['error_remark'] = $value['error_remark'];
                 $temp['stock_num']=$n['allot_num'];
                 $temp['updatetime'] = date("Y-m-d H:i:s");
-                $np = Db::name('allot_info')->where(['good_type_code'=>$value['good_code'],'allot_code'=> $al['allot_code'],'is_del'=>0])->save($temp);
+                $np = Db::name('allot_info')->where(['good_type_code'=>$value['spuCode'],'allot_code'=> $al['allot_code'],'is_del'=>0])->save($temp);
                 if($np==false){
                     Db::rollback();
                     return error_show(1001,"数据更新失败");
                 }
 
-                $stock = Db::name("good_stock")->where(["spuCode"=>$value['good_code'],"wsm_code"=>$al['wsm_out'],
+                $stock = Db::name("good_stock")->where(["spuCode"=>$value['spuCode'],"wsm_code"=>$al['wsm_out'],
                     "is_del"=>0])->find();
                 if($stock['intra_stock']<$n['allot_num']){
                     Db::rollback();
@@ -621,10 +638,10 @@ class Allot extends BaseController
                     return error_show(1002,"数据更新失败");
                 }
                 $good_data[]=["stock_id"=>$stock['id'],"type"=>2,'stock'=>$n['allot_num'],"stock_name"=>"intra_stock"];
-                $instock = Db::name("good_stock")->where(["spuCode"=>$value['good_code'],"wsm_code"=>$al['wsm_in'],"is_del"=>0])->find();
+                $instock = Db::name("good_stock")->where(["spuCode"=>$value['spuCode'],"wsm_code"=>$al['wsm_in'],"is_del"=>0])->find();
                 if($instock==false){
                    $instock =[];
-                    $instock['spuCode']=$value['good_code'];
+                    $instock['spuCode']=$value['spuCode'];
                     $instock['wsm_code']=$al['wsm_in'];
                     $instock['wait_in_stock']=0;
                     $instock['wait_out_stock']=0;
@@ -687,7 +704,7 @@ public function vesio(){
             ActionLog::logAdd($this->post['token'],$order,"DBD",5,$this->post);
             foreach ($dain as $value) {
                 $st = Db::name("good")->alias("b")
-                    ->join("good_stock c", "c.spuCode = b.spuCode", "left")->where(['wsm_code' => $al['wsm_in'], 'b.spuCode' => $value['good_code'], 'b.is_del' => 0, 'a.is_del' => 0])->where("c.is_del=0 or c.is_del is null")
+                    ->join("good_stock c", "c.spuCode = b.spuCode", "left")->where(['wsm_code' => $al['wsm_in'], 'b.spuCode' => $value['spuCode'], 'b.is_del' => 0, 'a.is_del' => 0])->where("c.is_del=0 or c.is_del is null")
                     ->field("b.spuCode,b.good_name,c.wsm_code,c.usable_stock")->find();
                 if (empty($st)) {
                     Db::rollback();
@@ -700,17 +717,17 @@ public function vesio(){
                 $temp['stock_num'] = $value['stock_num'];
                 $temp['error_remark'] = $value['error_remark'];
                 $temp['updatetime'] = date("Y-m-d H:i:s");
-                $np = Db::name('allot_info')->where(['good_type_code'=>$value['good_code'],'allot_code'=> $al['allot_code']])->save($temp);
+                $np = Db::name('allot_info')->where(['good_type_code'=>$value['spuCode'],'allot_code'=> $al['allot_code']])->save($temp);
                 if($np==false){
                     Db::rollback();
                     return error_show(1001,"数据更新失败");
                 }
-                $p = Db::name('allot_info')->where(['good_type_code'=>$value['good_code'],'allot_code'=>$al['allot_code'],"is_del"=>0])->find();
+                $p = Db::name('allot_info')->where(['good_type_code'=>$value['spuCode'],'allot_code'=>$al['allot_code'],"is_del"=>0])->find();
                 if($p==false){
                     Db::rollback();
                     return error_show(1002,"未找到数据");
                 }
-                $stock = Db::name("good_stock")->where(["spuCode"=>$value['good_code'],"wsm_code"=>$al['wsm_in'],"is_del"=>0])->find();
+                $stock = Db::name("good_stock")->where(["spuCode"=>$value['spuCode'],"wsm_code"=>$al['wsm_in'],"is_del"=>0])->find();
                 if($stock['wait_in_stock']<$p['stock_num']){
                     Db::rollback();
                    return error_show(2000,"超出待入库存数量");

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

@@ -6,6 +6,7 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 
+//客户属性
 class Attr extends BaseController
 {
     public $post="";

+ 2 - 1
app/admin/controller/Base.php

@@ -9,6 +9,7 @@ use think\App;
 class Base extends \app\BaseController
 {
     public  $post=[];
+    public  $uid='';
     public function __construct(App $app)
     {
         parent::__construct($app);
@@ -26,6 +27,6 @@ class Base extends \app\BaseController
         if(!empty($effetc) && $effetc['code']!=0) {
             return error_show($effetc['code'], $effetc['message']);
         }
-        // TODO: Change the autogenerated stub
+
     }
 }

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

@@ -7,6 +7,7 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 
+//品牌
 class Brand extends BaseController
 {
     public $post="";

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

@@ -6,6 +6,7 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 
+//业务企业
 class Business extends BaseController
 {
     public $post = "";

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

@@ -8,6 +8,7 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 
+//分类
 class Cat extends BaseController
 {
 public $post="";

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

@@ -6,6 +6,7 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 
+//分类描述信息
 class Catdesc extends BaseController
 {
     public $post="";

+ 50 - 11
app/admin/controller/Check.php

@@ -8,6 +8,7 @@ use think\App;
 use think\facade\Db;
 use app\admin\model\ActionLog;
 
+//盘点 wsm_good_check(主表,记录了哪个仓库,那个人,什么时间)和wsm_check_item(盘点的商品明细)
 class Check extends BaseController
 {
 public $post = "";
@@ -103,20 +104,56 @@ public function flist(){
         ->join("good_stock c","c.spuCode=b.spuCode","left")
         ->where($condtion)->count();
     $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
-    $list = Db::name("good")->alias("b")
+    $list = Db::name("good")
+        ->alias("b")
         ->join("good_stock c","c.spuCode=b.spuCode","left")
-        ->where($condtion)->page($page,$size)->select();
+        ->where($condtion)
+        ->page($page,$size)
+        ->select()
+        ->toArray();
+
     $data=[];
-    foreach ($list as $key=>$value){
-        $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
-        $value['supplier_name'] =isset($supplier['name']) ?$supplier['name'] :"";
-        $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")->where(["a.wsm_code"=>$value['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
-        $value['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
-        $value['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
-        $value['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
-        $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
-        $data[]=$value;
+    if($list) {
+
+        //品牌信息
+        $brands = Db::name('brand')->whereIn('id', array_column($list, 'brand_id'))->where('is_del', 0)->column('brand_name', 'id');
+        $units = Db::name('unit')->whereIn('id', array_column($list, 'good_unit'))->where('is_del', 0)->column('unit', 'id');
+
+        foreach ($list as $key=>$value){
+            $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
+            $value['supplier_name'] =isset($supplier['name']) ?$supplier['name'] :"";
+            $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")->where(["a.wsm_code"=>$value['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
+            $value['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
+            $value['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
+            $value['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
+            $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
+
+            $value['brand_name'] = $brands[$value['brand_id']]??'';
+            $value['unit'] = $units[$value['good_unit']]??'';
+
+            //规格信息
+            $spec = Db::name("good_spec")->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
+
+            $speclist = [];
+            if (!empty($spec)) {
+                foreach ($spec as $val) {
+                    $temp = [];
+                    $temp['spec_id'] = $val['spec_id'];
+                    $temp['spec_value_id'] = $val['spec_value_id'];
+                    $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
+                    $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
+                    $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
+                    $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
+                    $speclist[] = $temp;
+                }
+            }
+            $value['specinfo'] = $speclist;
+
+            $data[]=$value;
+        }
+
     }
+
     return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
 }
 public function list()
@@ -497,6 +534,7 @@ public function edit()
 
     }
 
+    //导出(盘点的明细)
     public function exportGood(){
         $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
         if($id==""){
@@ -534,6 +572,7 @@ public function edit()
        // return app_show(0,"获取成功",$data);
     }
 
+    //导入
     public function importGood(){
         $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
         if($id==""){

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

@@ -6,6 +6,7 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 
+//系统配置
 class Conf extends BaseController
 {
     public function __construct(App $app)

+ 173 - 250
app/admin/controller/Consult.php

@@ -2,9 +2,13 @@
 
 namespace app\admin\controller;
 
+use app\admin\model\ActionLog;
+use app\admin\model\ProcessOrder;
 use think\App;
 use think\facade\Db;
+use think\facade\Validate;
 
+//咨询单
 class Consult extends Base
 {
     public $noble=[];
@@ -130,14 +134,7 @@ class Consult extends Base
         if($endtime===""){
             return error_show(1002,"参数endtime不能为空");
         }
-//        $saleid =  isset($this->post['saleid']) && $this->post['saleid'] !=="" ? intval($this->post['saleid']) : "";
-//        if($saleid===""){
-//            return error_show(1002,"参数saleid不能为空");
-//        }
-//        $depart =  isset($this->post['depart']) && $this->post['depart'] !=="" ? intval($this->post['depart']) : "";
-//        if($depart===""){
-//            return error_show(1002,"参数depart不能为空");
-//        }
+
         $platform_code =  isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code']) :
             "";
         if($platform_code===""){
@@ -159,226 +156,96 @@ class Consult extends Base
         $creater= isset($user["data"]['nickname']) ?  $user["data"]['nickname'] : "";
         $depart= Db::name("depart_user")->where(["uid"=>$createrid,"status"=>1,"is_del"=>0])->find();
         $zxNo=makeNo("ZX");
-        $data=[
-            "zxNo"=>$zxNo,
-            "createrid"=>$createrid,
-            "creater"=>$creater,
-            "is_project"=>$is_project,
-            "projectNo"=>isset($projectNo) ? $projectNo:"",
-            "khNo"=>$khNo,
-            "companyNo"=>$companyNo,
-            "endtime"=>$endtime,
-            "salesman"=>$creater,
-            "platform_code"=>$platform_code,
-            "saleid"=>$createrid,
-            "depart"=>isset($depart['itemid'])?$depart['itemid']:0,
-            "status"=>0,
-            "is_del"=>0,
-            "addtime"=>date("Y-m-d H:i:s"),
-            "updatetime"=>date("Y-m-d H:i:s"),
-        ];
-        $zx = Db::name("consult_order")->insert($data);
-        if($zx){
-            foreach ($ladder as $value){
-                $infoNo=makeNo("INF");
-                $specinfo=[];
-                if(isset($value['specinfo']) &&!empty($value['specinfo'])){
-                    foreach ($value["specinfo"] as $v){
-                        $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
-                        $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
-                        $v['spec_name']=isset($spec['spec_name'])? $spec['spec_name']:"";
-                        $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"" ;
-                        $specinfo[]=$v;
+        Db::startTrans();
+        try{
+            $data=[
+                "zxNo"=>$zxNo,
+                "createrid"=>$createrid,
+                "creater"=>$creater,
+                "is_project"=>$is_project,
+                "projectNo"=>isset($projectNo) ? $projectNo:"",
+                "khNo"=>$khNo,
+                "companyNo"=>$companyNo,
+                "endtime"=>$endtime,
+                "salesman"=>$creater,
+                "platform_code"=>$platform_code,
+                "saleid"=>$createrid,
+                "depart"=>isset($depart['itemid'])?$depart['itemid']:0,
+                "status"=>0,
+                "is_del"=>0,
+                "addtime"=>date("Y-m-d H:i:s"),
+                "updatetime"=>date("Y-m-d H:i:s"),
+            ];
+            $zx = Db::name("consult_order")->insert($data);
+            if($zx){
+                foreach ($ladder as $value){
+                    $infoNo=makeNo("IF");
+                    $specinfo=[];
+                    if(isset($value['specinfo']) &&!empty($value['specinfo'])){
+                        foreach ($value["specinfo"] as $v){
+                            $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
+                            $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
+                            $v['spec_name']=isset($spec['spec_name'])? $spec['spec_name']:"";
+                            $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"" ;
+                            $specinfo[]=$v;
+                        }
+                    }
+                    $info=[
+                        "infoNo"=>$infoNo,
+                        "zxNo"=>$zxNo,
+                        "spuCode"=>"",
+                        "good_name"=>$value['good_name'],
+                        "good_img"=>$value['good_img'],
+                        "cat_id"=>$value['cat_id'],
+                        "unit"=>$value['unit'],
+                        "brand_id"=>$value['brand_id'],
+                        "arrival_time"=>$value['arrival_time'],
+                        "specinfo"=>empty($specinfo)?"" : json_encode($specinfo),
+                        "cost_desc"=>$value['cost_desc'],
+                        "is_addrs"=>$value['is_addrs'],
+                        "is_custom"=>$value['is_custom'],
+                        "metal_id"=>$value['metal_id'],
+                        "config"=>isset($value['config'])?$value['config']:"",
+                        "other_config"=>isset($value['other_config'])?$value['other_config']:"",
+                        "specs_weight"=>isset($value['specs_weight'])?$value['specs_weight']:"0",
+                        "gold_price"=>isset($value['gold_price'])?$value['gold_price']:"0",
+                        "is_gold_price"=>isset($value['is_gold_price'])?$value['is_gold_price']:"0",
+                        "total_weight"=>isset($value['total_weight'])?$value['total_weight']:"0",
+                        "budget_price"=>$value['budget_price'],
+                        "num"=>$value['num'],
+                        "pgNo"=>isset($value['pgNo'])&&$value['pgNo']!==""?trim($value['pgNo']):"",
+                        "use_desc"=>$value['use_desc'],
+                        "remark"=>$value['remark'],
+                        "status"=>1,
+                        "is_del"=>0,
+                        "addtime"=>date("Y-m-d H:i:s"),
+                        "updatetime"=>date("Y-m-d H:i:s")
+                    ];
+                    $up = Db::name("consult_info")->insert($info);
+                    if(!$up){
+                        Db::rollback();
+                        return error_show(1004,'添加失败');
                     }
                 }
-                $info=[
-                    "infoNo"=>$infoNo,
-                    "zxNo"=>$zxNo,
-                    "spuCode"=>"",
-                    "good_name"=>$value['good_name'],
-                    "good_img"=>$value['good_img'],
-                    "cat_id"=>$value['cat_id'],
-                    "unit"=>$value['unit'],
-                    "brand_id"=>$value['brand_id'],
-                    "arrival_time"=>$value['arrival_time'],
-                    "specinfo"=>empty($specinfo)?"" : json_encode($specinfo),
-                    "cost_desc"=>$value['cost_desc'],
-                    "is_addrs"=>$value['is_addrs'],
-                    "is_custom"=>$value['is_custom'],
-                    "metal_id"=>$value['metal_id'],
-                    "config"=>isset($value['config'])?$value['config']:"",
-                    "other_config"=>isset($value['other_config'])?$value['other_config']:"",
-                    "specs_weight"=>isset($value['specs_weight'])?$value['specs_weight']:"0",
-                    "gold_price"=>isset($value['gold_price'])?$value['gold_price']:"0",
-                    "is_gold_price"=>isset($value['is_gold_price'])?$value['is_gold_price']:"0",
-                    "total_weight"=>isset($value['total_weight'])?$value['total_weight']:"0",
-                    "budget_price"=>$value['budget_price'],
-                    "num"=>$value['num'],
-                    "pgNo"=>isset($value['pgNo'])&&$value['pgNo']!==""?trim($value['pgNo']):"",
-                    "use_desc"=>$value['use_desc'],
-                    "remark"=>$value['remark'],
-                    "status"=>1,
-                    "is_del"=>0,
-                    "addtime"=>date("Y-m-d H:i:s"),
-                    "updatetime"=>date("Y-m-d H:i:s")
-                ];
-                $up = Db::name("consult_info")->insert($info);
-                if(!$up){
-                    Db::rollback();
-                    return error_show(1004,'添加失败');
-                }
+                $stn = ["order_code"=>$zxNo,"status"=>1,"action_remark"=>'',"action_type"=>"create"];
+                ActionLog::logAdd($this->post['token'],$stn,"ZXD",2,$info);
+                $process=["order_code"=>$zxNo,"order_id"=>Db::name("consult_order")->getLastInsID(),"order_status"=>1,"order_type"=>'ZXD'];
+                ProcessOrder::AddProcess($this->post['token'],$process);
+                Db::commit();
+                return  app_show(0,"新建成功",["zxNo"=>$zxNo]);
+            }else{
+                Db::rollback();
+                return error_show(1004,"新建失败");
             }
-
-            return  app_show(0,"新建成功",["zxNo"=>$zxNo]);
-        }else{
-            return error_show(1004,"新建失败");
+        }catch (\Exception $e){
+            Db::rollback();
+            return error_show(1003,$e->getMessage());
         }
+
     }
 
-//    public function zxadd(){
-//        $good_name = isset($this->post['good_name'])&&$this->post['good_name']!==""?trim($this->post['good_name']):"";
-//        if($good_name===""){
-//            return error_show(1004,"参数good_name不能为空");
-//        }
-//        $zxNo = isset($this->post['zxNo'])&&$this->post['zxNo']!==""?trim($this->post['zxNo']):"";
-//        if($zxNo===""){
-//            return error_show(1004,"参数zxNo不能为空");
-//        }
-//
-//        $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!==""?intval($this->post['cat_id']):"";
-//        if($cat_id===""){
-//            return error_show(1004,"参数cat_id不能为空");
-//        }
-//        $arrival_time = isset($this->post['arrival_time'])&&$this->post['arrival_time']!==""?$this->post['arrival_time']
-//            :"";
-//        if($arrival_time===""){
-//            return error_show(1004,"参数arrival_time不能为空");
-//        }
-//        $good_img = isset($this->post['good_img'])&&$this->post['good_img']!==""?trim($this->post['good_img']):"";
-//        if($good_img===""){
-//            return error_show(1004,"参数good_img不能为空");
-//        }
-//        $is_custom = isset($this->post['is_custom'])&&$this->post['is_custom']!==""?intval($this->post['is_custom']):"";
-//        if($is_custom===""){
-//            return error_show(1004,"参数is_custom不能为空");
-//        }
-//        $unit = isset($this->post['unit'])&&$this->post['unit']!==""?trim($this->post['unit']):"";
-//        if($unit===""){
-//            return error_show(1004,"参数unit不能为空");
-//        }
-//        $brand_id = isset($this->post['brand_id'])&&$this->post['brand_id']!==""?intval($this->post['brand_id']):"";
-//        if($brand_id===""){
-//            return error_show(1004,"参数brand_id不能为空");
-//        }
-//        $material = isset($this->post['material'])&&$this->post['material']!==""?trim($this->post['material']):"";
-//        if($material===""){
-//            return error_show(1004,"参数material不能为空");
-//        }
-//        $color = isset($this->post['color'])&&$this->post['color']!==""?trim($this->post['color']):"";
-//        if($color===""){
-//            return error_show(1004,"参数color不能为空");
-//        }
-//        $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!==""?trim($this->post['cost_desc']):"";
-//        if($cost_desc===""){
-//            return error_show(1004,"参数cost_desc不能为空");
-//        }
-//        $model = isset($this->post['model'])&&$this->post['model']!==""?trim($this->post['model']):"";
-//        if($model===""){
-//            return error_show(1004,"参数model不能为空");
-//        }
-//
-//        $is_addrs = isset($this->post['is_addrs'])&&$this->post['is_addrs']!==""?intval($this->post['is_addrs']):"";
-//        if($is_addrs===""){
-//            return error_show(1004,"参数is_addrs不能为空");
-//        }
-//
-//        $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!==""?trim($this->post['metal_id']):"";
-//        if($metal_id===""){
-//            return error_show(1004,"参数metal_id不能为空");
-//        }
-//        if($metal_id==0){
-//            $config = isset($this->post['config'])&&!empty($this->post['config'])?$this->post['config']:"";
-//            if($config===""){
-//                return error_show(1004,"参数config不能为空");
-//            }
-//            $other_config = isset($this->post['other_config'])&&$this->post['other_config']!==""?trim($this->post['other_config'])
-//                :"";
-//            if($other_config===""){
-//                return error_show(1004,"参数other_config不能为空");
-//            }
-//            $specs_weight = isset($this->post['specs_weight'])&&$this->post['specs_weight']!==""?floatval($this->post['specs_weight']):"";
-//            if($specs_weight===""){
-//                return error_show(1004,"参数specs_weight不能为空");
-//            }
-//            $gold_price = isset($this->post['gold_price'])&&$this->post['gold_price']!==""?floatval($this->post['gold_price']):"";
-//            if($gold_price===""){
-//                return error_show(1004,"参数gold_price不能为空");
-//            }
-//
-//        }
-//        $budget_price = isset($this->post['budget_price'])&&$this->post['budget_price']!==""?floatval($this->post['budget_price']):"";
-//        if($budget_price===""){
-//            return error_show(1004,"参数budget_price不能为空");
-//        }
-//        $num = isset($this->post['num'])&&$this->post['num']!==""?intval($this->post['num']):"";
-//        if($num===""){
-//            return error_show(1004,"参数num不能为空");
-//        }
-//        $use_desc = isset($this->post['use_desc'])&&$this->post['use_desc']!==""?trim($this->post['use_desc']):"";
-//        if($use_desc===""){
-//            return error_show(1004,"参数use_desc不能为空");
-//        }
-//        $remark = isset($this->post['remark'])&&$this->post['remark']!==""?trim($this->post['remark']):"";
-//        if($remark===""){
-//            return error_show(1004,"参数remark不能为空");
-//        }
-//
-//        Db::startTrans();
-//        try{
-//                $infoNo=makeNo("INF");
-//                $info=[
-//                    "infoNo"=>$infoNo,
-//                    "zxNo"=>$zxNo,
-//                    "spuCode"=>"",
-//                    "good_name"=>$good_name,
-//                    "good_img"=>$good_img,
-//                    "cat_id"=>$cat_id,
-//                    "unit"=>$unit,
-//                    "brand_id"=>$brand_id,
-//                    "arrival_time"=>$arrival_time,
-//                    "model"=>$model,
-//                    "color"=>$color,
-//                    "material"=>$material,
-//                    "cost_desc"=>$cost_desc,
-//                    "is_addrs"=>$is_addrs,
-//                    "is_custom"=>$is_custom,
-//                    "metal_id"=>$metal_id,
-//                    "config"=>isset($config)?$config:"",
-//                    "other_config"=>isset($other_config)?$other_config:"",
-//                    "specs_weight"=>isset($specs_weight)?$specs_weight:0,
-//                    "gold_price"=>isset($gold_price)?$gold_price:0,
-//                    "budget_price"=>$budget_price,
-//                    "num"=>$num,
-//                    "use_desc"=>$use_desc,
-//                    "remark"=>$remark,
-//                    "status"=>0,
-//                    "is_del"=>0,
-//                    "addtime"=>date("Y-m-d H:i:s"),
-//                    "updatetime"=>date("Y-m-d H:i:s")
-//                ];
-//                $up = Db::name("consult_info")->insert($info);
-//                if($up){
-//                    Db::commit();
-//                    return app_show(0,"添加成功",["infoNo"=>$infoNo]);
-//                }else{
-//                    Db::rollback();
-//                    return error_show(1004,'添加失败');
-//                }
-//        }catch (\Exception $e){
-//            Db::rollback();
-//            return error_show(1004,$e->getMessage());
-//        }
-//    }
+
+    
 
     public function zxinfo(){
         $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
@@ -491,14 +358,6 @@ class Consult extends Base
         if($specin==""){
             return error_show(1003,"参数specinfo不能为空");
         }
-//        $color= isset($this->post['color'])&&$this->post['color']!=""?trim($this->post['color']):"";
-//        if($color==""){
-//            return error_show(1003,"参数color不能为空");
-//        }
-//        $material= isset($this->post['material'])&&$this->post['material']!=""?trim($this->post['material']):"";
-//        if($material==""){
-//            return error_show(1003,"参数material不能为空");
-//        }
         $cost_desc= isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""?trim($this->post['cost_desc']):"";
         if($cost_desc==""){
             return error_show(1003,"参数cost_desc不能为空");
@@ -538,6 +397,10 @@ class Consult extends Base
         if($remark==""){
             return error_show(1003,"参数remark不能为空");
         }
+        $endtime = isset($this->post['endtime'])&& $this->post['endtime']!="" ? trim($this->post['endtime']):"";
+        if($endtime==""){
+            return error_show(1003,"参数endtime不能为空");
+        }
         if($metal_id!=0){
             if($config==""){
                 return error_show(1003,"参数config不能为空");
@@ -571,8 +434,9 @@ class Consult extends Base
         $createrid= isset($user["data"]['id']) ?  $user["data"]['id'] : "";
         $creater= isset($user["data"]['nickname']) ?  $user["data"]['nickname'] : "";
         $bidlist = Db::name("consult_bids")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->select();
+        Db::startTrans();
         try{
-            $innew =makeNo("INF");
+            $innew =makeNo("IF");
             $info=[
                 "infoNo"=>$innew,
                 "zxNo"=>$zxinfo['zxNo'],
@@ -604,7 +468,8 @@ class Consult extends Base
                 "status"=>1,
                 "is_del"=>0,
                 "addtime"=>date("Y-m-d H:i:s"),
-                "updatetime"=>date("Y-m-d H:i:s")
+                "updatetime"=>date("Y-m-d H:i:s"),
+                'bargain_status'=>1
             ];
             $up = Db::name("consult_info")->insert($info);
             if($up){
@@ -613,7 +478,7 @@ class Consult extends Base
                         unset($value['id']);
                         $value['infoNo']=$innew;
                         $value['bidNo']=makeNo("BD");
-                        $value['spuCode']=makeNo("SPU");
+                        $value['spuCode']=makeNo("SKU");
                         $value['status'] =0;
                         $value['updatetime'] =date("Y-m-d H:i:s");
                         $in = Db::name("consult_bids")->insert($value);
@@ -631,6 +496,10 @@ class Consult extends Base
                     Db::rollback();
                     return error_show(1004,"反馈商品更新失败");
                 }
+
+                //更新consule_order记录
+                Db::name('consult_order')->where('zxNo',$zxinfo['zxNo'])->update(['endtime'=>$endtime,'updatetime'=>date('Y-m-d H:i:s')]);
+
                 Db::commit();
                 return app_show(0,"咨询新建成功",["infoNo"=>$innew]);
             }
@@ -661,6 +530,7 @@ class Consult extends Base
         $zxinfo['updatetime']=date("Y-m-d H:i:s");
         $up = Db::name("consult_info")->save($zxinfo);
         if($up){
+
             return app_show(0,"状态更新成功");
         }else{
             return error_show(1003,"状态更新失败");
@@ -731,8 +601,8 @@ class Consult extends Base
         $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"";
         $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"";
         $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"";
-        if($nake_fee==="" ||$nake_fee==0 ){
-            return error_show(1004,"参数nake_fee不能为空或零");
+        if($nake_fee===""  ){
+            return error_show(1004,"参数nake_fee不能为空");
             }
         $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
         $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
@@ -748,9 +618,28 @@ class Consult extends Base
         $createrid= isset($user["data"]['id']) ?  $user["data"]['id'] : "";
         $creater= isset($user["data"]['nickname']) ?  $user["data"]['nickname'] : "";
         $bidNo=makeNo("BD");
-        $spucode=makeNo("SPU");
+        $spucode=makeNo("SKU");
         $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
         $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
+
+        //部分参数的大小校验
+        $vali = Validate::rule([
+            'expire_day|有效时长'=>'require|elt:214748364',
+            'delivery_day|物流时长'=>'require|elt:214748364',
+            'work_day|生产工期'=>'require|elt:214748364',
+            'weight|总重量'=>'require|max:10',
+        ]);
+
+        $temp = [
+            'expire_day'=>$expire_day,
+            'delivery_day'=>$delivery_day,
+            'work_day'=>$work_day,
+            'weight'=>$weight,
+        ];
+
+        if(!$vali->check($temp)) return error_show(0,$vali->getError());
+
+
         if($is_gold_price==1){
             $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
                 ->find();
@@ -878,11 +767,14 @@ class Consult extends Base
                                 $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
                                     ->count();
                                 if($count==0){
-                                    $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
-                                    (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
-                                    if($proc==false){
-                                        Db::rollback();
-                                        return error_show(1006,"项目反馈失败");
+                                    $projetc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->find();
+                                    if($projetc!=false){
+                                        $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
+                                        (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
+                                        if($proc==false){
+                                            Db::rollback();
+                                            return error_show(1006,"项目反馈失败");
+                                        }
                                     }
                                 }
                             }
@@ -1167,6 +1059,16 @@ class Consult extends Base
         if(empty($user)||$user['code']!=0){
             return error_show(1002,"用户数据不存在");
         }
+        //新增两个字段
+        //议价备注
+        $bargain_remark = isset($this->post['bargain_remark']) && $this->post['bargain_remark'] != "" ? trim($this->post['bargain_remark']) : "";
+        //议价原因id
+        $result_info_id = isset($this->post['result_info_id']) && $this->post['result_info_id'] != "" ? $this->post['result_info_id'] : "";
+        if ($result_info_id != '') {
+            $temp = Db::name('result_info')->field('id')->where(['result_code' => $result_info_id, 'type' => 7, 'status' => 1, 'is_del' => 0])->find();//type 7议价原因
+            if (empty($temp)) return error_show(1004, "议价原因选择不正确");
+        }
+
         $createrid= isset($user["data"]['id']) ?  $user["data"]['id'] : "";
         $creater= isset($user["data"]['nickname']) ?  $user["data"]['nickname'] : "";
         $bargainNo =makeNo("BA");
@@ -1191,7 +1093,9 @@ class Consult extends Base
                 "creater"=>$creater,
                 "createrid"=>$createrid,
                 "addtime"=>date("Y-m-d H:i:s"),
-                "updatetime"=>date("Y-m-d H:i:s")
+                "updatetime"=>date("Y-m-d H:i:s"),
+                'bargain_remark'=>$bargain_remark,
+                'result_info_id'=>$result_info_id,
             ];
             $int = Db::name("bargain_order")->insert($data);
             if($int){
@@ -1421,6 +1325,13 @@ class Consult extends Base
         $info['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
         $info['sale_price'] =round($bidinfos['sale_price'],2);
         $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
+
+        //获取议价原因
+        if ($info['result_info_id'] != 0) {
+            $info['result_info'] = Db::name('result_info')->where(['result_code' => $info['result_info_id'], 'type' => 7, 'status' => 1, 'is_del' => 0])->value('result');
+        } else {
+            $info['result_info'] = '';
+        }
         return app_show(0,"获取成功",$info);
     }
 
@@ -1456,6 +1367,17 @@ class Consult extends Base
             ("zxNo");
             $where[] = ['zxNo','in',$zxlist];
         }
+
+        $token = isset($this->post['token']) ? trim($this->post['token']) : "";
+        if($token==""){
+            return error_show(101,'token不能为空');
+        }
+        $apply_id =GetUserInfo($token);
+        if(empty($apply_id)||$apply_id['code']!=0){
+            return error_show(1002,"申请人数据不存在");
+        }
+        $rm= isset($apply_id["data"]['id']) ?  $apply_id["data"]['id'] : "";
+        $where[]=['createrid',"=",$rm];
         $count = Db::name('consult_bids')->where($where)->count();
         $total = ceil($count / $size);
         $page = $page >= $total ? $total : $page;
@@ -1526,13 +1448,14 @@ class Consult extends Base
         if($token==''){
             return error_show(102,"参数token不能为空");
         }
-        $user =GetUserInfo($token);
-        if(empty($user)||$user['code']!=0){
-            return error_show(105,"用户数据不存在");
-        }
-        $createrid= isset($user["data"]['id']) ?  $user["data"]['id'] : "";
-        $creater= isset($user["data"]['nickname']) ?  $user["data"]['nickname'] : "";
-        $where[] = ["createrid","=",$createrid];
+//        $user =GetUserInfo($token);
+//        if(empty($user)||$user['code']!=0){
+//            return error_show(105,"用户数据不存在");
+//        }
+
+//        $createrid= isset($user["data"]['id']) ?  $user["data"]['id'] : "";
+//        $creater= isset($user["data"]['nickname']) ?  $user["data"]['nickname'] : "";
+//        $where[] = ["createrid","=",$createrid];
         $list =Db::name('consult_bids')->where($where)->select();
         $data=[];
         foreach ($list as $value){
@@ -1607,7 +1530,7 @@ class Consult extends Base
         $count=Db::name("bargain_order")->where($where)->count();
         $total = ceil($count / $size);
         $page = $page >= $total ? $total : $page;
-        $list =Db::name('bargain_order')->where($where)->page($page,$size)->select();
+        $list =Db::name('bargain_order')->where($where)->page($page,$size)->order('addtime','desc')->select();
         $data=[];
         foreach ($list as $value){
            $bidinfos =   Db::name("consult_bids")->where([["bidNo","=",$value['bidsNo']],["is_del","=",0]])->find();

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

@@ -7,6 +7,7 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 
+//客户
 class Customar extends BaseController
 {
     public $post = "";

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

@@ -7,6 +7,7 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 
+//客户的组织架构
 class Customer extends BaseController
 {
     public $post = "";

+ 2 - 0
app/admin/controller/Departuser.php

@@ -6,6 +6,8 @@ use app\admin\model\ActionLog;
 use app\BaseController;
 use think\App;
 use think\facade\Db;
+
+//部门
 class Departuser extends BaseController
 {
     public $post = "";

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

@@ -7,6 +7,7 @@ namespace app\admin\controller;
 use think\App;
 use think\facade\Db;
 
+//泰康专属的一个列表
 class Exclusive extends Base
 {
     public function __construct(App $app)

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

@@ -6,6 +6,7 @@ use app\admin\model\ActionLog;
 use think\App;
 use think\facade\Db;
 
+//物流信息
 class Express extends \app\BaseController
 {
     public $post='';

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

@@ -8,6 +8,7 @@ use app\admin\model\ActionLog;
 use think\App;
 use think\facade\Db;
 
+//金价
 class Gold extends \app\BaseController
 {
     public $post=[];

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

@@ -6,6 +6,7 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 
+//金价
 class Goldprice extends BaseController
 {
     public $post="";

+ 396 - 260
app/admin/controller/Good.php

@@ -6,33 +6,35 @@ namespace app\admin\controller;
 use app\admin\model\GoodLog;
 use think\App;
 use think\facade\Db;
+
+//线上商品
 class Good extends Base
 {
 
-        private $acton=[
-            "allotsend"=>'调拨发货',
-            "allotin"=>'调拨入库',
-            "allotincheck"=>'调拨验货',
-            'CGD'=>'采购单',
-            'BHD'=>'备库单',
-            'FKD'=>'备库反馈单',
-            'RKD'=>'入库单',
-            'ZXQRD'=>'咨询单',
-            'XSQRD'=>'销售单',
-            'PDD'=>'盘点单',
-            'DBD'=>'调拨单',
-            'CKD'=>'出库单',
-            'CGTHD'=>'采购退货单',
-            'XSTHD'=>'销售退货单',
-            'CGGCD'=>'采购工差单',
-            'ZXGCD'=>'咨询工差单'
-        ];
-        public $noble=[];
-        public function __construct(App $app)
-        {
-            parent::__construct($app);
-            $this->noble=\think\facade\Config::get("noble");
-        }
+    private $acton=[
+        "allotsend"=>'调拨发货',
+        "allotin"=>'调拨入库',
+        "allotincheck"=>'调拨验货',
+        'CGD'=>'采购单',
+        'BHD'=>'备库单',
+        'FKD'=>'备库反馈单',
+        'RKD'=>'入库单',
+        'ZXQRD'=>'咨询单',
+        'XSQRD'=>'销售单',
+        'PDD'=>'盘点单',
+        'DBD'=>'调拨单',
+        'CKD'=>'出库单',
+        'CGTHD'=>'采购退货单',
+        'XSTHD'=>'销售退货单',
+        'CGGCD'=>'采购工差单',
+        'ZXGCD'=>'咨询工差单'
+    ];
+    public $noble=[];
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        $this->noble=\think\facade\Config::get("noble");
+    }
 
     public function list(){
         $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
@@ -49,8 +51,8 @@ class Good extends Base
         $skucode = isset($this->post['spucode']) && $this->post['spucode'] !=="" ? trim($this->post['spucode'])
             :"";
         if($skucode!==""){
-          $where [] = ['b.skucode',"like","%$skucode%"];
-         }
+            $where [] = ['b.skucode',"like","%$skucode%"];
+        }
         $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
         if($start!==""){
             $where[]=['a.addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
@@ -118,7 +120,7 @@ class Good extends Base
         $total = ceil($count / $size);
         $page = $page >= $total ? $total : $page;
         $list = Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->where($where)->page
-            ($page,$size)->field("b.skuCode,b.platform_code,b.plat_code,b.id as good_id,a.*,b.addtime,b.updatetime,b.exam_status")
+        ($page,$size)->field("b.skuCode,b.platform_code,b.plat_code,b.id as good_id,a.*,b.addtime,b.updatetime,b.exam_status")
             ->order("b.addtime desc")
             ->select();
         $data=[];
@@ -162,30 +164,30 @@ class Good extends Base
     }
 
     public function info(){
-            $skucode=isset($this->post['skuCode'])&&$this->post['skuCode']!=""?trim($this->post['skuCode']):"";
-            if($skucode==""){
-                return error_show(1005,"参数skuCode不能为空");
-            }
-            $good_platform = Db::name("good_platform")->where(['skuCode'=>$skucode,"is_del"=>0])->find();
-            if($good_platform==false){
-              return error_show(1004,"未找到商品数据");
-            }
-            $data = Db::name("good")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->find();
-            if($data==false){
-                return error_show(1004,"未找到商品数据");
-            }
-            $plat =Db::name("platform")->where(["id"=>$good_platform['platform_code']])->find();
-            $data['skuCode']=$good_platform['skuCode'];
-            $data['platform_code']=$good_platform['id'];
-            $data['platform_code_en']=isset($plat['platform_code'])?$plat['platform_code']:"";
-            $data['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
-            $data['online_reason']=$good_platform['online_reason'];
-            $data['online_time']=$good_platform['online_time'];
-            $data['online_remark']=$good_platform['online_remark'];
-            $data['exam_status']=$good_platform['exam_status'];
-            $data['is_online']=$good_platform['is_online'];
-            $data['plat_code']=$good_platform['plat_code'];
-            $data['exclusive']=makeExcluse($data['is_exclusive']);
+        $skucode=isset($this->post['skuCode'])&&$this->post['skuCode']!=""?trim($this->post['skuCode']):"";
+        if($skucode==""){
+            return error_show(1005,"参数skuCode不能为空");
+        }
+        $good_platform = Db::name("good_platform")->where(['skuCode'=>$skucode,"is_del"=>0])->find();
+        if($good_platform==false){
+            return error_show(1004,"未找到商品数据");
+        }
+        $data = Db::name("good")->where(["spuCode"=>$good_platform['spuCode'],"is_del"=>0])->find();
+        if($data==false){
+            return error_show(1004,"未找到商品数据");
+        }
+        $plat =Db::name("platform")->where(["id"=>$good_platform['platform_code']])->find();
+        $data['skuCode']=$good_platform['skuCode'];
+        $data['platform_code']=$good_platform['id'];
+        $data['platform_code_en']=isset($plat['platform_code'])?$plat['platform_code']:"";
+        $data['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
+        $data['online_reason']=$good_platform['online_reason'];
+        $data['online_time']=$good_platform['online_time'];
+        $data['online_remark']=$good_platform['online_remark'];
+        $data['exam_status']=$good_platform['exam_status'];
+        $data['is_online']=$good_platform['is_online'];
+        $data['plat_code']=$good_platform['plat_code'];
+        $data['exclusive']=makeExcluse($data['is_exclusive']);
         $unit =Db::name("unit")->where(["id"=>$data['good_unit']])->find();
         $data['unit'] = isset($unit['unit'])?$unit['unit']:'';
         $data['cat_info'] = made($data['cat_id'],[]);
@@ -239,7 +241,7 @@ class Good extends Base
         $data["ladderlist"]=!empty($ladder)?$ladder:[];
         $nakelist = Db::name("good_nake")->where(['spuCode'=>$good_platform['spuCode'],"is_del"=>0])->select()->toArray();
         $catinfo = Db::name("cat")->where(["id"=>$data['cat_id']])->find();
-       // $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
+        // $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
         $nakearry=[];
         if(!empty($nakelist)){
             foreach ($nakelist as $value){
@@ -255,39 +257,39 @@ class Good extends Base
 
 
     public function SetWarn(){
-            $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;
-            }else{
-                return error_show(1004,"参数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;
-            }else{
-                return error_show(1004,"参数type_code 不能为空");
-            }
-           $good= Db::name("good_stock")->where($condition)->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);
-            if($up){
-                $data=["stock_id"=>$good['id'],"type"=>1,'stock'=>$warn_stock,"stock_name"=>"warn_stock"];
-                GoodLog::LogAdd($this->post['token'],$data,'setwarn');
-
-                return app_show(0,"预警库存更新成功");
-            }else{
-                return error_show(1005,"预警库存更新失败");
-            }
+        $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;
+        }else{
+            return error_show(1004,"参数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;
+        }else{
+            return error_show(1004,"参数type_code 不能为空");
+        }
+        $good= Db::name("good_stock")->where($condition)->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);
+        if($up){
+            $data=["stock_id"=>$good['id'],"type"=>1,'stock'=>$warn_stock,"stock_name"=>"warn_stock"];
+            GoodLog::LogAdd($this->post['token'],$data,'setwarn');
+
+            return app_show(0,"预警库存更新成功");
+        }else{
+            return error_show(1005,"预警库存更新失败");
         }
+    }
 
     public function SetStatus(){
         $id = isset($this->post['id']) &&$this->post['id'] !=="" ? intval($this->post['id']):"";
@@ -309,7 +311,7 @@ class Good extends Base
         $condition = [["a.is_del","=",0]];
         $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
         if($type_code!==""){
-          $condition[]=["a.good_type_code","=",$type_code];
+            $condition[]=["a.spuCode","=",$type_code];
         }
         $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code'])
             :"";
@@ -323,12 +325,12 @@ class Good extends Base
             $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
             $condition[]=["a.wsm_code","in",$wsmcode];
         }
-       $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($condition)->field("a.id,b.name as wsm_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();
+        $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($condition)->field("a.id,b.name as wsm_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();
         if(empty($list)){
             return error_show(1004,"未找到数据");
         }
-     return app_show(0,"获取成功",$list);
+        return app_show(0,"获取成功",$list);
     }
 
     /**
@@ -337,77 +339,107 @@ class Good extends Base
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-  public function GetStockBet(){
-      $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;
-      $condition = [["is_del","=",0]];
-      $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
-      if($type_code!==""){
-          $condition[]=["good_type_code","like","%{$type_code}%"];
-      }
-      $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code'])
-          :"";
-      if($wsm_code!==""){
-          $condition[]=["wsm_code","=",$wsm_code];
-      }
-      $suplierNo = isset($this->post['suplierNo']) &&$this->post['suplierNo'] !=="" ? trim($this->post['suplierNo'])
-          :"";
-      if($suplierNo!==""){
-          $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
-          $condition[]=["wsm_code","in",$wsmcode];
-      }
-      $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
-      if ($companyNo !== "") {
-          $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
-          $condition[]=["wsm_code","in",$wsmcode];
-      }
-      $start = isset($this->post['start']) &&$this->post['start'] !=="" ? $this->post['start']:"";
-      $end = isset($this->post['end']) &&$this->post['end'] !=="" ? $this->post['end']:"";
-      if($start!=""){
-          $condition[]=["addtime",">=",$start];
-      }
-      if($end!=""){
-          $condition[]=["addtime","<=",$end];
-      }
-      $count = Db::name("good_stock")->where($condition)->count();
-      $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
-      $list = Db::name("good_stock")->where($condition)->page($page,$size)->order("addtime desc")->select();
-      $data=[];
-      foreach ($list as $key=>$value){
-          $temp=[];
-          if($value['wsm_code']!=""){
-              $wsm = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")->where
-              (['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])->field("a.name as wsm_name,wsm_code,b.code,b.name")
-                  ->find();
-          }
-          $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:"";
-          $temp['wsm_code']=$value['wsm_code'];
-          $temp['supplier_code']=isset($wsm['code'])?$wsm['code']:"";
-          $temp['supplier_name']=isset($wsm['name'])?$wsm['name']:"";
-          if($value['spuCode']!=""){
-              $good=Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
-          }
-          $temp['good_code']=isset($good['spuCode'])?$good['spuCode']:"";
-        //  $temp['type_code']=isset($good['type_code'])?$good['type_code']:"";
-          $temp['good_name']=isset($good['good_name'])?$good['good_name']:"";
-          $temp['unit']=isset($good['unit'])?$good['unit']:"";
-        //  $temp['attribute']=isset($good['attribute'])?$good['attribute']:"";
-          $temp['sort_f']=isset($good['cat_id'])?$good['cat_id']:"";
-          $temp['cat_info']=isset($good['cat_id'])?made($good['cat_id']):"";
-          $temp['usable_stock'] = $value['usable_stock'];
-          $temp['wait_in_stock'] = $value['wait_in_stock'];
-          $temp['wait_out_stock'] = $value['wait_out_stock'];
-          $temp['intra_stock'] = $value['intra_stock'];
-          $temp['total_stock'] = $value['total_stock'];
-          $temp['warn_stock'] = $value['warn_stock'];
-          $temp['id'] = $value['id'];
-          $temp['out_total'] =0;
-          $temp['in_total'] = 0;
-          $temp['addtime'] = $value['addtime'];
-          $data[]=$temp;
-      }
-      return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
-  }
+    public function GetStockBet(){
+        $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;
+        $condition = [["is_del","=",0]];
+        $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
+        if($type_code!==""){
+            $condition[]=["spuCode","like","%{$type_code}%"];
+        }
+        $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code'])
+            :"";
+        if($wsm_code!==""){
+            $condition[]=["wsm_code","=",$wsm_code];
+        }
+        $suplierNo = isset($this->post['suplierNo']) &&$this->post['suplierNo'] !=="" ? trim($this->post['suplierNo']):"";
+        if($suplierNo!==""){
+            $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
+            $condition[]=["wsm_code","in",$wsmcode];
+        }
+        $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
+        if ($companyNo !== "") {
+            $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
+            $condition[]=["wsm_code","in",$wsmcode];
+        }
+        $start = isset($this->post['start']) &&$this->post['start'] !=="" ? $this->post['start']:"";
+        $end = isset($this->post['end']) &&$this->post['end'] !=="" ? $this->post['end']:"";
+        if($start!=""){
+            $condition[]=["addtime",">=",$start];
+        }
+        if($end!=""){
+            $condition[]=["addtime","<=",$end];
+        }
+        $count = Db::name("good_stock")->where($condition)->count();
+        $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
+        $list = Db::name("good_stock")->where($condition)->page($page,$size)->order("addtime desc")->select();
+        $data=[];
+        foreach ($list as $key=>$value){
+            $temp=[];
+            if($value['wsm_code']!=""){
+                $wsm = Db::name("warehouse_info")
+                    ->alias("a")
+                    ->leftJoin("supplier b","a.supplierNo=b.code")
+                    ->leftJoin("business bus","a.companyNo=bus.companyNo")
+                    ->where(['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])
+                    ->field("a.name as wsm_name,wsm_code,a.supplierNo,b.name supplierName,a.companyNo,bus.company")
+                    ->find();
+            }
+            $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:"";
+            $temp['wsm_code']=$value['wsm_code'];
+            $temp['supplier_code']=isset($wsm['supplierNo'])?$wsm['supplierNo']:"";
+            $temp['supplier_name']=isset($wsm['supplierName'])?$wsm['supplierName']:"";
+            $temp['company_no']=isset($wsm['companyNo'])?$wsm['companyNo']:"";
+            $temp['company_name']=isset($wsm['company'])?$wsm['company']:"";
+            if($value['spuCode']!=""){
+                $good=Db::name("good")
+                    ->alias('g')
+                    ->field('g.*,b.brand_name,u.unit')
+                    ->where(["g.spuCode"=>$value['spuCode'],"g.is_del"=>0])
+                    ->leftJoin('brand b','b.id=g.brand_id')
+                    ->leftJoin('unit u','u.id=g.good_unit')
+                    ->find();
+
+                //规格信息
+                $spec = Db::name("good_spec")->field('id,spec_id,spec_value_id')->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
+
+                $speclist = [];
+                if (!empty($spec)) {
+                    foreach ($spec as $val) {
+                        $tmp = [];
+                        $tmp['spec_id'] = $val['spec_id'];
+                        $tmp['spec_value_id'] = $val['spec_value_id'];
+                        $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
+                        $tmp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
+                        $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
+                        $tmp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
+                        $speclist[] = $tmp;
+                    }
+                }
+                $temp['specinfo'] = $speclist;
+            }
+            $temp['good_code']=isset($good['spuCode'])?$good['spuCode']:"";
+            //  $temp['type_code']=isset($good['type_code'])?$good['type_code']:"";
+            $temp['good_name']=isset($good['good_name'])?$good['good_name']:"";
+            $temp['unit']=isset($good['unit'])?$good['unit']:"";
+            $temp['brand_name']=isset($good['brand_name'])?$good['brand_name']:"";
+            //  $temp['attribute']=isset($good['attribute'])?$good['attribute']:"";
+            $temp['sort_f']=isset($good['cat_id'])?$good['cat_id']:"";
+            $temp['cat_info']=isset($good['cat_id'])?made($good['cat_id']):"";
+            $temp['usable_stock'] = $value['usable_stock'];
+            $temp['wait_in_stock'] = $value['wait_in_stock'];
+            $temp['wait_out_stock'] = $value['wait_out_stock'];
+            $temp['intra_stock'] = $value['intra_stock'];
+            $temp['total_stock'] = $value['total_stock'];
+            $temp['warn_stock'] = $value['warn_stock'];
+            $temp['id'] = $value['id'];
+            $temp['out_total'] =0;
+            $temp['in_total'] = 0;
+            $temp['addtime'] = $value['addtime'];
+            $data[]=$temp;
+        }
+        return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
+    }
 
     /**
      * @return \think\response\Json|void
@@ -416,105 +448,185 @@ class Good extends Base
      * @throws \think\db\exception\ModelNotFoundException
      * @throws \think\exception\DbException
      */
-  public function GetStockWsm(){
-      $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;
-      $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];
-      }
-      $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
-          :"";
-      if($suplierNo!==""){
-          $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
-          $condition[]=["wsm_code","in",$wsmcode];
-      }
-      $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
-      if ($companyNo !== "") {
-          $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
-          $condition[]=["wsm_code","in",$wsmcode];
-      }
-      $build= Db::name("good_stock")->where($condition)->group("wsm_code")->field("wsm_code")->buildSql();
-      $count = Db::table($build." a")->count();
-      $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
-      $list = Db::name("good_stock")->where($condition)->page($page,$size)->group("wsm_code")
-          ->field("wsm_code,sum(wait_in_stock) wait_in_stock,sum(wait_out_stock) wait_out_stock,sum(usable_stock) usable_stock,
-          sum(intra_stock) intra_stock,sum(warn_stock) warn_stock,sum(total_stock) total_stock")->select();
-      $data=[];
-      foreach ($list as $key=>$value){
-          $temp=[];
-          if($value['wsm_code']!=""){
-              $wsm = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")->where
-              (['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])->field("a.name as wsm_name,wsm_code,b.code,b.name")
-                  ->find();
-              $good = Db::name("good_stock")->alias("a")
-                  ->join("good c","c.spuCode=a.spuCode","left")->where(["a.wsm_code"=>$value['wsm_code'],"a
-                  .is_del"=>0,"c.is_del"=>0])->select();
-          }
-          $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:"";
-          $temp['wsm_code']=$value['wsm_code'];
-          $temp['supplier_code']=isset($wsm['code'])?$wsm['code']:"";
-          $temp['supplier_name']=isset($wsm['name'])?$wsm['name']:"";
-          $temp['usable_stock'] = $value['usable_stock'];
-          $temp['wait_in_stock'] = $value['wait_in_stock'];
-          $temp['wait_out_stock'] = $value['wait_out_stock'];
-          $temp['intra_stock'] = $value['intra_stock'];
-          $temp['total_stock'] = $value['total_stock'];
-         // $temp['warn_stock'] = $value['warn_stock'];
-          $temp['child']=isset($good)&&!empty($good) ? $good:[];
-          $data[]=$temp;
-      }
-      return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
-  }
-
-    public function GetStockGod(){
+    public function GetStockWsm(){
         $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;
-        $condition = [["a.is_del","=",0],["b.is_del","=",0],["c.usable_stock",">",0]];
-        $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code'])
-            :"";
-        if($type_code!==""){
-            $condition[]=["b.type_code","like","%{$type_code}%"];
+        $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];
+        }
+        $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
+        if($suplierNo!==""){
+            $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"is_del"=>0])->column("wsm_code");
+            $condition[]=["wsm_code","in",$wsmcode];
         }
-        $count = Db::name("good_type")->alias("b")
-            ->join("good a","a.good_code = b.good_code","left")
-            ->join("good_stock c","c.good_type_code = b.type_code","left")
-            ->where($condition)->group("a.good_code,a.good_name,a.unit,a.sort_f,b.type_code,b.attribute,a.addtime")->count();
+        $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
+        if ($companyNo !== "") {
+            $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
+            $condition[]=["wsm_code","in",$wsmcode];
+        }
+        $build= Db::name("good_stock")->where($condition)->group("wsm_code")->field("wsm_code")->buildSql();
+        $count = Db::table($build." a")->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")
-            ->join("good_stock c","c.good_type_code = b.type_code","left")
-            ->where($condition)->field("a.good_code,a.good_name,a.unit,a.sort_f,b.type_code,b.attribute,a.addtime,sum(c.wait_in_stock) wait_in_stock,
-                sum(c.wait_out_stock) wait_out_stock,sum(c.usable_stock) usable_stock,sum(c.intra_stock) intra_stock,sum(c.warn_stock) warn_stock,sum(c.total_stock) total_stock")
-            ->page($page,$size)->order("a.addtime desc")->group("a.good_code,a.good_name,a.unit,a.sort_f,b.type_code,b.attribute,a.addtime")->select();
-       // echo Db::name("good_type")->getLastSql();
+        $list = Db::name("good_stock")
+            ->where($condition)
+            ->page($page,$size)
+            ->group("wsm_code")
+            ->field("wsm_code,sum(wait_in_stock) wait_in_stock,sum(wait_out_stock) wait_out_stock,sum(usable_stock) usable_stock,sum(intra_stock) intra_stock,sum(warn_stock) warn_stock,sum(total_stock) total_stock")
+            ->select()
+            ->toArray();
         $data=[];
         foreach ($list as $key=>$value){
             $temp=[];
-            if($value['type_code']!=""){
-                $child = Db::name("good_stock")->alias("a")->join("warehouse_info b","a.wsm_code=b.wsm_code","left")
-                    ->where(['a.good_type_code'=>$value['type_code'],"b.wsm_type"=>1,"a.is_del"=>0])->field("a.wsm_code,b.name wsm_name,a.wait_in_stock,a.wait_out_stock,a.usable_stock,a.intra_stock,a.total_stock,a.warn_stock")->select();
+            if($value['wsm_code']!=""){
+                $wsm = Db::name("warehouse_info")
+                    ->alias("a")
+                    ->leftJoin("business bus", "bus.companyNo=a.companyNo")
+                    ->leftJoin("supplier b","a.supplierNo=b.code")
+                    ->where(['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])
+                    ->field("a.name as wsm_name,wsm_code,a.supplierNo,b.name supplierName,a.companyNo,bus.company")
+                    ->find();
+                $good = Db::name("good_stock")
+                    ->alias("a")
+                    ->leftJoin("good c","c.spuCode=a.spuCode")
+                    ->where(["a.wsm_code"=>$value['wsm_code'],"a.is_del"=>0,"c.is_del"=>0])
+                    ->select()
+                    ->toArray();
+
+                //商品单位和品牌
+                $good_unit_s = Db::name("unit")->whereIn('id', array_column($good, 'good_unit'))->where('is_del', 0)->column('unit', 'id');
+                $brands = Db::name("brand")->whereIn('id', array_column($good, 'brand_id'))->where('is_del', 0)->column('brand_name', 'id');
+
+                foreach ($good as &$item_good){
+                    //规格信息
+                    $spec = Db::name("good_spec")->field('id,spec_id,spec_value_id')->where(["spuCode" => $item_good['spuCode'], "is_del" => 0])->select()->toArray();
+
+                    $speclist = [];
+                    if (!empty($spec)) {
+                        foreach ($spec as $val) {
+                            $tmp = [];
+                            $tmp['spec_id'] = $val['spec_id'];
+                            $tmp['spec_value_id'] = $val['spec_value_id'];
+                            $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
+                            $tmp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
+                            $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
+                            $tmp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
+                            $speclist[] = $tmp;
+                        }
+                    }
+                    $item_good['specinfo'] = $speclist;
+                    $item_good['unit'] = $good_unit_s[$item_good['good_unit']]??'';
+                    $item_good['brand_name'] = $brands[$item_good['brand_id']]??'';
+                }
+
+
             }
-            $temp['good_name'] = $value['good_name'];
-            $temp['good_code'] = $value['good_code'];
-            $temp['type_code'] = $value['type_code'];
-            $temp['unit'] = $value['unit'];
-            $temp['sort_f']=$value['sort_f'];
-            $temp['attribute']=$value['attribute'];
-            $temp['addtime']=$value['addtime'];
-            $temp['usable_stock'] = isset($value['usable_stock'])? $value['usable_stock']:"";
-            $temp['wait_in_stock'] = isset($value['wait_in_stock'])? $value['wait_in_stock']:"";
-            $temp['wait_out_stock'] = isset($value['wait_out_stock'])? $value['wait_out_stock']:"";
-            $temp['intra_stock'] = isset($value['intra_stock'])? $value['intra_stock']:"";
-            $temp['total_stock'] = isset($value['total_stock'])? $value['total_stock']:"";
-           // $temp['warn_stock'] = isset($value['warn_stock'])? $value['warn_stock']:"";
-            $temp['child']=isset($child)&&!empty($child) ? $child:[];
+            $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:"";
+            $temp['wsm_code']=$value['wsm_code'];
+            $temp['supplier_code']=isset($wsm['supplierNo'])?$wsm['supplierNo']:"";
+            $temp['supplier_name']=isset($wsm['supplierName'])?$wsm['supplierName']:"";
+            $temp['company_no']=isset($wsm['companyNo'])?$wsm['companyNo']:"";
+            $temp['company_name']=isset($wsm['company'])?$wsm['company']:"";
+            $temp['usable_stock'] = $value['usable_stock'];
+            $temp['wait_in_stock'] = $value['wait_in_stock'];
+            $temp['wait_out_stock'] = $value['wait_out_stock'];
+            $temp['intra_stock'] = $value['intra_stock'];
+            $temp['total_stock'] = $value['total_stock'];
+            // $temp['warn_stock'] = $value['warn_stock'];
+            $temp['child']=isset($good)&&!empty($good) ? $good:[];
             $data[]=$temp;
         }
         return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
     }
+
+    public function GetStockGod(){
+        $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;
+        $condition = [["b.is_del","=",0],["c.usable_stock",">",0]];
+        $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
+        if($type_code!==""){
+            $condition[]=["b.spuCode","like","%{$type_code}%"];
+        }
+        $count = Db::name("good")->alias("b")
+            ->join("good_stock c","c.spuCode = b.spuCode","left")
+            ->where($condition)
+            ->group("b.spuCode,b.good_name,b.good_unit,b.cat_id,b.craft_desc,b.addtime")
+            ->count();
+        $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
+        $list = Db::name("good")
+            ->alias("b")
+            ->join("good_stock c","c.spuCode = b.spuCode","left")
+            ->where($condition)
+            ->field("b.spuCode,b.good_name,b.good_unit,b.brand_id,b.cat_id,b.craft_desc,b.addtime,sum(c.wait_in_stock) wait_in_stock,sum(c.wait_out_stock) wait_out_stock,sum(c.usable_stock) usable_stock,sum(c.intra_stock) intra_stock,sum(c.warn_stock) warn_stock,sum(c.total_stock) total_stock")
+            ->page($page,$size)
+            ->order("b.addtime desc")
+            ->group("b.spuCode,b.good_name,b.good_unit,b.brand_id,b.cat_id,b.craft_desc,b.addtime")
+            ->select()
+            ->toArray();
+        // echo Db::name("good_type")->getLastSql();
+        $data=[];
+
+        if($list) {
+
+            //商品单位和品牌
+            $good_unit_s = Db::name("unit")->whereIn('id', array_column($list, 'good_unit'))->where('is_del', 0)->column('unit', 'id');
+            $brands = Db::name("brand")->whereIn('id', array_column($list, 'brand_id'))->where('is_del', 0)->column('brand_name', 'id');
+
+            foreach ($list as $key => $value) {
+                $temp = [];
+                if ($value['spuCode'] != "") {
+                    $child = Db::name("good_stock")
+                        ->alias("a")
+                        ->join("warehouse_info b", "a.wsm_code=b.wsm_code", "left")
+                        ->join("business bus", "bus.companyNo=b.companyNo", "left")
+                        ->join("supplier s", "s.code=b.supplierNo", "left")
+                        ->where(['a.spuCode' => $value['spuCode'], "b.wsm_type" => 1, "a.is_del" => 0])
+                        ->field("a.wsm_code,b.name wsm_name,a.wait_in_stock,a.wait_out_stock,a.usable_stock,a.intra_stock,a.total_stock,a.warn_stock,b.supplierNo,s.name supplierName,b.companyNo,bus.company")
+                        ->select()
+                        ->toArray();
+                }
+                $temp['good_name'] = $value['good_name'];
+                $temp['good_code'] = $value['spuCode'];
+                $temp['type_code'] = '';
+//                $unit = Db::name("unit")->where(['id' => $value['good_unit']])->find();
+                $temp['unit'] =$good_unit_s[$value['spuCode']]??'';
+                $temp['brand_name'] =$brands[$value['brand_id']]??'';
+                $temp['sort_f'] = isset($value['cat_id']) ? made($value['cat_id']) : [];
+                $temp['sort_f'] = implode('/', array_column($temp['sort_f'], 'name'));//由于这个字段原样在页面显示,所以在这里特意拼接成字符串
+                $temp['attribute'] = $value['craft_desc'];
+                $temp['addtime'] = $value['addtime'];
+                $temp['usable_stock'] = isset($value['usable_stock']) ? $value['usable_stock'] : "";
+                $temp['wait_in_stock'] = isset($value['wait_in_stock']) ? $value['wait_in_stock'] : "";
+                $temp['wait_out_stock'] = isset($value['wait_out_stock']) ? $value['wait_out_stock'] : "";
+                $temp['intra_stock'] = isset($value['intra_stock']) ? $value['intra_stock'] : "";
+                $temp['total_stock'] = isset($value['total_stock']) ? $value['total_stock'] : "";
+                // $temp['warn_stock'] = isset($value['warn_stock'])? $value['warn_stock']:"";
+                $temp['child'] = isset($child) && !empty($child) ? $child : [];
+
+                //规格信息
+                $spec = Db::name("good_spec")->field('id,spec_id,spec_value_id')->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
+
+                $speclist = [];
+                if (!empty($spec)) {
+                    foreach ($spec as $val) {
+                        $tmp = [];
+                        $tmp['spec_id'] = $val['spec_id'];
+                        $tmp['spec_value_id'] = $val['spec_value_id'];
+                        $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
+                        $tmp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
+                        $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
+                        $tmp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
+                        $speclist[] = $tmp;
+                    }
+                }
+                $temp['specinfo'] = $speclist;
+
+                $data[] = $temp;
+            }
+        }
+        return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
+    }
     /**
      * @return \think\response\Json|void
      * @throws \think\db\exception\DataNotFoundException
@@ -525,7 +637,7 @@ class Good extends Base
         $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;
+            //$condition["wsm_code"] = $wsm_code;
             $condition[]=["wsm_code","=",$wsm_code];
         }
         $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :"";
@@ -580,7 +692,7 @@ class Good extends Base
         $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.cg_saler,a.good_type,a.market_fee,a.gys_code,a.unit,
                 a.sort_f,a.sort_s,a.sort_t,b.color,b.material,b.specs,b.is_main,b.type_code,b.attribute,b.status as bstatus,a.addtime,a.updatetime")
-           ->select();
+            ->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");
@@ -613,21 +725,43 @@ class Good extends Base
             $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
             $condition[]=["b.wsm_code","in",$wsmcode];
         }
-        $count = Db::name("good_log")->alias('a')
-            ->join("good_stock b","b.id=a.id","left")->where($where)->count();
+        $count = Db::name("good_log")
+            ->alias('a')
+            ->join("good_stock b","b.id=a.id","left")
+            ->where($where)
+            ->count();
         $total = ceil($count/$size);
         $page = $total>=$page ? $page :$total;
-        $list = Db::name("good_log")->alias('a')
+        $list = Db::name("good_log")
+            ->alias('a')
             ->join("good_stock b","b.id=a.stock_id","left")
-            ->where($where)->page($page,$size)->order("a.addtime desc")
-            ->field("a.action_name,a.type,a.stock_name,a.stock,a.action_type,b.spuCode,
-            a.addtime,a.action_uid,b.wsm_code")->select();
-       $data=[];
+            ->where($where)
+            ->page($page,$size)
+            ->order("a.addtime desc")
+            ->field("a.good_log_code,a.action_name,a.type,a.stock_name,a.stock,a.action_type,b.spuCode,a.addtime,a.action_uid,b.wsm_code")
+            ->select()
+            ->toArray();
+        $data=[];
+
+        $action_uids = array_column($list, 'action_uid');
+        $action_uids = array_unique($action_uids);
+        $item = [];
+        foreach ($action_uids as $action_uid) {
+            $items = Db::name("depart_user")->where('uid', $action_uid)->column("itemid");
+            foreach ($items as $it) {
+                $item[$action_uid][] = implode('/', array_column(GetPart($it), 'name'));
+            }
+        }
+
         foreach ($list as $value){
-            $db = Db::name("depart_user")->where(['uid'=>$value['action_uid']])->column("itemid");
-            $item = Db::name("company_item")->where(['id'=>$db])->column("id,name");
-            $wsm = Db::name("warehouse_info")->alias("a")->Join("supplier b","a.supplierNo=b.code","left")->where
-            (['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])->field("a.name as wsm_name,wsm_code,b.code,b.name")->find();
+            $wsm = Db::name("warehouse_info")
+                ->alias("a")
+                ->Join("supplier b","a.supplierNo=b.code","left")
+                ->Join("business bus","bus.companyNo=a.companyNo","left")
+                ->where(['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])
+                ->field("a.name as wsm_name,wsm_code,b.code,b.name,bus.company,bus.companyNo")
+                ->find();
+
             $godd =Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
             $value['good_name']=isset($godd['good_name'])? $godd['good_name']:"";
             $value['cat_id']=isset($godd['cat_id'])? $godd['cat_id']:"";
@@ -637,8 +771,10 @@ class Good extends Base
             $value['code'] =$wsm['code'];
             $value['name'] =$wsm['name'];
             $value['action_type_cn'] =$this->acton[$value['action_type']];
-            $value['item'] =$item;
+            $value['item'] =$item[$value['action_uid']];
             $value['can'] =$int;
+            $value['company'] =$wsm['company']??'';
+            $value['companyNo'] =$wsm['companyNo']??'';
             $data[]=$value;
         }
         return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);

+ 9 - 4
app/admin/controller/Goodup.php

@@ -6,6 +6,7 @@ use app\admin\model\ChangeLog;
 use think\App;
 use think\facade\Db;
 
+//商品基础库
 class Goodup extends Base
 {
     public $noble=[];
@@ -82,6 +83,10 @@ class Goodup extends Base
             $where[]=['status',"=",$status];
             $condit[]=['a.status',"=",$status];
         }
+        $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] !== "" ? intval($this->post['is_stock']) : '';
+        if ($is_stock!=='') {
+            $where[] = ['is_stock', "=", $is_stock];
+        }
         $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
         if($start!==""){
             $where[]=['addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
@@ -314,7 +319,7 @@ class Goodup extends Base
         }
         $createrid= isset($user["data"]['id']) ?  $user["data"]['id'] : "";
         $creater= isset($user["data"]['nickname']) ?  $user["data"]['nickname'] : "";
-        $spucode=makeNo("SPU");
+        $spucode=makeNo("SKU");
         Db::startTrans();
         try {
             $data=[
@@ -994,7 +999,7 @@ class Goodup extends Base
             }
             $data[]=[
                 "spuCode"=>$value,
-                "skuCode"=>makeNo("SKU"),
+                "skuCode"=>makeNo("SN"),
                 "platform_code"=>$platform,
                 "online_reason"=>$online_reason,
                 "online_remark"=>$online_remark,
@@ -1303,7 +1308,7 @@ class Goodup extends Base
         $creater= isset($user["data"]['nickname']) ?  $user["data"]['nickname'] : "";
         $nake = Db::name("good_nake")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
         $ladd=[];
-        $newCode =makeNo("SPU");
+        $newCode =makeNo("SKU");
         if(!empty($nake)){
             foreach ($nake as $value){
                     $tmp=[];
@@ -1697,7 +1702,7 @@ class Goodup extends Base
             return error_show(1010,"起订量不足{$nakelist['min_num']}");
         }
         $catinfo = Db::name("cat")->where(["id"=>$good['cat_id']])->find();
-        $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
+        $budget = isset($catinfo['sale_rate']) ? $catinfo['sale_rate']/100:0;
         if($good['is_gold_price']==1){
             $saleprice =  $good['noble_weight']*$good["cgd_gold_price"] + $nakelist['cost_fee']/(1-$budget)*
                 $good['noble_weight']+$nakelist['mark_fee']+$nakelist['package_fee']+$nakelist['cert_fee']+$nakelist['nake_fee']+$nakelist['delivery_fee'];

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

@@ -6,6 +6,7 @@ use app\BaseController;
 use think\facade\Db;
 use think\App;
 
+//管理员权限分组
 class Group extends BaseController
 {
     public  function __construct(App $app)

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

@@ -6,6 +6,7 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 
+//品牌授权
 class Keepbrand extends Base
 {
     public function __construct(App $app)

+ 2 - 0
app/admin/controller/Listcustomer.php

@@ -6,6 +6,8 @@ namespace app\admin\controller;
 use app\BaseController;
 use think\App;
 use think\facade\Db;
+
+//客户信息
 class Listcustomer extends BaseController
 {
     public $post = "";

+ 4 - 3
app/admin/controller/Log.php

@@ -8,6 +8,7 @@ use think\Request;
 use think\App;
 use think\facade\Db;
 
+//日志
 class Log extends BaseController
 {
     public $post = "";
@@ -37,8 +38,8 @@ class Log extends BaseController
         $condition = [['type',"=",1]];
         $count = Db::name("action_log")->where($condition)->count();
         $total = ceil($count/$size);
-        $page = $page >= $total ? $total : $page;
-        $list =Db::name("action_log")->where($condition)->page($page,$size)->select();
+        $page = $page >= $total ? intval($total) : $page;
+        $list =Db::name("action_log")->where($condition)->page($page,$size)->order("addtime desc")->select();
         return app_show(0,"获取成功",['list'=>$list,"count"=>$count]);
     }
 
@@ -115,7 +116,7 @@ class Log extends BaseController
         $count = Db::name("order_msg")->where($condition)->count();
         $total = ceil($count/$size);
         $page = $page >= $total ? $total : $page;
-        $list =Db::name("order_msg")->where($condition)->page($page,$size)->select();
+        $list =Db::name("order_msg")->where($condition)->page(intval($page),$size)->order("addtime desc")->select();
         $data=[];
         $type = \think\facade\Config::get("order");
         foreach ($list as $value){

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

@@ -9,6 +9,7 @@ use think\App;
 use think\facade\Db;
 use think\Request;
 
+//菜单
 class Menu extends BaseController
 {
     public $post="";

+ 2 - 0
app/admin/controller/Newfill.php

@@ -7,6 +7,8 @@ use think\App;
 use think\facade\Db;
 use app\admin\model\ActionLog;
 
+
+//系统的组织架构
 class Newfill extends BaseController
 {
      public $post = "";

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

@@ -8,6 +8,7 @@ use app\admin\model\ProcessOrder;
 use think\App;
 use think\facade\Db;
 
+//退货单
 class Orderback extends \app\BaseController
 {
     public $post=[];

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

@@ -6,6 +6,7 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 
+//订单用途
 class Orderuse extends BaseController
 {
     public $post="";

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

@@ -7,6 +7,7 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 
+//平台
 class Platform extends BaseController
 {
     public $post ="";

+ 2 - 0
app/admin/controller/Process.php

@@ -5,6 +5,8 @@ namespace app\admin\controller;
 use app\BaseController;
 use think\App;
 use think\facade\Db;
+
+//流程单
 class Process extends BaseController
 {
     public $post="";

+ 12 - 26
app/admin/controller/Project.php

@@ -5,6 +5,7 @@ namespace app\admin\controller;
 use think\App;
 use think\facade\Db;
 
+//项目
 class Project extends Base
 {
 
@@ -65,7 +66,7 @@ class Project extends Base
         $creater= isset($user["data"]['nickname']) ?  $user["data"]['nickname'] : "";
         Db::startTrans();
         try {
-            $projectNo = makeNo("PRO");
+            $projectNo = makeNo("PR");
             $data=[
                 "projectNo"=>$projectNo,
                 "platform_id"=>$platform,
@@ -89,7 +90,7 @@ class Project extends Base
                 if(!empty($ladder)){
                     $la=[];
                     foreach ($ladder as $value){
-                        $pgNo = makeNo("PRI");
+                        $pgNo = makeNo("PI");
                         $temp=[];
                         $temp['pgNo']=$pgNo;
                         $temp['projectNo']=$projectNo;
@@ -346,33 +347,16 @@ class Project extends Base
                 $nake =Db::name("good_nake")->where(["spuCode"=>$good['spuCode'],"is_del"=>0])->where([["min_num","<=",$value['num']]])
                     ->order("min_num desc")->find();
                 $good['origin_price']=$nake['nake_total'];
+                $good['work_day']=$good['lead_time'];
                 $good_img = $good['good_thumb_img'];
+
             }else{
                 $good=Db::name("consult_bids")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
                 $good['specinfo'] = isset($good['specinfo'])&&$good['specinfo']!=""?json_decode($good['specinfo'],
                     true):"";
                 $catinfo = Db::name("cat")->where(["id"=>$good['cat_id']])->find();
                 $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:100;
-                $good=[
-                    "metal_id"=>$good['metal_id'],
-                    "weight"=>$good["weight"],
-                    "demo_fee"=>$good["demo_fee"],
-                    "delivery_fee"=>$good["delivery_fee"],
-                    "open_fee"=>$good["open_fee"],
-                    "packing_fee"=>$good["pakge_fee"],
-                    "mark_fee"=>$good["mark_fee"],
-                    "nake_fee"=>$good["nake_fee"],
-                    "cert_fee"=>$good["cert_fee"],
-                    "cost_fee"=>$good["cost_fee"],
-                    "num"=>$value["num"],
-                    "good_img"=>$good["good_img"],
-                ];
                 $good_img = $good['good_img'];
-//                if($good['is_gold_price']==1){
-//                    $price = GoldPrice($god, 0);
-//                }else{
-//                    $price = GoodPrice($god, 0);
-//                }
             }
             $nobel =\think\facade\Config::get("noble");
             $value['good_name'] = isset($good['good_name'])?$good['good_name']:"";
@@ -386,7 +370,9 @@ class Project extends Base
             $value["unit_name"]=isset($unit['unit'])?$unit['unit']:"";
             $value['cost_desc'] = isset($good['cost_desc'])?$good['cost_desc']:"";
             $value['work_day'] = isset($good['work_day'])?$good['work_day']:"";
-            $value['good_img'] = $good_img;;
+            $value['delivery_day'] = isset($good['delivery_day'])?$good['delivery_day']:"";
+            $value['expire_day'] = isset($good['expire_day'])?$good['expire_day']:"0";
+            $value['good_img'] = $good_img;
             $value['expire_day'] = isset($good['expire_day'])?$good['expire_day']:"";
             $value['origin_place'] = isset($good['origin_place'])?$good['origin_place']:"";
             $value['supplierNo'] = isset($good['supplierNo'])?$good['supplierNo']:"";
@@ -498,7 +484,7 @@ class Project extends Base
         $creater= isset($user["data"]['nickname']) ?  $user["data"]['nickname'] : "";
         Db::startTrans();
         try {
-            $planNo=makeNo("PLA");
+            $planNo=makeNo("PL");
             $total=0;
             $num_t=0;
             $origia=0;
@@ -654,7 +640,7 @@ class Project extends Base
                             $val["sale_price"]=$price;
                             $val["origin_num"]=$val['num'];
                             $val["num"]=$feedback[$key]['sale_num'];
-                            if($val['data_source']==1){
+                            if($val['data_source']!=1){
                                 $good=Db::name("consult_bids")->where(["spuCode"=>$val['spuCode'],"is_del"=>0])->find();
                                 $good['specinfo']=isset($good['specinfo'])&&$good['specinfo']!=""?json_decode($good['specinfo'],true):[];
                             }else{
@@ -673,7 +659,7 @@ class Project extends Base
                             if(isset($good['brand_id'])){
                                 $brand =Db::name("brand")->where(["id"=>$good['brand_id']])->find();
                             }
-                            $val['good_img']=isset($good['good_img'])&&$good['good_img']!=""?trim($good['good_img']):"";
+                            $val['good_img']=isset($good['good_thumb_img'])&&$good['good_thumb_img']!=""?trim($good['good_thumb_img']):"";
                             $val['brand_id']=isset($good['brand_id'])&&$good['brand_id']!=""?$good['brand_id']:"";
                             $val['brand_name']=isset($brand['brand_name'])&&$brand['brand_name']!=""?$brand['brand_name']:"";
                             $val['specinfo']=isset($good['specinfo'])&&$good['specinfo']!=""?$good['specinfo']:[];
@@ -833,7 +819,7 @@ class Project extends Base
             }
             $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
             $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
-        $orderCode = makeNo("CX");
+        $orderCode = makeNo("QR");
         Db::startTrans();
         try{
             $data = [

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

@@ -6,6 +6,7 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 
+//消息(已读未读)
 class Proorder extends BaseController
 {
 public $post="";

+ 76 - 50
app/admin/controller/Purch.php

@@ -9,6 +9,7 @@ use app\admin\model\ProcessOrder;
 use think\App;
 use think\facade\Db;
 
+//采购单相关功能
 class Purch extends Base
 {
 
@@ -142,6 +143,11 @@ class Purch extends Base
                 }
                 $value["speclist"]=empty($speclist)?[]:$speclist;
             }
+            
+            //采购单详情字段order_type 为1或者2时,取线上商品库 商品创建人   order_type 为3或者4时 取采购反馈的商品库 商品反馈人
+            $value['cgder_id'] = $goon['createrid'];
+            $value['cgder'] = $goon['creater'];
+
             $inorder= Db::name("purchease_in")->where(['cgdNo'=>$value['cgdNo'],"is_del"=>0])->select();
             $value['child']=empty($inorder)? [] : $inorder;
             $data[]=$value;
@@ -161,11 +167,15 @@ class Purch extends Base
         $im = Db::name('purchease_back')->where(['cgdNo'=>$data['cgdNo'],'is_del'=>0])->select();
         $var=[];
         foreach ($im as $value){
-            $goon = Db::name('good_basic')->where(['spuCode'=>$value['good_code']])->field("cat_id")->find();
-            if(empty($goon)){
-                return error_show(1002,"未找到商品数据");
+            if($data['order_type']==3|| $data['order_type']==4){
+                $goo = Db::name("good_zixun")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
+            }else {
+                $goo =Db::name('good_basic')->where(['spuCode'=>$value['spuCode']])->find();
+            }
+            if($goo==false) {
+                return error_show(1002, "未找到商品数据");
             }
-            $cat= isset($goon['cat_id']) && $goon['cat_id'] !=0 ? made($goon['cat_id']):[];
+            $cat= isset($goo['cat_id']) && $goo['cat_id'] !=0 ? made($goo['cat_id']):[];
             $value['cant']=$cat;
             $var[]=$value;
         }
@@ -419,12 +429,12 @@ class Purch extends Base
         if($cg==""){
             return error_show(1002,"未找到采购单数据");
         }
-        $gd= Db::name('good')->where(['good_code'=>$cg['good_code']])->find();
+        $gd= Db::name('good')->where(['spuCode'=>$cg['spuCode']])->find();
         if($gd==""){
             return error_show(1002,"未找到商品数据");
         }
-        $diff_weight = isset($this->post['diff_weight']) && $this->post['diff_weight'] !=="" ? trim($this->post['diff_weight']) :"";
-        if($diff_weight==""){
+        $diff_weight = isset($this->post['diff_weight']) && $this->post['diff_weight'] !=="" ? floatval($this->post['diff_weight']) :"";
+        if($diff_weight===""){
             return error_show(1002,"参数diff_weight不能为空");
         }
         $apply_id =GetUserInfo($token);
@@ -434,11 +444,9 @@ class Purch extends Base
         $rid= isset($apply_id["data"]['id']) ?  $apply_id["data"]['id'] : "";
         $rname= isset($apply_id["data"]['nickname']) ?  $apply_id["data"]['nickname'] : "";
         $diff_price = $diff_weight*$cg['gold_price'];
-       // $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
         $data=[
             "cgdNo"=>$cgdNo,
-            "good_code"=>$cg['good_type_code'],
-            "good_kode"=>$cg['good_code'],
+            "good_code"=>$cg['spuCode'],
             "good_name"=>$cg['good_name'],
             "sale_price"=>$cg['good_price'],
             "good_weight"=>$cg['weight'],
@@ -447,7 +455,7 @@ class Purch extends Base
             "apply_name"=>$rname,
             "diff_weight"=>$diff_weight,
             "diff_price"=>$diff_price,
-            "gold_price"=>$cg['gold_price'],
+            "gold_price"=>$cg['good_price'],
             "status"=>1,
             "is_del"=>0,
             "addtime"=>date("Y-m-d H:i:s"),
@@ -457,40 +465,45 @@ class Purch extends Base
         try{
             $item = Db::name("purchease_diff")->insert($data,true);
             if($item>0){
-                $stm = ["order_code"=>$cgdNo,"status"=>1,"action_remark"=>'',"action_type"=>"create"];
-                ActionLog::logAdd($this->post['token'],$stm,"CGGCD",1,$stm);
-                $process=["order_code"=>$cgdNo,"order_id"=>$item,"order_status"=>1,"order_type"=>'CGGCD'];
-                ProcessOrder::AddProcess($this->post['token'],$process);
-                if($cg['order_type']==2){
-                    $order = Db::name("sale")->where(["orderCode"=>$cg['bkcode']])->find();
+//                $stm = ["order_code"=>$cgdNo,"status"=>1,"action_remark"=>'',"action_type"=>"create"];
+//                ActionLog::logAdd($this->post['token'],$stm,"CGGCD",1,$stm);
+//                $process=["order_code"=>$cgdNo,"order_id"=>$item,"order_status"=>1,"order_type"=>'CGGCD'];
+//                ProcessOrder::AddProcess($this->post['token'],$process);
+                $orderCode = Db::name("order_num")->where([["cgdNo","=",$cg['cgdNo']],["status","=",1]])->column("orderCode");
+
+                if(!empty($orderCode)){
+                    $order = Db::name("sale")->where("orderCode", 'in', $orderCode)->select()->toArray();
                     if(empty($order)){
                         Db::rollback();
                         return error_show(1002,"未找到确认单信息");
                     }
-                    $data=[
-                        "orderCode"=>$cg['bkcode'],
-                        "good_code"=>$cg['good_type_code'],
-                        "good_kode"=>$cg['good_code'],
-                        "good_name"=>$cg['good_name'],
-                        "diff_weight"=>$diff_weight,
-                        "diff_price"=>$diff_weight*$cg['gold_price'],
-                        "gold_price"=>$cg['gold_price'],
-                        "status"=>1,
-                        "addtime"=>date("Y-m-d H:i:s"),
-                        "updatetime"=>date("Y-m-d H:i:s")
-                    ];
-                    $cgd = Db::name('sale_diff')->insert($data,true);
-                    if($cgd>0){
-                        $sto = ["order_code"=>$cg['bkcode'],"status"=>1,"action_remark"=>'',"action_type"=>"create"];
-                        ActionLog::logAdd($this->post['token'],$sto,"ZXGCD",1,$sto);
-                        $process=["order_code"=>$cg['bkcode'],"order_id"=>$cgd,"order_status"=>1,"order_type"=>'ZXGCD'];
-                        ProcessOrder::AddProcess($this->post['token'],$process);
-                        Db::commit();
-                        return error_show(0,"新建成功");
-                    }else{
-                        Db::rollback();
-                        return error_show(1002,"新建失败");
+                    foreach ($orderCode as $value){
+                        $data=[
+                            "cgd_diffid"=>$item,
+                            "orderCode"=>$value,
+                            "good_code"=>$cg['spuCode'],
+                            "good_name"=>$cg['good_name'],
+                            "diff_weight"=>$diff_weight,
+                            "diff_price"=>$diff_weight*$cg['good_price'],
+                            "gold_price"=>$cg['good_price'],
+                            "status"=>1,
+                            "addtime"=>date("Y-m-d H:i:s"),
+                            "updatetime"=>date("Y-m-d H:i:s")
+                        ];
+                        $cgd = Db::name('sale_diff')->insert($data,true);
+                        if($cgd==0){
+//                            $sto = ["order_code"=>$cg['bkcode'],"status"=>1,"action_remark"=>'',"action_type"=>"create"];
+//                            ActionLog::logAdd($this->post['token'],$sto,"ZXGCD",1,$sto);
+//                            $process=["order_code"=>$cg['bkcode'],"order_id"=>$cgd,"order_status"=>1,"order_type"=>'ZXGCD'];
+//                            ProcessOrder::AddProcess($this->post['token'],$process);
+//                            Db::commit();
+//                            return error_show(0,"新建成功");
+//                        }else{
+                            Db::rollback();
+                            return error_show(1002,"新建失败");
+                        }
                     }
+
                 }
                 Db::commit();
                 return error_show(0,"新建成功");
@@ -527,11 +540,11 @@ class Purch extends Base
         if($apply_name!==""){
             $where[]=['a.apply_name',"like","%$apply_name%"];
         }
-        $count = Db::name('purchease_diff')->alias('a')->join("good b","b.good_code=a.good_kode","left")
+        $count = Db::name('purchease_diff')->alias('a')->join("good b","b.spuCode=a.good_code","left")
             ->where($where)->count();
         $total = ceil($count/$size);
         $page = $page >= $total ? $total : $page;
-        $list = Db::name('purchease_diff')->alias('a')->join("good b","b.good_code=a.good_kode","left")
+        $list = Db::name('purchease_diff')->alias('a')->join("good b","b.spuCode=a.good_code","left")
             ->where($where)->page($page,$size)->order("a.addtime desc")->field("a.*,b.cat_id")->select();
         $data=[];
         foreach ($list as $value){
@@ -549,8 +562,14 @@ class Purch extends Base
         if($idinf==false){
             return error_show(1002,"未找到采购工差单数据");
         }
-        $dn = Db::name('purchease_order')->where(['cgdNo'=>$idinf['cgdNo'],'is_del'=>0])->field('order_type')->find();
-        $goon = Db::name('good')->where(['good_code'=>$idinf['good_kode']])->find();
+        $dn = Db::name('purchease_order')->where(['cgdNo'=>$idinf['cgdNo'],'is_del'=>0])->find();
+
+        if($dn['order_type']==3|| $dn['order_type']==4){
+            $goon = Db::name("good_zixun")->where(["spuCode"=>$dn['spuCode'],"is_del"=>0])->find();
+        }else {
+            $goon =Db::name('good_basic')->where(['spuCode'=>$dn['spuCode']])->find();
+        }
+//        $goon = Db::name('good')->where(['spuCode'=>$idinf['good_code']])->find();
         if(empty($goon)){
             return error_show(1002,"未找到商品数据");
         }
@@ -570,7 +589,6 @@ class Purch extends Base
             $idinf['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
             $idinf['wsm_contactor'] =isset($wsmcode['wsm_contactor']) ? $wsmcode['wsm_contactor']:"";
             $idinf['wsm_mobile'] =isset($wsmcode['wsm_mobile']) ? $wsmcode['wsm_mobile']:"";
-            // $data['wsm_addr'] =isset($wsmcode['wsm_addr']) ? $wsmcode['wsm_addr']:"";
             $idinf['addr_code'] =isset($wsmcode['addr_code']) ? $wsmcode['addr_code']:"";
             $idinf['addr_cn'] =isset($wsmcode['addr_code']) ? GetAddr($wsmcode['addr_code']):"";
             $idinf['wsm_addr']=isset($wsmcode['wsm_addr']) ? $wsmcode['wsm_addr']:"";
@@ -579,6 +597,14 @@ class Purch extends Base
         $int= isset($goon['cat_id']) && $goon['cat_id'] !=0 ? made($goon['cat_id']):[];
         $idinf['can']=$int;
         $idinf['order_type']=$dn['order_type'];
+
+        //取出销售的工差单信息
+        $diff = Db::name('sale_diff')->field('id,customer_remark,is_act,remark')->where('cgd_diffid',$id)->find();
+
+        $idinf['diff_customer_remark']=$diff['customer_remark'];
+        $idinf['diff_is_act']=$diff['is_act'];
+        $idinf['diff_remark']=$diff['remark'];
+
        return  app_show(0,"获取成功",$idinf);
 
     }
@@ -602,12 +628,12 @@ class Purch extends Base
         $temp = $dio['status'];
             $dio['status']=$status;
             $dio['updatetime']=date("Y-m-d H:i:s");
-            $item = Db::name("purchease_diff")->update($dio);
+            $item = Db::name("purchease_diff")->save($dio);
          if ($item){
-             $sto = ["order_code"=>$dio['cgdNo'],"status"=>$temp,"action_remark"=>'',"action_type"=>"status"];
-             ActionLog::logAdd($this->post['token'],$sto,"CGGCD",$dio['status'],$sto);
-             $process=["order_code"=>$dio['cgdNo'],"order_id"=>$dio['id'],"order_status"=>$status,"order_type"=>'CGGCD'];
-             ProcessOrder::AddProcess($this->post['token'],$process);
+//             $sto = ["order_code"=>$dio['cgdNo'],"status"=>$temp,"action_remark"=>'',"action_type"=>"status"];
+//             ActionLog::logAdd($this->post['token'],$sto,"CGGCD",$dio['status'],$sto);
+//             $process=["order_code"=>$dio['cgdNo'],"order_id"=>$dio['id'],"order_status"=>$status,"order_type"=>'CGGCD'];
+//             ProcessOrder::AddProcess($this->post['token'],$process);
                 return error_show(0,"更新成功");
             }else{
                 return error_show(1002,"更新失败");

+ 2 - 1
app/admin/controller/Purchback.php

@@ -8,6 +8,7 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 
+//采购单退货
 class Purchback extends BaseController
 {
 public $post="";
@@ -18,7 +19,7 @@ public function __construct(App $app)
 }
 public function create(){
     $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
-    $returnCode=makeNo("TH");
+    $returnCode=makeNo("CT");
     $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo'] !==""? trim($this->post['cgdNo']) :"";
     if($cgdNo==""){
         return error_show(1002,"参数cgdNo不能为空");

+ 237 - 51
app/admin/controller/Purchin.php

@@ -7,6 +7,8 @@ use app\admin\model\ProcessOrder;
 use app\BaseController;
 use think\facade\Db;
 use think\App;
+
+//采购单入库
 class Purchin extends BaseController
 {
     public $post="";
@@ -90,6 +92,48 @@ class Purchin extends BaseController
             ->order("a.addtime desc")->select();
         $data=[];
         foreach ($list as $value){
+
+            //获取规格、品牌信息
+            if ($value['order_type'] == 3 || $value['order_type'] == 4) {
+                $temp = Db::name('good_zixun')
+                    ->alias('gz')
+                    ->field('gz.specinfo,b.brand_name')
+                    ->join('brand b', 'b.id=gz.brand_id')
+                    ->where(['gz.spuCode' => $value['spuCode'], 'gz.is_del' => 0])
+                    ->find();
+                $value["brand_name"] = $temp['brand_name'];
+                $value["speclist"] = json_decode($temp['specinfo'], true);
+
+            } else {
+                $value['brand_name'] = Db::name('good_basic')
+                    ->alias('gb')
+                    ->join('brand b', 'b.id=gb.brand_id')
+                    ->where(['gb.spuCode' => $value['spuCode']])
+                    ->value('b.brand_name');
+
+                $spec = Db::name("good_spec")
+                    ->where(["spuCode" => $value['spuCode'], "is_del" => 0])
+                    ->select()
+                    ->toArray();
+                $speclist = [];
+                if (!empty($spec)) {
+                    foreach ($spec as $val) {
+                        $temp = [];
+                        $temp['id'] = $val['id'];
+                        $temp['spuCode'] = $val['spuCode'];
+                        $temp['spec_id'] = $val['spec_id'];
+                        $temp['spec_value_id'] = $val['spec_value_id'];
+                        $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
+                        $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
+                        $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
+                        $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
+                        $speclist[] = $temp;
+                    }
+                }
+                $value["speclist"] = empty($speclist) ? [] : $speclist;
+            }
+
+
             $wsmcode = Db::name("warehouse_info")->alias("k")->leftJoin("supplier c","k.supplierNo=c.code")
                 ->where(["k.wsm_code"=>$value['wsm_code']])->field("k.name as wsm_name,c.name,c.code")->find();
             $value['wsm_name'] = $wsmcode['wsm_name'];
@@ -112,7 +156,7 @@ class Purchin extends BaseController
            return error_show(1005,"采购单未发货");
        }
 
-        $wsm_in_code = makeNo("IC");
+        $wsm_in_code = makeNo("CF");
 //       $wsm_code = isset($this->post['wsm_code'])&&$this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
 //       if($wsm_code==""){
 //           return error_show(1004,"参数 wsm_code 不能为空");
@@ -145,14 +189,20 @@ class Purchin extends BaseController
         if($send_num>$cgdinfo['wsend_num']){
             return error_show(1009,"采购单剩余未发货数量不足");
         }
-        if($cgdinfo['order_type']==1||$cgdinfo['order_type']==2 ){
-            $goodinfo = Db::name("good")->where(["spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->find();
-            if($goodinfo==false){
-                return error_show(1004,"商品数据未找到");
-            }
-            if($goodinfo['is_stock']==0){
-                $status=4;
-            }
+//        if($cgdinfo['order_type']==1||$cgdinfo['order_type']==2 ){
+//            $goodinfo = Db::name("good_basic")->where(["spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->find();
+//            if($goodinfo==false){
+//                return error_show(1004,"商品数据未找到");
+//            }
+//            if($goodinfo['is_stock']==0){
+//                $status=4;
+//            }
+//        } else {
+//            $send_way = Db::name("good_zixun")->where(["spuCode" => $cgdinfo['spuCode'], "is_del" => 0])->value('send_way');
+//            if ($send_way) $status = 4;
+//        }
+        if($sendtype==2){
+            $status=4;
         }
         $orin = [
             "wsm_in_code"=>$wsm_in_code,
@@ -192,6 +242,32 @@ class Purchin extends BaseController
                     $cgdinfo['updatetime']=date("Y-m-d H:i:s");
                     $up=Db::name("purchease_order")->save($cgdinfo);
                     if($up){
+                        $good = Db::name("good_stock")->where(["wsm_code"=>$cgdinfo['wsm_code'],"spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->find();
+                        if(empty($good)) {
+                            $good=[
+                                "spuCode"=>$cgdinfo['spuCode'],
+                                "wsm_code"=>$cgdinfo['wsm_code'],
+                                "usable_stock"=>0,
+                                "wait_out_stock"=>0,
+                                "wait_in_stock"=>0,
+                                "total_stock"=>0,
+                                "addtime"=>date("Y-m-d H:i:s"),
+                                "updatetime"=>date("Y-m-d H:i:s"),
+                            ];
+                            $order = ["order_code"=>$good['spuCode'],"status"=>1,"action_remark"=>'', "action_type"=>"create"];
+                        }else{
+                            $order = ["order_code"=>$good['spuCode'],"status"=>1,"action_remark"=>'', "action_type"=>"edit"];
+                        }
+                        $good['wait_in_stock']+=$send_num;
+                        $good['updatetime'] = date("Y-m-d H:i:s");
+                        $upd=  Db::name("good_stock")->save($good);
+                        if($upd==false){
+                            Db::rollback();
+                            return error_show(1004,"新建失败");
+                        }
+                            $good_data[]=["stock_id"=>isset($good['id'])? $good['id']:Db::name("good_stock")->getLastInsID(),"type"=>1,'stock'=>$send_num,"stock_name"=>"usable_stock"];
+                            GoodLog::LogAdd($this->post['token'],$good_data,'RKD');
+                            ActionLog::logAdd($this->post['token'],$order,"RKD", 1,$good  );
                             $process=["order_code"=>$cgdNo,"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD'];
                             ProcessOrder::AddProcess($this->post['token'],$process);
                             Db::commit();
@@ -216,8 +292,7 @@ class Purchin extends BaseController
                     ActionLog::logAdd($this->post['token'],$order,"CGD", $cgdinfo['status'],$cgdinfo);
                     $process=["order_code"=>$cgdNo,"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD'];
                     ProcessOrder::AddProcess($this->post['token'],$process);
-                    $good = Db::name("good_stock")->where(["wsm_code"=>$cgdinfo['wsm_code'],
-                        "spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->find();
+                    $good = Db::name("good_stock")->where(["wsm_code"=>$cgdinfo['wsm_code'],"spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->find();
                     if(empty($good)) {
                         $good=[
                             "spuCode"=>$cgdinfo['spuCode'],
@@ -229,22 +304,58 @@ class Purchin extends BaseController
                             "addtime"=>date("Y-m-d H:i:s"),
                             "updatetime"=>date("Y-m-d H:i:s"),
                         ];
-                        $order = ["order_code"=>$good['spuCode'],"status"=>1,"action_remark"=>'',
-                            "action_type"=>"create"];
-
+                        $order = ["order_code"=>$good['spuCode'],"status"=>1,"action_remark"=>'', "action_type"=>"create"];
                     }else{
                         $order = ["order_code"=>$good['spuCode'],"status"=>1,"action_remark"=>'', "action_type"=>"edit"];
                     }
                     $good['usable_stock']+=$send_num;
-                    $good['wait_in_stock']-=$send_num;
                     $good['total_stock']=$good['usable_stock']+$good['wait_out_stock'];
                     $good['updatetime'] = date("Y-m-d H:i:s");
                     $upd=  Db::name("good_stock")->save($good);
                     $good_data[]=["stock_id"=>isset($good['id'])? $good['id']:Db::name("good_stock")->getLastInsID(),"type"=>1,
                         'stock'=>$send_num,"stock_name"=>"usable_stock"];
                     if($upd){
-                        GoodLog::LogAdd($this->post['token'],$good_data,'入库单');
-                        ActionLog::logAdd($this->post['token'],$order,"仓库库存", 1,$good  );
+                        GoodLog::LogAdd($this->post['token'],$good_data,'RKD');
+                        ActionLog::logAdd($this->post['token'],$order,"RKD", 1,$good  );
+                        if($cgdinfo['send_status']==3){
+                            $send=Db::name("order_send")->where(["cgdNo"=>$cgdNo,"status"=>1])->column("outCode");
+                            if(!empty($send)){
+                                $out =Db::name("order_out")->where(["outCode"=>$send,"status"=>0])->select()
+                                    ->toArray();
+                                if(!empty($out)){
+                                    $up =Db::name("order_out")->where(["outCode"=>$send,"status"=>0])->update
+                                    (["status"=>1,'wsm_code'=>$cgdinfo['wsm_code'],"updatetime"=>date('Y-m-d H:i:s')]);
+                                    if($up==false){
+                                        Db::rollback();
+                                        return error_show(1004,"出库单出库失败");
+                                    }
+                                    $good1 = Db::name("good_stock")->where(["wsm_code"=>$cgdinfo['wsm_code'], "spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->find();
+                                    if($good1==false){
+                                        Db::rollback();
+                                        return error_show(1004,"未找到对应商品库存");
+                                    }
+                                    $out_num = intval(array_sum(array_column($out,"send_num")));
+                                    if($out_num>$good1['usable_stock']){
+                                        Db::rollback();
+                                        return error_show(1004,"库存数量不足发货");
+                                    }
+                                    $good1['usable_stock']-=$out_num;
+                                    $good1['wait_out_stock']+=$out_num;
+                                    $good1['total_stock']=$good1['usable_stock']+$good1['wait_out_stock'];
+                                    $good1['updatetime'] = date("Y-m-d H:i:s");
+                                    $upd=  Db::name("good_stock")->save($good1);
+                                    if($upd==false){
+                                        Db::rollback();
+                                        return error_show(1004,"库存数量更新失败");
+                                    }
+                                    $sendp=Db::name("order_send")->where(["cgdNo"=>$cgdNo,"outCode"=>$send,"status"=>1])->save (["status"=>2]);
+                                    if($sendp==false){
+                                        Db::rollback();
+                                        return error_show(1004,"库存发货失败");
+                                    }
+                                }
+                            }
+                        }
                         Db::commit();
                         return app_show(0,'商品入库成功',["wsm_in_code"=>$wsm_in_code]);
                     }else{
@@ -356,7 +467,7 @@ class Purchin extends BaseController
             $info['updatetime'] = date("Y-m-d H:i:s");
             $up =Db::name("purchease_in")->save($info);
             if($up){
-                ActionLog::logAdd($this->post['token'],$order,"rkd",2,$this->post);
+                ActionLog::logAdd($this->post['token'],$order,"RKD",2,$this->post);
                 $process=["order_code"=>$info['wsm_in_code'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'RKD'];
                 ProcessOrder::AddProcess($this->post['token'],$process);
                 if(!empty($error_list)){
@@ -418,7 +529,7 @@ class Purchin extends BaseController
             $info['updatetime'] = date("Y-m-d H:i:s");
             $update = Db::name("purchease_in")->save($info);
             if($update){
-                ActionLog::logAdd($this->post['token'],$order,"入库单",$status,$this->post);
+                ActionLog::logAdd($this->post['token'],$order,"RKD",$status,$this->post);
                 $process=["order_code"=>$info['wsm_in_code'],"order_id"=>$info['id'],"order_status"=>$status,"order_type"=>'RKD'];
                 ProcessOrder::AddProcess($this->post['token'],$process);
                 if($status==0){
@@ -502,8 +613,47 @@ class Purchin extends BaseController
                     $good_data[]=["stock_id"=>isset($good['id'])? $good['id']:Db::name("good_stock")->getLastInsID(),"type"=>1,
                     'stock'=>$info['wsm_num'],"stock_name"=>"usable_stock"];
                     if($upd){
-                        GoodLog::LogAdd($this->post['token'],$good_data,'入库单');
-                        ActionLog::logAdd($this->post['token'],$order,"仓库库存", 1,$good  );
+                        GoodLog::LogAdd($this->post['token'],$good_data,'RKD');
+                        ActionLog::logAdd($this->post['token'],$order,"RKD", 1,$good  );
+//                        if($cgdinfo['send_status']==3){
+//                            $send=Db::name("order_send")->where(["cgdNo"=>$info['cgdNo'],"status"=>1])->column("outCode");
+//                            if(!empty($send)){
+//                                $out =Db::name("order_out")->where(["outCode"=>$send,"status"=>0,"is_del"=>0])->select()
+//                                    ->toArray();
+//                                if(!empty($out)){
+//                                    $up =Db::name("order_out")->where(["outCode"=>$send,"status"=>0,"is_del"=>0])->update
+//                                    (["status"=>1,"updatetime"=>date('Y-m-d H:i:s')]);
+//                                    if($up==false){
+//                                        Db::rollback();
+//                                        return error_show(1004,"出库单出库失败");
+//                                    }
+//                                    $good1 = Db::name("good_stock")->where(["wsm_code"=>$cgdinfo['wsm_code'], "spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->find();
+//                                    if($good1==false){
+//                                        Db::rollback();
+//                                        return error_show(1004,"未找到对应商品库存");
+//                                    }
+//                                    $out_num = intval(array_sum(array_column($out,"send_num")));
+//                                    if($out_num>$good1['usable_stock']){
+//                                        Db::rollback();
+//                                        return error_show(1004,"库存数量不足发货");
+//                                    }
+//                                    $good1['usable_stock']-=$out_num;
+//                                    $good1['wait_out_stock']+=$out_num;
+//                                    $good1['total_stock']=$good1['usable_stock']+$good1['wait_out_stock'];
+//                                    $good1['updatetime'] = date("Y-m-d H:i:s");
+//                                    $upd=  Db::name("good_stock")->save($good1);
+//                                    if($upd==false){
+//                                        Db::rollback();
+//                                        return error_show(1004,"库存数量更新失败");
+//                                    }
+//                                    $sendp=Db::name("order_send")->where(["cgdNo"=>$info['cgdNo'],"outCode"=>$out,"status"=>1])->save (["status"=>2]);
+//                                    if($sendp==false){
+//                                        Db::rollback();
+//                                        return error_show(1004,"库存发货失败");
+//                                    }
+//                                }
+//                            }
+//                        }
                         Db::commit();
                         return app_show(0,'商品入库成功');
                     }else{
@@ -567,43 +717,79 @@ class Purchin extends BaseController
         Db::startTrans();
        try{
 
-        $info['status'] =5;
+        $info['status'] =$info['wsm_num']==$wsm_num ? 4 :5;
         $info['is_th'] =$return_num>0 ?1:0;
         $info['updatetime'] = date("Y-m-d H:i:s");
         $up= Db::name("purchease_in")->save($info);
         if($up){
-            $process=["order_code"=>$info['wsm_in_code'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'RKD'];
-            ProcessOrder::AddProcess($this->post['token'],$process);
-            $data=[
-                "wsm_in_code"=>$incode,
-                "wsm_num"=>$wsm_num,
-                "reissue_num"=>$reissue_num,
-                "return_num"=>$return_num,
-                "return_contactor"=>$contactor,
-                "return_addr"=>$addr,
-                "return_mobile"=>$mobile,
-                "error_remark"=>$error_remark,
-                "post_code"=>"",
-                "post_company"=>"",
-                "remark"=>$remark ,
-                "apply_id"=>$userinfo['id'],
-                "apply_name"=>$userinfo['nickname'],
-                "status"=>0,
-                "addtime"=>date("Y-m-d H:i:s"),
-                "updatetime"=>date("Y-m-d H:i:s")
-            ];
-            $res = Db::name("purchease_return")->insert($data,true);
-            if($res){
-                $sto = ["order_code"=>$incode,"status"=>0,"action_remark"=>'',"action_type"=>"create"];
-                ActionLog::logAdd($this->post['token'],$sto,"RKTHD",0,$sto);
-                $process=["order_code"=>$info['wsm_in_code'],"order_id"=>$res,"order_status"=>0,"order_type"=>'RKTHD'];
-                ProcessOrder::AddProcess($this->post['token'],$process);
-                Db::commit();
-                return app_show(0,"验货审核完成");
+            $cgdinfo=Db::name("purchease_order")->where(['cgdNo'=>$info['cgdNo'],"is_del"=>0])->find();
+            if(empty($cgdinfo)){
+                Db::rollback();
+                return error_show(1002,"未找到采购单数据");
+            }
+            $good = Db::name("good_stock")->where(["wsm_code"=>$info['wsm_code'], "spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->find();
+
+            if(empty($good)) {
+                $good=[
+                    "spuCode"=>$cgdinfo['spuCode'],
+                    "wsm_code"=>$info['wsm_code'],
+                    "usable_stock"=>0,
+                    "wait_out_stock"=>0,
+                    "wait_in_stock"=>0,
+                    "total_stock"=>0,
+                    "addtime"=>date("Y-m-d H:i:s"),
+                    "updatetime"=>date("Y-m-d H:i:s"),
+                ];
+                $order = ["order_code"=>$good['spuCode'],"status"=>1,"action_remark"=>'',
+                    "action_type"=>"create"];
+
             }else{
+                $order = ["order_code"=>$good['spuCode'],"status"=>1,"action_remark"=>'', "action_type"=>"edit"];
+            }
+            $good['usable_stock']+=$wsm_num;
+            $good['wait_in_stock']-=$wsm_num;
+            $good['total_stock']=$good['usable_stock']+$good['wait_out_stock'];
+            $good['updatetime'] = date("Y-m-d H:i:s");
+            $upd=  Db::name("good_stock")->save($good);
+            if($upd==false){
                 Db::rollback();
-                return error_show(1002,"验货审核失败");
+                return error_show(1002,"库存更新失败");
+            }
+            $good_data[]=["stock_id"=>isset($good['id'])? $good['id']:Db::name("good_stock")->getLastInsID(),"type"=>1, 'stock'=>$info['wsm_num'],"stock_name"=>"usable_stock"];
+            GoodLog::LogAdd($this->post['token'],$good_data,'RKD');
+            $process=["order_code"=>$info['wsm_in_code'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'RKD'];
+            ProcessOrder::AddProcess($this->post['token'],$process);
+            if($info['status']==5){
+                $data=[
+                    "wsm_in_code"=>$incode,
+                    "wsm_num"=>$wsm_num,
+                    "reissue_num"=>$reissue_num,
+                    "return_num"=>$return_num,
+                    "return_contactor"=>$contactor,
+                    "return_addr"=>$addr,
+                    "return_mobile"=>$mobile,
+                    "error_remark"=>$error_remark,
+                    "post_code"=>"",
+                    "post_company"=>"",
+                    "remark"=>$remark ,
+                    "apply_id"=>$userinfo['id'],
+                    "apply_name"=>$userinfo['nickname'],
+                    "status"=>0,
+                    "addtime"=>date("Y-m-d H:i:s"),
+                    "updatetime"=>date("Y-m-d H:i:s")
+                ];
+                $res = Db::name("purchease_return")->insert($data,true);
+                if($res==false){
+                    Db::rollback();
+                    return error_show(1002,"验货审核失败");
+                }
             }
+            $sto = ["order_code"=>$incode,"status"=>0,"action_remark"=>'',"action_type"=>"create"];
+            ActionLog::logAdd($this->post['token'],$sto,"RKTHD",0,$sto);
+            $process=["order_code"=>$info['wsm_in_code'],"order_id"=>$res,"order_status"=>0,"order_type"=>'RKTHD'];
+            ProcessOrder::AddProcess($this->post['token'],$process);
+            Db::commit();
+            return app_show(0,"验货审核完成");
         }
        }catch (\Exception $e){
            Db::rollback();

+ 19 - 5
app/admin/controller/Reorder.php

@@ -7,6 +7,8 @@ use app\admin\model\ProcessOrder;
 use think\facade\Db;
 use think\App;
 use app\admin\model\ActionLog;
+
+//销售单退货
 class Reorder extends \app\BaseController
 {
     public $post=[];
@@ -50,7 +52,7 @@ class Reorder extends \app\BaseController
         if($returnadr!=''){
             $thnum=array_sum(array_column($returnadr,"return_num"));
         }
-        $returnCode=makeNo("RXS");
+        $returnCode=makeNo("RS");
         Db::startTrans();
         try{
             $in = [
@@ -216,8 +218,9 @@ class Reorder extends \app\BaseController
             $info['supplier_name'] = isset($customerinfo['company']) ? $customerinfo['company']:"";
         }
         $info['platform_name']='';
-        if($info['platform_id']!=0){
-            $plat=Db::name("platform")->where(['id'=>$info['platform_id']])->find();
+        $info['platform_id']=$orderinfo['platform_id'];
+        if($orderinfo['platform_id']!=0){
+            $plat=Db::name("platform")->where(['id'=>$orderinfo['platform_id']])->find();
             $info['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
         }
         $info['cgd_wsend']="";
@@ -234,6 +237,7 @@ class Reorder extends \app\BaseController
             $error = Db::name("result_info")->where(["result_code"=>$info['error_code']])->find();
             $info['error_msg']= isset($error['result'])?$error['result']:"";
         }
+
         if($info['return_wsm']!=""){
             $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
                 ->where(["a.wsm_code"=>$info['return_wsm']])->field("a.name as wsm_name,b.name,b.code")->find();
@@ -241,6 +245,7 @@ class Reorder extends \app\BaseController
         $info['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
 //        $info['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
 //        $info['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
+
         $wsm_return = Db::name("sale_returninfo")->where(["returnCode"=>$info["returnCode"],"is_del"=>0])->select()->toArray();
         $wsm=[];
         if(!empty($wsm_return)){
@@ -381,16 +386,25 @@ class Reorder extends \app\BaseController
                 return error_show(1004,"参数is_th不能为空");
             }
 
-            $return_wsm =isset($this->post['return_wsm'])&&$this->post['return_wsm']!=="" ? intval($this->post['return_wsm']):"";
+            $return_wsm =isset($this->post['return_wsm'])&&$this->post['return_wsm']!=="" ? trim($this->post['return_wsm']):"";
             if($return_wsm===""){
                 return error_show(1004,"参数return_wsm 不能为空");
             }
+<<<<<<< HEAD
             $wsmcode = Db::name("warehouse_info")->where(['wsm_code'=>$return_wsm])->find();
             if($wsmcode==false){
                 return error_show(1004,"为找到仓库数据");
             }
             $info['return_wsm'] =$return_wsm ;
             $info['is_th'] =$is_th ;
+=======
+            $wsmcode = Db::name("warehouse_info")->where(["wsm_code"=>$return_wsm])->find();
+            if($wsmcode==false){
+                return error_show(1004,"未找到对应得仓库");
+            }
+            $info['return_wsm']=$return_wsm;
+            $info['is_th']=$is_th;
+>>>>>>> 74d2d74a91266a2eced8b724d04bf70e4c95de38
         }
 
         Db::startTrans();
@@ -488,7 +502,7 @@ class Reorder extends \app\BaseController
         if($order['wsend_num']<$num){
             return error_show(1002,"仓库未发货数量不足退货");
         }
-        $returnCode=makeNo("RXS");
+        $returnCode=makeNo("RS");
         Db::startTrans();
         try{
             $in = [

+ 39 - 37
app/admin/controller/Resign.php

@@ -11,6 +11,8 @@ use app\admin\model\ProcessOrder;
 use app\BaseController;
 use think\facade\Db;
 use think\App;
+
+//备货
 class Resign extends BaseController
 {
     public $post="";
@@ -766,7 +768,7 @@ class Resign extends BaseController
             "send_num"=>"0",
             "wsend_num"=>$info['good_num'],
             "remark"=>"",
-            "status"=>1,
+            "status"=>0,//0表示初始化
             "lasttime"=>date("Y-m-d H:i:s"),
             "is_del"=>0,
             "order_type"=>1,
@@ -788,45 +790,45 @@ class Resign extends BaseController
                     "updatetime"=>date("Y-m-d H:i:s")
                 ];
                 $in =Db::name("order_bk")->insert($data);
-                if($in){
-                  $good = Db::name("good_stock")->where(["wsm_code"=>$info['wsm_code'],"spuCode"=>$info['spuCode'],"is_del"=>0])->find();
-                        if($good==false) {
-                            $good=[
-                                "spuCode"=>$info['spuCode'],
-                                "wsm_code"=>$info['wsm_code'],
-                                "usable_stock"=>0,
-                                "wait_out_stock"=>0,
-                                "wait_in_stock"=>0,
-                                "total_stock"=>0,
-                                "addtime"=>date("Y-m-d H:i:s"),
-                                "updatetime"=>date("Y-m-d H:i:s"),
-                            ];
-                            $order = ["order_code"=>$info['spuCode'],"status"=>1,"action_remark"=>'',"action_type"=>"create"];
-                        }else{
-                            $order = ["order_code"=>$info['spuCode'],"status"=>1,"action_remark"=>'', "action_type"=>"edit"];
+                if($in) {
+//                    $good = Db::name("good_stock")->where(["wsm_code" => $info['wsm_code'], "spuCode" => $info['spuCode'], "is_del" => 0])->find();
+//                    if ($good == false) {
+//                        $good = [
+//                            "spuCode" => $info['spuCode'],
+//                            "wsm_code" => $info['wsm_code'],
+//                            "usable_stock" => 0,
+//                            "wait_out_stock" => 0,
+//                            "wait_in_stock" => 0,
+//                            "total_stock" => 0,
+//                            "addtime" => date("Y-m-d H:i:s"),
+//                            "updatetime" => date("Y-m-d H:i:s"),
+//                        ];
+//                        $order = ["order_code" => $info['spuCode'], "status" => 1, "action_remark" => '', "action_type" => "create"];
+//                    } else {
+//                        $order = ["order_code" => $info['spuCode'], "status" => 1, "action_remark" => '', "action_type" => "edit"];
+//                    }
+//                    $good['wait_in_stock'] += $info['good_num'];
+//                    $good['updatetime'] = date("Y-m-d H:i:s");
+//                    $upd = Db::name("good_stock")->save($good);
+//                    $good_data[] = ["stock_id" => isset($good['id']) ? $good['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1,
+//                        'stock' => $info['good_num'], "stock_name" => "wait_in_stock"];
+//                    if ($upd) {
+//                        GoodLog::LogAdd($this->post['token'], $good_data, 'RKD');
+//                        ActionLog::logAdd($this->post['token'], $order, "RKD", 1, $good);
+//                        $process = ["order_code" => $cgdCode, "order_id" => Db::name("purchease_order")->getLastInsID(), "order_status" => $cg['status'], "order_type" => 'CGD'];
+//                        ProcessOrder::AddProcess($this->post['token'], $process);
+                        $info['wsm_code'] = $wsm_code;
+                        $info['status'] = 2;
+                        $info['updatetime'] = date("Y-m-d H:i:s");
+                        $bas = Db::name("purchease")->save($info);
+                        if ($bas) {
+                            Db::commit();
+                            return app_show(0, "采购单新建成功", ["cgdNo" => $cgdCode]);
                         }
-                        $good['wait_in_stock']+=$info['good_num'];
-                        $good['updatetime'] = date("Y-m-d H:i:s");
-                        $upd=  Db::name("good_stock")->save($good);
-                        $good_data[]=["stock_id"=>isset($good['id'])? $good['id']:Db::name("good_stock")->getLastInsID(),"type"=>1,
-                            'stock'=>$info['good_num'],"stock_name"=>"wait_in_stock"];
-                        if($upd) {
-                            GoodLog::LogAdd($this->post['token'], $good_data, '入库单');
-                            ActionLog::logAdd($this->post['token'], $order, "仓库库存", 1, $good);
-                            $process=["order_code"=>$cgdCode,"order_id"=>Db::name("purchease_order")->getLastInsID(),"order_status"=>$cg['status'],"order_type"=>'CGD'];
-                            ProcessOrder::AddProcess($this->post['token'],$process);
-                            $info['wsm_code']=$wsm_code;
-                            $info['status']=2;
-                            $info['updatetime']=date("Y-m-d H:i:s");
-                            $bas= Db::name("purchease")->save($info);
-                            if($bas){
-                                Db::commit();
-                                return app_show(0, "采购单新建成功", ["cgdNo" => $cgdCode]);
-                            }
 
-                        }
+//                    }
+                    }
                 }
-            }
                 Db::rollback();
                 return error_show(1004,"采购单新建失败");
         }catch (\Exception $e){

+ 2 - 0
app/admin/controller/Resigninfo.php

@@ -6,6 +6,8 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 use app\admin\model\ActionLog;
+
+//交接
 class Resigninfo extends BaseController
 {
     public $post="";

+ 2 - 0
app/admin/controller/Result.php

@@ -6,6 +6,8 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 use app\admin\model\ActionLog;
+
+//异常原因
 class Result extends BaseController
 {
     public $post = "";

+ 3 - 1
app/admin/controller/Role.php

@@ -6,6 +6,8 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 use app\admin\model\ActionLog;
+
+//角色
 class Role extends BaseController
 {
 
@@ -197,7 +199,7 @@ class Role extends BaseController
         $info['action'] =explode(",",$info['action_conllect']);
         $info['action_data'] =$info['action_data']!=""?explode(",",$info['action_data']):"";
         $info['private_data'] =$info['private_data']!=""?explode(",",$info['private_data']) :"";
-        $info['private_field'] =$info['private_field']!=""?explode(",",$info['private_field']) :"";
+        $info['private_field'] =$info['private_field']!=""?explode(",",$info['private_field']) :[];
 
         return app_show(0,"获取成功",$info);
     }

+ 327 - 210
app/admin/controller/Sale.php

@@ -9,6 +9,7 @@ use think\App;
 use think\facade\Db;
 use app\admin\model\ActionLog;
 
+//销售单
 class Sale extends Base
 {
 
@@ -22,7 +23,7 @@ class Sale extends Base
     public function create()
     {
         $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
-        $orderCode=makeNo("CX");
+        $orderCode=makeNo("QR");
         $customer_code= isset($this->post['customer_code'])&& $this->post['customer_code'] !=="" ? trim($this->post['customer_code']) :"";
         if($customer_code==""){
             return error_show(1002,"客户customer_code不能为空");
@@ -51,14 +52,7 @@ class Sale extends Base
         if($platform_id==''){
             return error_show(1004,"参数platform_id不能为空");
         }
-//        $zxinfoNo= isset($this->post['zxinfoNo'])&& $this->post['zxinfoNo'] !=="" ? trim($this->post['zxinfoNo']) :"";
-//        if($zxinfoNo=="" &&$order_type!==1){
-//            return error_show(1002,"参数 zxinfoNo 不能为空");
-//        }
         $platform_order =isset($this->post['platform_order']) && $this->post['platform_order'] !=="" ?trim($this->post['platform_order']):"";
-//        if($platform_order==''){
-//            return error_show(1004,"参数platform_order不能为空");
-//        }
         $good_code =isset($this->post['good_code']) && $this->post['good_code'] !=="" ?trim($this->post['good_code']):"";
         if($good_code==''){
             return error_show(1004,"参数good_code不能为空");
@@ -83,7 +77,6 @@ class Sale extends Base
             $is_stock=$ct['is_stock'];
             $spuCode = $ct['spuCode'];
             $skuCode = $ct['skuCode'];
-
         $is_activity= isset($this->post['is_activity'])&&$this->post['is_activity']!=="" ?$this->post['is_activity']:"";
         $actcode= isset($this->post['act_code'])&&$this->post['act_code']!=="" ?trim($this->post['act_code']):"";
         if($order_type==1){
@@ -105,7 +98,7 @@ class Sale extends Base
         if($origin==false){
             return error_show(1003,"未找到相关阶梯成本价格");
         }
-        $origin_price = $origin['nake_fee'];
+        $origin_price = $origin['nake_total'];
         $sale_price = isset($this->post['good_price'])&&$this->post['good_price']!="" ? floatval($this->post['good_price']):0;
         if($goodtype==1){
             $good = Db::name("good_ladder")->where(["skuCode"=>$skuCode,"is_del"=>0,"status"=>1])->where([["min_num",
@@ -130,10 +123,6 @@ class Sale extends Base
                 $sale_price=$act['activity_price'];
             }
         }
-
-
-
-
         $cgd=[
             "supplierNo"=>$ct['supplierNo'],
             "companyNo"=>$supplierNo,
@@ -151,7 +140,9 @@ class Sale extends Base
             "demo_fee"=>$ct['demo_fee'],
             "good_num"=>$good_num,
             "good_type"=>$goodtype,
-            "order_type"=>$order_type,
+            "order_type"=>$is_stock==1?1:2,
+            'send_way'=>2
+
         ];
         $addrlist = isset($this->post['addrlist']) && $this->post['addrlist'] !=="" ?$this->post['addrlist']:"";
         if($sendtype==1){
@@ -161,8 +152,6 @@ class Sale extends Base
         }
         $remark =isset($this->post['remark']) && $this->post['remark'] !=="" ?trim($this->post['remark']):"";
 
-        $proofid= isset($this->post['proof_id'])&&$this->post['proof_id']===""?intval($this->post['proof_id']):"0";
-
         $apply_id =GetUserInfo($token);
         if(empty($apply_id)||$apply_id['code']!=0){
             return error_show(1002,"申请人数据不存在");
@@ -198,7 +187,6 @@ class Sale extends Base
                 "remark"=>$remark,
                 "is_stock"=>$is_stock,
                 "is_activity"=>$is_activity===""?0:$is_activity,
-                "proof_id"=>$proofid,
                 "order_type"=>$order_type,
 //                "poNo"=>$poNo,
                 "workNo"=>$workNo,
@@ -271,61 +259,78 @@ class Sale extends Base
                         $temp['arrive_time']=$arrtime;
                         $vmp = Db::name('order_addr')->insert($temp,true);
                         if($vmp>0){
-//                            $outCode=makeNo("CK");
-//                            $out=[
-//                                "orderCode"=>$orderCode,
-//                                "outCode"=>$outCode,
-//                                "apply_id"=>$rm,
-//                                "apply_name"=>$ri,
-//                                "addrid"=>$vmp,
-//                                "post_name"=>"",
-//                                "post_code"=>"",
-//                                "post_fee"=>0,
-//                                "sendtime"=>date("Y-m-d H:i:s"),
-//                                "send_num"=>$value['receipt_quantity'],
-//                                "check_num"=>0,
-//                                "error_num"=>0,
-//                                "wsm_code"=>"",
-//                                "order_type"=>$order_type,
-//                                "status"=>0,
-//                                "addtime"=>date("Y-m-d H:i:s"),
-//                                "updatetime"=>date("Y-m-d H:i:s")
-//                            ];
-//                            $ou =Db::name("order_out")->insert($out);
-//                            if($ou==false){
-//                                Db::rollback();
-//                                return error_show(1002,"发货地址添加创建失败");
-//                            }
-//                            if($is_stock==0){
-//                                $order =Db::name("order_num")->where(["orderCode"=>$orderCode,"status"=>1])->where([["wsend_num",">=",0]])
-//                                    ->find();
-//                                if($order==false){
-//                                    Db::rollback();
-//                                    return error_show(1006,"采购单关联数据未找到");
-//                                }
-//                                $order['send_num']+=$value['receipt_quantity'];
-//                                $order['wsend_num']-=$value['receipt_quantity'];
-//                                if($order['wsend_num']<0){
-//                                    Db::rollback();
-//                                    return error_show(1002,"发货数量已超出总数");
-//                                }
-//                                $ups = Db::name("order_num")->save($order);
-//                                if($ups){
-//                                    $tep=[
-//                                        "cgdNo"=>$order['cgdNo'],
-//                                        "outCode"=>$outCode,
-//                                        "send_num"=>$value['receipt_quantity'],
-//                                        "status"=>1,
-//                                        "addtime"=>date("Y-m-d H:i:s"),
-//                                        "updatetime"=>date("Y-m-d H:i:s")
-//                                    ];
-//                                    $sen=Db::name("order_send")->save($tep);
-//                                    if($sen==false){
-//                                        Db::rollback();
-//                                        return error_show(1002,"发货地址添加创建失败");
-//                                    }
-//                                }
-//                            }
+                            if($is_stock==0) {
+                                $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
+                                    ->select()->toArray();
+                                if (empty($order)) {
+                                    return error_show(1004, "未找到可以发货得采购单数据");
+                                }
+                                $num = $value['receipt_quantity'];
+                                $orsend = [];
+                                foreach ($order as $val) {
+                                    $outCode = makeNo("DF");
+                                    $tep = [];
+                                    $ornum = 0;
+                                    if ($val['wsend_num'] >= $num) {
+                                        $val['wsend_num'] -= $num;
+                                        $val['send_num'] += $num;
+                                        $ornum = $num;
+                                        $num = 0;
+                                    } else {
+                                        $num -= $val['wsend_num'];
+                                        $val['send_num'] += $val['wsend_num'];
+                                        $ornum = $val['wsend_num'];
+                                        $val['wsend_num'] = 0;
+                                    }
+                                    $or = Db::name("order_num")->save($val);
+                                    if ($or == false) {
+                                        Db::rollback();
+                                        return error_show(1002, "发货地址添加创建失败");
+                                    }
+                                    $tep = [
+                                        "cgdNo" => $val['cgdNo'],
+                                        "outCode" => $outCode,
+                                        "send_num" => $ornum,
+                                        "status" => 1,
+                                        "addtime" => date("Y-m-d H:i:s"),
+                                        "updatetime" => date("Y-m-d H:i:s")
+                                    ];
+                                    $sen = Db::name("order_send")->save($tep);
+                                    if ($sen == false) {
+                                        Db::rollback();
+                                        return error_show(1002, "发货地址添加创建失败");
+                                    }
+                                    $cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $val['cgdNo']])->find();
+                                    if ($cgdinfo == false) {
+                                        Db::rollback();
+                                        return error_show(1002, "未匹配到采购数据");
+                                    }
+                                    $out = [
+                                        "orderCode" => $orderCode,
+                                        "outCode" => $outCode,
+                                        "apply_id" => $rm,
+                                        "apply_name" => $ri,
+                                        "addrid" => $vmp,
+                                        "post_name" => "",
+                                        "post_code" => "",
+                                        "post_fee" => 0,
+                                        "sendtime" => date("Y-m-d H:i:s"),
+                                        "send_num" => $ornum,
+                                        "check_num" => 0,
+                                        "error_num" => 0,
+                                        "wsm_code" => $cgdinfo['wsm_code'],
+                                        "order_type" =>1,
+                                        "status" => 0,
+                                        "addtime" => date("Y-m-d H:i:s"),
+                                        "updatetime" => date("Y-m-d H:i:s")
+                                    ];
+                                    $ou = Db::name("order_out")->insert($out);
+                                    if ($ou == false) {
+                                        Db::rollback();
+                                        return error_show(1002, "发货地址添加创建失败");
+                                    }
+                                }
+                            }
                         }else{
                             Db::rollback();
                             return error_show(1002,"发货地址添加创建失败");
@@ -342,6 +347,8 @@ class Sale extends Base
             return error_show(1005,$e->getMessage());
         }
     }
+
+    //采购单
     public function createCgd($data){
         $cgdCode = makeNo("CG");
         $supplier=Db::name("supplier")->where(["code"=>$data['supplierNo'],"is_del"=>0])->find();
@@ -386,7 +393,7 @@ class Sale extends Base
             "good_name"=>$data['good_name'],
             "good_num"=>$data['good_num'],
             "good_price"=>$data['sale_price'],
-            "total_fee"=>$data['total_fee'],
+            "total_fee"=>round($data['sale_price']*$data['good_num'],2),
             "pakge_fee"=>$data['pakge_fee'],
             "cert_fee"=>$data['cert_fee'],
             "open_fee"=>$data['open_fee'],
@@ -401,10 +408,10 @@ class Sale extends Base
             "supplier_name"=>$supplier['name'],
             "companyNo"=>$data['companyNo'],
             "send_status"=>1,
-            "send_num"=>"0",
+            "send_num"=>0,
             "wsend_num"=>$data['good_num'],
             "remark"=>"",
-            "status"=>1,
+            "status"=>0,//0初始化
             "lasttime"=>date("Y-m-d H:i:s"),
             "is_del"=>0,
             "order_type"=>$data['order_type'],
@@ -435,18 +442,15 @@ class Sale extends Base
                     $stokc=[
                         "spuCode"=>$data['spuCode'],
                         "wsm_code"=>$wsm_code,
-                        "wait_in_stock"=>$data['good_num'],
+                        "wait_in_stock"=>0,
                         "wait_out_stock"=>0,
                         "usable_stock"=>0,
                         "intra_stock"=>0,
-                        "total_stock"=>$data['good_num'],
+                        "total_stock"=>0,
                         "status"=>1,
                         "addtime"=>date("Y-m-d H:i:s"),
                         "updatetime"=>date("Y-m-d H:i:s")
                     ];
-                }else{
-                    $stokc['wait_in_stock']+=$data['good_num'];
-                    $stokc['updatetime']=date("Y-m-d H:i:s");
                 }
                 $stoc= Db::name("good_stock")->save($stokc);
                 if($stoc==false){
@@ -470,11 +474,6 @@ class Sale extends Base
         if($arrtime==""){
             return error_show(1004,"参数arrtime不能为空");
         }
-        $order =Db::name("order_num")->where(["orderCode"=>$orderCode,"status"=>1])->where([["wsend_num",">=",0]])
-            ->select()->toArray();
-        if(empty($order)){
-            return error_show(1004,"未找到可以发货得采购单数据");
-        }
         $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
         $apply_id =GetUserInfo($token);
         if(empty($apply_id)||$apply_id['code']!=0){
@@ -513,35 +512,18 @@ class Sale extends Base
                 $temp['arrive_time']=$arrtime;
                 $vmp = Db::name('order_addr')->insert($temp,true);
                 if($vmp>0){
-                    $outCode=makeNo("CK");
-                    $out=[
-                        "orderCode"=>$orderCode,
-                        "outCode"=>$outCode,
-                        "apply_id"=>$rm,
-                        "apply_name"=>$ri,
-                        "addrid"=>$vmp,
-                        "post_name"=>"",
-                        "post_code"=>"",
-                        "post_fee"=>0,
-                        "sendtime"=>date("Y-m-d H:i:s"),
-                        "send_num"=>$value['receipt_quantity'],
-                        "check_num"=>0,
-                        "error_num"=>0,
-                        "wsm_code"=>"",
-                        "order_type"=>$etid['order_type'],
-                        "status"=>0,
-                        "addtime"=>date("Y-m-d H:i:s"),
-                        "updatetime"=>date("Y-m-d H:i:s")
-                    ];
-                    $ou =Db::name("order_out")->insert($out);
-                    if($ou==false){
-                        Db::rollback();
-                        return error_show(1002,"发货地址添加创建失败");
+
+                    $order =Db::name("order_num")->where(["orderCode"=>$orderCode,"status"=>1])->where([["wsend_num",">=",0]])
+                        ->select()->toArray();
+                    if(empty($order)){
+                        return error_show(1004,"未找到可以发货得采购单数据");
                     }
                     $num = $value['receipt_quantity'];
                     $orsend=[];
                     foreach ($order as $val){
-                        $tep=[];$ornum=0;
+                        $outCode=makeNo("DF");
+                        $tep=[];
+                        $ornum=0;
                         if($val['wsend_num']>=$num){
                             $val['wsend_num']-=$num;
                             $val['send_num']+=$num;
@@ -571,10 +553,70 @@ class Sale extends Base
                             Db::rollback();
                             return error_show(1002,"发货地址添加创建失败");
                         }
+                        $cgdinfo =Db::name("purchease_order")->where(["cgdNo"=>$val['cgdNo']])->find();
+                        if($cgdinfo==false){
+                            Db::rollback();
+                            return error_show(1002,"未匹配到采购数据");
+                        }
+                        $out=[
+                            "orderCode"=>$orderCode,
+                            "outCode"=>$outCode,
+                            "apply_id"=>$rm,
+                            "apply_name"=>$ri,
+                            "addrid"=>$vmp,
+                            "post_name"=>"",
+                            "post_code"=>"",
+                            "post_fee"=>0,
+                            "sendtime"=>date("Y-m-d H:i:s"),
+                            "send_num"=>$ornum,
+                            "check_num"=>0,
+                            "error_num"=>1,
+                            "wsm_code"=>$cgdinfo['wsm_code'],
+                            "order_type"=>$etid['order_type'],
+                            "status"=>0,
+                            "addtime"=>date("Y-m-d H:i:s"),
+                            "updatetime"=>date("Y-m-d H:i:s")
+                        ];
+                        $ou =Db::name("order_out")->insert($out);
+                        if($ou==false){
+                            Db::rollback();
+                            return error_show(1002,"发货地址添加创建失败");
+                        }
+
+                        //维护商品所在仓库的库存 --- start
+                        $temp = Db::name('wsm_good_stock')
+                            ->field('id,usable_stock,wait_out_stock')
+                            ->where(['spuCode' => $val['spuCode'], 'wsm_code' => $cgdinfo['wsm_code']])
+                            ->find();
+                        if ($temp == false) {
+                            Db::rollback();
+                            return error_show(1004, '库存不足');
+                        }
+
+                        if (($temp['usable_stock'] - $ornum) < 0) {
+                            Db::rollback();
+                            return error_show(1004, '库存不足');
+                        }
+
+                        $up =Db::name('wsm_good_stock')
+                            ->where('id', $temp['id'])
+                            ->update([
+                                'usable_stock' => $temp['usable_stock'] - $ornum,
+                                'wait_out_stock' => $temp['wait_out_stock'] + $ornum,
+                                'updatetime' => date('Y-m-d H:i:s'),
+                            ]);
+                        if($up==false){
+                            Db::rollback();
+                            return error_show(1004, '库存更新失败');
+                        }
+                        //维护商品所在仓库的库存 --- end
+
+
                         if($num==0){
                             break;
                         }
                     }
+
                 }else{
                     Db::rollback();
                     return error_show(1002,"发货地址添加创建失败");
@@ -616,6 +658,13 @@ class Sale extends Base
         if($good_num===""){
             return error_show(1003,"参数 good_num 不能为空");
         }
+        $sale_price = isset($this->post['sale_price']) && $this->post['sale_price'] != "" ? floatval($this->post['sale_price']) : "";
+        if ($sale_price === "") {
+            return error_show(1003, "参数 sale_price 销售单价 不能为空");
+        }
+        if ($sale_price < $zxinfo['sale_price']) {
+            return error_show(1003, "修改的销售单价不能低于原来的销售单价");
+        }
         $sendtype = isset($this->post['sendtype'])&&$this->post['sendtype']!="" ? intval($this->post['sendtype']):"";
         if($sendtype==""){
             return error_show(1003,"参数sendtype不能为空");
@@ -631,7 +680,7 @@ class Sale extends Base
             "skuCode"=>$skuCode,
             "orderCode"=>$orderCode,
             "good_name"=>$zxinfo['good_name'],
-            "sale_price"=>$zxinfo['sale_price'],
+            "sale_price"=>$zxinfo['origin_price'],
             "total_fee"=>$zxinfo['total_fee'],
             "pakge_fee"=>$zxinfo['pakge_fee'],
             "cert_fee"=>$zxinfo['cert_fee'],
@@ -643,6 +692,7 @@ class Sale extends Base
             "good_type"=>1,
             "is_diff"=>$zxinfo['is_diff'],
             "order_type"=>3,
+            'send_way'=>$zxinfo['send_way']
         ];
         $token=isset($this->post['token'])&&$this->post['token']!=""? trim($this->post['token']):"";
         if($token==""){
@@ -678,7 +728,7 @@ class Sale extends Base
                 "apply_id"=>$rm,
                 "apply_name"=>$ri,
                 "origin_price"=>$zxinfo['nake_fee'],
-                "sale_price"=>$zxinfo['sale_price'],
+                "sale_price" => $sale_price,//销售单价支持修改
                 "post_fee"=>0,
                 "status"=>0,
                 "send_num"=>0,
@@ -699,7 +749,7 @@ class Sale extends Base
                 "order_type"=>3,
                 "addtime"=>date("Y-m-d H:i:s"),
                 "updatetime"=>date("Y-m-d H:i:s"),
-                'total_price'=>round($zxinfo['sale_price']*$good_num,2),
+                'total_price' => round($sale_price * $good_num, 2),
             ];
             $datainfo = Db::name('sale')->insert($data, true);
             if($datainfo>0){
@@ -740,6 +790,7 @@ class Sale extends Base
                         "config"=>$zxinfo['config'],
                         "other_config"=>$zxinfo['other_config'],
                         "weight"=>$zxinfo['weight'],
+                        "good_weight"=>$zxinfo['good_weight'],
                         "is_diff"=>$zxinfo['is_diff'],
                         "supply_area"=>$zxinfo['supply_area'],
                         "pay_way"=>$zxinfo['pay_way'],
@@ -788,7 +839,7 @@ class Sale extends Base
                             $temp['arrive_time']=$arrtime;
                             $vmp = Db::name('order_addr')->insert($temp,true);
                             if($vmp>0){
-                                $outCode=makeNo("CK");
+                                $outCode=makeNo("DF");
                                 $out=[
                                     "orderCode"=>$orderCode,
                                     "outCode"=>$outCode,
@@ -1000,6 +1051,8 @@ class Sale extends Base
             "good_num"=>$data['good_num'],
             "good_type"=>1,
             "order_type"=>4,
+            "send_way"=>$goodinfo['send_way'],
+
         ];
         $datas=[
             "orderCode"=>$orderCode,
@@ -1198,7 +1251,7 @@ class Sale extends Base
         if($origin==false){
             return false;
         }
-        $origin_price = $origin['nake_fee'];
+        $origin_price = $origin['nake_total'];
         $orderCode=makeNo("QR");
         $datas=[
             "orderCode"=>$orderCode,
@@ -1252,7 +1305,8 @@ class Sale extends Base
                 "demo_fee"=>$good['demo_fee'],
                 "good_num"=>$data['good_num'],
                 "good_type"=>1,
-                "order_type"=>2,
+                "order_type"=>$good['is_stock']==1?1:2,
+                'send_way'=>2
             ];
             if($good['is_stock']==0) {
                 $bol = $this->createCgd($cgd);
@@ -1884,7 +1938,7 @@ class Sale extends Base
                     if ($dio['send_type'] == 1) {
                         $addr = Db::name('order_addr')->where(["orderCode" => $dio['orderCode'], 'is_del' => 0])->select();
                         foreach ($addr as $value) {
-                            $outCode = makeNo("CK");
+                            $outCode = makeNo("DF");
                             $data = [
                                 "wsm_code" => $wsm['wsm_code'],
                                 "orderCode" => $dio['orderCode'],
@@ -1912,7 +1966,7 @@ class Sale extends Base
                                 return error_show(1003, "创建失败");
                             }
                         }
-                        $wsm_in_code = makeNo("IC");
+                        $wsm_in_code = makeNo("CF");
                         $orin = [
                             "wsm_in_code" => $wsm_in_code,
                             "cgdNo" => $cgd,
@@ -2025,7 +2079,7 @@ class Sale extends Base
     public function out()
     {
         $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
-        $outCode = makeNo("CK");
+        $outCode = makeNo("DF");
         $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
         if ($orderCode == "") {
             return error_show(1002, "参数orderCoder不能为空");
@@ -2298,13 +2352,12 @@ class Sale extends Base
 //        }
         $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
         if ($supplierNo != "") {
-            $supplier = Db::name("supplier")->where([['code', "like", "%$supplierNo%"]])->column('code');
-//            if(empty($supplier)){
-//                return error_show(1004,"未找到供应商信息");
-//            }
-            $wsmcode = Db::name("sale")->where([
-                "is_del" => 0, "supplierNo" => $supplier])->column("orderCode");
-            $where[] = ['a.orderCode', "in", $wsmcode];
+//            $supplier = Db::name("business")->where([['code', "like", "%$supplierNo%"]])->column('code');
+////            if(empty($supplier)){
+////                return error_show(1004,"未找到供应商信息");
+////            }
+//            $wsmcode = Db::name("sale")->where(["is_del" => 0, "supplierNo" => $supplier])->column("orderCode");
+            $where[] = ['c.supplierNo', "like", "%$supplierNo%"];
         }
         $companyNo =isset($this->post['companyNo']) &&$this->post['companyNo'] !=="" ? trim($this->post['companyNo']):"";
         if($companyNo!=""){
@@ -2314,25 +2367,27 @@ class Sale extends Base
         $count = Db::name('sale_diff')->alias('a')
             ->join("sale c", "c.orderCode=a.orderCode", "left")
             ->join("customer_info v", "v.companyNo=c.customer_code", "left")
-            ->join("good b", "b.good_code=a.good_code", "left")
             ->where($where)->count();
         $total = ceil($count / $size);
-        $page = $page >= $total ? $total : $page;
-       //var_dump( Db::name('sale_diff')->getLastSql());
+        $page = $page >= $total ? intval($total) : $page;
         $list = Db::name('sale_diff')->alias('a')
             ->join("sale c", "c.orderCode=a.orderCode", "left")
             ->join("customer_info v", "v.companyNo=c.customer_code", "left")
-            ->join("good b", "b.good_code=a.good_kode", "left")
-            ->where($where)->page($page, $size)->field("a.*,b.cat_id,c.customer_code,v.companyName")
+            ->where($where)->page($page, $size)->field("a.*,c.customer_code,v.companyName,c.skuCode,c.order_type,c.supplierNo")
             ->order("a.addtime desc")->select();
 
         $data = [];
         foreach ($list as $value) {
-            $value['can'] = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
-            $wsm = Db::name("sale")->alias("a")->Join("supplier b", "a.supplierNo=b.code", "left")->where
-            (['a.orderCode' => $value['orderCode'], "a.is_del" => 0])->field("b.code,b.name")->find();
-            $value['supplierNo'] = isset($wsm['code']) ? $wsm['code'] : "";
-            $value['supplierName'] = isset($wsm['name']) ? $wsm['name'] : "";
+            if($value['order_type']==3|| $value['order_type']==4){
+                $goon = Db::name("good_zixun")->where(["spuCode"=>$value['good_code'],"is_del"=>0])->find();
+            }else {
+                $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
+                    ->where(['a.skuCode' => $value['skuCode']])->find();
+            }
+            $value['can'] = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
+            $wsm = Db::name("business")->where(['companyNo' => $value['supplierNo']])->find();
+            $value['supplierNo'] = isset($wsm['companyNo']) ? $wsm['companyNo'] : "";
+            $value['supplierName'] = isset($wsm['company']) ? $wsm['company'] : "";
             $data[] = $value;
         }
         return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
@@ -2397,25 +2452,43 @@ class Sale extends Base
             return error_show(1004, "参数id不能为空");
         }
         $info = Db::name("sale_diff")->where(["id" => $id])->find();
-        if (empty($info)) {
+        if ($info==false) {
             return error_show(1004, "订单数据未找到");
         }
+        $cgd = Db::name("purchease_diff")->where(['id'=>$info['cgd_diffid']])->find();
+        if($cgd==false){
+            return error_show(1004, "采购工差单数据未找到");
+        }
         $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "3";
         $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
         $ite=$info['status'];
-        $info['status'] = $status;
-        $info['remark'] = $remark;
-        $info['updatetime'] = date("Y-m-d H:i:s");
-        $up = Db::name("sale_diff")->save($info);
-        if ($up) {
-            $stx = ["order_code"=>$info["orderCode"],"status"=>$ite,"action_remark"=>'',"action_type"=>"status"];
-            ActionLog::logAdd($this->post['token'],$stx,"QRGCD",$info['status'],$info);
-            $order=["order_type"=>"QRGCD","order_code"=>$info["orderCode"],"order_id"=>$info['id'],"order_status"=>$info['status']];
-            ProcessOrder::AddProcess($this->post['token'],$order);
-            return app_show(0, "更新成功");
-        } else {
-            return error_show(1003, "更新失败");
+        Db::startTrans();
+        try{
+            $upda=[
+                "status"=>$status,
+                "remark"=>$remark,
+                "updatetime"=> date("Y-m-d H:i:s"),
+            ];
+            $up = Db::name("sale_diff")->where($info)->save($upda);
+            if ($up) {
+                $stx = ["order_code"=>$info["orderCode"],"status"=>$ite,"action_remark"=>'',"action_type"=>"status"];
+                ActionLog::logAdd($this->post['token'],$stx,"QRGCD",$info['status'],$info);
+                $order=["order_type"=>"QRGCD","order_code"=>$info["orderCode"],"order_id"=>$info['id'],"order_status"=>$status];
+                ProcessOrder::AddProcess($this->post['token'],$order);
+                $cgdup =Db::name("purchease_diff")->where(["id"=>$info['cgd_diffid']])->save($upda);
+                if($cgdup){
+                    Db::commit();
+                    return app_show(0, "更新成功");
+                }
+            }
+                Db::rollback();
+                return error_show(1003, "更新失败");
+
+        }catch (\Exception $e){
+            Db::rollback();
+            return error_show(1003,$e->getMessage());
         }
+
     }
 
     /**
@@ -2430,11 +2503,26 @@ class Sale extends Base
         if ($id === "") {
             return error_show(1004, "参数id不能为空");
         }
-        $info = Db::name('sale_diff')->alias('a')->join("good b", "b.good_code=a.good_kode", "left")->where
-        (["a.id" => $id])->field("a.*,b.cat_id")->find();
+        $info = Db::name('sale_diff')->where(["id" => $id])->find();
         if (empty($info)) {
-            return error_show(1004, "订单数据未找到");
+            return error_show(1004, "工差订单数据未找到");
         }
+        $einfo = Db::name('sale')->where(['orderCode' => $info['orderCode'], 'is_del' => 0])->find();
+        if ($einfo==false) {
+            return error_show(1002, "未找到销售订单数据");
+        }
+        if($einfo['order_type']==3|| $einfo['order_type']==4){
+            $goon = Db::name("good_zixun")->where(["spuCode"=>$einfo['good_code'],"is_del"=>0])->find();
+        }else {
+            $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
+                ->where(['a.skuCode' => $einfo['skuCode']])->find();
+        }
+        if($goon==false){
+            return error_show(1002, "未找到商品数据");
+        }
+        $info['skuCode'] =isset($goon['skuCode']) ? $goon['skuCode']:"";
+        $info['spuCode'] =isset($goon['spuCode']) ? $goon['spuCode']:"";
+        $info['order_type'] =isset($einfo['order_type']) ? $einfo['order_type']:"";
         $info['can'] = isset($info['cat_id']) && $info['cat_id'] !== 0 ? made($info['cat_id']) : [];
         return app_show(0, "获取成功", $info);
     }
@@ -2563,6 +2651,8 @@ class Sale extends Base
         $codeinfo['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
         $codeinfo['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
         $codeinfo['can'] = $int;
+        $orderReturn = Db::name("order_return")->where(["outCode"=>$outCode,"is_del"=>0])->order("id desc")->find();
+        $codeinfo['order_return'] = $orderReturn ;
         return app_show(0, "获取成功", $codeinfo);
     }
 
@@ -2644,7 +2734,7 @@ class Sale extends Base
                     $num = $send_num;
                     $data=[];
                     foreach ($order as $val){
-                        $outCode = makeNo("CK");
+                        $outCode = makeNo("DF");
                         $cgd =Db::name("purchease_order")->where(["cgdNo"=>$val['cgdNo']])->find();
                         $tep=[];
                         $ornum=0;
@@ -2696,6 +2786,32 @@ class Sale extends Base
                             "addtime" => date("Y-m-d H:i:s"),
                             "updatetime" => date("Y-m-d H:i:s")
                         ];
+                        //维护商品所在仓库的库存 --- start
+                        $temp = Db::name('wsm_good_stock')
+                            ->field('id,usable_stock,wait_out_stock')
+                            ->where(['spuCode' => $der['spuCode'], 'wsm_code' => $cgd['wsm_code']])
+                            ->find();
+                        if ($temp == false) {
+                            Db::rollback();
+                            return error_show(1004, '库存不足');
+                        }
+
+                        if (($temp['usable_stock'] - $ornum) < 0) {
+                            Db::rollback();
+                            return error_show(1004, '库存不足');
+                        }
+
+                        $up =Db::name('wsm_good_stock')
+                            ->where('id', $temp['id'])
+                            ->update([
+                                'usable_stock' => $temp['usable_stock'] - $ornum,
+                                'wait_out_stock' => $temp['wait_out_stock'] + $ornum,
+                                'updatetime' => date('Y-m-d H:i:s'),
+                            ]);
+                        if($up==false){
+                            Db::rollback();
+                            return error_show(1004, '库存更新失败');
+                        }
                         if($num==0){
                             break;
                         }
@@ -2747,6 +2863,8 @@ class Sale extends Base
         $outinfo['sendtime'] = date("Y-m-d H:i:s");
         $outinfo['status'] = 2;
         $outinfo['updatetime'] = date("Y-m-d H:i:s");
+
+        Db::startTrans();
         try{
             $up =Db::name("order_out")->save($outinfo);
             if($up){
@@ -2915,76 +3033,74 @@ class Sale extends Base
 
     }
 
-    public function  getPrice(){
-        $skuCode=isset($this->post['skuCode'])&&$this->post['skuCode']!=""?trim($this->post['skuCode']):"";
-        if($skuCode===""){
-            return error_show(1003,"参数skuCode不能为空");
+    public function getPrice()
+    {
+        $skuCode = isset($this->post['skuCode']) && $this->post['skuCode'] != "" ? trim($this->post['skuCode']) : "";
+        if ($skuCode === "") {
+            return error_show(1003, "参数skuCode不能为空");
         }
-        $is_activity=isset($this->post['is_activity'])&&$this->post['is_activity']!==""?intval($this->post['is_activity'])
-            :"";
-        if($is_activity===""){
-            return error_show(1003,"参数is_activity不能为空");
+        $is_activity = isset($this->post['is_activity']) && $this->post['is_activity'] !== "" ? intval($this->post['is_activity'])
+            : "";
+        if ($is_activity === "") {
+            return error_show(1003, "参数is_activity不能为空");
         }
-        $sale_num=isset($this->post['sale_num'])&&$this->post['sale_num']!==""?intval($this->post['sale_num']):"";
-        if($sale_num===""){
-            return error_show(1003,"参数sale_num不能为空");
+        $sale_num = isset($this->post['sale_num']) && $this->post['sale_num'] !== "" ? intval($this->post['sale_num']) : "";
+        if ($sale_num === "") {
+            return error_show(1003, "参数sale_num不能为空");
         }
         $ct = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
-            ->where(['a.skuCode' =>$skuCode])->find();
+            ->where(['a.skuCode' => $skuCode])->find();
         if ($ct == false) {
             return error_show(1002, "未找到商品数据");
         }
-        $origin = Db::name("good_nake")->where([["spuCode","=",$ct['spuCode']],["min_num","<=", $sale_num],["is_del","=",
-            0]])->order("min_num desc")->find();
-        if($origin==false){
-            $origin = Db::name("good_nake")->where([["spuCode","=",$ct['spuCode']],["is_del","=",
-                0]])->order("min_num asc")->find();
-            return error_show(1003,"不满足成本最低阶梯数量{$origin['min_num']}");
-        }
-        $stock=0;
-        if($ct['is_stock']==1){
-            $good_stock =Db::name("good_stock")->where(["spuCode"=>$ct['spuCode'],"is_del"=>0])->find();
-            $stock= isset($good_stock['usable_stock'])?$good_stock['usable_stock']:"0";
-        }
-        if($is_activity==1){
-            $act = Db::name("activity_info")->alias("a")->leftJoin("good_activity b","a.activity_code=b.activity_code")
-                ->where(["a.skuCode"=>$skuCode,"a.is_del"=>0,"a.status"=>1,"b.status"=>6,"b.is_del"=>0])->find();
-            if($act==false){
-                return error_show(1003,"未找到相关活动价");
-            }
-            if($act['moq_num']>$sale_num){
-                return error_show(1003,"商品不满足活动价起订量{$act['moq_num']}");
+
+        $stock = 0;
+        if ($ct['is_stock'] == 1) {
+            $good_stock = Db::name("good_stock")->where(["spuCode" => $ct['spuCode'], "is_del" => 0])->find();
+            $stock = isset($good_stock['usable_stock']) ? $good_stock['usable_stock'] : "0";
+        }
+        if ($is_activity == 1) {
+            $act = Db::name("activity_info")->alias("a")->leftJoin("good_activity b", "a.activity_code=b.activity_code")
+                ->where(["a.skuCode" => $skuCode, "a.is_del" => 0, "a.status" => 1, "b.status" => 6, "b.is_del" => 0])->find();
+            if ($act == false) {
+                return error_show(1003, "未找到相关活动价");
             }
-            if($act['activity_stock']<$sale_num){
-                return error_show(1003,"商品活动库存剩余{$act['activity_stock']}");
+            if ($act['moq_num'] > $sale_num) {
+                return error_show(1003, "商品不满足活动价起订量{$act['moq_num']}");
             }
-            return app_show(0,"获取成功",['sale_price'=>$act['activity_price'],"stock"=>$act['activity_stock']]);
-        }else{
-          $good = Db::name("good_ladder")->where(["skuCode"=>$skuCode,"is_del"=>0,"status"=>1])->order("min_num desc")
-              ->select()->toArray();
-            if(empty($good)){
-                return error_show(1003,"未找到相关阶梯价格");
+            if ($act['activity_stock'] < $sale_num) {
+                return error_show(1003, "商品活动库存剩余{$act['activity_stock']}");
             }
-            $lastnum=0;
-            $lastprice=0;
-            foreach ($good as $value){
-
-                if($value['min_num']>$sale_num){
-                    $lastnum=$value['min_num'];
-                    $lastprice=0;
-                    continue;
-                }else{
-                    $lastnum=0;
-                    $lastprice=$value['sale_price'];
-                    break;
+            return app_show(0, "获取成功", ['sale_price' => $act['activity_price'], "stock" => $act['activity_stock']]);
+        } else {
+
+            if ($ct['is_stock'] == 0) {
+                //good_nake 成本阶梯 good_ladder销售阶梯
+                $origin = Db::name("good_nake")->where([["spuCode", "=", $ct['spuCode']], ["is_del", "=", 0]])->order("min_num asc")->find();
+                if (!$origin) {
+                    return error_show(1003, "没有找到成本数据");
                 }
+            }
 
+            $good = Db::name("good_ladder")->where(["skuCode" => $skuCode, "is_del" => 0, "status" => 1])->order("min_num asc")->find();
+            if (!$good) {
+                return error_show(1003, "未找到相关阶梯价格");
             }
-            if($lastnum==0){
-                return app_show(0,"获取成功",['sale_price'=>$lastprice,"stock"=>$stock]);
-            }else{
-                return error_show(1003,"商品不满足起订量{$lastnum}");
+
+            if(!isset($origin['min_num'])) $origin['min_num']=0;
+
+            $lastnum = max($origin['min_num']??0, $good['min_num']);
+            if ($sale_num < $lastnum) {
+                return error_show(1003, "商品不满足起订量{$lastnum}");
             }
+
+            $good_temp = Db::name("good_ladder")->where(["skuCode" => $skuCode, "is_del" => 0, "status" => 1])->where('min_num', '<=', $sale_num)->order("min_num desc")->find();
+            if (!$good_temp) {
+                return error_show(1003, "未找到相关阶梯价格");
+            }
+
+            return app_show(0, "获取成功", ['sale_price' => $good_temp['sale_price'], "stock" => $stock]);
+
         }
     }
 
@@ -3044,6 +3160,7 @@ class Sale extends Base
         $palt =Db::name("platform")->where(["id"=>$order['platform_id']])->find();
         $order['platform_name']=isset($palt['platform_name']) ? $palt['platform_name']:"";
         $order["gold_price"] = isset($price['price'])?$price['price']:0;
+        $order["noble_weight"] = isset($order['weight'])?$order['weight']:0;
         return app_show(0,"获取成功",$order);
     }
 }

+ 3 - 3
app/admin/controller/Salezx.php

@@ -18,7 +18,7 @@ class Salezx extends \app\BaseController
 
     public function create(){
         $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
-        $orderCode=makeNo("CX");
+        $orderCode=makeNo("QR");
         $customer_code= isset($this->post['customer_code'])&& $this->post['customer_code'] !=="" ? trim($this->post['customer_code']) :"";
         if($customer_code==""){
             return error_show(1002,"客户code不能为空");
@@ -159,7 +159,7 @@ class Salezx extends \app\BaseController
                         $temp['arrive_time']=$value['arrive_time'];
                         $vmp = Db::name('order_addr')->insert($temp,true);
                         if($vmp>0){
-                            $outCode=makeNo("CK");
+                            $outCode=makeNo("DF");
                             $out=[
                                 "orderCode"=>$orderCode,
                                 "outCode"=>$outCode,
@@ -524,7 +524,7 @@ class Salezx extends \app\BaseController
 
     public function outaddr(){
         $token= isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
-        $outCode=makeNo("CK");
+        $outCode=makeNo("DF");
         $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
         if($orderCode==""){
             return error_show(1002,"参数orderCoder不能为空");

+ 2 - 0
app/admin/controller/Share.php

@@ -7,6 +7,8 @@ use app\BaseController;
 use think\Request;
 use think\facade\Db;
 use app\admin\model\ActionLog;
+
+//角色权限共享
 class Share extends BaseController
 {
     /**

+ 1 - 12
app/admin/controller/Specs.php

@@ -7,6 +7,7 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 
+//商品规格
 class Specs extends BaseController
 {
     public $post="";
@@ -143,23 +144,11 @@ class Specs extends BaseController
         if($spec_name==""){
             return error_show(1002,"参数spec_name不能为空");
         }
-//        $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
-//        if($token==''){
-//            return error_show(105,"参数token不能为空");
-//        }
-//        $user =GetUserInfo($token);
-//        if(empty($user)||$user['code']!=0){
-//            return error_show(1002,"创建人数据不存在");
-//        }
-//        $createrid= isset($user["data"]['id']) ?  $user["data"]['id'] : "";
-//        $creater= isset($user["data"]['nickname']) ?  $user["data"]['nickname'] : "";
         $exam_status = isset($this->post['exam_status']) &&$this->post['exam_status'] !==""? intval($this->post['exam_status']):"0";
         $status = isset($this->post['status']) &&$this->post['status'] !==""? intval($this->post['status']):"0";
         $data = [
             "id"=>$id,
             "spec_name"=>$spec_name,
-//            "creater"=>$creater,
-//            "createrid"=>$createrid,
             "exam_status"=>$exam_status,
             "status"=>$status,
             "is_del"=>0,

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

@@ -6,6 +6,7 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 
+//规格值
 class Specvalue extends BaseController
 {
     public $post="";

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

@@ -8,6 +8,7 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 
+//供应商
 class Suppler extends BaseController
 {
     public $post = "";

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

@@ -7,6 +7,7 @@ use app\BaseController;
 use think\facade\Db;
 use think\Request;
 
+//系统设置
 class System extends BaseController
 {
     /**

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

@@ -7,6 +7,7 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 
+//客户的营业执照相关信息
 class Title extends BaseController
 {
     public $post = "";

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

@@ -7,6 +7,7 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 
+//单位
 class Unit extends BaseController
 {
     public $post ="";

+ 2 - 0
app/admin/controller/User.php

@@ -6,6 +6,8 @@ namespace app\admin\controller;
 use app\BaseController;
 use think\facade\Db;
 use app\admin\model\ActionLog;
+
+//用户
 class User extends BaseController
 {
     /**

+ 327 - 0
app/admin/controller/Version.php

@@ -6,6 +6,7 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 
+//版本
 class Version extends BaseController
 {
     public function __construct(App $app)
@@ -53,4 +54,330 @@ class Version extends BaseController
         }
     }
 
+    public function info(){
+        $projectNo = isset($this->post['projectNo'])&&$this->post['projectNo']!==""?trim($this->post['projectNo']):"";
+        if($projectNo==""){
+            return error_show(1004,"参数projectNo不能为空");
+        }
+
+        $type = isset($this->post['type'])&&$this->post['type']!=="" ? intval($this->post['type']) :0;
+
+        $info =Db::name("project")->where(["projectNo"=>$projectNo,"is_del"=>0])->find();
+        if($info==false){
+            return error_show(1004,"未找到项目信息");
+        }
+        $plat = Db::name("platform")->where(['id'=>$info['platform_id']])->find();
+        $info['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
+        $info['platform_code']=isset($plat['platform_code'])?$plat['platform_code']:"";
+
+        $khinfo = Db::name("customer_info")->where(["companyNo"=>$info['khNo']])->find();
+        $info['khName'] = isset($khinfo['companyName'])?$khinfo['companyName']:"";
+        $company = Db::name("business")->where(["companyNo"=>$info['companyNo']])->find();
+        $info['company'] = isset($company['company'])?$company['company']:"";
+
+        $ladder = Db::name("project_info")->where(['projectNo'=>$projectNo,"is_del"=>0])->select()->toArray();
+        $info['ladder']=[];
+        if(!empty($ladder)){
+            foreach ($ladder as $value){
+                $value["cat_info"]=isset($value['cat_id']) &&$value['cat_id']!=""? made($value['cat_id'],[]):[];
+                $condition  = $type==0?['pgNo'=>$value['pgNo'],"is_del"=>0] : ['pgNo'=>$value['pgNo'],"is_del"=>0,"status"=>1];
+                $feedback = Db::name("project_feedback")->where($condition)->select()->toArray();
+                array_walk($feedback,function (&$v){
+                    $v["cat_info"]=isset($v['cat_id'])&&$v['cat_id']!=""? made($v['cat_id'],[]):[];
+                });
+
+                $value['feedback']=$feedback;
+                $info['ladder'][]=$value;
+            }
+        }
+        return app_show(0,"获取成功",$info);
+    }
+    public function  feedlist(){
+        $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;
+        $where=[["is_del","=",0]];
+        $pgNo =isset($this->post['pgNo'])&&$this->post['pgNo']!==""?trim($this->post['pgNo']):"";
+        if($pgNo!==""){
+            $where[]=["pgNo","=",$pgNo];
+        }
+        $projectNo =isset($this->post['projectNo'])&&$this->post['projectNo']!==""?trim($this->post['projectNo']):"";
+        if($projectNo!==""){
+            $where[]=["projectNo","=",$projectNo];
+        }
+        $source =isset($this->post['source'])&&$this->post['source']!==""?intval($this->post['source']):"";
+        if($source!==""){
+            $where[]=["data_source","=",$source];
+        }
+        $cat_id =isset($this->post['cat_id'])&&$this->post['cat_id']!==""?intval($this->post['cat_id']):"";
+        if($cat_id!==""){
+            $where[]=["cat_id","=",$cat_id];
+        }
+        $status =isset($this->post['status'])&&$this->post['status']!==""?intval($this->post['status']):"";
+        if($status!==""){
+            $where[]=["status","=",$status];
+        }
+        $count = Db::name('project_feedback')->where($where)->count();
+        $total = ceil($count / $size);
+        $page = $page >= $total ? $total : $page;
+        $list = Db::name('project_feedback')->where($where)->page($page,$size)->order("addtime desc")->select();
+        $data=[];
+        foreach ($list as $value){
+            $value['can']=isset($value['cat_id'])&&$value['cat_id']!=""?made($value['cat_id']):"";
+
+            if($value['data_source']==1){
+                $good=Db::name("good_platform")->alias("a")->leftJoin("good b","a.spuCode=b.spuCode")->where
+                (["a.skuCode"=>$value['skuCode'],"a.is_del"=>0])->find();
+                $nake = Db::name("good_nake")->where([["spuCode","=",$value['spuCode']],["min_num","<=",
+                    $value["num"]],["is_del","=",0]])->order("min_num desc")->find();
+                $good['unit_id'] = isset($good['good_unit'])?$good['good_unit']:"";
+                $good['cost_desc'] = isset($good['craft_desc'])?$good['craft_desc']:"";
+                $good['pakge_fee'] = isset($nake['package_fee'])?$nake['package_fee']:"0";
+                $good['mark_fee'] = isset($nake['mark_fee'])?$nake['mark_fee']:"0";
+                $good['other_fee'] = isset($nake['other_fee'])?$nake['other_fee']:"0";
+                $good['cert_fee'] = isset($nake['cert_fee'])?$nake['cert_fee']:"0";
+                $good['delivery_fee'] = isset($nake['delivery_fee'])?$nake['delivery_fee']:"0";
+                $good['nake_fee'] = isset($nake['nake_fee'])?$nake['nake_fee']:"0";
+                $good['metal_id'] = isset($good['noble_metal'])?$good['noble_metal']:"0";
+                $spec = Db::name("good_spec")->where(["spuCode"=>$good['spuCode'],"is_del"=>0])->select()->toArray();
+                $good['specinfo']=[];
+                if(!empty($spec)){
+                    foreach ($spec as $vae){
+                        $specs=Db::name("specs")->where(["id"=>$vae['spec_id']])->find();
+                        $spec_value = Db::name("spec_value")->where(["id"=>$vae["spec_value_id"]])->find();
+                        $temp = ["specid"=>$vae['spec_id'],"spec_name"=>$specs['spec_name'],"spec_value_id"=>$vae['spec_value_id'],"spec_value_name"=>$spec_value["spec_value"]];
+                        $good['specinfo'][]=$temp;
+                    }
+
+                }
+                $nake =Db::name("good_nake")->where(["spuCode"=>$good['spuCode'],"is_del"=>0])->where([["min_num","<=",$value['num']]])
+                    ->order("min_num desc")->find();
+                $good['origin_price']=$nake['nake_total'];
+                $good['work_day']=$good['lead_time'];
+                $good_img = $good['good_thumb_img'];
+
+            }else{
+                $good=Db::name("consult_bids")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
+                $good['specinfo'] = isset($good['specinfo'])&&$good['specinfo']!=""?json_decode($good['specinfo'],
+                    true):"";
+                $catinfo = Db::name("cat")->where(["id"=>$good['cat_id']])->find();
+                $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:100;
+                $good_img = $good['good_img'];
+            }
+            $nobel =\think\facade\Config::get("noble");
+            $value['good_name'] = isset($good['good_name'])?$good['good_name']:"";
+            //  $value['good_img'] = isset($good['good_img'])?$good['good_img']:"";
+            $value['brand_id'] = isset($good['brand_id'])?$good['brand_id']:"";
+            $brand = Db::name("brand")->where(['id'=>$value["brand_id"]])->find();
+            $value['brand_name'] =isset($brand['brand_name']) ? $brand['brand_name']:"";
+            $value['specinfo'] = isset($good['specinfo'])&&$good['specinfo']!=""?$good['specinfo']:[];
+            $value['unit_id'] = isset($good['unit_id'])?$good['unit_id']:"";
+            $unit = Db::name("unit")->where(['id'=>$value["unit_id"]])->find();
+            $value["unit_name"]=isset($unit['unit'])?$unit['unit']:"";
+            $value['cost_desc'] = isset($good['cost_desc'])?$good['cost_desc']:"";
+            $value['work_day'] = isset($good['work_day'])?$good['work_day']:"";
+            $value['delivery_day'] = isset($good['delivery_day'])?$good['delivery_day']:"";
+            $value['expire_day'] = isset($good['expire_day'])?$good['expire_day']:"0";
+            $value['good_img'] = $good_img;
+            $value['expire_day'] = isset($good['expire_day'])?$good['expire_day']:"";
+            $value['origin_place'] = isset($good['origin_place'])?$good['origin_place']:"";
+            $value['supplierNo'] = isset($good['supplierNo'])?$good['supplierNo']:"";
+            $value['pay_way'] = isset($good['pay_way'])?$good['pay_way']:"";
+            $value['tax'] = isset($good['tax'])?$good['tax']:"";
+            $value['send_way'] = isset($good['send_way'])?$good['send_way']:"";
+            $value['metal_id'] = isset($good['metal_id'])?$good['metal_id']:"";
+            $value['metal_name'] = isset($nobel[$good['metal_id']])?$nobel[$good['metal_id']]:"";
+            $value['is_gold_price'] = isset($good['is_gold_price'])?$good['is_gold_price']:"0";
+            $value['config'] = isset($good['config'])?$good['config']:"";
+            $value['other_config'] = isset($good['other_config'])?$good['other_config']:"";
+            $value['weight'] = isset($good['weight'])?$good['weight']:"";
+            $value['is_diff'] = isset($good['is_diff'])?$good['is_diff']:"0";
+            $value['demo_fee'] = isset($good['demo_fee'])?$good['demo_fee']:"0";
+            $value['deivery_fee'] = isset($good['deivery_fee'])?$good['deivery_fee']:"0";
+            $value['open_fee'] = isset($good['open_fee'])?$good['open_fee']:"0";
+            $value['pakge_fee'] = isset($good['pakge_fee'])?$good['pakge_fee']:"0";
+            $value['nake_fee'] = isset($good['nake_fee'])?$good['nake_fee']:"0";
+            $value['mark_fee'] = isset($good['mark_fee'])?$good['mark_fee']:"0";
+            $value['cert_fee'] = isset($good['cert_fee'])?$good['cert_fee']:"0";
+            $value['cost_fee'] = isset($good['cost_fee'])?$good['cost_fee']:"0";
+            $value['rate'] =round(($value['sale_price'] - $value['origin_price'])/$value['sale_price'] * 100,2);
+            $value['supply_area'] = isset($good['supply_area'])?$good['supply_area']:"";
+            $data[]=$value;
+        }
+        return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
+    }
+    public function project_plan(){
+        $projectNo = isset($this->post['projectNo'])&&$this->post['projectNo']!==""?trim($this->post['projectNo']):"";
+        if($projectNo==""){
+            return error_show(1004,"参数projectNo不能为空");
+        }
+
+        $type = isset($this->post['type'])&&$this->post['type']!=="" ? intval($this->post['type']) :0;
+
+        $info =Db::name("project")->where(["projectNo"=>$projectNo,"is_del"=>0])->find();
+        if($info==false){
+            return error_show(1004,"未找到项目信息");
+        }
+        $plat = Db::name("platform")->where(['id'=>$info['platform_id']])->find();
+        $info['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
+        $info['platform_code']=isset($plat['platform_code'])?$plat['platform_code']:"";
+
+        $khinfo = Db::name("customer_info")->where(["companyNo"=>$info['khNo']])->find();
+        $info['khName'] = isset($khinfo['companyName'])?$khinfo['companyName']:"";
+        if($type==1){
+            $where = ['projectNo'=>$projectNo,"is_del"=>0,"status"=>1];
+        }else{
+            $where = ['projectNo'=>$projectNo,"is_del"=>0];
+        }
+        $ladder = Db::name("project_plan")->where($where)->order("addtime desc")->select()->toArray();
+        $info=[];
+        if(!empty($ladder)){
+            foreach ($ladder as $value){
+                $value['feedback']=[];
+                $feedback =Db::name("project_plan_rela")->where(["planNo"=>$value['planNo'],"is_del"=>0])->column("feedback_id,sale_price,sale_num");
+                if(!empty($feedback)){
+                    $feedid = array_column($feedback,"feedback_id");
+                    $feedlist = Db::name("project_feedback")->where(["id"=>$feedid,"is_del"=>0])->select();
+                    if(!empty($feedlist)){
+                        foreach ($feedlist as $val){
+                            $key =array_search($val['id'],$feedid);
+                            $price = $feedback[$key]['sale_price'];
+                            $val["cat_info"]=isset($val['cat_id'])&&$val['cat_id']!=""? made($val['cat_id'],[]):[];
+                            $val["sale_price"]=$price;
+                            $val["origin_num"]=$val['num'];
+                            $val["num"]=$feedback[$key]['sale_num'];
+                            if($val['data_source']!=1){
+                                $good=Db::name("consult_bids")->where(["spuCode"=>$val['spuCode'],"is_del"=>0])->find();
+                                $good['specinfo']=isset($good['specinfo'])&&$good['specinfo']!=""?json_decode($good['specinfo'],true):[];
+                            }else{
+                                $good=Db::name("good")->where(["spuCode"=>$val['spuCode'],"is_del"=>0])->find();
+                                $spec = Db::name("good_spec")->where(["spuCode"=>$val['spuCode'],"is_del"=>0])->select()->toArray();
+                                $good['specinfo']=[];
+                                if(!empty($spec)){
+                                    foreach ($spec as $vae){
+                                        $specs=Db::name("specs")->where(["id"=>$vae['spec_id']])->find();
+                                        $spec_value = Db::name("spec_value")->where(["id"=>$vae["spec_value_id"]])->find();
+                                        $temp = ["specid"=>$vae['spec_id'],"spec_name"=>$specs['spec_name'],"spec_value_id"=>$vae['spec_value_id'],"spec_value_name"=>$spec_value["spec_value"]];
+                                        $good['specinfo'][]=$temp;
+                                    }
+                                }
+                            }
+                            if(isset($good['brand_id'])){
+                                $brand =Db::name("brand")->where(["id"=>$good['brand_id']])->find();
+                            }
+                            $val['good_img']=isset($good['good_img'])&&$good['good_img']!=""?trim($good['good_img']):"";
+                            $val['brand_id']=isset($good['brand_id'])&&$good['brand_id']!=""?$good['brand_id']:"";
+                            $val['brand_name']=isset($brand['brand_name'])&&$brand['brand_name']!=""?$brand['brand_name']:"";
+                            $val['specinfo']=isset($good['specinfo'])&&$good['specinfo']!=""?$good['specinfo']:[];
+                            $value['feedback'][]=$val;
+                        }
+                    }
+                }
+                $info[]=$value;
+            }
+        }
+        return app_show(0,"获取成功",$info);
+    }
+    public function  feedCheck(){
+        $feedid = isset($this->post['feedid'])&&!empty($this->post['feedid']) ? $this->post['feedid'] :[];
+        if(empty($feedid)){
+            return error_show(1004,"参数feedid不能为空");
+        }
+        $feedid=array_unique($feedid);
+        $selec = Db::name("project_feedback")->where(["id"=>$feedid,'is_del'=>0,"status"=>0])->select()->toArray();
+        if(empty($selec)){
+            return error_show(1004,"反馈数据信息未找到");
+        }
+        $pgnos =array_column($selec,"pgNo");
+        $infolist =   Db::name("project_info")->where(['pgNo'=>$pgnos])->select()->toArray();
+        if(empty($infolist)){
+            return error_show(1004,"项目商品数据未找到");
+        }
+        Db::startTrans();
+        try{
+            $up = Db::name("project_feedback")->where(["id"=>$feedid,'is_del'=>0,"status"=>0])->save(["status"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
+            if($up){
+
+                foreach ($infolist as $value){
+                    $value['status']=3;
+                    $value['updatetime']=date("Y-m-d H:i:s");
+                    $up = Db::name("project_info")->save($value);
+                    if($up){
+                        $count = Db::name("project_info")->where(["projectNo"=>$value['projectNo'],"status"=>2])
+                            ->count();
+                        if($count==0){
+                            $proc =Db::name("project")->where(["projectNo"=>$value['projectNo']])->save
+                            (["status"=>3,"updatetime"=>date("Y-m-d H:i:s")]);
+                            if(!$proc){
+                                Db::rollback();
+                                return error_show(1004,"反馈数据选择失败");
+                            }
+                        }
+                    }else{
+                        Db::rollback();
+                        return error_show(1004,"反馈数据选择失败");
+                    }
+                    $consult =Db::name('consult_order')->where(["projectNo"=>$value['projectNo']])->find();
+                    if($consult!=false){
+                        $up=Db::name("consult_info")->where(['zxNo'=>$consult['zxNo'],"is_del"=>0,"status"=>1])->select()
+                            ->toArray();
+                        if(!empty($up)){
+                            $staar=Db::name("consult_info")->where(['zxNo'=>$consult['zxNo'],"is_del"=>0,"status"=>1])->save
+                            (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
+                            if($staar==false){
+                                Db::rollback();
+                                return error_show(1002, "项目咨询单招标结束失败");
+                            }
+                        }
+                    }
+                }
+
+                Db::commit();
+                return app_show(0,"反馈数据选择成功");
+            }else{
+                Db::rollback();
+                return error_show(1004,"反馈数据选择失败");
+            }
+        }catch (\Exception $e){
+            Db::rollback();
+            return error_show(1004,$e->getMessage());
+        }
+
+    }
+    public function  planCheck(){
+        $planNos = isset($this->post['planNos'])&&!empty($this->post['planNos'])? $this->post['planNos'] :"";
+        if($planNos==""){
+            return error_show(1004,"参数planNos不能为空");
+        }
+        $status=isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):"";
+        if($status==""){
+            return error_show(1004,"参数status不能为空");
+        }
+        $selec = Db::name("project_plan")->where(["planNo"=>$planNos,'is_del'=>0,"status"=>0])->select()->toArray();
+        if(empty($selec)){
+            return error_show(1004,"项目方案数据信息未找到");
+        }
+        Db::startTrans();
+        try{
+            $up = Db::name("project_plan")->where(["planNo"=>$planNos,'is_del'=>0,"status"=>0])->save(["status"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
+            if($up) {
+                $project = array_column($selec, "projectNo");
+                if (empty($project)) {
+                    Db::rollback();
+                    return error_show(1004, "方案选择失败");
+                }
+                $pro = Db::name("project")->where(["projectNo" => $project, "status" => 4])->save(["status" => 5, "updatetime" => date("Y-m-d H:i:s")]);
+                if ($pro) {
+                    Db::commit();
+                    return app_show(0, "方案数据修改成功");
+                }
+            }
+            Db::rollback();
+            return error_show(1004,"方案选择失败");
+        }catch (\Exception $e){
+            Db::rollback();
+            return error_show(1004,$e->getMessage());
+        }
+
+    }
+
 }

+ 10 - 1
app/admin/controller/WareHouse.php

@@ -5,6 +5,8 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 use app\admin\model\ActionLog;
+
+//仓库
 class WareHouse extends BaseController
 {
     public function __construct(App $app)
@@ -134,7 +136,7 @@ class WareHouse extends BaseController
     public function list(){
         $post  =$this->request->post();
 
-        $condition= [['a.is_del',"=",0],['a.status',"=",1],["b.is_del","=",0]];
+        $condition= [['a.is_del',"=",0],["b.is_del","=",0]];
 
         $supplier = isset($post['supplierNo'])&&$post['supplierNo']!="" ? trim($post['supplierNo']) :"";
         if($supplier!=""){
@@ -180,6 +182,10 @@ class WareHouse extends BaseController
         if($companyNo!=""){
             $condition[]=["a.companyNo","like","%{$companyNo}%"];
         }
+        $wsm_type = isset($post['wsm_type'])&&$post['wsm_type']!="" ? (int)($post['wsm_type']) :0;
+        if($wsm_type){
+            $condition[]=["a.wsm_type",'=',$wsm_type];
+        }
         $page = isset($post['page']) &&$post['page']!=='' ?intval($post['page']) :1;
         $size = isset($post['size']) &&$post['size']!=='' ?intval($post['size']) :10;
         $count = Db::name("warehouse_info")->alias("a")->join("warehouse_addr b ","a.wsm_code=b.wsm_code","left")
@@ -211,6 +217,9 @@ class WareHouse extends BaseController
             }
             $value['addrs_cn'] =isset($value['addrs_code']) ?GetAddr($value['addrs_code']):"";
             $value['addr_cn'] =isset($value['addr_code']) ? GetAddr($value['addr_code']):"";
+
+            $value['addr_code'] = json_decode($value['addr_code'], true);
+            $value['addrs_code'] = json_decode($value['addrs_code'], true);
             $list[$key]=$value;
 
         }

+ 1 - 3
app/admin/model/ActionLog.php

@@ -12,6 +12,7 @@ use think\facade\Db;
 class ActionLog extends Model
 {
     /**
+     * 记录操作日志
      * @param $token
      * @param $order
      * @param $type
@@ -43,8 +44,5 @@ class ActionLog extends Model
         ];
         self::insert($data);
    }
-   public function  list(){}
 
-   public function info(){}
-   static function aad(){}
 }

+ 1 - 0
app/admin/model/ChangeLog.php

@@ -6,6 +6,7 @@ use think\Model;
 
 class ChangeLog extends Model
 {
+    //记录商品、咨询单的修改记录
     static function logAdd($type,$code,$before_info,$after_info,$token,$post){
         $user = GetUserInfo($token);
         unset($post['token']);

+ 1 - 0
app/admin/model/GoodLog.php

@@ -7,6 +7,7 @@ use  think\Model;
 class GoodLog extends Model
 {
     /**
+     * 记录库存的变化
      * @param $token
      * @param $data [{'stock_id':1,'stock_name':‘usable_stock’,'stock_remark':'','stock':10,'type':'cgd'}]
      * @param $action_type

+ 1 - 0
app/admin/model/OrderMsg.php

@@ -11,6 +11,7 @@ use think\Model;
  */
 class OrderMsg extends Model
 {
+    //每个用户的消息
     public static function addmsg($msg){
         $conf=Config::get("order");
         $order_type = $conf['order_type'];

+ 3 - 2
app/admin/model/ProcessOrder.php

@@ -6,12 +6,13 @@ use think\facade\Config;
 
 class ProcessOrder extends \think\Model
 {
+    //记录流程
     public static function AddProcess($token,$order){
         $user = GetUserInfo($token);
         $uid = isset($user['data']['id']) ? $user['data']['id'] :0;
         $name = isset($user['data']['nickname']) ? $user['data']['nickname'] :'';
-        $conf =Config::get("process");
-        $action = isset($conf[$order['order_type']]) ? $conf[$order['order_type']]:[];
+       // $conf =Config::get("process");
+        //$action = isset($conf[$order['order_type']]) ? $conf[$order['order_type']]:[];
 
         $data=[
             "order_type"=>$order['order_type'],

+ 1 - 0
app/admin/model/Workflow.php

@@ -4,6 +4,7 @@
 namespace app\admin\model;
 use think\facade\Config;
 
+//记录操作流程
 class Workflow extends \think\Model
 {
 

+ 8 - 15
app/admin/route/app.php

@@ -114,9 +114,6 @@ Route::rule('checkestatus','admin/Check/statu');
 Route::rule('checkexport','admin/Check/exportGood');
 Route::rule('checkimport','admin/Check/importGood');
 
-//Route::rule('veversioncreatersionlist','admin/Version/list');
-//Route::rule('','admin/Version/create');
-
 Route::rule('allotlist','admin/Allot/list');
 Route::rule('allotcreate','admin/Allot/create');
 Route::rule('allotedit','admin/Allot/edit');
@@ -199,7 +196,6 @@ Route::rule("cgddifflist","admin/Purch/difflist");
 Route::rule("cgddiffinfo","admin/Purch/diffinfo");
 Route::rule("cgddiffstatu","admin/Purch/diffstatu");
 
-
 Route::rule("orderinlist","admin/Purchin/list");
 Route::rule("orderinadd","admin/Purchin/add");
 Route::rule("orderininfo","admin/Purchin/info");
@@ -209,7 +205,6 @@ Route::rule("orderinreturn","admin/Purchin/ReturnAdd");
 Route::rule("returnsend","admin/Purchin/ReturnSend");
 Route::rule("returnstatus","admin/Purchin/ReturnStatus");
 
-
 Route::rule("processlist","admin/Process/list");
 Route::rule("processinfo","admin/Process/info");
 Route::rule("process","admin/Process/process");
@@ -230,7 +225,6 @@ Route::rule('cattlist','admin/Cat/tlist');
 Route::rule('catratedit','admin/Cat/ratedit');
 Route::rule('catwlist',"admin/Cat/wlist");
 
-
 Route::rule('backcreate','admin/Purchback/create');
 Route::rule('backlist','admin/Purchback/list');
 Route::rule('backstatus','admin/Purchback/status');
@@ -246,6 +240,7 @@ Route::rule('afterfeed','admin/After/postfeed');
 Route::rule('afterpost','admin/After/addpost');
 Route::rule('aftergys','admin/After/GysFeed');
 Route::rule('afterwsm','admin/After/GetWsm');
+Route::rule('aftercancel','admin/After/Cancel');
 //Route::rule('aftersetwsm','admin/After/setWsm');
 
 Route::rule('processolist','admin/Proorder/list');
@@ -294,7 +289,6 @@ Route::rule('attrstatus','admin/Attr/status');
 Route::rule('attredit','admin/Attr/edit');
 Route::rule('attrdelete','admin/Attr/del');
 
-
 Route::rule('specscreate','admin/Specs/create');
 Route::rule('specslist','admin/Specs/list');
 Route::rule('specsstatus','admin/Specs/status');
@@ -302,7 +296,6 @@ Route::rule('specstitle','admin/Specs/title');
 Route::rule('specsedit','admin/Specs/edit');
 Route::rule('specsdelete','admin/Specs/del');
 
-
 Route::rule('brandcreate','admin/Brand/create');
 Route::rule('brandlist','admin/Brand/list');
 Route::rule('brandedit','admin/Brand/edit');
@@ -378,7 +371,6 @@ Route::rule('platforminfo','admin/Platform/info');
 Route::rule('platformdelete','admin/Platform/del');
 Route::rule('platformstatus','admin/Platform/status');
 
-
 Route::rule('actcreate','admin/Activity/create');
 Route::rule('actcost','admin/Activity/cost');
 Route::rule('activity','admin/Activity/activity');
@@ -396,7 +388,6 @@ Route::rule('keepbdelete','admin/Keepbrand/del');
 Route::rule('valuecreate','admin/Specvalue/create');
 Route::rule('valueall','admin/Specvalue/all');
 
-
 Route::rule('titlecreate','admin/Title/create');
 Route::rule('titlelist','admin/Title/list');
 Route::rule('titleedit','admin/Title/edit');
@@ -404,11 +395,8 @@ Route::rule('titleinfo','admin/Title/info');
 Route::rule('titledelete','admin/Title/del');
 Route::rule('titlestatus','admin/Title/status');
 
-
 Route::rule('ocrquery','admin/Ocrlicense/query');
 
-
-//Route::rule('consultlist','admin/Consult/conlist');
 Route::rule('consultlists','admin/Consult/conlist');
 Route::rule('consultinfo','admin/Consult/info');
 Route::rule('consultdel','admin/Consult/del');
@@ -430,7 +418,6 @@ Route::rule('bidscheck','admin/Consult/bids_check');
 
 Route::rule('crontablist','admin/Consult/crontablist');
 
-
 Route::rule('supplercreate','admin/Suppler/create');
 Route::rule('supplerlist','admin/Suppler/list');
 Route::rule('suppleredit','admin/Suppler/edit');
@@ -438,7 +425,6 @@ Route::rule('supplerinfo','admin/Suppler/info');
 Route::rule('supplerstatus','admin/Suppler/status');
 Route::rule('supplerdelete','admin/Suppler/del');
 
-
 Route::rule("projectcreate","admin/Project/create");
 Route::rule("projectlist","admin/Project/list");
 Route::rule("projectinfo","admin/Project/info");
@@ -471,3 +457,10 @@ Route::rule("useedit","admin/Orderuse/edit");
 Route::rule("useinfo","admin/Orderuse/info");
 Route::rule("usestatus","admin/Orderuse/status");
 Route::rule("usedelete","admin/Orderuse/dele");
+
+Route::rule("projectshare","admin/Version/info");
+Route::rule("projectsharelist","admin/Version/feedlist");
+Route::rule("projectshareplan","admin/Version/project_plan");
+Route::rule("projectsharecheck","admin/Version/feedCheck");
+Route::rule("plancheck","admin/Version/planCheck");
+