data["active_test"] = "active";
}
public function method(Request $request, $method)
{
return call_user_func([$this, $method], $request);
}
function packageFromLog(Request $request)
{ //x $packagesBatch=Package::where('batch_number',$batch_number)->first();
ini_set('max_execution_time', 2500);
ini_set('memory_limit', '1526M');
$uploaded = 0;
$count = DB::table('logs')->where('operation', 'like', "%PackageController::new_%")
->where('created_at', '>', "2020-06-08 15:46:00")
->where('created_at', '<', "2020-06-08 15:47:00")
->where('type', "request_new_")
->count();
$requests = DB::table('logs')->where('operation', 'like', "%PackageController::new_%")
->where('created_at', '>', "2020-06-08 15:46:00")
->where('created_at', '<', "2020-06-08 15:47:00")
->where('type', "request_new_")
->get();
$requests->each(function ($request) use (&$uploaded) {
$requestJson = json_decode($request->description, true);
$response = Zttp::withHeaders(['content-type' => 'application/json',
])->post('https://was.baoshi56.com/api/thirdPart/flux/package/new',
$requestJson
);
if ($response->json() && $response->json()['response'] && $response->json()['response']['flag'] == 'Y')
$uploaded += 1;
});
dd($uploaded . '/' . $count);
}
function issues()
{
/** @var OrderPackageService $orderPackageService */
$orderPackageService = app('orderPackageService');
$ids = [741,739,738,736,735,733,732,731,730,729,728,725,724,723,721,720,719,718,717,715,714,713,712,711,710,705,703,702,701,700,699,698,696,694,693,692,691,690];
$orderIssues = OrderIssue::query()->whereIn('id',$ids)->get();
$order_ids = data_get($orderIssues,'*.order_id');
$orders = Order::query()->whereIn('id',$order_ids)->get();
foreach ($orders as $item) {
$orderPackageService->createdByOrder($item);
}
}
function t2(Request $request)
{ //x $packagesBatch=Package::where('batch_number',$batch_number)->first();
$inventoryCompareService = new InventoryCompareService();
echo ($inventoryCompareService)->getCreatingMissionCode('安桥主品');
echo ($inventoryCompareService)->getCreatingMissionCode('安桥主品');
echo ($inventoryCompareService)->getCreatingMissionCode('安桥主品');
echo ($inventoryCompareService)->getCreatingMissionCode('安桥主品');
}
function setCache(Request $request)
{
$today = now();
Cache::put('storedTest', $today);
return "cacheing:'$today'";
}
function getCache(Request $request)
{
$cache=Cache::get('storedTest');
return "cacheing get:'$cache'";
}
function t1(Request $request)
{
{
$username=config('database.connections.oracle.username');
$password=config('database.connections.oracle.password');
$host=config('database.connections.oracle.host');
$service_name=config('database.connections.oracle.service_name');
$conn=oci_connect($username,$password,$host.'/'.$service_name); //连接oracle数据库
$IN_WarehouseID='';
$IN_TraceID='' ;
$IN_WavenNo='';
$IN_UserID='';
$IN_Language='';
$OUT_Return_Code='';
$sql_sp="begin SPCUS_EDI_WCS001(:IN_WarehouseID,:IN_Process_Action_C,:IN_Process_By_C,
:IN_WaveNO_C,:IN_OrderNO_C,:IN_OrderLineNO_C,:IN_AllocationDetailsID,:IN_Language,:IN_UserID,:OUT_Return_Code); end;";
$stmt = oci_parse($conn, $sql_sp);
oci_bind_by_name($stmt,':IN_Warehouse',$IN_WarehouseID);
oci_bind_by_name($stmt,':IN_TraceID',$IN_TraceID);
oci_bind_by_name($stmt,':IN_WavenNo',$IN_WavenNo);
oci_bind_by_name($stmt,':IN_Language',$IN_Language);
oci_bind_by_name($stmt,':IN_UserID',$IN_UserID);
oci_bind_by_name($stmt,':OUT_Return_Code',$OUT_Return_Code);
return oci_execute($stmt);
}
}
function packageT(Request $request)
{
$package=Package::where('created_at','<','2020-07-08')->whereNotNull('logistic_number')->first();
$package->fetchLogistic();
}
function injectJS(Request $request)
{
$items = RejectedBillItem::whereHas('rejectedBill', function ($query) {
return $query->where('id_owner', 2);
})->where('created_at', '>', '2019-12-23 18:11:00')->where('created_at', '<', '2019-12-24 11:25:00')->get();
(new RejectedBillItemController())->collectionsToPackConfirm($items);
}
public function tj2(Request $request)
{
$numbersesOfBatch=OracleDOCWaveDetails::select('picktotraceid as logistic_number','act_allocation_details.orderno')->where('doc_wave_details.waveno','W190630000042')
->leftJoin('act_allocation_details','doc_wave_details.orderno','act_allocation_details.orderno')->get();
$oneIdxAsrsReceive=OracleDocOrderPackingSummary::where('traceid',$numbersesOfBatch[0]['logistic_number'])->first();
if(!$oneIdxAsrsReceive){
$inserts='';
$values=[];
foreach($numbersesOfBatch as $numbers){
$inserts .= " into doc_order_packing_summary (traceid,orderno,grossweight,addwho,addtime,editwho,edittime)values(?,?,?,?,?,?,?) ";
$values[] = $numbers['logistic_number']??'';
$values[] = $numbers['orderno']??'';
$values[] = 12;
$values[] = 'WAS';
$values[] = Carbon::now();
$values[] = 'WAS';
$values[] = Carbon::now();
}
DB::connection('oracle')->insert("insert all {$inserts} select * from dual",$values);
}else{
$logisticNumbers=$numbersesOfBatch->map(function($numbers){return $numbers['logistic_number'];});
OracleDocOrderPackingSummary::whereIn('traceid',$logisticNumbers)->update(['grossweight'=>32]);
}
}
public function delme()
{
$fields = [
'doc_order_header.userdefine1',
'doc_order_header.userdefine2',
'doc_order_header.SOReference5',
'doc_order_header.waveno',
'doc_order_header.orderno',
'doc_order_header.customerid',
'doc_order_header.Consigneename'
];
if(''){
$resultOracleObj=OracleDOCOrderHeader::select($fields)->where('orderno','SO200603004708');
}else{
$resultOracleObj=OracleActAllocationDetails::select($fields);
$resultOracleObj->where('picktotraceid','546152742096');
$resultOracleObj->leftJoin('DOC_Order_Header','act_allocation_details.orderno','doc_order_header.orderno');
}
$_temOracleInfo=$resultOracleObj->first();
dd($_temOracleInfo);
}
public function mergerPackageData(){
ini_set('max_execution_time',36000);
ini_set('memory_limit','1526M');
$number = 3000;
$start_at = 1;
$sum = Package::query()->where('id','>', $start_at)->count();
$len = ceil($sum / $number);
$id = $start_at;
for ($i = 1;$i <= $len; $i++){
$packages = Package::query()->orderBy('id')->where('id','>',$id)->limit($number)->get();
$error = [];
foreach ($packages as $package){
/** @var $service OrderPackageService */
$service = app('orderPackageService');
$orderPackage = $service->firstOrCreate($package->logistic_number,
['batch_number'=>$package->batch_number,
'batch_rule'=>$package->batch_rule,
'bulk'=>$package->bulk,
'weight'=>$package->weight,
'length'=>$package->length,
'width'=>$package->width,
'height'=>$package->height,
'paper_box_id'=>$package->paper_box_id,
'measuring_machine_id'=>$package->measuring_machine_id,
'weighed_at'=>$package->weighed_at,
'status'=>$package->status]);
if (!$orderPackage)array_push($error,$package->id);
}
LogService::log(__METHOD__,"同步时WMS中未找到这些订单",json_encode($error));
$id = $packages[count($packages)-1]->id;
echo $number.' a bunch done at:'.now()->toFormattedDateString().'
';
}
}
public function excelIt()
{
$excel = new ExcelController();
return $excel->makeExcel();
}
public function featureIt()
{
LogisticNumberFeatureController::loadRecentRejectedsToFeatures(5, 2500);
}
public function newSku()
{
$url = 'http://bswcs/api/sorting/flux/newSku';
$response = Zttp::post($url, [
'request' => [
[
"SKU" => "1234567890",
"NAME" => "瑞士莲**巧克力",
"Alternate_SKU1" => "1122334455",
"GrossWeight" => "1.2",
"Cube" => "0.75",
"SKULength" => "0.25",
"SKUWidth" => "0.15",
"SKUHigh" => "0.05"
],
[
"SKU" => "1234567892",
"NAME" => "跳跳饼",
"Alternate_SKU1" => "",
"GrossWeight" => "1.3",
"Cube" => "0.75",
"SKULength" => "0.25",
"SKUWidth" => "0.15",
"SKUHigh" => "0.25"
],
]
]);
return $response->json();
}
public function changePackage()
{
$packages = Package::where('delivery_number', '<>', null)->where('logistic_id', null)->get();
$packages = Package::whereRaw('delivery_number IS NOT NULL AND logistic_id IS NULL')->get();
$logistics = Logistic::get();
$packages->each(function ($package) use ($logistics) {
$logistics->each(function ($logistic) use ($package) {
if ($package->WMSReflectPackage->CarrierID == $logistic->code) {
$package->logistic_id = $logistic->id;
return;
}
});
});
return "OK";
}
public function tNull()
{
User::query()->get()->toArray();
User::query()->get()->toJson();
}
public function deletePackageAuthority()
{
$authorities = Authority::where('name', 'like', '%包裹信息%')->get();
$authorities->each(function ($authority) {
$authority->delete();
});
}
function test(){
$ids = [];
$logs = Log::query()->select('description')->where('type','同步时WMS中未找到这些订单')->get();
foreach ($logs as $log){
$arr = [];
eval("\$arr = ".$log->description.'; ');
if (count($arr) < 1)continue;
$ids = array_merge($ids,$arr);
}
$ids = array_unique($ids);
$error = [];
foreach($ids as $id){
$package = Package::query()->find($id);
/** @var OrderPackageService */
$orderPackage = app('orderPackageService')->firstOrCreate($package->logistic_number,
['batch_number'=>$package->batch_number,
'batch_rule'=>$package->batch_rule,
'bulk'=>$package->bulk,
'weight'=>$package->weight,
'length'=>$package->length,
'width'=>$package->width,
'height'=>$package->height,
'paper_box_id'=>$package->paper_box_id,
'measuring_machine_id'=>$package->measuring_machine_id,
'weighed_at'=>$package->weighed_at,
'status'=>$package->status]);
if (!$orderPackage)array_push($error,$package->id);
}
if (count($error) > 0)LogService::log(__METHOD__,"同步时WMS中未找到这些订单_two",json_encode($error));
}
function test1(){
$statistics = ProcessStatistic::query()->whereNull('revenue')->get();
$id = array_column($statistics->toArray(),'process_id');
$processes = Process::query()->where(function (Builder $query){
$query->where('status','待交接')->orWhere('status','交接完成');
})->whereIn('id',$id)->get();
$sign_end = true;
foreach ($processes as $process){
if (count($process->processDailies)>0){
$completed_amount=0;
foreach ($process->processDailies as $processDaily){
$completed_amount=$completed_amount+($processDaily->output);
}
$process->completed_amount=$completed_amount;
}
//统计:
$revenue=($process->unit_price)*($process->completed_amount); //收入合计
$processDailies=ProcessDaily::with('processDailyParticipants')->where('process_id',$process->id)->where('output','>',0)->get();
$duration_days=count($processDailies); //完成天数
$duration_man_hours=0; //总工时
$total_cost=0; //合计成本
foreach ($processDailies as $processDailyOne){
foreach ($processDailyOne->processDailyParticipants as $processDailyParticipant){
if (!$processDailyParticipant->unit_price && !$processDailyParticipant->hour_price) continue;
$duration_man_hours += $processDailyParticipant->hour_count;
if ($processDailyParticipant->unit_count){
$total_cost += ($processDailyParticipant->unit_count)*($processDailyParticipant->unit_price);
continue;
}
$total_cost += ($processDailyParticipant->hour_count)*($processDailyParticipant->hour_price);
}
};
$processStatistic=ProcessStatistic::query()->find($process->id);
$processStatistic->revenue=$revenue;
$processStatistic->duration_days=$duration_days;
$processStatistic->duration_man_hours=$duration_man_hours;
if ($sign_end) $processStatistic->ended_at = date('Y-m-d H:i:s');
if (!$revenue || !$total_cost){
$processStatistic->update();
continue;
}
$gross_profit=$revenue-$total_cost; //毛利润
if ($gross_profit!=0)$gross_profit_rate=$gross_profit/$revenue; //毛利率;
else $gross_profit_rate=0;
$processStatistic->total_cost=$total_cost;
$processStatistic->gross_profit=$gross_profit;
$processStatistic->gross_profit_rate=$gross_profit_rate;
$processStatistic->update();
$this->log(__METHOD__,"修改二次加工单统计单_".__FUNCTION__,json_encode($processStatistic),Auth::user()['id']);
}
}
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(){
$owner = Owner::where('name','B站')->first();
$commodities = Commodity::query()->where('owner_id',$owner->id)->get();
$comID = array_column($commodities->toArray(),'id');
CommodityBarcode::query()->whereIn('commodity_id',$comID)->delete();
Commodity::destroy($comID);
return $comID;
}
/*1*/
function socket(Request $request)
{/**/
$a = microtime(true);
error_reporting(E_ALL);
set_time_limit(0);
echo "