Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function index()
- {
- $failas = "akcijos.txt";
- $directory = "app/";
- $failas = $directory.$failas;
- $myfile = fopen(storage_path($failas), "r");
- $key = fread($myfile,filesize(storage_path($failas)));
- fclose($myfile);
- $key = explode("||", $key);
- $keyword = $key[0];
- //paieska, paprasta, isplestine
- if($key[1]){
- $pa = "%{$keyword}%";
- }else{
- $pa = "{$keyword}%";
- }
- //reikia pasiziuret kuriose valstybese yra
- //sutraukti musu gamybos, jei tik nori
- //Kai itraukiam akcija kodui, ir ieskom maziausia kaina, reikia ziureti ar turi konkretu sandseli, jei turi isskirti atskirai
- $group = array();
- /*$group = DB::table('akcijos')
- ->join('likutis', function ($q) use($pa) {
- $q->on('akcijos.preke', '=', 'likutis.preke')
- ->where('akcijos.preke', 'like', $pa);
- })
- ->select('akcijos.*', 'likutis.kaina as pradine')
- ->get();*/
- $directory = "app/CSV_DATA/";
- $failas = $directory."likutis.csv";
- if (($handle = fopen(storage_path($failas), "r")) !== FALSE) {
- while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
- $duomenys = mb_convert_encoding($data, "UTF-8", "ISO-8859-13");
- $r[] = $duomenys[0];
- $rr[$duomenys[0]] = array();
- }
- fclose($handle);
- }
- $query_p = Akcijos::query();
- $query_p->whereIn('preke', $r);
- //$query_p->where('preke', $r[$i]);
- $re = $query_p->get();
- foreach ( $re as $value ) {
- if(strtotime($value['galioja_iki']) > strtotime(date("Y-m-d H:i:s"))){
- if (!array_key_exists($value['preke'], $group)){
- $group[$value['preke']] = $value;
- }else{
- if(floatval($value['kaina']) < floatval($group[$value['preke']]['kaina'])){
- if($value['sandelis'] == ""){
- $group[$value['preke']] = $value;
- }else{
- $group[$value['preke']."-||SAND"] = $value;
- }
- }
- }
- }
- }
- $group = array_merge($rr, $group);
- //Sudedam norimus likucius
- $query = Likutis::query();
- $query->whereIn('preke', $r);
- $re = $query->get();
- foreach ( $re as $value ) {
- if (array_key_exists($value['preke'], $group)){
- if (!array_key_exists('pradine', $group[$value['preke']])){
- $group[$value['preke']]['pradine'] = $value['kaina'];
- }
- if (!array_key_exists('preke', $group[$value['preke']])){
- $group[$value['preke']]['preke'] = $value['preke'];
- }
- //if($value['salis'] == 1){
- //neveikia sita vieta jei parasau gale []
- $group[$value['preke']]['sandeliai'][] = $value['sandelis'];
- //}
- $group[$value['preke']]['likutis'] += $value['kiekis'];
- }else{
- $group[$value['preke']]['kaina'] = 'NΔRA';
- $group[$value['preke']]['preke'] = $value['preke'];
- $group[$value['preke']]['pradine'] = $value['kaina'];
- $group[$value['preke']]['likutis'] += $value['kiekis'];
- }
- }
- ksort($group);
- $group = array_values($group);
- return response()->json([
- 'status' => true,
- 'paieska' => $keyword,
- 'data' => $group,
- 'likutis' => $re,
- 'paieska_big' => $key[1],
- ]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement