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(); dd($packages); $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']); } } public function test2(){ $wmsCommodities = app('oracleBasSkuService')->getPiece([],0,5000); dd(count($wmsCommodities)); dd(json_encode($wmsCommodities,JSON_UNESCAPED_UNICODE)); //json_decode(json_encode($wmsCommodities,JSON_UNESCAPED_UNICODE),true); } /*1*/ function socket(Request $request) {/**/ $a = microtime(true); error_reporting(E_ALL); set_time_limit(0); echo "

TCP/IP Connection

\n"; $port = 8091; $ip = "127.0.0.1"; /* +------------------------------- * @socket连接整个过程 +------------------------------- * @socket_create * @socket_connect * @socket_write * @socket_read * @socket_close +-------------------------------- */ $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if ($socket < 0) { echo "socket_create() failed: reason: " . socket_strerror($socket) . "\n"; }else { echo "OK.\n"; } echo "试图连接 '$ip' 端口 '$port'...\n"; $result = socket_connect($socket, $ip, $port); if ($result < 0) { echo "socket_connect() failed.\nReason: ($result) " . socket_strerror($result) . "\n"; }else { echo "连接OK\n"; } $b = microtime(true); echo "连接耗时:".($b-$a)."\n"; $content = Commodity::query()->limit(200)->get(); $c= microtime(true); echo "查询数据耗时:".($c-$b)."\n"; $content->toArray(); /*$chunks=$content->chunk(100); foreach ($chunks as $chunk){ $chunk->toJson(); var_dump(mb_strlen($chunk->toJson())); //socket_write($socket, $chunk->toJson(), mb_strlen($chunk->toJson())); }*/ $d= microtime(true); echo "发送数据耗时:".($d-$c)."\n"; socket_close($socket); $e= microtime(true); echo "共耗时:".($e-$a)."\n"; } public function test3() { // $startDate = \Illuminate\Support\Carbon::parse('2020-05-06 13:16:51')->toDateTimeString(); $startDate = \Illuminate\Support\Carbon::parse('2020-09-21 00:00:00')->toDateTimeString(); /** @var OrderTrackingService $orderTrackingService */ $orderTrackingService = app('orderTrackingService'); $orderTrackingService->trackingWmsOrder($startDate); } public function syncWmsOrder(){ $startDate = \Illuminate\Support\Carbon::parse('2020-09-19 00:00:00')->toDateTimeString(); /** @var OrderTrackingService $orderTrackingService */ $orderTrackingService = app('orderTrackingService'); $orderTrackingService->trackingWmsOrder($startDate); } public function orderTrckingOwnerAll(){ $owners = Owner::all(); foreach ($owners as $owner) { $orderTrackingOwner = OrderTrackingOwner::query()->where('owner_id',$owner->id)->first(); if($orderTrackingOwner == null){ OrderTrackingOwner::query()->create(['owner_id'=>$owner->id,'status'=>'启用']); }else{ if($orderTrackingOwner->status == '禁用'){ $orderTrackingOwner->status = '启用'; } } } } public function updateOrderTracking(){ // update client order_remark $orderTrackings = OrderTracking::query() ->with('commodities.package.order') ->get(); $orderNos = []; $order_tracking = []; foreach ($orderTrackings as $orderTracking) { $order = $orderTracking->commodities->package->order ?? ''; $orderNos[] = $order->code; $order_tracking[$order->code][] = $orderTracking; } $orderHeaders = OracleDOCOrderHeader::query() ->whereIn('orderNo',$orderNos) ->get(); $fillables = [['id','client','order_remark']]; foreach ($orderHeaders as $orderHeader) { $orderTracking_list = $order_tracking[$orderHeader->orderno]; $notes = $orderHeader['notes']; // $notes = str_replace('【','[',$notes); $client = null; $order_remark = null; if (strpos($notes, '[')) { $arr= str_split($notes,strpos($notes,'[')); $client = $arr[0] ?? ''; $order_remark = $arr[1] ?? ''; $order_remark = str_replace(['[',']'],'',$order_remark); } foreach ($orderTracking_list as $item) { $fillables[] = [ 'id' => $item->id, 'client' => $client, 'order_remark' => $order_remark ]; } } /** @var BatchUpdateService $batchUpdateService */ $batchUpdateService = app('batchUpdateService'); $batchUpdateService->batchUpdate('order_trackings',$fillables); } public function updateOrderTrackingLogistic(){ $orderTrackings = OrderTracking::query()->with('commodities.package.order')->get(); $order_nos = []; foreach ($orderTrackings as $order_tracking){ $order = $order_tracking->commodities->package->order ?? false; if($order ?? false){ $order_nos[] = $order['code']; } } $order_nos = array_unique($order_nos); $orderHeaders = OracleDOCOrderHeader::query()->whereIn('OrderNo',$order_nos)->get(); $owners_code = data_get($orderHeaders,'*.userdefine1'); $logistics = Logistic::query()->where('code',$owners_code)->get(); $orders = Order::query()->whereIn('code',data_get($orderHeaders,'*.orderno'))->get(); foreach ($orderHeaders as $orderHeader) { $order = $orders->where('code',$orderHeader->orderno)->first(); $logistics = $logistics->where('code',$orderHeader->userdefine1)->first(); $order->update(['logistic_id'=>$logistics->id]); } } public function updateClient(){ $orderTrackings = OrderTracking::query()->with('commodities.package.order')->get(); $orderNo = data_get($orderTrackings,'*.commodities.package.order.code'); $orders = Order::query()->where('code',$orderNo)->get(); OracleDOCOrderHeader::query()->whereIn('orderno',data_get('*'))->first(); } }