|
|
@@ -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);
|
|
|
}
|