|
|
@@ -7,6 +7,7 @@ use App\Authority;
|
|
|
use App\Batch;
|
|
|
use App\City;
|
|
|
use App\Commodity;
|
|
|
+use App\CommodityBarcode;
|
|
|
use App\Events\CancelOrder;
|
|
|
use App\Log;
|
|
|
use App\Logistic;
|
|
|
@@ -412,9 +413,135 @@ 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));
|
|
|
+
|
|
|
+ CommodityBarcode::query()->where('code',"")->delete();
|
|
|
+ $barcodes = DB::select(DB::raw('select * from commodity_barcodes c
|
|
|
+where (c.code,c.commodity_id) in (select code,commodity_id from commodity_barcodes group by code,commodity_id having count(*) > 1) order by commodity_id'));
|
|
|
+ $barcodeMap = [];
|
|
|
+ $barcodeDelete = [];
|
|
|
+ foreach ($barcodes as $barcode){
|
|
|
+ if (isset($barcodeMap[$barcode->code.'_'.$barcode->commodity_id]))$barcodeDelete[] = $barcode->id;
|
|
|
+ else $barcodeMap[$barcode->code.'_'.$barcode->commodity_id] = $barcode->id;
|
|
|
+ }
|
|
|
+
|
|
|
+ $logCommodityBarcodes = CommodityBarcode::query()->whereIn('id',$barcodeDelete)->get();
|
|
|
+ if (count($logCommodityBarcodes) > 0)LogService::log(__METHOD__,"纠正商品-删除重复条码",json_encode($logCommodityBarcodes,JSON_UNESCAPED_UNICODE));
|
|
|
+
|
|
|
+ CommodityBarcode::destroy($barcodeDelete);
|
|
|
+ }
|
|
|
+ public function correctCommodity(){
|
|
|
+ ini_set('max_execution_time',2500);
|
|
|
+ ini_set('memory_limit','1526M');
|
|
|
+ //清理冗余条码
|
|
|
+ $this->cleanBarcode();
|
|
|
+
|
|
|
+ //获取重复条码
|
|
|
+ $commodities = DB::select(DB::raw('select commodities.name,commodities.sku,commodities.owner_id,commodity_barcodes.id as barcode_id,commodity_barcodes.code as barcode_code,commodity_barcodes.commodity_id from commodities LEFT JOIN commodity_barcodes on commodities.id = commodity_barcodes.commodity_id
|
|
|
+where (commodities.owner_id,commodity_barcodes.code) in (select commodities.owner_id,commodity_barcodes.code from commodities LEFT JOIN commodity_barcodes on commodities.id = commodity_barcodes.commodity_id group by commodities.owner_id,commodity_barcodes.code having count(*) > 1) order by commodities.owner_id,commodity_barcodes.code'));
|
|
|
+
|
|
|
+ //对比map池
|
|
|
+ $commodityMap = [];
|
|
|
+ //需要删除项
|
|
|
+ $commodityDelete = [];
|
|
|
+ foreach ($commodities as $index => $commodity){
|
|
|
+ $commodity->barcode_code=strtolower(trim($commodity->barcode_code));
|
|
|
+ //货主+条码 为唯一key值 设想正常数据下同货主不应该有同条码
|
|
|
+ $key = $commodity->owner_id.'_'.$commodity->barcode_code;
|
|
|
+ //使用map池对比为重复数据
|
|
|
+ if(isset($commodityMap[$key])){
|
|
|
+ //获取下标指针指向的源数据
|
|
|
+ $c = $commodities[$commodityMap[$key]];
|
|
|
+ //源数据不符合规范,当前数据替换掉它
|
|
|
+ if (($c->sku == null || $c->sku == "") && ($commodity->sku != null && $commodity->sku != "")){
|
|
|
+ $commodityDelete[] = $commodityMap[$key];
|
|
|
+ $commodityMap[$key] = $index;
|
|
|
+ }else{
|
|
|
+ //当前数据比源数据更符合预期,替换掉
|
|
|
+ if (($c->sku == $commodity->sku) && (strlen($c->name) < strlen($commodity->name))){
|
|
|
+ $commodityDelete[] = $commodityMap[$key];
|
|
|
+ $commodityMap[$key] = $index;
|
|
|
+ }else{
|
|
|
+ //扔进处理池
|
|
|
+ $commodityDelete[] = $index;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //第一次出现的新数据,val为下标,当作指针指向源数据
|
|
|
+ }else $commodityMap[$key] = $index;
|
|
|
+ }
|
|
|
+ $createBarcodes = []; //批量生成条码
|
|
|
+ $deleteCommodities = []; //批量删除商品及商品条码
|
|
|
+
|
|
|
+ $updateCommodities = [];
|
|
|
+ foreach ($commodityDelete as $index){
|
|
|
+ //获取到被处理数据 与 目标数据
|
|
|
+ $del = $commodities[$index];
|
|
|
+ $target = $commodities[$commodityMap[$del->owner_id.'_'.$del->barcode_code]];
|
|
|
+
|
|
|
+ //记录ID删除商品与条码
|
|
|
+ $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
|
|
|
+ where commodity_id = ".$target->commodity_id." and b.code = a.code) = 0"));
|
|
|
+ if (count($barcodes) > 0){
|
|
|
+ foreach ($barcodes as $barcode){
|
|
|
+ $createBarcodes[] = ['code'=>$barcode->code, 'commodity_id'=>$target->commodity_id];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $updateCommodities[$del->commodity_id] = $target->commodity_id;
|
|
|
+ }
|
|
|
+ if (count($updateCommodities) > 0){
|
|
|
+ $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(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(data_get($logCommodityBarcodes,'*.id'),JSON_UNESCAPED_UNICODE));
|
|
|
+
|
|
|
+ CommodityBarcode::query()->whereIn('commodity_id',$deleteCommodities)->delete();
|
|
|
+
|
|
|
+// $logCommodities = Commodity::query()->whereIn('id',$deleteCommodities)->get();
|
|
|
+ if (count($deleteCommodities) > 0)LogService::log(__METHOD__,"纠正商品-删除无用商品",json_encode($deleteCommodities,JSON_UNESCAPED_UNICODE));
|
|
|
+
|
|
|
+ Commodity::destroy($deleteCommodities);
|
|
|
+ }
|
|
|
+
|
|
|
public function test2(){
|
|
|
- $commodity = app('commodityService')->ownerBarcodeSeekCommodityFirst(['id'=>8],"6971393121341");
|
|
|
- dd($commodity);
|
|
|
+ ini_set('max_execution_time',2500);
|
|
|
+ ini_set('memory_limit','1526M');
|
|
|
+ $logs = Log::query()->where('created_at','>','2020-09-30 12:25:36')
|
|
|
+ ->where('created_at','<','2020-09-30 18:00:36')
|
|
|
+ ->where('operation','App\Services\common\BatchUpdateService::batchUpdateItself')
|
|
|
+ ->get();
|
|
|
+ foreach ($logs as $log){
|
|
|
+ $str1 = mb_strlen("批量更新失败 SQL:(");
|
|
|
+ $str2 = mb_strripos($log->description,") 堆栈:");
|
|
|
+ $str = mb_substr($log->description,$str1,$str2-$str1);
|
|
|
+ $str = str_replace('CASEcommodity_id',"CASE commodity_id",$str);
|
|
|
+ $str = str_replace('END WHERE commodity_id'," END WHERE commodity_id",$str);
|
|
|
+ try{
|
|
|
+ DB::select(DB::raw($str));
|
|
|
+ LogService::log(__METHOD__,"纠正商品-SQL执行BUG",$str);
|
|
|
+ }catch(\Exception $e){
|
|
|
+ LogService::log(__METHOD__,"纠正商品-SQL执行BUG-失败",$str." | 堆栈:". $e->getMessage() . $e->getTraceAsString());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/*1*/
|
|
|
@@ -506,10 +633,9 @@ class TestController extends Controller
|
|
|
|
|
|
}
|
|
|
|
|
|
- public function doctype(){
|
|
|
-
|
|
|
- $a=\Doctrine\DBAL\Types\Type::getTypesMap();
|
|
|
- dd($a);
|
|
|
+ public function usage(){
|
|
|
+ dd(Request::all());
|
|
|
+ $users=User::query();
|
|
|
}
|
|
|
public function orderTrckingOwnerAll(){
|
|
|
$owners = Owner::all();
|