wufeng 2 роки тому
батько
коміт
1388283006
50 змінених файлів з 4998 додано та 2165 видалено
  1. 10 5
      app/abutment/controller/Consult.php
  2. 33 14
      app/abutment/controller/Good.php
  3. 118 16
      app/abutment/controller/Order.php
  4. 54 5
      app/abutment/controller/Sale.php
  5. 27 5
      app/abutment/middleware/homeMiddleware.php
  6. 1 1
      app/abutment/route/app.php
  7. 14 10
      app/admin/controller/ActionProcess.php
  8. 9 16
      app/admin/controller/Activity.php
  9. 477 268
      app/admin/controller/After.php
  10. 199 70
      app/admin/controller/Allot.php
  11. 128 0
      app/admin/controller/Base.php
  12. 225 249
      app/admin/controller/Check.php
  13. 3 2
      app/admin/controller/Consult.php
  14. 10 4
      app/admin/controller/Good.php
  15. 5 2
      app/admin/controller/GoodOfflineLog.php
  16. 279 156
      app/admin/controller/Goodup.php
  17. 1 1
      app/admin/controller/Group.php
  18. 265 102
      app/admin/controller/Orderback.php
  19. 54 47
      app/admin/controller/Process.php
  20. 13 5
      app/admin/controller/Project.php
  21. 240 51
      app/admin/controller/Proorder.php
  22. 130 70
      app/admin/controller/Purch.php
  23. 322 160
      app/admin/controller/Purchin.php
  24. 481 283
      app/admin/controller/Reorder.php
  25. 115 48
      app/admin/controller/Resign.php
  26. 58 20
      app/admin/controller/Resigninfo.php
  27. 382 266
      app/admin/controller/Sale.php
  28. 61 8
      app/admin/controller/Salezx.php
  29. 1 1
      app/admin/controller/Stat.php
  30. 1 1
      app/admin/controller/Suppler.php
  31. 2 2
      app/admin/controller/Version.php
  32. 242 0
      app/admin/model/GoodStockInfo.php
  33. 5 2
      app/admin/model/ProcessOrder.php
  34. 50 18
      app/admin/model/ProcessWait.php
  35. 41 0
      app/admin/model/SaleInfo.php
  36. 2 1
      app/admin/model/Workflow.php
  37. 17 16
      app/admin/route/app.php
  38. 1 1
      app/command/ImportOrderFromCAnalysisData.php
  39. 126 69
      app/command/ImportOrderFromCHandleData.php
  40. 134 75
      app/command/NowReportHandle.php
  41. 80 0
      app/command/UpdateProcessWaitFinallyActionData.php
  42. 171 0
      app/command/UpdateProcessWaitFinallyData.php
  43. 59 0
      app/command/UpdateYzHistoryData.php
  44. 163 80
      app/command/handleYzOrderData.php
  45. 54 0
      app/command/license.php
  46. 83 1
      app/common.php
  47. 0 1
      app/youzan/controller/Index.php
  48. 31 10
      app/youzan/logic/Goodup.php
  49. 19 1
      app/youzan/logic/Order.php
  50. 2 2
      public/index.php

+ 10 - 5
app/abutment/controller/Consult.php

@@ -958,7 +958,10 @@ class Consult extends HomeBaseController
                                             "order_type" => 'PRO',
                                             "order_code" => $projetc['projectNo'],
                                             "order_id" => $projetc['id'],
-                                            "order_status" => 2, "before_status" => 1
+                                            "order_status" => 2,
+                                            "before_status" => 1,
+                                            'holder_id'=>$projetc['createrid'],
+                                            'person_id' => Db::name('supplier')->where(['code' => $this->request->user['supplierNo'], 'is_del' => 0])->value('personid'),
                                         ]);
                                     }
                                 }
@@ -1186,9 +1189,9 @@ class Consult extends HomeBaseController
 
                                 if ($count == 0) {
                                     //先查询是否存在status==1的项目,有的话再更新,否则跳过
-                                    $project_id = Db::name("project")->where(["projectNo" => $projectinfo['projectNo'], "status" => 1])->value('id', 0);
+                                    $project_id = Db::name("project")->where(["projectNo" => $projectinfo['projectNo'], "status" => 1])->field('id,createrid')->findOrEmpty();
                                     if ($project_id) {
-                                        $proc = Db::name("project")->where(["id" => $project_id])->update(["status" => 2, "updatetime" => date("Y-m-d H:i:s")]);
+                                        $proc = Db::name("project")->where(["id" => $project_id['id']])->update(["status" => 2, "updatetime" => date("Y-m-d H:i:s")]);
                                         if ($proc == false) {
                                             Db::rollback();
                                             return json_show(1006, "项目反馈失败");
@@ -1204,9 +1207,11 @@ class Consult extends HomeBaseController
                                             ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
                                                     "order_type" => 'PRO',
                                                     "order_code" => $projectinfo['projectNo'],
-                                                    "order_id" => $project_id,
+                                                    "order_id" => $project_id['id'],
                                                     "order_status" => 2,
-                                                    "before_status" => 1
+                                                    "before_status" => 1,
+                                                    'holder_id'=>$project_id['createrid'],
+                                                    'person_id' => Db::name('supplier')->where(['code' => $this->request->user['supplierNo'], 'is_del' => 0])->value('personid'),
                                                 ]
                                             );
                                         }

+ 33 - 14
app/abutment/controller/Good.php

@@ -199,6 +199,11 @@ class Good extends HomeBaseController
         if ($cat_id == '') {
             return json_show(1004, "商品分类不能为空");
         }
+        //不允许创建贵金属商品
+        $top_cat_id = made($cat_id);//获取所有分类
+        $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
+        if($top_cat_id && $top_cat_id==6) return json_show(1004,'不允许创建贵金属商品');
+
         $brandid = isset($this->post['brandid']) && $this->post['brandid'] != "" ? intval($this->post['brandid']) : "";
         if ($brandid == '') {
             return json_show(1004, "商品品牌不能为空");
@@ -470,10 +475,9 @@ class Good extends HomeBaseController
                         return json_show(1004, "商品规格值创建失败");
                     }
                 }
-                $catinfo = Db::name("cat")->where(["id" => $cat_id])->find();
-                $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate'] / 100 : 0;
-                $top_cat_id = made($cat_id);//获取所有分类
-                $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
+//                $catinfo = Db::name("cat")->where(["id" => $cat_id])->find();
+//                $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate'] / 100 : 0;
+
                 if ($good_ladder !== "" && !empty($good_ladder)) {
                     $temp = [];
                     foreach ($good_ladder as $value) {
@@ -526,7 +530,10 @@ class Good extends HomeBaseController
                     "order_type" => 'SPCB',
                     "order_code" => $spucode,//咨询单详情编号
                     "order_id" => $in,
-                    "order_status" => 0, "before_status" => 0
+                    "order_status" => 0,
+                    "before_status" => 0,
+                    'holder_id' => $data['createrid'],
+                    'person_id' => Db::name('supplier')->where(['code' => $this->request->user['supplierNo'], 'is_del' => 0])->value('personid'),
                 ]);
                 Db::commit();
                 return json_show(0, "创建成功", ["spuCode" => $spucode]);
@@ -794,7 +801,10 @@ class Good extends HomeBaseController
                     "order_type" => 'SPCB',
                     "order_code" => $supcode,//咨询单详情编号
                     "order_id" => $data['id'],
-                    "order_status" => $temp['status'], "before_status" => $data['status']
+                    "order_status" => $temp['status'],
+                    "before_status" => $data['status'],
+                    'holder_id' => $data['createrid'],
+                    'person_id' => Db::name('supplier')->where(['code' => $this->request->user['supplierNo'], 'is_del' => 0])->value('personid'),
                 ]);
                 Db::commit();
                 return json_show(0, "更新成功");
@@ -899,7 +909,10 @@ class Good extends HomeBaseController
                     "order_type" => 'SPCB',
                     "order_code" => $supcode,//咨询单详情编号
                     "order_id" => $datas['id'],
-                    "order_status" => $data['status'], "before_status" => $datas['status']
+                    "order_status" => $data['status'],
+                    "before_status" => $datas['status'],
+                    'holder_id' => $datas['createrid'],
+                    'person_id' => Db::name('supplier')->where(['code' => $this->request->user['supplierNo'], 'is_del' => 0])->value('personid'),
                 ]);
 //                $online =  Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
 //                if($online){
@@ -1256,7 +1269,10 @@ class Good extends HomeBaseController
                     "order_type" => 'SPCB',
                     "order_code" => $supcode,//咨询单详情编号
                     "order_id" => $data['id'],
-                    "order_status" => 0, "before_status" => 0
+                    "order_status" => 0,
+                    "before_status" => 0,
+                    'holder_id' => $data['createrid'],
+                    'person_id' => Db::name('supplier')->where(['code' => $this->request->user['supplierNo'], 'is_del' => 0])->value('personid'),
                 ]);
                 if ($speclist !== "" && !empty($speclist)) {
                     foreach ($speclist as $value) {
@@ -1620,10 +1636,10 @@ class Good extends HomeBaseController
         if ($data == false) {
             return json_show(1004, "未找到商品数据");
         }
-        $token = isset($this->post['token']) && $this->post['token'] != '' ? trim($this->post['token']) : "";
-        if ($token == '') {
-            return json_show(105, "参数token不能为空");
-        }
+//        $token = isset($this->post['token']) && $this->post['token'] != '' ? trim($this->post['token']) : "";
+//        if ($token == '') {
+//            return json_show(105, "参数token不能为空");
+//        }
 //        $user =GetUserInfo($token);
 //        if(empty($user)||$user['code']!=0){
 //            return json_show(102,"用户数据不存在");
@@ -1694,7 +1710,10 @@ class Good extends HomeBaseController
                     "order_type" => 'SPCB',
                     "order_code" => $newCode,//咨询单详情编号
                     "order_id" => Db::name("good_basic")->getLastInsID(),
-                    "order_status" => 7, "before_status" => 0
+                    "order_status" => 7,
+                    "before_status" => 0,
+                    'holder_id' => $data['createrid'],
+                    'person_id' => Db::name('supplier')->where(['code' => $this->request->user['supplierNo'], 'is_del' => 0])->value('personid'),
                 ]);
                 if (!empty($ladd)) {
                     $na = Db::name("good_nake")->insertAll($ladd);
@@ -1724,7 +1743,7 @@ class Good extends HomeBaseController
 
     }
 
-    //商品详情
+    //上线商品详情
     public function info()
     {
 

+ 118 - 16
app/abutment/controller/Order.php

@@ -2,9 +2,11 @@
 
 namespace app\abutment\controller;
 
+use app\abutment\model\SupplierRelationUser as SupplierRelationUserModel;
+use app\abutment\model\SupplierUser as SupplierUserModel;
 use app\admin\model\ActionLog;
 use app\admin\model\GoodLog;
-use app\admin\model\ProcessOrder;
+use app\admin\model\GoodStockInfo;use app\admin\model\ProcessOrder;
 use think\Exception;
 use think\facade\Db;
 use think\facade\Validate;
@@ -385,10 +387,13 @@ class Order extends HomeBaseController
         //原始数据
         $info = Db::name("purchease_order")
             ->whereIn('cgdNo', $cgdNo)
-            ->column('id,cgdNo,status', 'cgdNo');
+            ->where('status', 0)
+            ->column('id,cgdNo,status,supplierNo,spuCode,order_type', 'cgdNo');
+        if (empty($info)) return json_show(1005, '没有可供确认的订单');
 
         $upd = Db::name("purchease_order")
             ->whereIn('cgdNo', $cgdNo)
+            ->where('status', 0)
             ->save([
                 'status' => $status,
                 'remark' => $remark,
@@ -399,8 +404,49 @@ class Order extends HomeBaseController
             $uid = $this->request->user['uid']; //isset($user['data']['id'])?$user['data']['id']:0;
             $uname = $this->request->user['nickname'];//isset($user['data']['nickname'])?$user['data']['nickname']:'';
 
+            $supplier_cgderid = Db::name('supplier')
+                ->where('is_del',0)
+                ->whereIn('code',array_column($info,'supplierNo'))
+                ->column('personid','code');
+
             foreach ($cgdNo as $vlue) {
-                $process = ["order_code" => $vlue, "order_id" => isset($info[$vlue]['id']) ? $info[$vlue]['id'] : 0, "order_status" => $status, "order_type" => 'CGD', "before_status" => isset($info[$vlue]['status']) ? $info[$vlue]['status'] : 0];
+                if($status==2 || $status==3){
+//                    $orderinfo = Db::name('sale')
+//                        ->alias('a')
+//                        ->field('a.id,a.orderCode,a.is_stock,a.order_type,a.cgderid')
+//                        ->leftJoin('order_num b','b.orderCode=a.orderCode')
+//                        ->where([
+//                            'a.is_del'=>0,
+//                            'b.cgdNo'=>$vlue,
+//                        ])->findOrEmpty();
+
+                    $is_stock = Db::name('good_basic')
+                        ->where(['is_del'=>0,'spuCode'=>$info[$vlue]['spuCode']])
+                        ->value('is_stock');
+
+                    if($is_stock==1){
+                        //库存品,推给31库管人员、41库管-张凯旋
+                        $uids = Db::name('user_role')
+                            ->where([
+                                ['is_del', '=', 0],
+                                ['roleid', 'in', [31, 41]],
+                                ['status', '=', 1]
+                            ])->column('uid');
+                        if(!in_array($uid,$uids)) throw new Exception('库存品订单只能由库管人员操作');
+                        $process = ["order_code" => $vlue, "order_id" => isset($info[$vlue]['id']) ? $info[$vlue]['id'] : 0, "order_status" => $status, "order_type" => 'CGD', "before_status" => isset($info[$vlue]['status']) ? $info[$vlue]['status'] : 0,'holder_id'=> isset($supplier_cgderid[$info[$vlue]['supplierNo']]) ? $supplier_cgderid[$info[$vlue]['supplierNo']] : 0,'handle_user_list'=>implode(',', $uids)];
+                    }elseif ($is_stock==0 || $info[$vlue]['order_type']==3) {
+                        //非库存品和采返商品,推给供应商负责人(还得是没开通账号的供应商)
+
+                        $res = SupplierRelationUserModel::field('id')
+                            ->where(['is_del' => SupplierUserModel::$is_del_normal, 'supplierNo' => $info[$vlue]['supplierNo'], 'status' => SupplierUserModel::$status_normal])
+                            ->findOrEmpty()
+                            ->isEmpty();
+                        if(!$res) throw new Exception('供应商已开通账号,只能由供应商端操作');
+
+                        if($uid != $supplier_cgderid[$info[$vlue]['supplierNo']])throw new Exception('非库存品和采返商品只能由供应商负责人操作');
+                        $process = ["order_code" => $vlue, "order_id" => isset($info[$vlue]['id']) ? $info[$vlue]['id'] : 0, "order_status" => $status, "order_type" => 'CGD', "before_status" => isset($info[$vlue]['status']) ? $info[$vlue]['status'] : 0,'holder_id'=> isset($supplier_cgderid[$info[$vlue]['supplierNo']]) ? $supplier_cgderid[$info[$vlue]['supplierNo']] : 0,'handle_user_list'=>isset($supplier_cgderid[$info[$vlue]['supplierNo']]) ? $supplier_cgderid[$info[$vlue]['supplierNo']] : 0];
+                    }
+                }else $process = ["order_code" => $vlue, "order_id" => isset($info[$vlue]['id']) ? $info[$vlue]['id'] : 0, "order_status" => $status, "order_type" => 'CGD', "before_status" => isset($info[$vlue]['status']) ? $info[$vlue]['status'] : 0,'holder_id'=> isset($supplier_cgderid[$info[$vlue]['supplierNo']]) ? $supplier_cgderid[$info[$vlue]['supplierNo']] : 0];
                 ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $uname], $process);
                 $order = ["order_code" => $vlue, "status" => '', "action_remark" => $remark, "action_type" => "status"];
                 ActionLog::logAdd(['id' => $uid, 'nickname' => $uname], $order, 'CGD', $status, $this->post);
@@ -427,7 +473,7 @@ class Order extends HomeBaseController
             ->whereIn('cgdNo', $param['cgdNo'])
             ->where(['is_del' => 0, 'supplierNo' => $this->request->user['supplierNo']])
             ->where('status', '=', 1)
-            ->column('id,wsm_code,good_num,spuCode,order_type,send_status,status', 'cgdNo');
+            ->column('id,wsm_code,good_num,good_price,spuCode,order_type,send_status,status,supplierNo', 'cgdNo');
 
         if (empty($cgdinfo)) return json_show(1005, "未找到采购单数据或采购单未发货");
 
@@ -446,6 +492,11 @@ class Order extends HomeBaseController
 
             $date = date('Y-m-d H:i:s');
 
+            $supplier_cgderid = Db::name('supplier')
+                ->where('is_del',0)
+                ->whereIn('code',array_column($cgdinfo,'supplierNo'))
+                ->column('personid,person','code');
+
             $i = 0;
             $status = 4;//4入库完成
             foreach ($param['cgdNo'] as $cgdNo) {
@@ -453,7 +504,7 @@ class Order extends HomeBaseController
                 if (empty($cgdinfo[$cgdNo])) throw new Exception('未找到采购单数据或采购单未发货');
 
                 $wsm_in_code = makeNo("CF");
-
+				$bn_code = makeNo("BN");
                 $send_num = $cgdinfo[$cgdNo]['good_num'];
                 //改变编码规则,将原编码后两位换成序列号
                 //str_pad字符串填充
@@ -464,6 +515,7 @@ class Order extends HomeBaseController
                 $win = Db::name("purchease_in")->insertGetId([
                     "wsm_in_code" => $wsm_in_code,
                     "cgdNo" => $cgdNo,
+                    "bnCode"=>$bn_code,
                     "wsm_code" => $cgdinfo[$cgdNo]['wsm_code'],
                     "wsm_reaper" => isset($recep[$cgdinfo[$cgdNo]['wsm_code']]) ? $recep[$cgdinfo[$cgdNo]['wsm_code']] : '',
                     "send_num" => $cgdinfo[$cgdNo]['good_num'],
@@ -484,7 +536,7 @@ class Order extends HomeBaseController
                 if ($win) {
                     $sto = ["order_code" => $wsm_in_code, "status" => $status, "action_remark" => '', "action_type" => "edit"];
                     ActionLog::logAdd(['id' => $uid, 'nickname' => $nickname], $sto, "RKD", $status, $this->request->filter('trim')->post());
-                    $process = ["order_code" => $wsm_in_code, "order_id" => $win, "order_status" => $status, "order_type" => 'RKD', "before_status" => $status];
+                    $process = ["order_code" => $wsm_in_code, "order_id" => $win, "order_status" => $status, "order_type" => 'RKD', "before_status" => $status,'holder_id' => $this->request->user['uid']];
                     ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $nickname], $process);
                     $order = ["order_code" => $cgdNo, "status" => $cgdinfo[$cgdNo]['status'], "action_remark" => '', "action_type" => "edit"];
 
@@ -528,12 +580,18 @@ class Order extends HomeBaseController
                     $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);
+                    $stockid=$good['id']?? Db::name("good_stock")->getLastInsID();
                     //商品变动日志表,good_log_code字段存储采购单单号
-                    $good_data[] = ['good_log_code' => $wsm_in_code, "stock_id" => isset($good['id']) ? $good['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1, 'stock' => $send_num, "stock_name" => "usable_stock"];
-                    $good_data[] = ['good_log_code' => $wsm_in_code, "stock_id" => isset($good['id']) ? $good['id'] : Db::name("good_stock")->getLastInsID(), "type" => 2, 'stock' => $send_num, "stock_name" => "wait_in_stock"];
+                    $good_data[] = ['good_log_code' => $wsm_in_code, "stock_id" =>$stockid, "type" => 1, 'stock' => $send_num, "stock_name" => "usable_stock"];
+                    $good_data[] = ['good_log_code' => $wsm_in_code, "stock_id" =>$stockid, "type" => 2, 'stock' => $send_num, "stock_name" => "wait_in_stock"];
                     if ($upd) {
                         GoodLog::LogAdd(['id' => $uid, 'nickname' => $nickname], $good_data, 'RKD');
                         if ($cgdinfo[$cgdNo]['order_type'] == 1) {
+                        	$bnin=GoodStockInfo::AddBn($stockid,$bn_code,$send_num,$cgdinfo[$cgdNo]['good_price']);
+	                        if($bnin==false){
+	                            Db::rollback();
+	                            return error_show(1004,"库存bn数据新增失败");
+	                        }
                             $bk = Db::name("order_bk")->where(['cgdNo' => $cgdNo])->find();
                             if ($bk == false) {
                                 $bk = [
@@ -567,6 +625,14 @@ class Order extends HomeBaseController
                                     $up = Db::name("order_out")->where(["outCode" => $send, "status" => 0])->update(["status" => 1, 'wsm_code' => $cgdinfo[$cgdNo]['wsm_code'], "updatetime" => date('Y-m-d H:i:s')]);
                                     if ($up == false) throw new Exception('出库单出库失败');
                                     else {
+
+                                        //查询是否有非库存品订单
+                                        $is_stock = Db::name('sale')
+                                            ->where([
+                                                ['is_del','=',0],
+                                                ['orderCode','in',array_column($out,'orderCode')]
+                                            ])->column('is_stock','orderCode');
+
                                         foreach ($out as $k => $v_outCode) {
                                             //修改状态,添加待办
                                             ActionLog::logAdd(['id' => $uid, 'nickname' => $nickname], [
@@ -576,13 +642,49 @@ class Order extends HomeBaseController
                                                 "action_type" => "status"//新建create,编辑edit,更改状态status
                                             ], "CKD", 1, $param);
 
-                                            ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $nickname], [
-                                                "order_type" => 'CKD',
-                                                "order_code" => $v_outCode['outCode'],//出库单号
-                                                "order_id" => $v_outCode['id'],
-                                                "order_status" => 1,
-                                                "before_status" => 0
-                                            ]);
+
+                                            //库存品,推给库管和库管-张凯旋
+                                            if($is_stock[$v_outCode['orderCode']] == 1){
+                                                $roleid = config('app.wsm_cgder_role');
+                                                $uids = Db::name('user_role')
+                                                    ->where('is_del', 0)
+                                                    ->whereIn('roleid', $roleid)
+                                                    ->column('uid');
+                                                ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $nickname], [
+                                                    "order_type" => 'CKD',
+                                                    "order_code" => $v_outCode['outCode'],//出库单号
+                                                    "order_id" => $v_outCode['id'],
+                                                    "order_status" => 1,
+                                                    "before_status" => 0,
+//                                                    'wait_id' => $wait['personid'],
+//                                                    'wait_name' => $wait['person'],
+//                                                    'holder_id' => $wait['personid'],
+                                                    'handle_user_list' => implode(',', $uids)
+                                                ]);
+                                            }elseif ($is_stock[$v_outCode['orderCode']] == 0 || $cgdinfo[$cgdNo]['order_type']==3){
+                                                //非库存品和采返商品,推给供应商负责人
+                                                $wait = $supplier_cgderid[$cgdinfo[$cgdNo]['supplierNo']];
+                                                ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $nickname], [
+                                                    "order_type" => 'CKD',
+                                                    "order_code" => $v_outCode['outCode'],//出库单号
+                                                    "order_id" => $v_outCode['id'],
+                                                    "order_status" => 1,
+                                                    "before_status" => 0,
+                                                    'wait_id' => $wait['personid'],
+                                                    'wait_name' => $wait['person'],
+                                                    'holder_id' => $wait['personid'],
+                                                ]);
+                                            }else{
+                                                ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $nickname], [
+                                                    "order_type" => 'CKD',
+                                                    "order_code" => $v_outCode['outCode'],//出库单号
+                                                    "order_id" => $v_outCode['id'],
+                                                    "order_status" => 1,
+                                                    "before_status" => 0,
+                                                    'holder_id' => $v_outCode['apply_id']
+                                                ]);
+                                            }
+
                                         }
                                     }
                                     $good1 = Db::name("good_stock")->where(["wsm_code" => $cgdinfo[$cgdNo]['wsm_code'], "spuCode" => $cgdinfo[$cgdNo]['spuCode'], "is_del" => 0])->find();
@@ -607,7 +709,7 @@ class Order extends HomeBaseController
                             }
                         }
                         ActionLog::logAdd(['id' => $uid, 'nickname' => $nickname], $order, "CGD", $cgdinfo[$cgdNo]['status'], $cgdinfo[$cgdNo]);
-                        $process = ["order_code" => $cgdNo, "order_id" => $cgdinfo[$cgdNo]['id'], "order_status" => $cgdinfo[$cgdNo]['status'], "order_type" => 'CGD', "before_status" => $order['status']];
+                        $process = ["order_code" => $cgdNo, "order_id" => $cgdinfo[$cgdNo]['id'], "order_status" => $cgdinfo[$cgdNo]['status'], "order_type" => 'CGD', "before_status" => $order['status'], 'holder_id' => isset($supplier_cgderid[$cgdinfo[$cgdNo]['supplierNo']]['personid']) ? $supplier_cgderid[$cgdinfo[$cgdNo]['supplierNo']]['personid'] : 0];
                         ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $nickname], $process);
 //                        Db::commit();
 //                        return json_show(0, '商品入库成功', ["wsm_in_code" => $wsm_in_code]);

+ 54 - 5
app/abutment/controller/Sale.php

@@ -4,7 +4,7 @@ namespace app\abutment\controller;
 
 use app\admin\model\ActionLog;
 use app\admin\model\GoodLog;
-use app\admin\model\ProcessOrder;
+use app\admin\model\GoodStockInfo;use app\admin\model\ProcessOrder;
 use Exception;
 use think\facade\Cache;
 use think\facade\Db;
@@ -271,6 +271,7 @@ class Sale extends HomeBaseController
                     "before_status" => $old_outinfo_status,
                     'wait_id' => $outinfo['apply_id'],
                     'wait_name' => $outinfo['apply_name'],
+                    'holder_id' => $outinfo['apply_id'],
                 ]);
                 $orderstatus = $einfo['status'];
                 $einfo['send_num'] += $outinfo['send_num'];
@@ -298,7 +299,10 @@ class Sale extends HomeBaseController
                     "order_type" => 'XSQRD',
                     "order_code" => $einfo['orderCode'],//出库单号
                     "order_id" => $einfo['id'],
-                    "order_status" => $einfo['status'], "before_status" => $orderstatus
+                    "order_status" => $einfo['status'],
+                    "before_status" => $orderstatus,
+                    'holder_id' => $einfo['apply_id'],
+                    'person_id' => Db::name('supplier')->where(['code' => $this->request->user['supplierNo'], 'is_del' => 0])->value('personid'),
                 ]);
 
                 $stokc = Db::name("good_stock")->where(['spuCode' => $einfo['good_code'], "wsm_code" => $outinfo['wsm_code'], "is_del" => 0])->find();
@@ -320,6 +324,27 @@ class Sale extends HomeBaseController
                     Db::rollback();
                     return json_show(1002, "库存更新失败");
                 }
+
+                 if($einfo["order_type"]!=1){
+                	$outsend =Db::name("order_send")->where(["outCode"=> $outCode])->findOrEmpty();
+                	if(empty($outsend)){
+                			Db::rollback();
+                             return error_show(1002, "未找到关联采购单");
+                		}
+                	$cgdinfo= Db::name("purchease_order")->where(["cgdNo"=>$outsend['cgdNo'],"is_del"=>0])
+                	->findOrEmpty();
+                	$bn_code =makeNo("BN");
+                	$bnin=GoodStockInfo::AddBn($stokc["id"],$bn_code,$outinfo['send_num'],$cgdinfo['good_price']??0);
+	                 if($bnin==false){
+	                      Db::rollback();
+	                      return error_show(1004,"库存bn数据新增失败");
+	                 }
+	                 $bnup =GoodStockInfo::OrderBn($outinfo['orderCode'],$stokc["id"],$outinfo['send_num'],0);
+	                 if($bnup==false){
+	                      Db::rollback();
+	                      return error_show(1004,"库存bn库存数更新失败");
+	                 }
+                }
                 $good_data[] = ['good_log_code' => $outCode, "stock_id" => $stokc['id'], "type" => 2, 'stock' => $outinfo['send_num'], "stock_name" => "wait_out_stock"];
 
                 GoodLog::LogAdd(['id' => $uid, 'nickname' => $uname], $good_data, "CKD");
@@ -395,7 +420,7 @@ class Sale extends HomeBaseController
                 $sale_infos = Db::name("sale")
                     ->where('orderCode', $order_out_infos[$value['outCode']]['orderCode'])
                     ->where('is_del', 0)
-                    ->column('id,send_num,wsend_num,status,good_code,order_source', 'orderCode');
+                    ->column('id,send_num,wsend_num,status,good_code,order_type,order_source,apply_id', 'orderCode');
 
                 if (!isset($sale_infos[$order_out_infos[$value['outCode']]['orderCode']])) throw new Exception($value['outCode'] . '该发货单对应的销售单未找到');
 
@@ -439,6 +464,8 @@ class Sale extends HomeBaseController
                         "before_status" => $order_out_infos[$value['outCode']]['status'],
                         'wait_id' => $order_out_infos[$value['outCode']]['apply_id'],
                         'wait_name' => $order_out_infos[$value['outCode']]['apply_name'],
+                        'holder_id' => $order_out_infos[$value['outCode']]['apply_id'],
+                        'person_id' => Db::name('supplier')->where(['code' => $this->request->user['supplierNo'], 'is_del' => 0])->value('personid'),
                     ]);
 
 
@@ -467,7 +494,10 @@ class Sale extends HomeBaseController
                         "order_type" => 'XSQRD',
                         "order_code" => $order_out_infos[$value['outCode']]['orderCode'],//出库单号
                         "order_id" => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['id'],
-                        "order_status" => $einfo['status'], "before_status" => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['status']
+                        "order_status" => $einfo['status'],
+                        "before_status" => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['status'],
+                        'holder_id' => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['apply_id'],
+                        'person_id' => Db::name('supplier')->where(['code' => $this->request->user['supplierNo'], 'is_del' => 0])->value('personid'),
                     ]);
 
                     //【库存】
@@ -490,7 +520,26 @@ class Sale extends HomeBaseController
                             ->where('id', $stock['id'])
                             ->update($stock);
                         if ($stock_rs == false) throw new Exception($value['outCode'] . '库存更新失败');
-
+						 if($sale_infos[$order_out_infos[$value['outCode']]['orderCode']]["order_type"]!=1){
+		                    $outsend =Db::name("order_send")->where(["outCode"=> $value['outCode']])->findOrEmpty();
+		                    if(empty($outsend)){
+		                            Db::rollback();
+		                             return error_show(1002, "未找到关联采购单");
+		                        }
+		                    $cgdinfo= Db::name("purchease_order")->where(["cgdNo"=>$outsend['cgdNo'],"is_del"=>0])
+		                    ->findOrEmpty();
+		                    $bn_code =makeNo("BN");
+		                    $bnin=GoodStockInfo::AddBn($stock["id"],$bn_code,$order_out_infos[$value['outCode']]['send_num'],$cgdinfo['good_price']??0);
+			                 if($bnin==false){
+			                      Db::rollback();
+			                      return error_show(1004,"库存bn数据新增失败");
+			                 }
+			                 $bnup =GoodStockInfo::OrderBn($order_out_infos[$value['outCode']]['orderCode'],$stock["id"],$order_out_infos[$value['outCode']]['send_num'],0);
+			                 if($bnup==false){
+			                      Db::rollback();
+			                      return error_show(1004,"库存bn库存数更新失败");
+			                 }
+						 }
                         $good_data[] = [
                             'good_log_code' => $value['outCode'],
                             'stock_id' => $stock['id'],

+ 27 - 5
app/abutment/middleware/homeMiddleware.php

@@ -30,11 +30,33 @@ class homeMiddleware
         //判断白名单
         if (!in_array(strtolower(request()->pathinfo()), $this->white_list)) {
 
-            //获取用户信息
-            $user = $this->getUserInfo($param);
-            if (is_array($user)) $request->user = $user;
-            else return $user;//响应信息,说明报错,直接返回给请求方
-
+            //请求头部是否有相关信息
+            $header = $request->header();
+            $val_header = Validate::rule([
+                'uid' => 'require|number|gt:0',
+                'nickname' => 'require|max:255',
+                'mobile' => 'require|number|length:11|mobile',
+                'email' => 'email|max:255',
+                'supplierno' => 'require|alphaNum|length:18',
+                'suppliername' => 'require|max:255',//header自动把大写字母转换成小写的了
+            ]);
+
+            if ($val_header->check($header)) {
+                $request->user = [
+                    'uid' => $header['uid'],
+                    'nickname' => $header['nickname'],
+                    'mobile' => $header['mobile'],
+                    'email' => '',
+                    'supplierNo' => $header['supplierno'],
+                    'supplierName' => $header['suppliername']
+                ];
+
+            } else {
+                //获取用户信息
+                $user = $this->getUserInfo($param);
+                if (is_array($user)) $request->user = $user;
+                else return $user;//响应信息,说明报错,直接返回给请求方
+            }
         }
 
         //3.记录日志

+ 1 - 1
app/abutment/route/app.php

@@ -38,7 +38,7 @@ route::rule('catList', 'abutment/Good/wlist');//分类列表
 route::rule('catListTitle', 'abutment/Good/title');//分类列表-全部
 route::rule('checkIsUpdate', 'abutment/Good/checkIsUpdate');//判断是否允许修改成本信息和基础信息
 route::rule('goodCopy', 'abutment/Good/copy');//上线商品复制
-route::rule('goodInfo', 'abutment/Good/info');//商品详情
+route::rule('goodInfo', 'abutment/Good/info');//上线商品详情
 
 //销售订单(采销的采购单)
 route::rule('getOrderList', 'abutment/Order/getList');//列表

+ 14 - 10
app/admin/controller/ActionProcess.php

@@ -78,7 +78,6 @@ class ActionProcess extends Base
             'next_action_ids|下一节点' => 'array|requireIf:action_type,' . APModel::$action_type_start . '|requireIf:action_type,' . APModel::$action_type_process,
         ]);
 
-
         $val->extend('checkOrderProcess', function ($val, $rule, $data) {
             return APModel::where([
                 'process_id' => $data['process_id'],
@@ -89,13 +88,20 @@ class ActionProcess extends Base
 
         if (!$val->check($param)) return error_show(1005, $val->getError());
 
-        $user = GetUserInfo($param['token']);
+        //获取流程
+        $process = PModel::field('id,process_name,process_type')
+            ->where(['id' => $param['process_id'], 'is_del' => PModel::$is_del_normal])
+            ->findOrEmpty()
+            ->toArray();
+        if (empty($process)) return error_show(1005, '您所选的流程不存在');
 
-        $uid = isset($user['data']['id']) ? $user['data']['id'] : 0;
-        $uname = isset($user['data']['nickname']) ? $user['data']['nickname'] : '';
+        $uid = $this->uid;
+        $uname = $this->uname;
         $date = date('Y-m-d H:i:s');
 
         return APModel::create(array_merge($param, [
+            'order_type' => $process['process_type'],
+            'order_name' => $process['process_name'],
             'status' => APModel::$status_disable,
             'is_del' => APModel::$is_del_normal,
             'createrid' => $uid,
@@ -156,7 +162,7 @@ class ActionProcess extends Base
             ->field('id,process_id')
             ->findOrEmpty();
 
-        if($info->isEmpty()) return error_show(1005,'该节点记录不存在');
+        if ($info->isEmpty()) return error_show(1005, '该节点记录不存在');
 
         if (isset($param['status']) && $param['status'] == APModel::$status_disable) {
             //禁用节点时,要校验其所属流程是否被禁用
@@ -169,10 +175,8 @@ class ActionProcess extends Base
 
         }
 
-        $user = GetUserInfo($param['token']);
-
-        $uid = isset($user['data']['id']) ? $user['data']['id'] : 0;
-        $uname = isset($user['data']['nickname']) ? $user['data']['nickname'] : '';
+        $uid = $this->uid;
+        $uname = $this->uname;
         $date = date('Y-m-d H:i:s');
 
         if (isset($param['next_action_ids']) && is_array($param['next_action_ids'])) $param['next_action_ids'] = implode(',', $param['next_action_ids']);
@@ -186,7 +190,7 @@ class ActionProcess extends Base
     {
 
         $data = PModel::where(['is_del' => PModel::$is_del_normal, 'status' => PModel::$status_normal])
-            ->order(['weight'=>'desc','id'=>'desc'])
+            ->order(['weight' => 'desc', 'id' => 'desc'])
             ->column('id,process_name,process_type', 'id');
 
         $action = APModel::where(['is_del' => APModel::$is_del_normal, 'status' => APModel::$status_normal, 'operation_type' => APModel::$operation_type_approval])

+ 9 - 16
app/admin/controller/Activity.php

@@ -285,8 +285,10 @@ class Activity extends Base
                     $skuCode =array_column($good_list,"skuCode");
                     $ist =Db::name("good_activity")->alias("a")
                     ->leftJoin("activity_info b","a.activity_code = b.activity_code and b.is_del=0")
-                    ->where(["b.skuCode"=>$skuCode,"a.is_del"=>0])->where([["a.status","<>",8],["start|end","between",
-                    [$activity_start,$activity_end]]])->select()->toArray();
+                    ->where(["b.skuCode"=>$skuCode,"a.is_del"=>0])->where([["a.status","<>",8]])->where(function
+                    ($query)use($activity_end,$activity_start){
+                    	return $query->whereOr([[["start","<=",$activity_start],["end",">=",$activity_end]],["start|end","between",[$activity_start, $activity_end]]]);
+	                   })->select()->toArray();
                     if(!empty($ist)){
                        Db::rollback();
                        $limit=[];
@@ -337,7 +339,7 @@ class Activity extends Base
 
                 $stn = ["order_code" => $activity_code, "status" => 0, "action_remark" => '', "action_type" => "create"];
                 ActionLog::logAdd($this->post['token'], $stn, "HD", $data['status'], $data);
-                $process = ["order_code" => $activity_code, "order_id" => $inset, "order_status" => $data['status'], "order_type" => 'HD', "before_status" => 0];
+                $process = ["order_code" => $activity_code, "order_id" => $inset, "order_status" => $data['status'], "order_type" => 'HD', "before_status" => 0, 'holder_id' => $data['createrid']];
                 ProcessOrder::AddProcess($this->post['token'], $process);
 
                 Db::commit();
@@ -389,7 +391,7 @@ class Activity extends Base
 
                 $stn = ["order_code" => $activity_code, "status" => $old_activity_status, "action_remark" => '', "action_type" => "status"];
                 ActionLog::logAdd($this->post['token'], $stn, "HD", $activity['status'], $activity);
-                $process = ["order_code" => $activity_code, "order_id" => $activity['id'], "order_status" => $activity['status'], "order_type" => 'HD', "before_status" => $old_activity_status];
+                $process = ["order_code" => $activity_code, "order_id" => $activity['id'], "order_status" => $activity['status'], "order_type" => 'HD', "before_status" => $old_activity_status, 'holder_id' => $activity['createrid']];
                 ProcessOrder::AddProcess($this->post['token'], $process);
 
                 Db::commit();
@@ -440,16 +442,7 @@ class Activity extends Base
 
                 $stn = ["order_code" => $activity_code, "status" => $old_activity_status, "action_remark" => '', "action_type" => "status"];
                 ActionLog::logAdd($this->post['token'], $stn, "HD", $activity['status'], $activity);
-
-                //查找财务主管
-                $user = Db::name('role')
-                    ->field('r.id,u.uid,u.nickname')
-                    ->alias('r')
-                    ->leftJoin('user_role ur', 'ur.roleid=r.id AND ur.is_del=0')
-                    ->leftJoin('depart_user u', 'u.uid=ur.uid AND u.is_del=0 AND u.status=1')
-                    ->where('r.id', 20)//财务负责人
-                    ->findOrEmpty();
-                $process = ["order_code" => $activity_code, "order_id" => $activity['id'], "order_status" => $activity['status'], "order_type" => 'HD', "before_status" => $old_activity_status, 'wait_id' => isset($user['uid']) ? $user['uid'] : 0, 'wait_name' => isset($user['nickname']) ? $user['nickname'] : ''];
+                $process = ["order_code" => $activity_code, "order_id" => $activity['id'], "order_status" => $activity['status'], "order_type" => 'HD', "before_status" => $old_activity_status, 'holder_id' => $activity['createrid']];
                 ProcessOrder::AddProcess($this->post['token'], $process);
 
                 Db::commit();
@@ -501,7 +494,7 @@ class Activity extends Base
 
                 $stn = ["order_code" => $activity_code, "status" => $old_activity_status, "action_remark" => '', "action_type" => "status"];
                 ActionLog::logAdd($this->post['token'], $stn, "HD", $activity['status'], $activity);
-                $process = ["order_code" => $activity_code, "order_id" => $activity['id'], "order_status" => $activity['status'], "order_type" => 'HD', "before_status" => $old_activity_status];
+                $process = ["order_code" => $activity_code, "order_id" => $activity['id'], "order_status" => $activity['status'], "order_type" => 'HD', "before_status" => $old_activity_status, 'holder_id' => $activity['createrid']];
                 ProcessOrder::AddProcess($this->post['token'], $process);
 
                 Db::commit();
@@ -601,7 +594,7 @@ class Activity extends Base
 
             $stn = ["order_code" => $activity_code, "status" => $old_status, "action_remark" => '', "action_type" => "status"];
             ActionLog::logAdd($this->post['token'], $stn, "HD", $activity['status'], $activity);
-            $process = ["order_code" => $activity_code, "order_id" => $activity['id'], "order_status" => $activity['status'], "order_type" => 'HD', "before_status" => $old_status];
+            $process = ["order_code" => $activity_code, "order_id" => $activity['id'], "order_status" => $activity['status'], "order_type" => 'HD', "before_status" => $old_status, 'holder_id' => $activity['createrid']];
             ProcessOrder::AddProcess($this->post['token'], $process);
 
             return  app_show(0,"修改成功");

Різницю між файлами не показано, бо вона завелика
+ 477 - 268
app/admin/controller/After.php


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

@@ -5,7 +5,8 @@ namespace app\admin\controller;
 use app\admin\model\ActionLog;
 use app\admin\model\DataGroup as DataGroupModel;
 use app\admin\model\GoodLog;
-use app\admin\model\ProcessOrder;
+use app\admin\model\GoodStockInfo;use app\admin\model\ProcessOrder;
+use app\admin\model\ProcessWait;
 use app\BaseController;
 use think\App;
 use think\facade\Db;
@@ -141,8 +142,7 @@ class Allot extends Base
         return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
     }
     public function create(){
-
-        $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
+    	$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==""){
         return error_show(1002,"出库仓库编号不能为空");
@@ -157,27 +157,6 @@ class Allot extends Base
             ->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,"商品属性不能为空");
-//    }
     $allot_code=makeNo("XK");
     $apply_id =GetUserInfo($token);
         if(empty($apply_id)||$apply_id['code']!=0){
@@ -220,28 +199,34 @@ class Allot extends Base
             $dm=[];
             if($pd>0) {
                 foreach ($dain as $value) {
-                    $st = Db::name("good_stock")->alias("a")->leftJoin("good b" ,"a.spuCode=b.spuCode")
-                        ->where(['wsm_code' => $wsm_out, 'a.spuCode' => $value['spuCode'], 'a.is_del' => 0])
-                        ->field("a.spuCode,wsm_code,usable_stock,wait_out_stock,wait_in_stock,b.good_name")->find();
+                    $st = Db::name("good_stock_info")->alias("a")
+                     ->leftJoin("good_stock d" ,"d.id=a.stockid")
+                    ->leftJoin("good b" ,"d.spuCode=b.spuCode")
+                        ->where(['wsm_code' => $wsm_out, 'a.bnCode' => $value['bnCode'], 'd.is_del' => 0])
+                        ->field("d.spuCode,wsm_code,d.usable_stock,d.wait_out_stock,d.wait_in_stock,b.good_name,a.total_num,a.balance_num,a.origin_price")
+                        ->find();
 
                     if (empty($st)) {
                         Db::rollback();
                         return error_show(1003, "商品不能为空");
                         }
-                    if($value['allot_num']>$st['usable_stock']){
+                    if($value['allot_num']>$st['balance_num']){
+                    	 Db::rollback();
                         return error_show(2000,"库存数量不足");
                     }
                         $temp = [];
                         $temp['good_name'] = $st['good_name'];
                         $temp['allot_code'] =$allot_code;
-                        $temp['good_type_code'] = $value['spuCode'];
+                        $temp['bnCode'] =$value['bnCode'];
+                        $temp['good_type_code'] = $st['spuCode'];
+                        $temp['origin_price'] = $st['origin_price'];
                         $temp['allot_num'] = $value['allot_num'];
-                        $temp['usable_num'] =$st['usable_stock'];
+                        $temp['usable_num'] =$st['balance_num'];
                         $temp['error_num'] = 0;
                         $temp['error_remark'] = "";
                         $temp['stock_num'] = 0;
                         $temp['error_code']="";
-                        $temp['good_num']=$st['usable_stock'];
+                        $temp['good_num']=$st['balance_num'];
                         $temp['addtime'] = date("Y-m-d H:i:s");
                         $temp['updatetime'] = date("Y-m-d H:i:s");
                         $dm[]=$temp;
@@ -250,7 +235,7 @@ class Allot extends Base
                 if ($io) {
                     $order = ["order_code"=>$allot_code,"status"=>$status,"action_remark"=>'',"action_type"=>"create"];
                     ActionLog::logAdd($this->post['token'],$order,"DBD",$status,$this->post);
-                    $process=["order_code"=>$allot_code,"order_id"=>$pd,"order_status"=>$status,"order_type"=>'DBD',"before_status"=>0];
+                    $process = ["order_code" => $allot_code, "order_id" => $pd, "order_status" => $status, "order_type" => 'DBD', "before_status" => 0, 'holder_id' => $data['apply_id']];
                     ProcessOrder::AddProcess($token,$process);
                     Db::commit();
                     return error_show(0, "调拨创建成功");
@@ -304,10 +289,13 @@ class Allot extends Base
 
             $data=[];
         foreach ($vmp as $k=>$value){
-            $s =Db::name('good_stock')->where(['spuCode'=>$value['good_type_code'],'wsm_code'=>$str['wsm_out']])
-                ->find();
+           $s = Db::name("good_stock_info")->alias("a")
+                     ->leftJoin("good_stock d" ,"d.id=a.stockid")
+                        ->where(['wsm_code' => $str['wsm_out'], 'a.bnCode' => $value['bnCode'], 'd.is_del' => 0])
+                        ->field("a.balance_num,a.origin_price")
+                        ->find();
             if($str['status']<=1) {
-                $value['usable_num'] = $s['usable_stock'];
+                $value['usable_num'] = $s['balance_num']??0;
             }
             $value['error_msg']="";
             $value['good_code']=$value['spuCode']=$value['good_type_code'];
@@ -374,9 +362,12 @@ class Allot extends Base
             $da = Db::name('allot_stock')->where(["id"=>$id,"is_del"=>0])->save($data);
             if($da!=false) {
                 foreach ($dain as $value) {
-                    $st = Db::name("good_stock")->alias("a")->leftJoin("good b" ,"a.spuCode=b.spuCode")
-                        ->where(['wsm_code' => $wsm_out, 'a.spuCode' => $value['spuCode'], 'a.is_del' => 0])
-                        ->field("a.spuCode,wsm_code,usable_stock,wait_out_stock,wait_in_stock,b.good_name")->find();
+                    $st = Db::name("good_stock_info")->alias("a")
+                     ->leftJoin("good_stock d" ,"d.id=a.stockid")
+                    ->leftJoin("good b" ,"d.spuCode=b.spuCode")
+                        ->where(['wsm_code' => $wsm_out, 'a.bnCode' => $value['bnCode'], 'd.is_del' => 0])
+                        ->field("d.spuCode,wsm_code,d.usable_stock,d.wait_out_stock,d.wait_in_stock,b.good_name,a.total_num,a.balance_num,a.origin_price")
+                        ->find();
                     if (empty($st)) {
                         Db::rollback();
                         return error_show(1003, "商品不能为空");
@@ -389,21 +380,23 @@ class Allot extends Base
                         }
                     }
 
-                    if($value['allot_num']>$st['usable_stock']){
+                    if($value['allot_num']>$st['balance_num']){
                         Db::rollback();
-                        return error_show(2000,"库存数量不足");
+                        return error_show(2000,"批次库存数量不足");
                     }
                     $temp = [];
                    isset($value['id'])&&$value['id']!=="" ? $temp['id'] = $value['id']:'';
                     $temp['good_name'] = $st['good_name'];
-                    $temp['good_type_code'] = $value['spuCode'];
+                    $temp['good_type_code'] = $st['spuCode'];
+                    $temp['bnCode'] =$value['bnCode'];
                     $temp['allot_num'] = $value['allot_num'];
-                    $temp['usable_num'] =$st['usable_stock'];
+                    $temp['usable_num'] =$st['balance_num'];
+                    $temp['origin_price'] = $st['origin_price'];
                     $temp['error_num'] = 0;
                     $temp['error_remark'] = "";
                     $temp['allot_code'] = $etid['allot_code'];
                     $temp['stock_num'] = 0;
-                    $temp['good_num']=$st['usable_stock'];
+                    $temp['good_num']=$st['balance_num'];
                     $temp['error_code']="";
                     $temp['is_del']=$value['is_del'];
                     isset($value['id'])&&$value['id']!=="" ? '' :$temp['addtime'] = date("Y-m-d H:i:s");
@@ -416,8 +409,6 @@ class Allot extends Base
                 }
                 $order = ["order_code"=>$etid['allot_code'],"status"=>$etid['status'],"action_remark"=>'',"action_type"=>"edit"];
                 ActionLog::logAdd($this->post['token'],$order,"DBD",$etid['status'],$this->post);
-//                $process=["order_code"=>$etid['allot_code'],"order_id"=>$etid['id'],"order_status"=>$etid['status'],"order_type"=>'DBD',"before_status"=>1];
-//                ProcessOrder::AddProcess($token,$process);
                 Db::commit();
                 return error_show(0, "调拨更新成功");
             }
@@ -443,11 +434,21 @@ class Allot extends Base
             ActionLog::logAdd($this->post['token'],$order,"DBD",$str['status'],$this->post);
             $process=["order_code"=>$str['allot_code'],"order_status"=>$str['status'],"order_type"=>'DBD'];
             ProcessOrder::workdel($process);
+            //将对应的调拨单流程的数据都删掉(没有相关的中断节点,所以这里直接操作process_wait表)
+            Db::name('process_wait')
+                ->where([
+                    'order_type' => 'DBD',
+                    'order_code' => $str['allot_code'],
+                    'order_id' => $id,
+                    'status' => ProcessWait::$status_wait,
+                ])->update(['status' => ProcessWait::$status_interrupt]);
+
             return error_show(0,"删除成功");
         }else{
             return error_show(1002,"删除失败");
         }
     }
+    // 0 待发起流程 1 待入库方同意 2 待出库方发货 3待入库方验货 4待验货审核 5 调拨完成  6 调拨驳回
     public function status(){
         $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"" ;
         if($id==""){
@@ -479,6 +480,11 @@ class Allot extends Base
                             Db::rollback();
                             return error_show(2000,"超出库存数量");
                         }
+                        $stockinfo = Db::name("good_stock_info")->where(["bnCode"=>$value['bnCode'],"stockid"=>$stock['id']])->find();
+                         if($value['allot_num']>$stockinfo['balance_num']){
+                            Db::rollback();
+                            return error_show(2000,"超出bn库存数量");
+                        }
                         if($status==2){
                             $stock['usable_stock']-=$value['allot_num'];
                             $stock['wait_out_stock']+=$value['allot_num'];
@@ -489,6 +495,11 @@ class Allot extends Base
                             if($Db==false){
                                 Db::rollback();
                                 return error_show(1002,"状态更新失败");
+                            }
+							$stoup =GoodStockInfo::bnStock($stock['id'],$value['bnCode'],$value['allot_num'],1);
+                            if($stoup==false){
+                            	Db::rollback();
+                                return error_show(1002,"bn库存数修改失败");
                             }
                            //商品变动日志表,good_log_code字段存储调拨单号
                         $good_data[] = ['good_log_code' => $st['allot_code'], "stock_id" => $stock['id'], "type" => 1, 'stock' =>$value['allot_num'], "stock_name" => "wait_out_stock"];
@@ -499,7 +510,7 @@ class Allot extends Base
                 }
                 $order = ["order_code"=>$st['allot_code'],"status"=>$sr,"action_remark"=>'',"action_type"=>"status"];
                 ActionLog::logAdd($this->post['token'],$order,"DBD",$status,$this->post);
-                $process=["order_code"=>$st['allot_code'],"order_id"=>$st['id'],"order_status"=>$st['status'],"order_type"=>'DBD',"before_status"=>$sr];
+                $process=["order_code"=>$st['allot_code'],"order_id"=>$st['id'],"order_status"=>$st['status'],"order_type"=>'DBD',"before_status"=>$sr, 'holder_id' => $st['apply_id']];
                 ProcessOrder::AddProcess($this->post['token'],$process);
                 Db::commit();
                 return error_show(0,"状态更新成功");
@@ -572,7 +583,7 @@ class Allot extends Base
                 }
                 $order = ["order_code"=>$al['allot_code'],"status"=>$al['status'],"action_remark"=>'',"action_type"=>"edit"];
                 ActionLog::logAdd($this->post['token'],$order,"DBD",3,$this->post);
-                $process=["order_code"=>$allot_code,"order_id"=>$al['id'],"order_status"=>3,"order_type"=>'DBD',"before_status"=>$al['status']];
+                $process=["order_code"=>$allot_code,"order_id"=>$al['id'],"order_status"=>3,"order_type"=>'DBD',"before_status"=>$al['status'], 'holder_id' => $al['apply_id']];
                 ProcessOrder::AddProcess($this->post['token'],$process);
                 Db::commit();
                 return error_show(0,"发货更新成功");
@@ -610,25 +621,20 @@ class Allot extends Base
         if($datainfo>0) {
             $good_data=[];
             foreach ($dain as $value) {
-                $st = Db::name("good_stock")->alias("a")->leftJoin("good b" ,"a.spuCode=b.spuCode")
-                    ->where(['wsm_code' => $al['wsm_out'], 'a.spuCode' => $value['good_code'], 'a.is_del' => 0])
-                    ->field("a.spuCode,wsm_code,usable_stock,wait_out_stock,wait_in_stock,b.good_name")->find();
-                if ($st==false) {
-                    Db::rollback();
-                    return error_show(1003, "未找到商品");
-                }
+//                $st = Db::name("good_stock")->alias("a")->leftJoin("good b" ,"a.spuCode=b.spuCode")
+//                    ->where(['wsm_code' => $al['wsm_out'], 'a.spuCode' => $value['good_code'], 'a.is_del' => 0])
+//                    ->field("a.spuCode,wsm_code,usable_stock,wait_out_stock,wait_in_stock,b.good_name")->find();
+//                if ($st==false) {
+//                    Db::rollback();
+//                    return error_show(1003, "未找到商品");
+//                }
                 $n = Db::name('allot_info')->where(['id'=>$value['id'],'allot_code'=>$al['allot_code'],'is_del'=>0])->find();
                 if($n==false){
                     Db::rollback();
                     return error_show(10032, "未找到盘点信息数据");
                 }
-//                if($value['allot_num']>$st['usable_stock']){
-//                    return error_show(2000,"库存数量不足");
-//                }
                 $temp = [];
                 $temp['error_code']=$value['error_code'];
-                $temp['good_num']=$st['usable_stock'];
-                $temp['usable_num'] = $st['usable_stock'];
                 $temp['error_num'] = $value['error_num'];
                 $temp['error_remark'] = $value['error_remark'];
                 $temp['stock_num']=$n['allot_num']-$value['error_num'];
@@ -681,7 +687,7 @@ class Allot extends Base
             GoodLog::LogAdd($this->post['token'],$good_data,'DBD');
             $order = ["order_code"=>$al['allot_code'],"status"=>$al['status'],"action_remark"=>'',"action_type"=>"edit"];
             ActionLog::logAdd($this->post['token'],$order,"DBD",4,$this->post);
-            $process=["order_code"=>$allot_code,"order_id"=>$al['id'],"order_status"=>4,"order_type"=>'DBD',"before_status"=>$al['status']];
+            $process=["order_code"=>$allot_code,"order_id"=>$al['id'],"order_status"=>4,"order_type"=>'DBD',"before_status"=>$al['status'], 'holder_id' => $al['apply_id']];
             ProcessOrder::AddProcess($this->post['token'],$process);
             Db::commit();
             return error_show(0, "入库验货更新成功");
@@ -720,21 +726,16 @@ public function vesio(){
             $order = ["order_code"=>$al['allot_code'],"status"=>$al['status'],"action_remark"=>'',"action_type"=>"edit"];
             ActionLog::logAdd($this->post['token'],$order,"DBD",5,$this->post);
             foreach ($dain as $value) {
-                $st = Db::name("good_stock")->alias("a")->leftJoin("good b" ,"a.spuCode=b.spuCode")
-                    ->where(['wsm_code' => $al['wsm_out'], 'a.spuCode' => $value['good_code'], 'a.is_del' => 0])
-                    ->field("a.spuCode,wsm_code,usable_stock,wait_out_stock,wait_in_stock,b.good_name")->find();
-                if ($st==false) {
-                    Db::rollback();
-                    return error_show(1003, "商品不能为空");
-                }
+//                $st = Db::name("good_stock")->alias("a")->leftJoin("good b" ,"a.spuCode=b.spuCode")
+//                    ->where(['wsm_code' => $al['wsm_out'], 'a.spuCode' => $value['good_code'], 'a.is_del' => 0])
+//                    ->field("a.spuCode,wsm_code,usable_stock,wait_out_stock,wait_in_stock,b.good_name")->find();
+
                 $p = Db::name('allot_info')->where(['id'=>$value['id'],'allot_code'=>$al['allot_code'],"is_del"=>0])->find();
                 if($p==false){
                     Db::rollback();
                     return error_show(1002,"未找到盘点数据");
                 }
                 $temp = [];
-                $temp['good_num']=$st['usable_stock'];
-                $temp['usable_num']=$st['usable_stock'];
                 $temp['error_num'] = $value['error_num']+$p['stock_num']-$value['stock_num'];
                 $temp['stock_num'] = $value['stock_num'];
                 $temp['error_remark'] = $value['error_remark'];
@@ -759,12 +760,17 @@ public function vesio(){
                     Db::rollback();
                     return error_show(1004, "验货更新失败");
                 }
+                $stoup =GoodStockInfo::bnStock($stock['id'],$p['bnCode'],$p['stock_num'],0,$p['origin_price']);
+                if($stoup==false){
+                	Db::rollback();
+                    return error_show(1002,"bn库存数修改失败");
+                }
                 //商品变动日志表,good_log_code字段存储调拨单号
                 $good_data[] = ['good_log_code' => $allot_code, "stock_id" => $stock['id'], "type" => 2, 'stock' => $p['stock_num'], "stock_name" => "wait_in_stock"];
                 $good_data[] = ['good_log_code' => $allot_code, "stock_id" => $stock['id'], "type" => 1, 'stock' => $p['stock_num'], "stock_name" => "usable_stock"];
             }
             GoodLog::LogAdd($this->post['token'],$good_data,'DBD');
-            $process=["order_code"=>$allot_code,"order_id"=>$al['id'],"order_status"=>5,"order_type"=>'DBD',"before_status"=>$al['status']];
+            $process=["order_code"=>$allot_code,"order_id"=>$al['id'],"order_status"=>5,"order_type"=>'DBD',"before_status"=>$al['status'], 'holder_id' => $al['apply_id']];
             ProcessOrder::AddProcess($this->post['token'],$process);
             Db::commit();
             return error_show(0, "验货更新成功");
@@ -776,4 +782,127 @@ public function vesio(){
         return error_show(1005,$e->getMessage());
     }
 }
+
+	public function goodlist()
+    {
+        $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : 1;
+        $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : 10;
+        $condtion = [['b.is_del', "=", 0], ['c.is_del', "=", 0],["d.balance_num",">=",0]];
+        $wsmcode = isset($this->post['wsm_code']) && $this->post['wsm_code'] !== "" ? trim($this->post['wsm_code']) : "";
+        if ($wsmcode !== "") {
+            //return error_show(1002,"仓库code不能为空");
+            $condtion[] = ['c.wsm_code', "=", $wsmcode];
+            // $typecode= Db::name("good_stock")->where(["wsm_code"=>$wsmcode,'is_del'=>0])->column("good_type_code");
+        }
+        $goodcode = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code'])
+            : "";
+        if ($goodcode != "") {
+            // $condtion['a.good_code'] = Db::raw("like '%{$goodcode}%'");
+            $condtion[] = ['b.spuCode', "like", "%{$goodcode}%"];
+        }
+        $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name'])
+            : "";
+        if ($good_name != "") {
+            //  $condtion['a.good_name'] = Db::raw("like '%{$good_name}%'");
+            $condtion[] = ['b.good_name', "like", "%{$good_name}%"];
+        }
+        $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
+        if ($supplierNo != "") {
+            $supplier = Db::name("supplier")->where(["code" => $supplierNo])->find();
+            if (empty($supplier)) {
+                return error_show(1004, "未找到供应商信息");
+            }
+            $wsmcode = Db::name("warehouse_info")->where(["is_del" => 0, "supplierNo" => $supplierNo])->column("wsm_code");
+            $condtion[] = ['c.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[] = ["c.wsm_code", "in", $wsmcode];
+        }
+        $stock_low = isset($this->post['stock_low']) && $this->post['stock_low'] !== "" ? intval($this->post['stock_low'])
+            : "";
+        if ($stock_low != "") {
+            $condtion[] = ['d.balance_num', ">=", $stock_low];
+        }
+        $stock_up = isset($this->post['stock_up']) && $this->post['stock_up'] !== "" ? trim($this->post['stock_up'])
+            : "";
+        if ($stock_up != "") {
+            $condtion[] = ['d.balance_num', "<=", $stock_up];
+        }
+
+        $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] !== "" ? intval($this->post['cat_id']) : "";
+        if ($cat_id != "") {
+            $at = Db::name('cat')->where(['id' => $cat_id])->find();
+            if (empty($at)) {
+                return error_show(1004, "未找到分类信息");
+            }
+            $cat = manger([$at['id']], $at['level']);
+            $condtion[] = ['b.cat_id', "in", $cat];
+        }
+        $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
+        if ($company_name !== "") $condtion[] = ["b.createrid", 'in', get_company_item_user_by_name($company_name)];
+
+        $count = Db::name("good")
+            ->alias("b")
+            ->join("good_stock c", "c.spuCode=b.spuCode", "left")
+            ->join("good_stock_info d", "c.id=d.stockid", "left")
+            ->where($condtion)
+            ->count();
+        $page >= ceil($count / $size) ? $page = ceil($count / $size) : "";
+        $list = Db::name("good")
+            ->alias("b")
+            ->leftJoin("good_stock c", "c.spuCode=b.spuCode")
+            ->join("good_stock_info d", "c.id=d.stockid", "left")
+            ->leftJoin("depart_user u", "u.uid=b.createrid AND u.is_del=0")
+            ->where($condtion)
+            ->field("b.*,c.id as stock_id,c.usable_stock,c.wait_in_stock,c.wait_out_stock,c.wsm_code,u.uid,u.nickname,u.itemid,d.bnCode,d.balance_num,d.origin_price")
+            ->page($page, $size)
+            ->select()
+            ->toArray();
+
+        $data = [];
+        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');
+            $business = Db::name('business')->whereIn('companyNo', array_column($list, 'companyNo'))->where('is_del', 0)->column('company', 'companyNo');
+            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'] = isset($brands[$value['brand_id']]) ? $brands[$value['brand_id']] : '';
+                $value['unit'] = isset($units[$value['good_unit']]) ? $units[$value['good_unit']] : '';
+                $value['companyName'] = isset($business[$value['companyNo']]) ? $business[$value['companyNo']] : '';
+                //规格信息
+                $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;
+                $value['cgder'] = isset($supplier['person']) ? $supplier['person'] : '';
+                $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
+                $data[] = $value;
+            }
+
+        }
+
+        return app_show(0, "获取成功", ["list" => $data, "count" => $count]);
+    }
 }

+ 128 - 0
app/admin/controller/Base.php

@@ -4,6 +4,8 @@
 namespace app\admin\controller;
 
 
+use app\admin\model\ActionLog;
+use app\admin\model\ProcessOrder;
 use think\App;
 use think\facade\Db;
 use app\admin\model\DataGroup as DataGroupModel;
@@ -50,6 +52,7 @@ class Base extends \app\BaseController
             return [];
         }
         $action=[];
+        $this->roleid=$uid['roleid'];
         $role =Db::name("role_action")->where(["role_id"=>$uid['roleid'],"status"=>1])->find();
         $action['action_conllect']=isset($role['action_conllect'])? $role['action_conllect']:'';
         $action['write'][]=$this->uid;
@@ -114,6 +117,7 @@ class Base extends \app\BaseController
 
     }
 
+
     //用户数据权限检查
     protected function checkDataShare(){
 
@@ -129,4 +133,128 @@ class Base extends \app\BaseController
         return $data;
     }
 
+    /**
+	* @param $good
+	* @param $isZx
+	* @param string $thNo
+	 * @return mixed|string
+	* @throws \think\Exception
+	 */
+    public function CheckGoodZx($good,$isZx,$thNo=''){
+  	    $spuCode= makeNo("SKU");
+  	    //查询是否存在转库存品记录 存在则返回库存编号
+  	    $newCode= Db::name("good_change_log")->where(["oldCode"=>$good['spuCode']])->value("newCode",'');
+  	    if($newCode==''){
+  	    	 $log=["oldCode"=>$good['spuCode'],
+		        "order_source"=>$isZx,
+		        "newCode"=>$spuCode,
+		        "thCode"=>$thNo,
+		        "createrid"=>$this->uid,
+		        "creater"=>$this->uname,
+		        "addtime"=>date("Y-m-d H:i:s")
+  	        ];
+  	    }else{
+  	    	return $newCode;
+  	    }
+
+  	    if($isZx==1){
+  	    	  $supplier =Db::name("supplier")->where(["code"=>$good['supplierNo']])->findOrEmpty();
+        if(empty($supplier)) throw new \Exception('非库存商品转库存失败');
+  	    	$good = [
+                    'spuCode' => $spuCode,
+                    'good_code' => $good['good_code'],
+                    'good_name' => $good['good_name'],
+                    'cat_id' => $good['cat_id'],
+                    'brand_id' => $good['brand_id'],
+                    'companyNo' => $good['companyNo'],
+                    'good_unit' => $good['good_unit'],
+                    'good_type' => $good['good_type'],
+                    'moq' => $good['moq'],
+                    'customized' => $good['customized'],
+                    'tax' => $good['tax'],
+                    'supplierNo' => $good['supplierNo'],
+                    'is_auth' => $good['is_auth'],
+                    'auth_img' => $good['auth_img'],
+                    'after_sales' => '',
+                    'craft_desc' => $good['craft_desc'],
+                    'good_remark' => $good['good_remark'],
+                    'weight' => $good['weight'],
+                    'packing_way' => '',
+                    'packing_size' => '',
+                    'packing_spec' => '',
+                    'packing_list' => '',
+                    'packing_weight' => '',
+                    'good_bar' => '',
+                    'supply_area' => $good['supply_area'],
+                    'delivery_place' => '',
+                    'origin_place' => '',
+                    'delivery_day' => '',
+                    'lead_time' => '',
+                    'sample_day' => '',
+                    'sample_fee' => '',
+                    'good_img' => '',//$good['good_img'],
+                    'good_thumb_img' => $good['good_thumb_img'],
+                    'good_info_img' => $good['good_img'],//商品主图对应到商品详情
+                    'cert_fee' => '',
+                    'packing_fee' => '',
+                    'cost_fee' => '',
+                    'mark_fee' => '',
+                    'demo_fee' => '',
+                    'open_fee' => '',
+                    'noble_metal' => $good['noble_metal'],
+                    'noble_weight' => $good['good_weight'],
+                    'is_gold_price' => $good['is_gold_price'],
+                    'cgd_gold_price' => '',
+                    'market_price' => '',
+                    'nake_price' => '',
+                    'is_step' => '',
+                    'is_online' => '0',
+                    'is_stock' => '1',
+                    'status' =>7,//咨询商品待编辑
+                    'createrid' =>$good['createrid'],
+                    'creater' => $good['creater'],
+                    'field_change' => '',
+                    'is_del' => 0,
+                    'is_support_stock' => 0,
+                    'addtime' => date('Y-m-d H:i:s'),
+                    'updatetime' => date('Y-m-d H:i:s'),
+                    'is_diff' => $good['is_diff'],
+                    'config' => $good['config'],
+                    'other_config' => $good['other_config'],
+                     'chargerid'=>$supplier['personid']??$good['createrid'],
+                      'charger'=>$supplier['person']??$good['creater'],//负责人跟创建人一致
+                ];
+  	    }else{
+			$good['id']=null;
+			$good['spuCode']=$spuCode;
+			$good['is_stock']=1;
+			$good['is_support_stock']=0;
+			$good['status']=7;
+			$good['addtime']=date("Y-m-d H:i:s");
+			$good['updatetime']=date("Y-m-d H:i:s");
+  	    }
+  	    $insert =Db::name("good_basic")->insert($good,true);
+  	    if($insert==false) throw new \Exception("非库存商品转库存失败",1005);
+  	     //修改状态,添加待办
+                ActionLog::logAdd($this->post['token'], [
+                    "order_code" =>$newCode,//咨询单详情编号
+                    "status" => 0,//这里的status是之前的值
+                    "action_remark" => '非库存品退货转库存',//备注
+                    "action_type" => "create"//新建create,编辑edit,更改状态status
+                ], "SPCB", 7,$good);
+
+                ProcessOrder::AddProcess($this->post['token'], [
+                    "order_type" => 'SPCB',
+                    "order_code" =>$newCode,//咨询单详情编号
+                    "order_id" => $insert,
+                    "order_status" =>7,
+                    "before_status"=>0,
+                    'holder_id'=>$good['createrid'],
+                ]);
+  	    $newAdd=Db::name("good_change_log")->insert($log);
+  	    if($newAdd==false) throw new \Exception("非库存商品转库存失败",1005);
+  	    return $spuCode;
+
+    }
+
 }

+ 225 - 249
app/admin/controller/Check.php

@@ -4,6 +4,7 @@ namespace app\admin\controller;
 
 use app\admin\model\DataGroup as DataGroupModel;
 use app\admin\model\ProcessOrder;
+use app\admin\model\ProcessWait;
 use app\BaseController;
 use think\App;
 use think\facade\Db;
@@ -109,6 +110,7 @@ public function __construct(App $app)
             ->leftJoin("good_stock c", "c.spuCode=b.spuCode")
             ->leftJoin("depart_user u", "u.uid=b.createrid AND u.is_del=0")
             ->where($condtion)
+            ->field("b.*,c.id as stock_id,c.usable_stock,c.wait_in_stock,c.wait_out_stock,c.wsm_code,u.uid,u.nickname,u.itemid")
             ->page($page, $size)
             ->select()
             ->toArray();
@@ -132,7 +134,7 @@ public function __construct(App $app)
                 $value['brand_name'] = isset($brands[$value['brand_id']]) ? $brands[$value['brand_id']] : '';
                 $value['unit'] = isset($units[$value['good_unit']]) ? $units[$value['good_unit']] : '';
                 $value['companyName'] = isset($business[$value['companyNo']]) ? $business[$value['companyNo']] : '';
-
+                $value['bninfo'] =Db::name("good_stock_info")->where([["stockid","=",$value['stock_id']],["balance_num",">",0]])->select()->toArray();
                 //规格信息
                 $spec = Db::name("good_spec")->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
 
@@ -150,17 +152,8 @@ public function __construct(App $app)
                     }
                 }
                 $value['specinfo'] = $speclist;
-
-                //采购人
-//                $value['cgder'] = Db::name('supplier')
-//                    ->where([
-//                        'code' => $value['supplierNo'],
-//                        'is_del' => 0,
-//                    ])->value('person', '');
                 $value['cgder'] = isset($supplier['person']) ? $supplier['person'] : '';
-
                 $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
-
                 $data[] = $value;
             }
 
@@ -255,225 +248,198 @@ public function list()
     }
     return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
 
-    }
-public function goodlist(){
-    $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];
-    $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
-    if($id==""){
-        return error_show(1002,"参数id不能为空");
-    }
-    $fo = Db::name('good_check')->alias('a')->join('warehouse_info b',"b.wsm_code=a.wsm_code","left")
-        ->join('supplier c',"c.code=b.supplierNo","left")->field("c.name,c.code,a.*")
-        ->where(['a.id'=>$id,'a.is_del'=>0])->find();
-    if(empty($fo)){
-        return error_show(1003,"未找到盘点信息");
-    }
-    if ($fo['check_code'] !== "") {
-        $where['check_code'] = $fo['check_code'];
-    }
-    $count = Db::name('check_item')->where($where)->count();
-    $total = ceil($count / $size);
-    $page = $page >= $total ?  $total: $page;
-    $list = Db::name('check_item')->where($where)->page($page,$size)->select();
-    return app_show(0,"获取成功",['count'=>$count,'list'=>$list]);
-}
-public function create(){
-    $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
-
-    $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
-    if($wsm_code==""){
-        return error_show(1002,"盘点仓库编号不能为空");
-    }
-    $type = isset($this->post['type']) && $this->post['type'] !=="" ? intval($this->post['type']) :"";
-    if($type==""){
-        return error_show(1002,"盘点类型不能为空");
-    }
-    $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) :"";
-    if($companyNo==""){
-        return error_show(1002,"参数companyNo不能为空");
-    }
-    $company =Db::name("business")->where(['companyNo'=>$companyNo,"is_del"=>0])->find();
-    if($company==false){
-        return error_show(1002,"未找到业务公司");
-    }
-    $check_code = makeNo("CK");
-    $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'] : "";
-    $ri= isset($apply_id["data"]['nickname']) ?  $apply_id["data"]['nickname'] : "";
-    $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"0";
-    $remark = isset($this->post['remark']) && $this->post['remark'] !=="" ? intval($this->post['remark']) :"";
-    Db::startTrans();
-    try{
-        $data=[
-            "check_code"=>$check_code,
-            "wsm_code"=>$wsm_code,
-            "type"=>$type,
-            "status"=>$status,
-            "companyNo"=>$companyNo,
-            "remark"=>$remark,
-            "apply_id"=>$rm,
-            "apply_name"=>$ri,
-            "is_del"=>0,
-            "addtime"=>date('Y-m-d H:i:s'),
-            "updatetime"=>date("Y-m-d H:i:s")
-        ];
-        $da= Db::name('good_check')->insert($data,true);
-//        $dio=[];
-//        if($da>0){
-//            foreach ($dain as $value){
-//            $st=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(['c.wsm_code'=>$wsm_code,'good_type_code'=>$value['type_code'],'b.is_del'=>0,'a.is_del'=>0])->where("c.is_del=0 or c.is_del is null")
-//                ->field("b.type_code,a.good_name,c.wsm_code,c.wait_in_stock,c.wait_out_stock,c.usable_stock,c.good_type_code,a.original_price")->find();
-//
-//            $temp=[];
-//            $temp['good_name']=$st['good_name'];
-//            $temp['origin_price']=$st['original_price'];
-//            $temp['good_type_code']=$st['good_type_code'];
-//            $temp['origin_num']=$st['usable_stock'];
-//            $temp['check_num']=0;
-//            $temp['diff_num']=0;
-//            $temp['status']=0;
-//            $temp['remark']="";
-//            $temp['is_del']=0;
-//            $temp['check_time']=date('Y-m-d H:i:s');
-//            $temp['check_code']=$check_code;
-//            $temp['addtime']=date("Y-m-d H:i:s");
-//            $temp['updatetime']=date("Y-m-d H:i:s");
-//            $dio[] =$temp;
-//            }
-//            $in= Db::name('check_item')->insertAll($dio);
-//        }
-        if($da){
-            $orde = ["order_code"=>$check_code,"status"=>$data['status'],"action_remark"=>'',"action_type"=>"create"];
-            ActionLog::logAdd($this->post['token'],$orde,'PDD',$data['status'],$orde);
-            $process=["order_code"=>$check_code,"order_id"=>$da,"order_status"=>$data['status'],"order_type"=>'PDD',"before_status"=>$data['status']];
-            ProcessOrder::AddProcess($this->post['token'],$process);
-           Db::commit();
-            return error_show(0,"盘点创建成功");
-        }else{
-            Db::rollback();
-           return error_show(1002,"创建失败");
-        }
-    }catch (\Exception $e){
-        Db::rollback();
-        return error_show(1005,$e->getMessage());
-   }
-    }
-public function info(){
-    $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
-    if($id==""){
-        return error_show(1002,"参数id不能为空");
-    }
-    $fo = Db::name('good_check')->alias('a')->join('warehouse_info b',"b.wsm_code=a.wsm_code","left")
-        ->join('supplier c',"c.code=b.supplierNo","left")->field("c.name,c.code,a.*")
-        ->where(['a.id'=>$id,'a.is_del'=>0])->find();
-    if(empty($fo)){
-        return error_show(1003,"未找到盘点信息");
-    }
-    $fi = Db::name('check_item')->where(['check_code'=>$fo['check_code'],'is_del'=>0])->select();
-    $fo['item']=$fi;
-    if(empty($fo)){
-        return error_show(1002,"未找到盘点编号");
-    }else{
-        return app_show(0,"获取成功",$fo);
-    }
-}
-public function edit()
-{
-    $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
-    $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
-    $eid = Db::name('good_check')->where(['id' => $id, 'is_del' => 0])->find();
-    if ($eid ==="") {
-        return error_show(1002, "未找到盘点编号信息");
-    }
-    $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !== "" ? trim($this->post['wsm_code']) : "";
-    if ($wsm_code == "") {
-        return error_show(1002, "盘点仓库不能为空");
-    }
-    $type = isset($this->post['type']) && $this->post['type'] !== "" ? trim($this->post['type']) : "";
-    $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
-    if ($type == "") {
-        return error_show(1002, "盘点类型不能为空");
-    }
-    $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'] : "";
-    $ri= isset($apply_id["data"]['nickname']) ?  $apply_id["data"]['nickname'] : "";
-//    $dain=isset($this->post['good']) && $this->post['good'] !=="" ? $this->post['good']:"";
-//    if($type==2){
-//       // var_dump($dain);
-//        if($dain==""||empty($dain)){
-//            return error_show(1002,"商品不能为空");
-//        }
-//    }else{
-//        if($type==1) {
-//
-//            $dain= 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(['c.wsm_code'=>$wsm_code,'b.is_del'=>0,'a.is_del'=>0])->where("c.is_del=0 or c.is_del is null")
-//                ->field("b.type_code,a.good_name")->select();
-//            //var_dump($dain);
-//        }
-//        if($dain==""){
-//            return error_show(1003,"商品不能为空");
-//        }
-//    }
-    Db::startTrans();
-    try {
-        $var = [
-            "wsm_code" => $wsm_code,
-            "type" => $type,
-            "apply_id" => $rm,
-            "apply_name" => $ri,
-            "remark" => $remark,
-            "updatetime" => date("Y-m-d H:i:s")
-        ];
-        $up = Db::name('good_check')->where(['id'=>$id,'is_del' => 0])->save($var);
-//            $dn =[];
-//            if($up>0){
-//                foreach ($dain as $value){
-//                    $st=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(['c.wsm_code'=>$wsm_code,'good_type_code'=>$value['type_code'],'b.is_del'=>0,'a.is_del'=>0])->where("c.is_del=0 or c.is_del is null")
-//                        ->field("b.type_code,a.good_name,c.wsm_code,c.wait_in_stock,c.wait_out_stock,c.usable_stock,c.good_type_code,a.original_price")->find();
-//                    $temp=[];
-//                    $temp['good_name']=$st['good_name'];
-//                    $temp['origin_price']=$st['original_price'];
-//                    $temp['good_type_code']=$st['good_type_code'];
-//                    $temp['origin_num']=$st['usable_stock'];
-//                    $temp['check_num']=0;
-//                    $temp['diff_num']=0;
-//                    $temp['status']=0;
-//                    $temp['remark']="";
-//                    $temp['is_del']=0;
-//                    $temp['check_time']=date('Y-m-d H:i:s');
-//                    $temp['check_code']=$eid['check_code'];
-//                    $temp['addtime']=date("Y-m-d H:i:s");
-//                    $temp['updatetime']=date("Y-m-d H:i:s");
-//                    $dn[] =$temp;
-//                }
-//                $np = Db::name('check_item')->where(['check_code'=>$eid['check_code'],'is_del'=>0])->update(['is_del'=>1,'updatetime'=>date('Y-m-d H:i:s')]);
-//               $io = db::name('check_item')->insertAll($up);
-               // var_dump(Db::name('check_item')->getLastSql());
-                if ($up) {
-                    $orde = ["order_code"=>$eid['check_code'],"status"=>$eid['status'],"action_remark"=>'',"action_type"=>"edit"];
-                    ActionLog::logAdd($this->post['token'],$orde,'qrd',$eid['status'],$orde);
-                    Db::commit();
-                    return error_show(0, "盘点更新成功");
-                }
-
-        Db::rollback();
-        return error_show(1003,"盘点更新失败");
-    } catch (\Exception $e) {
-        Db::rollback();
-        return error_show(1005, $e->getMessage());
-    }
-}
+	    }
+	public function goodlist(){
+	    $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];
+	    $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
+	    if($id==""){
+	        return error_show(1002,"参数id不能为空");
+	    }
+	    $fo = Db::name('good_check')->alias('a')->join('warehouse_info b',"b.wsm_code=a.wsm_code","left")
+	        ->join('supplier c',"c.code=b.supplierNo","left")->field("c.name,c.code,a.*")
+	        ->where(['a.id'=>$id,'a.is_del'=>0])->find();
+	    if(empty($fo)){
+	        return error_show(1003,"未找到盘点信息");
+	    }
+	    if ($fo['check_code'] !== "") {
+	        $where['check_code'] = $fo['check_code'];
+	    }
+	    $count = Db::name('check_item')->where($where)->count();
+	    $total = ceil($count / $size);
+	    $page = $page >= $total ?  $total: $page;
+	    $list = Db::name('check_item')->where($where)->page($page,$size)->select();
+	    return app_show(0,"获取成功",['count'=>$count,'list'=>$list]);
+	}
+	public function create(){
+	    $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
+	    $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
+	    if($wsm_code==""){
+	        return error_show(1002,"盘点仓库编号不能为空");
+	    }
+	    $type = isset($this->post['type']) && $this->post['type'] !=="" ? intval($this->post['type']) :"";
+	    if($type==""){
+	        return error_show(1002,"盘点类型不能为空");
+	    }
+	    $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) :"";
+	    if($companyNo==""){
+	        return error_show(1002,"参数companyNo不能为空");
+	    }
+	    $company =Db::name("business")->where(['companyNo'=>$companyNo,"is_del"=>0])->find();
+	    if($company==false){
+	        return error_show(1002,"未找到业务公司");
+	    }
+	    $check_code = makeNo("CK");
+//	    $apply_id=GetUserInfo($token);
+//	    if(empty($apply_id)||$apply_id['code']!=0){
+//	        return error_show(1002,"申请人数据不存在");
+//	    }
+	    $rm= $this->uid;//isset($apply_id["data"]['id']) ?  $apply_id["data"]['id'] : "";
+	    $ri= $this->uname;//isset($apply_id["data"]['nickname']) ?  $apply_id["data"]['nickname'] : "";
+	    $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"0";
+	    $remark = isset($this->post['remark']) && $this->post['remark'] !=="" ? intval($this->post['remark']) :"";
+	    Db::startTrans();
+	    try{
+	        $data=[
+	            "check_code"=>$check_code,
+	            "wsm_code"=>$wsm_code,
+	            "type"=>$type,
+	            "status"=>$status,
+	            "companyNo"=>$companyNo,
+	            "remark"=>$remark,
+	            "apply_id"=>$rm,
+	            "apply_name"=>$ri,
+	            "is_del"=>0,
+	            "addtime"=>date('Y-m-d H:i:s'),
+	            "updatetime"=>date("Y-m-d H:i:s")
+	        ];
+	        $da= Db::name('good_check')->insert($data,true);
+	        if($da){
+                $orde = ["order_code" => $check_code, "status" => $data['status'], "action_remark" => '', "action_type" => "create"];
+                ActionLog::logAdd(['id' => $rm, 'nickname' => $ri], $orde, 'PDD', $data['status'], $orde);
+                $process = ["order_code" => $check_code, "order_id" => $da, "order_status" => $data['status'], "order_type" => 'PDD', "before_status" => $data['status'], 'holder_id' => $rm];
+                ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], $process);
+	           Db::commit();
+	            return error_show(0,"盘点创建成功");
+	        }else{
+	            Db::rollback();
+	           return error_show(1002,"创建失败");
+	        }
+	    }catch (\Exception $e){
+	        Db::rollback();
+	        return error_show(1005,$e->getMessage());
+	   }
+	    }
+	public function info(){
+	    $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
+	    if($id==""){
+	        return error_show(1002,"参数id不能为空");
+	    }
+	    $fo = Db::name('good_check')->alias('a')->join('warehouse_info b',"b.wsm_code=a.wsm_code","left")
+	        ->join('supplier c',"c.code=b.supplierNo","left")->field("c.name,c.code,a.*")
+	        ->where(['a.id'=>$id,'a.is_del'=>0])->find();
+	    if(empty($fo)){
+	        return error_show(1003,"未找到盘点信息");
+	    }
+	    $fi = Db::name('check_item')->where(['check_code'=>$fo['check_code'],'is_del'=>0])->select();
+	    $fo['item']=$fi;
+	    if(empty($fo)){
+	        return error_show(1002,"未找到盘点编号");
+	    }else{
+	        return app_show(0,"获取成功",$fo);
+	    }
+	}
+	public function edit()
+	{
+	    $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
+	    $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
+	    $eid = Db::name('good_check')->where(['id' => $id, 'is_del' => 0])->find();
+	    if ($eid ==="") {
+	        return error_show(1002, "未找到盘点编号信息");
+	    }
+	    $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !== "" ? trim($this->post['wsm_code']) : "";
+	    if ($wsm_code == "") {
+	        return error_show(1002, "盘点仓库不能为空");
+	    }
+	    $type = isset($this->post['type']) && $this->post['type'] !== "" ? trim($this->post['type']) : "";
+	    $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
+	    if ($type == "") {
+	        return error_show(1002, "盘点类型不能为空");
+	    }
+	    $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'] : "";
+	    $ri= isset($apply_id["data"]['nickname']) ?  $apply_id["data"]['nickname'] : "";
+	//    $dain=isset($this->post['good']) && $this->post['good'] !=="" ? $this->post['good']:"";
+	//    if($type==2){
+	//       // var_dump($dain);
+	//        if($dain==""||empty($dain)){
+	//            return error_show(1002,"商品不能为空");
+	//        }
+	//    }else{
+	//        if($type==1) {
+	//
+	//            $dain= 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(['c.wsm_code'=>$wsm_code,'b.is_del'=>0,'a.is_del'=>0])->where("c.is_del=0 or c.is_del is null")
+	//                ->field("b.type_code,a.good_name")->select();
+	//            //var_dump($dain);
+	//        }
+	//        if($dain==""){
+	//            return error_show(1003,"商品不能为空");
+	//        }
+	//    }
+	    Db::startTrans();
+	    try {
+	        $var = [
+	            "wsm_code" => $wsm_code,
+	            "type" => $type,
+	            "apply_id" => $rm,
+	            "apply_name" => $ri,
+	            "remark" => $remark,
+	            "updatetime" => date("Y-m-d H:i:s")
+	        ];
+	        $up = Db::name('good_check')->where(['id'=>$id,'is_del' => 0])->save($var);
+	//            $dn =[];
+	//            if($up>0){
+	//                foreach ($dain as $value){
+	//                    $st=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(['c.wsm_code'=>$wsm_code,'good_type_code'=>$value['type_code'],'b.is_del'=>0,'a.is_del'=>0])->where("c.is_del=0 or c.is_del is null")
+	//                        ->field("b.type_code,a.good_name,c.wsm_code,c.wait_in_stock,c.wait_out_stock,c.usable_stock,c.good_type_code,a.original_price")->find();
+	//                    $temp=[];
+	//                    $temp['good_name']=$st['good_name'];
+	//                    $temp['origin_price']=$st['original_price'];
+	//                    $temp['good_type_code']=$st['good_type_code'];
+	//                    $temp['origin_num']=$st['usable_stock'];
+	//                    $temp['check_num']=0;
+	//                    $temp['diff_num']=0;
+	//                    $temp['status']=0;
+	//                    $temp['remark']="";
+	//                    $temp['is_del']=0;
+	//                    $temp['check_time']=date('Y-m-d H:i:s');
+	//                    $temp['check_code']=$eid['check_code'];
+	//                    $temp['addtime']=date("Y-m-d H:i:s");
+	//                    $temp['updatetime']=date("Y-m-d H:i:s");
+	//                    $dn[] =$temp;
+	//                }
+	//                $np = Db::name('check_item')->where(['check_code'=>$eid['check_code'],'is_del'=>0])->update(['is_del'=>1,'updatetime'=>date('Y-m-d H:i:s')]);
+	//               $io = db::name('check_item')->insertAll($up);
+	               // var_dump(Db::name('check_item')->getLastSql());
+	                if ($up) {
+	                    $orde = ["order_code"=>$eid['check_code'],"status"=>$eid['status'],"action_remark"=>'',"action_type"=>"edit"];
+	                    ActionLog::logAdd($this->post['token'],$orde,'qrd',$eid['status'],$orde);
+	                    Db::commit();
+	                    return error_show(0, "盘点更新成功");
+	                }
+	        Db::rollback();
+	        return error_show(1003,"盘点更新失败");
+	    } catch (\Exception $e) {
+	        Db::rollback();
+	        return error_show(1005, $e->getMessage());
+	    }
+	}
 
     /**
      * @return \think\response\Json|void
@@ -493,10 +459,18 @@ public function edit()
         $sv = Db::name('good_check')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
         if($sv){
             $orde = ["order_code"=>$deln['check_code'],"status"=>$deln['status'],"action_remark"=>'',"action_type"=>"delete"];
-            ActionLog::logAdd($this->post['token'],$orde,'PDD',$deln['status'],['id'=>$id,'is_del'=>1,
-                'updatetime'=>date("Y-m-d H:i:s")]);
+            ActionLog::logAdd($this->post['token'],$orde,'PDD',$deln['status'],['id'=>$id,'is_del'=>1, 'updatetime'=>date("Y-m-d H:i:s")]);
             $process=["order_code"=>$deln['check_code'],"order_status"=>$deln['status'],"order_type"=>'PDD'];
             ProcessOrder::workdel($process);
+
+            //将对应的盘点单流程的数据都删掉(没有相关的中断节点,所以这里直接操作process_wait表)
+            Db::name('process_wait')
+                ->where([
+                    'order_type' => 'PDD',
+                    'order_code' => $deln['check_code'],
+                    'order_id' => $id,
+                    'status' => ProcessWait::$status_wait,
+                ])->update(['status' => ProcessWait::$status_interrupt]);
             return error_show(0,"删除成功");
         }else{
             return error_show(1002,"删除失败");
@@ -550,8 +524,7 @@ public function edit()
                         return error_show(1003,"未上传盘点结果");
                     }
                 }
-                $process=["order_code"=>$st['check_code'],"order_id"=>$st['id'],"order_status"=>$stauts,
-                    "order_type"=>'PDD',"before_status"=>$temp];
+                $process=["order_code"=>$st['check_code'],"order_id"=>$st['id'],"order_status"=>$stauts, "order_type"=>'PDD',"before_status"=>$temp, 'holder_id' => $st['apply_id']];
                 ProcessOrder::AddProcess($this->post['token'],$process);
                 Db::commit();
                 return error_show(0,"状态更新成功");
@@ -577,11 +550,12 @@ public function edit()
         if(empty($fo)){
             return error_show(1003,"未找到盘点信息");
         }
-        $list = Db::name("good_basic")->alias("b")
-            ->join("good_stock c","c.spuCode=b.spuCode","left")
-            ->where(['c.wsm_code'=>$fo['wsm_code'],"b.is_del"=>0,"c.is_del"=>0])->field("b.spuCode'商品编码',
+        $list = Db::name("good_stock_info")->alias("d")
+            ->join("good_stock c","c.id=d.stockid and d.balance_num>0","left")
+            ->join("good b","c.spuCode=b.spuCode","left")
+            ->where(['c.wsm_code'=>$fo['wsm_code'],"b.is_del"=>0,"c.is_del"=>0])->field("d.bnCode '商品批次号',b.spuCode'商品编码',
             b.good_name '商品名称',b.craft_desc '商品描述',b.brand_id '品牌',b.good_unit '单位',b.supplierNo '供应商编码','' as '供应商名称','' as  '一级分类','' as '二级分类','' as  '三级分类',
-            b.addtime '新建时间',c.wsm_code '仓库编码','' as '仓库名称',c.usable_stock '可用库存','' as '盘点库存'")
+            b.addtime '新建时间',c.wsm_code '仓库编码','' as '仓库名称',c.usable_stock '可用库存',d.balance_num '批次库存数','' as '盘点库存'")
             ->select();
         $data=[];
         foreach ($list as $key=>$value){
@@ -625,22 +599,24 @@ public function edit()
         $insert=[];
         foreach ($data as $value){
             if($value["value0"]==""){
-                return error_show(1003,"商品编号不能为空");
+                return error_show(1003,"商品批次编号不能为空");
             }
-            if($value["value14"]===""){
+            if($value["value16"]===""){
                 continue;
             }
-            $stock = Db::name("good_stock")->where(["spuCode"=>$value["value0"],"wsm_code"=>$fo['wsm_code'], "is_del"=>0])->find();
-            $stock_num = isset($stock) ? $stock['usable_stock']:0;
+            $stock = Db::name("good_stock")->alias("a")
+            ->join("good_stock_info b","a.id=b.stockid","left")
+            ->where(["a.spuCode"=>$value["value1"],"wsm_code"=>$fo['wsm_code'],"bnCode"=>$value['value0'],"is_del"=>0])->find();
+            $stock_num = isset($stock) ? $stock['balance_num']:0;
             $insert[]=[
-                "spuCode"=>$value["value0"],
-                "good_name"=>$value["value1"],
+                "spuCode"=>$value["value1"],
+                "bnCode"=>$value["value0"],
+                "good_name"=>$value["value2"],
                 "origin_price"=>0,
-                "origin_num"=>isset($stock) ? $stock['usable_stock']:0,
-                "check_num"=>$value["value14"],
-                "is_profit"=>intval($value["value14"])>=$stock_num ?0:1,
-                "diff_num"=>intval($value["value14"])>=$stock_num ?intval($value["value14"])
-                    -$stock_num:$stock_num-intval($value["value14"]),
+                "origin_num"=>isset($stock) ? $stock['balance_num']:0,
+                "check_num"=>$value["value16"],
+                "is_profit"=>intval($value["value16"])>=$stock_num ?0:1,
+                "diff_num"=>intval($value["value16"])>=$stock_num ?intval($value["value16"])-$stock_num:$stock_num-intval($value["value16"]),
                 'addtime'=>date("Y-m-d H:i:s"),
                 'updatetime'=>date("Y-m-d H:i:s"),
                 "check_code"=>$fo['check_code']
@@ -657,7 +633,7 @@ public function edit()
                 if($check_up){
                     $orde = ["order_code"=>$fo['check_code'],$fo['status'],"action_remark"=>'',"action_type"=>"edit"];
                     ActionLog::logAdd($this->post['token'],$orde,'PDD',2,["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
-                    $process=["order_code"=>$fo['check_code'],"order_id"=>$fo['id'],"order_status"=>2,"order_type"=>'PDD',"before_status"=>$fo['status']];
+                    $process = ["order_code" => $fo['check_code'], "order_id" => $fo['id'], "order_status" => 2, "order_type" => 'PDD', "before_status" => $fo['status'], 'holder_id' => $fo['apply_id']];
                     ProcessOrder::AddProcess($this->post['token'],$process);
                     Db::commit();
                     return app_show(0,"盘点数据导入成功");

+ 3 - 2
app/admin/controller/Consult.php

@@ -1384,7 +1384,8 @@ class Consult extends Base
                     "order_code" => $bargainNo,
                     "order_id" => $int,
                     "order_status" =>0,
-                    "before_status"=>0
+                    "before_status"=>0,
+                    'holder_id'=>$data['createrid']
                 ]);
                 $odlstatus=$info['status'];
                 $info['status']=3;
@@ -1620,7 +1621,7 @@ class Consult extends Base
                     "action_remark" => '',//备注
                     "action_type" => "status"//新建create,编辑edit,更改状态status
                 ], "YJD", $info['status'], $info);
-                $process=["order_code"=>$bargainNo,"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'YJD',"before_status"=>$ra_status];
+                $process=["order_code"=>$bargainNo,"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'YJD',"before_status"=>$ra_status,'holder_id'=>$info['createrid']];
                 ProcessOrder::AddProcess($token,$process);
                 if($info['status']==1||$info['status']==3||$info['status']==8||$info['status']==6||$info['status']==9||$info['status']==10||$info['status']==11){
                     $bidstatus=$bids['status'];

+ 10 - 4
app/admin/controller/Good.php

@@ -62,7 +62,11 @@ class Good extends Base
         }
         $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :"";
         if($supplierNo!==""){
-            $where[]=['a.supplierNo',"=",$supplierNo];
+            $where[]=['a.supplierNo',"like","%$supplierNo%"];
+        }
+         $supplier_name = isset($this->post['supplier_name']) && $this->post['supplier_name'] !=="" ? trim($this->post['supplier_name']):"";
+        if($supplier_name!==""){
+            $where[]=['s.name',"like","%$supplier_name%"];
         }
         $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) :"";
         if($companyNo!==""){
@@ -114,6 +118,7 @@ class Good extends Base
         $count = Db::name('good')
             ->alias("a")
             ->leftJoin("good_platform b","a.spuCode=b.spuCode")
+            ->leftJoin("supplier s","a.supplierNo=s.code")
             ->leftJoin("depart_user u", "u.uid=b.createrid AND u.is_del=0")
             ->leftJoin("platform p","p.id=b.platform_code")
             ->where('p.platform_type',0)//只筛选非对接平台的商品
@@ -125,9 +130,10 @@ class Good extends Base
             ->alias("a")
             ->field("b.skuCode,b.platform_code,b.plat_code,b.id as good_id,a.cat_id,a.good_name,a.good_img,a.good_info_img,a.good_thumb_img,
             b.createrid,a.is_exclusive,a.brand_id,a.supplierNo,a.good_unit,a.noble_metal,a.companyNo,a.spuCode,a.good_type,b.creater,b.addtime,
-            b.updatetime,b.exam_status,a.createrid purchase_id,a.creater purchase,u.itemid,a.is_stock")
+            b.updatetime,b.exam_status,a.createrid purchase_id,a.creater purchase,u.itemid,a.is_stock,s.name as supplier_name")
             //成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
             ->leftJoin("good_platform b","a.spuCode=b.spuCode")
+            ->leftJoin("supplier s","a.supplierNo=s.code")
 //            ->leftJoin("good_basic gb","gb.spuCode=a.spuCode")
             ->leftJoin("depart_user u", "u.uid=b.createrid AND u.is_del=0")
             ->leftJoin("platform p","p.id=b.platform_code")
@@ -142,8 +148,8 @@ class Good extends Base
             $platform = Db::name("platform")->where(["id"=>$value['platform_code']])->find();
             $value['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name']:"";
             $value['platform_code_en'] = isset($platform['platform_code_en']) ? $platform['platform_code_en']:"";
-            $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
-            $value['supplier_name'] = isset($supplier['name']) ? $supplier['name']:"";
+//            $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
+//            $value['supplier_name'] = isset($supplier['name']) ? $supplier['name']:"";
             $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
             $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
             $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();

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

@@ -13,17 +13,20 @@ class GoodOfflineLog extends Base
     public function getList()
     {
 
-        $param = $this->request->only(['start_date' => '', 'end_date' => '', 'creater' => '', 'page' => 1, 'size' => 15], 'post', 'trim');
+        $param = $this->request->only(['start_date' => '', "spuCode"=>'',"good_name"=>'','end_date' => '', 'creater' => '',
+         'page' => 1,'size' => 15], 'post', 'trim');
 
         $where = [];
         if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['addtime', 'between', [$param['start_date'], $param['end_date']]];
         if ($param['creater'] != '') $where[] = ['creater', 'like', '%' . $param['creater'] . '%'];
+		if ($param['spuCode'] != '') $where[] = ['spuCode', 'like', '%' . $param['spuCode'] . '%'];
+        if ($param['good_name'] != '') $where[] = ['good_name', 'like', '%' . $param['good_name'] . '%'];
         $role = $this->checkDataShare();
         if (!empty($role[DataGroupModel::$type_全部])) $where[] = ["createrid", "in", $role[DataGroupModel::$type_全部]];
 
 
-        $count = Db::name('good_offline_log')->where($where)->count('id');
 
+        $count = Db::name('good_offline_log')->where($where)->count('id');
         $list = Db::name('good_offline_log')
             ->field('id,spuCode,good_name,creater,addtime,createrid')
             ->where($where)

+ 279 - 156
app/admin/controller/Goodup.php

@@ -9,6 +9,8 @@ use app\admin\model\ProcessOrder;
 use app\youzan\model\PlatformYouzan;
 use think\App;
 use think\Exception;
+use think\facade\Cache;
+use think\facade\Config;
 use think\facade\Db;
 use think\facade\Validate;
 
@@ -139,7 +141,9 @@ class Goodup extends Base
         $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
         if ($company_name !== "") $where[] = ["gb.createrid", 'in', get_company_item_user_by_name($company_name)];
 
-        $count = Db::name('good_basic')->alias('gb')->where($where)->count();
+        $count = Db::name('good_basic')->alias('gb')->where($where)->where(function ($Query)use($wheror){
+			return $Query->whereOr($wheror);
+        })->count();
         $total = ceil($count / $size);
         $page = $page >= $total ? $total : $page;
         $list = Db::name('good_basic')
@@ -147,7 +151,9 @@ class Goodup extends Base
             ->field('gb.*,u.itemid')
             ->leftJoin("depart_user u", "u.uid=gb.chargerid AND u.is_del=0")
             ->where($where)
-            ->page($page,$size)
+            ->where(function ($Query)use($wheror){
+			return $Query->whereOr($wheror);
+                })->page($page,$size)
             ->order("addtime desc")
             ->select()
             ->toArray();
@@ -212,8 +218,7 @@ class Goodup extends Base
         if($unit==''){
             return error_show(1004,"商品单位不能为空");
         }
-        $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type'])
-            :"";
+        $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type']) :"";
         if($good_type===''){
             return error_show(1004,"参数good_type不能为空");
         }
@@ -241,6 +246,8 @@ class Goodup extends Base
         if($supplierNo==''){
             return error_show(1004,"参数supplierNo不能为空");
         }
+        $supplier =Db::name("supplier")->where(["code"=>$supplierNo])->findOrEmpty();
+        if(empty($supplier)) return error_show(1004,"供应商信息未找到");
         $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size']):"";
         if($good_size==''){
             return error_show(1004,"参数good_size不能为空");
@@ -377,12 +384,12 @@ class Goodup extends Base
         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'] : "";
+//        $user =GetUserInfo($token);
+//        if(empty($user)||$user['code']!=0){
+//            return error_show(1002,"创建人数据不存在");
+//        }
+        $createrid= $this->uid;
+        $creater= $this->uname;
         $spucode=makeNo("SKU");
         Db::startTrans();
         try {
@@ -449,8 +456,8 @@ class Goodup extends Base
                 "addtime"=>date("Y-m-d H:i:s"),
                 "updatetime"=>date("Y-m-d H:i:s"),
                 'is_support_barter'=>$is_support_barter,
-                'chargerid'=>$createrid,
-                'charger'=>$creater,//负责人跟创建人一致
+                'chargerid'=>$supplier['personid']??$createrid,
+                'charger'=>$supplier['person']??$creater,//负责人跟创建人一致
             ];
             $in = Db::name("good_basic")->insertGetId($data);
             if($in){
@@ -495,8 +502,7 @@ class Goodup extends Base
                             //$lemp['nake_total'] = $noble_weight * $gold['price'] + $value['cost_fee'] * $noble_weight + $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
                             //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用
                             //成本总计启用实时金价时,采用供应商实时金价
-                            $lemp['nake_total'] = $noble_weight *$gold['price'] + $value['cost_fee'] * $noble_weight +
-                            $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
+                            $lemp['nake_total'] = $noble_weight *$gold['price'] + $value['cost_fee'] * $noble_weight + $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
 
                         }else{
                             $lemp['nake_total'] =$value['nake_fee']+$value['delivery_fee']+$value['cert_fee']+$value['mark_fee']+$value['package_fee']+$value['other_fee'];
@@ -516,19 +522,21 @@ class Goodup extends Base
                 }
 
                 //修改状态,添加待办
-                ActionLog::logAdd($this->post['token'], [
+                ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
                     "order_code" =>$spucode,//咨询单详情编号
                     "status" => 0,//这里的status是之前的值
                     "action_remark" => '',//备注
                     "action_type" => "create"//新建create,编辑edit,更改状态status
                 ], "SPCB", 0,$data);
 
-                        ProcessOrder::AddProcess($this->post['token'], [
-                            "order_type" => 'SPCB',
-                            "order_code" => $spucode,//咨询单详情编号
-                            "order_id" => $in,
-                            "order_status" =>0,"before_status"=>0
-                        ]);
+                ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
+                    "order_type" => 'SPCB',
+                    "order_code" => $spucode,//咨询单详情编号
+                    "order_id" => $in,
+                    "order_status" => 0,
+                    "before_status" => 0,
+                    'holder_id'=>$data['createrid'],
+                ]);
                     Db::commit();
                     return app_show(0,"创建成功",["spuCode"=>$spucode]);
 
@@ -551,8 +559,7 @@ class Goodup extends Base
         if($data==false){
             return error_show(1004,"未找到商品数据");
         }
-        $is_down = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->where("exam_status","<>",8)
-            ->find();
+        $is_down = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->where("exam_status","<>",8)->find();
         if($is_down!=false){
             return error_show(1004,"存在未下线商品数据");
         }
@@ -572,8 +579,7 @@ class Goodup extends Base
         if($unit==''){
             return error_show(1004,"商品单位不能为空");
         }
-        $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type'])
-            :"";
+        $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type']) :"";
         if($good_type===''){
             return error_show(1004,"参数good_type不能为空");
         }
@@ -606,13 +612,14 @@ class Goodup extends Base
         if($supplierNo==''){
             return error_show(1004,"参数supplierNo不能为空");
         }
-        $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size'])
-            :"";
+        $supplier =Db::name("supplier")->field('id,personid,person')->where(["code"=>$supplierNo])->findOrEmpty();
+        if(empty($supplier)) return error_show(1004,"供应商信息未找到");
+
+        $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size']) :"";
         if($good_size==''){
             return error_show(1004,"参数good_size不能为空");
         }
-        $company_id = isset($this->post['company_id'])&&$this->post['company_id']!=""? trim($this->post['company_id'])
-            :"";
+        $company_id = isset($this->post['company_id'])&&$this->post['company_id']!=""? trim($this->post['company_id']) :"";
         if($company_id==''){
             return error_show(1004,"参数company_id不能为空");
         }
@@ -675,8 +682,7 @@ class Goodup extends Base
         if($delivery_day===""){
             return error_show(1004,"参数delivery_day不能为空");
         }
-        $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time'])
-            :"0";
+        $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time']) :"0";
 //        if($lead_time===""){
 //            return error_show(1004,"参数lead_time不能为空");
 //        }
@@ -745,12 +751,14 @@ class Goodup extends Base
                 'is_stock'=>$is_stock,
                 "config"=>$config,
                 "other_config"=>$other_config,
-                "good_img"=>$good_img,
-                 "stock_moq"=>$stock_moq,
+                "good_img" => $good_img,
+                "stock_moq" => $stock_moq,
                 "good_thumb_img"=>$good_thumb_img,
                 "good_info_img"=>$good_info_img,
                 "status"=>$count>0?2:1,
-                "updatetime"=>date("Y-m-d H:i:s")
+                "updatetime" => date("Y-m-d H:i:s"),
+                'chargerid' => $supplier['personid'] ?? $this->uid,
+                'charger' => $supplier['person'] ?? $this->uname,//负责人跟创建人一致
             ];
             $field = array_diff_assoc($temp,$data);
             $temp['field_change'] =empty($field)?"":json_encode(array_keys($field));
@@ -778,18 +786,20 @@ class Goodup extends Base
                     }
                 }
                 //修改状态,添加待办
-                ActionLog::logAdd($this->post['token'], [
+                ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
                     "order_code" =>$supcode,//咨询单详情编号
                     "status" =>  $data['status'],//这里的status是之前的值
                     "action_remark" => '',//备注
                     "action_type" => "edit"//新建create,编辑edit,更改状态status
                 ], "SPCB",$temp['status'] ,$data);
 
-                ProcessOrder::AddProcess($this->post['token'], [
+                ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
                     "order_type" => 'SPCB',
                     "order_code" => $supcode,//咨询单详情编号
                     "order_id" => $data['id'],
-                    "order_status" =>$temp['status'],"before_status"=>$data['status']
+                    "order_status" =>$temp['status'],
+                    "before_status"=>$data['status'],
+                    'holder_id'=>$data['createrid'],
                 ]);
                 Db::commit();
                 return app_show(0,"更新成功");
@@ -883,7 +893,9 @@ class Goodup extends Base
                     "order_type" => 'SPCB',
                     "order_code" => $supcode,//咨询单详情编号
                     "order_id" => $datas['id'],
-                    "order_status" =>$data['status'],"before_status"=>$datas['status']
+                    "order_status" =>$data['status'],
+                    "before_status"=>$datas['status'],
+                    'holder_id'=>$datas['createrid'],
                 ]);
 //                $online =  Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
 //                if($online){
@@ -927,13 +939,11 @@ class Goodup extends Base
                         $top_cat_id = made($datas['cat_id']);//获取所有分类
                         $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
                         if($is_gold_price==1 && $top_cat_id==6){
-                            //$gold =Db::name("gold_price1")->where(["type"=>$noble_metal,"status"=>1,"is_del"=>0])
-//                            ->order("addtime desc")->find();
+                            $gold =Db::name("gold_price1")->where(["type"=>$noble_metal,"status"=>1,"is_del"=>0])->order("addtime desc")->find();
                             //$lemp['nake_total'] =$noble_weight*$gold['price'] + $value['cost_fee']*$noble_weight+$value['mark_fee']+$value['package_fee']+$value['cert_fee']+$value['nake_fee']+$value['delivery_fee']+$value['other_fee'];
                             //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用
                             //成本总计启用实时金价时,采用供应商实时金价
-                            $lemp['nake_total'] = $noble_weight * $cgd_gold_price+ $value['cost_fee'] * $noble_weight +
-                                $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
+                            $lemp['nake_total'] = $noble_weight * $gold['price']+ $value['cost_fee'] * $noble_weight + $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
                         }else{
                             $lemp['nake_total'] =$value['nake_fee']+$value['delivery_fee']+$value['cert_fee']+$value['mark_fee']+$value['package_fee']+$value['other_fee'];
                         }
@@ -1014,7 +1024,9 @@ class Goodup extends Base
                         "order_type" => 'SPSX',
                         "order_code" =>$online['skuCode'],//咨询单详情编号
                         "order_id" => $online['id'],
-                        "order_status" => 2,"before_status"=>$online['exam_status']
+                        "order_status" => 2,
+                        "before_status"=>$online['exam_status'],
+                        'holder_id' => $online['createrid'],
                     ]);
                 }
             }
@@ -1043,7 +1055,9 @@ class Goodup extends Base
                     "order_type" => 'SPCB',
                     "order_code" => $supcode,//咨询单详情编号
                     "order_id" => $data['id'],
-                    "order_status" =>$data['status'],"before_status"=>$old_status
+                    "order_status" =>$data['status'],
+                    "before_status"=>$old_status,
+                    'holder_id'=>$data['createrid'],
                 ]);
                 $data=[
                     "code"=>$supcode,
@@ -1338,7 +1352,9 @@ class Goodup extends Base
                         "order_type" => 'SPSX',
                         "order_code" =>$skuCode,//咨询单详情编号
                         "order_id" => $create,
-                        "order_status" =>$tmp['exam_status'],"before_status"=>$tmp['exam_status']
+                        "order_status" =>$tmp['exam_status'],
+                        "before_status"=>$tmp['exam_status'],
+                        'holder_id' => $tmp['createrid'],
                     ]);
                     $iso = Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
                     if($iso==false){
@@ -1553,20 +1569,47 @@ class Goodup extends Base
                         //消息表
                         Db::name('order_msg')->insertAll($insert_order_msg_data);
 
-                    } else {
-                        ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
-                            "order_code" => $skuCode,//编号
-                            "status" => $bifore,
-                            "action_remark" => '',//备注
-                            "action_type" => "status"//新建create,编辑edit,更改状态status
-                        ], "SPSX", $exam_status, $platform);
+                    }
+                    ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
+                        "order_code" => $skuCode,//编号
+                        "status" => $bifore,
+                        "action_remark" => '',//备注
+                        "action_type" => "status"//新建create,编辑edit,更改状态status
+                    ], "SPSX", $exam_status, $platform);
 
-                        ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
-                            "order_type" => 'SPSX',
-                            "order_code" => $skuCode,//咨询单详情编号
-                            "order_id" => $platform['id'],
-                            "order_status" => $exam_status, "before_status" => $bifore
-                        ]);
+                    ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
+                        "order_type" => 'SPSX',
+                        "order_code" => $skuCode,//咨询单详情编号
+                        "order_id" => $platform['id'],
+                        "order_status" => $exam_status,
+                        "before_status" => $bifore,
+                        'holder_id' => $platform['createrid'],
+                    ]);
+
+                    //商品上线的话,将数据包塞入到队列中
+                    if ($exam_status == 6) {
+                        //将上线成功数据塞入到队列中
+
+                        $good_info = Db::name('good_basic')
+                            ->field('id,good_name,supplierNo')
+                            ->where(['is_del' => 0, 'spuCode' => $platform['spuCode']])
+                            ->findOrEmpty();
+                        if ($good_info) {
+                            $push_data = json_encode([
+                                'supplierNo' => $good_info['supplierNo'],
+                                'type' => 2,//1销售订单(采销的采购单),2上线结果
+                                'data' => [
+                                    'spuCode' => $platform['spuCode'],
+                                    'skuCode' => $platform['skuCode'],
+                                    'good_name' => $good_info['good_name'],
+                                    'platform_id' => $platform['platform_code'],
+                                    'platform_name' => Db::name('platform')->where(['id' => $platform['platform_code']])->value('platform_name', ''),
+                                    'plat_code' => $platform['plat_code'],
+                                    'online_time' => $platform['online_time'],
+                                ],
+                            ], JSON_UNESCAPED_UNICODE);
+                            Cache::store("redis")->handler()->lPush(Config::get('app.abutment_queue'), $push_data);
+                        }
                     }
 
                     Db::commit();
@@ -1658,7 +1701,9 @@ class Goodup extends Base
                     "order_type" => 'SPSX',
                     "order_code" =>$platform['skuCode'],//咨询单详情编号
                     "order_id" => $platform['id'],
-                    "order_status" => $platform['exam_status'],"before_status"=>$bifore
+                    "order_status" => $platform['exam_status'],
+                    "before_status"=>$bifore,
+                    'holder_id' => $platform['createrid'],
                 ]);
                 $proof=[
                     'spuCode'=>$platform['spuCode'],
@@ -1771,7 +1816,9 @@ class Goodup extends Base
                     "order_type" => 'SPSX',
                     "order_code" =>$platform['skuCode'],//咨询单详情编号
                     "order_id" => $platform['id'],
-                    "order_status" => $platform['exam_status'],"before_status"=>$bifore
+                    "order_status" => $platform['exam_status'],
+                    "before_status"=>$bifore,
+                    'holder_id' => $platform['createrid'],
                 ]);
                 $data=[
                     "code"=>$platform['skuCode'],
@@ -1825,12 +1872,12 @@ class Goodup extends Base
         if($token==''){
             return error_show(105,"参数token不能为空");
         }
-        $user =GetUserInfo($token);
-        if(empty($user)||$user['code']!=0){
-            return error_show(102,"用户数据不存在");
-        }
-        $createrid= isset($user["data"]['id']) ?  $user["data"]['id'] : "";
-        $creater= isset($user["data"]['nickname']) ?  $user["data"]['nickname'] : "";
+//        $user =GetUserInfo($token);
+//        if(empty($user)||$user['code']!=0){
+//            return error_show(102,"用户数据不存在");
+//        }
+        $createrid= $this->uid;
+        $creater= $this->uname;
         $nake = Db::name("good_nake")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
         $ladd=[];
         $newCode =makeNo("SKU");
@@ -1878,7 +1925,7 @@ class Goodup extends Base
             $data['status']=7;
             $data['addtime']=date("Y-m-d H:i:s");
             $data['updatetime']=date("Y-m-d H:i:s");
-            $cre = Db::name("good_basic")->insert($data);
+            $cre = Db::name("good_basic")->insertGetId($data);
             if($cre){
                 //修改状态,添加待办
                 ActionLog::logAdd($this->post['token'], [
@@ -1891,8 +1938,10 @@ class Goodup extends Base
                 ProcessOrder::AddProcess($this->post['token'], [
                     "order_type" => 'SPCB',
                     "order_code" =>$newCode,//咨询单详情编号
-                    "order_id" => Db::name("good_basic")->getLastInsID(),
-                    "order_status" =>7,"before_status"=>0
+                    "order_id" => $cre,
+                    "order_status" =>7,
+                    "before_status"=>0,
+                    'holder_id'=>$data['createrid'],
                 ]);
                 if(!empty($ladd)){
                     $na = Db::name("good_nake")->insertAll($ladd);
@@ -1956,8 +2005,7 @@ class Goodup extends Base
         if($unit==''){
             return error_show(1004,"商品单位不能为空");
         }
-        $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type'])
-            :"";
+        $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type']) :"";
         if($good_type===''){
             return error_show(1004,"参数good_type不能为空");
         }
@@ -1990,13 +2038,14 @@ class Goodup extends Base
         if($supplierNo==''){
             return error_show(1004,"参数supplierNo不能为空");
         }
-        $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size'])
-            :"";
+        $supplier = Db::name("supplier")->field('id,personid,person')->where(["code" => $supplierNo])->findOrEmpty();
+        if (empty($supplier)) return error_show(1004, "供应商信息未找到");
+
+        $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size']) :"";
         if($good_size==''){
             return error_show(1004,"参数good_size不能为空");
         }
-        $company_id = isset($this->post['companyNo'])&&$this->post['companyNo']!=""? trim($this->post['companyNo'])
-            :"";
+        $company_id = isset($this->post['companyNo'])&&$this->post['companyNo']!=""? trim($this->post['companyNo']) :"";
         if($company_id==''){
             return error_show(1004,"参数companyNo不能为空");
         }
@@ -2174,7 +2223,9 @@ class Goodup extends Base
                 "stock_moq"=>$stock_moq,
                 "status"=>"0",
                 "updatetime"=>date("Y-m-d H:i:s"),
-                'is_support_barter'=>$is_support_barter
+                'is_support_barter'=>$is_support_barter,
+                'chargerid' => $supplier['personid'] ?? $this->uid,
+                'charger' => $supplier['person'] ?? $this->uname,
             ];
             $field = array_diff_assoc($temp,$data);
             $temp['field_change'] =empty($field)?"":json_encode(array_keys($field));
@@ -2196,7 +2247,9 @@ class Goodup extends Base
                     "order_type" => 'SPCB',
                     "order_code" =>$supcode,//咨询单详情编号
                     "order_id" => $data['id'],
-                    "order_status" =>0,"before_status"=>0
+                    "order_status" =>0,
+                    "before_status"=>0,
+                    'holder_id'=>$data['createrid'],
                 ]);
                 if($speclist!=="" && !empty($speclist)){
                     foreach ($speclist as $value){
@@ -2236,13 +2289,12 @@ class Goodup extends Base
                         $lemp['other_fee'] = $value['other_fee'];
 
                         if ($is_gold_price == 1 && $top_cat_id == 6) {
-                           // $gold =Db::name("gold_price1")->where(["type"=>$noble_metal,"status"=>1,"is_del"=>0])
-                           // ->order("addtime desc")->find();
+                            $gold =Db::name("gold_price1")->where(["type"=>$noble_metal,"status"=>1,"is_del"=>0])->order("addtime desc")->find();
 
                             //$lemp['nake_total'] =$noble_weight*$gold['price'] + $value['cost_fee']*$noble_weight+$value['mark_fee']+$value['package_fee']+$value['cert_fee']+$value['nake_fee']+$value['delivery_fee']+$value['other_fee'];
                             //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用
                             //成本总计启用实时金价时,采用供应商实时金价
-                            $lemp['nake_total'] =$noble_weight *$cgd_gold_price+ $value['cost_fee'] * $noble_weight +
+                            $lemp['nake_total'] =$noble_weight *$gold['price']+ $value['cost_fee'] * $noble_weight +
                                 $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
                         }else{
                             $lemp['nake_total'] =$value['nake_fee']+$value['delivery_fee']+$value['cert_fee']+$value['mark_fee']+$value['package_fee']+$value['other_fee'];
@@ -2632,6 +2684,7 @@ class Goodup extends Base
                         "order_id" => isset($value['id']) ? $value['id'] : 0,
                         "order_status" => 8,//待产品审核
                         "before_status" => 0,//待产品审核
+                        'holder_id'=>$value['createrid'],
                     ]);
                 }
                 foreach ($data as $value) {
@@ -2648,7 +2701,8 @@ class Goodup extends Base
                         "order_code" =>$value['skuCode'],//
                         "order_id" => isset($value['id']) ? $value['id'] : 0,
                         "order_status" =>$value['exam_status'],//待产品审核
-                        "before_status" => 0
+                        "before_status" => 0,
+                        'holder_id' => $value['createrid'],
                     ]);
                 }
                 Db::commit();
@@ -2682,7 +2736,7 @@ class Goodup extends Base
         try {
 
             $rs = Db::name("good_platform")
-                ->field('id,spuCode,skuCode,exam_status')
+                ->field('id,spuCode,skuCode,exam_status,createrid')
                 ->where(['skuCode' => $param['skuCode'], 'is_del' => 0])
                 ->where('exam_status', '<>', 6)//exam_status==6上线成功
                 ->find();
@@ -2727,7 +2781,9 @@ class Goodup extends Base
                 "order_type" => 'SPSX',
                 "order_code" => $param['skuCode'],//咨询单详情编号
                 "order_id" => $rs['id'],
-                "order_status" => $exam_status, "before_status" => $rs['exam_status']
+                "order_status" => $exam_status,
+                "before_status" => $rs['exam_status'],
+                'holder_id' => $rs['createrid'],
             ]);
 
             Db::commit();
@@ -2757,92 +2813,159 @@ class Goodup extends Base
         Db::startTrans();
         try {
 
+            $good_name = Db::name("good_basic")
+                ->where(['is_del' => 0, 'spuCode' => $param['spuCode']])
+                ->value('good_name', '');
+
             $skuCodeS = Db::name("good_platform")
-                ->where(['spuCode' => $param['spuCode'], 'is_del' => 0])//exam_status 7审核失败,8已下线
+                ->where(['spuCode' => $param['spuCode'], 'is_del' => 0, 'exam_status' => 6])//exam_status 7审核失败,8已下线
                 ->column('exam_status,skuCode', 'skuCode');
-            if (empty($skuCodeS)) throw new \Exception('该商品未在任何平台申请上线');
-
-            //商品平台
-            Db::name("good_platform")
-                ->where(['spuCode' => $param['spuCode'], 'is_del' => 0])
-                ->save([
-                    'exam_status' => 8,
-                    'updatetime' => date('Y-m-d H:i:s'),
-                ]);
 
-            //商品下线记录
-            $good_offline_log_id = Db::name("good_offline_log")->insertGetId([
-                'spuCode' => $param['spuCode'],
-                'skuCodes' => implode(',', array_keys($skuCodeS)),
-                'good_name' => Db::name("good_basic")->where('spuCode', $param['spuCode'])->value('good_name', ''),
-                'offline_reason' => $param['offline_reason'],
-                'offline_remark' => $param['offline_remark'],
-                'createrid' => $createrid,
-                'creater' => $creater,
-                'addtime' => date('Y-m-d H:i:s'),
-            ]);
+            if ($skuCodeS) {
 
-            //根据权限查询应该接收商品下线通知的人员
-            $all_uid_name = Db::name('role_action')
-                ->whereFindInSet('action_conllect', '877')//数据写死的,要注意各个环境数据是否一致
-                ->field('role_id')
-                ->buildSql();
-
-            $all_user = Db::name('user_role')
-                ->alias('ur')
-                ->where('ur.roleid IN ' . $all_uid_name)
-                ->leftJoin('depart_user du', 'du.uid = ur.uid AND du.is_del=0')
-                ->column('ur.uid,du.nickName');
-
-            $insert_good_exam_data = $insert_order_msg_data = [];
-            foreach ($skuCodeS as $skuCode => $value) {
-                $insert_good_exam_data[] = [
-                    'code' => $skuCode,
-                    'exam_status' => 8,
-                    'type' => 2,
-                    'exam_id' => $createrid,
-                    'exam_name' => $creater,
-                    'exam_remark' => '',
-                    'addtime' => date('Y-m-d H:i:s')
-                ];
+//            if (empty($skuCodeS)) throw new \Exception('该商品未在任何平台申请上线');
 
-                ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
-                    "order_code" => $skuCode,//编号
-                    "status" => 6,
-                    "action_remark" => '',//备注
-                    "action_type" => "status"//新建create,编辑edit,更改状态status
-                ], "GOL", 8, $param);
+                //商品平台
+                Db::name("good_platform")
+                    ->where(['spuCode' => $param['spuCode'], 'is_del' => 0, 'exam_status' => 6])
+                    ->save([
+                        'exam_status' => 8,
+                        'updatetime' => date('Y-m-d H:i:s'),
+                    ]);
 
-                ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
-                    "order_type" => 'GOL',
-                    "order_code" => $skuCode,
-                    "order_id" => $good_offline_log_id,
-                    "order_status" => 8, "before_status" => 6
+                //商品下线记录
+                $good_offline_log_id = Db::name("good_offline_log")->insertGetId([
+                    'spuCode' => $param['spuCode'],
+                    'skuCodes' => implode(',', array_keys($skuCodeS)),
+                    'good_name' => $good_name,
+                    'offline_reason' => $param['offline_reason'],
+                    'offline_remark' => $param['offline_remark'],
+                    'createrid' => $createrid,
+                    'creater' => $creater,
+                    'addtime' => date('Y-m-d H:i:s'),
                 ]);
 
-                foreach ($all_user as $itemitem) {
-                    $insert_order_msg_data[] = [
-                        'content' => '商品下线:' . $skuCode . '由' . $creater . '操作下线',
-                        'orderCode' => $skuCode,
-                        'order_type' => 'GOL',
-                        'order_status' => 8,
-                        'order_id' => $good_offline_log_id,
-                        'uid' => $itemitem['uid'],
-                        'uname' => empty($itemitem['nickName']) ? '' : $itemitem['nickName'],
-                        'apply_id' => $createrid,
-                        'apply_name' => $creater,
-                        'is_read' => 0,
-                        'addtime' => date('Y-m-d H:i:s'),
-                        'updatetime' => date('Y-m-d H:i:s'),
+                //根据权限查询应该接收商品下线通知的人员
+                $all_uid_name = Db::name('role_action')
+                    ->whereFindInSet('action_conllect', '877')//数据写死的,要注意各个环境数据是否一致
+                    ->field('role_id')
+                    ->buildSql();
+
+                $all_user = Db::name('user_role')
+                    ->alias('ur')
+                    ->where('ur.roleid IN ' . $all_uid_name)
+                    ->leftJoin('depart_user du', 'du.uid = ur.uid AND du.is_del=0')
+                    ->column('ur.uid,du.nickName');
+
+                $insert_good_exam_data = $insert_order_msg_data = [];
+                foreach ($skuCodeS as $skuCode => $value) {
+                    $insert_good_exam_data[] = [
+                        'code' => $skuCode,
+                        'exam_status' => 8,
+                        'type' => 2,
+                        'exam_id' => $createrid,
+                        'exam_name' => $creater,
+                        'exam_remark' => '',
+                        'addtime' => date('Y-m-d H:i:s')
                     ];
+
+                    ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
+                        "order_code" => $skuCode,//编号
+                        "status" => 6,
+                        "action_remark" => '',//备注
+                        "action_type" => "status"//新建create,编辑edit,更改状态status
+                    ], "GOL", 8, $param);
+
+                    ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
+                        "order_type" => 'GOL',
+                        "order_code" => $skuCode,
+                        "order_id" => $good_offline_log_id,
+                        "order_status" => 8,
+                        "before_status" => $value['exam_status']
+                    ]);
+
+                    foreach ($all_user as $itemitem) {
+                        $insert_order_msg_data[] = [
+                            'content' => '商品下线:' . $skuCode . '由' . $creater . '操作下线',
+                            'orderCode' => $skuCode,
+                            'order_type' => 'GOL',
+                            'order_status' => 8,
+                            'order_id' => $good_offline_log_id,
+                            'uid' => $itemitem['uid'],
+                            'uname' => empty($itemitem['nickName']) ? '' : $itemitem['nickName'],
+                            'apply_id' => $createrid,
+                            'apply_name' => $creater,
+                            'is_read' => 0,
+                            'addtime' => date('Y-m-d H:i:s'),
+                            'updatetime' => date('Y-m-d H:i:s'),
+                        ];
+                    }
                 }
+
+                //变动记录
+                Db::name("good_exam")->insertAll($insert_good_exam_data);
+
+                //消息表
+                Db::name('order_msg')->insertAll($insert_order_msg_data);
             }
 
-            //变动记录
-            Db::name("good_exam")->insertAll($insert_good_exam_data);
+            //处理有赞平台
+
+            $rs = Db::name('platform_youzan')
+                ->field('id,spuCode,skuCode,exam_status,platform_id')
+                ->where(['spuCode' => $param['spuCode'], 'is_del' => PlatformYouzan::$del_normal, 'exam_status' => PlatformYouzan::$exam_status_6])
+                ->select()
+                ->toArray();
+
+            if ($rs) {
+
+                $insert_good_offline_log_youzan_data = [];
+
+                foreach ($rs as $value) {
+
+                    $curl_data = [
+                        'item_no' => $value['skuCode'],//商品自定义编码 skuCode
+                        'uid' => $createrid,
+                        'nickname' => $creater,
+                    ];
 
-            //消息表
-            Db::name('order_msg')->insertAll($insert_order_msg_data);
+                    //已上线的要调用有赞接口下线
+                    //调有赞项目的接口,从有赞平台下线该商品
+                    $host = config('app.yz_domain');
+                    $response = curl_request($host . 'api/yz_goodup_offline', $curl_data);
+
+                    $response = json_decode($response, true);
+
+                    if ($response['code'] != 0) throw new Exception($response['message']);
+
+                    $insert_good_offline_log_youzan_data[] = [
+                        'spuCode' => $value['spuCode'],
+                        'skuCodes' => $value['skuCode'],
+                        'good_name' => $good_name,
+                        'offline_reason' => $param['offline_reason'],
+                        'offline_remark' => $param['offline_remark'],
+                        'createrid' => $createrid,
+                        'creater' => $creater,
+                        'addtime' => date('Y-m-d H:i:s')
+                    ];
+
+                }
+
+                Db::name('platform_youzan')
+                    ->where(['spuCode' => $param['spuCode'], 'is_del' => PlatformYouzan::$del_normal, 'exam_status' => PlatformYouzan::$exam_status_6])
+                    ->update([
+                        'exam_status' => PlatformYouzan::$exam_status_8,
+                        'offline_reason_id' => $param['offline_reason'],
+                        'offline_remark' => $param['offline_remark'],
+                        'updaterid' => $createrid,
+                        'updater' => $creater,
+                        'updatetime' => date('Y-m-d H:i:s')
+                    ]);
+
+                //下线记录表增加记录
+                if ($insert_good_offline_log_youzan_data) Db::name('good_offline_log_youzan')->insertAll($insert_good_offline_log_youzan_data);
+
+            }
 
             Db::commit();
             return app_show(0, "下线成功");

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

@@ -31,7 +31,7 @@ class Group extends Base
         $condition=['is_del'=>0];
         $count = Db::name("role_group")->where($condition)->count();
         $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
-        $list =  Db::name("role_group")->where($condition)->page($page,$size)->select();
+        $list =  Db::name("role_group")->where($condition)->page($page,$size)->order('addtime','desc')->select()->toArray();
         $data =[];
         foreach ($list as $key=>$val) {
             $userlist = [];

+ 265 - 102
app/admin/controller/Orderback.php

@@ -6,7 +6,7 @@ namespace app\admin\controller;
 use app\admin\model\ActionLog;
 use app\admin\model\DataGroup as DataGroupModel;
 use app\admin\model\GoodLog;
-use app\admin\model\ProcessOrder;
+use app\admin\model\GoodStockInfo;use app\admin\model\ProcessOrder;
 use think\App;
 use think\Exception;
 use think\facade\Db;
@@ -235,9 +235,17 @@ class Orderback extends Base
           $up=Db::name("order_back")->save($info);
           if($up){
               $stn = ["order_code"=>$info['thNo'],"status"=>$str,"action_remark"=>'',"action_type"=>"edit"];
-              ActionLog::logAdd($this->post['token'],$stn,"CKTHD",$info['status'],$info);
-              $process=["order_code"=>$info['thNo'],"order_id"=>$info['id'],"order_status"=>$info['status'],'order_type'=>"CKTHD","before_status"=>$str];
-              ProcessOrder::AddProcess($this->post['token'],$process);
+              ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname],$stn,"CKTHD",$info['status'],$info);
+
+              if($info['status'] == 2) $roleid = [10, 31, 41];//特殊处理,写入到10采购负责人、31库管人员、41库管-张凯旋这三个角色下的所有人
+              else $roleid = [31,41];//特殊处理,写入到31库管人员、41库管-张凯旋这三个角色下的所有人
+
+              $handle_user_list = Db::name('user_role')
+                  ->where('is_del', 0)
+                  ->whereIn('roleid', $roleid)
+                  ->column('uid');
+              $process = ["order_code" => $info['thNo'], "order_id" => $info['id'], "order_status" => $info['status'], 'order_type' => "CKTHD", "before_status" => $str, 'handle_user_list' => implode(',', $handle_user_list)];
+              ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $process);
               if(empty($errorlist)){
                   Db::commit();
                   return app_show(0,'更新成功');
@@ -288,9 +296,16 @@ class Orderback extends Base
           $up=Db::name("order_back")->save($info);
           if($up){
               $stn = ["order_code"=>$thNo,"status"=>$temp,"action_remark"=>'',"action_type"=>"edit"];
-              ActionLog::logAdd($this->post['token'],$stn,"CKTHD",$info['status'],$stn);
-              $process=["order_code"=>$info['thNo'],"order_id"=>$info['id'],"order_status"=>3,"order_type"=>"CKTHD","before_status"=>$temp];
-              ProcessOrder::AddProcess($this->post['token'],$process);
+              ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $stn, "CKTHD", $info['status'], $stn);
+
+              //特殊处理,写入到31库管人员、41库管-张凯旋这三个角色下的所有人
+              $handle_user_list = Db::name('user_role')
+                  ->where('is_del', 0)
+                  ->whereIn('roleid', [31, 41])
+                  ->column('uid');
+              $process = ["order_code" => $info['thNo'], "order_id" => $info['id'], "order_status" => 3, "order_type" => "CKTHD", "before_status" => $temp, 'handle_user_list' => implode(',', $handle_user_list)];
+              ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $process);
+
               if(empty($errorlist)){
                   $up =Db::name("order_backinfo")->where(["thNo"=>$thNo,"is_del"=>0])->save(["status"=>1,
                       "updatetime"=>date("Y-m-d H:i:s")]);
@@ -381,9 +396,22 @@ class Orderback extends Base
             $up=Db::name("order_back")->save($info);
             if($up){
                 $stn = ["order_code"=>$thNo,"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
-                ActionLog::logAdd($this->post['token'],$stn,"CKTHD",$info['status'],$this->post);
-                $process=["order_code"=>$info['thNo'],"order_id"=>$info['id'],"order_status"=>$status,"order_type"=>"CKTHD","before_status"=>$var];
-                ProcessOrder::AddProcess($this->post['token'],$process);
+                ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$stn,"CKTHD",$info['status'],$this->post);
+
+                if (in_array($status, [2, 3])) {
+
+                    if ($status == 2) $roleid = [10, 31, 41];//特殊处理,写入到10采购负责人、31库管人员、41库管-张凯旋这三个角色下的所有人
+                    else $roleid = [31, 41];//特殊处理,写入到、31库管人员、41库管-张凯旋这三个角色下的所有人
+
+                    $handle_user_list = Db::name('user_role')
+                        ->where('is_del', 0)
+                        ->whereIn('roleid', $roleid)
+                        ->column('uid');
+                    $process = ["order_code" => $info['thNo'], "order_id" => $info['id'], "order_status" => $status, "order_type" => "CKTHD", "before_status" => $var, 'handle_user_list' => implode(',', $handle_user_list)];
+
+                } else $process = ["order_code" => $info['thNo'], "order_id" => $info['id'], "order_status" => $status, "order_type" => "CKTHD", "before_status" => $var];
+
+                ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $process);
                 Db::commit();
                 return app_show(0,'更新成功');
             }
@@ -406,9 +434,7 @@ class Orderback extends Base
         $val->extend('checkRemark', function ($val, $rule, $data) {
             return $data['status'] == 4 ? true : (empty($val) ? '请填写备注' : true);
         });
-
         if (!$val->check($param)) return error_show(1004, $val->getError());
-//        $good =Db::name("good")
         Db::startTrans();
         try {
 
@@ -423,6 +449,17 @@ class Orderback extends Base
                 Db::rollback();
                 return error_show(1004,"未找到销售单数据");
             }
+            $spuCode= $info['good_code'];
+            if($sale['order_type']!=1){
+              if($sale['order_type']==3){
+		          $goon = Db::name("good_zixun")->where(["spuCode"=>$sale['good_code'],"is_del"=>0])->find();
+		          $isZx=1;
+		      }else {
+		          $goon = Db::name('good_basic')->where(['spuCode' => $sale['good_code']])->find();
+		          $isZx=2;
+		      }
+              $spuCode = $this->CheckGoodZx($goon,$isZx,$param['thNo']);
+            }
             $out =Db::name("order_out")->where(['outCode'=>$info['outCode']])->find();
             if($out==false){
                 Db::rollback();
@@ -433,15 +470,16 @@ class Orderback extends Base
                 Db::rollback();
                 return error_show(1004,"未找到售后单数据");
             }
-
+			$sabebn =Db::name("sale_info")->where([["orderCode",'=',$info['orderCode']],["num",">",0]])->select()->toArray();
             if($param['can_sell_num']!=0&& $param['can_sell_wsm']!=''){
-                    if($sale['is_stock']==1){ //库存品退回原仓库 备库单释放数量 采购单
-                        $param['can_sell_wsm'] = $out['wsm_code'];
-                    }
-                    $stock = Db::name("good_stock")->where(["spuCode"=>$info['good_code'],'wsm_code'=>$param['can_sell_wsm']])->find();
+//                    if($sale['is_stock']==1){ //库存品退回原仓库 备库单释放数量 采购单
+//                        $param['can_sell_wsm'] = $out['wsm_code'];
+//                    }
+                    $stock = Db::name("good_stock")->where(["spuCode"=>$spuCode,'wsm_code'=>$param['can_sell_wsm']])
+                    ->find();
                     if(empty($stock)) {
                         $stock=[
-                            "spuCode"=>$info['good_code'],
+                            "spuCode"=>$spuCode,
                             "wsm_code"=>$param['can_sell_wsm'],
                             "usable_stock"=>0,
                             "wait_out_stock"=>0,
@@ -457,14 +495,69 @@ class Orderback extends Base
                     if($st_up==false){
                         return error_show(1005,'可售商品入库失败');
                     }
-                $good_data=['good_log_code'=>$param['thNo'],"stock_id"=>isset($stock['id'])? $stock['id']:Db::name("good_stock")->getLastInsID(),"type"=>1,'stock'=>$param['can_sell_num'],"stock_name"=>"usable_stock"];
+                    $stockid = isset($stock['id']) ? $stock['id'] : Db::name("good_stock")->getLastInsID();
+
+                        if(!empty($sabebn)){
+                        	$total_num =$param['can_sell_num'];
+                        	foreach ($sabebn as $ve){
+                        		$tempnum=0;
+                        		if ($total_num==0) break;
+                        		if($total_num>=$ve['num']){
+                        			$tempnum = $ve['num'];
+                        			$total_num-=$ve['num'];
+                        			$ve['th_num']+=$ve['num'];
+                        			$ve['num']=0;
+                        		}else{
+                        		    $tempnum = $total_num;
+                        			$ve['num']-=$total_num;
+                        			$ve['th_num']+=$total_num;
+                        			$total_num=0;
+                        		}
+                        		$bnin=GoodStockInfo::ReturnAdd($stockid,$ve['bnCode'],$tempnum,$ve['stockid']);
+                        		if($bnin==false){
+                        			 Db::rollback();
+                                    return error_show(1005, '可售商品Bn库存数入库失败');
+                        		}
+								$up=Db::name("sale_info")->save($ve);
+                        		if($up==false){
+                        			 Db::rollback();
+                                    return error_show(1005, '可售商品Bn库存数入库失败');
+                        		}
+								$bnin=GoodStockInfo::ReturnBn($info['returnCode'],$ve['id'],$tempnum);
+                        		if($bnin==false){
+                        			 Db::rollback();
+                                    return error_show(1005, '可售商品Bn库存数入库失败');
+                        		}
+                        	}
+                        }else{
+                        	if($sale['order_type']==1){
+                        	 $ordernum = Db::name("order_num")->where(['orderCode' =>$info['orderCode']])->find();
+					        if ($ordernum == false) {
+					        	Db::rollback();
+					            return error_show(1005, '未找到关联采购单');
+					        }
+					         $cgd = Db::name("purchease_order")->where(["cgdNo" => $ordernum['cgdNo'], "is_del" => 0])->find();
+					        if ($cgd == false) {
+					        	Db::rollback();
+					            return error_show(1005, '未找到采购单数据');
+					        }
+					        $bn =makeNo("BN");
+					        $yp=GoodStockInfo::AddBn($stockid,$bn,$param['can_sell_num'],$cgd['good_price']);
+					        if($yp==false){
+					        	Db::rollback();
+								return error_show(1005, '商品批次退货入库失败');
+					        }
+                        	}
+                        }
+                $good_data=['good_log_code'=>$param['thNo'],"stock_id"=> $stockid,"type"=>1,'stock'=>$param['can_sell_num'],"stock_name"=>"usable_stock"];
                 GoodLog::LogAdd($this->post['token'],$good_data,'RKTHD');
              }
+
             if($param['defective_num']!=0&& $param['defective_wsm']!=''){
-                $defective = Db::name("good_stock")->where(["spuCode"=>$info['good_code'],'wsm_code'=>$param['defective_wsm']])->find();
+                $defective = Db::name("good_stock")->where(["spuCode"=>$spuCode,'wsm_code'=>$param['defective_wsm']])->find();
                 if(empty($defective)) {
                     $defective=[
-                        "spuCode"=>$info['good_code'],
+                        "spuCode"=>$spuCode,
                         "wsm_code"=>$param['defective_wsm'],
                         "usable_stock"=>0,
                         "wait_out_stock"=>0,
@@ -473,9 +566,9 @@ class Orderback extends Base
                         "addtime"=>date("Y-m-d H:i:s"),
                         "updatetime"=>date("Y-m-d H:i:s"),
                     ];
-                    $order = ["order_code"=>$info['good_code'],"status"=>1,"action_remark"=>'', "action_type"=>"create"];
+                    $order = ["order_code"=>$spuCode,"status"=>1,"action_remark"=>'', "action_type"=>"create"];
                 }else{
-                    $order = ["order_code"=>$info['good_code'],"status"=>1,"action_remark"=>'', "action_type"=>"edit"];
+                    $order = ["order_code"=>$spuCode,"status"=>1,"action_remark"=>'', "action_type"=>"edit"];
                 }
                 $defective['usable_stock']+=$param['defective_num'];
                 $defective['updatetime'] = date("Y-m-d H:i:s");
@@ -484,6 +577,60 @@ class Orderback extends Base
                     Db::rollback();
                     return error_show(1005,'次品商品入库失败');
                 }
+                $stockid = isset($defective['id']) ? $defective['id'] : Db::name("good_stock")->getLastInsID();
+                $sabebn =Db::name("sale_info")->where(["orderCode"=>$info['orderCode']])->select()->toArray();
+                 if(!empty($sabebn)){
+                        	$total_num =$param['defective_num'];
+                        	foreach ($sabebn as $ve){
+                        		$tempnum=0;
+                        		if ($total_num==0) break;
+                        		if($total_num>=$ve['num']){
+                        			$tempnum = $ve['num'];
+                        			$total_num-=$ve['num'];
+                        			$ve['th_num']+=$ve['num'];
+                        			$ve['num']=0;
+                        		}else{
+                        		    $tempnum = $total_num;
+                        			$ve['num']-=$total_num;
+                        			$ve['th_num']+=$total_num;
+                        			$total_num=0;
+                        		}
+                        	    $bnin=GoodStockInfo::ReturnAdd($stockid,$ve['bnCode'],$tempnum,$ve['stockid']);
+                        		if($bnin==false){
+                        			 Db::rollback();
+                                    return error_show(1005, '可售商品Bn库存数入库失败');
+                        		}
+								$up=Db::name("sale_info")->save($ve);
+                        		if($up==false){
+                        			 Db::rollback();
+                                    return error_show(1005, '可售商品Bn库存数入库失败');
+                        		}
+								$bnin=GoodStockInfo::ReturnBn($info['returnCode'],$ve['id'],$tempnum);
+                        		if($bnin==false){
+                        			 Db::rollback();
+                                    return error_show(1005, '可售商品Bn库存数入库失败');
+                        		}
+                        	}
+                        }else{
+	                        if($sale['order_type']==1){
+	                             $ordernum = Db::name("order_num")->where(['orderCode' =>$info['orderCode']])->find();
+						        if ($ordernum == false) {
+						            Db::rollback();
+						            return error_show(1005, '未找到关联采购单');
+						        }
+						         $cgd = Db::name("purchease_order")->where(["cgdNo" => $ordernum['cgdNo'], "is_del" => 0])->find();
+						        if ($cgd == false) {
+						            Db::rollback();
+						            return error_show(1005, '未找到采购单数据');
+						        }
+						        $bn =makeNo("BN");
+						        $yp=GoodStockInfo::AddBn($stockid,$bn,$param['defective_num'],$cgd['good_price']);
+						        if($yp==false){
+						            Db::rollback();
+									return error_show(1005, '商品批次退货入库失败');
+						        }
+	                            }
+                        }
                 $good_data=['good_log_code'=>$param['thNo'],"stock_id"=>isset($defective['id'])? $defective['id']:Db::name("good_stock")->getLastInsID(),"type"=>1,'stock'=>$param['defective_num'],"stock_name"=>"usable_stock"];
                 GoodLog::LogAdd($this->post['token'],$good_data,'RKTHD');
             }
@@ -510,55 +657,55 @@ class Orderback extends Base
                         Db::rollback();
                         return error_show(1005,'销售单订单更新失败');
                     }
-                    $ordernum =Db::name("order_num")->where(['orderCode'=>$info['orderCode']])->find();
-                    if($ordernum==false){
-                        Db::rollback();
-                        return error_show(1005,'未找到关联采购单');
-                    }
-                    $ordernum['send_num']-=$info['return_num'];
-                    $orderup =Db::name("order_num")->save($ordernum);
-                    if($orderup==false){
-                        Db::rollback();
-                        return error_show(1005,'关联数据更新失败');
-                    }
-                    $cgd =Db::name("purchease_order")->where(["cgdNo"=>$ordernum['cgdNo'],"is_del"=>0])->find();
-                    if($cgd==false){
-                        Db::rollback();
-                        return error_show(1005,'未找到采购单数据');
-                    }
-                    $cgd['th_fee']+= round($cgd['good_price']*$param['can_sell_num'],2);
-                    $cgd['th_num']+=  $param['can_sell_num'];
-                    if($cgd['th_num']==$cgd['send_num']&& $cgd['wsend_num']==0){
-                        $cgd['status']=4;
-                    }
-                    $cgd['updatetime']= date("Y-m-d H:i:s");
-                    $cgdup =Db::name("purchease_order")->save($cgd);
-                    if($cgdup==false){
-                        Db::rollback();
-                        return error_show(1005,'采购单数据更新失败');
-                    }
-                    if($cgd['bkcode']!=""){
-                        $bk=Db::name("purchease_order")->where(["bkcode"=>$cgd['bkcode'],"order_type"=>1,"order_source"=>0,"is_del"=>0])->find();
-                        if($bk==false){
-                            Db::rollback();
-                            return error_show(1005,'未找到备库单数据');
-                        }
-                       $orderbk = Db::name("order_bk")->where(['cgdNo'=>$bk['cgdNo'],"is_del"=>0])->find();
-                        if($orderbk==false){
-                            Db::rollback();
-                            return error_show(1005,'备库单未完全入库');
-                        }
-                        $merge_num = Db::name("purchease_order")->where(["bkcode"=>$bk['bkcode'],"order_type"=>1,"is_del"=>0])->where("order_source","<>",0)->field("sum(send_num)-sum(th_num) as num")->find();
-
-                        $orderbk['balance_num']=$orderbk['total_num']-$merge_num['num'];
-                        $orderbk['merge_num']=$merge_num['num'];
-                        $orderbk['updatetime']=date("Y-m-d H:i:s");
-                        $orderbkup=Db::name("order_bk")->save($orderbk);
-                        if($orderbkup==false){
-                            Db::rollback();
-                            return error_show(1005,'备库单库存数据释放失败');
-                        }
-                    }
+//                    $ordernum =Db::name("order_num")->where(['orderCode'=>$info['orderCode']])->find();
+//                    if($ordernum==false){
+//                        Db::rollback();
+//                        return error_show(1005,'未找到关联采购单');
+//                    }
+//                    $ordernum['send_num']-=$info['return_num'];
+//                    $orderup =Db::name("order_num")->save($ordernum);
+//                    if($orderup==false){
+//                        Db::rollback();
+//                        return error_show(1005,'关联数据更新失败');
+//                    }
+//                    $cgd =Db::name("purchease_order")->where(["cgdNo"=>$ordernum['cgdNo'],"is_del"=>0])->find();
+//                    if($cgd==false){
+//                        Db::rollback();
+//                        return error_show(1005,'未找到采购单数据');
+//                    }
+//                    $cgd['th_fee']+= round($cgd['good_price']*$param['can_sell_num'],2);
+//                    $cgd['th_num']+=  $param['can_sell_num'];
+//                    if($cgd['th_num']==$cgd['send_num']&& $cgd['wsend_num']==0){
+//                        $cgd['status']=4;
+//                    }
+//                    $cgd['updatetime']= date("Y-m-d H:i:s");
+//                    $cgdup =Db::name("purchease_order")->save($cgd);
+//                    if($cgdup==false){
+//                        Db::rollback();
+//                        return error_show(1005,'采购单数据更新失败');
+//                    }
+//                    if($cgd['bkcode']!=""){
+//                        $bk=Db::name("purchease_order")->where(["bkcode"=>$cgd['bkcode'],"order_type"=>1,"order_source"=>0,"is_del"=>0])->find();
+//                        if($bk==false){
+//                            Db::rollback();
+//                            return error_show(1005,'未找到备库单数据');
+//                        }
+//                       $orderbk = Db::name("order_bk")->where(['cgdNo'=>$bk['cgdNo'],"is_del"=>0])->find();
+//                        if($orderbk==false){
+//                            Db::rollback();
+//                            return error_show(1005,'备库单未完全入库');
+//                        }
+//                        $merge_num = Db::name("purchease_order")->where(["bkcode"=>$bk['bkcode'],"order_type"=>1,"is_del"=>0])->where("order_source","<>",0)->field("sum(send_num)-sum(th_num) as num")->find();
+//
+//                        $orderbk['balance_num']=$orderbk['total_num']-$merge_num['num'];
+//                        $orderbk['merge_num']=$merge_num['num'];
+//                        $orderbk['updatetime']=date("Y-m-d H:i:s");
+//                        $orderbkup=Db::name("order_bk")->save($orderbk);
+//                        if($orderbkup==false){
+//                            Db::rollback();
+//                            return error_show(1005,'备库单库存数据释放失败');
+//                        }
+//                    }
                 }else{
                     if($returninfo['return_tag']==1){
                         $sale['th_num']+= $info['return_num'];
@@ -612,33 +759,33 @@ class Orderback extends Base
                             Db::rollback();
                             return error_show(1005,'销售单订单更新失败');
                         }
-                        $ordernum =Db::name("order_num")->where(['orderCode'=>$info['orderCode']])->find();
-                        if($ordernum==false){
-                            Db::rollback();
-                            return error_show(1005,'未找到关联采购单');
-                        }
-                        $ordernum['send_num']-=$info['return_num'];
-                        $orderup =Db::name("order_num")->save($ordernum);
-                        if($orderup==false){
-                            Db::rollback();
-                            return error_show(1005,'关联数据更新失败');
-                        }
-                        $cgd =Db::name("purchease_order")->where(["cgdNo"=>$ordernum['cgdNo'],"is_del"=>0])->find();
-                        if($cgd==false){
-                            Db::rollback();
-                            return error_show(1005,'未找到采购单数据');
-                        }
-                        $cgd['th_fee']+= round($cgd['good_price']*$param['can_sell_num'],2);
-                        $cgd['th_num']+=  $param['can_sell_num'];
-                        if($cgd['th_num']==$cgd['send_num']&& $cgd['wsend_num']==0){
-                            $cgd['status']=4;
-                        }
-                        $cgd['updatetime']= date("Y-m-d H:i:s");
-                        $cgdup =Db::name("purchease_order")->save($cgd);
-                        if($cgdup==false){
-                            Db::rollback();
-                            return error_show(1005,'采购单数据更新失败');
-                        }
+//                        $ordernum =Db::name("order_num")->where(['orderCode'=>$info['orderCode']])->find();
+//                        if($ordernum==false){
+//                            Db::rollback();
+//                            return error_show(1005,'未找到关联采购单');
+//                        }
+//                        $ordernum['send_num']-=$info['return_num'];
+//                        $orderup =Db::name("order_num")->save($ordernum);
+//                        if($orderup==false){
+//                            Db::rollback();
+//                            return error_show(1005,'关联数据更新失败');
+//                        }
+//                        $cgd =Db::name("purchease_order")->where(["cgdNo"=>$ordernum['cgdNo'],"is_del"=>0])->find();
+//                        if($cgd==false){
+//                            Db::rollback();
+//                            return error_show(1005,'未找到采购单数据');
+//                        }
+//                        $cgd['th_fee']+= round($cgd['good_price']*$param['can_sell_num'],2);
+//                        $cgd['th_num']+=  $param['can_sell_num'];
+//                        if($cgd['th_num']==$cgd['send_num']&& $cgd['wsend_num']==0){
+//                            $cgd['status']=4;
+//                        }
+//                        $cgd['updatetime']= date("Y-m-d H:i:s");
+//                        $cgdup =Db::name("purchease_order")->save($cgd);
+//                        if($cgdup==false){
+//                            Db::rollback();
+//                            return error_show(1005,'采购单数据更新失败');
+//                        }
                     }
                 }
             }
@@ -679,9 +826,25 @@ class Orderback extends Base
                 }
 
                 $stn = ["order_code" => $param['thNo'], "status" => $info['status'], "action_remark" => '', "action_type" => "edit"];
-                ActionLog::logAdd($this->post['token'], $stn, "CKTHD",  $param['status'], $stn);
-                $process = ["order_code" => $param['thNo'], "order_id" => $info['id'], "order_status" => $param['status'], "order_type" =>"CKTHD","before_status"=>$info['status']];
-                ProcessOrder::AddProcess($this->post['token'], $process);
+                ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stn, "CKTHD",  $param['status'], $stn);
+
+                if (in_array($param['status'], [1,2, 3])) {
+                    if ($param['status'] == 2) $roleid = [10, 31, 41];//特殊处理,写入到10采购负责人、31库管人员、41库管-张凯旋这三个角色下的所有人
+                    else $roleid = [31, 41];//特殊处理,写入到、31库管人员、41库管-张凯旋这三个角色下的所有人
+
+                    $handle_user_list = Db::name('user_role')
+                        ->where('is_del', 0)
+                        ->whereIn('roleid', $roleid)
+                        ->column('uid');
+
+                    //如果是退货商品验收(节点1),把供应商负责人也加进去
+                    if ($param['status'] == 1) $handle_user_list[] = $sale['cgderid'];
+
+                    $process = ["order_code" => $param['thNo'], "order_id" => $info['id'], "order_status" => $param['status'], "order_type" => "CKTHD", "before_status" => $info['status'], 'handle_user_list' => implode(',', $handle_user_list)];
+
+                } else $process = ["order_code" => $param['thNo'], "order_id" => $info['id'], "order_status" => $param['status'], "order_type" => "CKTHD", "before_status" => $info['status']];
+
+                ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $process);
 
                 Db::commit();
                 return app_show(0, '操作成功');

+ 54 - 47
app/admin/controller/Process.php

@@ -58,65 +58,72 @@ class Process extends Base
         return app_show(0, "获取成功", $info);
     }
 
-    /**
-     * @return \think\response\Json|void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\DbException
-     * @throws \think\db\exception\ModelNotFoundException
-     */
+    //审核记录
     public function process()
     {
-        $process_type = isset($this->post['type']) && $this->post['type'] != "" ? $this->post['type'] : "";
-        if ($process_type == "") {
-            return error_show(1004, "参数type 不能为空");
-        }
-        $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] != "" ? $this->post['orderCode'] : "";
-        if ($orderCode == "") {
-            return error_show(1004, "参数orderCode不能为空");
-        }
-        $list = Db::name("action_process")
-            ->where(['order_type' => $process_type, "is_del" => 0, "status" => 1])
-            ->order("weight desc,id desc")
-            ->column('*', 'order_process');
+        $param = $this->request->filter('trim')->only(['type', 'orderCode'], 'post');
+
+        $val = Validate::rule([]);
+        if (!$val->check($param)) return error_show(1004, $val->getError());
+//        $process_type = isset($this->post['type']) && $this->post['type'] != "" ? $this->post['type'] : "";
+//        if ($process_type == "") {
+//            return error_show(1004, "参数type 不能为空");
+//        }
+//        $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] != "" ? $this->post['orderCode'] : "";
+//        if ($orderCode == "") {
+//            return error_show(1004, "参数orderCode不能为空");
+//        }
+//        $list = Db::name("action_process")
+//            ->where(['order_type' => $param['type'], "is_del" => 0, "status" => 1])
+//            ->order("weight desc,id desc")
+//            ->column('*', 'order_process');
 
         //根据所有的状态,查询对应的操作
-        $order_process_s = array_column($list, 'order_process');
+//        $order_process_s = array_column($list, 'order_process');
 
         $rs = Db::name("process_order")
-            ->where(["order_type" => $process_type])
-            ->whereIn('action_process', $order_process_s)
-            ->field('id,action_uid,action_name,addtime,action_process,order_type,source');
-        if (is_numeric($orderCode)) $rs->where('order_id', $orderCode);
-        else $rs->where('order_code', $orderCode);
+            ->alias('a')
+            ->leftJoin('action_process b', 'b.order_type=a.order_type AND b.order_process=a.action_process')
+            ->where(["a.order_type" => $param['type']])
+            ->order('a.id', 'asc')
+            ->field('a.id,a.action_uid,a.action_name,a.addtime,a.action_process,a.order_type,a.source,a.action_process,b.status_name');
+        if (is_numeric($param['orderCode'])) $rs->where('a.order_id', $param['orderCode']);
+        else $rs->where('a.order_code', $param['orderCode']);
 
         $node = $rs
             ->select()
             ->toArray();
 
-        foreach ($node as &$value) {
-            $value['order_process'] = isset($list[$value['action_process']]['order_process']) ? $list[$value['action_process']]['order_process'] : 0;
-            $value['order_name'] = isset($list[$value['action_process']]['order_name']) ? $list[$value['action_process']]['order_name'] : '';
-            $value['pid'] = isset($list[$value['action_process']]['pid']) ? $list[$value['action_process']]['pid'] : '';
-            $value['status_name'] = isset($list[$value['action_process']]['status_name']) ? $list[$value['action_process']]['status_name'] : '';
-            $value['roleid'] = isset($list[$value['action_process']]['roleid']) ? $list[$value['action_process']]['roleid'] : '';
-            $value['status'] = isset($list[$value['action_process']]['status']) ? $list[$value['action_process']]['status'] : '';
-            $value['weight'] = isset($list[$value['action_process']]['weight']) ? $list[$value['action_process']]['weight'] : '';
-            $value['is_del'] = isset($list[$value['action_process']]['is_del']) ? $list[$value['action_process']]['is_del'] : '';
-
-
-//        $value = isset($list[$value['action_process']])?array_merge($list[$value['action_process']],$value):$value;
-//        $node = Db::name("process_order")
-//            ->where([
-//                "order_type"=>$value['order_type'],
-//                "action_process"=>$value['order_process'],
-//                "order_code"=>$orderCode])
-//            ->find();
-//        $value['action_uid']= isset($node[$value['order_process']]['action_uid']) ? $node[$value['order_process']]['action_uid']:'';
-//        $value['action_name']= isset($node[$value['order_process']]['action_name']) ? $node[$value['order_process']]['action_name']:'';
-//        $value['addtime']= isset($node[$value['order_process']]['addtime']) ? $node[$value['order_process']]['addtime']:'';
-//        $data[]=$value;
+        $i = 0;
+        $data = [['status_name' => '创建', 'order_process' => -1]];
+        foreach ($node as $value) {
+
+            $data[$i] = array_merge($data[$i], [
+                'action_uid' => $value['action_uid'],
+                'action_name' => $value['action_name'],
+                'addtime' => $value['addtime'],
+                'source' => $value['source'],
+            ]);
+
+            $data[$i + 1] = [
+                'status_name' => $value['status_name'],
+                'order_process' => $value['action_process']
+            ];
+//            $value['order_process'] = isset($list[$value['action_process']]['order_process']) ? $list[$value['action_process']]['order_process'] : 0;
+//            $value['order_name'] = isset($list[$value['action_process']]['order_name']) ? $list[$value['action_process']]['order_name'] : '';
+//            $value['pid'] = isset($list[$value['action_process']]['pid']) ? $list[$value['action_process']]['pid'] : '';
+//            $value['status_name'] = isset($list[$value['action_process']]['status_name']) ? $list[$value['action_process']]['status_name'] : '';
+//            $value['roleid'] = isset($list[$value['action_process']]['roleid']) ? $list[$value['action_process']]['roleid'] : '';
+//            $value['status'] = isset($list[$value['action_process']]['status']) ? $list[$value['action_process']]['status'] : '';
+//            $value['weight'] = isset($list[$value['action_process']]['weight']) ? $list[$value['action_process']]['weight'] : '';
+//            $value['is_del'] = isset($list[$value['action_process']]['is_del']) ? $list[$value['action_process']]['is_del'] : '';
+
+            $i++;
         }
-        return app_show(0, "获取成功", $node);
+
+//        if ($node) array_unshift($node, ['status_name' => '创建', 'order_process' => -1]);
+
+        return app_show(0, "获取成功", $data);
     }
 
 

+ 13 - 5
app/admin/controller/Project.php

@@ -142,7 +142,7 @@ class Project extends Base
                             "action_remark" => '',//备注
                             "action_type" => "create"//新建create,编辑edit,更改状态status
                         ], "PRO", 1, $this->post);
-                        $process = ["order_code" => $projectNo, "order_id" => $pro, "order_status" =>1, "order_type" =>"PRO","before_status"=>1];
+                        $process = ["order_code" => $projectNo, "order_id" => $pro, "order_status" =>1, "order_type" =>"PRO","before_status"=>1,'holder_id'=>$data['createrid']];
                         ProcessOrder::AddProcess(['id'=>$createrid,'nickname'=>$creater], $process);
 
                     //台账记录
@@ -296,7 +296,9 @@ class Project extends Base
                                 "order_type"=>'PRO',
                                 "order_code"=>$projectinfo['projectNo'],
                                 "order_id"=>$project['id'],//这里更新是根据编码更新的,没有主键id
-                                "order_status"=>2,"before_status"=>1
+                                "order_status"=>2,
+                                "before_status"=>1,
+                                'holder_id'=>$project['createrid']
                             ]);
 
                             Db::commit();
@@ -704,7 +706,9 @@ class Project extends Base
                             "order_type" => 'PRO',
                             "order_code" => $projectNo,
                             "order_id" => $info['id'],
-                            "order_status" => 4,"before_status"=>$old_project_status
+                            "order_status" => 4,
+                            "before_status"=>$old_project_status,
+                            'holder_id'=>$info['createrid']
                         ]);
                         Db::commit();
                         return app_show(0,"方案制作成功",["planNo"=>$planNo]);
@@ -883,7 +887,9 @@ class Project extends Base
                                     "order_type" => 'PRO',
                                     "order_code" =>$value['projectNo'],
                                     "order_id" => $poject['id'],
-                                    "order_status" => 3,"before_status"=>$poject['status']
+                                    "order_status" => 3,
+                                    "before_status"=>$poject['status'],
+                                    'holder_id'=>$poject['createrid']
                                 ]);
                             }
                         }
@@ -958,7 +964,9 @@ class Project extends Base
                             "order_type" => 'PRO',
                             "order_code" =>$value,
                             "order_id" => $poject['id'],
-                            "order_status" => 5,"before_status"=>4
+                            "order_status" => 5,
+                            "before_status"=>4,
+                            'holder_id'=>$poject['createrid']
                         ]);
                     }
 

+ 240 - 51
app/admin/controller/Proorder.php

@@ -2,6 +2,7 @@
 
 namespace app\admin\controller;
 
+use app\admin\model\ProcessWait;
 use think\App;
 use think\facade\Db;
 
@@ -9,11 +10,10 @@ use think\facade\Db;
 class Proorder extends Base
 {
 
-public function __construct(App $app)
-{
-    parent::__construct($app);
-}
-
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+    }
 
     //已读列表
     public function list()
@@ -27,10 +27,10 @@ public function __construct(App $app)
          * if(!empty($role['write'])){
          * $where[]=["a.action_uid","in",$role['write']];
          * }
-         * $count = Db::name('process_order')->alias("a")->leftJoin("workflow b","a.order_type=b.order_type and a.order_code=b.order_code")->where($where)->count();
+         * $count = Db::name('process_order')->alias("a")->leftJoin("workflow b","a.order_id=b.order_id and a.order_code=b.order_code")->where($where)->count();
          * $total = ceil("$count/$size");
          * $page = $page>$total ? $total:$page;
-         * $list = Db::name('process_order')->alias("a")->leftJoin("workflow b","a.order_type=b.order_type and a.order_code=b.order_code")
+         * $list = Db::name('process_order')->alias("a")->leftJoin("workflow b","a.order_id=b.order_id and a.order_code=b.order_code")
          * ->field("b.apply_id,b.apply_name,a.addtime,a.action_uid,a.action_name,a.order_status,a.action_status,a.order_type,a.action_process,a.order_code,a.order_id,a.id")
          * ->where($where)->page($page,$size)->order("a.addtime desc")->select();
          * $data=[];
@@ -49,10 +49,9 @@ public function __construct(App $app)
 
             $param = $this->request->filter('trim')->only(['token', 'apply_id' => '', 'action_uid' => '', 'order_code' => '', 'page' => 1, 'size' => 10], 'post');
 
-            $db = Db::name('process_wait')
-                ->alias("a")
-                ->leftJoin("workflow b", "a.order_type=b.order_type and a.order_code=b.order_code")
-                ->where(['is_del' => 0, 'a.status' => 2]);
+            $db = ProcessWait::alias("a")
+                ->leftJoin('workflow b', 'a.order_type=b.order_type and a.order_id=b.order_id')//这个地方不适宜用order_code,因为特殊单子没有编码,例如离职交接单
+                ->where(['is_del' => 0, 'a.status' => ProcessWait::$status_finish]);
 
             $db->where(function ($query) use ($param) {
                 //所属角色
@@ -61,20 +60,59 @@ public function __construct(App $app)
                 $query->whereFindInSet('roleid', $role['roleid']);
 
                 //本人id
-                $user = GetUserInfo($param['token']);
-                if (isset($user['data']['id'])) $query->whereOr('wait_id', $user['data']['id']);
+//                $user = GetUserInfo($param['token']);
+                //if (isset($user['data']['id']))
+                $query->whereOr('wait_id', $this->uid);
             });
 
             if ($param['order_code'] != '') $db->whereLike("a.order_code", '%' . $param['order_code'] . '%');
             if ($param['action_uid'] != '') $db->where('a.action_uid', $param['action_uid']);
 
-            $count = $db->count();
+            $count = $db
+//                ->field("ANY_VALUE(`a`.`id`) id,`a`.order_type,`a`.order_id,GROUP_CONCAT(`a`.`id` ORDER BY `a`.`id` DESC) ids")
+                ->group('a.order_type,a.order_id')
+//                ->order(['a.id'=>'desc'])
+//                ->fetchSql()
+//                ->withAttr('ids', function ($val) {
+//                    $temp = explode(',', $val);
+//                    return $temp[0];
+//                })
+//                ->page($page, $param['size'])
+                ->count('a.id');
 
             $total = ceil($count / $param['size']);
             $page = $param['page'] > $total ? $total : $param['page'];
-            $list = $db
-                ->field("b.apply_id,b.apply_name,a.addtime,a.action_uid,a.action_name,a.order_status,a.order_type,a.order_process,a.order_code,a.order_id,a.id")
+
+            //筛选符合条件的order_type,排除重复数据
+            $order_types = $db
+                ->field("ANY_VALUE(`a`.`id`) id,`a`.order_type,`a`.order_id,GROUP_CONCAT(`a`.`id` ORDER BY `a`.`id` DESC) ids")
+                ->group('a.order_type,a.order_id')
+                ->order(['id' => 'desc'])
+                ->withAttr('ids', function ($val) {
+                    $temp = explode(',', $val);
+                    return $temp[0];
+                })
                 ->page($page, $param['size'])
+                ->select()
+                ->toArray();
+
+            $list = ProcessWait::alias("a")
+                ->field([
+                    'b.apply_id',
+                    'b.apply_name',
+                    'a.addtime',
+                    'a.action_uid_finally' => 'action_uid',//取实时操作人id
+                    'a.action_name_finally' => 'action_name',//取实时操作人
+                    'a.order_status',
+                    'a.order_type',
+                    'a.order_code',
+                    'a.order_id',
+                    'a.id',
+                    'a.order_process_finally' => 'order_process',//取实时状态值
+                ])
+                ->whereIn('a.id', array_column($order_types, 'ids'))
+                ->leftJoin("workflow b", "a.order_type=b.order_type and a.order_id=b.order_id")
+//                ->page($page, $param['size'])
                 ->order("a.addtime desc")
                 ->select()
                 ->toArray();
@@ -88,14 +126,17 @@ public function __construct(App $app)
             foreach ($list as $value) {
                 $var = Db::name("action_process")
                     ->where(['order_type' => $value['order_type'], 'order_process' => $value['order_process']])
+//                    ->whereIn('order_process', [$value['order_process'], $value['order_process_finally']])
                     ->field("status_name,order_process,order_name,roleid")
-                    ->find();
+//                    ->column('status_name,order_process,order_name,roleid', 'order_process');
+                    ->findOrEmpty();
                 $value['process_name'] = isset($all_process[$value['order_type']]) ? $all_process[$value['order_type']] : '';
                 $value['order_name'] = $var['order_name'];
                 $value['status_name'] = $var['status_name'];
+//                $value['order_process_finally_status_name'] = $var[$value['order_process_finally']]['status_name'] ?? '';
                 $data[] = $value;
             }
-            return app_show(0, "获取成功", ["list" => $data, 'count' => $count]);
+            return app_show(0, "获取成功", ['count' => $count, 'list' => $data]);
         }
 
 
@@ -107,22 +148,23 @@ public function __construct(App $app)
 
         $param = $this->request->filter('trim')->only(['token', 'apply_id' => '', 'action_uid' => '', 'order_code' => '', 'page' => 1, 'size' => 10], 'post');
 
-        $db = Db::name('process_wait')
-            ->alias("a")
-            ->leftJoin("workflow b", "a.order_type=b.order_type and a.order_code=b.order_code")
-            ->where(['is_del' => 0, 'a.status' => 1]);
+        $db = ProcessWait::alias("a")
+            ->leftJoin('workflow b', 'a.order_type=b.order_type and a.order_id=b.order_id')//这个地方不适宜用order_code,因为特殊单子没有编码,例如离职交接单
+//            ->leftJoin('process p', 'p.process_type=a.order_type AND p.is_del=0 AND p.status=1')
+            ->where(['a.status' => ProcessWait::$status_wait]);
 
-        $db->where(function ($query) use ($param) {
-            //所属角色
-            $role = $this->checkRole();
+
+//        $db->where(function ($query) use ($param) {
+        //所属角色
+        $role = $this->checkRole();
+        if ($role['roleid'] != 1) $db->whereFindInSet('handle_user_list', $this->uid);
 
 //            if (!empty($role['write']) || $role['roleid'] == 33) $query->whereFindInSet('roleid', $role['roleid']);
-            $query->whereFindInSet('roleid', $role['roleid']);
+//            $query->whereFindInSet('roleid', $role['roleid']);
 
-            //本人id
-            $user = GetUserInfo($param['token']);
-            if (isset($user['data']['id'])) $query->whereOr('wait_id', $user['data']['id']);
-        });
+        //本人id
+//            $query->whereOr('wait_id', $this->uid);
+//        });
 
         if ($param['order_code'] != '') $db->whereLike('a.order_code', '%' . $param['order_code'] . '%');
         if ($param['action_uid'] != '') $db->where('a.action_uid', $param['action_uid']);
@@ -132,9 +174,13 @@ public function __construct(App $app)
         $total = ceil($count / $param['size']);
         $page = $param['page'] > $total ? $total : $param['page'];
         $list = $db
-            ->field("a.id,b.apply_id,b.apply_name,a.addtime,a.action_uid,a.action_name,a.order_status,a.order_type,a.order_process,a.order_code,a.order_id")
+            ->field("a.id,a.addtime,a.action_name,a.order_status,a.order_type,a.order_process,a.order_code,a.order_id,a.handle_user_list,b. apply_id,b.apply_name")
             ->page($page, $param['size'])
             ->order("a.addtime desc")
+//            ->append(['handle_user_list'])
+//            ->withAttr('handle_user_list', function ($val, $da) {
+//                return [];
+//            })
             ->select()
             ->toArray();
 
@@ -152,29 +198,172 @@ public function __construct(App $app)
             $value['process_name'] = isset($all_process[$value['order_type']]) ? $all_process[$value['order_type']] : '';
             $value['order_name'] = $var['order_name'];
             $value['status_name'] = $var['status_name'];
+
+            //找到流程对应记录的所有人(创建人 or 申请人 or 采购员)
+//            $holder_id = 0;
+
+//            switch ($value['order_type']) {
+//                //1.采购单流程
+//                case 'CGD':
+//                    $holder_id = Db::name('purchease_order')->where(['id' => $value['order_id'], 'is_del' => 0])->value('cgder_id', 0);
+//                    break;
+//                //2.采购单入库流程
+//                case 'RKD':
+//                    $holder_id = Db::name('purchease_in')->where(['id' => $value['order_id'], 'is_del' => 0])->value('apply_id', 0);
+//                    break;
+//                //3.备货申请单流程
+//                case 'BHD':
+//                    $holder_id = Db::name('purchease')->where(['id' => $value['order_id'], 'is_del' => 0])->value('apply_id', 0);
+//                    break;
+//                //4.销售订单流程
+//                case 'XSQRD':
+//                    $holder_id = Db::name('sale')->where(['id' => $value['order_id'], 'is_del' => 0])->value('apply_id', 0);
+//                    break;
+//                //5.发货申请单流程
+//                case 'CKD':
+//                    $holder_id = Db::name('order_out')->where(['id' => $value['order_id'], 'is_del' => 0])->value('apply_id', 0);
+//                    break;
+//                //6.售后申请单流程
+//                case 'SHD':
+//                    $holder_id = Db::name('order_return')->where(['id' => $value['order_id'], 'is_del' => 0])->value('apply_id', 0);
+//                    break;
+//                //7.售后退货单流程
+//                case 'CKTHD':
+//                    $holder_id = Db::name('order_back')->where(['id' => $value['order_id'], 'is_del' => 0])->value('apply_id', 0);
+//                    break;
+//                //8.销售退货单流程
+//                case 'XSTHD':
+//                    $holder_id = Db::name('sale_return')->where(['id' => $value['order_id'], 'is_del' => 0])->value('apply_id', 0);
+//                    break;
+//                //9.采购工差单流程
+//                case 'CGGCD':
+//                    $holder_id = Db::name('purchease_diff')->where(['id' => $value['order_id'], 'is_del' => 0])->value('apply_id', 0);
+//                    break;
+//                //10.销售工差单流程
+//                case 'XSGCD':
+//                    $holder_id = Db::name('sale_diff')
+//                        ->alias('a')
+//                        ->where(['a.id' => $value['order_id']])
+//                        ->leftJoin('sale s', 's.orderCode=a.orderCode')
+//                        ->value('s.apply_id', 0);
+//                    break;
+//                //11.调拨单流程
+//                case 'DBD':
+//                    $holder_id = Db::name('allot_stock')->where(['id' => $value['order_id'], 'is_del' => 0])->value('apply_id', 0);
+//                    break;
+//                //12.盘点单流程
+//                case 'PDD':
+//                    $holder_id = Db::name('good_check')->where(['id' => $value['order_id'], 'is_del' => 0])->value('apply_id', 0);
+//                    break;
+//                //13.议价单流程
+//                case 'YJD':
+//                    $holder_id = Db::name('bargain_order')->where(['id' => $value['order_id'], 'is_del' => 0])->value('createrid', 0);
+//                    break;
+//                //14.项目单流程
+//                case 'PRO':
+//                    $holder_id = Db::name('project')->where(['id' => $value['order_id'], 'is_del' => 0])->value('createrid', 0);
+//                    break;
+//                //15.商品成本流程
+//                case 'SPCB':
+//                    $holder_id = Db::name('good_basic')->where(['id' => $value['order_id'], 'is_del' => 0])->value('chargerid', 0);
+//                    break;
+//                //16.商品上线流程
+//                case 'SPSX':
+//                    $holder_id = Db::name('good_platform')
+//                        ->alias('a')
+//                        ->where(['a.id' => $value['order_id']])
+//                        ->leftJoin('good g', 'g.spuCode=a.spuCode')
+//                        ->value('g.createrid', 0);
+//                    break;
+//                //17.活动流程
+//                case 'HD':
+//                    $holder_id = Db::name('good_activity')->where(['id' => $value['order_id'], 'is_del' => 0])->value('createrid', 0);
+//                    break;
+//                //19.有赞商品上架流程
+//                case 'YZSX':
+//                    $holder_id = Db::name('platform_youzan')
+//                        ->alias('a')
+//                        ->where(['a.id' => $value['order_id']])
+//                        ->leftJoin('good g', 'g.spuCode=a.spuCode')
+//                        ->value('g.createrid', 0);
+//                    break;
+//                //20.有赞订单审核流程
+////                case 'YZQRD':
+////                    $holder_id = Db::name('')->where(['id' => $value['order_id'], 'is_del' => 0])->value('', 0);
+////                    break;
+//                //22.离职交接流程
+//                case 'LZJJ':
+//                    $holder_id = Db::name('resign_info')->where(['id' => $value['order_id'], 'is_del' => 0])->value('hand_uid', 0);
+//                    break;
+//                //23.采购单退货流程
+//                case 'CGTHD':
+//                    $holder_id = Db::name('purchease_return')->where(['id' => $value['order_id'], 'is_del' => 0])->value('apply_id', 0);
+//                    break;
+//                //24.竞价单流程
+//                case 'ZXD':
+//                    $holder_id = Db::name('consult_order')->where(['id' => $value['order_id'], 'is_del' => 0])->value('createrid', 0);
+//                    break;
+//                //25.商品下线流程
+//                case 'GOL':
+//                    $holder_id = Db::name('good_offline_log')->where(['id' => $value['order_id'], 'is_del' => 0])->value('createrid', 0);
+//                    break;
+//            }
+
+            //根据记录的所有人判断哪些人能看到它的记录
+//            $uids_1 = $this->get_uids_by_group_share($holder_id, $value['api_url']);
+
+            //根据角色筛选
+            $uid = Db::name('user_role')
+                ->field('uid')
+                ->where([
+                    ['is_del', '=', 0],
+                    ['uid', 'in', $value['handle_user_list']],
+//                    ['roleid', '<>', 1],//超级管理员不在这个范围内
+                    ['status', '=', 1],
+                ])
+                ->buildSql();
+            $value['handle_user_list'] = Db::name('depart_user')
+                ->where(['is_del' => 0, 'status' => 1])
+                ->where('uid IN ' . $uid)
+                ->column('nickname');
+
+//            $value['uid_1'] = $uids_1;
+//            $value['uid_2'] = $uids_2;
+
+//            $uids = array_intersect($uids_1, $uids_2);
+
+//            $users = Db::name('depart_user')->where(['is_del' => 0, 'status' => 1])->whereIn('uid', $uids)->column('nickname');
+
+            //当前操作人
+//            $value['handle_user_list'] = $value['wait_name'] ? array_merge($users, [$value['wait_name']]) : $users;
+
             $data[] = $value;
         }
         return app_show(0, "获取成功", ["list" => $data, 'count' => $count]);
     }
-public function all(){
-    $token = isset($this->post['token']) ? trim($this->post['token']) : "";
-    if($token==""){
-        return error_show(101,'token不能为空');
-    }
-    $effetc = VerifyTokens($token);
-    if(!empty($effetc) && $effetc['code']!=0){
-        return error_show($effetc['code'],$effetc['message']);
-    }
-    $where=[["is_del","=",0]];
-    $process_name = isset($this->post['process_name']) && $this->post['process_name'] !==""? trim($this->post['process_name']) :"";
-    if($process_name!=""){
-        $where[]=["process_name","like","%$process_name%"];
-    }
-    $process_type = isset($this->post['process_type']) && $this->post['process_type'] !==""? trim($this->post['process_type']) :"";
-    if($process_type!=""){
-        $where[]=["process_type","like","%$process_type%"];
+
+    public function all()
+    {
+        $token = isset($this->post['token']) ? trim($this->post['token']) : "";
+        if ($token == "") {
+            return error_show(101, 'token不能为空');
+        }
+        $effetc = VerifyTokens($token);
+        if (!empty($effetc) && $effetc['code'] != 0) {
+            return error_show($effetc['code'], $effetc['message']);
+        }
+        $where = [["is_del", "=", 0]];
+        $process_name = isset($this->post['process_name']) && $this->post['process_name'] !== "" ? trim($this->post['process_name']) : "";
+        if ($process_name != "") {
+            $where[] = ["process_name", "like", "%$process_name%"];
+        }
+        $process_type = isset($this->post['process_type']) && $this->post['process_type'] !== "" ? trim($this->post['process_type']) : "";
+        if ($process_type != "") {
+            $where[] = ["process_type", "like", "%$process_type%"];
+        }
+        $list = Db::name('process')->where($where)->order("addtime desc")->select();
+        return app_show(0, "获取成功", $list);
     }
-    $list = Db::name('process')->where($where)->order("addtime desc")->select();
-    return app_show(0,"获取成功",$list);
-}
+
+
 }

+ 130 - 70
app/admin/controller/Purch.php

@@ -87,34 +87,38 @@ class Purch extends Base
         $start = isset($this->post['start']) && $this->post['start']!="" ?$this->post['start']:"";
         if($start!=""){
             // $where['addtime'] = Db::raw(" >= '{$start}'");
-            $where[]=['po.addtime',">=", $start];
+            $where[]=['po.addtime',">=", $start." 00:00:00"];
         }
         $end = isset($this->post['end']) && $this->post['end']!="" ?$this->post['end']:"";
         if($end!=""){
-            $where[]=['po.addtime',"<=", $end];
+            $where[]=['po.addtime',"<=", $end." 23:59:59"];
         }
         $last_start = isset($this->post['last_start']) && $this->post['last_start']!="" ?$this->post['last_start']:"";
         if($last_start!=""){
             //$where['lasttime'] = Db::raw(" >= '{$last_start}'");
-            $where[]=['po.lasttime',">=", $last_start];
+            $where[]=['po.lasttime',">=", $last_start." 00:00:00"];
 
         }
         $last_end = isset($this->post['last_end']) && $this->post['last_end']!="" ?$this->post['last_end']:"";
         if($last_end!=""){
             //$where['lasttime'] = Db::raw(" <= '{$last_end}'");
-            $where[]=['po.lasttime',"<=", $last_end];
+            $where[]=['po.lasttime',"<=", $last_end." 23:59:59"];
         }
         $orderCode = isset($this->post['orderCode']) && $this->post['orderCode']!="" ?$this->post['orderCode']:"";
         if($orderCode!=""){
             //$where['lasttime'] = Db::raw(" <= '{$last_end}'");
             $where[]=['on.orderCode',"like", '%'.$orderCode.'%'];
         }
-//        $role=$this->checkRole();
-//        if(!empty($role['write'])){
-//            $where[]=["po.cgder_id","in",$role['write']];
-//        }
-        $role = $this->checkDataShare();
-        if (!empty($role[DataGroupModel::$type_全部])) $where[] = ["po.cgder_id", "in", $role[DataGroupModel::$type_全部]];
+		$whereor=[];
+        if(!empty($role['write'])){
+//            $whereor[]=["po.cgder_id","in",$role['write']];
+//            $whereor[]=["sip.personid","=",$this->uid];
+            $whereor[]=["sip.personid","in",$role['write']];//最后的筛选条件
+//            $whereor[]=["po.cgder_id","=",$this->uid];
+        }
+		$role = $this->checkDataShare();
+        if (!empty($role[DataGroupModel::$type_全部])) $where[] = ["sip.personid", "in", $role[DataGroupModel::$type_全部]];
+
 
         $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
         if ($company_name !== "") $where[] = ["po.cgder_id", 'in', get_company_item_user_by_name($company_name)];
@@ -126,20 +130,26 @@ class Purch extends Base
         $count = Db::name("purchease_order")
             ->alias('po')
             ->leftJoin('order_num on', 'on.cgdNo=po.cgdNo')
+            ->leftJoin('supplier sip', 'sip.code=po.supplierNo')
             ->where($where)
             ->where(function ($query) use ($where) {
                 $query->whereOr([['po.order_type', '<>', 1], ['po.order_source', '=', 0]]);
-            })
-            ->count();
+            })->where(function ($query) use ($whereor) {
+                $query->whereOr($whereor);
+            })->count();
         $total = ceil($count/$size);
         $page = $page >= $total ? $total : $page;
         $list = Db::name("purchease_order")
             ->alias('po')
             ->leftJoin('order_num on','on.cgdNo=po.cgdNo')
             ->leftJoin("depart_user u", "u.uid=po.cgder_id AND u.is_del=0")
-            ->field('po.*,on.orderCode,u.itemid')
+            ->leftJoin('supplier sip', 'sip.code=po.supplierNo')
+            ->field('po.*,on.orderCode,u.itemid,sip.personid as supplier_cgderid,sip.person as supplier_cgder')
             ->where($where)
             ->where(function($query) use ($where){$query->whereOr([['po.order_type', '<>', 1],['po.order_source', '=', 0]]);})
+            ->where(function ($query) use ($whereor) {
+                $query->whereOr($whereor);
+            })
             ->page($page,$size)
             ->order("po.addtime desc")
             ->select()
@@ -156,9 +166,9 @@ class Purch extends Base
                 $value['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
                 $value['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
             }
-			$supplierCgder =Db::name("supplier")->where(["code"=>$value['supplierNo']])->findOrEmpty();
-            $value['supplier_cgderid'] = $supplierCgder['personid'] ??'';
-            $value['supplier_cgder'] = $supplierCgder['person'] ??'';
+//			$supplierCgder =Db::name("supplier")->where(["code"=>$value['supplierNo']])->findOrEmpty();
+//            $value['supplier_cgderid'] = $supplierCgder['personid'] ??'';
+//            $value['supplier_cgder'] = $supplierCgder['person'] ??'';
             if($value['order_type']==3){
                 $goon = Db::name("good_zixun")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
                 $value["speclist"]=isset($goon['specinfo'])&&$goon['specinfo']!=""? json_decode($goon['specinfo'],true):"";
@@ -286,8 +296,8 @@ class Purch extends Base
             }
 
             $supplier = Db::name("supplier")->where(["code"=>$goon['supplierNo']])->find();
-	        $goon['supplier_cgderid'] = $supplier['personid'] ??'';
-	        $goon['supplier_cgder'] = $supplier['person'] ??'';
+            $goon['supplier_cgderid'] = $supplier['personid'] ??'';
+            $goon['supplier_cgder'] = $supplier['person'] ??'';
             $goon['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
             $goon['noble_name']=isset($goon['noble_metal'])&&$goon['noble_metal']!=0?$this->noble[$goon['noble_metal']] :"";
             if(isset($goon['companyNo'])&&$goon['companyNo']!=""){
@@ -639,17 +649,19 @@ class Purch extends Base
             return error_show(1004, "参数status 不能为空");
         }
 
-        if ($status == 0) {
-            $data = Db::name("purchease_order")
-                ->field('id,cgdNo')
-                ->whereIn('cgdNo', $cgdNo)
-                ->where(["is_del" => 0])
-                ->where('send_status', '>', 1)
-                ->find();
-            if (!empty($data)) {
-                return error_show(1004, $data['cgdNo'] . "采购单发货中无法取消");
+        Db::startTrans();
+        try {
+
+            if ($status == 0) {
+                $data = Db::name("purchease_order")
+                    ->field('id,cgdNo,spuCode')
+                    ->whereIn('cgdNo', $cgdNo)
+                    ->where(["is_del" => 0])
+                    ->where('send_status', '>', 1)
+                    ->find();
+                if (!empty($data)) throw new Exception($data['cgdNo'] . "采购单发货中无法取消");
+
             }
-        }
 //        if($data['send_status']>1 && $status==0){
 //            return error_show(1004,"采购单发货中无法取消");
 //        }
@@ -658,36 +670,84 @@ class Purch extends Base
 //        $data['remark'] = $remark;
 //        $data['updatetime'] =date("Y-m-d H:i:s");
 
-        //原始数据
-        $info = Db::name("purchease_order")
-            ->whereIn('cgdNo', $cgdNo)
-            ->column('id,cgdNo,status','cgdNo');
-
-        $upd = Db::name("purchease_order")
-            ->whereIn('cgdNo', $cgdNo)
-            ->save([
-                'status' => $status,
-                'remark' => $remark,
-                'updatetime' => date("Y-m-d H:i:s"),
-            ]);
-        if ($upd) {
-
-            $user=GetUserInfo($this->post['token']);
-            $uid = isset($user['data']['id'])?$user['data']['id']:0;
-            $uname = isset($user['data']['nickname'])?$user['data']['nickname']:'';
-
-            foreach ($cgdNo as $vlue) {
-                $process = ["order_code" => $vlue, "order_id" => isset($info[$vlue]['id']) ? $info[$vlue]['id'] : 0, "order_status" => $status, "order_type" => 'CGD', "before_status" => isset($info[$vlue]['status']) ? $info[$vlue]['status'] : 0];
-                ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $uname], $process);
-                $order = ["order_code" => $vlue, "status" => '', "action_remark" => $remark, "action_type" => "status"];
-                ActionLog::logAdd(['id' => $uid, 'nickname' => $uname], $order, 'CGD', $status, $this->post);
-            }
+            //原始数据
+            $info = Db::name("purchease_order")
+                ->whereIn('cgdNo', $cgdNo)
+                ->column('id,cgdNo,status,supplierNo,spuCode,order_type', 'cgdNo');
+
+            $upd = Db::name("purchease_order")
+                ->whereIn('cgdNo', $cgdNo)
+                ->save([
+                    'status' => $status,
+                    'remark' => $remark,
+                    'updatetime' => date("Y-m-d H:i:s"),
+                ]);
+            if ($upd) {
+
+                $supplier_cgderid = Db::name('supplier')
+                    ->where('is_del', 0)
+                    ->whereIn('code', array_column($info, 'supplierNo'))
+                    ->column('personid', 'code');
+//            ->leftJoin('supplier sip', 'sip.code=po.supplierNo')
+//                ->field('po.*,on.orderCode,u.itemid,sip.personid as supplier_cgderid,sip.person as supplier_cgder')
+
+//            $user=GetUserInfo($this->post['token']);
+                $uid = $this->uid;
+                $uname = $this->uname;
+
+
+
+                foreach ($cgdNo as $vlue) {
+
+                    if($status == 1 && $uid != $supplier_cgderid[$info[$vlue]['supplierNo']]) throw new Exception('只能由供应商负责人来操作');//与供应商确认的这个操作,只能由供应商负责人来操作
+
+                    if ($status == 1 || $status == 2) {
+//                    $orderinfo = Db::name('sale')
+//                    ->alias('a')
+//                    ->field('a.id,a.orderCode,a.is_stock,a.order_type,a.cgderid')
+//                    ->leftJoin('order_num b','b.orderCode=a.orderCode')
+//                    ->where([
+//                        'a.is_del'=>0,
+//                        'b.cgdNo'=>$vlue,
+//                    ])->findOrEmpty();
+                        $is_stock = Db::name('good_basic')
+                            ->where(['is_del' => 0, 'spuCode' => $info[$vlue]['spuCode']])
+                            ->value('is_stock');
+
+                        if ($is_stock == 1) {
+                            //库存品,推给31库管人员、41库管-张凯旋
+                            $uids = Db::name('user_role')
+                                ->where([
+                                    ['is_del', '=', 0],
+                                    ['roleid', 'in', [31, 41]],
+                                    ['status', '=', 1]
+                                ])->column('uid');
+//                            if (!in_array($this->uid, $uids)) throw new Exception('库存品订单只能由库管人员操作');
+                            $process = ["order_code" => $vlue, "order_id" => isset($info[$vlue]['id']) ? $info[$vlue]['id'] : 0, "order_status" => $status, "order_type" => 'CGD', "before_status" => isset($info[$vlue]['status']) ? $info[$vlue]['status'] : 0, 'holder_id' => isset($supplier_cgderid[$info[$vlue]['supplierNo']]) ? $supplier_cgderid[$info[$vlue]['supplierNo']] : 0, 'handle_user_list' => implode(',', $uids)];
+                        } elseif ($is_stock == 0 || $info[$vlue]['order_type'] == 3) {
+                            //非库存品和采返商品,推给供应商负责人
+//                            if ($this->uid != $supplier_cgderid[$info[$vlue]['supplierNo']]) throw new Exception('非库存品和采返商品只能由供应商负责人操作');
+
+                            $process = ["order_code" => $vlue, "order_id" => isset($info[$vlue]['id']) ? $info[$vlue]['id'] : 0, "order_status" => $status, "order_type" => 'CGD', "before_status" => isset($info[$vlue]['status']) ? $info[$vlue]['status'] : 0, 'holder_id' => isset($supplier_cgderid[$info[$vlue]['supplierNo']]) ? $supplier_cgderid[$info[$vlue]['supplierNo']] : 0, 'handle_user_list' => isset($supplier_cgderid[$info[$vlue]['supplierNo']]) ? $supplier_cgderid[$info[$vlue]['supplierNo']] : 0];
+                        }
+                    } else $process = ["order_code" => $vlue, "order_id" => isset($info[$vlue]['id']) ? $info[$vlue]['id'] : 0, "order_status" => $status, "order_type" => 'CGD', "before_status" => isset($info[$vlue]['status']) ? $info[$vlue]['status'] : 0, 'holder_id' => isset($supplier_cgderid[$info[$vlue]['supplierNo']]) ? $supplier_cgderid[$info[$vlue]['supplierNo']] : 0];
+
+                    ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $uname], $process);
+                    $order = ["order_code" => $vlue, "status" => '', "action_remark" => $remark, "action_type" => "status"];
+                    ActionLog::logAdd(['id' => $uid, 'nickname' => $uname], $order, 'CGD', $status, $this->post);
+                }
+//                return app_show(0, "更新成功");
+            } else throw new Exception('更新失败');
+//                return error_show(1004, '更新失败');
+
+            Db::commit();
             return app_show(0, "更新成功");
-        } else {
-            return error_show(1004, '更新失败');
+        } catch (Exception $exception) {
+            Db::rollback();
+            return error_show(1004, '更新失败,' . $exception->getMessage());
         }
     }
-    
+
     //创建采购工差单
     public function diffcreat(){
         $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
@@ -712,12 +772,12 @@ class Purch extends Base
         if($diff_weight===""){
             return error_show(1002,"参数diff_weight不能为空");
         }
-        $apply_id =GetUserInfo($token);
-        if(empty($apply_id)||$apply_id['code']!=0){
-            return error_show(1002,"申请人数据不存在");
-        }
-        $rid= isset($apply_id["data"]['id']) ?  $apply_id["data"]['id'] : "";
-        $rname= isset($apply_id["data"]['nickname']) ?  $apply_id["data"]['nickname'] : "";
+//        $apply_id =GetUserInfo($token);
+//        if(empty($apply_id)||$apply_id['code']!=0){
+//            return error_show(1002,"申请人数据不存在");
+//        }
+        $rid= $this->uid;
+        $rname= $this->uname;
         $diff_price = round($diff_weight*$cg['gold_price']+$diff_weight*$cg['teach_fee'],2);
 
         //如果有未处理的工差单,不允许创建新的
@@ -751,9 +811,9 @@ class Purch extends Base
             if($item>0){
 
                 $sto = ["order_code"=>$cgdNo,"status"=>1,"action_remark"=>'',"action_type"=>"create"];
-                ActionLog::logAdd($this->post['token'],$sto,"CGGCD",1,$data);
-                $process=["order_code"=>$cgdNo,"order_id"=>$item,"order_status"=>1,"order_type"=>'CGGCD',"before_status"=>1];
-                ProcessOrder::AddProcess($this->post['token'],$process);
+                ActionLog::logAdd(['id'=>$rid,'nickname'=>$rname],$sto,"CGGCD",1,$data);
+                $process=["order_code"=>$cgdNo,"order_id"=>$item,"order_status"=>1,"order_type"=>'CGGCD',"before_status"=>1,'holder_id'=>$rid];
+                ProcessOrder::AddProcess(['id'=>$rid,'nickname'=>$rname],$process);
 
                 $update_standing_book_data = [
                     'cgd_diff_id' => $item,//采购工差单id
@@ -795,7 +855,7 @@ class Purch extends Base
                     }
                     $sto = ["order_code"=>$orderCode['orderCode'],"status"=>1,"action_remark"=>'',"action_type"=>"create"];
                     ActionLog::logAdd($this->post['token'],$sto,"XSGCD",1,$data);
-                    $process=["order_code"=>$orderCode['orderCode'],"order_id"=>$cgd,"order_status"=>1,"order_type"=>'XSGCD',"before_status"=>1];
+                    $process=["order_code"=>$orderCode['orderCode'],"order_id"=>$cgd,"order_status"=>1,"order_type"=>'XSGCD',"before_status"=>1,'holder_id'=>$order['apply_id']];
                     ProcessOrder::AddProcess($this->post['token'],$process);
 
                     $update_standing_book_data['sale_diff_id']=$cgd;//工差单id
@@ -983,10 +1043,10 @@ class Purch extends Base
                         }
                     }
                 }
-                $sto = ["order_code"=>$dio['cgdNo'],"status"=>1,"action_remark"=>'',"action_type"=>"create"];
-                ActionLog::logAdd($this->post['token'],$sto,"CGGCD",$status,$this->post);
-                $process=["order_code"=>$dio['cgdNo'],"order_id"=>$dio['id'],"order_status"=>$status,"order_type"=>'CGGCD',"before_status"=>1];
-                ProcessOrder::AddProcess($this->post['token'],$process);
+                $sto = ["order_code" => $dio['cgdNo'], "status" => 1, "action_remark" => '', "action_type" => "create"];
+                ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $sto, "CGGCD", $status, $this->post);
+                $process = ["order_code" => $dio['cgdNo'], "order_id" => $dio['id'], "order_status" => $status, "order_type" => 'CGGCD', "before_status" => 1, 'holder_id' => $dio['apply_id']];
+                ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $process);
                 Db::commit();
                 return error_show(0,"更新成功");
             }else{
@@ -1115,7 +1175,7 @@ class Purch extends Base
             unset($value['order_type']);
 
         }
-   
+
         $headerArr = array_keys($list[0]);
         excelSave('采购单导出' . date('YmdHis'), $headerArr, $list);
     }

+ 322 - 160
app/admin/controller/Purchin.php

@@ -1,11 +1,14 @@
 <?php
 namespace app\admin\controller;
 
+use app\abutment\model\SupplierRelationUser as SupplierRelationUserModel;
+use app\abutment\model\SupplierUser as SupplierUserModel;
 use app\admin\model\ActionLog;
 use app\admin\model\DataGroup as DataGroupModel;
 use app\admin\model\GoodLog;
-use app\admin\model\ProcessOrder;
+use app\admin\model\GoodStockInfo;use app\admin\model\ProcessOrder;
 use app\BaseController;
+use think\Exception;
 use think\facade\Db;
 use think\App;
 
@@ -94,6 +97,7 @@ class Purchin extends Base
         $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
         if ($company_name !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($company_name)];
 
+        //$count = Db::name('purchease_in')->alias('a')->join("purchease_order b","b.cgdNo=a.cgdNo","left")
         $count = Db::name('purchease_in')
             ->alias('a')
             ->join("purchease_order b","b.cgdNo=a.cgdNo","left")
@@ -106,6 +110,7 @@ class Purchin extends Base
         $list = Db::name('purchease_in')
             ->alias('a')
             ->join("purchease_order b","b.cgdNo=a.cgdNo","left")
+            ->leftJoin('supplier sip', 'sip.code=b.supplierNo')
             ->leftJoin("warehouse_info c","a.wsm_code=c.wsm_code")
             ->leftJoin("depart_user u", "u.uid=a.apply_id AND u.is_del=0")
             ->where($where)
@@ -186,11 +191,8 @@ class Purchin extends Base
            return error_show(1005,"采购单未发货");
        }
 
-        $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 不能为空");
-//       }
+       $wsm_in_code = makeNo("CF");
+       $bn_code = makeNo("BN");
        $wsminfo = Db::name("warehouse_info")->where(["wsm_code"=>$cgdinfo['wsm_code'],"is_del"=>0])->find();
        if(empty($wsminfo)){
            return error_show(1004,"未找到仓库信息");
@@ -202,11 +204,11 @@ class Purchin extends Base
             return error_show(1004,"参数 sendtype 不能为空");
         }
 
-        $data = GetUserInfo($this->post['token']);
-        if((!empty($data) && $data['code']!=0) ||empty($data) ){
-            return error_show($data['code'],$data['message']);
-        }
-        $userinfo = $data['data'];
+//        $data = GetUserInfo($this->post['token']);
+//        if((!empty($data) && $data['code']!=0) ||empty($data) ){
+//            return error_show($data['code'],$data['message']);
+//        }
+//        $userinfo = $data['data'];
         $post_company = isset($this->post['post_company'])&&$this->post['post_company']!="" ? trim($this->post['post_company']):"";
         $post_code = isset($this->post['post_code'])&&$this->post['post_code']!="" ? trim($this->post['post_code']):"";
         $post_fee = isset($this->post['post_fee'])&&$this->post['post_fee']!="" ? $this->post['post_fee']:"0";
@@ -221,24 +223,13 @@ class Purchin extends Base
         if($send_num>$cgdinfo['wsend_num']-$wsmin_num){
             return error_show(1009,"采购单剩余未发货数量不足");
         }
-//        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 || $cgdinfo['order_type']!=1){
             $status=4;
         }
         $orin = [
             "wsm_in_code"=>$wsm_in_code,
             "cgdNo"=>$cgdNo,
+            "bnCode"=>$bn_code,
             "wsm_code"=>$cgdinfo['wsm_code'],
             "wsm_reaper"=>isset($recep)&& $recep['wsm_name']!=''? $recep['wsm_name']:"",
             "send_num"=>$send_num,
@@ -246,8 +237,8 @@ class Purchin extends Base
             "post_code"=>$post_code,
             "post_fee"=>$post_fee,
             "sendtime"=>$post_time,
-            "apply_id"=>$userinfo['id'],
-            "apply_name"=>$userinfo['nickname'],
+            "apply_id"=>$this->uid,
+            "apply_name"=>$this->uname,
             "wait_num"=>0,
             "wsm_num"=>0,
             "sendtype"=>$sendtype,
@@ -260,14 +251,38 @@ class Purchin extends Base
             $win = Db::name("purchease_in")->insert($orin,true);
             if($win){
                 $sto = ["order_code"=>$wsm_in_code,"status"=>$status,"action_remark"=>'',"action_type"=>"edit"];
-                ActionLog::logAdd($this->post['token'],$sto,"RKD",$status,$this->post);
-                $process=["order_code"=>$wsm_in_code,"order_id"=>$win,"order_status"=>$status,"order_type"=>'RKD',"before_status"=>$status];
-                ProcessOrder::AddProcess($this->post['token'],$process);
+                ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$sto,"RKD",$status,$this->post);
+                $process=["order_code"=>$wsm_in_code,"order_id"=>$win,"order_status"=>$status,"order_type"=>'RKD',"before_status"=>$status,'holder_id' => $orin['apply_id']];
+                ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process);
                 $order = ["order_code"=>$cgdNo,"status"=>$cgdinfo['status'],"action_remark"=>'',"action_type"=>"edit"];
 
                 //维护台账信息
                 Db::execute("UPDATE `wsm_standing_book` SET `wsm_in_code`=CONCAT(IFNULL(`wsm_in_code`,''),',{$wsm_in_code}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE `cgdNo`='{$cgdNo}'");
 
+
+                $is_stock = Db::name('good_basic')
+                    ->where(['is_del'=>0,'spuCode'=>$cgdinfo['spuCode']])
+                    ->value('is_stock');
+                if($is_stock == 1){
+                    //库存品,只能由库管操作
+                    $own_roleid = Db::name('user_role')->where(['is_del' => 0, 'status' => 1, 'uid' => $this->uid])->value('roleid');
+                    if (!in_array($own_roleid, config('app.wsm_cgder_role'))) throw new Exception('只能由库管人员操作');
+                }else{
+                    //非库存品,只能由供应商负责人操作(开通账号的不能操作)
+                    //判断该供应商是否开通账号
+                    //好像status==4里面的判断没用了,但是没时间修改
+                    $res = SupplierRelationUserModel::field('id')
+                        ->where(['is_del' => SupplierUserModel::$is_del_normal, 'supplierNo' => $cgdinfo['supplierNo'], 'status' => SupplierUserModel::$status_normal])
+                        ->findOrEmpty()
+                        ->isEmpty();
+                    if(!$res) throw new Exception('供应商已开通账号,只能由供应商端操作');
+
+                    $personid = Db::name('supplier')
+                        ->where('code',$cgdinfo['supplierNo'])
+                        ->value('personid');
+                    if ($this->uid != $personid) throw new Exception('只能由供应商负责人操作');
+                }
+
                 if($status==1){
                             Db::commit();
                             return app_show(0,'新建成功',["wsm_in_code"=>$wsm_in_code]);
@@ -295,35 +310,25 @@ class Purchin extends Base
                             "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;
-//                    if($good['presale_stock']>0){
-//                        if($good['presale_stock']>=$send_num){
-//                            $good['presale_stock']-=$send_num;
-//                            $good['wait_out_stock']+=$send_num;
-//                        }else{
-//                            $good['presale_stock']=0;
-//                            $good['usable_stock']+=$send_num-$good['presale_stock'];
-//                            $good['wait_out_stock']+=$good['presale_stock'];
-//                        }
-//                    }else{
-                        $good['usable_stock']+=$send_num;
-               //     }
-
+                    $good['usable_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);
+                    $stockid=$good['id']?? Db::name("good_stock")->getLastInsID();
                     //商品变动日志表,good_log_code字段存储采购单单号
-                    $good_data[]=['good_log_code'=>$wsm_in_code,"stock_id"=>isset($good['id'])? $good['id']:Db::name("good_stock")->getLastInsID(),"type"=>1,'stock'=>$send_num,"stock_name"=>"usable_stock"];
-                    $good_data[]=['good_log_code'=>$wsm_in_code,"stock_id"=>isset($good['id'])? $good['id']:Db::name("good_stock")->getLastInsID(),"type"=>2,'stock'=>$send_num,"stock_name"=>"wait_in_stock"];
+                    $good_data[]=['good_log_code'=>$wsm_in_code,"stock_id"=>$stockid,"type"=>1,'stock'=>$send_num,"stock_name"=>"usable_stock"];
+                    $good_data[]=['good_log_code'=>$wsm_in_code,"stock_id"=>$stockid,"type"=>2,'stock'=>$send_num,"stock_name"=>"wait_in_stock"];
                     if($upd){
-                        GoodLog::LogAdd($this->post['token'],$good_data,'RKD');
+                    	GoodLog::LogAdd(['id'=>$this->uid,'nickname'=>$this->uname],$good_data,'RKD');
+                        //todo:: 新增bn编号库存数据修改
                         if($cgdinfo['order_type']==1){
+                        	$bnin=GoodStockInfo::AddBn($stockid,$bn_code,$send_num,$cgdinfo['good_price']);
+	                        if($bnin==false){
+	                            Db::rollback();
+	                            return error_show(1004,"库存bn数据新增失败");
+	                        }
                             $bk =Db::name("order_bk")->where(['cgdNo'=>$cgdinfo['cgdNo']])->find();
                             if($bk==false){
                                 $bk=[
@@ -355,8 +360,7 @@ class Purchin extends Base
                         if($cgdinfo['send_status']==3 && $cgdinfo['order_type']!=1){
                             $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();
+                                $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')]);
@@ -364,21 +368,68 @@ class Purchin extends Base
                                         Db::rollback();
                                         return error_show(1004,"出库单出库失败");
                                     }else{
+
+                                        //查询是否有非库存品订单
+                                        $is_stock = Db::name('sale')
+                                            ->where([
+                                                ['is_del','=',0],
+                                                ['orderCode','in',array_column($out,'orderCode')]
+                                            ])->column('is_stock','orderCode');
+
+                                        $supplier = Db::name('supplier')
+                                            ->field('person,personid')
+                                            ->where(['code'=>$cgdinfo['supplierNo'],'is_del'=>0])
+                                            ->findOrEmpty();
+
                                         foreach ($out as $k => $v_outCode) {
-                                            //修改状态,添加待办
-                                            ActionLog::logAdd($this->post['token'], [
+                                            ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
                                                 "order_code" => $v_outCode['outCode'],//出库单号
                                                 "status" => 0,//这里的status是之前的值
                                                 "action_remark" => '',//备注
                                                 "action_type" => "status"//新建create,编辑edit,更改状态status
                                             ], "CKD", 1, $this->post);
 
-                                            ProcessOrder::AddProcess($this->post['token'], [
-                                                "order_type" => 'CKD',
-                                                "order_code" => $v_outCode['outCode'],//出库单号
-                                                "order_id" => $v_outCode['id'],
-                                                "order_status" => 1,"before_status"=>0
-                                            ]);
+                                            if ($is_stock[$v_outCode['orderCode']] == 1) {
+                                                //库存品,推给库管和库管-张凯旋
+                                                $roleid = config('app.wsm_cgder_role');
+                                                $uids = Db::name('user_role')
+                                                    ->where('is_del', 0)
+                                                    ->whereIn('roleid', $roleid)
+                                                    ->column('uid');
+                                                ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
+                                                    "order_type" => 'CKD',
+                                                    "order_code" => $v_outCode['outCode'],//出库单号
+                                                    "order_id" => $v_outCode['id'],
+                                                    "order_status" => 1,
+                                                    "before_status" => 0,
+//                                                    'wait_id' => $supplier['personid'],
+//                                                    'wait_name' => $supplier['person'],
+//                                                    'holder_id' => $supplier['personid'],
+                                                    'handle_user_list' => implode(',', $uids)
+                                                ]);
+                                            } elseif ($is_stock[$v_outCode['orderCode']] == 0 || $cgdinfo['order_type'] = 3) {
+                                                //非库存品和采返商品,推给供应商负责人
+                                                ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
+                                                    "order_type" => 'CKD',
+                                                    "order_code" => $v_outCode['outCode'],//出库单号
+                                                    "order_id" => $v_outCode['id'],
+                                                    "order_status" => 1,
+                                                    "before_status" => 0,
+                                                    'wait_id' => $supplier['personid'],
+                                                    'wait_name' => $supplier['person'],
+                                                    'holder_id' => $supplier['personid'],
+                                                ]);
+                                            } else {
+                                                ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
+                                                    "order_type" => 'CKD',
+                                                    "order_code" => $v_outCode['outCode'],//出库单号
+                                                    "order_id" => $v_outCode['id'],
+                                                    "order_status" => 1,
+                                                    "before_status" => 0,
+                                                    'holder_id' => $v_outCode['apply_id']
+                                                ]);
+                                            }
+
                                         }
                                     }
                                     $good1 = Db::name("good_stock")->where(["wsm_code"=>$cgdinfo['wsm_code'], "spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->find();
@@ -400,9 +451,11 @@ class Purchin extends Base
                                         Db::rollback();
                                         return error_show(1004,"库存数量更新失败");
                                     }
-                                    $good_data[]=['good_log_code'=>$wsm_in_code,"stock_id"=>isset($good['id'])?$good['id']:Db::name("good_stock")->getLastInsID(),"type"=>1,'stock'=>$send_num,"stock_name"=>"wait_out_stock"];
-                                    $good_data[]=['good_log_code'=>$wsm_in_code,"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');
+                                    $stockid= isset($good['id'])?$good['id']:Db::name("good_stock")->getLastInsID();
+
+                                    $good_data[]=['good_log_code'=>$wsm_in_code,"stock_id"=>$stockid,"type"=>1,'stock'=>$send_num,"stock_name"=>"wait_out_stock"];
+                                    $good_data[]=['good_log_code'=>$wsm_in_code,"stock_id"=>$stockid,"type"=>1,'stock'=>$send_num,"stock_name"=>"usable_stock"];
+                                    GoodLog::LogAdd(['id'=>$this->uid,'nickname'=>$this->uname],$good_data,'RKD');
                                     $sendp=Db::name("order_send")->where(["cgdNo"=>$cgdNo,"outCode"=>$send,"status"=>1])->save (["status"=>2]);
                                     if($sendp==false){
                                         Db::rollback();
@@ -411,9 +464,38 @@ class Purchin extends Base
                                 }
                             }
                         }
-                        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',"before_status"=>$order['status']];
-                        ProcessOrder::AddProcess($this->post['token'],$process);
+
+                        ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$order,"CGD", $cgdinfo['status'],$cgdinfo);
+
+
+                        $personid = Db::name('supplier')
+                            ->where('is_del',0)
+                            ->where('code',$cgdinfo['supplierNo'])
+                            ->value('personid');
+
+                        if($cgdinfo['status']==1 || $cgdinfo['status']==2){
+
+                            $is_stock = Db::name('good_basic')
+                                ->where(['is_del'=>0,'spuCode'=>$cgdinfo['spuCode']])
+                                ->value('is_stock');
+                            if($is_stock==1){
+                                //库存品,推给31库管人员、41库管-张凯旋
+                                $uid = Db::name('user_role')
+                                    ->where([
+                                        ['is_del', '=', 0],
+                                        ['roleid', 'in', [31, 41]],
+                                        ['status', '=', 1]
+                                    ])->column('uid');
+                                if(!in_array($this->uid,$uid)) throw new Exception('库存品订单只能由库管人员操作');
+                                $process = ["order_code" => $cgdNo, "order_id" => $cgdinfo['id'], "order_status" => $cgdinfo['status'], "order_type" => 'CGD', "before_status" => $order['status'], 'holder_id' => $personid,'handle_user_list'=>implode(',', $uid)];
+
+                            }elseif ($is_stock==0 || $cgdinfo['order_type']==3){
+                                if($this->uid != $personid)throw new Exception('非库存品和采返商品只能由供应商负责人操作');
+                                $process = ["order_code" => $cgdNo, "order_id" => $cgdinfo['id'], "order_status" => $cgdinfo['status'], "order_type" => 'CGD', "before_status" => $order['status'], 'holder_id' => $personid,'handle_user_list'=>$personid];   //非库存品和采返商品,推给供应商负责人
+                            }
+                        }else $process = ["order_code" => $cgdNo, "order_id" => $cgdinfo['id'], "order_status" => $cgdinfo['status'], "order_type" => 'CGD', "before_status" => $order['status'], 'holder_id' => $personid];
+                        
+                        ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process);
                         Db::commit();
                         return app_show(0,'商品入库成功',["wsm_in_code"=>$wsm_in_code]);
                     }else{
@@ -428,7 +510,7 @@ class Purchin extends Base
             return error_show(1004,"新建失败");
         }catch (\Exception $e){
             Db::rollback();
-            return error_show(1004, $e->getMessage() . '|' . $e->getFile() . '|' . $e->getLine());
+            return error_show(1004, $e->getMessage());
         }
     }
 
@@ -538,7 +620,7 @@ class Purchin extends Base
             $up =Db::name("purchease_in")->save($info);
             if($up){
                 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',"before_status"=>$order['status']];
+                $process=["order_code"=>$info['wsm_in_code'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'RKD',"before_status"=>$order['status'],'holder_id' => $info['apply_id']];
                 ProcessOrder::AddProcess($this->post['token'],$process);
                 if(!empty($error_list)){
                     $data=[];
@@ -600,7 +682,7 @@ class Purchin extends Base
             $update = Db::name("purchease_in")->save($info);
             if($update){
                 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',"before_status"=>$order['status']];
+                $process=["order_code"=>$info['wsm_in_code'],"order_id"=>$info['id'],"order_status"=>$status,"order_type"=>'RKD',"before_status"=>$order['status'],'holder_id' => $info['apply_id']];
                 ProcessOrder::AddProcess($this->post['token'],$process);
                 if($status==0){
                     $cgdinfo=Db::name("purchease_order")->where(['cgdNo'=>$info['cgdNo'],"is_del"=>0])->find();
@@ -617,8 +699,38 @@ class Purchin extends Base
                     $up=Db::name("purchease_order")->save($cgdinfo);
                     if($up){
                         ActionLog::logAdd($this->post['token'],$order,"CGD", $cgdinfo['status'],$cgdinfo);
-                        $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status']];
-                        ProcessOrder::AddProcess($this->post['token'],$process);
+
+                        if($cgdinfo['status']==1  || $cgdinfo['status']==2){
+//                            $orderinfo = Db::name('sale')
+//                                ->alias('a')
+//                                ->field('a.id,a.orderCode,a.is_stock,a.order_type,a.cgderid')
+//                                ->leftJoin('order_num b','b.orderCode=a.orderCode')
+//                                ->where([
+//                                    'a.is_del'=>0,
+//                                    'b.cgdNo'=>$cgdinfo['cgdNo'],
+//                                ])->findOrEmpty();
+                            $is_stock = Db::name('good_basic')
+                                ->where(['is_del'=>0,'spuCode'=>$cgdinfo['spuCode']])
+                                ->value('is_stock');
+
+                            if($is_stock==1){
+                                //库存品,推给31库管人员、41库管-张凯旋
+                                $uid = Db::name('user_role')
+                                    ->where([
+                                        ['is_del', '=', 0],
+                                        ['roleid', 'in', [31, 41]],
+                                        ['status', '=', 1]
+                                    ])->column('uid');
+                                if(!in_array($this->uid,$uid)) throw new Exception('库存品订单只能由库管人员操作');
+                                $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0),'handle_user_list'=>implode(',', $uid)];
+                            }elseif ($is_stock==0 || $cgdinfo['order_type']==3) {
+                                $holder_id = Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0);
+                                if($this->uid != $holder_id)throw new Exception('非库存品和采返商品只能由供应商负责人操作');
+                                $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>$holder_id,'handle_user_list'=>$holder_id];
+                            }//非库存品和采返商品,推给供应商负责人
+                        }else $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0)];
+
+                        ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $process);
                         Db::commit();
                         return app_show(0,'取消成功');
                     }else{
@@ -641,7 +753,36 @@ class Purchin extends Base
                     $up=Db::name("purchease_order")->save($cgdinfo);
                     if($up){
                         ActionLog::logAdd($this->post['token'],$order,"CGD", $cgdinfo['status'],$cgdinfo);
-                        $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status']];
+
+
+                        if($cgdinfo['status'] == 1  || $cgdinfo['status']==2){
+//                            $orderinfo = Db::name('sale')
+//                                ->alias('a')
+//                                ->field('a.id,a.orderCode,a.is_stock,a.order_type,a.cgderid')
+//                                ->leftJoin('order_num b','b.orderCode=a.orderCode')
+//                                ->where([
+//                                    'a.is_del'=>0,
+//                                    'b.cgdNo'=>$cgdinfo['cgdNo'],
+//                                ])->findOrEmpty();
+                            $is_stock = Db::name('good_basic')
+                                ->where(['is_del'=>0,'spuCode'=>$cgdinfo['spuCode']])
+                                ->value('is_stock');
+                            if($is_stock==1){
+                                //库存品,推给31库管人员、41库管-张凯旋
+                                $uid = Db::name('user_role')
+                                    ->where([
+                                        ['is_del', '=', 0],
+                                        ['roleid', 'in', [31, 41]],
+                                        ['status', '=', 1]
+                                    ])->column('uid');
+                                if(!in_array($this->uid,$uid)) throw new Exception('库存品订单只能由库管人员操作');
+                                $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0),'handle_user_list'=>implode(',', $uid)];
+                            }elseif ($is_stock==0 || $cgdinfo['order_type']==3) {
+                                $holder_id = Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0);
+                                if($this->uid != $holder_id)throw new Exception('非库存品和采返商品只能由供应商负责人操作');
+                                $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>$holder_id,'handle_user_list'=>$holder_id];
+                            }//非库存品和采返商品,推给供应商负责人
+                        }else $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0)];
                         ProcessOrder::AddProcess($this->post['token'],$process);
                         Db::commit();
                         return app_show(0,'发货成功');
@@ -668,7 +809,35 @@ class Purchin extends Base
                         return error_show(1002,"发货失败");
                     }
                     ActionLog::logAdd($this->post['token'],$order,"CGD", $cgdinfo['status'],$cgdinfo);
-                    $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status']];
+
+                    if($cgdinfo['status']==1 || $cgdinfo['status']==2){
+//                        $orderinfo = Db::name('sale')
+//                            ->alias('a')
+//                            ->field('a.id,a.orderCode,a.is_stock,a.order_type,a.cgderid')
+//                            ->leftJoin('order_num b','b.orderCode=a.orderCode')
+//                            ->where([
+//                                'a.is_del'=>0,
+//                                'b.cgdNo'=>$cgdinfo['cgdNo'],
+//                            ])->findOrEmpty();
+                        $is_stock = Db::name('good_basic')
+                            ->where(['is_del'=>0,'spuCode'=>$cgdinfo['spuCode']])
+                            ->value('is_stock');
+                        if($is_stock==1){
+                            //库存品,推给31库管人员、41库管-张凯旋
+                            $uid = Db::name('user_role')
+                                ->where([
+                                    ['is_del', '=', 0],
+                                    ['roleid', 'in', [31, 41]],
+                                    ['status', '=', 1]
+                                ])->column('uid');
+                            if(!in_array($this->uid,$uid)) throw new Exception('库存品订单只能由库管人员操作');
+                            $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0),'handle_user_list'=>implode(',', $uid)];
+                        }elseif ($is_stock==0 || $cgdinfo['order_type']==3) {
+                            $holder_id = Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0);
+                            if($this->uid != $holder_id)throw new Exception('非库存品和采返商品只能由供应商负责人操作');
+                            $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>$holder_id,'handle_user_list'=>$holder_id];
+                        }//非库存品和采返商品,推给供应商负责人
+                    }else $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0)];
                     ProcessOrder::AddProcess($this->post['token'],$process);
 
                     $good = Db::name("good_stock")->where(["wsm_code"=>$info['wsm_code'], "spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->find();
@@ -690,29 +859,22 @@ class Purchin extends Base
                     }else{
                         $order = ["order_code"=>$good['spuCode'],"status"=>1,"action_remark"=>'', "action_type"=>"edit"];
                     }
-//                    $good['usable_stock']+=$info['wsm_num'];
                     $good['wait_in_stock']-=$info['wsm_num'];
-//                    if($good['presale_stock']>0){
-//                        if($good['presale_stock']>=$info['wsm_num']){
-//                            $good['presale_stock']-=$info['wsm_num'];
-//                            $good['wait_out_stock']+$info['wsm_num'];
-//                        }else{
-//                            $good['presale_stock']=0;
-//                            $good['usable_stock']+=$info['wsm_num']-$good['presale_stock'];
-//                            $good['wait_out_stock']+=$good['presale_stock'];
-//                        }
-//                    }else{
-                        $good['usable_stock']+=$info['wsm_num'];
-          //          }
-
+					$good['usable_stock']+=$info['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);
+                    $stockid=$good['id']?? Db::name("good_stock")->getLastInsID();
                     //商品变动日志表,good_log_code字段存储入库单编号
                     $good_data[] = ['good_log_code' => $incode, "stock_id" => isset($good['id']) ? $good['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1, 'stock' => $info['wsm_num'], "stock_name" => "usable_stock"];
                     $good_data[] = ['good_log_code' => $incode, "stock_id" => isset($good['id']) ? $good['id'] :
                         Db::name("good_stock")->getLastInsID(), "type" => 2, 'stock' => $info['wsm_num'], "stock_name" => "wait_in_stock"];
                     if($upd){
+                    	$bnin=GoodStockInfo::AddBn($stockid,$info['bnCode'],$info['wsm_num'],$cgdinfo['good_price']);
+                    	if($bnin==false){
+                    		Db::rollback();
+                            return error_show(1004,"库存bn数据新增失败");
+                    	}
                         GoodLog::LogAdd($this->post['token'],$good_data,'RKD');
                         Db::commit();
                         return app_show(0,'商品入库成功');
@@ -805,7 +967,35 @@ class Purchin extends Base
                     return error_show(1002,"发货失败");
                 }
                 ActionLog::logAdd($this->post['token'],$order,"CGD", $cgdinfo['status'],$cgdinfo);
-                $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status']];
+
+                if($cgdinfo['status']==1 || $cgdinfo['status']==2){
+//                    $orderinfo = Db::name('sale')
+//                        ->alias('a')
+//                        ->field('a.id,a.orderCode,a.is_stock,a.order_type,a.cgderid')
+//                        ->leftJoin('order_num b','b.orderCode=a.orderCode')
+//                        ->where([
+//                            'a.is_del'=>0,
+//                            'b.cgdNo'=>$cgdinfo['cgdNo'],
+//                        ])->findOrEmpty();
+                    $is_stock = Db::name('good_basic')
+                        ->where(['is_del'=>0,'spuCode'=>$cgdinfo['spuCode']])
+                        ->value('is_stock');
+                    if($is_stock==1){
+                        //库存品,推给31库管人员、41库管-张凯旋
+                        $uid = Db::name('user_role')
+                            ->where([
+                                ['is_del', '=', 0],
+                                ['roleid', 'in', [31, 41]],
+                                ['status', '=', 1]
+                            ])->column('uid');
+                        if(!in_array($this->uid,$uid)) throw new Exception('库存品订单只能由库管人员操作');
+                        $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0),'handle_user_list'=>implode(',', $uid)];
+                    }elseif ($is_stock==0 || $cgdinfo==3) {
+                        $holder_id = Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0);
+                        if($this->uid != $holder_id)throw new Exception('非库存品和采返商品只能由供应商负责人操作');
+                        $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>$holder_id,'handle_user_list'=>$holder_id];
+                    }//非库存品和采返商品,推给供应商负责人
+                }else $process=["order_code"=>$info['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0)];
                 ProcessOrder::AddProcess($this->post['token'],$process);
                 $good = Db::name("good_stock")->where(["wsm_code"=>$info['wsm_code'], "spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->find();
                 if(empty($good)) {
@@ -878,7 +1068,7 @@ class Purchin extends Base
 
             }
             ActionLog::logAdd($this->post['token'],$sto,"RKD", $info['status'],$this->post);
-            $process=["order_code"=>$info['wsm_in_code'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'RKD',"before_status"=>$sto['status']];
+            $process=["order_code"=>$info['wsm_in_code'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'RKD',"before_status"=>$sto['status'],'holder_id' => $info['apply_id']];
             ProcessOrder::AddProcess($this->post['token'],$process);
 
             //需要在详情页把相关退货记录原样取出来,所以这里把if去掉,所有记录都入purchease_return表
@@ -981,7 +1171,7 @@ class Purchin extends Base
                 if($sa){
                     $stn = ["order_code"=>$info['wsm_in_code'],"status"=>$ark,"action_remark"=>'',"action_type"=>"edit"];
                     ActionLog::logAdd($this->post['token'],$stn,"RKD",6,$info);
-                    $process=["order_code"=>$info['wsm_in_code'],"order_id"=>$info['id'],"order_status"=>6,"order_type"=>'RKD',"before_status"=>$stn['status']];
+                    $process=["order_code"=>$info['wsm_in_code'],"order_id"=>$info['id'],"order_status"=>6,"order_type"=>'RKD',"before_status"=>$stn['status'],'holder_id' => $info['apply_id']];
                     ProcessOrder::AddProcess($this->post['token'],$process);
 
                         $good = Db::name("good_stock")->where(["wsm_code"=>$info['wsm_code'], "spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->find();
@@ -996,27 +1186,12 @@ class Purchin extends Base
                                 "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['wait_in_stock']-=$return['wsm_num']+$return['return_num']-$return['reissue_num'];
-//                        if($good['presale_stock']>0){
-//                            if($good['presale_stock']>=$return['wsm_num']){
-//                                $good['presale_stock']-=$return['wsm_num'];
-//                                $good['wait_out_stock']+=$return['wsm_num'];
-//                            }else{
-//                                $good['presale_stock']=0;
-//                                $good['usable_stock']+=$return['wsm_num']-$good['presale_stock'];
-//                                $good['wait_out_stock']+=$good['presale_stock'];
-//                            }
-//                        }else{
-                            $good['usable_stock']+=$return['wsm_num'];
-//                        }
-//                        $good['usable_stock']+=$return['wsm_num'];
-//                        $good['wait_in_stock']-=$return['wsm_num']+$return['return_num']-$return['reissue_num'];
+                        $good['wait_in_stock']-=$return['wsm_num']+$return['return_num']-$return['reissue_num'];
+						$good['usable_stock']+=$return['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);
@@ -1024,8 +1199,14 @@ class Purchin extends Base
                             Db::rollback();
                             return error_show(1002,"库存更新失败");
                         }
-                        $good_data[]=['good_log_code' => $incode,"stock_id"=>isset($good['id'])? $good['id']:Db::name("good_stock")->getLastInsID(),"type"=>1, 'stock'=>$info['wsm_num'],"stock_name"=>"usable_stock"];
-                        $good_data[]=['good_log_code' => $incode,"stock_id"=>isset($good['id'])? $good['id']:Db::name("good_stock")->getLastInsID(),"type"=>2, 'stock'=>$good['wait_in_stock'],"stock_name"=>"wait_in_stock"];
+                        $stockid=$good['id']?? Db::name("good_stock")->getLastInsID();
+                        $bnin=GoodStockInfo::AddBn($stockid,$info['bnCode'],$return['wsm_num'],$cgdinfo['good_price']);
+                    	if($bnin==false){
+                    		Db::rollback();
+                            return error_show(1004,"库存bn数据新增失败");
+                    	}
+                        $good_data[]=['good_log_code' => $incode,"stock_id"=>$stockid,"type"=>1, 'stock'=>$info['wsm_num'],"stock_name"=>"usable_stock"];
+                        $good_data[]=['good_log_code' => $incode,"stock_id"=>$stockid,"type"=>2, 'stock'=>$good['wait_in_stock'],"stock_name"=>"wait_in_stock"];
                         GoodLog::LogAdd($this->post['token'],$good_data,'RKD');
 
                     $order = ["order_code"=>$cgdinfo['cgdNo'],"status"=>$cgdinfo['status'],"action_remark"=>'',"action_type"=>"edit"];
@@ -1044,7 +1225,6 @@ class Purchin extends Base
                         Db::rollback();
                         return error_show(1004,"采购单数量更新失败");
                     }
-
                     $bk =Db::name("order_bk")->where(['cgdNo'=>$cgdinfo['cgdNo']])->lock(true)->find();
                     if($bk==false){
                         $bk=[
@@ -1069,8 +1249,39 @@ class Purchin extends Base
                         return error_show(1004,"采购单数量更新失败");
                     }
                     ActionLog::logAdd($this->post['token'],$order,"CGD", $cgdinfo['status'],$cgdinfo);
-                    $process=["order_code"=>$cgdinfo['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status']];
+
+                    if($cgdinfo['status']==1 || $cgdinfo['status']==2){
+//                        $orderinfo = Db::name('sale')
+//                            ->alias('a')
+//                            ->field('a.id,a.orderCode,a.is_stock,a.order_type,a.cgderid')
+//                            ->leftJoin('order_num b','b.orderCode=a.orderCode')
+//                            ->where([
+//                                'a.is_del'=>0,
+//                                'b.cgdNo'=>$cgdinfo['cgdNo'],
+//                            ])->findOrEmpty();
+                        $is_stock = Db::name('good_basic')
+                            ->where(['is_del'=>0,'spuCode'=>$cgdinfo['spuCode']])
+                            ->value('is_stock');
+
+                        if($is_stock==1){
+                            //库存品,推给31库管人员、41库管-张凯旋
+                            $uid = Db::name('user_role')
+                                ->where([
+                                    ['is_del', '=', 0],
+                                    ['roleid', 'in', [31, 41]],
+                                    ['status', '=', 1]
+                                ])->column('uid');
+                            if(!in_array($this->uid,$uid)) throw new Exception('库存品订单只能由库管人员操作');
+                            $process=["order_code"=>$cgdinfo['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0),'handle_user_list'=>implode(',', $uid)];
+
+                        }elseif ($is_stock==0 || $cgdinfo['order_type']==3) {
+                            $holder_id = Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0);
+                            if($this->uid != $holder_id)throw new Exception('非库存品和采返商品只能由供应商负责人操作');
+                            $process=["order_code"=>$cgdinfo['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>$holder_id,'handle_user_list'=>$holder_id];//非库存品和采返商品,推给供应商负责人
+                        }
+                    }else $process=["order_code"=>$cgdinfo['cgdNo'],"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status'],'holder_id'=>Db::name('supplier')->where(['code' => $cgdinfo['supplierNo'], 'is_del' => 0])->value('personid', 0)];
                     ProcessOrder::AddProcess($this->post['token'],$process);
+
                     Db::commit();
                     return  app_show(0,"退货发货成功");
                 }else{
@@ -1147,55 +1358,6 @@ class Purchin extends Base
             $data[]=$value;
         }
         return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
-
     }
 
-//    public function ReturnStatus(){
-//        $incode = isset($this->post['wsm_in_code'])&&$this->post['wsm_in_code']!="" ? trim($this->post['wsm_in_code']) :"";
-//        if($incode==""){
-//            return error_show(1004,"参数wsm_in_code 不为空");
-//        }
-//        $info = Db::name("purchease_in")->where(['wsm_in_code'=>$incode,"is_del"=>0])->find();
-//        if(empty($info)){
-//            return error_show(1004,"未找到发货单数据");
-//        }
-//        $return = Db::name("purchease_return")->where(['wsm_in_code'=>$incode,"is_del"=>0])->find();
-//        if(empty($return)){
-//            return error_show(1004,"未找到数据");
-//        }
-//        if($info['status']<4){
-//            return error_show(1004,"入库单未完成");
-//        }
-//        $status = isset($this->post['status'])&&$this->post['status']!="" ?$this->post['status']:"";
-//        if($status==""){
-//            return error_show(1004,"参数status 不为空");
-//        }
-//        Db::startTrans();
-//        try{
-//            $data=[
-//                "status"=>$status,
-//                "updatetime"=>date("Y-m-d H:i:s")
-//            ];
-//            $up =Db::name("purchease_return")->where($return)->save($data);
-//            if($up){
-//                    $info['status']=$status==1?5:6;
-//                    $info['updatetime']=date("Y-m-d H:i:s");
-//                    $sa=Db::name("purchease_in")->save($info);
-//                    if($sa){
-//                        Db::commit();
-//                        return  app_show(0,"更新成功");
-//                    }else{
-//                        Db::rollback();
-//                        return  error_show(1004,"更新失败");
-//                    }
-//            }else{
-//                Db::rollback();
-//                return  error_show(1004,"更新失败");
-//            }
-//        }catch (\Exception $e){
-//            Db::rollback();
-//            return  error_show(1004,$e->getMessage());
-//        }
-//
-//    }
 }

+ 481 - 283
app/admin/controller/Reorder.php

@@ -5,7 +5,8 @@ namespace app\admin\controller;
 
 use app\admin\model\DataGroup as DataGroupModel;
 use app\admin\model\GoodLog;
-use app\admin\model\ProcessOrder;
+use app\admin\model\GoodStockInfo;use app\admin\model\ProcessOrder;
+use think\Exception;
 use think\facade\Db;
 use think\App;
 use app\admin\model\ActionLog;
@@ -86,6 +87,8 @@ class Reorder extends Base
                 "apply_name"=>$ri,
                 "cgderid"=>$goon['createrid'],
                 "cgder"=>$goon['creater'],
+                "person"=>$supplier['person']??'',
+                "person_id"=>$supplier['personid']??0,
                 "error_code"=>$errorCode,
                 "num"=>$thnum,
                 "total_fee"=>round($order['sale_price']*$thnum,2),
@@ -103,24 +106,11 @@ class Reorder extends Base
             if($create>0){
                 $stn = ["order_code"=>$returnCode,"status"=>0,"action_remark"=>'',"action_type"=>"create"];
                 ActionLog::logAdd($this->post['token'],$stn,"XSTHD",$in['status'],$in);
-                $process=["order_code"=>$returnCode,"order_id"=>$create,"order_status"=>$in['status'],"order_type"=>'XSTHD',"before_status"=>0];
+                $process=["order_code"=>$returnCode,"order_id"=>$create,"order_status"=>$in['status'],"order_type"=>'XSTHD',"before_status"=>0,'holder_id'=>$in['apply_id']];
                 ProcessOrder::AddProcess($this->post['token'],$process);
-
                 //维护台账信息
                 Db::execute("UPDATE `wsm_standing_book` SET `returnGoodCode`=CONCAT(IFNULL(`returnGoodCode`,''),',{$returnCode}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE `orderCode`='{$ordeCode}'");
 
-//                $rs = Db::name('standing_book')->where('orderCode', $ordeCode)->order('returnGoodCode')->find();
-//                if (!empty($rs)) {
-//                    if ($rs['returnGoodCode'] == '') Db::name('standing_book')->where('id', $rs['id'])->update(["returnGoodCode" => $returnCode, "updatetime" => date("Y-m-d H:i:s")]);
-//                    else {
-//                        unset($rs['id']);
-//                        $rs['standBookNo'] = makeNo('IO');
-//                        $rs['addtime'] = $rs['updatetime'] = date("Y-m-d H:i:s");
-//                        $rs['returnGoodCode'] = $returnCode;
-//                        Db::name('standing_book')->insert($rs);
-//                    }
-//                }
-
                 if($returnadr!=""){
                     $inf=[];
                     foreach ($returnadr as $val){
@@ -173,19 +163,20 @@ class Reorder extends Base
                                         Db::rollback();
                                         return error_show(1004, "地址发货单更新失败");
                                     }
-                                    $ordersend = Db::name("order_send")->where(["outCode" => $out['outCode']])->find();
-                                    if ($ordersend['send_num'] < $val['return_num']) {
-                                        Db::rollback();
-                                        return error_show(1004, "发货单发货数量不足");
-                                    }
-                                    $ordersend['send_num'] -= $val['return_num'];
-                                    $ordersend['status'] = $ordersend['send_num'] <= 0 ? 0 : 1;
-                                    $ordersend['updatetime'] = date("Y-m-d H:i:s");
-                                    $sendip = Db::name("order_send")->save($ordersend);
-                                    if ($sendip == false) {
-                                        Db::rollback();
-                                        return error_show(1004, "发货单更新失败");
-                                    }
+
+//                                    $ordersend = Db::name("order_send")->where(["outCode" => $out['outCode']])->find();
+//                                    if ($ordersend['send_num'] < $val['return_num']) {
+//                                        Db::rollback();
+//                                        return error_show(1004, "发货单发货数量不足");
+//                                    }
+//                                    $ordersend['send_num'] -= $val['return_num'];
+//                                    $ordersend['status'] = $ordersend['send_num'] <= 0 ? 0 : 1;
+//                                    $ordersend['updatetime'] = date("Y-m-d H:i:s");
+//                                    $sendip = Db::name("order_send")->save($ordersend);
+//                                    if ($sendip == false) {
+//                                        Db::rollback();
+//                                        return error_show(1004, "发货单更新失败");
+//                                    }
 
 //                                }
                         }
@@ -243,89 +234,135 @@ class Reorder extends Base
                         "order_status" =>$order['status'],"before_status"=>$lor
                     ]);
 
-                    $ordernum = Db::name("order_num")->where(['orderCode' => $ordeCode])->find();
-                    if ($ordernum == false) {
-                        Db::rollback();
-                        return error_show(1005, '未找到关联采购单');
-                    }
-                    $ordernum['send_num'] -= $thnum;
-                    $orderup = Db::name("order_num")->save($ordernum);
-                    if ($orderup == false) {
-                        Db::rollback();
-                        return error_show(1005, '关联数据更新失败');
-                    }
-                    $cgd = Db::name("purchease_order")->where(["cgdNo" => $ordernum['cgdNo'], "is_del" => 0])->find();
-                    if ($cgd == false) {
-                        Db::rollback();
-                        return error_show(1005, '未找到采购单数据');
-                    }
-                    $cgd['th_fee'] += round($cgd['good_price'] * $thnum, 2);
-                    $cgd['th_num'] += $thnum;
-                    $cgd['updatetime'] = date("Y-m-d H:i:s");
-                    $cgdup = Db::name("purchease_order")->save($cgd);
-                    if ($cgdup == false) {
-                        Db::rollback();
-                        return error_show(1005, '采购单数据更新失败');
-                    }
-                    if ($cgd['bkcode'] != "") {
-                        $bk = Db::name("purchease_order")->where(["bkcode" => $cgd['bkcode'], "order_type" => 1, "order_source" =>0, "is_del" => 0])
-                            ->find();
-                        if ($bk == false) {
-                            Db::rollback();
-                            return error_show(1005, '未找到备库单数据');
-                        }
-                        $orderbk = Db::name("order_bk")->where(['cgdNo' => $bk['cgdNo'], "is_del" => 0])->find();
-                        if ($orderbk == false) {
-                            Db::rollback();
-                            return error_show(1005, '备库单未完全入库');
-                        }
-                        $merge_num = Db::name("purchease_order")->where(["bkcode" => $bk['bkcode'], "order_type" =>
-                                1, "is_del" => 0])->where("order_source","<>",0)->field("sum(send_num)-sum(th_num) as num")
-                            ->find();
-
-                        $orderbk['balance_num'] = $orderbk['total_num'] - $merge_num['num'];
-                        $orderbk['merge_num'] = $merge_num['num'];
-                        $orderbk['updatetime'] = date("Y-m-d H:i:s");
-                        $orderbkup = Db::name("order_bk")->save($orderbk);
-                        if ($orderbkup == false) {
-                            Db::rollback();
-                            return error_show(1005, '备库单库存数据释放失败');
-                        }
-                    }
-                    $stock = Db::name("good_stock")->where(["spuCode" => $order['good_code'], 'wsm_code' => $cgd['wsm_code']])
+//                    $ordernum = Db::name("order_num")->where(['orderCode' => $ordeCode])->find();
+//                    if ($ordernum == false) {
+//                        Db::rollback();
+//                        return error_show(1005, '未找到关联采购单');
+//                    }
+//                    $ordernum['send_num'] -= $thnum;
+//                    $orderup = Db::name("order_num")->save($ordernum);
+//                    if ($orderup == false) {
+//                        Db::rollback();
+//                        return error_show(1005, '关联数据更新失败');
+//                    }
+//                    $cgd = Db::name("purchease_order")->where(["cgdNo" => $ordernum['cgdNo'], "is_del" => 0])->find();
+//                    if ($cgd == false) {
+//                        Db::rollback();
+//                        return error_show(1005, '未找到采购单数据');
+//                    }
+//                    $cgd['th_fee'] += round($cgd['good_price'] * $thnum, 2);
+//                    $cgd['th_num'] += $thnum;
+//                    $cgd['updatetime'] = date("Y-m-d H:i:s");
+//                    $cgdup = Db::name("purchease_order")->save($cgd);
+//                    if ($cgdup == false) {
+//                        Db::rollback();
+//                        return error_show(1005, '采购单数据更新失败');
+//                    }
+//                    if ($cgd['bkcode'] != "") {
+//                        $bk = Db::name("purchease_order")->where(["bkcode" => $cgd['bkcode'], "order_type" => 1, "order_source" =>0, "is_del" => 0])
+//                            ->find();
+//                        if ($bk == false) {
+//                            Db::rollback();
+//                            return error_show(1005, '未找到备库单数据');
+//                        }
+//                        $orderbk = Db::name("order_bk")->where(['cgdNo' => $bk['cgdNo'], "is_del" => 0])->find();
+//                        if ($orderbk == false) {
+//                            Db::rollback();
+//                            return error_show(1005, '备库单未完全入库');
+//                        }
+//                        $merge_num = Db::name("purchease_order")->where(["bkcode" => $bk['bkcode'], "order_type" =>
+//                                1, "is_del" => 0])->where("order_source","<>",0)->field("sum(send_num)-sum(th_num) as num")
+//                            ->find();
+//
+//                        $orderbk['balance_num'] = $orderbk['total_num'] - $merge_num['num'];
+//                        $orderbk['merge_num'] = $merge_num['num'];
+//                        $orderbk['updatetime'] = date("Y-m-d H:i:s");
+//                        $orderbkup = Db::name("order_bk")->save($orderbk);
+//                        if ($orderbkup == false) {
+//                            Db::rollback();
+//                            return error_show(1005, '备库单库存数据释放失败');
+//                        }
+//                    }
+
+					$saleinfo=Db::name("sale_info")->where([["orderCode","=",$ordeCode],["num",">",0]])->select()
+					->toArray();
+					if(empty($saleinfo)) {
+						$ordernum = Db::name("order_num")->where(['orderCode' => $ordeCode])->find();
+					        if ($ordernum == false) {
+					        	Db::rollback();
+					            return error_show(1005, '未找到关联采购单');
+					        }
+					         $cgd = Db::name("purchease_order")->where(["cgdNo" => $ordernum['cgdNo'], "is_del" => 0])->find();
+					        if ($cgd == false) {
+					        	Db::rollback();
+					            return error_show(1005, '未找到采购单数据');
+					        }
+					        $bn =makeNo("BN");
+					        $stock = Db::name("good_stock")->where(["spuCode" => $order['good_code'], 'wsm_code'=>$cgd['wsm_code'],"is_del"=>0,"status"=>1])->find();
+					        if($stock==false){
+					        	Db::rollback();
+								return error_show(1005, '商品库存数据未找到');
+					        }
+					        $stock['usable_stock']+=$thnum;
+		                    $stock['wait_out_stock'] -=$thnum;
+		                    $stock['updatetime'] = date("Y-m-d H:i:s");
+		                    $st_up = Db::name("good_stock")->save($stock);
+		                    if ($st_up == false) {
+		                        return error_show(1005, '可售商品入库失败');
+		                    }
+					        $yp=GoodStockInfo::AddBn($stock['id'],$bn,$thnum,$cgd['good_price']);
+					        if($yp==false){
+					        	Db::rollback();
+								return error_show(1005, '商品批次退货入库失败');
+					        }
+					}else{
+					$tempnum =$thnum;
+					foreach ( $saleinfo as $va){
+					if($tempnum ==0) break;
+					$stock = Db::name("good_stock")->where(["spuCode" => $order['good_code'], 'id' => $va['stockid']])
                         ->find();
-                    if (empty($stock)) {
-                        $stock = [
-                            "spuCode" => $order['good_code'],
-                            "wsm_code" => $cgd['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"),
-                        ];
-                    }
-//                    if($stock['presale_stock']>0){
-//                            if($stock['presale_stock']>=$thnum){
-//                                $stock['presale_stock']-=$thnum;
-//                            }else{
-//                                $stock['presale_stock']=0;
-//                                $stock['usable_stock']+=$thnum;
-//                                $stock['wait_out_stock'] -= ($thnum -$stock['presale_stock']);
-//                            }
-//                    }else{
-                        $stock['usable_stock']+=$thnum;
-                        $stock['wait_out_stock'] -= $thnum;
-              //      }
+					if($stock==false) {
+						Db::rollback();
+						return error_show(1005, '商品库存数据未找到');
+					}
+					if($va['num']>=$tempnum) {
+						$tnm = $tempnum;
+						$va['num']-= $tempnum;
+						$va['th_num']+= $tempnum;
+						$tempnum=0;
+					}else{
+						$tnm = $va['num'];
+						$tempnum -=$va['num'];
+						$va['th_num']+= $va['num'];
+						$va['num'] =0;
+					}
+                    $stock['usable_stock']+=$tnm;
+                    $stock['wait_out_stock'] -=$tnm;
                     $stock['updatetime'] = date("Y-m-d H:i:s");
                     $st_up = Db::name("good_stock")->save($stock);
                     if ($st_up == false) {
                         return error_show(1005, '可售商品入库失败');
                     }
-                    $good_data[]= ['good_log_code' => $returnCode, "stock_id" => isset($stock['id']) ? $stock['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1, 'stock' => $thnum, "stock_name" => "usable_stock"];
-                    $good_data[]= ['good_log_code' => $returnCode, "stock_id" => isset($stock['id']) ? $stock['id'] : Db::name("good_stock")->getLastInsID(), "type" => 2, 'stock' => $thnum, "stock_name" => "wait_out_stock"];
+					$ps = GoodStockInfo::AddBn($va['stockid'],$va['bnCode'],$tnm);
+                     if ($ps == false) {
+                        return error_show(1005, '商品批次退货入库失败');
+                    }
+                     $ret = GoodStockInfo::ReturnBn($returnCode,$va['id'],$tnm);
+                     if ($ret == false) {
+                        return error_show(1005, '商品批次退货入库失败');
+                    }
+                     $va['updatetime']=date("Y-m-d H:i:s");
+                     $sal= Db::name("sale_info")->save($va);
+					  if ($sal == false) {
+                        return error_show(1005, '商品批次退货入库失败');
+                    }
+                    $good_data[]= ['good_log_code' => $returnCode, "stock_id" => $va['stockid'], "type" => 1, 'stock' => $thnum, "stock_name" => "usable_stock"];
+                    $good_data[]= ['good_log_code' => $returnCode, "stock_id" => $va['stockid'], "type" => 2, 'stock' => $thnum, "stock_name" => "wait_out_stock"];
                     GoodLog::LogAdd($this->post['token'], $good_data, 'XSTHD');
+					}
+					}
+
+
                     $data=[
                         "orderCode"=>$ordeCode,
                         "th_type"=>1,
@@ -601,8 +638,7 @@ class Reorder extends Base
      * @throws \think\db\exception\ModelNotFoundException
      */
     public function exam(){
-        $code =  isset($this->post['returnCode']) && $this->post['returnCode'] !=="" ? trim($this->post['returnCode'])
-            :"";
+        $code =  isset($this->post['returnCode']) && $this->post['returnCode'] !=="" ? trim($this->post['returnCode']):"";
         if($code==""){
             return error_show(1004,"参数returnCode不能为空");
         }
@@ -656,10 +692,15 @@ class Reorder extends Base
             $info["updatetime"]=date("Y-m-d H:i:s");
             $up = Db::name("sale_return")->save($info);
             if($up) {
-                $process = ["order_code" => $code, "order_id" => $info['id'], "order_status" => $status,  "order_type"=>"XSTHD",'before_status'=>$temp];
-                ProcessOrder::AddProcess($this->post['token'], $process);
+
+                //如果是节点2(待专员审核),要将待办数据推给供应商负责人
+                if ($info['status'] == 2) $process = ["order_code" => $code, "order_id" => $info['id'], "order_status" => $status, "order_type" => "XSTHD", 'before_status' => $temp, 'wait_id' => $info['person_id'], 'wait_name' => $info['person']];
+                else $process = ["order_code" => $code, "order_id" => $info['id'], "order_status" => $status, "order_type" => "XSTHD", 'before_status' => $temp, 'holder_id' => $info['apply_id']];
+
+                ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $process);
+
                 $ste = ["order_code" => $code, "status" => $temp, "action_remark" => '', "action_type" => "status"];
-                ActionLog::logAdd($this->post['token'], $ste,  "XSTHD", $status, $info);
+                ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $ste, "XSTHD", $status, $info);
                 if ($status == 4) {
                     if ($info['is_addr'] == 1) {
                         if (isset($addr) && !empty($addr)) {
@@ -703,20 +744,6 @@ class Reorder extends Base
                                         Db::rollback();
                                         return error_show(1004, "地址发货单更新失败");
                                     }
-                                    $ordersend = Db::name("order_send")->where(["outCode" => $value['outCode']])->find();
-                                    if ($ordersend['send_num'] < $value['return_num']) {
-                                        Db::rollback();
-                                        return error_show(1004, "发货单发货数量不足");
-                                    }
-                                    $ordersend['send_num'] -= $value['return_num'];
-                                    $ordersend['status'] = $ordersend['send_num'] <= 0 ? 0 : 1;
-                                    $ordersend['updatetime'] = date("Y-m-d H:i:s");
-                                    $sendip = Db::name("order_send")->save($ordersend);
-                                    if ($sendip == false) {
-                                        Db::rollback();
-                                        return error_show(1004, "发货单更新失败");
-                                    }
-
                                 }
                             }
                         }
@@ -743,61 +770,9 @@ class Reorder extends Base
                             Db::rollback();
                             return error_show(1005, '销售单订单更新失败');
                         }
-                        $ordernum = Db::name("order_num")->where(['orderCode' => $info['orderCode']])->find();
-                        if ($ordernum == false) {
-                            Db::rollback();
-                            return error_show(1005, '未找到关联采购单');
-                        }
-                        $ordernum['send_num'] -= $info['num'];
-                        $orderup = Db::name("order_num")->save($ordernum);
-                        if ($orderup == false) {
-                            Db::rollback();
-                            return error_show(1005, '关联数据更新失败');
-                        }
-                        $cgd = Db::name("purchease_order")->where(["cgdNo" => $ordernum['cgdNo'], "is_del" => 0])->find();
-                        if ($cgd == false) {
-                            Db::rollback();
-                            return error_show(1005, '未找到采购单数据');
-                        }
-                        $cgd['th_fee'] += round($cgd['good_price'] * $info['num'], 2);
-                        $cgd['th_num'] += $info['num'];
-                        if($cgd['th_num']==$cgd['send_num']&& $cgd['wsend_num']==0){
-                            $cgd['status']=4;
-                        }
-                        $cgd['updatetime'] = date("Y-m-d H:i:s");
-                        $cgdup = Db::name("purchease_order")->save($cgd);
-                        if ($cgdup == false) {
-                            Db::rollback();
-                            return error_show(1005, '采购单数据更新失败');
-                        }
-                        if ($cgd['bkcode'] != "") {
-                            $bk = Db::name("purchease_order")->where(["bkcode" => $cgd['bkcode'], "order_type" => 1,"order_source"=>0, "is_del" => 0])
-                                ->find();
-                            if ($bk == false) {
-                                Db::rollback();
-                                return error_show(1005, '未找到备库单数据');
-                            }
-                            $orderbk = Db::name("order_bk")->where(['cgdNo' => $bk['cgdNo'], "is_del" => 0])->find();
-                            if ($orderbk == false) {
-                                Db::rollback();
-                                return error_show(1005, '备库单未完全入库');
-                            }
-                            $merge_num = Db::name("purchease_order")->where(["bkcode" => $bk['bkcode'], "order_type"
-                                => 1, "is_del" => 0])->where("order_source","<>",0)
-                                ->field("sum(send_num)-sum(th_num) as num")->find();
-
-                            $orderbk['balance_num'] = $orderbk['total_num'] - $merge_num['num'];
-                            $orderbk['merge_num'] = $merge_num['num'];
-                            $orderbk['updatetime'] = date("Y-m-d H:i:s");
-                            $orderbkup = Db::name("order_bk")->save($orderbk);
-                            if ($orderbkup == false) {
-                                Db::rollback();
-                                return error_show(1005, '备库单库存数据释放失败');
-                            }
-                        }
-                    } else {
 
-                        if ($info['is_th'] == 1) {
+                    }else{
+						if ($info['is_th'] == 1){
                             $orderinfo['th_num'] += $info['num'];
                             if($orderinfo['th_num']==$orderinfo['send_num']&& $orderinfo['wsend_num']==0){
                                 $orderinfo['status']=3;
@@ -875,6 +850,7 @@ class Reorder extends Base
                                 return error_show(1005, '可售商品入库失败');
                             }
 
+
                         } else {
                             $orderinfo['th_num'] += $info['num'];
                             if($orderinfo['th_num']==$orderinfo['send_num']&& $orderinfo['wsend_num']==0){
@@ -904,24 +880,35 @@ class Reorder extends Base
                                 Db::rollback();
                                 return error_show(1005, '未找到采购单数据');
                             }
-                            $stock = Db::name("good_stock")->where(["spuCode" => $info['good_code'], 'wsm_code' =>$cgd['wsm_code']])->find();
+
+                            $stock = Db::name("good_stock")->where(["spuCode" =>  $orderinfo['good_code'], 'wsm_code' =>$cgd['wsm_code']])->find();
                             if ($stock==false) {
                                 Db::rollback();
                                 return error_show(1005, '商品仓库未找到');
                             }
-                            if($stock['usable_stock']+$stock['wait_out_stock']<$info['num']){
-                                Db::rollback();
-                                return error_show(1005, '商品可用库存不足退回数量');
+                            if($info['is_all']==1){
+	                            if($stock['wait_in_stock']<$info['num']){
+	                                Db::rollback();
+	                                return error_show(1005, '商品可用库存不足退回数量');
+	                            }else{
+	                                    $stock['wait_in_stock']-= $info['num'];
+	                            }
                             }else{
+	                                if($stock['usable_stock']+$stock['wait_out_stock']<$info['num']){
+	                                Db::rollback();
+	                                return error_show(1005, '商品可用库存不足退回数量');
+	                            }else{
 
-                                if($stock['usable_stock']>$info['num']){
-                                    $stock['usable_stock'] -= $info['num'];
-                                }else{
-                                    $stock['usable_stock'] = 0;
-                                    $stock['wait_out_stock']-= $info['num']- $stock['usable_stock'] ;
-                                }
-                                $stock['total_stock']= $stock['usable_stock']+ $stock['wait_out_stock'];
+	                                if($stock['usable_stock']>$info['num']){
+	                                    $stock['usable_stock'] -= $info['num'];
+	                                }else{
+	                                    $stock['usable_stock'] = 0;
+	                                    $stock['wait_out_stock']-= $info['num']- $stock['usable_stock'] ;
+	                                }
+	                                $stock['total_stock']= $stock['usable_stock']+ $stock['wait_out_stock'];
+	                            }
                             }
+
                             $stock['updatetime'] = date("Y-m-d H:i:s");
                             $st_up = Db::name("good_stock")->save($stock);
                             if ($st_up == false) {
@@ -945,18 +932,71 @@ class Reorder extends Base
                         "order_status" =>$orderinfo['status'],"before_status"=>$lor
                     ]);
 
-                    if($orderinfo['is_stock'] == 1 || $info['is_th'] == 0){
-                        $wsmcode = $orderinfo['is_stock'] == 1 ? $cgd['wsm_code'] : $info['return_wsm'];
-                        if ($wsmcode == "") {
-                            Db::rollback();
-                            return error_show(1005, '未找到退货仓库');
+                    //对应采购单也要处理
+                    $holder_id = Db::name('supplier')->where(['code' => $cgd['supplierNo'], 'is_del' => 0])->value('personid', 0);
+                    if(in_array($cgd['status'],[1,2])){
+                        if($orderinfo['is_stock']==1){
+                            //库存品,推给31库管人员、41库管-张凯旋
+                            $uid = Db::name('user_role')
+                                ->where([
+                                    ['is_del', '=', 0],
+                                    ['roleid', 'in', [31, 41]],
+                                    ['status', '=', 1]
+                                ])->column('uid');
+                            if(!in_array($this->uid,$uid)) throw new Exception('库存品订单只能由库管人员操作');
+                            ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
+                                "order_type" => 'CGD',
+                                "order_code" => $cgd['cgdNo'],
+                                "order_id" => $cgd["id"],
+                                "order_status" => $cgd['status'],
+                                "before_status" => $lor,
+                                'holder_id' => $holder_id,
+                                'handle_user_list' => implode(',', $uid),
+                            ]);
+                        }elseif ($orderinfo['is_stock']==0 || $orderinfo['order_type']==3){
+                            if($this->uid != $holder_id)throw new Exception('非库存品和采返商品只能由供应商负责人操作');
+                            //非库存品和采返商品,推给供应商负责人
+                            ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
+                                "order_type" => 'CGD',
+                                "order_code" => $cgd['cgdNo'],
+                                "order_id" => $cgd["id"],
+                                "order_status" => $cgd['status'],
+                                "before_status" => $lor,
+                                'holder_id' => $holder_id,
+                                'handle_user_list' => $orderinfo['cgderid'],
+                            ]);
                         }
-                        //::todo 非库存品订单退货 采购单退货 虚拟仓如何减库存
+                    }else{
+                        ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
+                            "order_type" => 'CGD',
+                            "order_code" => $cgd['cgdNo'],
+                            "order_id" => $cgd["id"],
+                            "order_status" => $cgd['status'],
+                            "before_status" => $lor,
+                            'holder_id' => $holder_id
+                        ]);
+                    }
 
-                        $stock = Db::name("good_stock")->where(["spuCode" => $info['good_code'], 'wsm_code' => $wsmcode])->find();
+                    if($orderinfo['is_stock'] == 1 || $info['is_th'] == 0){
+
+                    	if ($orderinfo['order_type']!=1){
+                            if($orderinfo['order_type']==3){
+						          $goon = Db::name("good_zixun")->where(["spuCode"=>$orderinfo['good_code'],"is_del"=>0])->find();
+						          $isZx=1;
+						      }else {
+						          $goon = Db::name('good_basic')->where(['spuCode' => $orderinfo['good_code']])->find();
+						          $isZx=2;
+						      }
+				              $spuCode = $this->CheckGoodZx($goon,$isZx,$code);
+                                $wsmcode = $info['return_wsm'];
+		                        if ($wsmcode == "") {
+		                            Db::rollback();
+		                            return error_show(1005, '未找到退货仓库');
+		                        }
+						$stock = Db::name("good_stock")->where(["spuCode" => $spuCode, 'wsm_code' => $wsmcode])->find();
                         if (empty($stock)) {
                             $stock = [
-                                "spuCode" => $info['good_code'],
+                                "spuCode" => $spuCode,
                                 "wsm_code" => $wsmcode,
                                 "usable_stock" => 0,
                                 "wait_out_stock" => 0,
@@ -973,9 +1013,135 @@ class Reorder extends Base
                             Db::rollback();
                             return error_show(1005, '可售商品入库失败');
                         }
-                        $good_data = ['good_log_code' => $info['returnCode'], "stock_id" => isset($stock['id']) ? $stock['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1, 'stock' => $info['num'], "stock_name" => "usable_stock"];
+                        $stockid = isset($stock['id']) ? $stock['id'] : Db::name("good_stock")->getLastInsID();
+                        	$sabebn =Db::name("sale_info")->where(["orderCode"=>$orderinfo["orderCode"]])->select()->toArray();
+                            if(!empty($sabebn)){
+                        	$total_num =$info['num'];
+                        	foreach ($sabebn as $ve){
+                        		$tempnum=0;
+                        		if ($total_num==0) break;
+                        		if($total_num>=$ve['num']){
+                        			$tempnum = $ve['num'];
+                        			$total_num-=$ve['num'];
+									$ve['th_num']+=$ve['num'];
+                        			$ve['num']=0;
+                        		}else{
+                        		    $tempnum = $total_num;
+                        			$ve['num']-=$total_num;
+                        			$ve['th_num']+=$total_num;
+                        			$total_num=0;
+                        		}
+                        		$bnin=GoodStockInfo::AddBn($stockid,$ve['bnCode'],$tempnum,$ve['origin_price']);
+                        		if($bnin==false){
+                        			 Db::rollback();
+                                    return error_show(1005, '可售商品Bn库存数入库失败');
+                        		}
+                        		$ve['updatetime']=date("Y-m-d H:i:s");
+								$up=Db::name("sale_info")->save($ve);
+                        		if($up==false){
+                        			 Db::rollback();
+                                    return error_show(1005, '可售商品Bn库存数入库失败');
+                        		}
+								$bnin=GoodStockInfo::ReturnBn($info['returnCode'],$ve['id'],$tempnum);
+                        		if($bnin==false){
+                        			 Db::rollback();
+                                    return error_show(1005, '可售商品Bn库存数入库失败');
+                        		}
+                        	}
+                        }else{
+								$bn=makeNo("BN");
+								$bnin=GoodStockInfo::AddBn($stockid,$bn,$info['num'],$cgd['good_price']??0);
+			                    if($bnin==false){
+			                     Db::rollback();
+			                     return error_show(1005, '可售商品Bn库存数入库失败');
+			                    }
+                        }
+                        $good_data = ['good_log_code' => $info['returnCode'], "stock_id" => $stockid, "type" => 1, 'stock'=> $info['num'], "stock_name" => "usable_stock"];
                         GoodLog::LogAdd($this->post['token'], $good_data, 'XSTHD');
+                    }else{
+						$sabebn =Db::name("sale_info")->where(["orderCode"=>$orderinfo["orderCode"]])->select()->toArray();
+						if(!empty($sabebn)){
+                        	$total_num =$info['num'];
+                        	foreach ($sabebn as $ve){
+                        		$stock = Db::name("good_stock")->where(["spuCode" => $orderinfo['good_code'], 'id' => $ve['stockid']])->find();
+								if($stock==false) {
+									Db::rollback();
+									return error_show(1005, '商品库存数据未找到');
+								}
+                        		$tempnum=0;
+                        		if ($total_num==0) break;
+                        		if($total_num>=$ve['num']){
+                        			$tempnum = $ve['num'];
+                        			$total_num-=$ve['num'];
+                        			$ve['th_num']+=$ve['num'];
+                        			$ve['num']=0;
+                        		}else{
+                        		    $tempnum = $total_num;
+                        			$ve['num']-=$total_num;
+                        			$ve['th_num']+=$total_num;
+                        			$total_num=0;
+                        		}
+							    $stock['usable_stock']+=$tempnum;
+			                    $stock['wait_out_stock'] -=$tempnum;
+			                    $stock['updatetime'] = date("Y-m-d H:i:s");
+			                    $st_up = Db::name("good_stock")->save($stock);
+			                    if ($st_up == false) {
+			                        return error_show(1005, '可售商品入库失败');
+			                    }
+
+                        		$bnin=GoodStockInfo::AddBn($ve['stock_id'],$ve['bnCode'],$tempnum,$ve['origin_price']);
+                        		if($bnin==false){
+                        			 Db::rollback();
+                                    return error_show(1005, '可售商品Bn库存数入库失败');
+                        		}
+                        		$ve['updatetime']=date("Y-m-d H:i:s");
+								$up=Db::name("sale_info")->save($ve);
+                        		if($up==false){
+                        			 Db::rollback();
+                                    return error_show(1005, '可售商品Bn库存数入库失败');
+                        		}
+								$bnin=GoodStockInfo::ReturnBn($info['returnCode'],$ve['id'],$tempnum);
+                        		if($bnin==false){
+                        			 Db::rollback();
+                                    return error_show(1005, '可售商品Bn库存数入库失败');
+                        		}
+                        	}
+                        }else{
+
+								$ordernum = Db::name("order_num")->where(['orderCode' =>$orderinfo["orderCode"]])->find();
+					        if ($ordernum == false) {
+					        	Db::rollback();
+					            return error_show(1005, '未找到关联采购单');
+					        }
+					         $cgd = Db::name("purchease_order")->where(["cgdNo" => $ordernum['cgdNo'], "is_del" => 0])->find();
+					        if ($cgd == false) {
+					        	Db::rollback();
+					            return error_show(1005, '未找到采购单数据');
+					        }
+					        $bn =makeNo("BN");
+					        $stock = Db::name("good_stock")->where(["spuCode" => $orderinfo['good_code'], 'wsm_code'=>$cgd['wsm_code'],"is_del"=>0,"status"=>1])->find();
+					        if($stock==false){
+					        	Db::rollback();
+								return error_show(1005, '商品库存数据未找到');
+					        }
+					        $stock['usable_stock']+=$info['num'];
+		                    $stock['wait_out_stock'] -=$info['num'];
+		                    $stock['updatetime'] = date("Y-m-d H:i:s");
+		                    $st_up = Db::name("good_stock")->save($stock);
+		                    if ($st_up == false) {
+		                        return error_show(1005, '可售商品入库失败');
+		                    }
+					        $yp=GoodStockInfo::AddBn($stock['id'],$bn,$info['num'],$cgd['good_price']);
+					        if($yp==false){
+					        	Db::rollback();
+								return error_show(1005, '商品批次退货入库失败');
+					        }
+
+                        }
                     }
+                }
+
+
                     $data=[
                         "orderCode"=>$info['orderCode'],
                         "th_type"=>1,
@@ -1064,7 +1230,7 @@ class Reorder extends Base
             ];
             $create = Db::name("sale_return")->insert($in,true);
             if($create>0) {
-                $process=["order_code"=>$returnCode,"order_id"=>$create,"order_status"=>0,"order_type"=>'XSTHD',"before_status"=>0];
+                $process=["order_code"=>$returnCode,"order_id"=>$create,"order_status"=>0,"order_type"=>'XSTHD',"before_status"=>0,'holder_id'=>$in['apply_id']];
                 ProcessOrder::AddProcess($this->post['token'],$process);
                 $ste = ["order_code"=>$returnCode,"status"=>0,"action_remark"=>'',
                     "action_type"=>"create"];
@@ -1089,7 +1255,7 @@ class Reorder extends Base
                             $value['updatetime']=date("Y-m-d H:i:s");
                            $up =Db::name("order_out")->save($value);
                            if($up){
-                               $process=["order_code"=> $value['outCode'],"order_id"=>$value['id'],"order_status"=>0,"order_type"=>'CKD',"before_status"=>$tt];
+                               $process=["order_code"=> $value['outCode'],"order_id"=>$value['id'],"order_status"=>0,"order_type"=>'CKD',"before_status"=>$tt,'holder_id' => $value['apply_id']];
                                ProcessOrder::AddProcess($this->post['token'],$process);
                                $ste = ["order_code"=>$value['outCode'],"status"=>$tt,"action_remark"=>'',"action_type"=>"status"];
                                ActionLog::logAdd($this->post['token'],$ste,"CKD",0,$value);
@@ -1123,8 +1289,7 @@ class Reorder extends Base
         if($order['wsend_num']!=$order['good_num']){
         	  return error_show(1005,"订单未发货数量与总数不等,无法全退");
         }
-        $retrun =Db::name("sale_return")->where([["orderCode","=",$orderCode],["is_del","=",0],["status","<",4]])
-            ->count();
+        $retrun =Db::name("sale_return")->where([["orderCode","=",$orderCode],["is_del","=",0],["status","<",4]])->count();
         if($retrun>0){
             return error_show(1005,"存在退货订单数据");
         }
@@ -1151,14 +1316,17 @@ class Reorder extends Base
         }
         $remark =isset($this->post['remark']) &&$this->post['remark']!=''?trim($this->post['remark']) :"";
         $addr =Db::name("order_addr")->where([["orderCode","=",$orderCode],["is_del","=",0]])->select()->toArray();
-         $ordernum = Db::name("order_num")->where(['orderCode' => $orderCode])->find();
-        if ($ordernum == false) {
-        	return error_show(1005, '未找到关联采购单');
-        }
-         $cgd = Db::name("purchease_order")->where(["cgdNo" => $ordernum['cgdNo'], "is_del" => 0])->find();
-        if ($cgd == false) {
-            return error_show(1005, '未找到采购单数据');
+        if($order['is_stock']==0){
+        	 $ordernum = Db::name("order_num")->where(['orderCode' => $orderCode])->find();
+	        if ($ordernum == false) {
+	            return error_show(1005, '未找到关联采购单');
+	        }
+	         $cgd = Db::name("purchease_order")->where(["cgdNo" => $ordernum['cgdNo'], "is_del" => 0])->find();
+	        if ($cgd == false) {
+	            return error_show(1005, '未找到采购单数据');
+	        }
         }
+
         if($order['is_stock']==0&&$cgd['send_status']!=1){
         	return error_show(1005, '采购单已发起入库');
         }
@@ -1174,6 +1342,8 @@ class Reorder extends Base
                 "apply_name"=>$this->uname,
                 "cgderid"=>$goon['createrid'],
                 "cgder"=>$goon['creater'],
+                 "person"=>$supplier['person']??'',
+                "person_id"=>$supplier['personid']??0,
                 "error_code"=>$errorCode,
                 "num"=>$order['wsend_num'],
                 "total_fee"=>round($order['sale_price']*$order['wsend_num'],2),
@@ -1192,7 +1362,7 @@ class Reorder extends Base
             if($create>0){
             	$stn = ["order_code"=>$returnCode,"status"=>0,"action_remark"=>'',"action_type"=>"create"];
                 ActionLog::logAdd(["id"=>$this->uid,"nickname"=>$this->uname],$stn,"XSTHD",$in['status'],$in);
-                $process=["order_code"=>$returnCode,"order_id"=>$create,"order_status"=>$in['status'],"order_type"=>'XSTHD',"before_status"=>0];
+                $process=["order_code"=>$returnCode,"order_id"=>$create,"order_status"=>$in['status'],"order_type"=>'XSTHD',"before_status"=>0,'holder_id'=>$in['apply_id']];
                 ProcessOrder::AddProcess(["id"=>$this->uid,"nickname"=>$this->uname],$process);
                   //维护台账信息
                 Db::execute("UPDATE `wsm_standing_book` SET `returnGoodCode`=CONCAT(IFNULL(`returnGoodCode`,''),',{$returnCode}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE `orderCode`='{$orderCode}'");
@@ -1227,18 +1397,28 @@ class Reorder extends Base
                                         Db::rollback();
                                         return error_show(1004, "地址发货单更新失败");
                                     }
-                                    $ordersend = Db::name("order_send")->where(["outCode" => $send['outCode']])->find();
-                                    if($ordersend==false){
-                                    	Db::rollback();
-                                        return error_show(1004, "发货单关联数据未找到");
-                                    }
-                                    $ordersend['status'] = 0;
-                                    $ordersend['updatetime'] = date("Y-m-d H:i:s");
-                                    $sendip = Db::name("order_send")->save($ordersend);
-                                    if ($sendip == false) {
-                                        Db::rollback();
-                                        return error_show(1004, "发货单更新失败");
-                                    }
+
+                            //处理发货申请单流程
+                            ProcessOrder::AddProcess(["id" => $this->uid, "nickname" => $this->uname], [
+                                "order_type" => 'CKD',
+                                "order_code" => $send["outCode"],//出库单号
+                                "order_id" => $send["id"],
+                                "order_status" => 4,//全部退货
+                                "before_status" => $send['status'],
+                                'holder_id=' => $send['apply_id']
+                            ]);
+//                                    $ordersend = Db::name("order_send")->where(["outCode" => $send['outCode']])->find();
+//                                    if($ordersend==false){
+//                                    	Db::rollback();
+//                                        return error_show(1004, "发货单关联数据未找到");
+//                                    }
+//                                    $ordersend['status'] = 0;
+//                                    $ordersend['updatetime'] = date("Y-m-d H:i:s");
+//                                    $sendip = Db::name("order_send")->save($ordersend);
+//                                    if ($sendip == false) {
+//                                        Db::rollback();
+//                                        return error_show(1004, "发货单更新失败");
+//                                    }
                         }
                         $temp['returnCode']=$returnCode;
                         $temp['orderCode']=$orderCode;
@@ -1284,70 +1464,88 @@ class Reorder extends Base
                         "order_type" => 'XSQRD',
                         "order_code" =>$order["orderCode"],//出库单号
                         "order_id" => $order["id"],
-                        "order_status" =>$order['status'],"before_status"=>$lor
+                        "order_status" =>$order['status'],
+                        "before_status"=>$lor,
+                        'holder_id=' => $order['apply_id']
                     ]);
 
-                    $ordernum['send_num'] -= $thnum;
-                    $orderup = Db::name("order_num")->save($ordernum);
-                    if ($orderup == false) {
-                        Db::rollback();
-                        return error_show(1005, '关联数据更新失败');
-                    }
-					$cgd['th_fee'] += round($cgd['good_price'] * $thnum, 2);
-                    $cgd['th_num'] += $thnum;
-                    $cgd['updatetime'] = date("Y-m-d H:i:s");
-                    $cgdup = Db::name("purchease_order")->save($cgd);
-                    if ($cgdup == false) {
-                        Db::rollback();
-                        return error_show(1005, '采购单数据更新失败');
-                    }
-					 if ($cgd['bkcode'] != "") {
-                        $bk = Db::name("purchease_order")->where(["bkcode" => $cgd['bkcode'], "order_type" => 1, "order_source" =>0, "is_del" => 0])
-                            ->find();
-                        if ($bk == false) {
-                            Db::rollback();
-                            return error_show(1005, '未找到备库单数据');
-                        }
-                        $orderbk = Db::name("order_bk")->where(['cgdNo' => $bk['cgdNo'], "is_del" => 0])->find();
-                        if ($orderbk == false) {
-                            Db::rollback();
-                            return error_show(1005, '备库单未完全入库');
-                        }
-                        $merge_num = Db::name("purchease_order")->where(["bkcode" => $bk['bkcode'], "order_type" =>1, "is_del" => 0])->where("order_source","<>",0)->field("sum(send_num)-sum(th_num) as num")
-                            ->find();
-                        $orderbk['balance_num'] = $orderbk['total_num'] - $merge_num['num'];
-                        $orderbk['merge_num'] = $merge_num['num'];
-                        $orderbk['updatetime'] = date("Y-m-d H:i:s");
-                        $orderbkup = Db::name("order_bk")->save($orderbk);
-                        if ($orderbkup == false) {
-                            Db::rollback();
-                            return error_show(1005, '备库单库存数据释放失败');
-                        }
-                    }
-					  $stock = Db::name("good_stock")->where(["spuCode" => $order['good_code'], 'wsm_code' => $cgd['wsm_code']])
-                        ->find();
-                    if (empty($stock)) {
-                        $stock = [
-                            "spuCode" => $order['good_code'],
-                            "wsm_code" => $cgd['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"),
-                        ];
-                    }
-                    $stock['usable_stock']+=$thnum;
-                    $stock['wait_out_stock'] -= $thnum;
-                    $stock['updatetime'] = date("Y-m-d H:i:s");
-                    $st_up = Db::name("good_stock")->save($stock);
-                    if ($st_up == false) {
-                        return error_show(1005, '可售商品入库失败');
-                    }
-                    $good_data[]= ['good_log_code' => $returnCode, "stock_id" => isset($stock['id']) ? $stock['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1, 'stock' => $thnum, "stock_name" => "usable_stock"];
-                    $good_data[]= ['good_log_code' => $returnCode, "stock_id" => isset($stock['id']) ? $stock['id'] : Db::name("good_stock")->getLastInsID(), "type" => 2, 'stock' => $thnum, "stock_name" => "wait_out_stock"];
-                    GoodLog::LogAdd(["id"=>$this->uid,"nickname"=>$this->uname], $good_data, 'XSTHD');
+                  	$saleinfo=Db::name("sale_info")->where([["orderCode","=",$orderCode],["num",">",0]])->select()->toArray();
+					if(empty($saleinfo)) {
+							$ordernum = Db::name("order_num")->where(['orderCode' => $orderCode])->find();
+					        if ($ordernum == false) {
+					        	Db::rollback();
+					            return error_show(1005, '未找到关联采购单');
+					        }
+					         $cgd = Db::name("purchease_order")->where(["cgdNo" => $ordernum['cgdNo'], "is_del" => 0])->find();
+					        if ($cgd == false) {
+					        	Db::rollback();
+					            return error_show(1005, '未找到采购单数据');
+					        }
+					        $bn =makeNo("BN");
+					        $stock = Db::name("good_stock")->where(["spuCode" => $order['good_code'], 'wsm_code'=>$cgd['wsm_code'],"is_del"=>0,"status"=>1])->find();
+					        if($stock==false){
+					        	Db::rollback();
+								return error_show(1005, '商品库存数据未找到');
+					        }
+					        $stock['usable_stock']+=$thnum;
+		                    $stock['wait_out_stock'] -=$thnum;
+		                    $stock['updatetime'] = date("Y-m-d H:i:s");
+		                    $st_up = Db::name("good_stock")->save($stock);
+		                    if ($st_up == false) {
+		                        return error_show(1005, '可售商品入库失败');
+		                    }
+					        $yp=GoodStockInfo::AddBn($stock['id'],$bn,$thnum,$cgd['good_price']);
+					        if($yp==false){
+					        	Db::rollback();
+								return error_show(1005, '商品批次退货入库失败');
+					        }
+
+					}else{
+						$tempnum =$thnum;
+					foreach ($saleinfo as $va){
+						if($tempnum ==0) break;
+						$stock = Db::name("good_stock")->where(["spuCode" => $order['good_code'], 'id' => $va['stockid']])->find();
+						if($stock==false) {
+							Db::rollback();
+							return error_show(1005, '商品库存数据未找到');
+						}
+						if($va['num']>=$tempnum) {
+							$tnm = $tempnum;
+							$va['num']-= $tempnum;
+							$va['th_num']+= $tempnum;
+							$tempnum=0;
+						}else{
+							$tnm = $va['num'];
+							$tempnum -=$va['num'];
+							$va['th_num']+= $va['num'];
+							$va['num'] =0;
+						}
+	                    $stock['usable_stock']+=$tnm;
+	                    $stock['wait_out_stock'] -=$tnm;
+	                    $stock['updatetime'] = date("Y-m-d H:i:s");
+	                    $st_up = Db::name("good_stock")->save($stock);
+	                    if ($st_up == false) {
+	                        return error_show(1005, '可售商品入库失败');
+	                    }
+						$ps = GoodStockInfo::AddBn($va['stockid'],$va['bnCode'],$tnm);
+	                     if ($ps == false) {
+	                        return error_show(1005, '商品批次退货入库失败');
+	                    }
+	                     $ret = GoodStockInfo::ReturnBn($returnCode,$va['id'],$tnm);
+	                     if ($ret == false) {
+	                        return error_show(1005, '商品批次退货入库失败');
+	                    }
+	                      $va['updatetime']=date("Y-m-d H:i:s");
+	                     $sal= Db::name("sale_info")->save($va);
+						  if ($sal == false) {
+	                        return error_show(1005, '商品批次退货入库失败');
+	                    }
+						  $good_data[]= ['good_log_code' => $returnCode, "stock_id" => $va['stockid'], "type" => 1, 'stock' => $tnm, "stock_name" => "usable_stock"];
+						  $good_data[]= ['good_log_code' => $returnCode, "stock_id" => $va['stockid'], "type" => 2, 'stock' => $tnm, "stock_name" => "wait_out_stock"];
+	                       GoodLog::LogAdd($this->post['token'], $good_data, 'XSTHD');
+					}
+					}
+
                     $data=[
                         "orderCode"=>$orderCode,
                         "th_type"=>1,

+ 115 - 48
app/admin/controller/Resign.php

@@ -9,6 +9,8 @@ use app\admin\model\ActionLog;
 use app\admin\model\DataGroup as DataGroupModel;
 use app\admin\model\GoodLog;
 use app\admin\model\ProcessOrder;
+use think\facade\Cache;
+use think\facade\Config;
 use think\facade\Db;
 use think\App;
 
@@ -159,16 +161,16 @@ class Resign extends Base
         }
         $supplier=Db::name("supplier")->where("code","=",$good['supplierNo'])->find();
         if($supplier==false)  return error_show(1004,"未找到供应商数据");
-        $bk= Db::name("purchease")->where([["spuCode","=",$good_code],["status","<>",2],["is_del","=",0]])->find();
-        if($bk!=false) return error_show(1004,"存在未完成备库单数据");
-        $cgd =Db::name("purchease_order")->where([["spuCode","=",$good_code],["status","in",[0,1]],["is_del","=",0]])->find();
-        if($cgd!=false) return error_show(1004,"存在未完成采购单数据");
+//        $bk= Db::name("purchease")->where([["spuCode","=",$good_code],["status","<>",2],["is_del","=",0]])->find();
+//        if($bk!=false) return error_show(1004,"存在未完成备库单数据");
+//        $cgd =Db::name("purchease_order")->where([["spuCode","=",$good_code],["status","in",[0,1]],["is_del","=",0]])->find();
+//        if($cgd!=false) return error_show(1004,"存在未完成采购单数据");
         //查验仓库库存数量
         $stock =Db::name("good_stock")->alias("a")->leftJoin("warehouse_info b","a.wsm_code=b.wsm_code")->where
         (["spuCode"=>$good_code, "a.is_del"=>0,"a.status"=>1,"b.companyNo"=>$good['companyNo']])->field("a.id,a.usable_stock,a.wait_out_stock")->find();
-        if(isset($stock['usable_stock'])&& $stock['usable_stock']!=0){
-            return error_show(1003,"库存数量为 {$stock['usable_stock']} 无法备库");
-        }
+//        if(isset($stock['usable_stock'])&& $stock['usable_stock']!=0){
+//            return error_show(1003,"库存数量为 {$stock['usable_stock']} 无法备库");
+//        }
         //校验数量
         $goodnake = Db::name("good_nake")
             ->field('id,min_num')
@@ -188,11 +190,11 @@ class Resign extends Base
         if($lastime===""){
             return error_show(1004,"参数lastime不能为空");
         }
-        $data = GetUserInfo($token);
-        if((!empty($data) && $data['code']!=0) ||empty($data) ){
-            return error_show($data['code'],$data['message']);
-        }
-        $userinfo = $data['data'];
+//        $data = GetUserInfo($token);
+//        if((!empty($data) && $data['code']!=0) ||empty($data) ){
+//            return error_show($data['code'],$data['message']);
+//        }
+//        $userinfo = $data['data'];
         $bk_code=makeNo("BK");
         $info = [
             "spuCode"=>$good['spuCode'],
@@ -209,16 +211,16 @@ class Resign extends Base
             "cgderid"=>$good['createrid'],
             "addtime"=>date("Y-m-d H:i:s"),
             "updatetime"=>date("Y-m-d H:i:s"),
-            "apply_id"=>$userinfo['id'],
-            "apply_name"=>$userinfo['nickname'],
+            "apply_id"=>$this->uid,
+            "apply_name"=>$this->uname,
             "bk_code"=>$bk_code
         ];
         $in = Db::name("purchease")->insert($info,true);
         if($in>0){
-            $order=["order_type"=>'BHD',"order_code"=>$bk_code,"order_id"=>$in,"order_status"=>1,"before_status"=>1];
-            ProcessOrder::AddProcess($token,$order);
-            $ste = ["order_code"=>$bk_code,"status"=>0,"action_remark"=>'',"action_type"=>"create"];
-            ActionLog::logAdd($token,$ste,"BHD",1,$info);
+            $order = ["order_type" => 'BHD', "order_code" => $bk_code, "order_id" => $in, "order_status" => 1, "before_status" => 1, 'wait_id' => $supplier['personid'], 'wait_name' => $supplier['person']];
+            ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $order);
+            $ste = ["order_code" => $bk_code, "status" => 0, "action_remark" => '', "action_type" => "create"];
+            ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $ste, "BHD", 1, $info);
 
             //台账记录
             Db::name('standing_book')
@@ -250,31 +252,35 @@ class Resign extends Base
         if(empty($info)){
             return error_show(1002,'未找到数据');
         }
-        $data = GetUserInfo($this->post['token']);
-        if((!empty($data) && $data['code']!=0) ||empty($data) ){
-            return error_show($data['code'],$data['message']);
-        }
+//        $data = GetUserInfo($this->post['token']);
+//        if((!empty($data) && $data['code']!=0) ||empty($data) ){
+//            return error_show($data['code'],$data['message']);
+//        }
         //查验仓库库存数量
-        $stock =Db::name("good_stock")->alias("a")->leftJoin("warehouse_info b","a.wsm_code=b.wsm_code")->where
-        (["spuCode"=>$info['spuCode'], "a.is_del"=>0,"a.status"=>1,"b.companyNo"=>$info['companyNo']])->field("a.id,a.usable_stock,a.wait_out_stock")->find();
-        if(isset($stock['usable_stock'])&& $stock['usable_stock']!=0){
-            return error_show(1003,"库存数量为 {$stock['usable_stock']} 无法备库");
-        }
-        $userinfo = $data['data'];
+//        $stock =Db::name("good_stock")->alias("a")->leftJoin("warehouse_info b","a.wsm_code=b.wsm_code")->where
+//        (["spuCode"=>$info['spuCode'], "a.is_del"=>0,"a.status"=>1,"b.companyNo"=>$info['companyNo']])->field("a.id,a.usable_stock,a.wait_out_stock")->find();
+//        if(isset($stock['usable_stock'])&& $stock['usable_stock']!=0){
+//            return error_show(1003,"库存数量为 {$stock['usable_stock']} 无法备库");
+//        }
+//        $userinfo = $data['data'];
         $bk_code=makeNo("BK");
         $info['bk_code']=$bk_code;
         $info['status']=1;
         $info['addtime']=date("Y-m-d H:i:s");
         $info['updatetime']=date("Y-m-d H:i:s");
-        $info['apply_id']=$userinfo['id'];
-        $info['apply_name']=$userinfo['nickname'];
+        $info['apply_id']=$this->uid;
+        $info['apply_name']=$this->uname;
         unset($info['id']);
         $in = Db::name("purchease")->insert($info,true);
         if($in>0){
-            $order=["order_type"=>'BHD',"order_code"=>$bk_code,"order_id"=>$in,"order_status"=>1,"before_status"=>1];
-            ProcessOrder::AddProcess($this->post['token'],$order);
+            $supplier = Db::name('supplier')
+                ->field('id,person,personid')
+                ->where('code', $info['supplierNo'])
+                ->findOrEmpty();
+            $order = ["order_type" => 'BHD', "order_code" => $bk_code, "order_id" => $in, "order_status" => 1, "before_status" => 1, 'wait_id' => $supplier['personid'], 'wait_name' => $supplier['person']];
+            ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $order);
             $ste = ["order_code"=>$bk_code,"status"=>0,"action_remark"=>'',"action_type"=>"create"];
-            ActionLog::logAdd($this->post['token'],$ste,"BHD",1,$info);
+            ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname],$ste,"BHD",1,$info);
             return app_show(0,"新建成功",['bk_code'=>$bk_code]);
         }else{
             return error_show(1005,"新建失败");
@@ -365,11 +371,11 @@ class Resign extends Base
         if($good==false){
             return error_show(1004,"未找到商品数据");
         }
-        $data = GetUserInfo($token);
-        if((!empty($data) && $data['code']!=0) ||empty($data) ){
-            return error_show($data['code'],$data['message']);
-        }
-        $userinfo = $data['data'];
+//        $data = GetUserInfo($token);
+//        if((!empty($data) && $data['code']!=0) ||empty($data) ){
+//            return error_show($data['code'],$data['message']);
+//        }
+//        $userinfo = $data['data'];
         $up =  [
             "spuCode"=>$good_code,
             "good_name"=>$good['good_name'],
@@ -383,7 +389,7 @@ class Resign extends Base
         ];
         $in = Db::name("purchease")->where($info)->save($up);
         if($in){
-            $order=["order_type"=>'BHD',"order_code"=>$info['bk_code'],"order_id"=>$info['id'],"order_status"=>$info['status'],"before_status"=>1];
+            $order=["order_type"=>'BHD',"order_code"=>$info['bk_code'],"order_id"=>$info['id'],"order_status"=>$info['status'],"before_status"=>1, 'holder_id' => $info['apply_id']];
             ProcessOrder::AddProcess($this->post['token'],$order);
             $ste = ["order_code"=>$info['bk_code'],"status"=>$info['status'],"action_remark"=>'',"action_type"=>"edit"];
             ActionLog::logAdd($this->post['token'],$ste,"BHD",$info['status'],$up);
@@ -432,9 +438,17 @@ class Resign extends Base
         $info['updatetime']=date("Y-m-d H:i:s");
         $up = Db::name("purchease")->update($info);
         if($up){
-            $order=["order_type"=>'BHD',"order_code"=>$info['bk_code'],"order_id"=>$info['id'],
-                "order_status"=>$status,"before_status"=>$temp];
+
+            if($status==1){
+                $supplier = Db::name('supplier')
+                    ->field('id,person,personid')
+                    ->where('code', $info['supplierNo'])
+                    ->findOrEmpty();
+                $order = ["order_type" => 'BHD', "order_code" => $info['bk_code'], "order_id" => $info['id'], "order_status" => $status, "before_status" => $temp,'wait_id' => $supplier['personid'], 'wait_name' => $supplier['person']];
+            }else $order = ["order_type" => 'BHD', "order_code" => $info['bk_code'], "order_id" => $info['id'], "order_status" => $status, "before_status" => $temp, 'holder_id' => $info['apply_id']];
+            $order = ["order_type" => 'BHD', "order_code" => $info['bk_code'], "order_id" => $info['id'], "order_status" => $status, "before_status" => $temp, 'holder_id' => $info['apply_id']];
             ProcessOrder::AddProcess($this->post['token'],$order);
+
             $ste = ["order_code"=>$info['bk_code'],"status"=> $temp,"action_remark"=>'',"action_type"=>"status"];
             ActionLog::logAdd($this->post['token'],$ste,"BHD",$status,$info);
             return app_show(0,"更新成功",['bk_code'=>$info['bk_code']]);
@@ -548,7 +562,7 @@ class Resign extends Base
                 $info['addtime']=date("Y-m-d H:i:s");
                 $ood=Db::name('purchease')->save($info);
                 if($ood){
-                    $order=["order_type"=>'BHD',"order_code"=>$info['bk_code'],"order_id"=>$info['id'], "order_status"=>$info['status'],"before_status"=>$temp];
+                    $order=["order_type"=>'BHD',"order_code"=>$info['bk_code'],"order_id"=>$info['id'], "order_status"=>$info['status'],"before_status"=>$temp, 'holder_id' => $info['apply_id']];
                     ProcessOrder::AddProcess($this->post['token'],$order);
                     $ste = ["order_code"=>$info['bk_code'],"status"=>$temp,"action_remark"=>'',"action_type"=>"status"];
                     ActionLog::logAdd($this->post['token'],$ste,"BHD",$info['status'],$info);
@@ -640,8 +654,14 @@ class Resign extends Base
             $feed['updatetime']=date("Y-m-d H:i:s");
             $up = Db::name("purchease")->update($feed);
             if($up){
-                $order=["order_type"=>'BHD',"order_code"=>$feed['bk_code'],"order_id"=>$feed['id'], "order_status"=>$feed['status'],"before_status"=>$tem];
-                ProcessOrder::AddProcess($this->post['token'],$order);
+                if ($feed['status'] == 1) {
+                    $supplier = Db::name('supplier')
+                        ->field('id,person,personid')
+                        ->where('code', $feed['supplierNo'])
+                        ->findOrEmpty();
+                    $order = ["order_type" => 'BHD', "order_code" => $feed['bk_code'], "order_id" => $feed['id'], "order_status" => $feed['status'], "before_status" => $tem, 'holder_id' => $feed['apply_id'], 'wait_id' => $supplier['personid'], 'wait_name' => $supplier['person']];
+                } else $order = ["order_type" => 'BHD', "order_code" => $feed['bk_code'], "order_id" => $feed['id'], "order_status" => $feed['status'], "before_status" => $tem, 'holder_id' => $feed['apply_id']];
+                ProcessOrder::AddProcess($this->post['token'], $order);
                 $ste = ["order_code"=>$feed['bk_code'],"status"=>$tem,"action_remark"=>'',"action_type"=>"edit"];
                 ActionLog::logAdd($this->post['token'],$ste,"BHD",$feed['status'],$feed);
                 if($status==3){
@@ -706,10 +726,30 @@ class Resign extends Base
                     ];
                     $in= Db::name("purchease_order")->insert($data,true);
                     if($in>0){
-                        $order=["order_type"=>'CGD',"order_code"=>$data['cgdNo'],"order_id"=>$in, "order_status"=>$data['status'],"before_status"=>0];
+                        //当采购单是节点0待与供应商确认,推给供应商负责人
+                        if(!isset($supplier)) $supplier = Db::name("supplier")->where(["code"=>$purse['supplier']])->find();
+                        $order=["order_type"=>'CGD',"order_code"=>$data['cgdNo'],"order_id"=>$in, "order_status"=>$data['status'],"before_status"=>0,'wait_id'=>$supplier['personid'],'wait_name'=>$supplier['person']];
                         ProcessOrder::AddProcess($this->post['token'],$order);
                         $ste = ["order_code"=>$inw,"status"=>$data['status'],"action_remark"=>'',"action_type"=>"create"];
                         ActionLog::logAdd($this->post['token'],$ste,"CGD",$data['status'],$data);
+
+                        //将采购单数据塞入到队列中
+                        $push_data = json_encode([
+                            'supplierNo' => $data['supplierNo'],
+                            'type' => 1,//1销售订单(采销的采购单),2上线结果
+                            'data' => [
+                                'cgdNo' => $data['cgdNo'],
+                                'spuCode' => $feed['spuCode'],
+                                'good_name' => $data['good_name'],
+                                'good_num' => $data['good_num'],
+                                'good_price' => $data['good_price'],
+                                'total_fee' => $data['total_fee'],
+                                'weight' => $data['weight'],
+                                'addtime' => $data['addtime'],
+                            ],
+                        ], JSON_UNESCAPED_UNICODE);
+                        Cache::store("redis")->handler()->lPush(Config::get('app.abutment_queue'), $push_data);
+
                         Db::commit();
                         return app_show(0,"更新成功",['cgdNo'=>$inw]);
                     }
@@ -779,11 +819,19 @@ class Resign extends Base
                 "action_type" => "edit"//新建create,编辑edit,更改状态status
             ], "BHD", $info['status'], $info);
 
+            $supplier = Db::name('supplier')
+                ->field('id,person,personid')
+                ->where('code', $info['supplierNo'])
+                ->findOrEmpty();
             ProcessOrder::AddProcess($this->post['token'], [
                 "order_type" => 'BHD',
                 "order_code" => $info['bk_code'],//销售单code
                 "order_id" => $info['id'],
-                "order_status" => $info['status'],"before_status"=>$old_info_status
+                "order_status" => $info['status'],
+                "before_status"=>$old_info_status,
+                //'holder_id' => $info['apply_id'],
+                'wait_id' => $supplier['personid'],
+                'wait_name' => $supplier['person'],
             ]);
 
             return app_show(0,"备库单仓库选择成功");
@@ -908,7 +956,7 @@ class Resign extends Base
                         $order = ["order_code" =>  $cgdCode, "status" => 0, "action_remark" => '', "action_type" => "create"];
                         GoodLog::LogAdd($this->post['token'], $good_data, 'CGD');
                         ActionLog::logAdd($this->post['token'], $order, "CGD", 0, $good);
-                        $process = ["order_code" => $cgdCode, "order_id" => $up, "order_status" => $cg['status'], "order_type" => 'CGD',"before_status"=>0];
+                        $process = ["order_code" => $cgdCode, "order_id" => $up, "order_status" => $cg['status'], "order_type" => 'CGD',"before_status"=>0,'holder_id'=>$supplier['personid'],'wait_id'=>$supplier['personid'],'wait_name'=>$supplier['person']];
                         ProcessOrder::AddProcess($this->post['token'], $process);
                         $info['wsm_code'] = $wsm_code;
                         $old_info_status = $info['status'];
@@ -929,7 +977,9 @@ class Resign extends Base
                                 "order_type" => 'BHD',
                                 "order_code" => $info['bk_code'],//销售单code
                                 "order_id" => $info['id'],
-                                "order_status" => $info['status'],"before_status"=> $old_info_status
+                                "order_status" => $info['status'],
+                                "before_status"=> $old_info_status,
+                                'holder_id' => $info['apply_id']
                             ]);
 
                             //维护台账记录
@@ -943,6 +993,23 @@ class Resign extends Base
                                 'updatetime' => date('Y-m-d H:i:s'),
                             ]);
 
+                            //将采购单数据塞入到队列中
+                            $push_data = json_encode([
+                                'supplierNo' => $cg['supplierNo'],
+                                'type' => 1,//1销售订单(采销的采购单),2上线结果
+                                'data' => [
+                                    'cgdNo' => $cg['cgdNo'],
+                                    'spuCode' => $cg['spuCode'],
+                                    'good_name' => $cg['good_name'],
+                                    'good_num' => $cg['good_num'],
+                                    'good_price' => $cg['good_price'],
+                                    'total_fee' => $cg['total_fee'],
+                                    'weight' => $cg['weight'],
+                                    'addtime' => $cg['addtime'],
+                                ],
+                            ], JSON_UNESCAPED_UNICODE);
+                            Cache::store("redis")->handler()->lPush(Config::get('app.abutment_queue'), $push_data);
+
                             Db::commit();
                             return app_show(0, "采购单新建成功", ["cgdNo" => $cgdCode]);
                         }

+ 58 - 20
app/admin/controller/Resigninfo.php

@@ -4,8 +4,10 @@ namespace app\admin\controller;
 
 use app\admin\model\DataGroup as DataGroupModel;
 use app\admin\model\ProcessOrder;
+use app\admin\model\ProcessWait;
 use app\BaseController;
 use think\App;
+use think\Exception;
 use think\facade\Db;
 use app\admin\model\ActionLog;
 
@@ -125,10 +127,10 @@ class Resigninfo extends Base
         ];
         $in = Db::name('resign_info')->insertGetId($data);
         $stn = ["order_code"=>'',"status"=>$status,"action_remark"=>'',"action_type"=>"create"];
-        ActionLog::logAdd(['id'=>isset($resign_uid["data"]['id'])?$resign_uid["data"]['id']:0,'nickname'=>$ri],$stn,"LZJJ",$status,$stn);
+        ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$stn,"LZJJ",$status,$stn);
 
-        $process=["order_code"=>'',"order_id"=>$in,"order_status"=>$status,"order_type"=>'LZJJ',"before_status"=>0];
-        ProcessOrder::AddProcess(['id'=>isset($resign_uid["data"]['id'])?$resign_uid["data"]['id']:0,'nickname'=>$ri],$process);
+        $process=["order_code"=>'',"order_id"=>$in,"order_status"=>$status,"order_type"=>'LZJJ',"before_status"=>0, 'holder_id' => $this->uid];
+        ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process);
         return $in ? error_show(0,"添加成功") : error_show(1002,"添加失败");
     }
     public function selec(){
@@ -188,27 +190,63 @@ class Resigninfo extends Base
       if($it){
           $stn = ["order_code"=>$id,"status"=>0,"action_remark"=>'',"action_type"=>"edit"];
           ActionLog::logAdd($this->post['token'],$stn,"LZJJ",0,$stn);
-          $process=["order_code"=>'',"order_id"=>$id,"order_status"=>$status,"order_type"=>'LZJJ',"before_status"=>0];
-          ProcessOrder::AddProcess(['id'=>isset($resign_uid["data"]['id'])?$resign_uid["data"]['id']:0,'nickname'=>$ri],$process);
+          $process=["order_code"=>'',"order_id"=>$id,"order_status"=>$eid['status'],"order_type"=>'LZJJ',"before_status"=>0, 'holder_id' => $this->uid];
+          ProcessOrder::AddProcess(['id'=>$hand_id,'nickname'=>$r],$process);
           return error_show(0,"编辑成功");
       }else{
           return error_show(1002,"编辑失败");
       }
     }
     public function del(){
-        $id = isset($this->post['id']) && $this->post['id'] !=="" ? $this->post['id']:"";
-        $fid = Db::name('resign_info')->where(['is_del'=>0,'id'=>$id])->find();
-        if($fid==false){
-            return error_show(1002,"离职人员不存在");
-        }
-        $num = Db::name('resign_info')->update(['is_del'=>1,'id'=>$id,"updatetime"=>date("Y-m-d H:i:s")]);
-        if($num){
-            $stn = ["order_code"=>"BH","status"=>0,"action_remark"=>'',"action_type"=>"delete"];
-            ActionLog::logAdd($this->post['token'],$stn,"LZJJ",0,$stn);
-            return error_show(0,"删除成功");
-        }else{
-            return error_show(1002,"删除失败");
+
+        $id = isset($this->post['id']) && $this->post['id'] !== "" ? $this->post['id'] : "";
+
+        $fid = Db::name('resign_info')->where(['is_del' => 0, 'id' => $id])->find();
+
+        if ($fid == false) return error_show(1002, "离职人员不存在");
+
+        Db::startTrans();
+
+        try {
+            $num = Db::name('resign_info')
+                ->where(['is_del' => 0, 'id' => $id])
+                ->update(['is_del' => 1, 'id' => $id, "updatetime" => date("Y-m-d H:i:s")]);
+            if ($num) {
+                $stn = ["order_code" => "BH", "status" => 0, "action_remark" => '', "action_type" => "delete"];
+                ActionLog::logAdd($this->post['token'], $stn, "LZJJ", 0, $stn);
+
+                //将对应的离职交接单流程的数据都删掉(没有相关的中断节点,所以这里直接操作process_wait表)
+                Db::name('process_wait')
+                    ->where([
+                        'order_type' => 'LZJJ',
+                        'order_id' => $id,
+                        'status' => ProcessWait::$status_wait,
+                    ])->update(['status' => ProcessWait::$status_interrupt]);
+
+                Db::commit();
+                return app_show(0, "删除成功");
+            } else throw new Exception("删除失败");
+
+        } catch (Exception $exception) {
+            Db::rollback();
+
+            return error_show(1004, $exception->getMessage());
         }
+
+
+//        $id = isset($this->post['id']) && $this->post['id'] !=="" ? $this->post['id']:"";
+//        $fid = Db::name('resign_info')->where(['is_del'=>0,'id'=>$id])->find();
+//        if($fid==false){
+//            return error_show(1002,"离职人员不存在");
+//        }
+//        $num = Db::name('resign_info')->update(['is_del'=>1,'id'=>$id,"updatetime"=>date("Y-m-d H:i:s")]);
+//        if($num){
+//            $stn = ["order_code"=>"BH","status"=>0,"action_remark"=>'',"action_type"=>"delete"];
+//            ActionLog::logAdd($this->post['token'],$stn,"LZJJ",0,$stn);
+//            return error_show(0,"删除成功");
+//        }else{
+//            return error_show(1002,"删除失败");
+//        }
     }
     public function statu(){
         $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
@@ -231,9 +269,9 @@ class Resigninfo extends Base
         $sv = Db::name('resign_info')->save($st);
         if($sv){
             $stn = ["order_code"=>$id,"status"=>$tn,"action_remark"=>'',"action_type"=>"edit"];
-            ActionLog::logAdd($this->post['token'],$stn,"LZJJ",$stauts,$st);
-            $process=["order_code"=>'',"order_id"=>$id,"order_status"=>$stauts,"order_type"=>'LZJJ',"before_status"=>$tn];
-            ProcessOrder::AddProcess($this->post['token'],$process);
+            ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$stn,"LZJJ",$stauts,$st);
+            $process = ["order_code" => '', "order_id" => $id, "order_status" => $st['status'], "order_type" => 'LZJJ', "before_status" => $tn, 'holder_id' => $this->uid];
+            ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process);
             return error_show(0,"状态更新成功");
         }else{
             return error_show(1002,"状态更新失败");

Різницю між файлами не показано, бо вона завелика
+ 382 - 266
app/admin/controller/Sale.php


+ 61 - 8
app/admin/controller/Salezx.php

@@ -5,10 +5,13 @@ namespace app\admin\controller;
 use app\admin\model\GoodLog;
 use app\admin\model\ProcessOrder;
 use think\App;
+use think\facade\Cache;
+use think\facade\Config;
 use think\facade\Db;
 use app\admin\model\ActionLog;
 class Salezx extends \app\BaseController
 {
+    private $cgd_data = [];//存储采购单的数据,目前是为了做供应商api推送而准备的
     public $post="";
     public function __construct(App $app)
     {
@@ -220,7 +223,8 @@ class Salezx extends \app\BaseController
                                    "order_code" => $outCode,//出库单号
                                    "order_id" => $ou,
                                    "order_status" => $out['status'],
-                                   'before_status'=>0
+                                   'before_status'=>0,
+                                   'holder_id' => $out['apply_id']
                                ]);
 
                                $standing_bood_data['outCode'][]=$outCode;
@@ -245,7 +249,8 @@ class Salezx extends \app\BaseController
                     "order_type" => 'XSQRD',
                     "order_code" => $orderCode,//销售单code
                     "order_id" => $datainfo,
-                    "order_status" => 0
+                    "order_status" => 0,
+                    'holder_id=' => $data['apply_id']
                 ]);
 
 
@@ -255,6 +260,25 @@ class Salezx extends \app\BaseController
                 if (empty($infoNo)) Db::name('standing_book')->insert(array_merge($standing_bood_data, ['addtime' => date('Y-m-d H:i:s'), 'standBookNo' => makeNo("IO")]));
                 else Db::name('standing_book')->where('infoNo', $infoNo)->update($standing_bood_data);
 
+                //将采购单数据塞入到队列中
+                if ($this->cgd_data) {
+                    $push_data = json_encode([
+                        'supplierNo' => $this->cgd_data['supplierNo'],
+                        'type' => 1,//1销售订单(采销的采购单),2上线结果
+                        'data' => [
+                            'cgdNo' => $this->cgd_data['cgdNo'],
+                            'spuCode' => $this->cgd_data['spuCode'],
+                            'good_name' => $this->cgd_data['good_name'],
+                            'good_num' => $this->cgd_data['good_num'],
+                            'good_price' => $this->cgd_data['good_price'],
+                            'total_fee' => $this->cgd_data['total_fee'],
+                            'weight' => $this->cgd_data['weight'],
+                            'addtime' => $this->cgd_data['addtime'],
+                        ],
+                    ], JSON_UNESCAPED_UNICODE);
+                    Cache::store("redis")->handler()->lPush(Config::get('app.abutment_queue'), $push_data);
+                }
+
                     Db::commit();
                     return error_show(0,"咨询订单创建成功");
             }
@@ -347,15 +371,21 @@ class Salezx extends \app\BaseController
                             "action_type" => "create"//新建create,编辑edit,更改状态status
                         ], "CGD", $cg['status'], $cg);
 
+                        //当采购单是节点0待与供应商确认,推给供应商负责人
                         ProcessOrder::AddProcess($this->post['token'], [
                             "order_type" => 'CGD',
                             "order_code" => $cg['cgdNo'],//销售单code
                             "order_id" => $up,
-                            "order_status" => $cg['status']
+                            "order_status" => $cg['status'],
+                            'holder_id'=>$supplier['personid'],
+                            'wait_id'=>$supplier['personid'],
+                            'wait_name'=>$supplier['person'],
                         ]);
 
                         $standing_bood_data['cgdNo']=$cgdCode;
 
+                        $this->cgd_data = $cg;
+
                         return true;
                     }else{
                         return false;
@@ -561,8 +591,30 @@ class Salezx extends \app\BaseController
             if($datainfo) {
                 $st = ["order_code"=>$der['outCode'],"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
                 ActionLog::logAdd($this->post['token'],$st,"CKD",1,$der);
-                $ord=["order_type"=>"CKD","order_code"=>$der['outCode'],"order_id"=>$der['id'], "order_status"=>$der['status']];
-                ProcessOrder::AddProcess($this->post['token'],$ord);
+
+                //是否库存品,待办数据推送到的人有区别,
+                $ord = [];
+                if ($order['is_stock'] == 1) {
+                    //库存品,推给库管和库管-张凯旋
+                    $roleid = config('app.wsm_cgder_role');
+                    $uids = Db::name('user_role')
+                        ->where('is_del', 0)
+                        ->whereIn('roleid', $roleid)
+                        ->column('uid');
+                    $ord = ["order_type" => "CKD", "order_code" => $der['outCode'], "order_id" => $der['id'], "order_status" => $der['status'], 'holder_id' => $der['apply_id'], 'handle_user_list' => implode(',', $uids)];
+                } elseif ($order['is_stock'] == 0 || $order['order_typee'] == 3) {
+                    //非库存品和采返商品,推给供应商负责人
+                    $supplier = Db::name('supplier')
+                        ->alias('a')
+                        ->field('a.id,a.person,a.personid')
+                        ->leftJoin('purchease_order b', 'b.is_del=0 AND b.supplierNo=a.code')
+                        ->leftJoin('order_num c', 'c.cgdNo=b.cgdNo')
+                        ->where('c.orderCode', $der['orderCode'])
+                        ->findOrEmpty();
+                    $ord = ["order_type" => "CKD", "order_code" => $der['outCode'], "order_id" => $der['id'], "order_status" => $der['status'], 'holder_id' => $der['apply_id'], 'wait_id' => $supplier['personid'], 'wait_name' => $supplier['person']];
+                }
+                if (empty($ord)) $ord = ["order_type" => "CKD", "order_code" => $der['outCode'], "order_id" => $der['id'], "order_status" => $der['status'], 'holder_id' => $der['apply_id']];
+                ProcessOrder::AddProcess($this->post['token'], $ord);
 //                    $send =Db::name("order_out")->where(["wsm_code"=>$der['wsm_code'],'orderCode'=>$der['orderCode']])->sum("send_num");
 //                    $order['send_num']+= $der['send_num'];
 //                    $order['wsend_num']-=$der['send_num'] ;//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
@@ -736,7 +788,7 @@ class Salezx extends \app\BaseController
                 }
                 $sio = ["order_code"=>$outCode,"status"=>0,"action_remark"=>'',"action_type"=>"create"];
                 ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri],$sio,"CKD",0,$data);
-                $order=["order_type"=>"CKD","order_code"=>$data['outCode'],"order_id"=>$datainfo,"order_status"=>$data['status'],'before_status'=>0];
+                $order=["order_type"=>"CKD","order_code"=>$data['outCode'],"order_id"=>$datainfo,"order_status"=>$data['status'],'before_status'=>0, 'holder_id' => $data['apply_id']];
                 ProcessOrder::AddProcess(['id'=>$rm,'nickname'=>$ri],$order);
                 $item = $der['status'];
                 $der['send_num']+= $receipt_quantity;
@@ -761,12 +813,13 @@ class Salezx extends \app\BaseController
                         "order_type" => 'XSQRD',
                         "order_code" => $der['orderCode'],//销售单code
                         "order_id" => $der['id'],
-                        "order_status" => $der['status']
+                        "order_status" => $der['status'],
+                        'holder_id=' => $der['apply_id']
                     ]);
                 }
             $sio = ["order_code"=>$orderCode,"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
             ActionLog::logAdd($this->post['token'],$sio,"zxd",$der['status'],$der);
-            $order=["order_type"=>"CKD","order_code"=>$orderCode,"order_id"=>$der['id'],"order_status"=>$der['status']];
+            $order=["order_type"=>"CKD","order_code"=>$orderCode,"order_id"=>$der['id'],"order_status"=>$der['status'], 'holder_id' => $data['apply_id']];
             ProcessOrder::AddProcess($this->post['token'],$order);
                 Db::commit();
                 return error_show(0,"创建成功");

+ 1 - 1
app/admin/controller/Stat.php

@@ -89,7 +89,7 @@ FROM
 				k.itemid = c.id 
 			     and f.is_del=0
 				AND f.platform_id = a.platform_id 
-				AND WEEK ( f.addtime, 1 ) = WEEK ( '$endtime', 1 ) 
+				AND WEEK ( e.addtime, 1 ) = WEEK ( '$endtime', 1 ) 
 				AND DATE_FORMAT ( e.addtime, '%Y' ) = DATE_FORMAT ( '$endtime', '%Y' )) AS week_thfee,
 		a.platform_id,
 		c.`name`,

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

@@ -146,7 +146,7 @@ class Suppler extends Base
                 "nature" => $nature,
                 "legaler" => $legaler,
                 "addr" => $addr,
-                "status" => 1,
+                "status" => 0,
                 "is_del" => 0,
                 "remark" => '',
                 "ticket_type" => $ticket_type,

+ 2 - 2
app/admin/controller/Version.php

@@ -332,7 +332,7 @@ class Version extends BaseController
                                 "action_type" => "edit"//新建create,编辑edit更改状态status
                             ], "PRO", 3, ["status" => 3, "updatetime" => date("Y-m-d H:i:s")]);
 
-                            $process = ["order_code" => $value['projectNo'], "order_id" => $pr['id'], "order_status" =>3, "order_type" => 'PRO',"before_status"=> $pr['status']];
+                            $process = ["order_code" => $value['projectNo'], "order_id" => $pr['id'], "order_status" =>3, "order_type" => 'PRO',"before_status"=> $pr['status'],'holder_id'=>$pr['createrid']];
                             ProcessOrder::AddProcess(['id'=>0,"nickname"=>'客户'], $process);
                         }
                     }else{
@@ -411,7 +411,7 @@ class Version extends BaseController
                     "action_type" => "edit"//新建create,编辑edit更改状态status
                 ], "PRO", 5, ["status" => 5, "updatetime" => date("Y-m-d H:i:s")]);
 
-                $process = ["order_code" => $pr['projectNo'], "order_id" => $pr['id'], "order_status" =>5, "order_type" => 'PRO',"before_status"=> $pr['status']];
+                $process = ["order_code" => $pr['projectNo'], "order_id" => $pr['id'], "order_status" =>5, "order_type" => 'PRO',"before_status"=> $pr['status'],'holder_id'=>$pr['createrid']];
                 ProcessOrder::AddProcess(['id'=>0,"nickname"=>'客户'], $process);
                     Db::commit();
                     return app_show(0, "方案数据修改成功");

+ 242 - 0
app/admin/model/GoodStockInfo.php

@@ -0,0 +1,242 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\model;
+
+use think\Exception;
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class GoodStockInfo extends Model
+{
+
+    /**
+	* @param int $stockid 仓库库存id
+	* @param string $bn bn编号
+	* @param int $num  bn数量
+	* @param float $origin_price 采购成本价
+	* @return bool  入库bn库存数新建 或退回bn库存数
+	*/
+    static function AddBn(int $stockid,string $bn,int $num,float $origin_price=0){
+		$data=self::where(["stockid"=>$stockid,"bnCode"=>$bn])->findOrEmpty()->toArray();
+		if(empty($data)){
+			$data=[
+				"stockid"=>$stockid,
+				"bnCode"=>$bn,
+				"total_num"=>$num,
+				"used_num"=>0,
+				"balance_num"=>$num,
+				"origin_price"=>$origin_price,
+				"addtime"=>date("Y-m-d H:i:s"),
+				"updatetime"=>date("Y-m-d H:i:s")
+				];
+			$result=self::insert($data);
+		}else{
+			$total_num = $data["balance_num"]+$num;
+			if($total_num> $data["total_num"]) throw new Exception("批次入库数量超过总数",1006);
+			$temp=[];
+			$temp["balance_num"]=$total_num;
+			$temp["used_num"]=$data["used_num"]-$num;
+			$temp["updatetime"]=date("Y-m-d H:i:s");
+			$result=self::update($temp,$data)->getNumRows();
+		}
+
+		return $result;
+    }
+
+	/**
+	* @param int $stockid
+	* @param int $num
+	 * @return array  库存品下单消耗bn库存数
+	* @throws \think\Exception
+	* @throws \think\db\exception\DataNotFoundException
+	* @throws \think\db\exception\DbException
+	* @throws \think\db\exception\ModelNotFoundException
+	*/
+	static function SaleBn($stockid,int $num,int $isstock=1){
+		$arr = self::where([["balance_num",">",0]])->where(["stockid"=>$stockid])->select()->toArray();
+		if(empty($arr)) throw new Exception("库存批次数量不足","1006");
+		$list=[];
+		foreach ($arr as $item) {
+			$stock = self::name("good_stock")->where(["id"=>$item['stockid']])->field("id,usable_stock,wait_out_stock")->find()->toArray();
+			if($num<=0) break;
+			$update=[];
+		    if($item['balance_num']<=$num){
+		    	$update['balance_num'] =0;
+		    	$update['used_num']= $item['used_num']+$item['balance_num'];
+		    	$num-=$item['balance_num'];
+		    	$update['updatetime'] =date("Y-m-d H:i:s");
+		    	$temp=["stockid"=>$item['stockid'],"bnCode"=>$item['bnCode'],"num"=>$item['balance_num'],"origin_price"=>$item["origin_price"]];
+		    	$stockup=["usable_stock"=>$stock['usable_stock']-$item['balance_num'],"wait_out_stock"=>$stock['wait_out_stock']+$item['balance_num'],"updatetime"=>date("Y-m-d H:i:s")];
+		    }else{
+				$update['balance_num']=$item['balance_num']-$num;
+		    	$update['used_num']=$item['used_num']+$num;
+		    	$update['updatetime'] =date("Y-m-d H:i:s");
+		    	$temp=["stockid"=>$item['stockid'],"bnCode"=>$item['bnCode'],"num"=>$num,"origin_price"=>$item["origin_price"]];
+		    	$stockup=["usable_stock"=>$stock['usable_stock']-$num,"wait_out_stock"=>$stock['wait_out_stock']+$num,"updatetime"=>date("Y-m-d H:i:s")];
+				$num=0;
+		    }
+			$up=self::update($update,$item);
+		    if($up==false)  throw new Exception("库存批次库存更新失败","1006");
+		    if($isstock==1) {
+		    	$stup=self::name("good_stock")->where($stock)->update($stockup);
+		    	if($stup==false)  throw new Exception("库存更新失败","1006");
+
+		    }
+		    $list[]=$temp;
+		}
+		return $list;
+    }
+	/**
+	* @param int $stockid
+	* @param string $bn
+	* @param int $num
+	* @return bool  盘点修改bn仓库库存数
+	* @throws \think\Exception
+	*/
+	static function CheckBn(int $stockid,string $bn,int $num){
+		$data=self::where(["stockid"=>$stockid,"bnCode"=>$bn])->findOrEmpty()->toArray();
+		if(empty($data)) throw new Exception("未找到Bn库存数据",1006);
+			$update=[];
+			$update["balance_num"]=$num;
+			$update["total_num"]=$data["used_num"]+$num;
+			$update["updatetime"]=date("Y-m-d H:i:s");
+		return self::update($update,$data)->getNumRows();
+    }
+	/**
+	* @param string $orderCode
+	* @param int|array $stockid
+	* @param int $num
+	 * @return int
+	* @throws \think\Exception
+	* @throws \think\db\exception\DataNotFoundException
+	* @throws \think\db\exception\DbException
+	* @throws \think\db\exception\ModelNotFoundException
+	 */
+	static function OrderBn(string $orderCode, $stockid,int $num,int $isstock=1){
+        $bnArr=self::SaleBn($stockid,$num,$isstock);
+        if(empty($bnArr)) throw new Exception("未找到Bn库存数据",1006);
+        $ordBn=[];
+        foreach ($bnArr as $value){
+	        $saleBn=[
+	        "orderCode"=>$orderCode,
+	        "bnCode"=>$value['bnCode'],
+	        "stockid"=>$value['stockid'],
+	        "num"=>$value['num'],
+	        "send_num"=>$value['num'],
+	        "origin_price"=>$value['origin_price'],
+	        "addtime"=>date("Y-m-d H:i:s"),
+	        "updatetime"=>date("Y-m-d H:i:s"),
+	        ];
+	        $ordBn[]=$saleBn;
+        }
+
+        return self::name("sale_info")->insertAll($ordBn);
+    }
+	/**
+	* @param string $returnCode
+	* @param int $salebnid
+	* @param int $num
+	* @param int $type
+	 * @return bool
+	* @throws \think\Exception
+	 */
+	static function ReturnBn(string $returnCode,int $salebnid,int $num,int $type=1){
+    	$sabn=self::name("sale_info")->where(['id'=>$salebnid])->findOrEmpty()->toArray();
+    	if(empty($sabn))throw new Exception("未找到Bn订单数据",1006);
+    	$return=[
+    		"returnCode"=>$returnCode,
+    	    "type"=>$type,
+    	    "orderCode"=>$sabn['orderCode'],
+    	    "bnCode"=>$sabn['bnCode'],
+    	    "origin_price"=>$sabn['origin_price'],
+    	    "num"=>$num,
+    	    "addtime"=>date("Y-m-d H:i:s")
+    	    ];
+    	return self::name("return_info")->insert($return);
+    }
+	/**  调拨专用 需要注意bn总数变化
+	* @param int $stockid 库存id
+	* @param string $bnCode bn编号
+	* @param int $num  库存数量
+	* @param int $flag  操作类型 0 添加库存 1 减少库存
+	* @param float|int $origin_price  成本价
+	 * @return bool
+	* @throws \think\Exception
+ */
+	static function bnStock(int $stockid,string $bnCode,int $num,int $flag=0,float $origin_price=0){
+			$stock =self::where(["stockid"=>$stockid,"bnCode"=>$bnCode])->lock(true)->findOrEmpty()->toArray();
+			$update=[];
+			if($flag==1) {
+				if(empty($stock)|| $stock['balance_num']< $num)
+					throw new Exception("bn库存数不足",1006);
+				else{
+						$update['balance_num']=$stock['balance_num']-$num;
+						$update['total_num']=$stock['total_num']-$num;
+						$update['updatetime']=date("Y-m-d H:i:s");
+					}
+			}else{
+				if (empty($stock)){
+					$update=[
+						"bnCode"=>$bnCode,
+						"stockid"=>$stockid,
+						"total_num"=>$num,
+						"used_num"=>0,
+						"balance_num"=>$num,
+						"origin_price"=>$origin_price,
+						"addtime"=>date("Y-m-d H:i:s"),
+						"updatetime"=>date("Y-m-d H:i:s")
+						];
+				}else{
+						$update['balance_num']=$stock['balance_num']+$num;
+						$update['total_num']=$stock['total_num']+$num;
+						$update['updatetime']=date("Y-m-d H:i:s");
+				}
+			}
+
+			return	empty($stock)? self::insert($update): self::update($update,$stock)->getNumRows();
+	}
+	/**
+    退货退到其他仓库的话 原仓库批次总数 - 退货数量
+	* @param $stockid 退货仓库
+	* @param $bnCode bn批次编号
+	* @param $num 退货数量
+	* @param $origin_stockid 原仓库
+	 * @return int
+	* @throws \think\Exception
+	 */
+	static function ReturnAdd(int $stockid,string $bnCode,int $num,int $origin_stockid){
+		$origin = self::where(["stockid"=>$origin_stockid,"bnCode"=>$bnCode])->findOrEmpty()->toArray();
+		if($stockid!=$origin_stockid){
+			if(empty($origin))throw new Exception("未找到Bn订单数据",1006);
+			$temp['total_num'] =$origin['total_num'] -$num;
+			$temp['used_num'] =$origin['used_num'] -$num;
+			$temp['updatetime'] =date("Y-m-d H:i:s");
+			self::update($temp,$origin);
+		}
+		$stock = self::where(["stockid"=>$stockid,"bnCode"=>$bnCode])->findOrEmpty()->toArray();
+		if(empty($stock)){
+			$update=[
+						"bnCode"=>$bnCode,
+						"stockid"=>$stockid,
+						"total_num"=>$num,
+						"used_num"=>0,
+						"balance_num"=>$num,
+						"origin_price"=>$origin['origin_price'],
+						"addtime"=>date("Y-m-d H:i:s"),
+						"updatetime"=>date("Y-m-d H:i:s")
+						];
+			$result= self::insert($update);
+		}else{
+						$update['balance_num']=$stock['balance_num']+$num;
+						$stockid!=$origin_stockid ? $update['total_num']=$stock['total_num']+$num:$update['used_num']=$stock['used_num']-$num;
+						$update['updatetime']=date("Y-m-d H:i:s");
+					$result=self::update($update,$stock)->getNumRows();
+		}
+		return $result;
+	}
+
+
+}

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

@@ -35,12 +35,15 @@ class ProcessOrder extends \think\Model
             "action_status"=>$order['before_status'],
             "action_uid"=>$uid,
             "action_name"=>$name,
-            "addtime"=>date("Y-m-d H:i:s")
+            "addtime"=>date("Y-m-d H:i:s"),
+//            'holder_id'=>$order['holder_id'],//数据所有人
         ];
         OrderMsg::addmsg($data);
 
         //手动排除竞价单ZXD
-        if($order['order_type']!='ZXD') ProcessWait::add($data, isset($order['wait_id']) ? $order['wait_id'] : 0, isset($order['wait_name']) ? $order['wait_name'] : '');
+        if($order['order_type']!='ZXD') {
+            ProcessWait::add(array_merge($data, ['holder_id' => $order['holder_id'] ?? 0,'person_id' => $order['person_id'] ?? 0]), isset($order['wait_id']) ? $order['wait_id'] : 0, isset($order['wait_name']) ? $order['wait_name'] : '',$order['handle_user_list']??'');
+        }
 
         $insert = $data;
         //如果是【供应商】应用,即abutment,增加字段source==2(操作来源为供应商)

+ 50 - 18
app/admin/model/ProcessWait.php

@@ -15,11 +15,12 @@ class ProcessWait extends Model
     protected $pk = 'id';
     protected $autoWriteTimestamp = false;
 
-    public static $status_wait_handle = 1;//状态,1待处理
-    public static $status_handle_finish = 2;//状态,2待处理
+    public static $status_wait = 1;//状态,1待处理
+    public static $status_finish = 2;//状态,2已处理
+    public static $status_interrupt = 3;//状态,3中断
 
     //添加待办记录
-    public static function add(array $data = [], int $wait_id = 0, string $wait_name = '')
+    public static function add(array $data = [], int $wait_id = 0, string $wait_name = '', string $handle_user_list = '')
     {
 //        $data数据格式实例
 //        $data=[
@@ -34,21 +35,38 @@ class ProcessWait extends Model
 //            "addtime"=>'',
 //        ];
 
+        //修改各个节点的最终节点
+        Db::name('process_wait')
+            ->where(['order_type' => $data['order_type'], 'order_code' => $data['order_code'], 'order_id' => $data['order_id']])
+            ->update(['order_process_finally' => $data['action_process'], 'action_uid_finally' => $data['action_uid'], 'action_name_finally' => $data['action_name']]);
+
         //把上一个节点改成已完成
         Db::name('process_wait')
-            ->where(['order_type' => $data['order_type'], 'order_process' => $data['action_status'], 'order_code' => $data['order_code'], 'order_id' => $data['order_id'], 'status' => self::$status_wait_handle])
-            ->update(['status' => self::$status_handle_finish, 'updatetime' => date('Y-m-d H:i:s')]);
+            ->where(['order_type' => $data['order_type'], 'order_process' => $data['action_status'], 'order_code' => $data['order_code'], 'order_id' => $data['order_id'], 'status' => self::$status_wait])
+            ->update(['status' => self::$status_finish, 'updatetime' => date('Y-m-d H:i:s')]);
 
         //查询流程下该节点值的id
-        $id = Db::name('process')
+        $info = Db::name('process')
             ->alias('a')
-            ->join('action_process p', 'p.process_id=a.id AND p.order_process=' . $data['action_process'] . ' AND p.operation_type = ' . ActionProcess::$operation_type_approval)
-            ->where(['a.process_type' => $data['order_type'], 'a.status' => Process::$status_normal, 'a.is_del' => Process::$is_del_normal])->value('p.id', 0);
+            ->field('p.id,p.action_type,p.operation_type,a.api_url')
+            ->join('action_process p', 'p.process_id=a.id AND p.order_process=' . $data['action_process'])
+            ->where(['a.process_type' => $data['order_type'], 'a.status' => Process::$status_normal, 'a.is_del' => Process::$is_del_normal])
+            ->findOrEmpty();
+
+        if ($info) {
+
+            //如果下一个节点是中断节点,则将相关记录删除,不再新增(只删除待办数据,221010145800@戴确认)
+            if ($info['action_type'] == ActionProcess::$action_type_interrupt) {
+                self::where(['order_type' => $data['order_type'], 'order_code' => $data['order_code'], 'order_id' => $data['order_id'], 'status' => self::$status_wait])
+                    ->update(['status' => self::$status_interrupt, 'updatetime' => date('Y-m-d H:i:s')]);
+                return true;
+            }
 
-        if ($id) {
+            //如果是系统节点,不写入待办已办数据
+            if ($info['operation_type'] == ActionProcess::$operation_type_system) return true;
 
             //如果是以下4个流程,还需要判断对应供应商是否开通账号,如果开通的话就不推送待办已办数据
-            if (in_array($data['order_type'], ['CKD', 'RKD', 'CGD', 'SPCB'])) {
+            if (in_array($data['order_type'], ['CKD', 'RKD', 'CGD'])) {
 
                 switch ($data['order_type']) {
                     //发货申请单流程
@@ -76,12 +94,12 @@ class ProcessWait extends Model
                             ->value('supplierNo');
                         break;
 
-                    //商品成本流程
-                    case 'SPCB':
-                        $supplierNo = Db::name('good_basic')
-                            ->where(['is_del' => 0, 'spuCode' => $data['order_code'],])
-                            ->value('supplierNo');
-                        break;
+//                    //商品成本流程--要根据节点的值来判断是否推送待办数据
+//                    case 'SPCB':
+//                        $supplierNo = Db::name('good_basic')
+//                            ->where(['is_del' => 0, 'spuCode' => $data['order_code'],])
+//                            ->value('supplierNo');
+//                        break;
 
                     default:
                         $supplierNo = '';
@@ -101,38 +119,52 @@ class ProcessWait extends Model
                         ->isEmpty();
 
                     if (!$res) return true;
+
                 }
 
             }
 
+            //如果是SPCB的话,以下节点值推送待办数据(0新建待审核,2基础修改待审核,3成本修改待审核)
+            if ($data['order_type'] == 'SPCB' && !in_array($data['action_process'], [0, 2, 3])) return true;
+
             $insert_data = [
                 'order_type' => $data['order_type'],
                 'order_code' => $data['order_code'],
                 'order_id' => $data['order_id'],
                 'action_uid' => $data['action_uid'],
                 'action_name' => $data['action_name'],
-                'status' => self::$status_wait_handle,
+                'status' => self::$status_wait,
                 'order_process' => $data['action_process'],
+                'order_process_finally' => $data['action_process'],
+                'action_uid_finally' => $data['action_uid'],
+                'action_name_finally' => $data['action_name'],
                 'addtime' => date('Y-m-d H:i:s'),
                 'updatetime' => date('Y-m-d H:i:s'),
             ];
 
             if ($wait_id) {
+                $insert_data['handle_user_list'] = $wait_id;//handle_user_list当前待处理人的uid集合
                 $insert_data['wait_id'] = $wait_id;
                 $insert_data['wait_name'] = $wait_name;
             } else {
                 //查询该节点值对应的角色id
                 $roleid = Db::name('role_process')
-                    ->whereFindInSet('action_data', $id)
+                    ->whereFindInSet('action_data', $info['id'])
                     ->where('is_del', 0)
                     ->column('role_id');
                 $insert_data['roleid'] = implode(',', $roleid);
+
+                //针对议价单流程,待boss审核节点,做特殊处理
+                if ($data['order_type'] == 'YJD' && $data['action_process'] == 7) $insert_data['handle_user_list'] = implode(',', Db::name('user_role')->whereIn('roleid', $roleid)->where(['is_del' => 0, 'status' => 1])->where('roleid', '<>', 1)->column('uid'));
+                else $insert_data['handle_user_list'] = $handle_user_list ? $handle_user_list : implode(',', get_handle_user_list($info['id'], $data['holder_id'] ?? 0, $info['api_url'], $data['person_id'] ?? 0));//handle_user_list当前待处理人的uid集合
             }
 
             //增加新的节点
             return self::create($insert_data)->save();
         }
 
+        return true;
+
     }
 
 }

+ 41 - 0
app/admin/model/SaleInfo.php

@@ -0,0 +1,41 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class SaleInfo extends Model
+{
+		/**
+		* @param string $orderCode
+		* @param int $sendNum
+		 * @return bool
+		* @throws \think\db\exception\DataNotFoundException
+		* @throws \think\db\exception\DbException
+		* @throws \think\db\exception\ModelNotFoundException
+	 */
+    static function SendStock(string $orderCode,int $sendNum){
+			$arr=self::where([["orderCode","=",$orderCode],["send_num",">",0]])->select()->toArray();
+			if(empty($arr))throw new \Exception("未找到可用的批次库存数据",1006);
+			$stockid = array_unique(array_column($arr,"stockid"));
+			$stock=self::name("good_stock")->where(["id"=>$stockid])->column("id,usable_stock,wait_out_stock",'id');
+			foreach ($arr as $value){
+				$temp=["send_num"=>0,"updatetime"=>date("Y-m-d H:i:s")];
+				if($sendNum >$value['send_num']){
+					$sendNum-=$value['send_num'];
+					$stockup=["total_stock"=>$stock[$value['stockid']]['wait_out_stock']+$stock[$value['stockid']]['usable_stock'],"wait_out_stock"=>$stock[$value['stockid']]['wait_out_stock']-$value['send_num'],"updatetime"=>date("Y-m-d H:i:s")];
+				}else{
+				$temp['send_num'] =$value['send_num']-$sendNum;
+				$stockup=["total_stock"=>$stock[$value['stockid']]['wait_out_stock']+$stock[$value['stockid']]['usable_stock'],"wait_out_stock"=>$stock[$value['stockid']]['wait_out_stock']-$sendNum,"updatetime"=>date("Y-m-d H:i:s")];
+				$sendNum=0;
+				}
+				self::where($value)->update($temp);
+				self::name("good_stock")->where($stock[$value['stockid']])->update($stockup);
+			}
+			return true;
+    }
+}

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

@@ -23,7 +23,8 @@ class Workflow extends \think\Model
         if((is_array($header)&&in_array($data['action_process'],$header))||$header==$data['action_process']){
             $order_status=1; //流程新建
         }
-        $proces = self::where(["order_type"=>$data['order_type'],"order_code"=>$data['order_code'],"is_del"=>0])->find();
+        $proces = self::where(["order_type"=>$data['order_type'],"order_id"=>$data['order_id'],"is_del"=>0])->find();
+
         if($proces){
             $info=[
                 "order_process"=>$data['order_status'],

+ 17 - 16
app/admin/route/app.php

@@ -78,12 +78,12 @@ Route::rule('resultedit','admin/Result/edit');
 Route::rule('resultdel','admin/Result/del');
 Route::rule('resultstatu','admin/Result/statu');
 
-Route::rule('Resigninfolist','admin/Resigninfo/list');
-Route::rule('Resigninfocreate','admin/Resigninfo/create');
+Route::rule('Resigninfolist','admin/Resigninfo/list');//离职交接单列表
+Route::rule('Resigninfocreate','admin/Resigninfo/create');//离职交接单创建
 Route::rule('Resigninfoselect','admin/Resigninfo/selec');
-Route::rule('Resigninfoedit','admin/Resigninfo/edit');
-Route::rule('Resigninfodel','admin/Resigninfo/del');
-Route::rule('Resigninfostatu','admin/Resigninfo/statu');
+Route::rule('Resigninfoedit','admin/Resigninfo/edit');//离职交接单编辑
+Route::rule('Resigninfodel','admin/Resigninfo/del');//离职交接单作废
+Route::rule('Resigninfostatu','admin/Resigninfo/statu');//离职交接单审核
 
 Route::rule('Consultlist','admin/Consult/list');
 Route::rule('Consultinfo','admin/Consult/info');
@@ -91,11 +91,11 @@ Route::rule('Consultdel','admin/Consult/del');
 
 Route::rule('infolist','admin/Listcustomer/list');
 
-Route::rule('salecreate','admin/Sale/create');
-Route::rule('salelist','admin/Sale/list');
-Route::rule('saleedit','admin/Sale/edit');
-Route::rule('saleinfo','admin/Sale/info');
-Route::rule('saledelect','admin/Sale/del');
+Route::rule('salecreate','admin/Sale/create');//参加销售订单
+Route::rule('salelist','admin/Sale/list');//销售订单列表
+Route::rule('saleedit','admin/Sale/edit');//编辑销售订单
+Route::rule('saleinfo','admin/Sale/info');//销售订单详情
+Route::rule('saledelect','admin/Sale/del');//删除销售订单
 Route::rule('salestatus','admin/Sale/status');
 Route::rule('salefee','admin/Sale/fee');
 Route::rule('saleout','admin/Sale/out');
@@ -117,7 +117,7 @@ Route::rule('checkgood','admin/Check/goodlist');
 Route::rule('checkcreate','admin/Check/create');
 Route::rule('checkinfo','admin/Check/info');
 Route::rule('checkedit','admin/Check/edit');
-Route::rule('checkedell','admin/Check/dell');
+Route::rule('checkedell','admin/Check/dell');//作废盘点单
 Route::rule('checkestatus','admin/Check/statu');
 Route::rule('checkexport','admin/Check/exportGood');
 Route::rule('checkimport','admin/Check/importGood');
@@ -131,6 +131,7 @@ Route::rule('allotstatus','admin/Allot/status');
 Route::rule('allotgetont','admin/Allot/getont');
 Route::rule('allotgetin','admin/Allot/getin');
 Route::rule('allotvesio','admin/Allot/vesio');
+Route::rule('allotgood','admin/Allot/goodlist');
 
 Route::rule('userlist', 'admin/User/list');
 Route::rule('userinfo', 'admin/User/userInfo');
@@ -182,7 +183,7 @@ Route::rule("goodloglist","admin/Good/loglist");
 Route::rule("goodplist","admin/Good/goodlist");
 Route::rule("getgoodlistbyladder","admin/Good/getGoodListByLadder");
 
-Route::rule("purchlist","admin/Resign/list");
+Route::rule("purchlist","admin/Resign/list");//备库单列表
 Route::rule("purchadd","admin/Resign/add");//创建备库单
 Route::rule("purchcopy","admin/Resign/copy");
 Route::rule("purchedit","admin/Resign/edit");
@@ -197,7 +198,7 @@ Route::rule("feeddel","admin/Resign/delFeed");
 Route::rule("feedchange","admin/Resign/changeFeed");
 Route::rule("feedinfo","admin/Resign/infoFeed");
 
-Route::rule("cgdlist","admin/Purch/list");
+Route::rule("cgdlist","admin/Purch/list");//采购单列表
 Route::rule("cgdinfo","admin/Purch/info");
 Route::rule("cgdedit","admin/Purch/edit");
 Route::rule("cgdeditnew","admin/Purch/editNew");//修改采购单的供应商
@@ -268,8 +269,8 @@ Route::rule('aftercancel','admin/After/Cancel');
 Route::rule('createSaleAndCgdByAfter','admin/After/createSaleAndCgdByAfter');
 //Route::rule('aftersetwsm','admin/After/setWsm');
 
-Route::rule('processolist','admin/Proorder/list');
-Route::rule('processowaitlist','admin/Proorder/waitlist');
+Route::rule('processolist','admin/Proorder/list');//我的已办
+Route::rule('processowaitlist','admin/Proorder/waitlist');//我的待办
 Route::rule('processoall','admin/Proorder/all');
 
 Route::rule('orderbacklist','admin/Orderback/list');
@@ -371,7 +372,7 @@ Route::rule('unitstatus','admin/Unit/status');
 
 Route::rule('goodupcreate','admin/Goodup/create');//创建商品成本
 //Route::rule('gooduplist','admin/Goodup/list');
-Route::rule('goodupeditinfo','admin/Goodup/editinfo');
+Route::rule('goodupeditinfo','admin/Goodup/editinfo');//修改商品成本基础信息
 Route::rule('goodupinfo','admin/Goodup/info');
 Route::rule('goodupeditfee','admin/Goodup/editfee');
 Route::rule('goodupdelall','admin/Goodup/delall');

+ 1 - 1
app/command/ImportOrderFromCAnalysisData.php

@@ -34,7 +34,7 @@ class ImportOrderFromCAnalysisData extends Command
 
             $rs = Db::name('order_import_from_c')
                 ->where(['is_del' => OIFCModel::$is_del_normal, 'status' => OIFCModel::$status_wait_validate])
-                ->lock(true)
+//                ->lock(true)
                 ->find();
 
             if (empty($rs)) throw new Exception('无符合条件的记录');

+ 126 - 69
app/command/ImportOrderFromCHandleData.php

@@ -5,7 +5,7 @@ namespace app\command;
 
 use app\admin\model\ActionLog;
 use app\admin\model\GoodLog;
-use app\admin\model\OrderImportFromC as OIFCModel;
+use app\admin\model\GoodStockInfo;use app\admin\model\OrderImportFromC as OIFCModel;
 use app\admin\model\ProcessOrder;
 use app\admin\model\Test1;
 use think\console\Command;
@@ -15,11 +15,18 @@ use think\console\input\Option;
 use think\console\Output;
 use think\Exception;
 use think\facade\Cache;
+use think\facade\Config;
 use think\facade\Db;
 
 //C端订单导入-处理
 class ImportOrderFromCHandleData extends Command
 {
+
+    private $cgd_data = [];//存储采购单的数据,目前是为了做供应商api推送而准备的
+
+
+
+
     protected function configure()
     {
         // 指令配置
@@ -40,7 +47,7 @@ class ImportOrderFromCHandleData extends Command
 
             $c_data = $order_import_from_c_db
                 ->where(['is_del' => OIFCModel::$is_del_normal, 'status' => OIFCModel::$status_wait_relation, 'id' => $c_data_id])
-                ->lock(true)
+//                ->lock(true)
                 ->field('id,createrid,creater')
                 ->find();
 
@@ -108,15 +115,26 @@ class ImportOrderFromCHandleData extends Command
                     $is_activity = empty($extend_data['activity_name']) ? 0 : 1;
 
                     if ($goodinfo['is_stock'] == 1) {
-                        $stock = Db::name("good_stock")
-                            ->alias("a")
-                            ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
-                            ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, 'b.wsm_type' => 5, "b.companyNo" => $supplierNo])
-                            ->field("a.id,a.usable_stock,a.wait_out_stock")
-                            ->find();
-
-                        if ($stock == false || $stock['usable_stock'] < $good_num) throw new Exception('库存数量不足');
-
+//                        $stock = Db::name("good_stock")
+//                            ->alias("a")
+//                            ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
+//                            ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, 'b.wsm_type' => 5, "b.companyNo" => $supplierNo])
+//                            ->field("a.id,a.usable_stock,a.wait_out_stock,a.wsm_code")
+//                            ->find();
+//
+//                        if ($stock == false || $stock['usable_stock'] < $good_num) throw new Exception('库存数量不足');
+//							$stock_num =Db::name("good_stock_info")->where(["stockid"=>$stock['id']])->sum('balance_num');
+//				            if($stock_num <  $good_num){
+//				              throw new Exception('bn库存数量不足');
+//				            }
+			            $stock_num = Db::name("good_stock")->alias("a")
+			            ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
+			            ->leftJoin("good_stock_info c", "a.id=c.stockid and c.balance_num>0")
+			            ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, "b.wsm_type" => 5, "b.companyNo" =>$supplierNo])
+			            ->sum('balance_num');
+			            if($stock_num < $good_num){
+			               throw new Exception('bn库存数量不足');
+			            }
                         $origin_price = 0;
 
                     } else {
@@ -174,6 +192,10 @@ class ImportOrderFromCHandleData extends Command
                             //$sale_price = $act['activity_price'];//不能改动价格
                         }
                     }
+                     $supplier_temp_info = Db::name('supplier')
+                        ->field('id,person,personid')
+                        ->where('code', $ct['supplierNo'])
+                        ->findOrEmpty();
                     $cgd = [
                         "supplierNo" => $ct['supplierNo'],
                         "companyNo" => $supplierNo,
@@ -195,12 +217,13 @@ class ImportOrderFromCHandleData extends Command
                         "good_type" => $goodtype,
                         "order_type" => $order_type,
                         "order_source" => $order_source,
-                        "createrid" => $ct['createrid'],
-                        "creater" => $ct['creater'],
+                        "createrid" =>$supplier_temp_info['personid'],
+                         "creater" =>$supplier_temp_info['person'],
                         'send_way' => 2,
                         'gold_price' => $ct['cgd_gold_price'],
                         'good_createrid' => $goodinfo['createrid'],
                         'good_creater' => $goodinfo['creater'],//商品创建人
+                        "weight"=>$ct['noble_weight']
                     ];
 
                     $send_num = $extend_data['num'];
@@ -208,10 +231,6 @@ class ImportOrderFromCHandleData extends Command
                     $rm = $c_data['createrid'];
                     $ri = $c_data['creater'];
 
-                    $supplier_temp_info = Db::name('supplier')
-                        ->field('id,person,personid')
-                        ->where('code',$ct['supplierNo'])
-                        ->findOrEmpty();
 
                     $data = [
                         "orderCode" => $orderCode,
@@ -292,25 +311,36 @@ class ImportOrderFromCHandleData extends Command
 
                         } else {
                             //库存品
-                            $bol = $this->RelaCgd(['orderCode' => $orderCode, "good_num" => $good_num, "spuCode" => $spuCode, "companyNo" => $supplierNo, 'order_type' => $order_type, 'order_source' => $order_source,'good_createrid'=>$ct['createrid'],'good_creater'=>$ct['creater']], $standing_book_data);
-                            if ($bol == false) throw new Exception('库存商品关联采购单失败');
-
-                            if (isset($stock)) {
-                                $stck = [
-                                    "usable_stock" => $stock['usable_stock'] - $good_num,
-                                    "wait_out_stock" => $stock['wait_out_stock'] + $good_num,
-                                    "updatetime" => date("Y-m-d H:i:s")
-                                ];
-                                $upad = Db::name("good_stock")
-                                    ->where($stock)
-                                    ->update($stck);
-                                if ($upad == false) throw new Exception('库存商品更新库存失败');
-
-                                //商品变动日志表,good_log_code字段存储采购单号
-                                $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $datainfo, "type" => 2, 'stock' => $good_num, "stock_name" => "usable_stock"];
-                                $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $datainfo, "type" => 1, 'stock' => $good_num, "stock_name" => "wait_out_stock"];
-                                GoodLog::LogAdd(['id' => $rm, 'nickname' => $ri], $good_data, "XSQRD");
-                            }
+//                            $bol = $this->RelaCgd(['orderCode' => $orderCode, "good_num" => $good_num, "spuCode" => $spuCode, "companyNo" => $supplierNo, 'order_type' => $order_type, 'order_source' => $order_source,'good_createrid'=>$ct['createrid'],'good_creater'=>$ct['creater']], $standing_book_data);
+//                            if ($bol == false) throw new Exception('库存商品关联采购单失败');
+						 $stockid= Db::name("good_stock")->alias("a")
+			            ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
+			            ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, "b.wsm_type" => 5, "b.companyNo" =>$supplierNo])
+			            ->column('a.id');
+	                        $stockinfo =GoodStockInfo::OrderBn($orderCode,$stockid,intval($good_num));
+	                        if($stockinfo==false){
+	                             throw new Exception('库存商品更新库存失败');
+	                        }
+
+//                            if (isset($stock)) {
+//                                $stck = [
+//                                    "usable_stock" => $stock['usable_stock'] - $good_num,
+//                                    "wait_out_stock" => $stock['wait_out_stock'] + $good_num,
+//                                    "updatetime" => date("Y-m-d H:i:s")
+//                                ];
+//                                $upad = Db::name("good_stock")
+//                                    ->where($stock)
+//                                    ->update($stck);
+//                                if ($upad == false) throw new Exception('库存商品更新库存失败');
+//								 $stockinfo =GoodStockInfo::OrderBn($orderCode,$stock['id'],$good_num);
+//		                        if($stockinfo==false){
+//		                                throw new Exception('bn库存商品更新库存失败');
+//		                        }
+//                                //商品变动日志表,good_log_code字段存储采购单号
+//                                $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $datainfo, "type" => 2, 'stock' => $good_num, "stock_name" => "usable_stock"];
+//                                $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $datainfo, "type" => 1, 'stock' => $good_num, "stock_name" => "wait_out_stock"];
+//                                GoodLog::LogAdd(['id' => $rm, 'nickname' => $ri], $good_data, "XSQRD");
+//                            }
 
                         }
                         if ($sendtype == 1) {
@@ -330,34 +360,35 @@ class ImportOrderFromCHandleData extends Command
                             ];
                             $vmp = Db::name('order_addr')->insert($temp, true);
                             if ($vmp > 0) {
-                                $order = Db::name("order_num")
-                                    ->where(["orderCode" => $orderCode, "status" => 1])
-                                    ->where([["wsend_num", ">=", 0]])
-                                    ->lock(true)
-                                    ->find();
-                                if ($order == false) throw new Exception('未找到可以发货得采购单数据');
-
-
-                                $num = $extend_data['num'];
+                            	 $num = $extend_data['num'];
                                 $outCode = makeNo("DF");
-                                $order['wsend_num'] -= $num;
-                                $order['send_num'] += $num;
-                                $or = Db::name("order_num")->save($order);
-                                if ($or == false) throw new Exception('发货地址更新失败');
-
-                                $tep = [
-                                    "cgdNo" => $order['cgdNo'],
-                                    "outCode" => $outCode,
-                                    "send_num" => $num,
-                                    "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) throw new Exception('发货地址添加创建失败');
-
-                                $cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
-                                if ($cgdinfo == false) throw new Exception('未匹配到采购数据');
+                            	if($is_stock!=1){
+	                                    $order = Db::name("order_num")
+	                                    ->where(["orderCode" => $orderCode, "status" => 1])
+	                                    ->where([["wsend_num", ">=", 0]])
+//	                                    ->lock(true)
+	                                    ->find();
+	                                if ($order == false) throw new Exception('未找到可以发货得采购单数据');
+	                                $order['wsend_num'] -= $num;
+	                                $order['send_num'] += $num;
+	                                $or = Db::name("order_num")->save($order);
+	                                if ($or == false) throw new Exception('发货地址更新失败');
+
+	                                $tep = [
+	                                    "cgdNo" => $order['cgdNo'],
+	                                    "outCode" => $outCode,
+	                                    "send_num" => $num,
+	                                    "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) throw new Exception('发货地址添加创建失败');
+
+	                                $cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
+	                                if ($cgdinfo == false) throw new Exception('未匹配到采购数据');
+
+                            	}
 
                                 $out = [
                                     "orderCode" => $orderCode,
@@ -372,7 +403,7 @@ class ImportOrderFromCHandleData extends Command
                                     "send_num" => $num,
                                     "check_num" => 0,
                                     "error_num" => 0,
-                                    "wsm_code" => $cgdinfo['wsm_code'],
+                                    "wsm_code" =>$is_stock==1?'': $cgdinfo['wsm_code'],
                                     "order_type" => $order_type,
                                     "status" => $is_stock == 1 ? 1 : 0,
                                     "addtime" => date("Y-m-d H:i:s"),
@@ -394,7 +425,8 @@ class ImportOrderFromCHandleData extends Command
                                         "order_code" => $outCode,//出库单号
                                         "order_id" => 0,
                                         "order_status" => 0,
-                                        "before_status" => 0
+                                        "before_status" => 0,
+                                        'holder_id' => $out['apply_id']
                                     ]);
 
                                     $standing_book_data['outCode'] = $outCode;
@@ -421,6 +453,25 @@ class ImportOrderFromCHandleData extends Command
                     //维护台账记录
                     Db::name('standing_book')->insert(array_merge($standing_book_data, ['addtime' => date('Y-m-d H:i:s'), 'updatetime' => date('Y-m-d H:i:s'), 'standBookNo' => makeNo("IO")]));
 
+                    //将采购单数据塞入到队列中
+                    if ($this->cgd_data) {
+                        $push_data = json_encode([
+                            'supplierNo' => $this->cgd_data['supplierNo'],
+                            'type' => 1,//1销售订单(采销的采购单),2上线结果
+                            'data' => [
+                                'cgdNo' => $this->cgd_data['cgdNo'],
+                                'spuCode' => $this->cgd_data['spuCode'],
+                                'good_name' => $this->cgd_data['good_name'],
+                                'good_num' => $this->cgd_data['good_num'],
+                                'good_price' => $this->cgd_data['good_price'],
+                                'total_fee' => $this->cgd_data['total_fee'],
+                                'weight' => $this->cgd_data['weight'],
+                                'addtime' => $this->cgd_data['addtime'],
+                            ],
+                        ], JSON_UNESCAPED_UNICODE);
+                        Cache::store("redis")->handler()->lPush(Config::get('app.abutment_queue'), $push_data);
+                    }
+
                     Db::commit();
 
                     $output->writeln(date('Y-m-d H:i:s') . '|处理成功');
@@ -480,7 +531,6 @@ class ImportOrderFromCHandleData extends Command
         } else {
             $wsm_code = $wsm['wsm_code'];
         }
-
         $cg = [
             "cgdNo" => $cgdCode,
             "bkcode" => "",
@@ -501,7 +551,7 @@ class ImportOrderFromCHandleData extends Command
             "demo_fee" => $data['demo_fee'],
             "nake_fee" => $data['nake_fee'],
             "delivery_fee" => $data['delivery_fee'],
-            #"weight"=>$data['weight'],
+            "weight"=>$data['weight'],
             "diff_weight" => "0",
             "diff_fee" => "0",
             "gold_price" => $data['gold_price'],
@@ -534,12 +584,16 @@ class ImportOrderFromCHandleData extends Command
                 "action_type" => "create"//新建create,编辑edit,更改状态status
             ], "CGD", $cg['status'], $cg);
 
+            //当采购单是节点0待与供应商确认,推给供应商负责人
             ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], [
                 "order_type" => 'CGD',
                 "order_code" => $cg['cgdNo'],//销售单code
                 "order_id" => $up,
                 "order_status" => $cg['status'],
-                "before_status" => 0
+                "before_status" => 0,
+                'holder_id' => $supplier['personid'],
+                'wait_id'=>$supplier['personid'],
+                'wait_name'=>$supplier['person'],
             ]);
 
             $standing_book_data['cgdNo'] = $cgdCode;
@@ -585,6 +639,8 @@ class ImportOrderFromCHandleData extends Command
                 $good_data[] = ['good_log_code' => $cgdCode, "stock_id" => isset($stoc['id']) ? $stoc['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1, 'stock' => $data['good_num'], "stock_name" => "wait_in_stock"];
                 GoodLog::LogAdd(['id' => 0, 'nickname' => 'system'], $good_data, "CGD");
 
+                $this->cgd_data = $cg;
+
                 return true;
             }
         } else return false;
@@ -603,7 +659,7 @@ class ImportOrderFromCHandleData extends Command
                 ["balance_num", ">=", $outinfo['good_num']],
                 ['companyNo', "=", $outinfo['companyNo']]
             ])
-            ->lock(true)
+//            ->lock(true)
             ->find();
 
         if ($cgd == false) return false;
@@ -688,6 +744,7 @@ class ImportOrderFromCHandleData extends Command
         $order = Db::name("order_num")->save($data);
         if ($order == false) return false;
 
+        $this->cgd_data = $QrdCgd;
         return true;
     }
 

+ 134 - 75
app/command/NowReportHandle.php

@@ -80,6 +80,10 @@ class NowReportHandle extends Command
                     case 'K':
                         $res = $this->K($info['start'], $info['end']);
                         break;
+                         //【库存报表】-库存品出库明细
+                    case 'L':
+                        $res = $this->NewOut($info['start'], $info['end']);
+                        break;
                     default:
                         throw new Exception('暂不支持这个报表');
                 }
@@ -179,7 +183,7 @@ class NowReportHandle extends Command
 							wait_in_stock '待入库存数量',
 							wait_out_stock '待出库存数量',
 							usable_stock '可用库存数量',
-							wait_out_stock+usable_stock '当前库存',
+							wait_out_stock+usable_stock '当前库存数量',
 							'' as '可用库存金额',
 							'' as '当前库存金额',
 							'' as '保质期时间',
@@ -187,7 +191,7 @@ class NowReportHandle extends Command
 							wgb.creater as 'CGD.采购员',
 							ws.`name` as '供应商名称',
 							wwi.`name` as '仓库名称',
-							'' as '最近入库时间' ")
+							wp.addtime as '备库创建时间' ")
             ->leftJoin('purchease_order wpo', 'wgs.spuCode = wpo.spuCode and order_source=0')
             ->leftJoin('purchease wp', 'wp.bk_code = wpo.bkcode')
             ->leftJoin('warehouse_info wwi', 'wwi.wsm_code = wgs.wsm_code')
@@ -206,12 +210,11 @@ class NowReportHandle extends Command
             $value['申请部门'] = get_company_name_by_uid(intval($value['申请部门']));
             $value['一级分类'] = isset($cat[0]['name'])?$cat[0]['name']:"";
             $value['可用库存金额'] = bcmul((string)$value['可用库存数量'] ?? '0', (string)$value['成本单价'] ?? '0', 2);
-            $value['当前库存金额'] = bcmul((string)$value['当前库存'] ?? '0', (string)$value['成本单价'] ?? '0', 2);
-            $value['最近入库时间'] =Db::name("purchease_order")->alias("a")->leftJoin("purchease_in c","a.cgdNo=c.cgdNo")->where(["spuCode"=>
-                $value['产品编号'],"order_type"=>1,"order_source"=>0,"c.status"=>[4,6]])->order("a.addtime desc")->value("c.addtime","");
-            if (!empty($value['最近入库时间'])) {
-                $value['保质期时间'] = date('Y-m-d H:i:s', strtotime($value['最近入库时间']) + 31536000);//365天之后
-                $value['库存天数'] = bcdiv((string)(time() - strtotime($value['最近入库时间'])), (string)(24 * 3600));//365天之后
+            $value['当前库存金额'] = bcmul((string)$value['当前库存数量'] ?? '0', (string)$value['成本单价'] ?? '0', 2);
+//            $value['最近入库时间'] =Db::name("purchease_order")->alias("a")->leftJoin("purchease_in c","a.cgdNo=c.cgdNo")->where(["spuCode"=>$value['产品编号'],"order_type"=>1,"order_source"=>0,"c.status"=>[4,6]])->order("a.addtime desc")->value("c.addtime","");
+            if (!empty($value['备库创建时间'])) {
+                $value['保质期时间'] = date('Y-m-d H:i:s', strtotime($value['备库创建时间']) + 31536000);//365天之后
+                $value['库存天数'] = bcdiv((string)(time() - strtotime($value['备库创建时间'])), (string)(24 * 3600));//365天之后
             }
             yield $list[] = $value;
         }
@@ -318,7 +321,7 @@ class NowReportHandle extends Command
             ->leftJoin("supplier ws","ws.code=wpo.supplierNo")
             ->where('woo.status',">=", 2)
             ->where('woo.is_del',"=", 0)
-            ->whereBetween('woo.addtime', [$start, $end])
+            ->whereBetween('woo.sendtime', [$start, $end])
             ->field(" year(`a`.`addtime`) AS `年`,
             month(`a`.`addtime`) AS `月`,
             dayofmonth(`a`.`addtime`) AS `日`,
@@ -379,7 +382,7 @@ class NowReportHandle extends Command
                 $value['单位']=Db::name("unit")->where(["id"=>$value['单位']])->value("unit",'');
                 if($value['是否库存品']==1){
                     $sendtype = Db::name("purchease_order")->alias("a")->leftJoin("purchease_in b","a.cgdNo=b.cgdNo and b.is_del=0")
-                        ->where(["bkcode"=>$value['发货方式'],"order_type"=>1])->order("b.addtime desc")
+                        ->where(["bkcode"=>$value['发货方式'],"order_type"=>1,"order_source"=>0])->order("b.addtime desc")
                         ->value("b.sendtype",'');
                     $value['是否库存品']='是';
                 }else{
@@ -423,7 +426,7 @@ class NowReportHandle extends Command
                                wpo.good_name as '商品名称',
                             if(wpi.status=4,wpi.send_num,wpi.wsm_num) '入库数量',
 	                        round( if(wpi.status=4,wpi.send_num,wpi.wsm_num) * good_price, 2 ) '入库金额',
-                               wpo.updatetime '本次入库时间',
+                               wpi.updatetime '本次入库时间',
                             wgb.tax/100 '采购税率',
                             '' as '不含税入库金额',
                             ''  as '税额',
@@ -433,7 +436,8 @@ class NowReportHandle extends Command
                                wpo.good_price '成本裸价',
                                wsm_type '仓库类型',
                                ws.name '供应商名称',
-                               wwi.name '仓库名称'
+                               wwi.name '仓库名称',
+                               wp.addtime '备库创建时间'
              ")->cursor();
         $data=[];
         foreach($list as $value){
@@ -466,27 +470,27 @@ class NowReportHandle extends Command
                             bkcode '备库单号',
                             woo.orderCode '销售单号',
                             woo.outCode '出库单号',
-                             wpo.cgdNo '采购单号',
-                               wpo.spuCode '商品编号',
-                               '' as '一级分类',
-                               '' as '二级分类',
-                                wgb.cat_id as '三级分类',
-                                wgb.cat_id as '财务核算编号',
-                               wpo.good_name as '商品名称',
-                                woo.send_num'出库数量',
-                               round( woo.send_num* wpo.good_price,2) '出库金额',
-                               woo.sendtime '本次出库时间',
-                                wgb.tax/100 '税率',
+                            wpo.cgdNo '采购单号',
+                            wpo.spuCode '商品编号',
+                            '' as '一级分类',
+                            '' as '二级分类',
+                            wgb.cat_id as '三级分类',
+                            wgb.cat_id as '财务核算编号',
+                            wpo.good_name as '商品名称',
+                            woo.send_num'出库数量',
+                            round( woo.send_num* wpo.good_price,2) '出库金额',
+                            woo.sendtime '本次出库时间',
+                            wgb.tax/100 '税率',
                             '' as '不含税出库金额',
                             ''as '税额',
-                               a.apply_id as '业务部门',
-                               a.apply_name as '业务员',
-                              wpo.cgder as '采购员',
-                               wpo.good_price '成本裸价',
-                               wor.return_num  '出库退货数量',
-                               wwi.wsm_type '仓库类型',
-                               ws.name '供应商名称',
-                               wwi.name '仓库名称'
+                            a.apply_id as '业务部门',
+                            a.apply_name as '业务员',
+                            wpo.cgder as '采购员',
+                            wpo.good_price '成本裸价',
+                            wor.return_num  '出库退货数量',
+                            wwi.wsm_type '仓库类型',
+                            ws.name '供应商名称',
+                            wwi.name '仓库名称'
              ")->cursor();
         $data=[];
         foreach($list as $value){
@@ -511,47 +515,47 @@ class NowReportHandle extends Command
         $list =$db->name("cgd_info")
           ->where(['ShortText1617866362204'=>'客服确认单'])->whereBetweenTime('createdTime',$start,$end)->field(
             "year(createdTime) AS `年`,
-month(createdTime) AS `月`,
-dayofmonth(createdTime) AS `日`,
-ShortText1618270466672 '公司名称',
-department '业务部门',
-ownerName '业务人员',
-ShortText1617866362204 '订单类型',
-'' as '商品类型',
-'' as '发货编号',
-Number1618240600907 '本次发货数量',
-createdTime '本次发货时间',
-ShortText1617866360004 '确认单编号',
-ShortText1617861001482 '商品编号',
-ShortText1617865626160 '一级分类',
-''as  '二级分类',
-'' as  '三级分类',
- '' as '财务核算编码',
- ShortText1617861966146 as '商品名称',
- ShortText1617865685744 as '单位',
- Number1618240600907 '下单数量',
- '' AS `销售货款`,
- ShortText1618315935182 as '采购单单号',
- ownerName '采购员',
-            Number1617865804813 AS `采购裸价`,
-           Number1617865807879 AS `加标费`,
-            Number1617865810822 AS `包装费`,
-          Number1617865813284 AS `证书费`,
-          Number1617865816181 AS `开模费`,
-          number1618240204358 AS `工艺费`,
-          number1618240287778 AS `物流费`,
-          Number1617865818517 AS `成本合计`,
-          Number1618240685904 AS `采购货款`,
-         ShortText1617865688485 AS `采购税点`, 
-		 ShortText1620399144946 AS `供应商名称`,
-							'否'as '是否库存品',
-              '' as '发货方式',
-              '' AS `退货编号`,
-		'' AS `退货数量`,
-		'' as '退货金额',
-		'' as '售前退货数量',
-		'' as '售前退货金额'
- ")->cursor();
+					month(createdTime) AS `月`,
+					dayofmonth(createdTime) AS `日`,
+					ShortText1618270466672 '公司名称',
+					department '业务部门',
+					ownerName '业务人员',
+					ShortText1617866362204 '订单类型',
+					'' as '商品类型',
+					'' as '发货编号',
+					Number1618240600907 '本次发货数量',
+					createdTime '本次发货时间',
+					ShortText1617866360004 '确认单编号',
+					ShortText1617861001482 '商品编号',
+					ShortText1617865626160 '一级分类',
+					''as  '二级分类',
+					'' as  '三级分类',
+					 '' as '财务核算编码',
+					 ShortText1617861966146 as '商品名称',
+					 ShortText1617865685744 as '单位',
+					 Number1618240600907 '下单数量',
+					 '' AS `销售货款`,
+					 ShortText1618315935182 as '采购单单号',
+					 ownerName '采购员',
+		            Number1617865804813 AS `采购裸价`,
+		            Number1617865807879 AS `加标费`,
+		            Number1617865810822 AS `包装费`,
+		            Number1617865813284 AS `证书费`,
+		            Number1617865816181 AS `开模费`,
+		            number1618240204358 AS `工艺费`,
+		            number1618240287778 AS `物流费`,
+		            Number1617865818517 AS `成本合计`,
+		            Number1618240685904 AS `采购货款`,
+		            ShortText1617865688485 AS `采购税点`, 
+				    ShortText1620399144946 AS `供应商名称`,
+					'否'as '是否库存品',
+		            '' as '发货方式',
+		            '' AS `退货编号`,
+					'' AS `退货数量`,
+					'' as '退货金额',
+					'' as '售前退货数量',
+					'' as '售前退货金额'
+                    ")->cursor();
         $data=[];
         foreach($list as $value){
             $value['销售货款'] = $db->name("qrd_info")->where(['sequenceNo'=>$value['确认单编号']])->value('Number1618248813613','');
@@ -667,7 +671,7 @@ ShortText1617865626160 '一级分类',
             ->leftJoin("good_zixun wgz", "wgz.spuCode=wpo.spuCode")
             ->leftJoin("supplier ws", "ws.code=wpo.supplierNo")
             ->where('woo.status', ">=", 2)
-            ->whereBetween('woo.addtime', [$start, $end])
+            ->whereBetween('woo.sendtime', [$start, $end])
             ->field(" year(`a`.`addtime`) AS `年`,month(`a`.`addtime`) AS `月`,dayofmonth(`a`.`addtime`) AS `日`,a.supplierNo as '公司名称', a.apply_id '业务部门名称' ,a.apply_name as '业务人员',a.order_type as '订单类型',a.good_type as '商品类型',woo.outCode '发货编号',`woo`.`send_num` AS `本次发货数量`,`woo`.`sendtime` AS `本次发货时间`,`woo`.`orderCode` AS `确认单编号`,`a`.`good_code` AS `商品编号`,'' as '一级分类','' as '二级分类',a.cat_id as '三级分类','' as '财务核算编码',a.good_name as '商品名称',ifnull( `wgb`.`good_unit`, `wgz`.`good_unit` ) as '单位',`a`.`good_num` AS `下单数量`,`wpo`.`cgdNo` AS `采购单单号`,`wpo`.`cgder` AS `采购员`,`ws`.`name` AS `供应商名称`,`wgb`.`is_stock`  as '是否库存品',if (`wgb`.`is_stock`=1,wpo.bkcode,wpo.cgdNo) as '发货方式',ifnull( `wor`.`thNo`, '' ) AS `退货编号`,ifnull( `wor`.`return_num`, '' ) AS `退货数量`,'' as '售前退货数量'")
             ->cursor();
         $order_tyepe = ["库存销售", '非库存销售', '咨询销售', '项目销售', '平台库存销售', '平台非库存销售'];
@@ -685,7 +689,10 @@ ShortText1617865626160 '一级分类',
             $value['三级分类'] = isset($cat[2]['name']) ? $cat[2]['name'] : "";
             $value['单位'] = Db::name("unit")->where(["id" => $value['单位']])->value("unit", '');
             if ($value['是否库存品'] == 1) {
-                $sendtype = Db::name("purchease_order")->alias("a")->leftJoin("purchease_in b", "a.cgdNo=b.cgdNo")->where(["bkcode" => $value['发货方式'], "order_type" => 1])->order("b.addtime desc")->value("b.sendtype", '');
+                $sendtype = Db::name("purchease_order")->alias("a")
+                ->leftJoin("purchease_in b", "a.cgdNo=b.cgdNo")
+                ->where(["bkcode" => $value['发货方式'], "order_type" => 1,"order_source"=>0])
+                ->order("b.addtime desc")->value("b.sendtype", '');
                 $value['是否库存品'] = '是';
             } else {
                 $sendtype = Db::name("purchease_order")->alias("a")->leftJoin("purchease_in b", "a.cgdNo=b.cgdNo")->where(["a.cgdNo" => $value['发货方式']])->order("b.addtime desc")->value("b.sendtype", '');
@@ -743,7 +750,7 @@ ShortText1617865626160 '一级分类',
             ->leftJoin("good_basic wgb", "wgb.spuCode=wpo.spuCode and wgb.is_del=0")
             ->leftJoin("supplier ws", "ws.code=wpo.supplierNo")
             ->leftJoin("warehouse_info wwi", "wwi.wsm_code = wpo.wsm_code")
-            ->where([['woo.status', ">=", 2],['woo.is_del',"=", 0],['a.order_type', "=", 1],['woo.addtime','between',[$start, $end]]])
+            ->where([['woo.status', ">=", 2],['woo.is_del',"=", 0],['a.order_type', "=", 1],['woo.sendtime','between',[$start, $end]]])
             ->field("wpo.companyNo '业务公司',bkcode '备库单号',woo.orderCode '销售单号',woo.outCode '出库单号',wpo.cgdNo '采购单号',wpo.spuCode '商品编号','' as '一级分类','' as '二级分类',wgb.cat_id as '三级分类',wpo.good_name as '商品名称',woo.send_num'出库数量',woo.sendtime '本次出库时间',a.apply_id as '业务部门',a.apply_name as '业务员',wpo.cgder as '采购员',wor.return_num  '出库退货数量',wwi.wsm_type '仓库类型',ws.name '供应商名称',wwi.name '仓库名称'")
             ->cursor();
         $data = [];
@@ -760,5 +767,57 @@ ShortText1617865626160 '一级分类',
         return $data;
     }
 
+    private function NewOut(string $start,string $end)
+    {
+		$data = Db::name("order_out")
+		->alias("a")
+		->leftJoin("sale b","a.orderCode=b.orderCode")
+		->leftJoin("depart_user du"," b.apply_id=du.uid and du.is_del=0")
+		->field("b.supplierNo '业务公司',a.orderCode AS '销售单号',outCode '出库单号',
+	b.good_code '商品编号',b.cat_id ,'' as '一级分类','' as '二级分类','' as  '三级分类','' as '财务核算编号',
+	b.good_name '商品名称',a.send_num '出库数量','' as '出库金额',a.sendtime '本次出库时间',
+    ''as '税率', b.apply_id as '业务部门',a.apply_name as '业务人员',cgder as '采购员','' as '成本裸价',
+	'' as '供应商名称','' as '出库退货数量',b.order_type")
+	->where([["a.status",">=",2],["a.is_del","=",0],["b.order_type","=",1],['a.sendtime','between',[$start, $end]]])
+	->cursor();
+		$list=[];
+		foreach ($data as $value){
+			 $value['业务公司'] = Db::name("business")->where(["companyNo" => $value['业务公司']])->value('company', '');
+			$value['业务部门'] = Db::name("depart_user")->alias("a")->leftJoin("company_item ci", "a.itemid=ci.id")->where(["a.uid" => $value['业务部门'], "a.status" => 1, "a.is_del" => 0])->value('ci.name', '');
+			$cat = made($value['cat_id']);
+			 $value['财务核算编号'] = Db::name("cat")->where(["id"=>$value['cat_id']])->value("fund_code",'');
+			 unset($value['cat_id']);
+             $value['一级分类'] = isset($cat[0]['name']) ? $cat[0]['name'] : "";
+             $value['二级分类'] = isset($cat[1]['name']) ? $cat[1]['name'] : "";
+             $value['三级分类'] = isset($cat[2]['name']) ? $cat[2]['name'] : "";
+			if($value["order_type"]==3){
+				$good =Db::name("good_zixun")->where(["spuCode"=>$value['商品编号']])->find();
+			}else{
+				$good =Db::name("good")->where(["spuCode"=>$value['商品编号']])->find();
+			}
+			$saleinfo =Db::name("sale_info")->where(["orderCode"=>$value['销售单号']])->field("num,origin_price,num*origin_price as total_price")->select()
+			->toArray();
+			if(empty($saleinfo)){
+				$value['成本裸价'] = Db::name("order_out")->alias("a")
+				->leftJoin("order_send b","a.outCode=b.outCode")
+				->leftJoin("purchease_order c","b.cgdNo=c.cgdNo")
+				->where(["a.outCode"=>$value['出库单号']])->value("c.good_price",'0');
+			}else{
+				$num=array_sum(array_column($saleinfo,"num"));
+				if($num==0){
+					$value['成本裸价']=0;
+				}else{
+					$value['成本裸价'] = round(array_sum(array_column($saleinfo,"total_price"))/ array_sum(array_column($saleinfo,"num"))
+						,2) ;
+				}
+			}
+			$value['出库金额'] = $value['出库数量']*$value['成本裸价'];
+			$value['税率'] = $good['tax']."%";
+			$value['供应商名称']=Db::name("supplier")->where(["code"=>$good['supplierNo']])->value("name","");
+			$value["出库退货数量"] = Db::name("order_back")->where(["outCode"=>$value['出库单号']])->sum("return_num");
+			unset($value['order_type']);
+			yield $list[] = $value;
+		}
+    }
 
 }

+ 80 - 0
app/command/UpdateProcessWaitFinallyActionData.php

@@ -0,0 +1,80 @@
+<?php
+declare (strict_types=1);
+
+namespace app\command;
+
+use think\console\Command;
+use think\console\Input;
+use think\console\input\Argument;
+use think\console\input\Option;
+use think\console\Output;
+use think\Exception;
+use think\facade\Db;
+
+class UpdateProcessWaitFinallyActionData extends Command
+{
+    protected function configure()
+    {
+        // 指令配置
+        $this->setName('UpdateProcessWaitFinallyActionData')
+            ->setDescription('更新待办数据表中的字段:最终操作人');
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+        //判断是否在执行中
+
+
+        Db::startTrans();
+        try {
+
+            //设置标识,执行中
+
+            Db::name('process_wait')
+                ->where('action_uid_finally','<>',0)
+                ->update(['action_uid_finally'=>0,'action_name_finally'=>'']);
+
+            $data = Db::name('process_wait')
+                ->field('order_code,order_type,order_id')
+                ->group('order_code,order_type,order_id')
+                ->whereIn('status', [1, 2])
+                ->cursor();
+
+            foreach ($data as $value) {
+
+                if($value['order_type'] == 'LZJJ') $order_code = $value['order_id'];//离职交接单,取id
+                else $order_code = $value['order_code'];
+
+                $action = Db::name('action_log')
+                    ->field('id,action_id,action_name')
+                    ->where([
+                        'order_code'=>$order_code,
+                        'order_type'=>$value['order_type']
+                    ])
+                    ->order('id','desc')
+                    ->findOrEmpty();
+
+                if ($action) Db::name('process_wait')
+                    ->where('order_code', $value['order_code'])
+                    ->where('order_type', $value['order_type'])
+                    ->update(['action_uid_finally' => $action['action_id'],'action_name_finally' => $action['action_name']]);
+            }
+
+            Db::commit();
+
+            $output->writeln('update success');
+
+            //解除标识,执行完毕
+
+        } catch (Exception $exception) {
+            Db::rollback();
+            $output->writeln('update fail,' . $exception->getMessage());
+            //解除标识,执行完毕
+
+        }
+
+
+    }
+
+
+}

+ 171 - 0
app/command/UpdateProcessWaitFinallyData.php

@@ -0,0 +1,171 @@
+<?php
+declare (strict_types=1);
+
+namespace app\command;
+
+use think\console\Command;
+use think\console\Input;
+use think\console\input\Argument;
+use think\console\input\Option;
+use think\console\Output;
+use think\Exception;
+use think\facade\Db;
+
+class UpdateProcessWaitFinallyData extends Command
+{
+    protected function configure()
+    {
+        // 指令配置
+        $this->setName('UpdateProcessWaitFinallyData')
+            ->setDescription('更新待办数据表中的字段:最终状态值');
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+        //判断是否在执行中
+
+
+
+        Db::startTrans();
+        try {
+
+            //设置标识,执行中
+
+
+            $data = Db::name('process_wait')
+                ->field('order_code,order_type,order_id')
+                ->group('order_code,order_type,order_id')
+                ->whereIn('status', [1, 2])
+                ->cursor();
+
+            foreach ($data as $value) {
+
+                $order_process_finally = 0;
+
+                switch ($value['order_type']) {
+                    //1.采购单流程
+                    case 'CGD':
+                        $order_process_finally = Db::name('purchease_order')->where(['id' => $value['order_id'], 'is_del' => 0])->value('status', 0);
+                        break;
+                    //2.采购单入库流程
+                    case 'RKD':
+                        $order_process_finally = Db::name('purchease_in')->where(['id' => $value['order_id'], 'is_del' => 0])->value('status', 0);
+                        break;
+                    //3.备货申请单流程
+                    case 'BHD':
+                        $order_process_finally = Db::name('purchease')->where(['id' => $value['order_id'], 'is_del' => 0])->value('status', 0);
+                        break;
+                    //4.销售订单流程
+                    case 'XSQRD':
+                        $order_process_finally = Db::name('sale')->where(['id' => $value['order_id'], 'is_del' => 0])->value('status', 0);
+                        break;
+                    //5.发货申请单流程
+                    case 'CKD':
+                        $order_process_finally = Db::name('order_out')->where(['id' => $value['order_id'], 'is_del' => 0])->value('status', 0);
+                        break;
+                    //6.售后申请单流程
+                    case 'SHD':
+                        $order_process_finally = Db::name('order_return')->where(['id' => $value['order_id'], 'is_del' => 0])->value('status', 0);
+                        break;
+                    //7.售后退货单流程
+                    case 'CKTHD':
+                        $order_process_finally = Db::name('order_back')->where(['id' => $value['order_id'], 'is_del' => 0])->value('status', 0);
+                        break;
+                    //8.销售退货单流程
+                    case 'XSTHD':
+                        $order_process_finally = Db::name('sale_return')->where(['id' => $value['order_id'], 'is_del' => 0])->value('status', 0);
+                        break;
+                    //9.采购工差单流程
+                    case 'CGGCD':
+                        $order_process_finally = Db::name('purchease_diff')->where(['id' => $value['order_id'], 'is_del' => 0])->value('status', 0);
+                        break;
+                    //10.销售工差单流程
+                    case 'XSGCD':
+                        $order_process_finally = Db::name('sale_diff')
+                            ->where(['id' => $value['order_id']])
+                            ->value('status', 0);
+                        break;
+                    //11.调拨单流程
+                    case 'DBD':
+                        $order_process_finally = Db::name('allot_stock')->where(['id' => $value['order_id'], 'is_del' => 0])->value('status', 0);
+                        break;
+                    //12.盘点单流程
+                    case 'PDD':
+                        $order_process_finally = Db::name('good_check')->where(['id' => $value['order_id'], 'is_del' => 0])->value('status', 0);
+                        break;
+                    //13.议价单流程
+                    case 'YJD':
+                        $order_process_finally = Db::name('bargain_order')->where(['id' => $value['order_id'], 'is_del' => 0])->value('status', 0);
+                        break;
+                    //14.项目单流程
+                    case 'PRO':
+                        $order_process_finally = Db::name('project')->where(['id' => $value['order_id'], 'is_del' => 0])->value('status', 0);
+                        break;
+                    //15.商品成本流程
+                    case 'SPCB':
+                        $order_process_finally = Db::name('good_basic')->where(['id' => $value['order_id'], 'is_del' => 0])->value('status', 0);
+                        break;
+                    //16.商品上线流程
+                    case 'SPSX':
+                        $order_process_finally = Db::name('good_platform')
+                            ->where(['id' => $value['order_id']])
+                            ->value('exam_status', 0);
+                        break;
+                    //17.活动流程
+                    case 'HD':
+                        $order_process_finally = Db::name('good_activity')->where(['id' => $value['order_id'], 'is_del' => 0])->value('status', 0);
+                        break;
+                    //19.有赞商品上架流程
+                    case 'YZSX':
+                        $order_process_finally = Db::name('platform_youzan')
+                            ->where(['id' => $value['order_id']])
+                            ->value('exam_status', 0);
+                        break;
+                    //20.有赞订单审核流程
+//                case 'YZQRD':
+//                    $order_process_finally = Db::name('')->where(['id' => $value['order_id'], 'is_del' => 0])->value('', 0);
+//                    break;
+                    //22.离职交接流程
+                    case 'LZJJ':
+                        $order_process_finally = Db::name('resign_info')->where(['id' => $value['order_id'], 'is_del' => 0])->value('status', 0);
+                        break;
+                    //23.采购单退货流程
+                    case 'CGTHD':
+                        $order_process_finally = Db::name('purchease_return')->where(['id' => $value['order_id'], 'is_del' => 0])->value('status', 0);
+                        break;
+                    //24.竞价单流程
+                    case 'ZXD':
+                        $order_process_finally = Db::name('consult_order')->where(['id' => $value['order_id'], 'is_del' => 0])->value('status', 0);
+                        break;
+                    //25.商品下线流程
+//                    case 'GOL':
+//                        $order_process_finally = Db::name('good_offline_log')->where(['id' => $value['order_id'], 'is_del' => 0])->value('status', 0);
+//                        break;
+                }
+
+                if ($order_process_finally) Db::name('process_wait')
+                    ->where('order_code', $value['order_code'])
+                    ->where('order_type', $value['order_type'])
+                    ->update(['order_process_finally' => $order_process_finally]);
+            }
+
+            Db::commit();
+
+            $output->writeln('update success');
+
+            //解除标识,执行完毕
+
+        } catch (Exception $exception) {
+            Db::rollback();
+            $output->writeln('update fail,' . $exception->getMessage());
+
+            //解除标识,执行完毕
+
+
+        }
+
+
+    }
+
+
+}

+ 59 - 0
app/command/UpdateYzHistoryData.php

@@ -0,0 +1,59 @@
+<?php
+declare (strict_types=1);
+
+namespace app\command;
+
+use think\console\Command;
+use think\console\Input;
+use think\console\input\Argument;
+use think\console\input\Option;
+use think\console\Output;
+use think\Exception;
+use think\facade\Db;
+
+class UpdateYzHistoryData extends Command
+{
+    protected function configure()
+    {
+        // 指令配置
+        $this->setName('UpdateYzHistoryData')
+            ->setDescription('更新有赞的历史数据');
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+
+        $data = Db::name('order_out')
+            ->alias('a')
+            ->field('a.orderCode,a.outCode,a.post_name,a.post_code')
+            ->leftJoin('sale b', 'b.orderCode=a.orderCode')
+            ->where('a.addtime', '>=', date('Y-m-d H:i:s', time() - 72 * 3600))
+            ->where([
+                'a.is_del' => 0,
+                'a.status' => 2,
+                'b.order_source' => 5
+            ])
+            ->limit(1)->select()->toArray();
+//            ->cursor();
+
+        $url = config('app.yz_domain') . 'api/yz_out_send';
+
+        foreach ($data as $value) {
+            $res = curl_request($url, [
+                'orderCode' => $value['orderCode'],
+                'out_stype' => $value['post_name'],
+                'post_code' => $value['post_code'],
+                'uid' => 96,
+                'uname' => '武锋(历史数据处理)',
+                'order_out' => $value['outCode'],
+            ]);
+
+            $res = json_decode($res, true);
+            if ($res['code'] != 0) $output->writeln('handle fail,' . json_encode($value, JSON_UNESCAPED_UNICODE) . ':' . $res['message']);
+        }
+
+
+    }
+
+
+}

+ 163 - 80
app/command/handleYzOrderData.php

@@ -4,7 +4,7 @@ namespace app\command;
 
 use app\admin\model\ActionLog;
 use app\admin\model\GoodLog;
-use app\admin\model\ProcessOrder;
+use app\admin\model\GoodStockInfo;use app\admin\model\ProcessOrder;
 use think\console\Command;
 use think\console\Input;
 use think\console\Output;
@@ -16,6 +16,8 @@ use think\facade\Db;
 //处理有赞订单数据
 class handleYzOrderData extends Command
 {
+    private $cgd_data = [];//存储采购单的数据,目前是为了做供应商api推送而准备的
+
     protected function configure()
     {
         // 指令配置
@@ -28,7 +30,7 @@ class handleYzOrderData extends Command
 
         $c_data = Cache::store('redis')->handler()->rpop(Config::get('app.handle_queue_key'));
 
-        if ($c_data) {
+        if ($c_data){
 
             $c_data = json_decode($c_data, true);
 
@@ -130,15 +132,22 @@ class handleYzOrderData extends Command
 //                $is_activity = empty($extend_data['activity_name']) ? 0 : 1;
 
                 if ($is_stock == 1) {
-                    $stock = Db::name("good_stock")
-                        ->alias("a")
-                        ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
-                        ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, 'b.wsm_type' => 5, "b.companyNo" => $supplierNo])
-                        ->field("a.id,a.usable_stock,a.wait_out_stock")
-                        ->find();
-
-                    if ($stock == false || $stock['usable_stock'] < $good_num) throw new Exception('库存数量不足');
-
+//                    $stock = Db::name("good_stock")
+//                        ->alias("a")
+//                        ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
+//                        ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, 'b.wsm_type' => 5, "b.companyNo" => $supplierNo])
+//                        ->field("a.id,a.usable_stock,a.wait_out_stock")
+//                        ->find();
+//
+//                    if ($stock == false || $stock['usable_stock'] < $good_num) throw new Exception('库存数量不足');
+                        $stock_num = Db::name("good_stock")->alias("a")
+			            ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
+			            ->leftJoin("good_stock_info c", "a.id=c.stockid and c.balance_num>0")
+			            ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, "b.wsm_type" => 5, "b.companyNo" =>$supplierNo])
+			            ->sum('balance_num');
+			            if($stock_num < $good_num){
+			                 throw new Exception('bn库存数量不足');
+			            }
                     $origin_price = 0;
 
                 } else {
@@ -237,7 +246,7 @@ class handleYzOrderData extends Command
 
                 $supplier_temp_info = Db::name('supplier')
                     ->field('id,person,personid')
-                    ->where('code',$ct['supplierNo'])
+                    ->where('code', $ct['supplierNo'])
                     ->findOrEmpty();
 
                 $data = [
@@ -336,12 +345,13 @@ class handleYzOrderData extends Command
                             "good_type" => $goodtype,
                             "order_type" => $order_type,
                             "order_source" => $order_source,
-                            "createrid" => $ct['createrid'],
-                            "creater" => $ct['creater'],
+                            "createrid" =>$supplier_temp_info['personid'],
+                             "creater" =>$supplier_temp_info['person'],
                             'send_way' => 2,
                             'gold_price' => $ct['cgd_gold_price'],
                             'good_createrid' => $goodinfo['createrid'],
                             'good_creater' => $goodinfo['creater'],//商品创建人
+                            'weight' => $ct['noble_weight'],//商品创建人
                         ];
 
                         //非库存品
@@ -350,35 +360,47 @@ class handleYzOrderData extends Command
 
                     } else {
                         //库存品
-                        $cgd = [
-                            'orderCode' => $orderCode,
-                            "good_num" => $good_num,
-                            "spuCode" => $spuCode,
-                            "companyNo" => $supplierNo,
-                            'order_type' => $order_type,
-                            'order_source' => $order_source,
-                            'good_createrid' => $goodinfo['createrid'],
-                            'good_creater' => $goodinfo['creater'],//商品创建人
-                        ];
-                        $bol = $this->RelaCgd($cgd, $standing_book_data);
-                        if ($bol == false) throw new Exception('库存商品关联采购单失败');
-
-                        if (isset($stock)) {
-                            $stck = [
-                                "usable_stock" => $stock['usable_stock'] - $good_num,
-                                "wait_out_stock" => $stock['wait_out_stock'] + $good_num,
-                                "updatetime" => date("Y-m-d H:i:s")
-                            ];
-                            $upad = Db::name("good_stock")
-                                ->where($stock)
-                                ->update($stck);
-                            if ($upad == false) throw new Exception('库存商品更新库存失败');
-
-                            //商品变动日志表,good_log_code字段存储采购单号
-                            $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $datainfo, "type" => 2, 'stock' => $good_num, "stock_name" => "usable_stock"];
-                            $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $datainfo, "type" => 1, 'stock' => $good_num, "stock_name" => "wait_out_stock"];
-                            GoodLog::LogAdd(['id' => $rm, 'nickname' => $ri], $good_data, "XSQRD");
-                        }
+//                        $cgd = [
+//                            'orderCode' => $orderCode,
+//                            "good_num" => $good_num,
+//                            "spuCode" => $spuCode,
+//                            "companyNo" => $supplierNo,
+//                            'order_type' => $order_type,
+//                            'order_source' => $order_source,
+//                            'good_createrid' => $goodinfo['createrid'],
+//                            'good_creater' => $goodinfo['creater'],//商品创建人
+//                        ];
+//                        $bol = $this->RelaCgd($cgd, $standing_book_data);
+//                        if ($bol == false) throw new Exception('库存商品关联采购单失败');
+
+//                        if (isset($stock)) {
+//                            $stck = [
+//                                "usable_stock" => $stock['usable_stock'] - $good_num,
+//                                "wait_out_stock" => $stock['wait_out_stock'] + $good_num,
+//                                "updatetime" => date("Y-m-d H:i:s")
+//                            ];
+//                            $upad = Db::name("good_stock")
+//                                ->where($stock)
+//                                ->update($stck);
+//                            if ($upad == false) throw new Exception('库存商品更新库存失败');
+//		                        $stockinfo =GoodStockInfo::OrderBn($orderCode,$stock['id'],$good_num);
+//		                    if($stockinfo==false){
+//		                             Db::rollback();
+//		                            return error_show(1002, "Bn库存更新库存失败");
+//		                     }
+//                            //商品变动日志表,good_log_code字段存储采购单号
+//                            $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $datainfo, "type" => 2, 'stock' => $good_num, "stock_name" => "usable_stock"];
+//                            $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $datainfo, "type" => 1, 'stock' => $good_num, "stock_name" => "wait_out_stock"];
+//                            GoodLog::LogAdd(['id' => $rm, 'nickname' => $ri], $good_data, "XSQRD");
+//                        }
+	                    $stockid= Db::name("good_stock")->alias("a")
+			            ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
+			            ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, "b.wsm_type" => 5, "b.companyNo" =>$supplierNo])
+			            ->column('a.id');
+	                        $stockinfo =GoodStockInfo::OrderBn($orderCode,$stockid,intval($good_num));
+	                        if($stockinfo==false){
+	                            throw new Exception('库存商品更新库存失败');
+	                        }
 
                     }
                     if ($sendtype == 1) {
@@ -407,35 +429,34 @@ class handleYzOrderData extends Command
                         ];
                         $vmp = Db::name('order_addr')->insertGetId($temp);
                         if ($vmp > 0) {
-                            $order = Db::name("order_num")
-                                ->where(["orderCode" => $orderCode, "status" => 1])
-                                ->where([["wsend_num", ">=", 0]])
-                                ->lock(true)
-                                ->find();
-                            if ($order == false) throw new Exception('未找到可以发货得采购单数据');
-
-
-                            $num = $c_data['num'];
-                            $outCode = makeNo("DF");
-                            $order['wsend_num'] -= $num;
-                            $order['send_num'] += $num;
-                            $or = Db::name("order_num")->save($order);
-                            if ($or == false) throw new Exception('发货地址更新失败');
-
-                            $tep = [
-                                "cgdNo" => $order['cgdNo'],
-                                "outCode" => $outCode,
-                                "send_num" => $num,
-                                "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) throw new Exception('发货地址添加创建失败');
-
-                            $cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
-                            if ($cgdinfo == false) throw new Exception('未匹配到采购数据');
-
+								$num = $c_data['num'];
+	                            $outCode = makeNo("DF");
+                        	if ($is_stock != 1) {
+	                            $order = Db::name("order_num")
+	                                ->where(["orderCode" => $orderCode, "status" => 1])
+	                                ->where([["wsend_num", ">=", 0]])
+	                                ->lock(true)
+	                                ->find();
+	                            if ($order == false) throw new Exception('未找到可以发货得采购单数据');
+	                            $order['wsend_num'] -= $num;
+	                            $order['send_num'] += $num;
+	                            $or = Db::name("order_num")->save($order);
+	                            if ($or == false) throw new Exception('发货地址更新失败');
+
+	                            $tep = [
+	                                "cgdNo" => $order['cgdNo'],
+	                                "outCode" => $outCode,
+	                                "send_num" => $num,
+	                                "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) throw new Exception('发货地址添加创建失败');
+
+	                            $cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
+	                            if ($cgdinfo == false) throw new Exception('未匹配到采购数据');
+							}
                             $out = [
                                 "orderCode" => $orderCode,
                                 "outCode" => $outCode,
@@ -449,13 +470,13 @@ class handleYzOrderData extends Command
                                 "send_num" => $num,
                                 "check_num" => 0,
                                 "error_num" => 0,
-                                "wsm_code" => $cgdinfo['wsm_code'],
+                                "wsm_code" => $is_stock==1? '':$cgdinfo['wsm_code'],
                                 "order_type" => $order_type,
                                 "status" => $is_stock == 1 ? 1 : 0,
                                 "addtime" => date("Y-m-d H:i:s"),
                                 "updatetime" => date("Y-m-d H:i:s")
                             ];
-                            $ou = Db::name("order_out")->insert($out);
+                            $ou = Db::name("order_out")->insertGetId($out);
                             if ($ou == false) throw new Exception('发货地址添加创建失败');
                             else {
                                 //修改状态,添加待办
@@ -466,12 +487,47 @@ class handleYzOrderData extends Command
                                     "action_type" => "create"//新建create,编辑edit,更改状态status
                                 ], "CKD", 0, $out);
 
-                                ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], [
+                                if ($out['status'] == 1) {
+                                    if ($is_stock == 1) {
+                                        //库存品,待办数据推给库管
+                                        $uids = Db::name('user_role')
+                                            ->where(['is_del' => 0, 'roleid' => config('app.wsm_cgder_role'), 'status' => 1])
+                                            ->column('uid');
+                                        ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], [
+                                            "order_type" => 'CKD',
+                                            "order_code" => $outCode,//出库单号
+                                            "order_id" => $ou,
+                                            "order_status" => $out['status'],
+                                            "before_status" => 0,
+                                            'holder_id' => $data['apply_id'],
+                                            'handle_user_list' => implode(',', $uids),
+                                        ]);
+                                    } else {
+                                        //非库存品推给供应商负责人
+                                        $supp = Db::name('supplier')
+                                            ->field('person,personid')
+                                            ->where('code', $ct['supplierNo'])
+                                            ->findOrEmpty();
+                                        ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], [
+                                            "order_type" => 'CKD',
+                                            "order_code" => $outCode,//出库单号
+                                            "order_id" => $ou,
+                                            "order_status" => $out['status'],
+                                            "before_status" => 0,
+                                            'holder_id' => $data['apply_id'],
+                                            'wait_id' => $supp['personid'],
+                                            'wait_name' => $supp['person'],
+                                        ]);
+                                    }
+
+
+                                }else ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], [
                                     "order_type" => 'CKD',
                                     "order_code" => $outCode,//出库单号
-                                    "order_id" => 0,
-                                    "order_status" => 0,
-                                    "before_status" => 0
+                                    "order_id" => $ou,
+                                    "order_status" => $out['status'],
+                                    "before_status" => 0,
+                                    'holder_id'=>$data['apply_id']
                                 ]);
 
 //                                $standing_book_data['outCode'] = $outCode;
@@ -503,6 +559,25 @@ class handleYzOrderData extends Command
                 $callback_rs = $this->callbackYz(['status' => 6, 'id' => $c_data['id'], 'orderCode' => $orderCode]);
                 if ($callback_rs['code'] != 0) throw new Exception($callback_rs['message']);
 
+                //将采购单数据塞入到队列中
+                if ($this->cgd_data) {
+                    $push_data = json_encode([
+                        'supplierNo' => $this->cgd_data['supplierNo'],
+                        'type' => 1,//1销售订单(采销的采购单),2上线结果
+                        'data' => [
+                            'cgdNo' => $this->cgd_data['cgdNo'],
+                            'spuCode' => $this->cgd_data['spuCode'],
+                            'good_name' => $this->cgd_data['good_name'],
+                            'good_num' => $this->cgd_data['good_num'],
+                            'good_price' => $this->cgd_data['good_price'],
+                            'total_fee' => $this->cgd_data['total_fee'],
+                            'weight' => $this->cgd_data['weight'],
+                            'addtime' => $this->cgd_data['addtime'],
+                        ],
+                    ], JSON_UNESCAPED_UNICODE);
+                    Cache::store("redis")->handler()->lPush(Config::get('app.abutment_queue'), $push_data);
+                }
+
                 Db::commit();
 
                 $output->writeln(date('Y-m-d H:i:s') . '|处理成功,orderCode:' . $orderCode);
@@ -582,7 +657,7 @@ class handleYzOrderData extends Command
             "demo_fee" => $data['demo_fee'],
             "nake_fee" => $data['nake_fee'],
             "delivery_fee" => $data['delivery_fee'],
-            #"weight"=>$data['weight'],
+            "weight"=>$data['weight'],
             "diff_weight" => "0",
             "diff_fee" => "0",
             "gold_price" => $data['gold_price'],
@@ -615,12 +690,16 @@ class handleYzOrderData extends Command
                 "action_type" => "create"//新建create,编辑edit,更改状态status
             ], "CGD", $cg['status'], $cg);
 
+            //当采购单是节点0待与供应商确认,推给供应商负责人
             ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], [
                 "order_type" => 'CGD',
                 "order_code" => $cg['cgdNo'],//销售单code
                 "order_id" => $up,
                 "order_status" => $cg['status'],
-                "before_status" => 0
+                "before_status" => 0,
+                'holder_id'=>$supplier['personid'],
+                'wait_id'=>$supplier['personid'],
+                'wait_name'=>$supplier['person'],
             ]);
 
             $standing_book_data['cgdNo'] = $cgdCode;
@@ -665,6 +744,8 @@ class handleYzOrderData extends Command
                 $good_data[] = ['good_log_code' => $cgdCode, "stock_id" => isset($stoc['id']) ? $stoc['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1, 'stock' => $data['good_num'], "stock_name" => "wait_in_stock"];
                 GoodLog::LogAdd(['id' => 0, 'nickname' => 'system'], $good_data, "CGD");
 
+                $this->cgd_data = $cg;
+
                 return true;
             }
         } else return false;
@@ -766,6 +847,8 @@ class handleYzOrderData extends Command
         $order = Db::name("order_num")->save($data);
         if ($order == false) return false;
 
+        $this->cgd_data = $QrdCgd;
+
         return true;
     }
 

+ 54 - 0
app/command/license.php

@@ -0,0 +1,54 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\command;
+
+use think\console\Command;
+use think\console\Input;
+use think\console\input\Argument;
+use think\console\input\Option;
+use think\console\Output;
+use app\admin\common\Ocr;
+use think\facade\Db;
+class license extends Command
+{
+    protected function configure()
+    {
+        // 指令配置
+        $this->setName('license')
+            ->setDescription('the license command');
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+        // 指令输出
+        $data=$this->getdata();
+        $ocr =new Ocr();
+        foreach ($data as $value){
+            $datwa =  $ocr->query("",$value['license_img']);
+            if($datwa['code']==0 && isset($datwa['data']['result'])){
+                $license = $datwa['data']['result'];
+                $value['legaler']= isset($license['legal_representative'])?$license['legal_representative']:"";
+                $value['addr']= isset($license['address'])?$license['address']:"";
+                $value['registertime']= isset($license['found_date'])? $license['found_date']:"";
+                $value['scope']= isset($license['business_scope'])?$license['business_scope']:"";
+                $value['capital']= isset($license['registered_capital'])?$license['registered_capital']:"";
+                $value['nature']= isset($license['type'])?$license['type']:"";
+                $value['registercode']= isset($license['registration_number'])?$license['registration_number']:"";
+                $value['status']=1;
+                $value['ocr_status']=1;
+            }else{
+                $value['remark']="营业执照识别失败";
+                $value['status']=0;
+                $value['ocr_status']=2;
+            }
+            Db::name("supplier")->save($value);
+        }
+        $output->writeln('license');
+    }
+
+    public function getdata(){
+      $sql = Db::name("supplier")->where(["ocr_status"=>2])->select();
+      return $sql;
+    }
+}

+ 83 - 1
app/common.php

@@ -1219,6 +1219,7 @@ if (!function_exists('checkHasAccountBySupplierNos')) {
 }
 
 
+
 //获取当前用户可查看的其他用户id
 if (!function_exists('get_group_share_uid')) {
     function get_group_share_uid(int $uid = 0)
@@ -1298,9 +1299,90 @@ if (!function_exists('get_group_share_uid')) {
         $data[DataGroupModel::$type_全部] = array_merge($data[DataGroupModel::$type_可编辑], $data[DataGroupModel::$type_只读]);
 
         sort($data[DataGroupModel::$type_全部]);
-        $data[DataGroupModel::$type_全部]=array_unique($data[DataGroupModel::$type_全部]);
+        $data[DataGroupModel::$type_全部] = array_unique($data[DataGroupModel::$type_全部]);
 
         return $data;
+    }
+}
+
+//获取当前操作人(待办列表)
+if (!function_exists('get_handle_user_list')) {
+    //$action_process_id 节点id
+    //$holder_id 所有人uid
+    //$api_url 接口路径,匹配菜单使用
+    //$person_id 供应商负责人(供应商端)
+    function get_handle_user_list(int $action_process_id = 0, int $holder_id = 0, string $api_url = '',int $person_id=0)
+    {
+
+        //筛选符合流程权限的角色id集合
+        $roleids = Db::name('role_process')
+            ->where('is_del', 0)
+            ->where('role_id', '<>', 1)//排除超级管理员
+            ->whereFindInSet('action_data', $action_process_id)
+            ->field('role_id')
+            ->buildSql();
+
+        //根据角色id筛选用户id
+        $data = Db::name('user_role')
+            ->where(['is_del' => 0, 'status' => 1])
+            ->where('roleid IN ' . $roleids)
+            ->column('uid');
+
+        //根据菜单筛选符合条件的共享数据
+        $tmp = getUserIdsByShare($api_url,$holder_id);
+
+        $res = array_intersect($tmp, $data);//流程权限和数据权限取交集
+
+        //如果本人有流程权限的话,加入到数组中
+        if (in_array($holder_id, $data)) $res[] = $holder_id;
+        if ($person_id) $res[] = $person_id;
+
+        sort($res);
+        $res = array_unique($res);
+
+        return $res;
+
+    }
+}
+
+//根据数据权限,筛选符合条件的用户
+if (!function_exists('getUserIdsByShare')) {
+    function getUserIdsByShare(string $api_url = '', int $holder_id = 0)
+    {
+        //当前请求的接口地址
+        if ($api_url == '') $api_url = app('http')->getName() . '/' . request()->pathinfo();
+        $menu_id = Db::name('admin_menu')
+            ->where(['is_del' => 0, 'menu_api' => $api_url])
+            ->value('id', 0);
+
+        $tmp = [];
+        if ($menu_id) {
+            //共享规则
+            $share = Db::name('role_share')
+                ->field('id,to_user,to_group')
+                ->where([
+                    'share_user' => $holder_id,
+                    'is_del' => 0,
+                    'status' => 1,
+                ])
+                ->whereFindInSet('action_collect', $menu_id)
+                ->cursor();
+
+            foreach ($share as $s) {
+                if ($s['to_user']) $tmp[] = $s['to_user'];
+                elseif ($s['to_group']) {
+                    $group_user = Db::name('role_group')
+                        ->where([
+                            'id' => $s['to_group'],
+                            'is_del' => 0,
+                            'status' => 1,
+                        ])->value('group_user');
+                    $tmp = array_merge($tmp, explode(',', $group_user));
+                }
+            }
+        }
+
+        return $tmp;
 
     }
 }

+ 0 - 1
app/youzan/controller/Index.php

@@ -123,7 +123,6 @@ class Index extends Base
     {
 
         $param = $this->request->filter('trim')->only(['tid' => '', 'oid' => '', 'plat_code' => '', 'orderCode' => '', 'skuCode' => '', 'platform_name' => '', 'status' => '', 'addtime_start' => '', 'addtime_end' => '', 'page' => 1, 'size' => 15], 'post');
-
         return Order::getYzOrderList($param);
 
     }

+ 31 - 10
app/youzan/logic/Goodup.php

@@ -40,7 +40,7 @@ class Goodup
                 //校验是否存在起订量为1的信息
                 if (empty($all_nake[$value['spuCode']])) {
                     $god = Db::name("good_basic")
-                        ->field('id,good_name,good_thumb_img')
+                        ->field('id,good_name,good_thumb_img,chargerid')
                         ->where(["spuCode" => $value['spuCode'], "is_del" => 0])
                         ->find();
                     if ($god) {
@@ -80,7 +80,7 @@ class Goodup
                 $ist = isset($all_list[$value['spuCode']]) ? $all_list[$value['spuCode']] : [];
                 if ($ist) {
                     $god = Db::name("good_basic")
-                        ->field('id,good_name,good_thumb_img')
+                        ->field('id,good_name,good_thumb_img,chargerid')
                         ->where(["spuCode" => $value['spuCode'], "is_del" => 0])
                         ->find();
                     if ($god) {
@@ -169,7 +169,8 @@ class Goodup
                         "order_code" => $skuCode,
                         "order_id" => $create,
                         "order_status" => $tmp['exam_status'],
-                        "before_status" => $tmp['exam_status']
+                        "before_status" => $tmp['exam_status'],
+                        'holder_id' => Db::name('good_basic')->where(["spuCode" => $value['spuCode'], "is_del" => 0])->value('chargerid', 0),
                     ]);
                     $iso = Db::name("good")->where(["spuCode" => $value['spuCode'], "is_del" => 0])->find();
                     if ($iso == false) {
@@ -210,7 +211,7 @@ class Goodup
             $db = new PlatformYouzan();
 
             $rs = $db
-                ->field('a.id,a.platform_id,a.spuCode,a.skuCode,a.exam_status,gb.good_name,gb.weight,gb.good_img,gb.cat_id,gb.good_info_img')
+                ->field('a.id,a.platform_id,a.spuCode,a.skuCode,a.exam_status,gb.good_name,gb.weight,gb.good_img,gb.cat_id,gb.good_info_img,gb.chargerid')
                 ->alias('a')
                 ->where(['a.id' => $platform_youzan_id, 'a.is_del' => $db::$del_normal])
                 ->leftJoin('good_basic gb', 'gb.spuCode=a.spuCode')
@@ -255,7 +256,7 @@ class Goodup
                     ->where('id', $data['good_ladder_id'])
                     ->findOrEmpty();
 
-                $post_fee = isset($nake_info['delivery_fee'])?$nake_info['delivery_fee']:0;
+                $post_fee = isset($nake_info['delivery_fee']) ? $nake_info['delivery_fee'] : 0;
 
 
                 $desc = explode(',', $rs->good_info_img);
@@ -275,7 +276,7 @@ class Goodup
                     'yz_cat_id' => $data['yz_cat_id'],
                     'is_support_barter' => $data['is_support_barter'],
                     'sale_price' => $sale_price,
-                    'cost_fee' => $nake_info['cost_fee']??0,
+                    'cost_fee' => $nake_info['cost_fee'] ?? 0,
                     'final_price' => $data['final_price'],
                     'start_sale_num' => $data['start_sale_num'],
                     'reject_reason' => '',
@@ -363,7 +364,9 @@ class Goodup
                 "order_type" => 'YZSX',
                 "order_code" => $rs->skuCode,//咨询单详情编号
                 "order_id" => $rs->id,
-                "order_status" => $update_data['exam_status'], "before_status" => $old_exam_status
+                "order_status" => $update_data['exam_status'],
+                "before_status" => $old_exam_status,
+                'holder_id'=>$rs->chargerid,
             ]);
 
             if ($res) {
@@ -441,7 +444,7 @@ class Goodup
             $db = new PlatformYouzan();
 
             $rs = $db
-                ->field('id,spuCode,skuCode,platform_id')
+                ->field('id,spuCode,skuCode,platform_id,exam_status')
                 ->where(['id' => $platform_youzan_id, 'is_del' => $db::$del_normal])
                 ->whereIn('exam_status', [$db::$exam_status_7, $db::$exam_status_8])
                 ->findOrEmpty();
@@ -449,14 +452,18 @@ class Goodup
             if ($rs->isEmpty()) return error_show(1005, '该商品上线记录不存在或不允许重新上线');
 
             $userinfo = GetUserInfo($token);
+            $uid = isset($userinfo['data']['id']) ? $userinfo['data']['id'] : 0;
+            $nickname = isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname'] : '';
+
+            $old_status = $rs->exam_status;
 
             //更新
             $db
                 ->where('id', $platform_youzan_id)
                 ->save([
                     'exam_status' => $db::$exam_status_0,
-                    'updaterid' => isset($userinfo['data']['id']) ? $userinfo['data']['id'] : 0,
-                    'updater' => isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname'] : '',
+                    'updaterid' => $uid,
+                    'updater' => $nickname,
                     'updatetime' => date('Y-m-d H:i:s'),
                 ]);
 
@@ -466,6 +473,12 @@ class Goodup
                 ->where('exam_status', '<>', 0)
                 ->update(['exam_status' => 0, 'updatetime' => date('Y-m-d H:i:s')]);
 
+            $stn = ["order_code" => $rs->skuCode, "status" => $old_status, "action_remark" => '', "action_type" => "status"];
+            ActionLog::logAdd(['id' => $uid, 'nickname' => $nickname], $stn, "YZSX", $db::$exam_status_0, ['id'=>$platform_youzan_id]);
+
+            $process = ["order_code" => $rs->skuCode, "order_id" => $rs->id, "order_status" => $db::$exam_status_0, "order_type" => 'YZSX', "before_status" => $old_status, 'holder_id' => $uid];
+            ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $nickname], $process);
+
             Db::commit();
 
             return app_show(0, '操作成功');
@@ -627,6 +640,8 @@ class Goodup
 
             $userinfo = GetUserInfo($data['token']);
 
+            $old_status = $rs->exam_status;
+
             $curl_data = [
                 'item_no' => $rs->skuCode,//商品自定义编码 skuCode
                 'uid' => isset($userinfo['data']['id']) ? $userinfo['data']['id'] : 0,
@@ -673,6 +688,12 @@ class Goodup
                     'addtime' => date('Y-m-d H:i:s')
                 ]);
 
+            $stn = ["order_code" => $rs->skuCode, "status" => $old_status, "action_remark" => '', "action_type" => "status"];
+            ActionLog::logAdd(['id' => $curl_data['uid'], ['nickname' => $curl_data['nickname']]], $stn, "YZSX", $db::$exam_status_8, $data);
+
+            $process = ["order_code" => $rs->skuCode, "order_id" => $rs->id, "order_status" => $db::$exam_status_8, "order_type" => 'YZSX', "before_status" => $old_status, 'holder_id' => $curl_data['uid']];
+            ProcessOrder::AddProcess(['id' => $curl_data['uid'], ['nickname' => $curl_data['nickname']]], $process);
+
             Db::commit();
 
             return app_show(0, '操作成功');

+ 19 - 1
app/youzan/logic/Order.php

@@ -56,12 +56,30 @@ class Order
                 "action_type" => "status"//新建create,编辑edit,更改状态status
             ], "YZQRD", 0, $data);
 
+
+            //取符合条件的角色下的所有人
+            $action_process_id = Db::name('action_process')
+                ->where(['order_type' => 'YZQRD', 'order_process' => $data['status']])
+                ->value('id', 0);
+            $roleids = Db::name('role_process')
+                ->where('is_del', 0)
+                ->where('role_id', '<>', 1)//排除超级管理员
+                ->whereFindInSet('action_data', $action_process_id)
+                ->field('role_id')
+                ->buildSql();
+            //根据角色id筛选用户id
+            $uids = Db::name('user_role')
+                ->where(['is_del' => 0, 'status' => 1])
+                ->where('roleid IN ' . $roleids)
+                ->column('uid');
+
             ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $uname], [
                 "order_type" => 'YZQRD',
                 "order_code" => $res['data']['skuCode'],
                 "order_id" => $data['id'],
                 "order_status" => $data['status'],
-                "before_status" => $res['data']['old_status']
+                "before_status" => $res['data']['old_status'],
+                'handle_user_list' => implode(',', $uids)
             ]);
 
             return app_show(0, '操作成功');

+ 2 - 2
public/index.php

@@ -15,9 +15,9 @@ namespace think;
 require __DIR__ . '/../vendor/autoload.php';
 header('Access-Control-Allow-Origin:*');
 header('Access-Control-Allow-Methods:POST,GET,OPTIONS,DELETE');
-header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");
+header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization,sign,appid,noce,timestamp");
 // 执行HTTP应用并响应
-if($_SERVER['REQUEST_METHOD']=="OPTIONS"){
+if ($_SERVER['REQUEST_METHOD'] == "OPTIONS") {
     echo '';
     exit();
 }

Деякі файли не було показано, через те що забагато файлів було змінено