Преглед изворни кода

问题件没有商品报错

LD пре 5 година
родитељ
комит
cee1bbfd16

+ 20 - 14
app/Http/Controllers/TestController.php

@@ -414,6 +414,7 @@ class TestController extends Controller
     }
 
     private function cleanBarcode(){
+
         $logCommodityBarcodes = CommodityBarcode::query()->where('code',"")->get();
         if (count($logCommodityBarcodes) > 0)LogService::log(__METHOD__,"纠正商品-删除空条码",json_encode($logCommodityBarcodes,JSON_UNESCAPED_UNICODE));
 
@@ -433,6 +434,8 @@ where (c.code,c.commodity_id) in (select code,commodity_id from commodity_barcod
         CommodityBarcode::destroy($barcodeDelete);
     }
     public function correctCommodity(){
+        ini_set('max_execution_time',2500);
+        ini_set('memory_limit','1526M');
         //清理冗余条码
         $this->cleanBarcode();
 
@@ -445,6 +448,7 @@ where (commodities.owner_id,commodity_barcodes.code) in (select commodities.owne
         //需要删除项
         $commodityDelete = [];
         foreach ($commodities as $index => $commodity){
+            $commodity->barcode_code=strtolower(trim($commodity->barcode_code));
             //货主+条码 为唯一key值 设想正常数据下同货主不应该有同条码
             $key = $commodity->owner_id.'_'.$commodity->barcode_code;
             //使用map池对比为重复数据
@@ -481,9 +485,9 @@ where (commodities.owner_id,commodity_barcodes.code) in (select commodities.owne
             $deleteCommodities[] = $del->commodity_id;
 
             //有效条码合并
-            $barcodes = DB::select(DB::raw("select * from 
-            (select * from commodity_barcodes where commodity_id = ".$del->commodity_id.")a 
-            where (select count(1) as num from commodity_barcodes b 
+            $barcodes = DB::select(DB::raw("select * from
+            (select * from commodity_barcodes where commodity_id = ".$del->commodity_id.")a
+            where (select count(1) as num from commodity_barcodes b
             where commodity_id = ".$target->commodity_id." and b.code = a.code) = 0"));
             if (count($barcodes) > 0){
                 foreach ($barcodes as $barcode){
@@ -493,25 +497,27 @@ where (commodities.owner_id,commodity_barcodes.code) in (select commodities.owne
             $updateCommodities[$del->commodity_id] = $target->commodity_id;
         }
         if (count($updateCommodities) > 0){
-            app('inventoryAccountMissionService')->batchUpdateItself('commodity_id', $updateCommodities);//批量更新库存盘点任务
-            app('inventoryCompareService')->batchUpdateItself('commodity_id', $updateCommodities);//批量更新库存对比
-            app('inventoryDailyLogService')->batchUpdateItself('commodity_id', $updateCommodities);//批量更新库存每日记录
-            app('processesContentService')->batchUpdateItself('commodity_id', $updateCommodities);//批量更新二次加工内容单
-            app('storeCheckingReceiveItemService')->batchUpdateItself('commodity_id', $updateCommodities);//批量更新入库盘收一体
-            app('orderPackageCommoditiesService')->batchUpdateItself('commodity_id', $updateCommodities);//批量更新订单商品
+            $targets=array_chunk($updateCommodities,1000);
+            foreach($targets as $targetCommodities){
+                app('inventoryAccountMissionService')->batchUpdateItself('commodity_id', $targetCommodities);//批量更新库存盘点任务
+                app('inventoryCompareService')->batchUpdateItself('commodity_id', $targetCommodities);//批量更新库存对比
+                app('inventoryDailyLogService')->batchUpdateItself('commodity_id', $targetCommodities);//批量更新库存每日记录
+                app('processesContentService')->batchUpdateItself('commodity_id', $targetCommodities);//批量更新二次加工内容单
+                app('storeCheckingReceiveItemService')->batchUpdateItself('commodity_id', $targetCommodities);//批量更新入库盘收一体
+                app('orderPackageCommoditiesService')->batchUpdateItself('commodity_id', $targetCommodities);//批量更新订单商品
+            }
         }
 
-        if (count($createBarcodes) > 0)LogService::log(__METHOD__,"纠正商品-录入合并条码",json_encode($createBarcodes,JSON_UNESCAPED_UNICODE));
+        if (count($createBarcodes) > 0)LogService::log(__METHOD__,"纠正商品-录入合并条码",json_encode(data_get($createBarcodes,'*.id'),JSON_UNESCAPED_UNICODE));
 
         CommodityBarcode::query()->insert($createBarcodes);
-
         $logCommodityBarcodes = CommodityBarcode::query()->whereIn('commodity_id',$deleteCommodities)->get();
-        if (count($logCommodityBarcodes) > 0)LogService::log(__METHOD__,"纠正商品-删除无用商品条码",json_encode($logCommodityBarcodes,JSON_UNESCAPED_UNICODE));
+        if (count($logCommodityBarcodes) > 0)LogService::log(__METHOD__,"纠正商品-删除无用商品条码",json_encode(data_get($logCommodityBarcodes,'*.id'),JSON_UNESCAPED_UNICODE));
 
         CommodityBarcode::query()->whereIn('commodity_id',$deleteCommodities)->delete();
 
-        $logCommodities = Commodity::query()->whereIn('id',$deleteCommodities)->get();
-        if (count($logCommodities) > 0)LogService::log(__METHOD__,"纠正商品-删除无用商品",json_encode($logCommodities,JSON_UNESCAPED_UNICODE));
+//        $logCommodities = Commodity::query()->whereIn('id',$deleteCommodities)->get();
+        if (count($deleteCommodities) > 0)LogService::log(__METHOD__,"纠正商品-删除无用商品",json_encode($deleteCommodities,JSON_UNESCAPED_UNICODE));
 
         Commodity::destroy($deleteCommodities);
     }

+ 2 - 2
app/Services/common/BatchUpdateService.php

@@ -71,11 +71,11 @@ class BatchUpdateService
     public function batchUpdateItself($tableName, $column, array $params, $connection = 'mysql')
     {
         $sql = "UPDATE ".$tableName;
-        $sql .= " SET ".$column." = CASE".$column;
+        $sql .= " SET ".$column." = CASE ".$column;
         foreach ($params as $key => $value){
             $sql .= " WHEN ".$key." THEN ".$value;
         }
-        $sql .= "END WHERE ".$column." IN (".implode(',',array_keys($params)).")";
+        $sql .= " END WHERE ".$column." IN (".implode(',',array_keys($params)).")";
         try {
             $bool = DB::connection($connection)->update($sql);
             LogService::log(__METHOD__, __FUNCTION__, '批量更新本身' .$sql);

+ 15 - 3
public/t.php

@@ -1,5 +1,17 @@
 <?php
-$value=`·sdf
-aa·`;
-var_dump( preg_match('/[\r\n]/',$value));
 
+
+ini_set('max_execution_time',2500);
+ini_set('memory_limit','2526M');
+
+$file=fopen('logs.txt','r');
+
+$adding=fread($file,filesize('logs.txt'));
+//$adding=fread($file,20000);
+$re=[];
+preg_match_all("/(批量更新失败 SQL\:\(.*?\) 堆栈)*/",$adding,$re);
+$str='';
+$fileToWrite=fopen('logSql.txt','a+');
+foreach ($re[1] as $str) {
+    fwrite($fileToWrite,$str);
+}

+ 2 - 2
resources/views/order/issue/index.blade.php

@@ -267,7 +267,7 @@
                                         :class="orderIssue.orderPackagecount > 1  ? 'collapse' : ''" :id="'order'+orderIssue.id"
                                         :data-value="orderIssue.orderCount = 0" :data-count="orderIssue.orderPackagecount = 0">
                                     <template v-for="packages in orderIssue.order.packages">
-                                        <tr v-for="item in packages.commodities" class="text-center" :data-value="orderIssue.orderCount += 1" align="center">
+                                        <tr v-for="item in packages.commodities" class="text-center" :data-value="orderIssue.orderCount += 1" align="center" v-if="item.commodity">
                                             <td >@{{ item.commodity.sku }}</td>
                                             <td>
                                                 <div class="text-truncate text-primary tooltipTarget" style="width: 100px;cursor:pointer;text-decoration: underline" title="双击展开" @dblclick="nowrapText($event)">@{{ item.commodity.name }}</div>
@@ -419,7 +419,7 @@
                                                :data-count="orderIssue.secondeOrderCount = 0"
                                                :data-value="orderIssue.secondeOrderItems = 0">
                                             <template v-for="packages in orderIssue.second_order.packages">
-                                                <tr v-for="item in packages.commodities" :data-value="orderIssue.secondeOrderCount += 1">
+                                                <tr v-for="item in packages.commodities" :data-value="orderIssue.secondeOrderCount += 1" v-if="item.commodity">
                                                     <td >@{{ item.commodity.sku }}</td>
                                                     <td >
                                                         <div class="text-truncate text-primary tooltipTarget" style="width: 100px;cursor:pointer;text-decoration: underline" title="双击展开" @dblclick="nowrapText($event)">@{{ item.commodity.name }}</div>