wugg před 1 rokem
rodič
revize
e26f6413c8

+ 8 - 5
app/command/ImportOrderFromCAnalysisData.php

@@ -27,14 +27,17 @@ class ImportOrderFromCAnalysisData extends Command
     protected function execute(Input $input, Output $output)
     {
         //解析信息存到extend表,其中customer_code字段根据订单编号去customer_info查,其他根据商品编号查询
-
+	    $key = 'import_order_cacalysis_c_key';
+        $c_data_id = Cache::store('redis')->get($key);
+		if($c_data_id==1)return '';
+		Cache::store('redis')->set($key,1,180);
         Db::startTrans();
         try {
 
             $rs = Db::name('order_import_from_c')
                 ->where(['is_del' => OIFCModel::$is_del_normal, 'status' => OIFCModel::$status_wait_validate])
 //                ->lock(true)
-                ->find();
+                ->findOrEmpty();
 
             if (empty($rs)) throw new \Exception('无符合条件的记录');
 
@@ -321,7 +324,7 @@ class ImportOrderFromCAnalysisData extends Command
                     'is_del' => OIFCModel::$is_del_normal,
                     'status' => OIFCModel::$status_wait_validate
                 ])->update($update_c_data);
-
+			if($res==false)throw new \Exception($rs['id'].'处理失败');
             Db::commit();
 
 //            if ($is && $res) Cache::store("redis")->handler()->lPush('import_order_from_c_key', $rs['id']);//校验无误,入队列
@@ -329,12 +332,12 @@ class ImportOrderFromCAnalysisData extends Command
             // 指令输出
 //            $output->writeln(date('Y-m-d H:i:s') . '|解析成功');
 
-        } catch (Exception $exception) {
+        } catch (\Exception $exception) {
             Db::rollback();
             // 指令输出
             $output->writeln(date('Y-m-d H:i:s') . '|解析失败,' . $exception->getMessage() . '|' . $exception->getFile() . '|' . $exception->getLine());
         }
-
+		Cache::store('redis')->set($key,0,180);
 
     }
 

+ 19 - 39
app/command/ImportOrderFromCHandleData.php

@@ -36,11 +36,10 @@ class ImportOrderFromCHandleData extends Command
     protected function execute(Input $input, Output $output)
     {
 
-//        $key = 'import_order_from_c_key';
-//        $c_data_id = Cache::store('redis')->handler()->rpop($key);
-
-//        if (!$c_data_id) $output->writeln('没有符合条件的记录');
-//        else {
+        $key = 'import_order_from_c_key';
+        $c_data_id = Cache::store('redis')->get($key);
+		if($c_data_id==1)return '';
+		Cache::store('redis')->set($key,1,180);
         $order_import_from_c_db = new OIFCModel();
 
         $c_data = $order_import_from_c_db
@@ -121,38 +120,17 @@ 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,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 ($ct['usable_stock'] < $good_num) {
                         throw new \Exception('商品库存数量不足');
                     }
                     $origin_price = 0;
-
                 } else {
-
                     $origin = Db::name("good_nake")
                         ->where([["spuCode", "=", $spuCode], ["min_num", "<=", $good_num], ["is_del", "=", 0]])
                         ->order("min_num desc")
                         ->find();
                     if ($origin == false) throw new \Exception('未找到相关成本价格');
-
                     $origin_price = $origin['nake_total'];
-
                 }
 
                 $sale_price = $extend_data['price'];
@@ -436,18 +414,20 @@ class ImportOrderFromCHandleData extends Command
 
                 //复用sale::create()方法 -- end
 
-                //处理完成
-                $order_import_from_c_db
-                    ->where('id', $c_data['id'])
-                    ->where('is_del', OIFCModel::$is_del_normal)
-                    ->save([
-                        'status' => $order_import_from_c_db::$status_success,
-                        'updatetime' => date('Y-m-d H:i:s'),
-                        'remark' => '',
-                        'updateid' => 0,
-                        'updater' => 'system',
-                        'orderCode' => $orderCode
-                    ]);
+
+	            //处理完成
+	            $up= $order_import_from_c_db
+		            ->where('id', $c_data['id'])
+		            ->where(['is_del'=> OIFCModel::$is_del_normal,'status' => OIFCModel::$status_wait_relation])
+		            ->save([
+			            'status' => $order_import_from_c_db::$status_success,
+			            'updatetime' => date('Y-m-d H:i:s'),
+			            'remark' => '',
+			            'updateid' => 0,
+			            'updater' => 'system',
+			            'orderCode' => $orderCode
+		            ]);
+	            if($up==false)throw new \Exception($c_data['id'].'处理失败');
 
                 //维护台账记录
                 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")]));
@@ -491,7 +471,7 @@ class ImportOrderFromCHandleData extends Command
                 }
             }
 //        }
-
+		Cache::store('redis')->set($key,0);
     }