wufeng 2 лет назад
Родитель
Сommit
ebe7ae4cf5
1 измененных файлов с 67 добавлено и 59 удалено
  1. 67 59
      app/admin/controller/Purch.php

+ 67 - 59
app/admin/controller/Purch.php

@@ -639,17 +639,19 @@ class Purch extends Base
             return error_show(1004, "参数status 不能为空");
         }
 
-        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)) {
-                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,33 +660,33 @@ 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,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');
+            //原始数据
+            $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;
+                $uid = $this->uid;
+                $uname = $this->uname;
 
-            foreach ($cgdNo as $vlue) {
-                if($status==1 || $status==2){
+                foreach ($cgdNo as $vlue) {
+                    if ($status == 1 || $status == 2) {
 //                    $orderinfo = Db::name('sale')
 //                    ->alias('a')
 //                    ->field('a.id,a.orderCode,a.is_stock,a.order_type,a.cgderid')
@@ -693,35 +695,41 @@ class Purch extends Base
 //                        '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];
+                        $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);
-            }
+                    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());
         }
     }